diff --git a/@stellar/design-system-website/docs/components/notifications/_category_.json b/@stellar/design-system-website/docs/components/notifications/_category_.json new file mode 100644 index 00000000..534b0b43 --- /dev/null +++ b/@stellar/design-system-website/docs/components/notifications/_category_.json @@ -0,0 +1,6 @@ +{ + "label": "Notifications", + "link": { + "type": "generated-index" + } +} diff --git a/@stellar/design-system-website/docs/components/notifications/notification.mdx b/@stellar/design-system-website/docs/components/notifications/notification.mdx new file mode 100644 index 00000000..6aee4a42 --- /dev/null +++ b/@stellar/design-system-website/docs/components/notifications/notification.mdx @@ -0,0 +1,19 @@ +--- +slug: /notification +--- + +# Notification + + + +## Example + +```tsx live + + + +``` + +## Props + + diff --git a/@stellar/design-system-website/src/componentPreview/notificationPreview .tsx b/@stellar/design-system-website/src/componentPreview/notificationPreview .tsx new file mode 100644 index 00000000..b30b3062 --- /dev/null +++ b/@stellar/design-system-website/src/componentPreview/notificationPreview .tsx @@ -0,0 +1,65 @@ +import React from "react"; +import { ComponentPreview } from "@site/src/components/PreviewBlock"; +import CheckIconSvg from "@site/static/img/check-icon.svg"; + +export const notificationPreview: ComponentPreview = { + options: [ + { + type: "select", + prop: "variant", + options: [ + { + value: "primary", + label: "Primary", + }, + { + value: "secondary", + label: "Secondary", + }, + { + value: "success", + label: "Success", + }, + { + value: "error", + label: "Error", + }, + { + value: "warning", + label: "Warning", + }, + ], + }, + { + type: "select", + prop: "icon", + customValue: , + options: [ + { + value: "", + label: "Default icon", + }, + { + value: "customIcon", + label: "Custom icon", + }, + ], + }, + { + type: "select", + prop: "children", + customValue: + "Lorem ipsum dolor sit amet consectetur, adipisicing elit. Tenetur asperiores autem excepturi doloremque esse, dicta sunt soluta! Quia quis eos beatae et optio facere voluptatum. Labore illum molestiae corporis id?", + options: [ + { + value: "", + label: "No message", + }, + { + value: "Message", + label: "Message", + }, + ], + }, + ], +}; diff --git a/@stellar/design-system-website/src/components/PreviewBlock/index.tsx b/@stellar/design-system-website/src/components/PreviewBlock/index.tsx index f0682e67..48d4933b 100644 --- a/@stellar/design-system-website/src/components/PreviewBlock/index.tsx +++ b/@stellar/design-system-website/src/components/PreviewBlock/index.tsx @@ -13,6 +13,7 @@ import { headingPreview } from "@site/src/componentPreview/headingPreview"; import { captionPreview } from "@site/src/componentPreview/captionPreview"; import { paragraphPreview } from "@site/src/componentPreview/paragraphPreview"; import { titlePreview } from "@site/src/componentPreview/titlePreview"; +import { notificationPreview } from "@site/src/componentPreview/notificationPreview "; // ============================================================================= // Component previews @@ -25,6 +26,7 @@ const previews: { [key: string]: ComponentPreview } = { Caption: captionPreview, Paragraph: paragraphPreview, Title: titlePreview, + Notification: notificationPreview, }; type Theme = "sds-theme-light" | "sds-theme-dark"; @@ -69,7 +71,7 @@ export const PreviewBlock = ({ children: React.ReactElement; }) => { const [sds, setSds] = useState({}); - const { Checkbox, Select } = sds; + const { Checkbox, Select, Notification } = sds; // Importing SDS here because we need it async for server-side-rendering useEffect(() => { @@ -191,6 +193,18 @@ export const PreviewBlock = ({ { checkbox: [], select: [] }, ); + const renderPreview = () => { + // Need to handle Notification manually because of name collision that + // breaks rendering + if (componentName === "Notification") { + return Notification ? ( + + ) : null; + } + + return component; + }; + return ( <>
@@ -217,7 +231,7 @@ export const PreviewBlock = ({
-
{component}
+
{renderPreview()}
{options.checkbox.length > 0 ? (
diff --git a/@stellar/design-system/src/components/Notification/index.tsx b/@stellar/design-system/src/components/Notification/index.tsx index e76841f2..b3b1893c 100644 --- a/@stellar/design-system/src/components/Notification/index.tsx +++ b/@stellar/design-system/src/components/Notification/index.tsx @@ -2,14 +2,28 @@ import React from "react"; import { Icon } from "../../icons"; import "./styles.scss"; -interface NotificationProps extends React.HtmlHTMLAttributes { +/** */ +export interface NotificationProps { + /** Variant of the notification */ variant: "primary" | "secondary" | "success" | "error" | "warning"; + /** Notification title */ title: string; + /** Notification icon @defaultValue `` */ icon?: React.ReactNode; + /** Notification message */ children?: string | React.ReactNode; } -export const Notification: React.FC = ({ +interface Props + extends NotificationProps, + React.HtmlHTMLAttributes { + title: string; +} + +/** + * Use notification to draw user attention. There are five variants `primary`, `secondary`, `success`, `error`, and `warning`. + */ +export const Notification: React.FC = ({ variant, title, icon, diff --git a/@stellar/design-system/src/components/Notification/styles.scss b/@stellar/design-system/src/components/Notification/styles.scss index b2745c24..93ab7a1e 100644 --- a/@stellar/design-system/src/components/Notification/styles.scss +++ b/@stellar/design-system/src/components/Notification/styles.scss @@ -10,6 +10,7 @@ font-family: var(--font-family-base); background-color: var(--Notification-color-background); border: 1px solid var(--Notification-color-border); + border-radius: pxToRem(4px); display: flex; flex-direction: column; gap: pxToRem(8px);