diff --git a/packages/react/src/components/Alert/index.mdx b/packages/react/src/components/Alert/index.mdx new file mode 100644 index 0000000..e1f55b8 --- /dev/null +++ b/packages/react/src/components/Alert/index.mdx @@ -0,0 +1,109 @@ +import { Canvas, Meta, Story, Source, ArgTypes } from '@storybook/blocks'; +import { Alert } from "./index"; +import * as Stories from './index.stories'; + + + +# Alert + +Cunningham provides a versatile Alert component for displaying any kind of information. + + + + + +## Types + +You can use the `type` prop to change the style of the alert. + + + + + + + +## Format + +There are 3 possible formats for the alert, the one line, the multi line one and the expandable one. + + +#### The one line format + + + +#### The multi line format + +> This one is automatically applied when you provide `additionalInformation` prop. + + + +#### The expandable format + +> This one is automatically applied when you provide `additionalInformation` and `expandable` prop. + + + +## Actions + +As you can see in the examples above, you can display buttons on the alerts. You can use the following prop to do so: + +- `primaryLabel` +- `primaryOnClick` +- `primaryProps` + +Those props are shortcuts props provided to the `Button` component. + + + +The same goes for the tertiary button: + +- `tertiaryLabel` +- `tertiaryOnClick` +- `tertiaryProps` + + + +> Those buttons automatically adapt according to the alert format. + +### Customize actions + +If the default provided buttons are not enough for you, you can provide your own buttons and any `ReactNode` you want. +To achieve that, you can use the `buttons` prop. + +> We strongly recommend you to stick to the default `primaryLabel` and `tertiaryLabel` props to match the design system. + + + +## Controlled / Non Controlled + +There are two different props that can be used to control the alert: `expanded`, `closed`. + +When using those props, you must provide `onExpand` and `onClose` callbacks to handle the state of the alert. + + + + +## Props + + + + + +## Design tokens + +Here are the custom design tokens defined by the Alert. + +| Token | Description | +|--------------- |----------------------------- | +| background-color | Default background color | +| border-radius | Border radius of the Alert | +| font-weight | Font weight of the main content | +| color | Color of the main content | +| additional-font-weight | Font weight of the additional information | +| additional-color | Color of the additional content | +| icon-size | Size of the left icon | diff --git a/packages/react/src/components/Alert/index.stories.tsx b/packages/react/src/components/Alert/index.stories.tsx new file mode 100644 index 0000000..e8cc840 --- /dev/null +++ b/packages/react/src/components/Alert/index.stories.tsx @@ -0,0 +1,163 @@ +import { Meta, StoryObj } from "@storybook/react"; +import React from "react"; +import { Alert, AlertProps, AlertType } from ":/components/Alert"; +import { Button } from ":/components/Button"; + +const meta: Meta = { + title: "Components/Alert", + component: Alert, +}; + +export default meta; +type Story = StoryObj; + +export const All: Story = { + render: (args) => { + const customProps: AlertProps = { type: args.type ?? AlertType.INFO }; + return ( + + + + + + + ); + }, + argTypes: { + type: { + options: ["info", "success", "warning", "error", "neutral"], + }, + }, +}; + +export const Info: Story = { + args: { + children: "Alert component info", + canClose: true, + primaryLabel: "Primary", + }, +}; +export const InfoWithTertiary: Story = { + args: { + children: "Alert component info", + canClose: true, + primaryLabel: "Primary", + tertiaryLabel: "Tertiary", + }, +}; +export const CustomButtons: Story = { + args: { + children: "Alert component info", + canClose: true, + buttons: ( + + Primary + Secondary + + ), + }, +}; + +export const Success: Story = { + args: { + children: "Alert component Success", + canClose: true, + primaryLabel: "Primary", + type: AlertType.SUCCESS, + }, +}; + +export const Warning: Story = { + args: { + children: "Alert component Warning", + canClose: true, + primaryLabel: "Primary", + type: AlertType.WARNING, + }, +}; + +export const Error: Story = { + args: { + children: "Alert component Error", + canClose: true, + primaryLabel: "Primary", + type: AlertType.ERROR, + }, +}; + +export const Neutral: Story = { + args: { + children: "Alert component Neutral", + canClose: true, + primaryLabel: "Primary", + type: AlertType.NEUTRAL, + }, +}; + +export const InfoAdditionalInformation: Story = { + args: { + children: "Alert component info", + additional: "Additional information", + canClose: true, + primaryLabel: "Primary", + tertiaryLabel: "Tertiary ", + }, +}; + +export const Controlled: Story = { + render: () => { + const [closed, setClosed] = React.useState(false); + return ( + + setClosed(true)} /> + closed: {closed ? "true" : "false"} + setClosed(false)}>Open + setClosed(true)}>Close + + ); + }, +}; + +export const InfoExpandable: Story = { + render: () => { + return ( + + ); + }, +}; + +export const ExpandableControlled: Story = { + render: () => { + const [closed, setClosed] = React.useState(false); + const [expanded, setExpanded] = React.useState(false); + return ( + + setClosed(true)} + expandable={true} + expanded={expanded} + onExpand={(value) => setExpanded(value)} + /> + closed: {closed ? "true" : "false"} + setClosed(false)}>Open + setClosed(true)}>Close + expanded: {expanded ? "true" : "false"} + setExpanded(true)}>Expand + setExpanded(false)}>Shrink + + ); + }, +};