Skip to content

Commit

Permalink
Notification docs + preview (#167)
Browse files Browse the repository at this point in the history
* Notification docs + preview

* Cleanup
  • Loading branch information
quietbits authored Sep 27, 2023
1 parent 938fe75 commit 0dde47a
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"label": "Notifications",
"link": {
"type": "generated-index"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
slug: /notification
---

# Notification

<ComponentDescription componentName="Notification" />

## Example

```tsx live
<PreviewBlock componentName="Notification">
<Notification title="Notification title" variant="primary" />
</PreviewBlock>
```

## Props

<ComponentProps componentName="Notification" />
Original file line number Diff line number Diff line change
@@ -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: <CheckIconSvg />,
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",
},
],
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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";
Expand Down Expand Up @@ -69,7 +71,7 @@ export const PreviewBlock = ({
children: React.ReactElement;
}) => {
const [sds, setSds] = useState<any>({});
const { Checkbox, Select } = sds;
const { Checkbox, Select, Notification } = sds;

// Importing SDS here because we need it async for server-side-rendering
useEffect(() => {
Expand Down Expand Up @@ -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 ? (
<Notification title="Notification title" variant="primary" {...props} />
) : null;
}

return component;
};

return (
<>
<div className={`PreviewBlock ${theme}`}>
Expand All @@ -217,7 +231,7 @@ export const PreviewBlock = ({
</div>
</div>

<div className="PreviewBlock__component">{component}</div>
<div className="PreviewBlock__component">{renderPreview()}</div>

{options.checkbox.length > 0 ? (
<div className="PreviewBlock__checkboxes">
Expand Down
18 changes: 16 additions & 2 deletions @stellar/design-system/src/components/Notification/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@ import React from "react";
import { Icon } from "../../icons";
import "./styles.scss";

interface NotificationProps extends React.HtmlHTMLAttributes<HTMLDivElement> {
/** */
export interface NotificationProps {
/** Variant of the notification */
variant: "primary" | "secondary" | "success" | "error" | "warning";
/** Notification title */
title: string;
/** Notification icon @defaultValue `<Icon.Info />` */
icon?: React.ReactNode;
/** Notification message */
children?: string | React.ReactNode;
}

export const Notification: React.FC<NotificationProps> = ({
interface Props
extends NotificationProps,
React.HtmlHTMLAttributes<HTMLDivElement> {
title: string;
}

/**
* Use notification to draw user attention. There are five variants `primary`, `secondary`, `success`, `error`, and `warning`.
*/
export const Notification: React.FC<Props> = ({
variant,
title,
icon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0dde47a

Please sign in to comment.