-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update
Snackbar
to import types from Notice
- Loading branch information
Showing
4 changed files
with
25 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,116 +1,42 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { MutableRefObject, ReactNode, SyntheticEvent } from 'react'; | ||
import type { MutableRefObject, ReactNode } from 'react'; | ||
|
||
export type NoticeActionWithURL = { | ||
label: string; | ||
url: string; | ||
onClick?: ( event: SyntheticEvent ) => void; | ||
}; | ||
|
||
type NoticeActionWithOnClick = { | ||
label: string; | ||
url?: string; | ||
onClick: ( event: SyntheticEvent ) => void; | ||
}; | ||
|
||
// TODO: move this type to the Notice component once it gets typed. | ||
export type NoticeAction = NoticeActionWithURL | NoticeActionWithOnClick; | ||
|
||
export type Notice = { | ||
id: string; | ||
spokenMessage: string; | ||
actions: NoticeAction[]; | ||
icon?: ReactNode; | ||
onDismiss?: () => void; | ||
content: string; | ||
isDismissible: boolean; | ||
explicitDismiss: boolean; | ||
}; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { NoticeProps, NoticeChildren } from '../notice/types'; | ||
|
||
export type SnackbarProps = { | ||
/** | ||
* The displayed message of a notice. | ||
* | ||
* Also used as the spoken message for assistive technology, | ||
* unless `spokenMessage` is provided as an alternative message. | ||
*/ | ||
children: string; | ||
/** | ||
* Used to provide a custom spoken message. | ||
* | ||
* @default children | ||
*/ | ||
spokenMessage?: Notice[ 'spokenMessage' ]; | ||
/** | ||
* A politeness level for the notice's spoken message. Should be provided as | ||
* one of the valid options for an `aria-live` attribute value. Note that this | ||
* value should be considered a suggestion; assistive technologies may | ||
* override it based on internal heuristics. | ||
* | ||
* A value of `'assertive'` is to be used for important, and usually | ||
* time-sensitive, information. It will interrupt anything else the screen | ||
* reader is announcing in that moment. | ||
* A value of `'polite'` is to be used for advisory information. It should | ||
* not interrupt what the screen reader is announcing in that moment | ||
* (the "speech queue") or interrupt the current task. | ||
* | ||
* @see https://www.w3.org/TR/wai-aria-1.1/#aria-live | ||
* | ||
* @default 'polite' | ||
*/ | ||
politeness?: 'polite' | 'assertive'; | ||
/** | ||
* An array of action objects. | ||
* | ||
* Each member object should contain | ||
* a `label` and either a `url` link string or `onClick` callback function. | ||
* | ||
* @default [] | ||
*/ | ||
actions?: Notice[ 'actions' ]; | ||
/** | ||
* Called to remove the snackbar from the UI. | ||
*/ | ||
onRemove?: () => void; | ||
type SnackbarOnlyProps = { | ||
/** | ||
* The icon to render in the snackbar. | ||
* | ||
* @default null | ||
*/ | ||
icon?: Notice[ 'icon' ]; | ||
icon?: ReactNode; | ||
/** | ||
* Whether to require user action to dismiss the snackbar. | ||
* By default, this is dismissed on a timeout, without user interaction. | ||
* | ||
* @default false | ||
*/ | ||
explicitDismiss?: Notice[ 'explicitDismiss' ]; | ||
/** | ||
* A callback executed when the snackbar is dismissed. | ||
* | ||
* It is distinct from onRemove, which _looks_ like a callback but is | ||
* actually the function to call to remove the snackbar from the UI. | ||
*/ | ||
onDismiss?: Notice[ 'onDismiss' ]; | ||
explicitDismiss?: boolean; | ||
/** | ||
* A ref to the list that contains the snackbar. | ||
*/ | ||
listRef?: MutableRefObject< HTMLDivElement | null >; | ||
}; | ||
|
||
export type SnackbarProps = NoticeProps & SnackbarOnlyProps; | ||
|
||
export type SnackbarListProps = { | ||
/** | ||
* Array of notices to render. | ||
*/ | ||
notices: Notice[]; | ||
/** | ||
* Children to be rendered inside the notice list. | ||
*/ | ||
children?: ReactNode; | ||
/** | ||
* Function called when a notice should be removed / dismissed. | ||
*/ | ||
onRemove?: ( id: Notice[ 'id' ] ) => void; | ||
notices: Array< | ||
Omit< SnackbarProps, 'children' > & { | ||
id: string; | ||
content: string; | ||
} | ||
>; | ||
onRemove: ( id: string ) => void; | ||
children?: NoticeChildren | Array< NoticeChildren >; | ||
}; |