-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Notice: refactor to TypeScript #47118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
c37a00b
remove from exclude list
chad1008 ee8bbb0
rename js files to js(x), add types.ts
chad1008 4456a8b
add main component prop types
chad1008 b99fc35
update `children` to handle `__unsafeHTML` and JSX elements
chad1008 f9e98d0
fix Button import
chad1008 75e3b3a
add typing to `useSpokenMessage` and `getDefaultPoliteness`
chad1008 a49fb49
type the `event` param of `onDismissNotice`
chad1008 8ab0011
add typing to action mapping arg
chad1008 bf8f7be
add `secondary` and `link` action variants
chad1008 ba475ec
add typing to `NoticeList`
chad1008 1a14810
migrate stories to TypeScript
chad1008 4a91556
add JSDoc example
chad1008 163d7b4
add story demonstrating actions
chad1008 fc7a49d
add story demonstrating JSX children
chad1008 12022b3
update `Snackbar` to import types from `Notice`
chad1008 b5fe417
rename test files to `*.tsx`
chad1008 de29435
unit tests: type `getNoticeWrapper`
chad1008 5fcc88e
add `children` prop values to unit tests
chad1008 bdeb877
update CHANGELOG
chad1008 10347cf
add JSDocs comments to `NoticeListProps`
chad1008 4380512
README: improve design `dos and donts` section readability
chad1008 52c2ddc
README: add horizontal rules between do/dont examples
chad1008 44d5b6d
README: update Props descriptions in README
chad1008 1437ff1
README: remove outdated screenshots and reference to `default` status
chad1008 c96c1aa
whitespace fixes
chad1008 2e1de69
remove `NoticeList` story comment
chad1008 b9963fd
unit test: update jest mocking
chad1008 e9751a9
unit tests: update snapshot
chad1008 508675d
restore JSDoc description for `useSpokenMessage`
chad1008 d85e2b1
remove `WordPressComponentProps` from typing, not really needed here
chad1008 1e6a732
add `NoticeList` n storybook as a subcomponent
chad1008 0385f09
add `NoticeList` JSDoc
chad1008 0c53a19
remove unneeded `argtypes`
chad1008 eec9afe
DRY `ComponentStory` type declarations
chad1008 c82704f
make `NoticeAction` types more specific
chad1008 8506b33
Update packages/components/src/notice/stories/index.tsx
chad1008 5ae653c
Update packages/components/src/notice/stories/index.tsx
chad1008 0342768
`onClick` events typed as `HTMLButtonElement`
chad1008 3a7dcf1
Update packages/components/src/notice/README.md
chad1008 7aa87c4
Update packages/components/src/notice/README.md
chad1008 ff2c6aa
Update packages/components/src/notice/README.md
chad1008 2cc232c
whitespace
chad1008 3d1a13b
Pick from new `Button` types
chad1008 70725f7
default for`NoticeProps[politeness]`
chad1008 08ef1ff
Revert "default for`NoticeProps[politeness]`"
chad1008 8bf4159
sync up docs
chad1008 d43fe8f
improved default for `politeness`
chad1008 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
update
Snackbar to import types from Notice
- Loading branch information
commit 12022b36621306468edf28d3a6d739ca07f807c4
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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'; | ||
chad1008 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * 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; | ||
chad1008 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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 >; | ||
| }; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.