7a89cecb6b
* Notice banner component * Snackbar support * Switch to new components * Finish snackbar implementation * Summary notice * Styling issues * Fix text wrap in shipping calculator * Storybook entries * Docs and tests for NoticeBanner * Framer motion to avoid components dependency * Snackbar list stories * Docs for snackbar list * Update assets/js/base/components/notice-banner/README.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update assets/js/base/components/notice-banner/README.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update assets/js/base/components/notice-banner/README.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update assets/js/base/components/notice-banner/README.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update assets/js/base/components/notice-banner/README.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Types/docblocks * Docs * Update notice type * Use NoticeBannerProps for type of noticeProps * Raw html to fix notice encoding * getClassNameFromStatus is unused * Update position text * Clarify notice text * Fix hover style in whisper TT3 theme * remove div styles * Add new templates for legacy buyer notices in WooCommerce core (https://github.com/woocommerce/woocommerce-blocks/pull/8732) * Add templates for legacy core notices * Update src/Domain/Services/Notices.php Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Remove debugging code * DRY get_notices_template * Simplify error template * Fix padding * Only include new notices if using block cart/checkout --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Fix view box tag * Hover and focus styles * Styling when notices added via ajax * Remove margin change * Implement react-transition-group instead of framer (https://github.com/woocommerce/woocommerce-blocks/pull/8920) * Add screenshots to docs --------- Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> |
||
---|---|---|
.. | ||
stories | ||
README.md | ||
constants.ts | ||
index.tsx | ||
snackbar.tsx | ||
style.scss |
README.md
SnackbarList Component
A temporary informational UI displayed at the bottom of store pages.
Table of contents
Design Guidelines
The buyer notice snackbar is temporary informational UI displayed at the bottom of store pages. WooCommerce blocks, themes, and plugins all use snackbar notices to indicate the result of a successful action.
Snackbar notices work in the same way as the NoticeBanner component, and support the same statuses and styles.
Development Guidelines
Usage
To display snackbar notices, pass an array of notices
to the SnackbarList
component:
import { SnackbarList } from '@woocommerce/base-components';
const notices = [
{
id: '1',
content: 'This is a snackbar notice.',
status: 'default',
isDismissible: true,
}
];
<SnackbarList notices={ notices }>;
The component consuming SnackbarList
is responsible for managing the notices state. The SnackbarList
component will automatically remove notices from the list when they are dismissed by the user using the provided onRemove
callback, and also when the notice times out after 10000ms.
Props
className
: string
Additional class name to give to the notice.
onRemove
: ( noticeId ) => void
Function called when dismissing the notice. When the close icon is clicked or the Escape key is pressed, this function will be called. This is also called when the notice times out after 10000ms.
notices
: NoticeType[]
A list of notices to display as snackbars. Each notice must have an id
and content
prop.
- The
id
prop is used to identify the notice and should be unique. - The
content
prop is the content to display in the notice. - The
status
prop is used to determine the color of the notice and the icon. Acceptable values are 'success', 'error', 'info', 'warning', and 'default'. - The
isDismissible
prop determines whether the notice can be dismissed by the user. - The
spokenMessage
prop is used to change the spoken message for assistive technology. If not provided, thecontent
prop will be used as the spoken message.