diff --git a/docs/figma/Dropdown.md b/docs/figma/Dropdown.md new file mode 100644 index 00000000..d9e69f69 --- /dev/null +++ b/docs/figma/Dropdown.md @@ -0,0 +1,40 @@ +# Dropdown: Figma notes (maintained by AI, do not edit by hand) + +## Nodes + +| What | ID | +| ----------------------------------------------------------- | ----------------------------------------------------------------- | +| Page | `466:793` | +| Component set `Dropdown` (128 variants) | `466:795` | +| Doc frame | `466:2275` | +| Playground frame | `466:2432` | +| Sections: Documentation, Playground, Component, Internal | `466:2274`, `466:2431`, `466:794`, `468:881` | +| Component table labels / spec tables (groups) | in `466:794`: `table labels` `469:1096`, `spec tables` `466:2024` | +| Parts `_Dropdown/Item` (12 variants), `_Dropdown/Menu` (12) | `468:934`, `468:1195` | + +## Properties + +- Variants: `variant` (8) × `shape` (solid, textOnly) × `size` (xs, sm, md, lg; md default) × `disabled`. +- `label` (text) + `showLabel`; `showIcon` + `icon` (instance swap) before the label; `arrow` (instance swap on + `arrowIcon`, always shown): `Icon/arrow_drop_down`, or `_Dropdown/ArrowUp` (`475:1253`, the same glyph turned 180°) + while the menu is open. `pill` is a `sizing/radius/round` corner override on the instance. +- `_Dropdown/Item`: `kind` (item, header) × `disabled` × `size`; `label`, `showIcon` + `icon`, `showDivider` (off on the + first item). +- `_Dropdown/Menu`: `spacing` (callout, withGap, noSpace) × `size`; the MenuList holds four items (header, two items, + a disabled item). +- Table: column `size`; blocks `shape` × `disabled`; rows `variant` (primary first under solid, neutral first under + textOnly). + +## Decisions + +- The button is Button's box and colors (heights 24 · 32 · 40 · 48, `text-{size}` stronger, `sizing/icon/{size}`, + solid fills, neutral `color/neutral/soft`, textOnly `color/{variant}/text` with a `{variant}/soft` hover). The code + default variant is primary for solid and neutral for textOnly (#250). +- The menu: `color/surface/raised`, 1px `color/border/default`, radius `sizing/radius/md`, `elevation/2`; items like + Select's options (`color/text/stronger`, hover `color/neutral/soft`, a `color/border/soft` divider); header + `color/text/softer` strong; disabled `color/text/disabled`. callout: a caret 12px from the anchor's right edge. +- Hover, active, focus and open are in the Color spec (fills bound to the state tokens, the focus ring frame, the up + arrow). open keeps the default colors in every variant: only the arrow turns. +- Spec tables: Size spec (xs … lg × label, icon, icon without label), Color spec (variants × default · hover · active · focus · open · disabled per shape). + Scenarios: open menu by spacing, open menu by size, pill · textOnly. +- No Examples. diff --git a/docs/figma/Modal.md b/docs/figma/Modal.md new file mode 100644 index 00000000..600df28d --- /dev/null +++ b/docs/figma/Modal.md @@ -0,0 +1,35 @@ +# Modal: Figma notes (maintained by AI, do not edit by hand) + +## Nodes + +| What | ID | +| ---------------------------------------------- | --------------------------------------- | +| Page | `465:2182` | +| Component `Modal` | `465:3118` | +| Doc frame | `465:2184` | +| Playground frame | `465:2249` | +| Sections: Documentation, Playground, Component | `465:2183`, `465:2248`, `465:2255` | +| Spec tables (group) | in `465:2255`: `spec tables` `465:3556` | + +## Properties + +- One component, no variants: Modal has no color variants and `size` only changes the width, so the instance width + binds to `sizing/320 · 480 · 720 · 960` (md 480 default). +- `title` and `subtitle` (text) with `showHeader` and `showSubtitle`; `children` (text, the content); `closable` + (the close IconButton xxl neutral, 16px from the top right); `showActions`, `showAction`, `showAlternate` (Button md + pill: action primary solid, alternate neutral outline). +- `noContentPadding` and custom `buttons` are instance overrides; `maximizable` is the instance size (the screen minus + `sizing/64`). + +## Decisions + +- Like AlertModal: `color/surface/raised`, radius `sizing/radius/lg`, `elevation/4`, backdrop `color/backdrop`. +- Header: padding and gap `sizing/space/16`, a 1px `color/border/soft` bottom border; title `heading-h4` + `color/text/strong`, subtitle `body-lg` `color/text/soft`. Content: padding `sizing/space/16`, min height + `sizing/64`, `color/text/default`. Actions: padding and gap `sizing/space/16`, right-aligned, a 1px + `color/border/soft` top border. +- Spec tables: Size spec (sm · md · lg · xl; size only changes the width). Every cell keeps 48px around the modal, so + the `elevation/4` shadows never overlap. Scenarios: Content (title · subtitle · actions, + closable, title only, no header, no actions, actionButton only) and Backdrop (Light · Dark). No Color spec: Modal has + no color variants; Light and Dark are on the doc page. +- No Examples. diff --git a/docs/figma/README.md b/docs/figma/README.md index ad1fdf70..599e4c6c 100644 --- a/docs/figma/README.md +++ b/docs/figma/README.md @@ -11,8 +11,8 @@ what the rules do not: node IDs, per-component decisions and Plugin API pitfalls read-only reference. - Pages, alphabetical inside each group (docs/review/figma.md, Pages): Cover `0:1`, Getting Started `7:2`; Foundations: Colors `7:4`, Elevation `7:8`, Radius `7:7`, Spacing & Sizing `7:6`, Typography `7:5`; Components: Accordion `349:22`, Alert `242:22`, AlertModal `137:22`, - Avatar `236:798`, Badge `230:439`, Breadcrumb `174:22`, Button `129:22`, ButtonGroup `353:22`, Checkbox `339:22`, Chip `239:22`, DataView `269:22`, Divider `169:22`, Form `434:22`, FormField `432:22`, FormFieldGroup `432:531`, Grid `438:522`, Icon `361:288`, IconButton `361:289`, ImageView `352:22`, InputNumber `391:22`, InputPassword `390:22`, InputText `389:22`, Link `171:958`, ListView `265:22`, Pagination `261:22`, Panel `372:22`, - PinCode `405:22`, Popover `381:22`, ProgressBar `176:810`, ProgressCircle `7:10`, Radio `375:22`, RadioGroup `378:22`, Select `7:11`, Skeleton `171:22`, Switch `344:22`, Textarea `403:22`, Timeline `272:22`, Tooltip `384:22`; + Avatar `236:798`, Badge `230:439`, Breadcrumb `174:22`, Button `129:22`, ButtonGroup `353:22`, Checkbox `339:22`, Chip `239:22`, DataView `269:22`, Divider `169:22`, Dropdown `466:793`, Form `434:22`, FormField `432:22`, FormFieldGroup `432:531`, Grid `438:522`, Icon `361:288`, IconButton `361:289`, ImageView `352:22`, InputNumber `391:22`, InputPassword `390:22`, InputText `389:22`, Link `171:958`, ListView `265:22`, Modal `465:2182`, Pagination `261:22`, Panel `372:22`, + PinCode `405:22`, Popover `381:22`, ProgressBar `176:810`, ProgressCircle `7:10`, Radio `375:22`, RadioGroup `378:22`, Select `7:11`, Skeleton `171:22`, Switch `344:22`, Textarea `403:22`, Timeline `272:22`, Toast `465:468`, Tooltip `384:22`; Common Components (divider `386:22`): `_MotifInputText` `386:23`; Internal: `_Doc` `7:13`. The 40 embedded `Icon/` glyph components live on the Icon page (Icons section). - Doc blocks on `_Doc`: Header `11:2`, SectionTitle `11:14`, PropRow `11:29`, Note `11:30`, Label `11:33`, Footer `11:35`, Logo `24:24`, Swatch `25:42`. diff --git a/docs/figma/Toast.md b/docs/figma/Toast.md new file mode 100644 index 00000000..67d87f9a --- /dev/null +++ b/docs/figma/Toast.md @@ -0,0 +1,36 @@ +# Toast: Figma notes (maintained by AI, do not edit by hand) + +## Nodes + +| What | ID | +| ---------------------------------------------- | ----------------------------------------------------- | +| Page | `465:468` | +| Component set `Toast` (8 variants) | `465:538` | +| Doc frame | `465:470` | +| Playground frame | `465:531` | +| Sections: Documentation, Playground, Component | `465:469`, `465:530`, `465:537` | +| Component table labels / spec tables (groups) | in `465:537`: `table labels`, `spec tables` `465:632` | + +## Properties + +- Variants: `variant` (8, default neutral). +- `title` (text) + `showTitle`; `content` (text, always shown: the code requires it); `showIcon` + `icon` (instance swap, + default `Icon/info`); `closable` (default true, like `useToast`); `showProgress` (default true: `useToast` gives a + 3000 ms duration) shows the countdown bar, a ProgressBar `size=sm` of the same variant, absolute along the bottom. +- The toast is 256px wide (`sizing/256`); the code makes it 100vw - 72px below the sm breakpoint. +- Table: no column property; rows `variant`, neutral first. + +## Decisions + +- Fill `{variant}/soft` layered over `color/surface/raised` (the soft tones are translucent and a toast floats over the + page), radius `sizing/radius/md` on every corner, no edge; the icon `{variant}/solid`, the title `{variant}/text` + (`label-xl` Semi Bold), the content `color/text/strong` (`body-md`); `elevation/3`; padding `sizing/space/10` + `sizing/space/16`, gap `sizing/space/10`. +- Toasts in the set, the doc and the spec tables sit 40px apart (cells 32px around the toast), so the `elevation/3` + shadows never overlap. +- The icon and the close button are 24px and sit on the title's line through Alert's `iconSlot` / `closeSlot` with the + 2px `titleOffset`. +- Spec tables: Color spec with the variants as rows and Light · Dark as columns. Scenarios: Content (title · content, + content only, icon unset, closable=false, duration unset). No Size spec: Toast has no sizes. +- The six positions, the slide animations and the pause on hover are on the doc page's "Not shown in Figma" note. +- No Examples. diff --git a/src/lib/components/DateRangePicker/__snapshots__/DateRangePicker.test.tsx.snap b/src/lib/components/DateRangePicker/__snapshots__/DateRangePicker.test.tsx.snap index f0d048ce..f79a41cf 100644 --- a/src/lib/components/DateRangePicker/__snapshots__/DateRangePicker.test.tsx.snap +++ b/src/lib/components/DateRangePicker/__snapshots__/DateRangePicker.test.tsx.snap @@ -13,7 +13,7 @@ exports[`DateRangePicker should render with only required props, have default pr class="selectionBar" > + ); +}; + +export default DropdownButton; diff --git a/src/lib/styles/tokens/compare/baseline/Dropdown/components/DropdownMenuItem.tsx b/src/lib/styles/tokens/compare/baseline/Dropdown/components/DropdownMenuItem.tsx new file mode 100644 index 00000000..98d3ee2e --- /dev/null +++ b/src/lib/styles/tokens/compare/baseline/Dropdown/components/DropdownMenuItem.tsx @@ -0,0 +1,37 @@ +import { DropdownMenuItemProps } from "../types"; +import styles from "../DropdownBaseline.module.scss"; +import GlobalIconWrapper from "../../../../../../components/Motif/GlobalIconWrapper/GlobalIconWrapper"; +import { MouseEvent, useContext } from "react"; +import { sanitizeModuleClasses } from "../../../../../../../utils/cssUtils"; +import { DropdownContext } from "../context/DropdownContext"; + +const DropdownMenuItem = (props: DropdownMenuItemProps) => { + const { label, header, icon, iconColor, disabled, action } = props; + const { size, hideMenu } = useContext(DropdownContext); + const classNames = sanitizeModuleClasses( + styles, + "MenuItem", + header ? "MenuItem_header" : "MenuItem_clickable", + disabled && "MenuItem_disabled", + ); + + const handleClick = (e: MouseEvent) => { + action?.(e); + hideMenu(); + }; + + return ( +
  • + + {header ?? ( + <> + {icon && } + {label && {label}} + + )} + +
  • + ); +}; + +export default DropdownMenuItem; diff --git a/src/lib/styles/tokens/compare/baseline/Dropdown/context/DropdownContext.tsx b/src/lib/styles/tokens/compare/baseline/Dropdown/context/DropdownContext.tsx new file mode 100644 index 00000000..d5fd86c3 --- /dev/null +++ b/src/lib/styles/tokens/compare/baseline/Dropdown/context/DropdownContext.tsx @@ -0,0 +1,4 @@ +import { createContext } from "react"; +import { dropdownContextDefaultValues, DropdownContextProps } from "../types"; + +export const DropdownContext = createContext(dropdownContextDefaultValues); diff --git a/src/lib/styles/tokens/compare/baseline/Dropdown/index.ts b/src/lib/styles/tokens/compare/baseline/Dropdown/index.ts new file mode 100644 index 00000000..4d208f48 --- /dev/null +++ b/src/lib/styles/tokens/compare/baseline/Dropdown/index.ts @@ -0,0 +1 @@ +export { default } from "./Dropdown"; diff --git a/src/lib/styles/tokens/compare/baseline/Dropdown/types.ts b/src/lib/styles/tokens/compare/baseline/Dropdown/types.ts new file mode 100644 index 00000000..c107818e --- /dev/null +++ b/src/lib/styles/tokens/compare/baseline/Dropdown/types.ts @@ -0,0 +1,54 @@ +import type { IconGlobalType } from "../../../../../types"; +import type { MouseEvent } from "react"; +import { OverlayRefProps, Size4SM, Variant } from "../../../../../types"; + +export type Spacing = "withGap" | "callout" | "noSpace"; + +export type DropdownProps = { + label?: string; + icon?: IconGlobalType; + disabled?: boolean; + /** + * ``` + * { + * label?: string; + * icon?: IconGlobalType; + * iconColor?: string; + * header?: string; + * action?: (event: MouseEvent) => void; + * disabled?: boolean; + * }[] + * ``` + */ + items: DropdownMenuItemProps[]; +} & OverlayRefProps & + DropdownDefaultableProps; + +export type DropdownDefaultableProps = { + shape?: "solid" | "textOnly"; + variant?: Variant; + size?: Size4SM; + pill?: boolean; + spacing?: Spacing; +}; + +export type DropdownMenuItemProps = { + label?: string; + icon?: IconGlobalType; + iconColor?: string; + header?: string; + action?: (event: MouseEvent) => void; + disabled?: boolean; +}; + +export type DropdownContextProps = { + size: Size4SM; + disabled?: boolean; + hideMenu: () => void; +}; + +export const dropdownContextDefaultValues: DropdownContextProps = { + size: "md", + disabled: false, + hideMenu: () => {}, +}; diff --git a/src/lib/styles/tokens/compare/baseline/Modal/Modal.tsx b/src/lib/styles/tokens/compare/baseline/Modal/Modal.tsx new file mode 100644 index 00000000..a31a6af7 --- /dev/null +++ b/src/lib/styles/tokens/compare/baseline/Modal/Modal.tsx @@ -0,0 +1,69 @@ +"use client"; + +import styles from "./ModalBaseline.module.scss"; +import ModalHeader from "./components/ModalHeader"; +import { PropsWithRef } from "../../../../../types"; +import ModalActions from "./components/ModalActions"; +import { useMemo } from "react"; +import { createPortal } from "react-dom"; +import useModalOverlay from "../../../../../hooks/useModalOverlay"; +import { ModalProps } from "./types"; +import { sanitizeModuleRootClasses } from "../../../../../../utils/cssUtils"; +import { mergeRefs } from "../../../../../../utils/reactUtils"; +import usePropsWithThemeDefaults from "../../../../../motif/hooks/usePropsWithThemeDefaults"; +import { MotifIconButton } from "@/components/Motif/Icon"; + +const Modal = (props: PropsWithRef) => { + const { + title, + subtitle, + open, + onClose, + onAfterClose, + children, + maximizable, + closable, + size = "md", + buttons, + actionButton, + alternateButton, + noContentPadding, + ref, + style, + className, + } = usePropsWithThemeDefaults("Modal", props); + + const { attached, visible, hide, rootRef, dialogRef, insideProps } = useModalOverlay({ + open: !!open, + onClose, + onAfterClose, + duration: 300, + closeOnOutsideClick: closable, + closeOnEscape: closable, + }); + const mergedRef = useMemo(() => mergeRefs(rootRef, ref), [rootRef, ref]); + + const classNames = sanitizeModuleRootClasses(styles, className, [ + visible && "show", + maximizable && "maximized", + noContentPadding && "noContentPadding", + size, + ]); + return ( + attached && + createPortal( +
    +
    + {closable && hide("closeButton")} size="xxl" className={styles.closeButton} />} + +
    {children}
    + +
    +
    , + document.body, + ) + ); +}; + +Modal.displayName = "Modal"; +export default Modal; diff --git a/src/lib/styles/tokens/compare/baseline/Modal/ModalBaseline.module.scss b/src/lib/styles/tokens/compare/baseline/Modal/ModalBaseline.module.scss new file mode 100644 index 00000000..a5e0776f --- /dev/null +++ b/src/lib/styles/tokens/compare/baseline/Modal/ModalBaseline.module.scss @@ -0,0 +1,141 @@ +@use "@styles" as *; + +$side-space: 4rem; +$sizes: ( + //sizeName, width + ("sm", "320x"), + ("md", "480x"), + ("lg", "720x"), + ("xl", "960x") +); + +.Root { + position: fixed; + inset: 0; + width: 100%; + height: 100%; + min-height: 100%; + background-color: var(--base-colors-black-black-overlay50); + display: flex; + z-index: 999; + @include fade-default; + + &.show { + @include fade-in; + } + + // Size classes at root level + @each $size, $width in $sizes { + &.#{$size} .modal { + width: var(--base-sizing-#{$width}); + } + } + + // Maximized class at root level + &.maximized .modal { + width: calc(100% - $side-space); + height: calc(100% - $side-space); + max-width: none; + max-height: none; + } +} + +.modal { + display: flex; + flex-direction: column; + position: fixed; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + background: white; + color: black; + border-radius: var(--theme-sizing-radius-default); + @include shadow(4); + height: auto; + max-width: calc(100% - $side-space); + max-height: 100%; + overflow: hidden; + transform-origin: left top; + @include pop-default; + + &:focus { + outline: none; + } +} + +.show .modal { + @include pop-in; +} + +.content { + padding: var(--base-sizing-16x); + min-height: var(--base-sizing-64x); + height: 100%; + overflow-y: auto; + + .noContentPadding & { + padding: 0; + } + + &::-webkit-scrollbar { + width: var(--base-sizing-8x); + } + + &::-webkit-scrollbar-track { + background: #f1f1f1; + margin: var(--base-sizing-1x) 0; + border-radius: var(--theme-sizing-radius-default); + } + + &::-webkit-scrollbar-thumb { + background: var(--base-colors-black-black-overlay25); + border-radius: var(--theme-sizing-radius-default); + } +} + +.closeButton { + position: absolute; + top: var(--base-sizing-16x); + right: var(--base-sizing-16x); +} + +// ============================================================================= +// Sub Component: Header +// ============================================================================= + +.header { + display: flex; + padding: var(--base-sizing-16x); + gap: var(--base-sizing-16x); + border-bottom: solid var(--base-sizing-1x) var(--theme-color-surface-base-base6); + align-items: flex-start; +} + +.headerContent { + flex: 1; + gap: var(--base-sizing-4x); + overflow-wrap: break-word; + + .headerTitle { + display: block; + color: var(--theme-color-text-base-title); + @include font("heading", "heading4"); + } + + .headerSubtitle { + display: block; + color: var(--theme-color-text-base-caption); + @include font("body", "lg"); + } +} + +// Modal Actions Styles +.actions { + display: flex; + flex-wrap: wrap; + padding: var(--base-sizing-16x); + gap: var(--base-sizing-16x); + justify-content: flex-end; + flex-shrink: 0; + border-top: solid var(--base-sizing-1x) var(--theme-color-surface-base-base6); +} diff --git a/src/lib/styles/tokens/compare/baseline/Modal/components/ModalActions.tsx b/src/lib/styles/tokens/compare/baseline/Modal/components/ModalActions.tsx new file mode 100644 index 00000000..7cab7dad --- /dev/null +++ b/src/lib/styles/tokens/compare/baseline/Modal/components/ModalActions.tsx @@ -0,0 +1,32 @@ +import type { MouseEvent } from "react"; +import { ReactElement } from "react"; +import Button from "../../../../../../components/Button/Button"; +import styles from "../ModalBaseline.module.scss"; +import { LinkProps } from "../../../../../../components/Link/types"; +import { ButtonProps } from "../../../../../../components/Button/types"; +import { IconButtonProps } from "../../../../../../components/IconButton/types"; + +type Props = { + actionButton?: { text: string; onClick: (event: MouseEvent) => void }; + alternateButton?: { text: string; onClick: (event: MouseEvent) => void }; + buttons?: ReactElement[]; +}; + +const ModalActions = (props: Props) => { + const { alternateButton, buttons, actionButton } = props; + const isVisible = actionButton || alternateButton || buttons?.length; + + return ( + isVisible && ( +
    + {actionButton &&
    + ) + ); +}; + +export default ModalActions; diff --git a/src/lib/styles/tokens/compare/baseline/Modal/components/ModalHeader.tsx b/src/lib/styles/tokens/compare/baseline/Modal/components/ModalHeader.tsx new file mode 100644 index 00000000..3f53778f --- /dev/null +++ b/src/lib/styles/tokens/compare/baseline/Modal/components/ModalHeader.tsx @@ -0,0 +1,25 @@ +import styles from "../ModalBaseline.module.scss"; + +export type HeaderProps = { + title?: string; + subtitle?: string; +}; + +const ModalHeader = (props: HeaderProps) => { + const { subtitle, title } = props; + + return ( + (title || subtitle) && ( +
    + {(title || subtitle) && ( +
    + {title && {title}} + {subtitle && {subtitle}} +
    + )} +
    + ) + ); +}; + +export default ModalHeader; diff --git a/src/lib/styles/tokens/compare/baseline/Modal/index.ts b/src/lib/styles/tokens/compare/baseline/Modal/index.ts new file mode 100644 index 00000000..09b91f72 --- /dev/null +++ b/src/lib/styles/tokens/compare/baseline/Modal/index.ts @@ -0,0 +1 @@ +export { default } from "./Modal"; diff --git a/src/lib/styles/tokens/compare/baseline/Modal/types.ts b/src/lib/styles/tokens/compare/baseline/Modal/types.ts new file mode 100644 index 00000000..3ce9bb23 --- /dev/null +++ b/src/lib/styles/tokens/compare/baseline/Modal/types.ts @@ -0,0 +1,24 @@ +import { ReactElement, ReactNode, MouseEvent } from "react"; +import { OverlayCloseReason, Size4LG } from "../../../../../types"; +import { LinkProps } from "../../../../../components/Link/types"; +import { ButtonProps } from "../../../../../components/Button/types"; +import { IconButtonProps } from "../../../../../components/IconButton/types"; + +export type ModalDefaultableProps = { + size?: Size4LG; + maximizable?: boolean; + closable?: boolean; +}; + +export type ModalProps = { + children: ReactNode; + title?: string; + subtitle?: string; + open?: boolean; + onClose?: (reason: OverlayCloseReason) => void; + onAfterClose?: () => void; + buttons?: ReactElement[]; + actionButton?: { text: string; onClick: (event: MouseEvent) => void }; + alternateButton?: { text: string; onClick: (event: MouseEvent) => void }; + noContentPadding?: boolean; +} & ModalDefaultableProps; diff --git a/src/lib/styles/tokens/compare/baseline/Toast/Toast.tsx b/src/lib/styles/tokens/compare/baseline/Toast/Toast.tsx new file mode 100644 index 00000000..9028c6c0 --- /dev/null +++ b/src/lib/styles/tokens/compare/baseline/Toast/Toast.tsx @@ -0,0 +1,87 @@ +"use client"; + +import { useCallback, useEffect, useMemo, useRef, useState } from "react"; +import styles from "./ToastBaseline.module.scss"; +import GlobalIconWrapper from "../../../../../components/Motif/GlobalIconWrapper/GlobalIconWrapper"; +import { MotifIconButton } from "@/components/Motif/Icon"; +import useTimeout from "../../../../../hooks/useTimeout"; +import { PropsWithRef } from "../../../../../types"; +import { ToastProps } from "./types"; +import { sanitizeModuleRootClasses } from "src/utils/cssUtils.ts"; +import ProgressBar from "@/components/ProgressBar"; + +const Toast = (props: PropsWithRef) => { + const { variant, title, content, duration, closable, icon, onDismiss, position, maxContentLength, ref, id, style, className } = props; + + const [dismissed, setDismissed] = useState(false); + const [closing, setClosing] = useState(false); + const closingTimeoutRef = useRef(null); + + const toastClasses = sanitizeModuleRootClasses(styles, className, [variant, closing && "closing"]); + + const handleDismiss = useCallback(() => { + setClosing(true); + closingTimeoutRef.current = setTimeout(() => { + setDismissed(true); + onDismiss?.(id, position); + }, 300); + }, [id, position, onDismiss]); + + const timer = useTimeout(handleDismiss, duration); + const [paused, setPaused] = useState(false); + + useEffect(() => { + if (duration !== undefined) timer.start(); + }, [duration, timer]); + + useEffect(() => { + return () => { + closingTimeoutRef.current && clearTimeout(closingTimeoutRef.current); + }; + }, []); + + const handleEnter = useCallback(() => { + timer.pause(); + setPaused(true); + }, [timer]); + + const handleLeave = useCallback(() => { + timer.start(); + setPaused(false); + }, [timer]); + + const handlers = useMemo( + () => + closable && { + onMouseEnter: handleEnter, + onMouseLeave: handleLeave, + onTouchStart: handleEnter, + onTouchEnd: handleLeave, + }, + [closable, handleEnter, handleLeave], + ); + + return ( + !dismissed && ( +
    + {icon && } + +
    + {title && {title}} + + {maxContentLength !== undefined && maxContentLength > 0 && maxContentLength < content.length + ? content.substring(0, maxContentLength).concat("...") + : content} + +
    + + {closable && } + + {duration !== undefined && } +
    + ) + ); +}; + +Toast.displayName = "Toast"; +export default Toast; diff --git a/src/lib/styles/tokens/compare/baseline/Toast/ToastBaseline.module.scss b/src/lib/styles/tokens/compare/baseline/Toast/ToastBaseline.module.scss new file mode 100644 index 00000000..bb665fa9 --- /dev/null +++ b/src/lib/styles/tokens/compare/baseline/Toast/ToastBaseline.module.scss @@ -0,0 +1,113 @@ +@use "@styles" as *; + +$color-types: (("secondary", "light"), ("warning", "warning"), ("success", "success"), ("danger", "danger"), ("info", "info")); +$positions: ( + // position, animationIn, animationOut, top, right, bottom, left, transform + ("top", slideInTop, slideOutTop, var(--base-sizing-16x), null, null, 50%, translateX(-50%)), + ("topRight", slideInRight, slideOutRight, var(--base-sizing-16x), var(--base-sizing-16x), null, null, null), + ("topLeft", slideInLeft, slideOutLeft, var(--base-sizing-16x), null, null, var(--base-sizing-16x), null), + ("bottom", slideInBottom, slideOutBottom, null, null, var(--base-sizing-16x), 50%, translateX(-50%)), + ("bottomRight", slideInRight, slideOutRight, null, var(--base-sizing-16x), var(--base-sizing-16x), null, null), + ("bottomLeft", slideInLeft, slideOutLeft, null, null, var(--base-sizing-16x), var(--base-sizing-16x), null) +); +$animation-keyframes: ( + // animation, transform0, transform100, opacity0, $opacity100 + ("slideInRight", translateX(100%), translateX(0%), 0, 1), + ("slideOutRight", translateX(0%), translateX(100%), 1, 0), + ("slideInLeft", translateX(-100%), translateX(0%), 0, 1), + ("slideOutLeft", translateX(0%), translateX(-100%), 1, 0), + ("slideInTop", translateY(-100%), translateY(0%), 0, 1), + ("slideOutTop", translateY(0%), translateY(-100%), 1, 0), + ("slideInBottom", translateY(100%), translateY(0%), 0, 1), + ("slideOutBottom", translateY(0%), translateY(100%), 1, 0) +); +@each $animation, $transformZero, $transformHundred, $opacityZero, $opacityHundred in $animation-keyframes { + @keyframes #{$animation} { + 0% { + opacity: $opacityZero; + transform: $transformZero; + } + 100% { + opacity: $opacityHundred; + transform: $transformHundred; + } + } +} + +.Root { + position: relative; + display: flex; + flex-wrap: nowrap; + @include width-or-width-below-screen-size(--theme-grid-breakpoint-sm, --base-sizing-256x, calc(100vw - var(--base-sizing-72x))); + padding: var(--base-sizing-10x) var(--base-sizing-20x); + gap: var(--base-sizing-10x); + border-radius: var(--theme-sizing-radius-default); + align-items: flex-start; + + .icon { + align-self: center; + } +} + +@each $color-type, $color in $color-types { + .#{$color-type} { + color: var(--theme-color-text-base-title); + background-color: var(--theme-color-surface-#{$color}-negative); + border-left-color: var(--theme-color-text-#{$color}-active); + + .title { + color: var(--theme-color-text-#{$color}-active); + } + } +} + +.contentContainer { + display: flex; + flex-direction: column; + gap: var(--base-sizing-4x); + flex-grow: 1; + max-height: 90vh; + overflow-y: scroll; + @include hidden-scrollbar; + + .content { + @include font("body", "md"); + } + .title { + @include font("base", "lg", "600"); + } +} + +.progress { + position: absolute; + bottom: 0; + left: 0; + width: 100%; +} + +.Container { + display: flex; + flex-direction: column-reverse; + row-gap: var(--base-sizing-12x); + position: fixed; + z-index: 5; + + @each $position, $animationIn, $animationOut, $top, $right, $bottom, $left, $transform in $positions { + &.#{$position} { + /* stylelint-disable declaration-block-no-redundant-longhand-properties */ + top: $top; + right: $right; + bottom: $bottom; + left: $left; + /* stylelint-enable declaration-block-no-redundant-longhand-properties */ + transform: $transform; + + .Root:not(.closing) { + animation: $animationIn 0.3s ease-in-out forwards; + } + .Root.closing { + animation: $animationOut 0.3s ease-in-out forwards; + } + } + } +} diff --git a/src/lib/styles/tokens/compare/baseline/Toast/types.ts b/src/lib/styles/tokens/compare/baseline/Toast/types.ts new file mode 100644 index 00000000..2ffa61c1 --- /dev/null +++ b/src/lib/styles/tokens/compare/baseline/Toast/types.ts @@ -0,0 +1,59 @@ +import type { IconGlobalType } from "../../../../../types"; +import { ReactElement } from "react"; +import { PropsWithRef } from "../../../../../types"; + +export type ToastPosition = "topLeft" | "topRight" | "top" | "bottomLeft" | "bottomRight" | "bottom"; + +export type ToastVariant = "secondary" | "danger" | "warning" | "info" | "success"; + +export type ToastProps = { + id: string; + onDismiss?: (id: string, position: ToastPosition) => void; + content: string; + variant: ToastVariant; + position: ToastPosition; + duration?: number; + closable?: boolean; + title?: string; + icon?: IconGlobalType; + maxContentLength?: number; +}; + +export type AddToastOptions = PropsWithRef; + +export type ToastDefaultableProps = { + title?: string; + position?: ToastPosition; + icon?: IconGlobalType; + duration?: number; + closable?: boolean; + maxContentLength?: number; +}; + +type AddToastType = (content: string, options?: AddToastOptions) => void; +export type UseToastProps = Record & { + toasts: ReactElement; +}; + +export type DeleteToastActionPayload = { id: string; position: ToastPosition }; + +export type AddToastActionType = { + type: string; + payload: PropsWithRef; +}; + +export type DeleteToastActionType = { + type: string; + payload: DeleteToastActionPayload; +}; + +export type ToastStateProps = { + toasts: { + topLeft?: ToastProps[]; + topRight?: ToastProps[]; + top?: ToastProps[]; + bottomLeft?: ToastProps[]; + bottomRight?: ToastProps[]; + bottom?: ToastProps[]; + }; +}; diff --git a/stylelint.config.mjs b/stylelint.config.mjs index 1eb31c8c..c63ce49b 100644 --- a/stylelint.config.mjs +++ b/stylelint.config.mjs @@ -50,6 +50,7 @@ export default { "src/lib/components/Container/**/*.scss", "src/lib/components/DataView/**/*.scss", "src/lib/components/Divider/**/*.scss", + "src/lib/components/Dropdown/**/*.scss", "src/lib/components/Form/**/*.scss", "src/lib/components/Grid/**/*.scss", "src/lib/components/Icon/**/*.scss", @@ -60,6 +61,7 @@ export default { "src/lib/components/InputText/**/*.scss", "src/lib/components/Link/**/*.scss", "src/lib/components/ListView/**/*.scss", + "src/lib/components/Modal/**/*.scss", "src/lib/components/Motif/InputText/**/*.scss", "src/lib/components/Pagination/**/*.scss", "src/lib/components/Panel/**/*.scss", @@ -75,6 +77,7 @@ export default { "src/lib/components/Text/**/*.scss", "src/lib/components/Textarea/**/*.scss", "src/lib/components/Timeline/**/*.scss", + "src/lib/components/Toast/**/*.scss", "src/lib/components/Tooltip/**/*.scss", ], rules: {