Skip to content

Commit d5680de

Browse files
erikyojohnhooks
andauthored
Storybook updates (#148)
* setup storybook as repo documentation * updates to storybook 7 / move the stuff to `./storybook/` in order to facilitate the ci action * enable scss // better dependencies setup * importing the root package json worked! * moving to storybook 7 - components integration * registers the store * working hub * Dashboard overload with multiple notices * feature: add useControlledState * Bell icon / Headbar style updates to storybook 7.0.4 * a better footer button style (also moves the shadow below it) * fixes the store registration/fetching issues * cleanup * removes jsondata from stories assets as suggested by @johnhooks * filters the jsondata in order to get the first of a type (in this case the first notice of the context "adminbar") --------- Co-authored-by: John Hooks <[email protected]>
1 parent ffd0e8f commit d5680de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+13690
-455
lines changed

.gitattributes

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# exclude vendored and generated files
22
package-lock.json linguist-generated
3-
/src/stories/assets/** linguist-vendored
3+
/storybook/stories/assets/** linguist-vendored
44
/docs/** linguist-documentation

.storybook/main.js

-18
This file was deleted.

package-lock.json

-37
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/scripts/components/NoticesArea.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const NoticesArea = ( props ) => {
4646
*/
4747
if ( context === defaultContext ) {
4848
/** Returns the empty notice banner whenever the number of notices is 0 */
49-
if ( ! notifications.length ) {
49+
if ( ! notifications?.length ) {
5050
return <NoticeEmpty size={ 96 } message={ __( 'empty' ) } />;
5151
}
5252

@@ -65,9 +65,9 @@ export const NoticesArea = ( props ) => {
6565
<NoticeHubSectionHeader
6666
context={ context }
6767
unreadCount={
68-
notifications.filter(
68+
notifications?.filter(
6969
( notice ) => notice.status === 'new'
70-
).length
70+
).length || 0
7171
}
7272
isMain={ index === 0 } // the main section is the first one
7373
/>

src/scripts/components/NotificationHub.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { __ } from '@wordpress/i18n';
2-
import { useEffect, useRef, useState } from '@wordpress/element';
2+
import { useEffect, useRef } from '@wordpress/element';
3+
import { useControlledState } from '@wordpress/components/build-module/utils';
34
import {
45
ShortcutProvider,
56
store as keyboardShortcutsStore,
@@ -9,9 +10,19 @@ import { Drawer } from './Drawer';
910
import { NotificationHubIcon } from './NotificationHubIcon';
1011
import * as classNames from 'classnames';
1112

12-
export const NotificationHub = () => {
13+
/**
14+
* The notification hub component.
15+
*
16+
* @param {Object} props
17+
* @param {boolean} props.active Externally supplied active state.
18+
* @param {boolean=} props.initialActive Optionally initially force the hub into an active state.
19+
*/
20+
export const NotificationHub = ( { active, initialActive } ) => {
1321
/** Drawer state */
14-
const [ isActive, setIsActive ] = useState( false );
22+
const [ isActive, setIsActive ] = useControlledState( active, {
23+
initial: initialActive === undefined ? false : initialActive,
24+
fallback: false,
25+
} );
1526
const drawerRef = useRef( null );
1627

1728
/** Register the keyboard shortcut(s) */
@@ -28,7 +39,7 @@ export const NotificationHub = () => {
2839
} );
2940

3041
function toggleDrawer() {
31-
setIsActive( ! isActive );
42+
setIsActive( ( prev ) => ! prev );
3243
}
3344

3445
const handleOutsideClick = ( event ) => {

src/stories/Dash-multiple.stories.js

-69
This file was deleted.

src/stories/Hub-multiple.stories.js

-172
This file was deleted.

0 commit comments

Comments
 (0)