@cloudwick/astral-ui-cli 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -1118,7 +1118,7 @@ async function promptForConfig({
|
|
|
1118
1118
|
// package.json
|
|
1119
1119
|
var package_default = {
|
|
1120
1120
|
name: "@cloudwick/astral-ui-cli",
|
|
1121
|
-
version: "2.
|
|
1121
|
+
version: "2.5.0",
|
|
1122
1122
|
description: "CLI for installing Astral UI components in any codebase",
|
|
1123
1123
|
main: "dist/index.js",
|
|
1124
1124
|
bin: {
|
|
@@ -1581,6 +1581,7 @@ var REGISTRY = {
|
|
|
1581
1581
|
"react",
|
|
1582
1582
|
"tailwind-variants",
|
|
1583
1583
|
"@floating-ui/react",
|
|
1584
|
+
"react-merge-refs",
|
|
1584
1585
|
"tailwind-merge"
|
|
1585
1586
|
],
|
|
1586
1587
|
"internalDependencies": [
|
|
@@ -1602,7 +1603,7 @@ var REGISTRY = {
|
|
|
1602
1603
|
},
|
|
1603
1604
|
{
|
|
1604
1605
|
"name": "button.tsx",
|
|
1605
|
-
"content": 'import * as React from "react";\nimport type { Placement } from "@floating-ui/react";\n\nimport { Tooltip } from "../tooltip";\nimport { ADPIcon, type TIconType } from "../adpIcon";\nimport { buttonVariants } from "./buttonVariants";\n\nexport const colors = [ "primary", "secondary", "success", "warning", "error" ] as const;\nexport const variants = [ "filled", "outline", "shade", "text" ] as const;\nexport enum ESizes {\n XS = "xs",\n SM = "sm",\n MD = "md",\n LG = "lg",\n XL = "xl"\n}\n\nexport type TColor = ( typeof colors )[number];\nexport type TVariant = ( typeof variants )[number];\nexport type TSize = `${ESizes}`;\n\n/**\n * Button component from Astral UI\n */\nexport interface IButtonProps\n extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "css"> {\n /**\n * Size of the button.\n * @default md\n */\n size?: TSize;\n /**\n * Color of the button.\n * @default primary\n */\n color?: TColor;\n /**\n * Variant of the button.\n * @default filled\n */\n variant?: TVariant;\n /**\n * Shows loading animation instead of the button content\n */\n loading?: boolean;\n /**\n * Icon to be displayed before the button\'s content.\n * @description\n * This prop accepts either an IconType (string) or a ReactNode.\n * - If an IconType is provided, it will render an ADPIcon component.\n * - If a ReactNode is provided, it will be rendered as-is.\n */\n prefixIcon?: TIconType | React.ReactNode;\n /**\n * Icon to be displayed after the button\'s content.\n * @description\n * This prop accepts either an IconType (string) or a ReactNode.\n * - If an IconType is provided, it will render an ADPIcon component.\n * - If a ReactNode is provided, it will be rendered as-is.\n */\n suffixIcon?: TIconType | React.ReactNode;\n /**\n * Tooltip to be displayed on hover of the button.\n * @description\n * This prop accepts a ReactNode, if this is passed then the button will render\n * tooltip on hover of the button.\n * This tooltip is only on hover and not on click.\n */\n tooltip?: React.ReactNode;\n /**\n * Placement of the tooltip\n * @default "bottom-end"\n */\n tooltipPlacement?: Placement;\n}\n\n// Map of button size to spinner size\nexport const ButtonSizeToSpinnerMap: Record<\n TSize,\n "xxs" | "xs" | "sm" | "md" | "lg" | "xl"\n> = {\n xs: "xs",\n sm: "xs",\n md: "sm",\n lg: "sm",\n xl: "md"\n};\n\n/**\n * Button component with multiple variants, colors, and sizes.\n *\n * @example\n * ```tsx\n * <Button variant="filled" color="primary" size="md">\n * Click me\n * </Button>\n * ```\n */\nexport const Button = React.forwardRef<HTMLButtonElement, IButtonProps>(\n (\n {\n className,\n variant = "filled",\n color = "primary",\n size = "md",\n children,\n disabled,\n loading = false,\n type = "button",\n prefixIcon,\n suffixIcon,\n tooltip,\n tooltipPlacement,\n ...props\n },\n ref\n ) => {\n // Determine if we should show padded styles based on whether children exist\n const hasChildren = Boolean( children );\n\n const buttonClasses = buttonVariants({\n variant,\n color,\n size,\n hasChildren: hasChildren ? true : undefined,\n class: className\n });\n\n // Create the button element\n const buttonElement = (\n <button\n type={type}\n className={buttonClasses}\n disabled={disabled || loading}\n ref={
|
|
1606
|
+
"content": 'import * as React from "react";\nimport type { Placement } from "@floating-ui/react";\nimport mergeRefs from "react-merge-refs";\n\nimport { Tooltip } from "../tooltip";\nimport { ADPIcon, type TIconType } from "../adpIcon";\nimport { buttonVariants } from "./buttonVariants";\n\nexport const colors = [ "primary", "secondary", "success", "warning", "error" ] as const;\nexport const variants = [ "filled", "outline", "shade", "text" ] as const;\nexport enum ESizes {\n XS = "xs",\n SM = "sm",\n MD = "md",\n LG = "lg",\n XL = "xl"\n}\n\nexport type TColor = ( typeof colors )[number];\nexport type TVariant = ( typeof variants )[number];\nexport type TSize = `${ESizes}`;\n\n/**\n * Button component from Astral UI\n */\nexport interface IButtonProps\n extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "css"> {\n /**\n * Size of the button.\n * @default md\n */\n size?: TSize;\n /**\n * Color of the button.\n * @default primary\n */\n color?: TColor;\n /**\n * Variant of the button.\n * @default filled\n */\n variant?: TVariant;\n /**\n * Shows loading animation instead of the button content\n */\n loading?: boolean;\n /**\n * Icon to be displayed before the button\'s content.\n * @description\n * This prop accepts either an IconType (string) or a ReactNode.\n * - If an IconType is provided, it will render an ADPIcon component.\n * - If a ReactNode is provided, it will be rendered as-is.\n */\n prefixIcon?: TIconType | React.ReactNode;\n /**\n * Icon to be displayed after the button\'s content.\n * @description\n * This prop accepts either an IconType (string) or a ReactNode.\n * - If an IconType is provided, it will render an ADPIcon component.\n * - If a ReactNode is provided, it will be rendered as-is.\n */\n suffixIcon?: TIconType | React.ReactNode;\n /**\n * Tooltip to be displayed on hover of the button.\n * @description\n * This prop accepts a ReactNode, if this is passed then the button will render\n * tooltip on hover of the button.\n * This tooltip is only on hover and not on click.\n * A string tooltip on a button without text also becomes the button\'s `aria-label`, unless\n * `aria-label` or `aria-labelledby` is passed.\n */\n tooltip?: React.ReactNode;\n /**\n * Placement of the tooltip\n * @default "bottom-end"\n */\n tooltipPlacement?: Placement;\n}\n\n/**\n * Whether the element contains text a screen reader reads. Text in aria-hidden subtrees and in SVGs\n * (such as an icon\'s <title>) is not counted.\n */\nconst hasExposedText = ( element: HTMLElement ): boolean => {\n const walker = document.createTreeWalker( element, NodeFilter.SHOW_TEXT );\n for ( let node = walker.nextNode(); node; node = walker.nextNode()) {\n const hiddenAncestor = node.parentElement?.closest( "[aria-hidden=\'true\'], svg" );\n if ( node.textContent?.trim() && !( hiddenAncestor && element.contains( hiddenAncestor ))) {\n return true;\n }\n }\n return false;\n};\n\n// Map of button size to spinner size\nexport const ButtonSizeToSpinnerMap: Record<\n TSize,\n "xxs" | "xs" | "sm" | "md" | "lg" | "xl"\n> = {\n xs: "xs",\n sm: "xs",\n md: "sm",\n lg: "sm",\n xl: "md"\n};\n\n/**\n * Button component with multiple variants, colors, and sizes.\n *\n * @example\n * ```tsx\n * <Button variant="filled" color="primary" size="md">\n * Click me\n * </Button>\n * ```\n */\nexport const Button = React.forwardRef<HTMLButtonElement, IButtonProps>(\n (\n {\n className,\n variant = "filled",\n color = "primary",\n size = "md",\n children,\n disabled,\n loading = false,\n type = "button",\n prefixIcon,\n suffixIcon,\n tooltip,\n tooltipPlacement,\n ...props\n },\n ref\n ) => {\n // Determine if we should show padded styles based on whether children exist\n const hasChildren = Boolean( children );\n\n const namesFromTooltip = typeof tooltip === "string" && tooltip.trim() !== "" && !props["aria-label"] && !props["aria-labelledby"];\n const hasTextChild = React.Children.toArray( children ).some(\n ( child ) => ( typeof child === "string" || typeof child === "number" ) && String( child ).trim() !== ""\n );\n // Element content can render its own text or only an icon, which is only known from the DOM.\n const needsTextCheck = namesFromTooltip && !hasTextChild && React.Children.toArray([ children, prefixIcon, suffixIcon ]).some( React.isValidElement );\n const buttonRef = React.useRef<HTMLButtonElement>( null );\n const mergedRef = React.useMemo(() => mergeRefs([ ref, buttonRef ]), [ref]);\n const [ elementsHaveText, setElementsHaveText ] = React.useState( true );\n\n React.useLayoutEffect(() => {\n if ( needsTextCheck && buttonRef.current ) {\n setElementsHaveText( hasExposedText( buttonRef.current ));\n }\n }, [ needsTextCheck, children, prefixIcon, suffixIcon ]);\n const tooltipName = namesFromTooltip && !hasTextChild && !( needsTextCheck && elementsHaveText ) ? tooltip : undefined;\n\n const buttonClasses = buttonVariants({\n variant,\n color,\n size,\n hasChildren: hasChildren ? true : undefined,\n class: className\n });\n\n // Create the button element\n const buttonElement = (\n <button\n type={type}\n className={buttonClasses}\n disabled={disabled || loading}\n ref={mergedRef}\n {...props}\n aria-label={tooltipName ?? props["aria-label"]}\n >\n {loading ? (\n <ADPIcon icon="spinner" spin size={ButtonSizeToSpinnerMap[size]} />\n ) : (\n prefixIcon && (\n typeof prefixIcon === "string"\n ? <ADPIcon icon={prefixIcon as TIconType} fixedWidth size={ButtonSizeToSpinnerMap[size]} />\n : prefixIcon\n )\n )}\n {children}\n {suffixIcon && (\n typeof suffixIcon === "string"\n ? <ADPIcon icon={suffixIcon as TIconType} fixedWidth size={ButtonSizeToSpinnerMap[size]} />\n : suffixIcon\n )}\n </button>\n );\n\n // If tooltip is present and not null or empty, wrap the button with Tooltip.\n if ( tooltip !== null && tooltip !== undefined && tooltip !== false && tooltip !== "" ) {\n return (\n <Tooltip\n clickable={false}\n trigger={buttonElement}\n placement={tooltipPlacement}\n >\n {tooltip}\n </Tooltip>\n );\n }\n\n // Otherwise, return just the button\n return buttonElement;\n }\n);\n\nButton.displayName = "Button";\n'
|
|
1606
1607
|
},
|
|
1607
1608
|
{
|
|
1608
1609
|
"name": "README.md",
|
|
@@ -2402,7 +2403,7 @@ DropdownItem.displayName = "DropdownItem";
|
|
|
2402
2403
|
},
|
|
2403
2404
|
"modal": {
|
|
2404
2405
|
"name": "modal",
|
|
2405
|
-
"description": "The Modal component creates a dialog overlay that appears above the page content using React Portal, requiring user interaction before returning to the main interface. It uses a compound component pattern with Header and Body subcomponents. **When to use:** - Confirmation dialogs that require user decisions - Forms that need focused attention without navigation - Alert messages and important notifications - Displaying detailed information without leaving the current page - Multi-step workflows that require isolation **Component Architecture:** - Built with React compound component pattern (Modal.Header, Modal.Body) - Rendered via React Portal for proper z-index layering - Uses react-focus-on for focus management and accessibility - Styled with Tailwind CSS and
|
|
2406
|
+
"description": "The Modal component creates a dialog overlay that appears above the page content using React Portal, requiring user interaction before returning to the main interface. It uses a compound component pattern with Header, Title and Body subcomponents. **When to use:** - Confirmation dialogs that require user decisions - Forms that need focused attention without navigation - Alert messages and important notifications - Displaying detailed information without leaving the current page - Multi-step workflows that require isolation **Component Architecture:** - Built with React compound component pattern (Modal.Header, Modal.Title, Modal.Body) - Rendered via React Portal for proper z-index layering - Uses react-focus-on for focus management and accessibility - Styled with Tailwind CSS and tailwind-variants (`modalVariants`) - Supports ESC key to close and focus trapping - Optional close button and RTL support",
|
|
2406
2407
|
"dependencies": [
|
|
2407
2408
|
"tailwind-variants",
|
|
2408
2409
|
"react",
|
|
@@ -2417,19 +2418,79 @@ DropdownItem.displayName = "DropdownItem";
|
|
|
2417
2418
|
"files": [
|
|
2418
2419
|
{
|
|
2419
2420
|
"name": "modalVariants.ts",
|
|
2420
|
-
"content": 'import { tv } from "tailwind-variants";\n\nexport const modalVariants = tv({\n slots: {\n container: [\n "justify-center items-center flex overflow-x-hidden overflow-y-auto fixed inset-0 outline-none focus:outline-none",\n "z-[2000] bg-secondary-100/50"\n ],\n modal: [\n "rounded shadow-md max-w-[calc(100vw-2.5rem)] max-h-[calc(100vh-2.5rem)]",\n "p-6 overflow-hidden relative font-regular flex flex-col outline-none",\n "bg-white dark:bg-iridium dark:border dark:border-secondary-500"\n ]\n },\n variants: {\n headerless: {\n true: { modal: "pt-9" }\n }\n
|
|
2421
|
+
"content": 'import { tv } from "tailwind-variants";\n\nexport const modalVariants = tv({\n slots: {\n container: [\n "justify-center items-center flex overflow-x-hidden overflow-y-auto fixed inset-0 outline-none focus:outline-none",\n "z-[2000] bg-secondary-100/50"\n ],\n modal: [\n "rounded shadow-md max-w-[calc(100vw-2.5rem)] max-h-[calc(100vh-2.5rem)]",\n "p-6 overflow-hidden relative font-regular flex flex-col outline-none",\n "bg-white dark:bg-iridium dark:border dark:border-secondary-500"\n ],\n header: "flex flex-row flex-nowrap justify-between text-lg font-semibold text-secondary-500 dark:text-secondary-50",\n title: "text-lg font-semibold text-secondary-500 dark:text-secondary-50"\n },\n variants: {\n headerless: {\n true: {}\n },\n // The built-in close button is absolutely positioned at the top end corner, so the header keeps\n // clear of it, and a modal without a header gets extra top padding to make room for it.\n closeButton: {\n true: { header: "me-7" }\n }\n },\n compoundVariants: [\n {\n headerless: true,\n closeButton: true,\n class: { modal: "pt-9" }\n }\n ],\n defaultVariants: {\n headerless: false,\n closeButton: true\n }\n});\n'
|
|
2422
|
+
},
|
|
2423
|
+
{
|
|
2424
|
+
"name": "modalTitle.tsx",
|
|
2425
|
+
"content": 'import * as React from "react";\n\nimport { usePartRegistration } from "@hooks";\n\nimport { modalVariants } from "./modalVariants";\nimport { ModalBodyContext, ModalContext } from "./modalContext";\n\nexport interface IModalTitleProps {\n /**\n * Title text of the Modal\n */\n children?: React.ReactNode;\n /**\n * Dynamically updates the classes applied to the component\n */\n className?: string;\n}\n\n/**\n * Modal title component. It is the dialog\'s heading and names the dialog, so the header\'s actions stay\n * out of the name. Place it inside Modal.Header, or in Modal.Body for dialogs that show the title there.\n *\n * @example\n * ```tsx\n * <Modal.Title>Modal Title</Modal.Title>\n * ```\n */\nexport const ModalTitle = React.forwardRef<HTMLHeadingElement, IModalTitleProps>(({ children, className }, ref ) => {\n const context = React.useContext( ModalContext );\n const inBody = React.useContext( ModalBodyContext );\n usePartRegistration( context?.setTitleMounted, Boolean( children ));\n usePartRegistration( context?.setTitleInBodyMounted, inBody && Boolean( children ));\n if ( !children ) {\n return null;\n }\n const { title } = modalVariants();\n return (\n <h2 ref={ref} id={context?.labelId} data-testid="modal-title" className={title({ class: className })}>\n {children}\n </h2>\n );\n});\n\nModalTitle.displayName = "ModalTitle";\n'
|
|
2426
|
+
},
|
|
2427
|
+
{
|
|
2428
|
+
"name": "modalContext.ts",
|
|
2429
|
+
"content": `import * as React from "react";
|
|
2430
|
+
|
|
2431
|
+
import { devWarn } from "@utils";
|
|
2432
|
+
|
|
2433
|
+
export interface IModalContext {
|
|
2434
|
+
labelId: string;
|
|
2435
|
+
descId: string;
|
|
2436
|
+
closeButton: boolean;
|
|
2437
|
+
titleRendered: boolean;
|
|
2438
|
+
setHeaderMounted: ( mounted: boolean ) => void;
|
|
2439
|
+
setTitleMounted: ( mounted: boolean ) => void;
|
|
2440
|
+
setTitleInBodyMounted: ( mounted: boolean ) => void;
|
|
2441
|
+
setBodyMounted: ( mounted: boolean ) => void;
|
|
2442
|
+
}
|
|
2443
|
+
|
|
2444
|
+
export const ModalContext = React.createContext<IModalContext | null>( null );
|
|
2445
|
+
|
|
2446
|
+
/**
|
|
2447
|
+
* True inside Modal.Body. A Modal.Title there would otherwise be both the dialog's name and part of its
|
|
2448
|
+
* description, which describes the dialog with the whole body.
|
|
2449
|
+
*/
|
|
2450
|
+
export const ModalBodyContext = React.createContext( false );
|
|
2451
|
+
|
|
2452
|
+
const FOCUSABLE_SELECTOR = "a[href], button, input, select, textarea, [tabindex]:not([tabindex='-1']), [contenteditable='true']";
|
|
2453
|
+
|
|
2454
|
+
/**
|
|
2455
|
+
* Development warnings for a dialog with no accessible name, and for a heading that contains controls,
|
|
2456
|
+
* which then become part of the heading and of the dialog's name. Warns once per Modal instance.
|
|
2457
|
+
*/
|
|
2458
|
+
export function useModalNameWarnings( dialog: HTMLElement | null, labelId: string, named: boolean, titleRendered: boolean ): void {
|
|
2459
|
+
const warnedUnnamed = React.useRef( false );
|
|
2460
|
+
const warnedControls = React.useRef( false );
|
|
2461
|
+
|
|
2462
|
+
React.useEffect(() => {
|
|
2463
|
+
if ( !dialog ) {
|
|
2464
|
+
return undefined;
|
|
2465
|
+
}
|
|
2466
|
+
// Parts register in layout effects, which re-render the dialog with their ids before the next task.
|
|
2467
|
+
const timer = setTimeout(() => {
|
|
2468
|
+
if ( !named && !warnedUnnamed.current ) {
|
|
2469
|
+
warnedUnnamed.current = true;
|
|
2470
|
+
devWarn( "Modal: the dialog has no accessible name. Render a Modal.Header or Modal.Title, or pass aria-label or aria-labelledby to Modal." );
|
|
2471
|
+
}
|
|
2472
|
+
const heading = document.getElementById( labelId );
|
|
2473
|
+
if ( heading && dialog.contains( heading ) && heading.querySelector( FOCUSABLE_SELECTOR ) && !warnedControls.current ) {
|
|
2474
|
+
warnedControls.current = true;
|
|
2475
|
+
devWarn( "Modal: the heading contains interactive elements, which become part of its accessible name. Wrap the title text in Modal.Title." );
|
|
2476
|
+
}
|
|
2477
|
+
});
|
|
2478
|
+
return () => clearTimeout( timer );
|
|
2479
|
+
}, [ dialog, labelId, named, titleRendered ]);
|
|
2480
|
+
}
|
|
2481
|
+
`
|
|
2421
2482
|
},
|
|
2422
2483
|
{
|
|
2423
2484
|
"name": "modal.tsx",
|
|
2424
|
-
"content": 'import * as React from "react";\nimport ReactDOM from "react-dom";\nimport { FocusOn } from "react-focus-on";\nimport mergeRefs from "react-merge-refs";\nimport { cn } from "tailwind-variants";\nimport { Button } from "../button";\nimport { modalVariants } from "./modalVariants";\n\nexport interface IModalProps {\n /**\n * Control modal\'s visibility\n */\n showModal: boolean;\n /**\n * Modal content\n */\n children:\n | React.ReactElement<IModalHeaderProps>\n | [React.ReactElement<IModalHeaderProps>, React.ReactElement<IModalBodyProps>];\n /**\n * Overwrite the Modal styles by passing space separated class names\n */\n className?: string;\n /**\n * Sets the modal content to right-to-left\n */\n rtl?: boolean;\n /**\n * Hide the modal on esc key press\n * @default true\n */\n escKeyClose?: boolean;\n /**\n * Show/hide the close button within the modal\n * @default true\n */\n closeButton?: boolean;\n /**\n * Pass a reference to the element where the Modal needs to be rendered\n * @default document.body\n */\n portalTarget?: HTMLElement;\n /**\n * A list of Refs to be considered as a part of the Lock. The html elements in the list will be accessible while the Modal is open.\n */\n shards?: ( HTMLElement | React.RefObject<any> )[];\n /**\n * Callback function for onHide\n */\n onHide?: () => void;\n /**\n * Accessible name for the dialog. Takes precedence over the name derived from Modal.Header, so use it\n * when the header holds no title text (an icon, a search input) or when no header is rendered.\n */\n "aria-label"?: string;\n}\n\nexport interface IModalHeaderProps {\n /**\n * Header of the Modal\n */\n children?: React.ReactNode;\n /**\n * Dynamically updates the classes applied to the component\n */\n className?: string;\n}\n\nexport interface IModalBodyProps {\n /**\n * Modal Body\n */\n children?: React.ReactNode;\n /**\n * Dynamically updates the classes applied to the component\n */\n className?: string;\n /**\n * Accessible name for the body while its content overflows and it becomes a focusable scroll region\n * @default "Scrollable content"\n */\n "aria-label"?: string;\n /**\n * Reserves a 4px gutter (padding offset by negative margins) so focus rings on controls at the body\'s\n * edges stay visible while it scrolls. A body that fits its content never clips, so this is only\n * needed for long, scrolling content. It interacts with width, padding and margin overrides.\n * @default false\n */\n gutter?: boolean;\n}\n\ninterface IModalBodyMetrics {\n overflowsX: boolean;\n overflowsY: boolean;\n overflowY: string;\n}\n\n// scrollHeight/scrollWidth and clientHeight/clientWidth round independently, so content that fits can read 1px over.\nconst OVERFLOW_TOLERANCE = 1;\n\n// Matches a consumer class that forces overflow-y (or both axes) to anything but visible, with or without variants.\nconst FORCED_OVERFLOW_Y = /(?:^|\\s)(?:\\S+:)?!?overflow-(?:y-)?(?:auto|scroll|hidden|clip)(?=\\s|$)/;\n\ninterface IModalContext {\n labelId: string;\n descId: string;\n setHeaderMounted: ( mounted: boolean ) => void;\n setBodyMounted: ( mounted: boolean ) => void;\n}\n\nconst ModalContext = React.createContext<IModalContext | null>( null );\n\n/**\n * Tells the parent Modal whether this part is rendering content, so the dialog\'s aria-labelledby and\n * aria-describedby only reference ids that exist. Registering from the part, rather than scanning\n * Modal\'s children, also finds parts nested in fragments or wrapper components.\n */\nfunction useModalPartRegistration( register: (( mounted: boolean ) => void ) | undefined, hasContent: boolean ): void {\n React.useLayoutEffect(() => {\n if ( !register || !hasContent ) {\n return undefined;\n }\n register( true );\n return () => register( false );\n }, [ register, hasContent ]);\n}\n\n// Compound component type with subcomponents attached\ntype TModalCompoundComponent = React.ForwardRefExoticComponent<\n React.PropsWithoutRef<IModalProps> & React.RefAttributes<HTMLDivElement>\n> & {\n Header: typeof ModalHeader;\n Body: typeof ModalBody;\n};\n\n/**\n * Modal component for displaying content in an overlay with optional header and close button.\n *\n * @example\n * ```tsx\n * <Modal showModal={modalVisible} onHide={() => setModalVisible(false)}>\n * <Modal.Header>Modal Title</Modal.Header>\n * <Modal.Body>Modal content goes here</Modal.Body>\n * </Modal>\n * ```\n */\nexport const Modal = React.forwardRef<HTMLDivElement, IModalProps>(\n (\n {\n showModal,\n onHide,\n closeButton = true,\n escKeyClose = true,\n rtl = false,\n portalTarget = typeof document !== "undefined" ? document.body : undefined,\n shards,\n className,\n children,\n "aria-label": ariaLabel\n },\n ref\n ) => {\n const [ headerRendered, setHeaderMounted ] = React.useState( false );\n const [ bodyRendered, setBodyMounted ] = React.useState( false );\n const instanceId = React.useId();\n const contextValue = React.useMemo(() => ({\n labelId: `${instanceId}-label`,\n descId: `${instanceId}-desc`,\n setHeaderMounted,\n setBodyMounted\n }), [instanceId]);\n\n const { container, modal } = modalVariants({ headerless: !headerRendered });\n\n const closeModal = React.useCallback(() => {\n if ( onHide ) {\n onHide();\n }\n }, [onHide]);\n\n React.useEffect(() => {\n const handleEsc = ( e: KeyboardEvent ) => {\n if ( e.code === "Escape" && escKeyClose ) {\n closeModal();\n }\n };\n\n if ( showModal ) {\n document.addEventListener( "keydown", handleEsc );\n }\n\n return () => {\n document.removeEventListener( "keydown", handleEsc );\n };\n }, [ showModal, escKeyClose, closeModal ]);\n\n if ( !showModal || !portalTarget ) {\n return null;\n }\n\n return ReactDOM.createPortal(\n <FocusOn\n enabled={showModal}\n shards={shards}\n {...( rtl ? { dir: "rtl" } : {})}\n className={container()}\n >\n <div\n ref={ref}\n data-testid="modal"\n className={modal({ class: className })}\n role="dialog"\n aria-modal="true"\n aria-label={ariaLabel}\n aria-labelledby={headerRendered && !ariaLabel ? contextValue.labelId : undefined}\n aria-describedby={bodyRendered ? contextValue.descId : undefined}\n tabIndex={-1}\n >\n {closeButton && (\n <Button\n prefixIcon="cross"\n onClick={closeModal}\n data-testid="close-button"\n variant="text"\n color="secondary"\n aria-label="close modal"\n className="absolute top-4 end-4 text-gray-900 dark:text-gray-800 dark:hover:text-gray-800"\n autoFocus\n />\n )}\n <ModalContext.Provider value={contextValue}>\n {children}\n </ModalContext.Provider>\n </div>\n </FocusOn>,\n portalTarget\n );\n }\n) as TModalCompoundComponent;\n\nModal.displayName = "Modal";\n\n/**\n * Modal header component for rendering the title in the Modal.\n *\n * @example\n * ```tsx\n * <Modal.Header>Modal Title</Modal.Header>\n * ```\n */\nconst ModalHeader = React.forwardRef<\n HTMLDivElement,\n IModalHeaderProps\n>(({ children, className }, ref ) => {\n const context = React.useContext( ModalContext );\n useModalPartRegistration( context?.setHeaderMounted, Boolean( children ));\n if ( !children ) {\n return null;\n }\n // role="heading" instead of <h2> so consumers can pass block content (divs, nested markup)\n return (\n <div\n ref={ref}\n id={context?.labelId}\n role="heading"\n aria-level={2}\n data-testid="modal-header"\n className={cn(\n "flex flex-row flex-nowrap justify-between text-lg font-semibold me-7 text-secondary-500 dark:text-secondary-50",\n className\n )}\n >\n {children}\n </div>\n );\n});\n\nModalHeader.displayName = "ModalHeader";\n\n/**\n * Modal body component for rendering content inside the Modal.\n *\n * The body only becomes a scroll container once its content overflows, because a scroll container\n * clips focus rings and shadows at its edges. Pass `gutter` to keep edge focus rings visible while\n * it scrolls.\n *\n * @example\n * ```tsx\n * <Modal.Body>Modal content goes here</Modal.Body>\n * ```\n */\nconst ModalBody = React.forwardRef<HTMLDivElement, IModalBodyProps>(\n ({ children, className, "aria-label": ariaLabel = "Scrollable content", gutter = false }, ref ) => {\n const context = React.useContext( ModalContext );\n const [ bodyElement, setBodyElement ] = React.useState<HTMLDivElement | null>( null );\n const mergedRef = React.useMemo(() => mergeRefs([ ref, setBodyElement ]), [ref]);\n const [ metrics, setMetrics ] = React.useState<IModalBodyMetrics>({ overflowsX: false, overflowsY: false, overflowY: "visible" });\n useModalPartRegistration( context?.setBodyMounted, Boolean( children ));\n\n const measure = React.useCallback(() => {\n if ( !bodyElement ) {\n return;\n }\n const next = {\n overflowsX: bodyElement.scrollWidth > bodyElement.clientWidth + OVERFLOW_TOLERANCE,\n overflowsY: bodyElement.scrollHeight > bodyElement.clientHeight + OVERFLOW_TOLERANCE,\n overflowY: getComputedStyle( bodyElement ).overflowY\n };\n setMetrics(( prev ) => (\n prev.overflowsX === next.overflowsX && prev.overflowsY === next.overflowsY && prev.overflowY === next.overflowY\n ? prev\n : next\n ));\n }, [bodyElement]);\n\n const { overflowsX, overflowsY, overflowY } = metrics;\n // Wide content is clipped at the body\'s edge, which requires a scroll container on both axes.\n const isScrollContainer = overflowsX || overflowsY;\n\n // The overflow classes depend on these metrics, so re-read them once the classes they produce are applied.\n React.useLayoutEffect( measure, [ measure, isScrollContainer, className ]);\n\n React.useLayoutEffect(() => {\n if ( !bodyElement || typeof window.ResizeObserver === "undefined" ) {\n return undefined;\n }\n let frame = 0;\n // Mutations and resizes arrive in bursts; coalesce them into one layout read per frame.\n const scheduleMeasure = () => {\n if ( !frame ) {\n frame = requestAnimationFrame(() => {\n frame = 0;\n measure();\n });\n }\n };\n const resizeObserver = new ResizeObserver( scheduleMeasure );\n const mutationObserver = new MutationObserver( scheduleMeasure );\n resizeObserver.observe( bodyElement );\n mutationObserver.observe( bodyElement, { childList: true, subtree: true, characterData: true });\n return () => {\n cancelAnimationFrame( frame );\n resizeObserver.disconnect();\n mutationObserver.disconnect();\n };\n }, [ bodyElement, measure ]);\n\n const isScrollable = overflowsY && overflowY !== "hidden" && overflowY !== "clip";\n // Read from the class list, not computed style: the body\'s own overflow-x-hidden turns a visible y axis into auto.\n const consumerForcesOverflowY = FORCED_OVERFLOW_Y.test( className ?? "" );\n // While the content fits, overflow stays visible so nothing is clipped. A consumer class that forces\n // overflow-y still makes the body a scroll container, so its x axis stays hidden as it always was.\n const overflowClasses = isScrollContainer\n ? "overflow-y-auto overflow-x-hidden"\n : cn( "overflow-y-visible", consumerForcesOverflowY ? "overflow-x-hidden" : "overflow-x-visible" );\n\n if ( !children ) {\n return null;\n }\n return (\n <div\n ref={mergedRef}\n id={context?.descId}\n data-testid="modal-content"\n className={cn(\n "text-base text-wrap mt-2 max-h-[84vh] min-h-0 dark:text-secondary-200",\n overflowClasses,\n gutter && "mt-1 -mx-1 -mb-1 p-1",\n "outline-none focus-visible:ring focus-visible:ring-gray-800 dark:focus-visible:ring-secondary-50",\n className\n )}\n {...( isScrollable\n ? { tabIndex: 0, role: "group", "aria-label": ariaLabel }\n : {})}\n >\n {children}\n </div>\n );\n }\n);\n\nModalBody.displayName = "ModalBody";\n\n// Attach the subcomponents\nModal.Header = ModalHeader;\nModal.Body = ModalBody;\n\n// Export the individual subcomponents\nexport { ModalHeader, ModalBody };\n'
|
|
2485
|
+
"content": 'import * as React from "react";\nimport ReactDOM from "react-dom";\nimport { FocusOn } from "react-focus-on";\nimport mergeRefs from "react-merge-refs";\nimport { cn } from "tailwind-variants";\n\nimport { usePartPresence, usePartRegistration } from "@hooks";\n\nimport { Button } from "../button";\nimport { modalVariants } from "./modalVariants";\nimport { ModalBodyContext, ModalContext, useModalNameWarnings } from "./modalContext";\nimport { ModalTitle, type IModalTitleProps } from "./modalTitle";\n\nexport interface IModalProps {\n /**\n * Control modal\'s visibility\n */\n showModal: boolean;\n /**\n * Modal content\n */\n children:\n | React.ReactElement<IModalHeaderProps>\n | [React.ReactElement<IModalHeaderProps>, React.ReactElement<IModalBodyProps>];\n /**\n * Overwrite the Modal styles by passing space separated class names\n */\n className?: string;\n /**\n * Sets the modal content to right-to-left\n */\n rtl?: boolean;\n /**\n * Hide the modal on esc key press\n * @default true\n */\n escKeyClose?: boolean;\n /**\n * Show/hide the close button within the modal\n * @default true\n */\n closeButton?: boolean;\n /**\n * Pass a reference to the element where the Modal needs to be rendered\n * @default document.body\n */\n portalTarget?: HTMLElement;\n /**\n * A list of Refs to be considered as a part of the Lock. The html elements in the list will be accessible while the Modal is open.\n */\n shards?: ( HTMLElement | React.RefObject<any> )[];\n /**\n * Callback function for onHide\n */\n onHide?: () => void;\n /**\n * Accessible name for the dialog. Takes precedence over the name derived from Modal.Title or Modal.Header,\n * so use it when the header holds no title text (an icon, a search input) or when no header is rendered.\n */\n "aria-label"?: string;\n /**\n * Id of the element that names the dialog. Takes precedence over Modal.Title, Modal.Header and `aria-label`.\n */\n "aria-labelledby"?: string;\n /**\n * Id of the element that describes the dialog, or `false` for no description.\n * @default the id of the rendered Modal.Body, unless it contains the Modal.Title\n */\n "aria-describedby"?: string | false;\n /**\n * Accessible name of the built-in close button\n * @default "Close"\n */\n closeButtonLabel?: string;\n}\n\nexport interface IModalHeaderProps {\n /**\n * Header of the Modal\n */\n children?: React.ReactNode;\n /**\n * Dynamically updates the classes applied to the component\n */\n className?: string;\n}\n\nexport interface IModalBodyProps {\n /**\n * Modal Body\n */\n children?: React.ReactNode;\n /**\n * Dynamically updates the classes applied to the component\n */\n className?: string;\n /**\n * Accessible name for the body while its content overflows and it becomes a focusable scroll region\n * @default "Scrollable content"\n */\n "aria-label"?: string;\n /**\n * Reserves a 4px gutter (padding offset by negative margins) so focus rings on controls at the body\'s\n * edges stay visible while it scrolls. A body that fits its content never clips, so this is only\n * needed for long, scrolling content. It interacts with width, padding and margin overrides.\n * @default false\n */\n gutter?: boolean;\n}\n\ninterface IModalBodyMetrics {\n overflowsX: boolean;\n overflowsY: boolean;\n overflowY: string;\n}\n\n// scrollHeight/scrollWidth and clientHeight/clientWidth round independently, so content that fits can read 1px over.\nconst OVERFLOW_TOLERANCE = 1;\n\n// Matches a consumer class that forces overflow-y (or both axes) to anything but visible, with or without variants.\nconst FORCED_OVERFLOW_Y = /(?:^|\\s)(?:\\S+:)?!?overflow-(?:y-)?(?:auto|scroll|hidden|clip)(?=\\s|$)/;\n\n// Compound component type with subcomponents attached\ntype TModalCompoundComponent = React.ForwardRefExoticComponent<\n React.PropsWithoutRef<IModalProps> & React.RefAttributes<HTMLDivElement>\n> & {\n Header: typeof ModalHeader;\n Title: typeof ModalTitle;\n Body: typeof ModalBody;\n};\n\n/**\n * Modal component for displaying content in an overlay with optional header and close button.\n *\n * @example\n * ```tsx\n * <Modal showModal={modalVisible} onHide={() => setModalVisible(false)}>\n * <Modal.Header>\n * <Modal.Title>Modal Title</Modal.Title>\n * </Modal.Header>\n * <Modal.Body>Modal content goes here</Modal.Body>\n * </Modal>\n * ```\n */\nexport const Modal = React.forwardRef<HTMLDivElement, IModalProps>(\n (\n {\n showModal,\n onHide,\n closeButton = true,\n escKeyClose = true,\n rtl = false,\n portalTarget = typeof document !== "undefined" ? document.body : undefined,\n shards,\n className,\n children,\n closeButtonLabel = "Close",\n "aria-label": ariaLabel,\n "aria-labelledby": ariaLabelledBy,\n "aria-describedby": ariaDescribedBy\n },\n ref\n ) => {\n const [ headerRendered, setHeaderMounted ] = usePartPresence();\n const [ titleRendered, setTitleMounted ] = usePartPresence();\n const [ titleInBody, setTitleInBodyMounted ] = usePartPresence();\n const [ bodyRendered, setBodyMounted ] = usePartPresence();\n const [ dialogElement, setDialogElement ] = React.useState<HTMLDivElement | null>( null );\n const mergedRef = React.useMemo(() => mergeRefs([ ref, setDialogElement ]), [ref]);\n const instanceId = React.useId();\n const contextValue = React.useMemo(() => ({\n labelId: `${instanceId}-label`,\n descId: `${instanceId}-desc`,\n closeButton,\n titleRendered,\n setHeaderMounted,\n setTitleMounted,\n setTitleInBodyMounted,\n setBodyMounted\n }), [ instanceId, closeButton, titleRendered, setHeaderMounted, setTitleMounted, setTitleInBodyMounted, setBodyMounted ]);\n\n const { container, modal } = modalVariants({ headerless: !headerRendered, closeButton });\n\n const labelledBy = ariaLabelledBy ?? (( headerRendered || titleRendered ) && !ariaLabel ? contextValue.labelId : undefined );\n // A title inside the body would be read again as part of the description, so that body describes nothing by default.\n const defaultDescribedBy = bodyRendered && !titleInBody ? contextValue.descId : undefined;\n const describedBy = ariaDescribedBy === false ? undefined : ariaDescribedBy ?? defaultDescribedBy;\n useModalNameWarnings( dialogElement, contextValue.labelId, Boolean( ariaLabel || labelledBy ), titleRendered );\n\n const closeModal = React.useCallback(() => {\n if ( onHide ) {\n onHide();\n }\n }, [onHide]);\n\n // Events from a portal bubble to the React ancestors of <Modal>, such as the control that opened it.\n const handleCloseClick = React.useCallback(( event: React.MouseEvent ) => {\n event.stopPropagation();\n closeModal();\n }, [closeModal]);\n\n React.useEffect(() => {\n const handleEsc = ( e: KeyboardEvent ) => {\n if ( e.code === "Escape" && escKeyClose ) {\n closeModal();\n }\n };\n\n if ( showModal ) {\n document.addEventListener( "keydown", handleEsc );\n }\n\n return () => {\n document.removeEventListener( "keydown", handleEsc );\n };\n }, [ showModal, escKeyClose, closeModal ]);\n\n if ( !showModal || !portalTarget ) {\n return null;\n }\n\n return ReactDOM.createPortal(\n <FocusOn\n enabled={showModal}\n shards={shards}\n {...( rtl ? { dir: "rtl" } : {})}\n className={container()}\n >\n <div\n ref={mergedRef}\n data-testid="modal"\n className={modal({ class: className })}\n role="dialog"\n aria-modal="true"\n aria-label={ariaLabel}\n aria-labelledby={labelledBy}\n aria-describedby={describedBy}\n tabIndex={-1}\n >\n {closeButton && (\n <Button\n prefixIcon="cross"\n onClick={handleCloseClick}\n data-testid="close-button"\n variant="text"\n color="secondary"\n aria-label={closeButtonLabel}\n className="absolute top-4 end-4 text-gray-900 dark:text-gray-800 dark:hover:text-gray-800"\n />\n )}\n <ModalContext.Provider value={contextValue}>\n {children}\n </ModalContext.Provider>\n </div>\n </FocusOn>,\n portalTarget\n );\n }\n) as TModalCompoundComponent;\n\nModal.displayName = "Modal";\n\n/**\n * Modal header component. With a Modal.Title inside, it is a layout row for the title and any actions;\n * without one, the whole header is the dialog\'s heading and name.\n *\n * @example\n * ```tsx\n * <Modal.Header>\n * <Modal.Title>Modal Title</Modal.Title>\n * <Button aria-label="Download" prefixIcon="download" />\n * </Modal.Header>\n * ```\n */\nconst ModalHeader = React.forwardRef<\n HTMLDivElement,\n IModalHeaderProps\n>(({ children, className }, ref ) => {\n const context = React.useContext( ModalContext );\n usePartRegistration( context?.setHeaderMounted, Boolean( children ));\n if ( !children ) {\n return null;\n }\n const { header } = modalVariants({ closeButton: context?.closeButton ?? true });\n // role="heading" instead of <h2> so consumers can pass block content (divs, nested markup)\n const headingProps = context?.titleRendered\n ? {}\n : { id: context?.labelId, role: "heading", "aria-level": 2 };\n return (\n <div\n ref={ref}\n {...headingProps}\n data-testid="modal-header"\n className={header({ class: className })}\n >\n {children}\n </div>\n );\n});\n\nModalHeader.displayName = "ModalHeader";\n\n/**\n * Modal body component for rendering content inside the Modal.\n *\n * The body only becomes a scroll container once its content overflows, because a scroll container\n * clips focus rings and shadows at its edges. Pass `gutter` to keep edge focus rings visible while\n * it scrolls.\n *\n * @example\n * ```tsx\n * <Modal.Body>Modal content goes here</Modal.Body>\n * ```\n */\nconst ModalBody = React.forwardRef<HTMLDivElement, IModalBodyProps>(\n ({ children, className, "aria-label": ariaLabel = "Scrollable content", gutter = false }, ref ) => {\n const context = React.useContext( ModalContext );\n const [ bodyElement, setBodyElement ] = React.useState<HTMLDivElement | null>( null );\n const mergedRef = React.useMemo(() => mergeRefs([ ref, setBodyElement ]), [ref]);\n const [ metrics, setMetrics ] = React.useState<IModalBodyMetrics>({ overflowsX: false, overflowsY: false, overflowY: "visible" });\n usePartRegistration( context?.setBodyMounted, Boolean( children ));\n\n const measure = React.useCallback(() => {\n if ( !bodyElement ) {\n return;\n }\n const next = {\n overflowsX: bodyElement.scrollWidth > bodyElement.clientWidth + OVERFLOW_TOLERANCE,\n overflowsY: bodyElement.scrollHeight > bodyElement.clientHeight + OVERFLOW_TOLERANCE,\n overflowY: getComputedStyle( bodyElement ).overflowY\n };\n setMetrics(( prev ) => (\n prev.overflowsX === next.overflowsX && prev.overflowsY === next.overflowsY && prev.overflowY === next.overflowY\n ? prev\n : next\n ));\n }, [bodyElement]);\n\n const { overflowsX, overflowsY, overflowY } = metrics;\n // Wide content is clipped at the body\'s edge, which requires a scroll container on both axes.\n const isScrollContainer = overflowsX || overflowsY;\n\n // The overflow classes depend on these metrics, so re-read them once the classes they produce are applied.\n React.useLayoutEffect( measure, [ measure, isScrollContainer, className ]);\n\n React.useLayoutEffect(() => {\n if ( !bodyElement || typeof window.ResizeObserver === "undefined" ) {\n return undefined;\n }\n let frame = 0;\n // Mutations and resizes arrive in bursts; coalesce them into one layout read per frame.\n const scheduleMeasure = () => {\n if ( !frame ) {\n frame = requestAnimationFrame(() => {\n frame = 0;\n measure();\n });\n }\n };\n const resizeObserver = new ResizeObserver( scheduleMeasure );\n const mutationObserver = new MutationObserver( scheduleMeasure );\n resizeObserver.observe( bodyElement );\n mutationObserver.observe( bodyElement, { childList: true, subtree: true, characterData: true });\n return () => {\n cancelAnimationFrame( frame );\n resizeObserver.disconnect();\n mutationObserver.disconnect();\n };\n }, [ bodyElement, measure ]);\n\n const isScrollable = overflowsY && overflowY !== "hidden" && overflowY !== "clip";\n // Read from the class list, not computed style: the body\'s own overflow-x-hidden turns a visible y axis into auto.\n const consumerForcesOverflowY = FORCED_OVERFLOW_Y.test( className ?? "" );\n // While the content fits, overflow stays visible so nothing is clipped. A consumer class that forces\n // overflow-y still makes the body a scroll container, so its x axis stays hidden as it always was.\n const overflowClasses = isScrollContainer\n ? "overflow-y-auto overflow-x-hidden"\n : cn( "overflow-y-visible", consumerForcesOverflowY ? "overflow-x-hidden" : "overflow-x-visible" );\n\n if ( !children ) {\n return null;\n }\n return (\n <div\n ref={mergedRef}\n id={context?.descId}\n data-testid="modal-content"\n className={cn(\n "text-base text-wrap mt-2 max-h-[84vh] min-h-0 dark:text-secondary-200",\n overflowClasses,\n gutter && "mt-1 -mx-1 -mb-1 p-1",\n "outline-none focus-visible:ring focus-visible:ring-gray-800 dark:focus-visible:ring-secondary-50",\n className\n )}\n {...( isScrollable\n ? { tabIndex: 0, role: "group", "aria-label": ariaLabel }\n : {})}\n >\n <ModalBodyContext.Provider value={true}>\n {children}\n </ModalBodyContext.Provider>\n </div>\n );\n }\n);\n\nModalBody.displayName = "ModalBody";\n\n// Attach the subcomponents\nModal.Header = ModalHeader;\nModal.Title = ModalTitle;\nModal.Body = ModalBody;\n\n// Export the individual subcomponents\nexport { ModalHeader, ModalTitle, ModalBody };\nexport type { IModalTitleProps };\n'
|
|
2425
2486
|
},
|
|
2426
2487
|
{
|
|
2427
2488
|
"name": "index.ts",
|
|
2428
|
-
"content": 'export {\n Modal,\n ModalHeader,\n ModalBody,\n type IModalProps,\n type IModalHeaderProps,\n type IModalBodyProps\n} from "./modal";\n\nexport { modalVariants } from "./modalVariants"
|
|
2489
|
+
"content": 'export {\n Modal,\n ModalHeader,\n ModalTitle,\n ModalBody,\n type IModalProps,\n type IModalHeaderProps,\n type IModalTitleProps,\n type IModalBodyProps\n} from "./modal";\n\nexport { modalVariants } from "./modalVariants";\n'
|
|
2429
2490
|
},
|
|
2430
2491
|
{
|
|
2431
2492
|
"name": "README.md",
|
|
2432
|
-
"content": '# Modal Component\n\n## Component Overview\n\nThe Modal component creates a dialog overlay that appears above the page content using React Portal, requiring user interaction before returning to the main interface. It uses a compound component pattern with Header and Body subcomponents.\n\n**When to use:**\n- Confirmation dialogs that require user decisions\n- Forms that need focused attention without navigation\n- Alert messages and important notifications\n- Displaying detailed information without leaving the current page\n- Multi-step workflows that require isolation\n\n**Component Architecture:**\n- Built with React compound component pattern (Modal.Header, Modal.Body)\n- Rendered via React Portal for proper z-index layering\n- Uses react-focus-on for focus management and accessibility\n- Styled with Tailwind CSS and class-variance-authority (cva)\n- Supports ESC key to close and focus trapping\n- Optional close button and RTL support\n\n## Basic Usage\n\n```tsx\nimport { Modal } from "@components";\nimport { Button } from "@components";\nimport { useState } from "react";\n\nexport function Example() {\n const [showModal, setShowModal] = useState(false);\n \n return (\n <>\n <Button onClick={() => setShowModal(true)}>Open Modal</Button>\n \n <Modal showModal={showModal} onHide={() => setShowModal(false)}>\n <Modal.Header>Example Modal</Modal.Header>\n <Modal.Body>\n <p>Modal content goes here.</p>\n </Modal.Body>\n </Modal>\n </>\n );\n}\n```\n\n**Note:** Update the import path based on your project structure. If you used the Astral UI CLI, the typical import path would be `@components/ui/modal` or `@components/modal`.\n\n## Component Props\n\n### Modal (Root Component)\n\n| Prop | Type | Default | Required | Description |\n|------|------|---------|----------|-------------|\n| `showModal` | `boolean` | - | Yes | Controls the modal\'s visibility |\n| `children` | `React.ReactElement<IModalHeaderProps> \\| [React.ReactElement<IModalHeaderProps>, React.ReactElement<IModalBodyProps>]` | - | Yes | Modal content (Header and/or Body components) |\n| `onHide` | `() => void` | `undefined` | No | Callback function invoked when the modal should close |\n| `closeButton` | `boolean` | `true` | No | Show/hide the close button in the top-right corner |\n| `escKeyClose` | `boolean` | `true` | No | Allow closing the modal by pressing the ESC key |\n| `rtl` | `boolean` | `false` | No | Sets the modal content to right-to-left layout |\n| `portalTarget` | `HTMLElement` | `document.body` | No | DOM element where the modal will be rendered |\n| `shards` | `(HTMLElement \\| React.RefObject<any>)[]` | `undefined` | No | List of elements that remain accessible while modal is open |\n| `className` | `string` | `undefined` | No | Additional CSS classes for the modal container |\n| `aria-label` | `string` | `undefined` | No | Accessible name for the dialog. Takes precedence over the `Modal.Header` text; required when no header is rendered |\n\n### Modal.Header\n\nRenders the header/title section of the modal. Returns null if no children provided.\n\n| Prop | Type | Default | Required | Description |\n|------|------|---------|----------|-------------|\n| `children` | `React.ReactNode` | `undefined` | No | Header content/title of the modal |\n| `className` | `string` | `undefined` | No | Additional CSS classes for header customization |\n\n### Modal.Body\n\nRenders the main content section of the modal. Returns null if no children provided.\n\n| Prop | Type | Default | Required | Description |\n|------|------|---------|----------|-------------|\n| `children` | `React.ReactNode` | `undefined` | No | Main content of the modal |\n| `className` | `string` | `undefined` | No | Additional CSS classes for body customization |\n| `aria-label` | `string` | `"Scrollable content"` | No | Accessible name for the body while it overflows and becomes a focusable scroll region |\n| `gutter` | `boolean` | `false` | No | Reserves 4px around the content so edge focus rings stay visible while the body scrolls |\n\nThe body becomes a scroll container only once its content is taller than it can grow (`max-h-[84vh]`). While the content fits, overflow stays visible, so focus rings and shadows on controls at its edges aren\'t clipped. A scrolling body does clip at its edges. Pass `gutter` to reserve 4px around the content (`p-1`, cancelled out by `-mx-1 -mb-1`) so edge focus rings stay visible while it scrolls.\n\n- With `gutter`, a `mt-*` override sets the gap above the gutter, so content sits 4px lower than the margin alone.\n- Explicit widths (`w-full`, `w-[30rem]`) or padding overrides on a body with `gutter` make the content 8px narrower or shift it. Leave `gutter` off for such bodies.\n\n## Usage Patterns\n\n### Controlled Visibility\n\nModal visibility is always controlled by the parent component:\n\n```tsx\nconst [isOpen, setIsOpen] = useState(false);\n\n<Modal showModal={isOpen} onHide={() => setIsOpen(false)}>\n <Modal.Header>Controlled Modal</Modal.Header>\n <Modal.Body>Content here</Modal.Body>\n</Modal>\n```\n\n### Optional Header\n\nThe header is optional. Omit it for simpler modals:\n\n```tsx\n<Modal showModal={showModal} onHide={handleClose}>\n <Modal.Body>\n <h2>Custom Title in Body</h2>\n <p>Content without using Modal.Header</p>\n </Modal.Body>\n</Modal>\n```\n\n### Closing Behavior\n\nControl how users can close the modal:\n\n```tsx\n// Allow ESC key and close button (default)\n<Modal showModal={showModal} onHide={handleClose} />\n\n// Disable ESC key\n<Modal showModal={showModal} onHide={handleClose} escKeyClose={false} />\n\n// No close button (must close via explicit action)\n<Modal showModal={showModal} onHide={handleClose} closeButton={false} />\n```\n\n**Note:** This component forwards refs to the container div element (`HTMLDivElement`).\n\n## Practical Examples\n\n### Confirmation Dialog\n\n```tsx\nimport { Modal } from "@components";\nimport { Button } from "@components";\nimport { useState } from "react";\n\nfunction DeleteConfirmation({ itemName, onConfirm }) {\n const [showModal, setShowModal] = useState(false);\n \n const handleConfirm = () => {\n onConfirm();\n setShowModal(false);\n };\n \n return (\n <>\n <Button \n color="error" \n onClick={() => setShowModal(true)}\n >\n Delete {itemName}\n </Button>\n \n <Modal \n showModal={showModal} \n onHide={() => setShowModal(false)}\n >\n <Modal.Header>Confirm Deletion</Modal.Header>\n <Modal.Body>\n <p className="mb-4">\n Are you sure you want to delete "{itemName}"? \n This action cannot be undone.\n </p>\n <div className="flex justify-end gap-2">\n <Button \n variant="outline" \n color="secondary"\n onClick={() => setShowModal(false)}\n >\n Cancel\n </Button>\n <Button \n color="error"\n onClick={handleConfirm}\n >\n Delete\n </Button>\n </div>\n </Modal.Body>\n </Modal>\n </>\n );\n}\n```\n\n### Form Modal\n\n```tsx\nimport { Modal } from "@components";\nimport { Button } from "@components";\nimport { TextField } from "@components";\nimport { useState } from "react";\n\nfunction CreateUserModal() {\n const [showModal, setShowModal] = useState(false);\n const [formData, setFormData] = useState({\n name: "",\n email: "",\n role: ""\n });\n \n const handleSubmit = (e) => {\n e.preventDefault();\n // Process form data\n console.log("Creating user:", formData);\n setShowModal(false);\n setFormData({ name: "", email: "", role: "" });\n };\n \n return (\n <>\n <Button onClick={() => setShowModal(true)}>\n Add New User\n </Button>\n \n <Modal \n showModal={showModal} \n onHide={() => setShowModal(false)}\n >\n <Modal.Header>Create New User</Modal.Header>\n <Modal.Body>\n <form onSubmit={handleSubmit} className="space-y-4">\n <TextField\n label="Full Name"\n name="name"\n value={formData.name}\n onChange={(e) => setFormData({...formData, name: e.target.value})}\n required\n />\n <TextField\n label="Email"\n name="email"\n type="email"\n value={formData.email}\n onChange={(e) => setFormData({...formData, email: e.target.value})}\n required\n />\n <TextField\n label="Role"\n name="role"\n value={formData.role}\n onChange={(e) => setFormData({...formData, role: e.target.value})}\n required\n />\n <div className="flex justify-end gap-2 pt-4">\n <Button \n variant="outline" \n color="secondary"\n type="button"\n onClick={() => setShowModal(false)}\n >\n Cancel\n </Button>\n <Button \n color="primary"\n type="submit"\n >\n Create User\n </Button>\n </div>\n </form>\n </Modal.Body>\n </Modal>\n </>\n );\n}\n```\n\n### Forced Action Modal\n\nPrevent dismissal until user takes action:\n\n```tsx\nimport { Modal } from "@components";\nimport { Button } from "@components";\nimport { useState } from "react";\n\nfunction AgreementModal() {\n const [showModal, setShowModal] = useState(true);\n \n const handleAgree = () => {\n // Save agreement\n localStorage.setItem(\'termsAgreed\', \'true\');\n setShowModal(false);\n };\n \n return (\n <Modal \n showModal={showModal} \n onHide={() => {}} // Empty function - cannot close\n closeButton={false} // No close button\n escKeyClose={false} // Cannot use ESC key\n >\n <Modal.Header>Terms and Conditions</Modal.Header>\n <Modal.Body>\n <div className="space-y-4">\n <p>Please read and accept the terms and conditions to continue.</p>\n <div className="max-h-60 overflow-y-auto border p-4 rounded">\n {/* Terms content */}\n <p>Terms and conditions text...</p>\n </div>\n <div className="flex justify-end">\n <Button \n color="primary"\n onClick={handleAgree}\n >\n I Accept\n </Button>\n </div>\n </div>\n </Modal.Body>\n </Modal>\n );\n}\n```\n\n### Information Modal with Scrollable Content\n\n```tsx\nimport { Modal } from "@components";\nimport { Button } from "@components";\nimport { useState } from "react";\n\nfunction DetailedInfoModal({ data }) {\n const [showModal, setShowModal] = useState(false);\n \n return (\n <>\n <Button \n variant="text" \n onClick={() => setShowModal(true)}\n >\n View Details\n </Button>\n \n <Modal \n showModal={showModal} \n onHide={() => setShowModal(false)}\n className="max-w-2xl"\n >\n <Modal.Header>Detailed Information</Modal.Header>\n <Modal.Body className="space-y-4">\n <section>\n <h3 className="font-semibold mb-2">Overview</h3>\n <p>{data.overview}</p>\n </section>\n \n <section>\n <h3 className="font-semibold mb-2">Specifications</h3>\n <ul className="list-disc list-inside space-y-1">\n {data.specs.map((spec, index) => (\n <li key={index}>{spec}</li>\n ))}\n </ul>\n </section>\n \n <section>\n <h3 className="font-semibold mb-2">Additional Notes</h3>\n <p>{data.notes}</p>\n </section>\n \n <div className="flex justify-end pt-4">\n <Button onClick={() => setShowModal(false)}>\n Close\n </Button>\n </div>\n </Modal.Body>\n </Modal>\n </>\n );\n}\n```\n\n### Multi-Step Modal\n\n```tsx\nimport { Modal } from "@components";\nimport { Button } from "@components";\nimport { useState } from "react";\n\nfunction MultiStepModal() {\n const [showModal, setShowModal] = useState(false);\n const [step, setStep] = useState(1);\n \n const handleNext = () => setStep(step + 1);\n const handlePrev = () => setStep(step - 1);\n const handleFinish = () => {\n // Process completion\n setShowModal(false);\n setStep(1);\n };\n \n return (\n <>\n <Button onClick={() => setShowModal(true)}>\n Start Wizard\n </Button>\n \n <Modal \n showModal={showModal} \n onHide={() => {\n setShowModal(false);\n setStep(1);\n }}\n >\n <Modal.Header>Setup Wizard - Step {step} of 3</Modal.Header>\n <Modal.Body>\n {step === 1 && (\n <div>\n <h3 className="font-semibold mb-2">Step 1: Basic Information</h3>\n {/* Step 1 content */}\n </div>\n )}\n {step === 2 && (\n <div>\n <h3 className="font-semibold mb-2">Step 2: Configuration</h3>\n {/* Step 2 content */}\n </div>\n )}\n {step === 3 && (\n <div>\n <h3 className="font-semibold mb-2">Step 3: Review</h3>\n {/* Step 3 content */}\n </div>\n )}\n \n <div className="flex justify-between pt-4">\n <Button \n variant="outline"\n disabled={step === 1}\n onClick={handlePrev}\n >\n Previous\n </Button>\n \n {step < 3 ? (\n <Button onClick={handleNext}>\n Next\n </Button>\n ) : (\n <Button color="primary" onClick={handleFinish}>\n Finish\n </Button>\n )}\n </div>\n </Modal.Body>\n </Modal>\n </>\n );\n}\n```\n\n## Styling and Customization\n\nUse the `className` prop for custom modal styling:\n\n```tsx\n<Modal \n showModal={showModal}\n onHide={handleClose}\n className="max-w-4xl" // Custom width\n>\n <Modal.Header className="bg-blue-50 border-b">\n Styled Header\n </Modal.Header>\n <Modal.Body className="p-8">\n Custom body styling\n </Modal.Body>\n</Modal>\n```\n\n## Technical Details\n\n### Portal Rendering\n\n- Modal is rendered outside the normal DOM hierarchy using React Portal\n- Default portal target is `document.body`\n- Custom portal target can be specified via `portalTarget` prop\n- Ensures proper z-index layering above all other content\n\n### Focus Management\n\n- Uses react-focus-on for focus trapping\n- Focus automatically moves to close button when modal opens\n- Without a close button, focus moves to the first focusable element in the modal, or to the dialog itself when there is none\n- Tab key cycles through interactive elements within modal\n- When the body content overflows, the body joins the tab order so it can be scrolled with the keyboard\n- Focus returns to trigger element when modal closes\n- Shards prop allows specified elements to remain accessible\n\n### Keyboard Interaction\n\n- ESC key closes modal (can be disabled via `escKeyClose={false}`)\n- Tab key navigates through interactive elements\n- Shift+Tab navigates backwards\n- Enter key activates focused button or link\n\n## Accessibility\n\nThe component includes built-in accessibility features:\n\n**Implemented:**\n- `role="dialog"` with `aria-modal="true"`\n- `aria-labelledby` / `aria-describedby` reference the rendered Header and Body through per-instance ids, so multiple modals never share ids\n- Modal.Header is exposed as a level-2 heading (`role="heading"`, `aria-level={2}`); don\'t nest another heading element inside it\n- Focus trapping prevents tabbing outside the modal\n- ESC key support for closing (standard modal behavior)\n- Close button has `aria-label` for screen readers\n- Portal rendering ensures proper screen reader announcement\n- Auto-focus on close button for immediate keyboard access\n- Background scroll locking via react-focus-on\n\n**Best Practices:**\n- Always provide a Modal.Header for context (used for `aria-labelledby`); for headerless modals pass `aria-label`\n- If the header has no title text (only an icon, or a search input), pass `aria-label`. It takes precedence over the header\n- If both `closeButton` and `escKeyClose` are disabled, render a keyboard-operable close or completion control in the body, otherwise keyboard users are trapped\n- Ensure modal content is keyboard navigable\n- Use semantic HTML within modal body\n- Provide clear action buttons for closing or completing modal flow\n- Don\'t nest modals within modals\n- Test with keyboard navigation (Tab, Shift+Tab, ESC, Enter)\n- Test with screen readers to verify announcements\n- For forced action modals, clearly communicate why dismissal is disabled\n'
|
|
2493
|
+
"content": '# Modal Component\n\n## Component Overview\n\nThe Modal component creates a dialog overlay that appears above the page content using React Portal, requiring user interaction before returning to the main interface. It uses a compound component pattern with Header, Title and Body subcomponents.\n\n**When to use:**\n- Confirmation dialogs that require user decisions\n- Forms that need focused attention without navigation\n- Alert messages and important notifications\n- Displaying detailed information without leaving the current page\n- Multi-step workflows that require isolation\n\n**Component Architecture:**\n- Built with React compound component pattern (Modal.Header, Modal.Title, Modal.Body)\n- Rendered via React Portal for proper z-index layering\n- Uses react-focus-on for focus management and accessibility\n- Styled with Tailwind CSS and tailwind-variants (`modalVariants`)\n- Supports ESC key to close and focus trapping\n- Optional close button and RTL support\n\n## Basic Usage\n\n```tsx\nimport { Modal } from "@components";\nimport { Button } from "@components";\nimport { useState } from "react";\n\nexport function Example() {\n const [showModal, setShowModal] = useState(false);\n \n return (\n <>\n <Button onClick={() => setShowModal(true)}>Open Modal</Button>\n \n <Modal showModal={showModal} onHide={() => setShowModal(false)}>\n <Modal.Header>\n <Modal.Title>Example Modal</Modal.Title>\n </Modal.Header>\n <Modal.Body>\n <p>Modal content goes here.</p>\n </Modal.Body>\n </Modal>\n </>\n );\n}\n```\n\n**Note:** Update the import path based on your project structure. If you used the Astral UI CLI, the typical import path would be `@components/ui/modal` or `@components/modal`.\n\n## Component Props\n\n### Modal (Root Component)\n\n| Prop | Type | Default | Required | Description |\n|------|------|---------|----------|-------------|\n| `showModal` | `boolean` | - | Yes | Controls the modal\'s visibility |\n| `children` | `React.ReactElement<IModalHeaderProps> \\| [React.ReactElement<IModalHeaderProps>, React.ReactElement<IModalBodyProps>]` | - | Yes | Modal content (Header and/or Body components) |\n| `onHide` | `() => void` | `undefined` | No | Callback function invoked when the modal should close |\n| `closeButton` | `boolean` | `true` | No | Show/hide the close button in the top-right corner |\n| `escKeyClose` | `boolean` | `true` | No | Allow closing the modal by pressing the ESC key |\n| `rtl` | `boolean` | `false` | No | Sets the modal content to right-to-left layout |\n| `portalTarget` | `HTMLElement` | `document.body` | No | DOM element where the modal will be rendered |\n| `shards` | `(HTMLElement \\| React.RefObject<any>)[]` | `undefined` | No | List of elements that remain accessible while modal is open |\n| `className` | `string` | `undefined` | No | Additional CSS classes for the modal container |\n| `aria-label` | `string` | `undefined` | No | Accessible name for the dialog. Takes precedence over `Modal.Title` and `Modal.Header`; required when neither is rendered |\n| `aria-labelledby` | `string` | `undefined` | No | Id of the element that names the dialog. Takes precedence over `Modal.Title`, `Modal.Header` and `aria-label` |\n| `aria-describedby` | `string \\| false` | id of `Modal.Body` | No | Id of the element that describes the dialog, or `false` for no description. A body that contains the `Modal.Title` is not used by default |\n| `closeButtonLabel` | `string` | `"Close"` | No | Accessible name of the built-in close button |\n\nThe built-in close button is absolutely positioned in the top end corner. While it is shown, `Modal.Header` keeps `me-7` of space for it, and a modal without a `Modal.Header` gets `pt-9` instead of `pt-6`. With `closeButton={false}`, neither is applied.\n\nClicks on the close button do not propagate, so they never reach an `onClick` on a React ancestor of `<Modal>`. Other events inside the modal still bubble through the React tree to its ancestors, as with any portal. If `<Modal>` is rendered inside a clickable element (a table row, a card), stop propagation in that element\'s handler for events from the modal, or render the modal outside it.\n\n### Modal.Header\n\nRenders the header row of the modal. Returns null if no children provided.\n\n- With a `Modal.Title` inside, the header is a plain layout row for the title and any actions (buttons, badges, a search input). Only the title is the heading and the dialog\'s name.\n- Without a `Modal.Title`, the whole header is the dialog\'s heading (`role="heading"`, `aria-level={2}`) and names it. Don\'t put controls in such a header, since their labels become part of the name.\n\n| Prop | Type | Default | Required | Description |\n|------|------|---------|----------|-------------|\n| `children` | `React.ReactNode` | `undefined` | No | Header content/title of the modal |\n| `className` | `string` | `undefined` | No | Additional CSS classes for header customization |\n\n### Modal.Title\n\nRenders the modal\'s title as an `<h2>` and names the dialog through `aria-labelledby`. Place it in `Modal.Header` next to the header\'s actions, or in `Modal.Body` for dialogs that show the title there. Returns null if no children provided.\n\n| Prop | Type | Default | Required | Description |\n|------|------|---------|----------|-------------|\n| `children` | `React.ReactNode` | `undefined` | No | Title text |\n| `className` | `string` | `undefined` | No | Additional CSS classes for the title |\n\n```tsx\n<Modal.Header>\n <Modal.Title>Share the Chat</Modal.Title>\n <Button variant="text" prefixIcon="download" tooltip="Download" />\n</Modal.Header>\n```\n\n### Modal.Body\n\nRenders the main content section of the modal. Returns null if no children provided.\n\n| Prop | Type | Default | Required | Description |\n|------|------|---------|----------|-------------|\n| `children` | `React.ReactNode` | `undefined` | No | Main content of the modal |\n| `className` | `string` | `undefined` | No | Additional CSS classes for body customization |\n| `aria-label` | `string` | `"Scrollable content"` | No | Accessible name for the body while it overflows and becomes a focusable scroll region |\n| `gutter` | `boolean` | `false` | No | Reserves 4px around the content so edge focus rings stay visible while the body scrolls |\n\nThe body becomes a scroll container only once its content is taller than it can grow (`max-h-[84vh]`). While the content fits, overflow stays visible, so focus rings and shadows on controls at its edges aren\'t clipped. A scrolling body does clip at its edges. Pass `gutter` to reserve 4px around the content (`p-1`, cancelled out by `-mx-1 -mb-1`) so edge focus rings stay visible while it scrolls.\n\n- With `gutter`, a `mt-*` override sets the gap above the gutter, so content sits 4px lower than the margin alone.\n- Explicit widths (`w-full`, `w-[30rem]`) or padding overrides on a body with `gutter` make the content 8px narrower or shift it. Leave `gutter` off for such bodies.\n\n## Usage Patterns\n\n### Controlled Visibility\n\nModal visibility is always controlled by the parent component:\n\n```tsx\nconst [isOpen, setIsOpen] = useState(false);\n\n<Modal showModal={isOpen} onHide={() => setIsOpen(false)}>\n <Modal.Header>Controlled Modal</Modal.Header>\n <Modal.Body>Content here</Modal.Body>\n</Modal>\n```\n\n### Optional Header\n\nThe header is optional. Omit it for simpler modals, and name the dialog with a `Modal.Title` in the body or with `aria-label`:\n\n```tsx\n<Modal showModal={showModal} onHide={handleClose}>\n <Modal.Body>\n <Modal.Title>Custom Title in Body</Modal.Title>\n <p>Content without using Modal.Header</p>\n </Modal.Body>\n</Modal>\n```\n\nA body that contains the `Modal.Title` doesn\'t describe the dialog, since the title would be read twice. Point `aria-describedby` at the message instead:\n\n```tsx\n<Modal showModal={showModal} onHide={handleClose} aria-describedby="delete-message">\n <Modal.Body>\n <Modal.Title>Delete file?</Modal.Title>\n <p id="delete-message">This cannot be undone.</p>\n </Modal.Body>\n</Modal>\n```\n\n### Closing Behavior\n\nControl how users can close the modal:\n\n```tsx\n// Allow ESC key and close button (default)\n<Modal showModal={showModal} onHide={handleClose} />\n\n// Disable ESC key\n<Modal showModal={showModal} onHide={handleClose} escKeyClose={false} />\n\n// No close button (must close via explicit action)\n<Modal showModal={showModal} onHide={handleClose} closeButton={false} />\n```\n\n**Note:** This component forwards refs to the container div element (`HTMLDivElement`).\n\n## Practical Examples\n\n### Confirmation Dialog\n\n```tsx\nimport { Modal } from "@components";\nimport { Button } from "@components";\nimport { useState } from "react";\n\nfunction DeleteConfirmation({ itemName, onConfirm }) {\n const [showModal, setShowModal] = useState(false);\n \n const handleConfirm = () => {\n onConfirm();\n setShowModal(false);\n };\n \n return (\n <>\n <Button \n color="error" \n onClick={() => setShowModal(true)}\n >\n Delete {itemName}\n </Button>\n \n <Modal \n showModal={showModal} \n onHide={() => setShowModal(false)}\n >\n <Modal.Header>Confirm Deletion</Modal.Header>\n <Modal.Body>\n <p className="mb-4">\n Are you sure you want to delete "{itemName}"? \n This action cannot be undone.\n </p>\n <div className="flex justify-end gap-2">\n <Button \n variant="outline" \n color="secondary"\n onClick={() => setShowModal(false)}\n >\n Cancel\n </Button>\n <Button \n color="error"\n onClick={handleConfirm}\n >\n Delete\n </Button>\n </div>\n </Modal.Body>\n </Modal>\n </>\n );\n}\n```\n\n### Form Modal\n\n```tsx\nimport { Modal } from "@components";\nimport { Button } from "@components";\nimport { TextField } from "@components";\nimport { useState } from "react";\n\nfunction CreateUserModal() {\n const [showModal, setShowModal] = useState(false);\n const [formData, setFormData] = useState({\n name: "",\n email: "",\n role: ""\n });\n \n const handleSubmit = (e) => {\n e.preventDefault();\n // Process form data\n console.log("Creating user:", formData);\n setShowModal(false);\n setFormData({ name: "", email: "", role: "" });\n };\n \n return (\n <>\n <Button onClick={() => setShowModal(true)}>\n Add New User\n </Button>\n \n <Modal \n showModal={showModal} \n onHide={() => setShowModal(false)}\n >\n <Modal.Header>Create New User</Modal.Header>\n <Modal.Body>\n <form onSubmit={handleSubmit} className="space-y-4">\n <TextField\n label="Full Name"\n name="name"\n value={formData.name}\n onChange={(e) => setFormData({...formData, name: e.target.value})}\n required\n />\n <TextField\n label="Email"\n name="email"\n type="email"\n value={formData.email}\n onChange={(e) => setFormData({...formData, email: e.target.value})}\n required\n />\n <TextField\n label="Role"\n name="role"\n value={formData.role}\n onChange={(e) => setFormData({...formData, role: e.target.value})}\n required\n />\n <div className="flex justify-end gap-2 pt-4">\n <Button \n variant="outline" \n color="secondary"\n type="button"\n onClick={() => setShowModal(false)}\n >\n Cancel\n </Button>\n <Button \n color="primary"\n type="submit"\n >\n Create User\n </Button>\n </div>\n </form>\n </Modal.Body>\n </Modal>\n </>\n );\n}\n```\n\n### Forced Action Modal\n\nPrevent dismissal until user takes action:\n\n```tsx\nimport { Modal } from "@components";\nimport { Button } from "@components";\nimport { useState } from "react";\n\nfunction AgreementModal() {\n const [showModal, setShowModal] = useState(true);\n \n const handleAgree = () => {\n // Save agreement\n localStorage.setItem(\'termsAgreed\', \'true\');\n setShowModal(false);\n };\n \n return (\n <Modal \n showModal={showModal} \n onHide={() => {}} // Empty function - cannot close\n closeButton={false} // No close button\n escKeyClose={false} // Cannot use ESC key\n >\n <Modal.Header>Terms and Conditions</Modal.Header>\n <Modal.Body>\n <div className="space-y-4">\n <p>Please read and accept the terms and conditions to continue.</p>\n <div className="max-h-60 overflow-y-auto border p-4 rounded">\n {/* Terms content */}\n <p>Terms and conditions text...</p>\n </div>\n <div className="flex justify-end">\n <Button \n color="primary"\n onClick={handleAgree}\n >\n I Accept\n </Button>\n </div>\n </div>\n </Modal.Body>\n </Modal>\n );\n}\n```\n\n### Information Modal with Scrollable Content\n\n```tsx\nimport { Modal } from "@components";\nimport { Button } from "@components";\nimport { useState } from "react";\n\nfunction DetailedInfoModal({ data }) {\n const [showModal, setShowModal] = useState(false);\n \n return (\n <>\n <Button \n variant="text" \n onClick={() => setShowModal(true)}\n >\n View Details\n </Button>\n \n <Modal \n showModal={showModal} \n onHide={() => setShowModal(false)}\n className="max-w-2xl"\n >\n <Modal.Header>Detailed Information</Modal.Header>\n <Modal.Body className="space-y-4">\n <section>\n <h3 className="font-semibold mb-2">Overview</h3>\n <p>{data.overview}</p>\n </section>\n \n <section>\n <h3 className="font-semibold mb-2">Specifications</h3>\n <ul className="list-disc list-inside space-y-1">\n {data.specs.map((spec, index) => (\n <li key={index}>{spec}</li>\n ))}\n </ul>\n </section>\n \n <section>\n <h3 className="font-semibold mb-2">Additional Notes</h3>\n <p>{data.notes}</p>\n </section>\n \n <div className="flex justify-end pt-4">\n <Button onClick={() => setShowModal(false)}>\n Close\n </Button>\n </div>\n </Modal.Body>\n </Modal>\n </>\n );\n}\n```\n\n### Multi-Step Modal\n\n```tsx\nimport { Modal } from "@components";\nimport { Button } from "@components";\nimport { useState } from "react";\n\nfunction MultiStepModal() {\n const [showModal, setShowModal] = useState(false);\n const [step, setStep] = useState(1);\n \n const handleNext = () => setStep(step + 1);\n const handlePrev = () => setStep(step - 1);\n const handleFinish = () => {\n // Process completion\n setShowModal(false);\n setStep(1);\n };\n \n return (\n <>\n <Button onClick={() => setShowModal(true)}>\n Start Wizard\n </Button>\n \n <Modal \n showModal={showModal} \n onHide={() => {\n setShowModal(false);\n setStep(1);\n }}\n >\n <Modal.Header>Setup Wizard - Step {step} of 3</Modal.Header>\n <Modal.Body>\n {step === 1 && (\n <div>\n <h3 className="font-semibold mb-2">Step 1: Basic Information</h3>\n {/* Step 1 content */}\n </div>\n )}\n {step === 2 && (\n <div>\n <h3 className="font-semibold mb-2">Step 2: Configuration</h3>\n {/* Step 2 content */}\n </div>\n )}\n {step === 3 && (\n <div>\n <h3 className="font-semibold mb-2">Step 3: Review</h3>\n {/* Step 3 content */}\n </div>\n )}\n \n <div className="flex justify-between pt-4">\n <Button \n variant="outline"\n disabled={step === 1}\n onClick={handlePrev}\n >\n Previous\n </Button>\n \n {step < 3 ? (\n <Button onClick={handleNext}>\n Next\n </Button>\n ) : (\n <Button color="primary" onClick={handleFinish}>\n Finish\n </Button>\n )}\n </div>\n </Modal.Body>\n </Modal>\n </>\n );\n}\n```\n\n## Styling and Customization\n\nUse the `className` prop for custom modal styling:\n\n```tsx\n<Modal \n showModal={showModal}\n onHide={handleClose}\n className="max-w-4xl" // Custom width\n>\n <Modal.Header className="bg-blue-50 border-b">\n Styled Header\n </Modal.Header>\n <Modal.Body className="p-8">\n Custom body styling\n </Modal.Body>\n</Modal>\n```\n\nHeader-styled rows outside `Modal.Header` can reuse its classes through the exported `modalVariants`, which has `header` and `title` slots:\n\n```tsx\nimport { modalVariants } from "@cloudwick/astral-ui";\n\nconst { header, title } = modalVariants({ closeButton: false });\n\n<div className={header()}>...</div>\n```\n\n## Technical Details\n\n### Portal Rendering\n\n- Modal is rendered outside the normal DOM hierarchy using React Portal\n- Default portal target is `document.body`\n- Custom portal target can be specified via `portalTarget` prop\n- Ensures proper z-index layering above all other content\n\n### Focus Management\n\n- Uses react-focus-on for focus trapping\n- Focus moves to the first focusable element when the modal opens, which is the close button when it is shown. Add `data-autofocus` to another element to start there instead\n- Without a close button, focus moves to the first focusable element in the modal, or to the dialog itself when there is none\n- Tab key cycles through interactive elements within modal\n- When the body content overflows, the body joins the tab order so it can be scrolled with the keyboard\n- Focus returns to trigger element when modal closes\n- Shards prop allows specified elements to remain accessible\n\n### Keyboard Interaction\n\n- ESC key closes modal (can be disabled via `escKeyClose={false}`)\n- Tab key navigates through interactive elements\n- Shift+Tab navigates backwards\n- Enter key activates focused button or link\n\n## Accessibility\n\nThe component includes built-in accessibility features:\n\n**Implemented:**\n- `role="dialog"` with `aria-modal="true"`\n- `aria-labelledby` / `aria-describedby` reference the rendered Title (or Header) and Body through per-instance ids, so multiple modals never share ids. Both can be overridden with the matching props\n- Modal.Title is an `<h2>`. A Modal.Header without a Modal.Title is exposed as a level-2 heading (`role="heading"`, `aria-level={2}`); don\'t nest another heading element inside it\n- Focus trapping prevents tabbing outside the modal\n- ESC key support for closing (standard modal behavior)\n- Close button is named by `closeButtonLabel` (default `"Close"`)\n- In development, a console warning is logged when the dialog has no accessible name, or when its heading contains focusable elements\n- Portal rendering ensures proper screen reader announcement\n- Initial focus goes to the first focusable element (the close button when shown), or to an element marked `data-autofocus`\n- Background scroll locking via react-focus-on\n\n**Best Practices:**\n- Put the title in a Modal.Title (used for `aria-labelledby`), so header actions stay out of the dialog\'s name; for modals without a visible title pass `aria-label`\n- If the header has no title text (only an icon, or a search input), pass `aria-label`. It takes precedence over the header\n- In localized apps, pass translated text to `closeButtonLabel` and to `Modal.Body`\'s `aria-label`\n- If both `closeButton` and `escKeyClose` are disabled, render a keyboard-operable close or completion control in the body, otherwise keyboard users are trapped\n- Ensure modal content is keyboard navigable\n- Use semantic HTML within modal body\n- Provide clear action buttons for closing or completing modal flow\n- Don\'t nest modals within modals\n- Test with keyboard navigation (Tab, Shift+Tab, ESC, Enter)\n- Test with screen readers to verify announcements\n- For forced action modals, clearly communicate why dismissal is disabled\n'
|
|
2433
2494
|
}
|
|
2434
2495
|
],
|
|
2435
2496
|
"directories": []
|
|
@@ -2875,12 +2936,14 @@ MultiSelectTransferModal.displayName = "MultiSelectTransferModal";
|
|
|
2875
2936
|
"files": [
|
|
2876
2937
|
{
|
|
2877
2938
|
"name": "panelVariants.ts",
|
|
2878
|
-
"content": 'import { tv } from "tailwind-variants";\n\nexport const panelVariants = tv({\n slots: {\n container: "z-[1080] relative",\n overlay: "hidden md:fixed md:inset-0 bg-black/40",\n panel: "!flex flex-col bg-white dark:bg-iridium dark:text-secondary-300",\n header: `flex px-6 py-4 min-h-11 border-b border-secondary-100 justify-between items-center gap-6 \n flex-shrink-0 dark:bg-secondary-800 dark:border-secondary-500`,\n body: "p-6 flex-1 overflow-y-auto",\n footer: "px-6 py-3 min-h-11 flex-shrink-0 border-t border-secondary-100 dark:bg-secondary-800 dark:border-secondary-500"\n },\n variants: {\n variant: {\n extended: { panel: "w-4/5 h-full inset-y-0" },\n compact: { panel: "w-2/5 h-[calc(100%-5rem)]" }\n },\n animation: {\n slideInRight: { panel: "animate-[panel-slide-in_0.5s]" },\n slideOutRight: { panel: "animate-[panel-slide-out_0.5s]" },\n slideInLeft: { panel: "animate-[panel-slide-in-rtl_0.5s]" },\n slideOutLeft: { panel: "animate-[panel-slide-out-rtl_0.5s]" },\n appear: { overlay: "animate-[panel-appear_0.5s] md:block" },\n disappear: { overlay: "animate-[panel-disappear_0.5s] md:block" },\n none: {}\n },\n visibility: {\n visible: { panel: "block", overlay: "md:block" },\n hidden: { panel: "hidden", overlay: "hidden" }\n },\n direction: {\n right: { panel: "rounded-l-xl fixed left-auto right-0" },\n left: { panel: "rounded-r-xl fixed right-auto left-0" }\n }\n },\n compoundVariants: [\n {\n variant: "compact",\n direction: "right",\n class: { panel: "rounded-xl right-8 inset-y-8" }\n },\n {\n variant: "compact",\n direction: "left",\n class: { panel: "rounded-xl left-8 inset-y-8" }\n }\n ],\n defaultVariants: {\n variant: "compact",\n animation: "none",\n visibility: "visible",\n direction: "right"\n }\n});\n\n// Variant for the toggleVisibilityUsingCss mode \u2014 uses CSS transitions instead of keyframe animations\nexport const cssVisibilityVariants = tv({\n slots: {\n container: "z-[1080] relative",\n overlay: "hidden md:fixed md:inset-0 bg-black/40 opacity-0 transition-opacity duration-500",\n panel: "shadow-xl transition-transform duration-500 flex flex-col bg-white dark:bg-iridium dark:text-secondary-300"\n },\n variants: {\n direction: {\n right: { panel: "fixed right-0 left-auto translate-x-full" },\n left: { panel: "fixed left-0 right-auto -translate-x-full" }\n },\n variant: {\n compact: { panel: "w-2/5 h-[calc(100%-5rem)] inset-y-8 rounded-xl" },\n extended: { panel: "w-4/5 h-full" }\n },\n showPanel: {\n true: { overlay: "block opacity-100 animate-[panel-appear_0.5s]" },\n false: {}\n }\n },\n compoundVariants: [\n {\n variant: "extended",\n direction: "right",\n class: { panel: "rounded-l-xl" }\n },\n {\n variant: "extended",\n direction: "left",\n class: { panel: "rounded-r-xl" }\n },\n {\n showPanel: true,\n direction: "right",\n variant: "compact",\n class: { panel: "-translate-x-8" }\n },\n {\n showPanel: true,\n direction: "right",\n variant: "extended",\n class: { panel: "-translate-x-0" }\n },\n {\n showPanel: true,\n direction: "left",\n variant: "compact",\n class: { panel: "translate-x-8" }\n },\n {\n showPanel: true,\n direction: "left",\n variant: "extended",\n class: { panel: "translate-x-0" }\n }\n ],\n defaultVariants: {\n direction: "right",\n variant: "compact",\n showPanel: false\n }\n});\n'
|
|
2939
|
+
"content": 'import { tv } from "tailwind-variants";\n\nexport const panelVariants = tv({\n slots: {\n container: "z-[1080] relative",\n overlay: "hidden md:fixed md:inset-0 bg-black/40",\n panel: "!flex flex-col bg-white dark:bg-iridium dark:text-secondary-300",\n header: `flex px-6 py-4 min-h-11 border-b border-secondary-100 justify-between items-center gap-6 \n flex-shrink-0 dark:bg-secondary-800 dark:border-secondary-500`,\n body: "p-6 flex-1 overflow-y-auto",\n footer: "px-6 py-3 min-h-11 flex-shrink-0 border-t border-secondary-100 dark:bg-secondary-800 dark:border-secondary-500"\n },\n variants: {\n variant: {\n extended: { panel: "w-4/5 h-full inset-y-0" },\n compact: { panel: "w-2/5 max-md:w-[calc(100%-4rem)] h-[calc(100%-5rem)]" }\n },\n animation: {\n slideInRight: { panel: "animate-[panel-slide-in_0.5s]" },\n slideOutRight: { panel: "animate-[panel-slide-out_0.5s]" },\n slideInLeft: { panel: "animate-[panel-slide-in-rtl_0.5s]" },\n slideOutLeft: { panel: "animate-[panel-slide-out-rtl_0.5s]" },\n appear: { overlay: "animate-[panel-appear_0.5s] md:block" },\n disappear: { overlay: "animate-[panel-disappear_0.5s] md:block" },\n none: {}\n },\n visibility: {\n visible: { panel: "block", overlay: "md:block" },\n hidden: { panel: "hidden", overlay: "hidden" }\n },\n direction: {\n right: { panel: "rounded-l-xl fixed left-auto right-0" },\n left: { panel: "rounded-r-xl fixed right-auto left-0" }\n }\n },\n compoundVariants: [\n {\n variant: "compact",\n direction: "right",\n class: { panel: "rounded-xl right-8 inset-y-8" }\n },\n {\n variant: "compact",\n direction: "left",\n class: { panel: "rounded-xl left-8 inset-y-8" }\n }\n ],\n defaultVariants: {\n variant: "compact",\n animation: "none",\n visibility: "visible",\n direction: "right"\n }\n});\n\n// Variant for the toggleVisibilityUsingCss mode \u2014 uses CSS transitions instead of keyframe animations\nexport const cssVisibilityVariants = tv({\n slots: {\n container: "z-[1080] relative",\n overlay: "hidden md:fixed md:inset-0 bg-black/40 opacity-0 transition-opacity duration-500",\n panel: "shadow-xl transition-transform duration-500 flex flex-col bg-white dark:bg-iridium dark:text-secondary-300"\n },\n variants: {\n direction: {\n right: { panel: "fixed right-0 left-auto translate-x-full" },\n left: { panel: "fixed left-0 right-auto -translate-x-full" }\n },\n variant: {\n compact: { panel: "w-2/5 max-md:w-[calc(100%-4rem)] h-[calc(100%-5rem)] inset-y-8 rounded-xl" },\n extended: { panel: "w-4/5 h-full" }\n },\n showPanel: {\n true: { overlay: "block opacity-100 animate-[panel-appear_0.5s]" },\n false: {}\n }\n },\n compoundVariants: [\n {\n variant: "extended",\n direction: "right",\n class: { panel: "rounded-l-xl" }\n },\n {\n variant: "extended",\n direction: "left",\n class: { panel: "rounded-r-xl" }\n },\n {\n showPanel: true,\n direction: "right",\n variant: "compact",\n class: { panel: "-translate-x-8" }\n },\n {\n showPanel: true,\n direction: "right",\n variant: "extended",\n class: { panel: "-translate-x-0" }\n },\n {\n showPanel: true,\n direction: "left",\n variant: "compact",\n class: { panel: "translate-x-8" }\n },\n {\n showPanel: true,\n direction: "left",\n variant: "extended",\n class: { panel: "translate-x-0" }\n }\n ],\n defaultVariants: {\n direction: "right",\n variant: "compact",\n showPanel: false\n }\n});\n'
|
|
2879
2940
|
},
|
|
2880
2941
|
{
|
|
2881
2942
|
"name": "panelHeader.tsx",
|
|
2882
2943
|
"content": `import * as React from "react";
|
|
2883
2944
|
import { panelVariants } from "./panelVariants";
|
|
2945
|
+
import { usePartRegistration } from "@hooks";
|
|
2946
|
+
import { PanelContext } from "./panelContext";
|
|
2884
2947
|
import { Button } from "../button";
|
|
2885
2948
|
import { iconList } from "../adpIcon";
|
|
2886
2949
|
|
|
@@ -2938,6 +3001,9 @@ export const PanelHeader = React.forwardRef<HTMLDivElement, IPanelHeaderProps>(
|
|
|
2938
3001
|
[onCloseHandler]
|
|
2939
3002
|
);
|
|
2940
3003
|
|
|
3004
|
+
const context = React.useContext( PanelContext );
|
|
3005
|
+
usePartRegistration( context?.setTitleMounted, Boolean( header ));
|
|
3006
|
+
|
|
2941
3007
|
const { header: headerClass } = panelVariants();
|
|
2942
3008
|
|
|
2943
3009
|
return (
|
|
@@ -2960,8 +3026,8 @@ export const PanelHeader = React.forwardRef<HTMLDivElement, IPanelHeaderProps>(
|
|
|
2960
3026
|
)}
|
|
2961
3027
|
{( header || subHeader ) && (
|
|
2962
3028
|
<div className="panel__heading-container flex-1">
|
|
2963
|
-
{header && <
|
|
2964
|
-
{subHeader && <p className="panel__sub-heading text-secondary-400 font-regular text-base
|
|
3029
|
+
{header && <h2 className="panel__heading text-secondary-500 font-semibold dark:text-secondary-50" id={context?.titleId}>{header}</h2>}
|
|
3030
|
+
{subHeader && <p className="panel__sub-heading text-secondary-400 font-regular text-base dark:text-secondary-300">{subHeader}</p>}
|
|
2965
3031
|
</div>
|
|
2966
3032
|
)}
|
|
2967
3033
|
{customCTA}
|
|
@@ -2973,7 +3039,6 @@ export const PanelHeader = React.forwardRef<HTMLDivElement, IPanelHeaderProps>(
|
|
|
2973
3039
|
onClick={closePanel}
|
|
2974
3040
|
variant="text"
|
|
2975
3041
|
color="secondary"
|
|
2976
|
-
autoFocus
|
|
2977
3042
|
aria-label="Close panel"
|
|
2978
3043
|
/>
|
|
2979
3044
|
)}
|
|
@@ -2989,13 +3054,17 @@ PanelHeader.displayName = "PanelHeader";
|
|
|
2989
3054
|
"name": "panelFooter.tsx",
|
|
2990
3055
|
"content": 'import * as React from "react";\nimport { panelVariants } from "./panelVariants";\n\nexport interface IPanelFooterProps extends React.HTMLAttributes<HTMLDivElement> {\n /**\n * Panel Footer\n */\n children?: React.ReactNode;\n /**\n * Overwrite the Panel footer styles by passing space separated class names\n */\n className?: string;\n}\n\nexport const PanelFooter = React.forwardRef<HTMLDivElement, IPanelFooterProps>(\n ({\n className,\n children,\n ...props\n }, ref ) => {\n const { footer } = panelVariants();\n\n return children ? (\n <div\n className={footer({ class: className })}\n data-testid="panel-footer"\n ref={ref}\n {...props}\n >\n {children}\n </div>\n ) : null;\n }\n);\n\nPanelFooter.displayName = "PanelFooter";\n'
|
|
2991
3056
|
},
|
|
3057
|
+
{
|
|
3058
|
+
"name": "panelContext.ts",
|
|
3059
|
+
"content": 'import * as React from "react";\n\ninterface IPanelContext {\n titleId: string;\n setTitleMounted: ( mounted: boolean ) => void;\n}\n\nexport const PanelContext = React.createContext<IPanelContext | null>( null );\n'
|
|
3060
|
+
},
|
|
2992
3061
|
{
|
|
2993
3062
|
"name": "panelBody.tsx",
|
|
2994
3063
|
"content": 'import * as React from "react";\nimport { panelVariants } from "./panelVariants";\n\nexport interface IPanelBodyProps extends React.HTMLAttributes<HTMLDivElement> {\n /**\n * Panel Body\n */\n children?: React.ReactNode;\n /**\n * Overwrite the Panel body styles by passing space separated class names\n */\n className?: string;\n}\n\nexport const PanelBody = React.forwardRef<HTMLDivElement, IPanelBodyProps>(\n ({\n className,\n children,\n ...props\n }, ref ) => {\n const { body } = panelVariants();\n\n return children ? (\n <div\n className={body({ class: className })}\n data-testid="panel-content"\n id="panel-description"\n ref={ref}\n {...props}\n >\n {children}\n </div>\n ) : null;\n }\n);\n\nPanelBody.displayName = "PanelBody";\n'
|
|
2995
3064
|
},
|
|
2996
3065
|
{
|
|
2997
3066
|
"name": "panel.tsx",
|
|
2998
|
-
"content": 'import * as React from "react";\nimport ReactDOM from "react-dom";\nimport { FocusOn } from "react-focus-on";\n\nimport { panelVariants, cssVisibilityVariants } from "./panelVariants";\nimport { PanelHeader } from "./panelHeader";\nimport { PanelBody } from "./panelBody";\nimport { PanelFooter } from "./panelFooter";\n\nexport interface IPanelProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "dir"> {\n /**\n * Variant of the Panel\n * @default compact\n */\n variant?: "extended" | "compact";\n /**\n * Prop to control the panel display\n * @default false\n */\n showPanel?: boolean;\n /**\n * Toggle the visibility of the Panel without unmounting it\n * @default false\n */\n toggleVisibilityUsingCss?: boolean;\n /**\n * Overwrite the Panel styles by passing space separated class names\n */\n className?: string;\n /**\n * Accepts children of ReactNode type\n */\n children: React.ReactNode;\n /**\n * Direction from which the panel slides in\n * @default "right"\n */\n slideDirection?: "left" | "right";\n /**\n * If true, indicates that the app is in RTL (right-to-left) mode\n * When true in RTL mode, slideDirection="left" will make panel open from right\n * @default false\n */\n rtl?: boolean;\n /**\n * Pass a reference to the element where the Panel needs to be rendered\n * @default document.body\n */\n portalTarget?: HTMLElement;\n /**\n * A list of Refs to be considered as a part of the Lock. The html elements in the list will be accessible while the Panel is open.\n */\n shards?: ( HTMLElement | React.RefObject<HTMLElement> )[];\n /**\n * Optional callback function to call when panel is closed\n */\n onClose?: ( e: React.MouseEvent<HTMLDivElement> | KeyboardEvent ) => void;\n}\n\n// Compound component type with subcomponents attached\ntype TPanelCompoundComponent = React.ForwardRefExoticComponent<\n React.PropsWithoutRef<IPanelProps> & React.RefAttributes<HTMLDivElement>\n> & {\n Header: typeof PanelHeader;\n Body: typeof PanelBody;\n Footer: typeof PanelFooter;\n};\n\n// Create the base Panel component\nexport const Panel = React.forwardRef<HTMLDivElement, IPanelProps>(\n ({\n variant = "compact",\n showPanel = false,\n toggleVisibilityUsingCss = false,\n className,\n children,\n rtl,\n slideDirection = "right",\n portalTarget = typeof document !== "undefined" ? document.body : undefined,\n shards,\n onClose,\n ...props\n }, ref ) => {\n // In RTL mode, we invert the slide direction\n const effectiveSlideDirection = rtl\n ? ( slideDirection === "left" ? "right" : "left" )\n : slideDirection;\n const panelRef = React.useRef<HTMLDivElement>( null );\n const [ shouldRender, setShouldRender ] = React.useState( false );\n\n // Handle showing/hiding the panel\n React.useEffect(() => {\n if ( showPanel ) {\n setShouldRender( true );\n }\n\n // When toggleVisibilityUsingCss = false, this timeout hides the panel before the slide out animation ends.\n if ( shouldRender && !showPanel ) {\n setTimeout(() => setShouldRender( false ), 490 );\n }\n }, [ showPanel, shouldRender ]);\n\n // Handle escape key for closing\n React.useEffect(() => {\n // Esc key handling\n const handleEscClick = ( event: KeyboardEvent ) => event.code === "Escape" && onClose?.( event );\n\n const removeListener = () => {\n document.removeEventListener( "keydown", handleEscClick, false );\n };\n\n // Event Listener added for the keypress and click when component mounts\n if ( showPanel ) {\n document.addEventListener( "keydown", handleEscClick, false );\n } else {\n removeListener();\n }\n\n return () => {\n // Event Listener removed for the keypress and click when component unmounts\n removeListener();\n };\n }, [ showPanel, onClose ]);\n\n // Using CSS to control visibility\n if ( toggleVisibilityUsingCss ) {\n const { container, overlay, panel } = cssVisibilityVariants({\n direction: effectiveSlideDirection,\n variant,\n showPanel\n });\n\n return portalTarget ? ReactDOM.createPortal(\n <FocusOn\n as="div"\n enabled={showPanel}\n shards={shards}\n className={container()}\n >\n <div\n className={overlay()}\n onClick={onClose}\n id="panel-overlay"\n />\n\n {
|
|
3067
|
+
"content": 'import * as React from "react";\nimport ReactDOM from "react-dom";\nimport { FocusOn } from "react-focus-on";\n\nimport { usePartPresence } from "@hooks";\n\nimport { panelVariants, cssVisibilityVariants } from "./panelVariants";\nimport { PanelHeader } from "./panelHeader";\nimport { PanelBody } from "./panelBody";\nimport { PanelFooter } from "./panelFooter";\nimport { PanelContext } from "./panelContext";\n\nexport interface IPanelProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "dir"> {\n /**\n * Variant of the Panel\n * @default compact\n */\n variant?: "extended" | "compact";\n /**\n * Prop to control the panel display\n * @default false\n */\n showPanel?: boolean;\n /**\n * Toggle the visibility of the Panel without unmounting it\n * @default false\n */\n toggleVisibilityUsingCss?: boolean;\n /**\n * Overwrite the Panel styles by passing space separated class names\n */\n className?: string;\n /**\n * Accepts children of ReactNode type\n */\n children: React.ReactNode;\n /**\n * Direction from which the panel slides in\n * @default "right"\n */\n slideDirection?: "left" | "right";\n /**\n * If true, indicates that the app is in RTL (right-to-left) mode\n * When true in RTL mode, slideDirection="left" will make panel open from right\n * @default false\n */\n rtl?: boolean;\n /**\n * Pass a reference to the element where the Panel needs to be rendered\n * @default document.body\n */\n portalTarget?: HTMLElement;\n /**\n * A list of Refs to be considered as a part of the Lock. The html elements in the list will be accessible while the Panel is open.\n */\n shards?: ( HTMLElement | React.RefObject<HTMLElement> )[];\n /**\n * Optional callback function to call when panel is closed\n */\n onClose?: ( e: React.MouseEvent<HTMLDivElement> | KeyboardEvent ) => void;\n}\n\n// Compound component type with subcomponents attached\ntype TPanelCompoundComponent = React.ForwardRefExoticComponent<\n React.PropsWithoutRef<IPanelProps> & React.RefAttributes<HTMLDivElement>\n> & {\n Header: typeof PanelHeader;\n Body: typeof PanelBody;\n Footer: typeof PanelFooter;\n};\n\n// Create the base Panel component\nexport const Panel = React.forwardRef<HTMLDivElement, IPanelProps>(\n ({\n variant = "compact",\n showPanel = false,\n toggleVisibilityUsingCss = false,\n className,\n children,\n rtl,\n slideDirection = "right",\n portalTarget = typeof document !== "undefined" ? document.body : undefined,\n shards,\n onClose,\n "aria-label": ariaLabel,\n ...props\n }, ref ) => {\n // In RTL mode, we invert the slide direction\n const effectiveSlideDirection = rtl\n ? ( slideDirection === "left" ? "right" : "left" )\n : slideDirection;\n const panelRef = React.useRef<HTMLDivElement>( null );\n const [ shouldRender, setShouldRender ] = React.useState( false );\n const [ titleMounted, setTitleMounted ] = usePartPresence();\n const instanceId = React.useId();\n const contextValue = React.useMemo(() => ({\n titleId: `${instanceId}-title`,\n setTitleMounted\n }), [ instanceId, setTitleMounted ]);\n\n // Handle showing/hiding the panel\n React.useEffect(() => {\n if ( showPanel ) {\n setShouldRender( true );\n }\n\n // When toggleVisibilityUsingCss = false, this timeout hides the panel before the slide out animation ends.\n if ( shouldRender && !showPanel ) {\n setTimeout(() => setShouldRender( false ), 490 );\n }\n }, [ showPanel, shouldRender ]);\n\n // Handle escape key for closing\n React.useEffect(() => {\n // Esc key handling\n const handleEscClick = ( event: KeyboardEvent ) => event.code === "Escape" && onClose?.( event );\n\n const removeListener = () => {\n document.removeEventListener( "keydown", handleEscClick, false );\n };\n\n // Event Listener added for the keypress and click when component mounts\n if ( showPanel ) {\n document.addEventListener( "keydown", handleEscClick, false );\n } else {\n removeListener();\n }\n\n return () => {\n // Event Listener removed for the keypress and click when component unmounts\n removeListener();\n };\n }, [ showPanel, onClose ]);\n\n const renderDialog = ( panelClassName: string, extraProps: Record<string, string> = {}) => children && (\n <div\n id="panel"\n aria-modal="true"\n role="dialog"\n aria-label={ariaLabel}\n aria-labelledby={titleMounted && !ariaLabel ? contextValue.titleId : undefined}\n {...rtl ? { dir: "rtl" } : {}}\n {...extraProps}\n ref={ref || panelRef}\n className={panelClassName}\n {...props}\n >\n <PanelContext.Provider value={contextValue}>\n {children}\n </PanelContext.Provider>\n </div>\n );\n\n // Using CSS to control visibility\n if ( toggleVisibilityUsingCss ) {\n const { container, overlay, panel } = cssVisibilityVariants({\n direction: effectiveSlideDirection,\n variant,\n showPanel\n });\n\n return portalTarget ? ReactDOM.createPortal(\n <FocusOn\n as="div"\n enabled={showPanel}\n shards={shards}\n className={container()}\n >\n <div\n className={overlay()}\n onClick={onClose}\n id="panel-overlay"\n />\n\n {renderDialog(\n panel({ class: className }),\n // A closed panel stays mounted off-screen; inert keeps it out of the tab order and accessibility tree.\n // React 18 has no boolean inert prop, so the attribute is set as an empty string.\n showPanel ? {} : { inert: "" }\n )}\n </FocusOn>,\n portalTarget\n ) : null;\n } else {\n const panelAnimation = (\n showPanel\n ? `slideIn${effectiveSlideDirection === "right" ? "Right" : "Left"}`\n : `slideOut${effectiveSlideDirection === "right" ? "Right" : "Left"}`\n ) as "slideInRight" | "slideOutRight" | "slideInLeft" | "slideOutLeft";\n\n const { container } = panelVariants();\n const { overlay } = panelVariants({\n animation: showPanel ? "appear" : "disappear",\n visibility: showPanel ? "visible" : "hidden"\n });\n const { panel } = panelVariants({\n variant,\n animation: panelAnimation,\n visibility: "visible",\n direction: effectiveSlideDirection\n });\n\n return shouldRender && portalTarget ? ReactDOM.createPortal(\n <FocusOn\n as="div"\n enabled={showPanel}\n shards={shards}\n className={container()}\n >\n <div\n className={overlay()}\n onClick={onClose}\n id="panel-overlay"\n />\n\n {renderDialog( panel({ class: className }))}\n </FocusOn>,\n portalTarget\n ) : null;\n }\n }\n) as TPanelCompoundComponent;\n\nPanel.displayName = "Panel";\n\n// Attach the subcomponents\nPanel.Header = PanelHeader;\nPanel.Body = PanelBody;\nPanel.Footer = PanelFooter;\n'
|
|
2999
3068
|
},
|
|
3000
3069
|
{
|
|
3001
3070
|
"name": "index.ts",
|
|
@@ -3003,7 +3072,7 @@ PanelHeader.displayName = "PanelHeader";
|
|
|
3003
3072
|
},
|
|
3004
3073
|
{
|
|
3005
3074
|
"name": "README.md",
|
|
3006
|
-
"content": '# Panel Component\n\n## Component Overview\n\nThe Panel component provides a sliding side panel (drawer) that appears from the edge of the screen using React Portal. It\'s ideal for displaying secondary content, forms, and detailed information without navigating away. Uses a compound component pattern with Header, Body, and Footer subcomponents.\n\n**When to use:**\n- Displaying detailed information or forms without leaving the current page\n- Navigation drawers and sidebars\n- Settings and configuration panels\n- Multi-step workflows or wizards\n- Filtering and advanced search options\n\n**Component Architecture:**\n- Built with React compound component pattern (Panel.Header, Panel.Body, Panel.Footer)\n- Rendered via React Portal for proper z-index layering\n- Uses react-focus-on for focus management and accessibility\n- Styled with Tailwind CSS and class-variance-authority (cva)\n- Configurable slide direction: panel can slide from left or right\n- Two size variants: compact and extended\n- RTL (right-to-left) support with inverted slide direction\n- Overlay backdrop that triggers close when clicked\n\n## Basic Usage\n\n```tsx\nimport { Panel } from "@components";\nimport { Button } from "@components";\nimport { useState } from "react";\n\nexport function Example() {\n const [showPanel, setShowPanel] = useState(false);\n \n return (\n <>\n <Button onClick={() => setShowPanel(true)}>Open Panel</Button>\n \n <Panel \n showPanel={showPanel}\n onClose={() => setShowPanel(false)}\n >\n <Panel.Header \n header="Panel Title"\n subHeader="Panel description"\n showCloseButton\n onCloseHandler={() => setShowPanel(false)}\n />\n <Panel.Body>\n <p>Panel content goes here</p>\n </Panel.Body>\n <Panel.Footer>\n <Button onClick={() => setShowPanel(false)}>Close</Button>\n </Panel.Footer>\n </Panel>\n </>\n );\n}\n```\n\n**Note:** Update the import path based on your project structure. If you used the Astral UI CLI, the typical import path would be `@components/ui/panel` or `@components/panel`.\n\n## Component Props\n\n### Panel (Root Component)\n\n| Prop | Type | Default | Required | Description |\n|------|------|---------|----------|-------------|\n| `showPanel` | `boolean` | `false` | No | Controls the panel\'s visibility |\n| `children` | `React.ReactNode` | - | Yes | Panel content (Header, Body, and/or Footer components) |\n| `variant` | `\'extended\' \\| \'compact\'` | `\'compact\'` | No | Controls the width of the panel |\n| `slideDirection` | `\'left\' \\| \'right\'` | `\'right\'` | No | Direction from which the panel slides in |\n| `onClose` | `(e: React.MouseEvent \\| KeyboardEvent) => void` | `undefined` | No | Callback function invoked when panel should close (overlay click or ESC key) |\n| `toggleVisibilityUsingCss` | `boolean` | `false` | No | When true, hides panel with CSS instead of unmounting |\n| `rtl` | `boolean` | `false` | No | If true, inverts the slide direction and sets right-to-left layout |\n| `portalTarget` | `HTMLElement` | `document.body` | No | DOM element where the panel will be rendered |\n| `shards` | `(HTMLElement \\| React.RefObject<HTMLElement>)[]` | `undefined` | No | List of elements that remain accessible while panel is open |\n| `className` | `string` | `undefined` | No | Additional CSS classes for the panel container |\n\n### Panel.Header\n\nRenders the header section with optional title, buttons, and custom actions.\n\n| Prop | Type | Default | Required | Description |\n|------|------|---------|----------|-------------|\n| `header` | `string` | `undefined` | No | Main title text for the panel |\n| `subHeader` | `string` | `undefined` | No | Subtitle or description text |\n| `showBackButton` | `boolean` | `false` | No | Show a back button in the header |\n| `onBackHandler` | `() => void` | `undefined` | No | Callback for back button click |\n| `showCloseButton` | `boolean` | `false` | No | Show a close button in the header |\n| `onCloseHandler` | `() => void` | `undefined` | No | Callback for close button click |\n| `customCTA` | `React.ReactNode` | `undefined` | No | Custom action element in the header |\n| `className` | `string` | `undefined` | No | Additional CSS classes for header customization |\n\n### Panel.Body\n\nRenders the main content section of the panel.\n\n| Prop | Type | Default | Required | Description |\n|------|------|---------|----------|-------------|\n| `children` | `React.ReactNode` | `undefined` | No | Main content of the panel |\n| `className` | `string` | `undefined` | No | Additional CSS classes for body customization |\n\n### Panel.Footer\n\nRenders the footer section of the panel, typically for actions.\n\n| Prop | Type | Default | Required | Description |\n|------|------|---------|----------|-------------|\n| `children` | `React.ReactNode` | `undefined` | No | Footer content (typically action buttons) |\n| `className` | `string` | `undefined` | No | Additional CSS classes for footer customization |\n\n## Usage Patterns\n\n### Panel Variants\n\n```tsx\n// Compact panel (default) - narrower width\n<Panel \n showPanel={showPanel} \n variant="compact"\n onClose={() => setShowPanel(false)}\n>\n <Panel.Header header="Compact Panel" showCloseButton onCloseHandler={() => setShowPanel(false)} />\n <Panel.Body>Content here</Panel.Body>\n</Panel>\n\n// Extended panel - wider width for more content\n<Panel \n showPanel={showPanel} \n variant="extended"\n onClose={() => setShowPanel(false)}\n>\n <Panel.Header header="Extended Panel" showCloseButton onCloseHandler={() => setShowPanel(false)} />\n <Panel.Body>More content here</Panel.Body>\n</Panel>\n```\n\n### Slide Direction\n\n```tsx\n// Panel slides from right (default)\n<Panel \n showPanel={showPanel} \n slideDirection="right"\n onClose={() => setShowPanel(false)}\n>\n <Panel.Header \n header="Right Panel" \n showCloseButton \n onCloseHandler={() => setShowPanel(false)} \n />\n <Panel.Body>Slides from the right side</Panel.Body>\n</Panel>\n\n// Panel slides from left\n<Panel \n showPanel={showPanel} \n slideDirection="left"\n onClose={() => setShowPanel(false)}\n>\n <Panel.Header \n header="Left Panel" \n showCloseButton \n onCloseHandler={() => setShowPanel(false)} \n />\n <Panel.Body>Slides from the left side</Panel.Body>\n</Panel>\n```\n\n### RTL Support\n\nThe `rtl` prop inverts the slide direction and enables right-to-left text layout. This is useful for RTL languages like Arabic or Hebrew.\n\n```tsx\n// With rtl=true and slideDirection="left", panel will slide from RIGHT\n<Panel \n showPanel={showPanel} \n rtl={true} \n slideDirection="left"\n onClose={() => setShowPanel(false)}\n>\n <Panel.Header \n header="RTL Panel"\n showCloseButton\n onCloseHandler={() => setShowPanel(false)}\n />\n <Panel.Body>Content flows right-to-left</Panel.Body>\n</Panel>\n\n// With rtl=true and slideDirection="right", panel will slide from LEFT\n<Panel \n showPanel={showPanel} \n rtl={true} \n slideDirection="right"\n onClose={() => setShowPanel(false)}\n>\n <Panel.Header \n header="RTL Panel (inverted)" \n showCloseButton \n onCloseHandler={() => setShowPanel(false)} \n />\n <Panel.Body>Content in RTL mode</Panel.Body>\n</Panel>\n```\n\n**Note:** This component forwards refs to the container div element (`HTMLDivElement`).\n\n## Practical Examples\n\n### Form Panel\n\n```tsx\nimport { Panel } from "@components";\nimport { Button } from "@components";\nimport { TextField } from "@components";\nimport { useState } from "react";\n\nfunction EditUserPanel({ user, onSave }) {\n const [showPanel, setShowPanel] = useState(false);\n const [formData, setFormData] = useState(user);\n \n const handleSubmit = (e) => {\n e.preventDefault();\n onSave(formData);\n setShowPanel(false);\n };\n \n return (\n <>\n <Button onClick={() => setShowPanel(true)}>\n Edit User\n </Button>\n \n <Panel \n showPanel={showPanel} \n variant="compact"\n onClose={() => setShowPanel(false)}\n >\n <Panel.Header \n header="Edit User Profile"\n subHeader="Update user information"\n showCloseButton\n onCloseHandler={() => setShowPanel(false)}\n />\n <Panel.Body>\n <form onSubmit={handleSubmit} className="space-y-4">\n <TextField\n label="Full Name"\n value={formData.name}\n onChange={(e) => setFormData({...formData, name: e.target.value})}\n />\n <TextField\n label="Email"\n type="email"\n value={formData.email}\n onChange={(e) => setFormData({...formData, email: e.target.value})}\n />\n <TextField\n label="Role"\n value={formData.role}\n onChange={(e) => setFormData({...formData, role: e.target.value})}\n />\n </form>\n </Panel.Body>\n <Panel.Footer className="flex justify-end gap-2">\n <Button \n variant="outline" \n color="secondary"\n onClick={() => setShowPanel(false)}\n >\n Cancel\n </Button>\n <Button \n color="primary"\n onClick={handleSubmit}\n >\n Save Changes\n </Button>\n </Panel.Footer>\n </Panel>\n </>\n );\n}\n```\n\n### Multi-Step Panel with Navigation\n\n```tsx\nimport { Panel } from "@components";\nimport { Button } from "@components";\nimport { useState } from "react";\n\nfunction MultiStepPanel() {\n const [showPanel, setShowPanel] = useState(false);\n const [step, setStep] = useState(1);\n \n const handleBack = () => setStep(step - 1);\n const handleNext = () => setStep(step + 1);\n const handleFinish = () => {\n // Complete process\n setShowPanel(false);\n setStep(1);\n };\n \n return (\n <>\n <Button onClick={() => setShowPanel(true)}>\n Start Wizard\n </Button>\n \n <Panel \n showPanel={showPanel} \n variant="extended"\n onClose={() => {\n setShowPanel(false);\n setStep(1);\n }}\n >\n <Panel.Header \n header={`Step ${step} of 3`}\n subHeader="Complete all steps to finish"\n showBackButton={step > 1}\n onBackHandler={handleBack}\n showCloseButton\n onCloseHandler={() => {\n setShowPanel(false);\n setStep(1);\n }}\n />\n <Panel.Body>\n {step === 1 && <div>Step 1 content</div>}\n {step === 2 && <div>Step 2 content</div>}\n {step === 3 && <div>Step 3 content</div>}\n </Panel.Body>\n <Panel.Footer className="flex justify-between">\n <Button \n variant="outline"\n disabled={step === 1}\n onClick={handleBack}\n >\n Previous\n </Button>\n {step < 3 ? (\n <Button onClick={handleNext}>\n Next\n </Button>\n ) : (\n <Button color="primary" onClick={handleFinish}>\n Finish\n </Button>\n )}\n </Panel.Footer>\n </Panel>\n </>\n );\n}\n```\n\n### Details Panel with Custom Actions\n\n```tsx\nimport { Panel } from "@components";\nimport { Button } from "@components";\nimport { useState } from "react";\n\nfunction DetailsPanel({ item }) {\n const [showPanel, setShowPanel] = useState(false);\n \n const customActions = (\n <div className="flex gap-2">\n <Button variant="outline" size="sm" prefixIcon="share">\n Share\n </Button>\n <Button variant="outline" size="sm" prefixIcon="download">\n Download\n </Button>\n </div>\n );\n \n return (\n <>\n <Button variant="text" onClick={() => setShowPanel(true)}>\n View Details\n </Button>\n \n <Panel \n showPanel={showPanel} \n variant="extended"\n onClose={() => setShowPanel(false)}\n >\n <Panel.Header \n header={item.title}\n subHeader={`Created on ${item.createdDate}`}\n showCloseButton\n onCloseHandler={() => setShowPanel(false)}\n customCTA={customActions}\n />\n <Panel.Body className="space-y-6">\n <section>\n <h3 className="font-semibold mb-2">Overview</h3>\n <p>{item.description}</p>\n </section>\n \n <section>\n <h3 className="font-semibold mb-2">Details</h3>\n <dl className="grid grid-cols-2 gap-4">\n <div>\n <dt className="text-gray-500">Status</dt>\n <dd className="font-medium">{item.status}</dd>\n </div>\n <div>\n <dt className="text-gray-500">Priority</dt>\n <dd className="font-medium">{item.priority}</dd>\n </div>\n <div>\n <dt className="text-gray-500">Assignee</dt>\n <dd className="font-medium">{item.assignee}</dd>\n </div>\n <div>\n <dt className="text-gray-500">Due Date</dt>\n <dd className="font-medium">{item.dueDate}</dd>\n </div>\n </dl>\n </section>\n </Panel.Body>\n <Panel.Footer className="flex justify-end gap-2">\n <Button variant="outline" color="secondary">\n Edit\n </Button>\n <Button color="error">\n Delete\n </Button>\n </Panel.Footer>\n </Panel>\n </>\n );\n}\n```\n\n### Filter Panel\n\n```tsx\nimport { Panel } from "@components";\nimport { Button } from "@components";\nimport { Select } from "@components";\nimport { TextField } from "@components";\nimport { useState } from "react";\n\nfunction FilterPanel({ onApplyFilters }) {\n const [showPanel, setShowPanel] = useState(false);\n const [filters, setFilters] = useState({\n status: \'\',\n category: \'\',\n dateFrom: \'\',\n dateTo: \'\'\n });\n \n const handleApply = () => {\n onApplyFilters(filters);\n setShowPanel(false);\n };\n \n const handleReset = () => {\n setFilters({ status: \'\', category: \'\', dateFrom: \'\', dateTo: \'\' });\n };\n \n return (\n <>\n <Button \n variant="outline" \n prefixIcon="filter"\n onClick={() => setShowPanel(true)}\n >\n Filters\n </Button>\n \n <Panel \n showPanel={showPanel} \n variant="compact"\n onClose={() => setShowPanel(false)}\n >\n <Panel.Header \n header="Filter Options"\n showCloseButton\n onCloseHandler={() => setShowPanel(false)}\n />\n <Panel.Body className="space-y-4">\n <Select\n label="Status"\n value={filters.status}\n onChange={(value) => setFilters({...filters, status: value})}\n options={[\n { label: \'All\', value: \'\' },\n { label: \'Active\', value: \'active\' },\n { label: \'Inactive\', value: \'inactive\' }\n ]}\n />\n <Select\n label="Category"\n value={filters.category}\n onChange={(value) => setFilters({...filters, category: value})}\n options={[\n { label: \'All\', value: \'\' },\n { label: \'Type A\', value: \'a\' },\n { label: \'Type B\', value: \'b\' }\n ]}\n />\n <TextField\n label="From Date"\n type="date"\n value={filters.dateFrom}\n onChange={(e) => setFilters({...filters, dateFrom: e.target.value})}\n />\n <TextField\n label="To Date"\n type="date"\n value={filters.dateTo}\n onChange={(e) => setFilters({...filters, dateTo: e.target.value})}\n />\n </Panel.Body>\n <Panel.Footer className="flex justify-between">\n <Button variant="text" color="secondary" onClick={handleReset}>\n Reset\n </Button>\n <div className="flex gap-2">\n <Button variant="outline" onClick={() => setShowPanel(false)}>\n Cancel\n </Button>\n <Button color="primary" onClick={handleApply}>\n Apply Filters\n </Button>\n </div>\n </Panel.Footer>\n </Panel>\n </>\n );\n}\n```\n\n### Settings Panel\n\n```tsx\nimport { Panel } from "@components";\nimport { Button } from "@components";\nimport { Toggle } from "@components";\nimport { Select } from "@components";\nimport { useState } from "react";\n\nfunction SettingsPanel() {\n const [showPanel, setShowPanel] = useState(false);\n const [settings, setSettings] = useState({\n notifications: true,\n theme: \'light\',\n language: \'en\',\n autoSave: false\n });\n \n const handleSave = () => {\n // Save settings\n localStorage.setItem(\'settings\', JSON.stringify(settings));\n setShowPanel(false);\n };\n \n return (\n <>\n <Button variant="outline" prefixIcon="settings" onClick={() => setShowPanel(true)}>\n Settings\n </Button>\n \n <Panel showPanel={showPanel} variant="compact" onClose={() => setShowPanel(false)}>\n <Panel.Header \n header="Application Settings"\n showCloseButton\n onCloseHandler={() => setShowPanel(false)}\n />\n <Panel.Body className="space-y-6">\n <div>\n <h3 className="font-semibold mb-3">Preferences</h3>\n <div className="space-y-3">\n <div className="flex items-center justify-between">\n <label>Enable Notifications</label>\n <Toggle\n checked={settings.notifications}\n onChange={(checked) => setSettings({...settings, notifications: checked})}\n />\n </div>\n <div className="flex items-center justify-between">\n <label>Auto Save</label>\n <Toggle\n checked={settings.autoSave}\n onChange={(checked) => setSettings({...settings, autoSave: checked})}\n />\n </div>\n </div>\n </div>\n \n <div>\n <h3 className="font-semibold mb-3">Appearance</h3>\n <Select\n label="Theme"\n value={settings.theme}\n onChange={(value) => setSettings({...settings, theme: value})}\n options={[\n { label: \'Light\', value: \'light\' },\n { label: \'Dark\', value: \'dark\' },\n { label: \'System\', value: \'system\' }\n ]}\n />\n </div>\n \n <div>\n <h3 className="font-semibold mb-3">Language</h3>\n <Select\n label="Language"\n value={settings.language}\n onChange={(value) => setSettings({...settings, language: value})}\n options={[\n { label: \'English\', value: \'en\' },\n { label: \'Spanish\', value: \'es\' },\n { label: \'French\', value: \'fr\' }\n ]}\n />\n </div>\n </Panel.Body>\n <Panel.Footer className="flex justify-end gap-2">\n <Button variant="outline" onClick={() => setShowPanel(false)}>\n Cancel\n </Button>\n <Button color="primary" onClick={handleSave}>\n Save Settings\n </Button>\n </Panel.Footer>\n </Panel>\n </>\n );\n}\n```\n\n## Styling and Customization\n\nUse the `className` prop for custom panel styling:\n\n```tsx\n<Panel \n showPanel={showPanel}\n variant="extended"\n className="custom-panel-styles"\n>\n <Panel.Header \n header="Custom Styled Panel"\n className="bg-blue-50 border-b-2"\n />\n <Panel.Body className="p-8">\n Custom body styling\n </Panel.Body>\n <Panel.Footer className="bg-gray-50">\n Custom footer\n </Panel.Footer>\n</Panel>\n```\n\n## Technical Details\n\n### Portal Rendering\n\n- Panel is rendered outside the normal DOM hierarchy using React Portal\n- Default portal target is `document.body`\n- Custom portal target can be specified via `portalTarget` prop\n- Ensures proper z-index layering above all other content\n\n### Focus Management\n\n- Uses react-focus-on for focus trapping\n- Focus automatically moves to close button when panel opens\n- Tab key cycles through interactive elements within panel\n- Focus returns to trigger element when panel closes\n- Shards prop allows specified elements to remain accessible\n\n### Animation and Performance\n\n- Smooth slide-in/slide-out CSS transitions\n- `toggleVisibilityUsingCss` keeps panel mounted for faster re-opening\n- Without this flag, panel unmounts after closing (better for memory)\n\n### User Interaction\n\n**Keyboard:**\n- ESC key closes panel (triggers `onClose` callback)\n- Tab key navigates through interactive elements\n- Shift+Tab navigates backwards\n\n**Mouse:**\n- Clicking the overlay backdrop closes panel (triggers `onClose` callback)\n- Close button in header (if enabled) closes panel\n\n## Accessibility\n\nThe component includes built-in accessibility features:\n\n**Implemented:**\n- ARIA attributes for screen readers\n- Focus trapping prevents tabbing outside the panel\n- ESC key support for closing\n- Close button has proper ARIA labels\n- Portal rendering ensures proper screen reader announcement\n- Auto-focus on close button for immediate keyboard access\n- Background scroll locking via react-focus-on\n\n**Best Practices:**\n- Always provide a Panel.Header for context\n- Use descriptive header text\n- Ensure panel content is keyboard navigable\n- Provide clear action buttons for closing or completing panel flow\n- Test with keyboard navigation (Tab, Shift+Tab, ESC, Enter)\n- Test with screen readers to verify announcements\n- Consider using `variant="extended"` for content-heavy panels\n'
|
|
3075
|
+
"content": '# Panel Component\n\n## Component Overview\n\nThe Panel component provides a sliding side panel (drawer) that appears from the edge of the screen using React Portal. It\'s ideal for displaying secondary content, forms, and detailed information without navigating away. Uses a compound component pattern with Header, Body, and Footer subcomponents.\n\n**When to use:**\n- Displaying detailed information or forms without leaving the current page\n- Navigation drawers and sidebars\n- Settings and configuration panels\n- Multi-step workflows or wizards\n- Filtering and advanced search options\n\n**Component Architecture:**\n- Built with React compound component pattern (Panel.Header, Panel.Body, Panel.Footer)\n- Rendered via React Portal for proper z-index layering\n- Uses react-focus-on for focus management and accessibility\n- Styled with Tailwind CSS and class-variance-authority (cva)\n- Configurable slide direction: panel can slide from left or right\n- Two size variants: compact and extended\n- RTL (right-to-left) support with inverted slide direction\n- Overlay backdrop that triggers close when clicked\n\n## Basic Usage\n\n```tsx\nimport { Panel } from "@components";\nimport { Button } from "@components";\nimport { useState } from "react";\n\nexport function Example() {\n const [showPanel, setShowPanel] = useState(false);\n \n return (\n <>\n <Button onClick={() => setShowPanel(true)}>Open Panel</Button>\n \n <Panel \n showPanel={showPanel}\n onClose={() => setShowPanel(false)}\n >\n <Panel.Header \n header="Panel Title"\n subHeader="Panel description"\n showCloseButton\n onCloseHandler={() => setShowPanel(false)}\n />\n <Panel.Body>\n <p>Panel content goes here</p>\n </Panel.Body>\n <Panel.Footer>\n <Button onClick={() => setShowPanel(false)}>Close</Button>\n </Panel.Footer>\n </Panel>\n </>\n );\n}\n```\n\n**Note:** Update the import path based on your project structure. If you used the Astral UI CLI, the typical import path would be `@components/ui/panel` or `@components/panel`.\n\n## Component Props\n\n### Panel (Root Component)\n\n| Prop | Type | Default | Required | Description |\n|------|------|---------|----------|-------------|\n| `showPanel` | `boolean` | `false` | No | Controls the panel\'s visibility |\n| `children` | `React.ReactNode` | - | Yes | Panel content (Header, Body, and/or Footer components) |\n| `variant` | `\'extended\' \\| \'compact\'` | `\'compact\'` | No | Controls the width of the panel |\n| `slideDirection` | `\'left\' \\| \'right\'` | `\'right\'` | No | Direction from which the panel slides in |\n| `onClose` | `(e: React.MouseEvent \\| KeyboardEvent) => void` | `undefined` | No | Callback function invoked when panel should close (overlay click or ESC key) |\n| `toggleVisibilityUsingCss` | `boolean` | `false` | No | When true, hides panel with CSS instead of unmounting |\n| `rtl` | `boolean` | `false` | No | If true, inverts the slide direction and sets right-to-left layout |\n| `portalTarget` | `HTMLElement` | `document.body` | No | DOM element where the panel will be rendered |\n| `shards` | `(HTMLElement \\| React.RefObject<HTMLElement>)[]` | `undefined` | No | List of elements that remain accessible while panel is open |\n| `className` | `string` | `undefined` | No | Additional CSS classes for the panel container |\n| `aria-label` | `string` | `undefined` | No | Accessible name for the panel. Overrides the name taken from `Panel.Header`\'s `header`; required when the panel has no `header` |\n\n### Panel.Header\n\nRenders the header section with optional title, buttons, and custom actions.\n\n| Prop | Type | Default | Required | Description |\n|------|------|---------|----------|-------------|\n| `header` | `string` | `undefined` | No | Main title text for the panel. Rendered as an `<h2>` and used as the dialog\'s accessible name |\n| `subHeader` | `string` | `undefined` | No | Subtitle or description text |\n| `showBackButton` | `boolean` | `false` | No | Show a back button in the header |\n| `onBackHandler` | `() => void` | `undefined` | No | Callback for back button click |\n| `showCloseButton` | `boolean` | `false` | No | Show a close button in the header |\n| `onCloseHandler` | `() => void` | `undefined` | No | Callback for close button click |\n| `customCTA` | `React.ReactNode` | `undefined` | No | Custom action element in the header |\n| `className` | `string` | `undefined` | No | Additional CSS classes for header customization |\n\n### Panel.Body\n\nRenders the main content section of the panel.\n\n| Prop | Type | Default | Required | Description |\n|------|------|---------|----------|-------------|\n| `children` | `React.ReactNode` | `undefined` | No | Main content of the panel |\n| `className` | `string` | `undefined` | No | Additional CSS classes for body customization |\n\n### Panel.Footer\n\nRenders the footer section of the panel, typically for actions.\n\n| Prop | Type | Default | Required | Description |\n|------|------|---------|----------|-------------|\n| `children` | `React.ReactNode` | `undefined` | No | Footer content (typically action buttons) |\n| `className` | `string` | `undefined` | No | Additional CSS classes for footer customization |\n\n## Usage Patterns\n\n### Panel Variants\n\n```tsx\n// Compact panel (default) - narrower width\n<Panel \n showPanel={showPanel} \n variant="compact"\n onClose={() => setShowPanel(false)}\n>\n <Panel.Header header="Compact Panel" showCloseButton onCloseHandler={() => setShowPanel(false)} />\n <Panel.Body>Content here</Panel.Body>\n</Panel>\n\n// Extended panel - wider width for more content\n<Panel \n showPanel={showPanel} \n variant="extended"\n onClose={() => setShowPanel(false)}\n>\n <Panel.Header header="Extended Panel" showCloseButton onCloseHandler={() => setShowPanel(false)} />\n <Panel.Body>More content here</Panel.Body>\n</Panel>\n```\n\n### Slide Direction\n\n```tsx\n// Panel slides from right (default)\n<Panel \n showPanel={showPanel} \n slideDirection="right"\n onClose={() => setShowPanel(false)}\n>\n <Panel.Header \n header="Right Panel" \n showCloseButton \n onCloseHandler={() => setShowPanel(false)} \n />\n <Panel.Body>Slides from the right side</Panel.Body>\n</Panel>\n\n// Panel slides from left\n<Panel \n showPanel={showPanel} \n slideDirection="left"\n onClose={() => setShowPanel(false)}\n>\n <Panel.Header \n header="Left Panel" \n showCloseButton \n onCloseHandler={() => setShowPanel(false)} \n />\n <Panel.Body>Slides from the left side</Panel.Body>\n</Panel>\n```\n\n### RTL Support\n\nThe `rtl` prop inverts the slide direction and enables right-to-left text layout. This is useful for RTL languages like Arabic or Hebrew.\n\n```tsx\n// With rtl=true and slideDirection="left", panel will slide from RIGHT\n<Panel \n showPanel={showPanel} \n rtl={true} \n slideDirection="left"\n onClose={() => setShowPanel(false)}\n>\n <Panel.Header \n header="RTL Panel"\n showCloseButton\n onCloseHandler={() => setShowPanel(false)}\n />\n <Panel.Body>Content flows right-to-left</Panel.Body>\n</Panel>\n\n// With rtl=true and slideDirection="right", panel will slide from LEFT\n<Panel \n showPanel={showPanel} \n rtl={true} \n slideDirection="right"\n onClose={() => setShowPanel(false)}\n>\n <Panel.Header \n header="RTL Panel (inverted)" \n showCloseButton \n onCloseHandler={() => setShowPanel(false)} \n />\n <Panel.Body>Content in RTL mode</Panel.Body>\n</Panel>\n```\n\n**Note:** This component forwards refs to the container div element (`HTMLDivElement`).\n\n## Practical Examples\n\n### Form Panel\n\n```tsx\nimport { Panel } from "@components";\nimport { Button } from "@components";\nimport { TextField } from "@components";\nimport { useState } from "react";\n\nfunction EditUserPanel({ user, onSave }) {\n const [showPanel, setShowPanel] = useState(false);\n const [formData, setFormData] = useState(user);\n \n const handleSubmit = (e) => {\n e.preventDefault();\n onSave(formData);\n setShowPanel(false);\n };\n \n return (\n <>\n <Button onClick={() => setShowPanel(true)}>\n Edit User\n </Button>\n \n <Panel \n showPanel={showPanel} \n variant="compact"\n onClose={() => setShowPanel(false)}\n >\n <Panel.Header \n header="Edit User Profile"\n subHeader="Update user information"\n showCloseButton\n onCloseHandler={() => setShowPanel(false)}\n />\n <Panel.Body>\n <form onSubmit={handleSubmit} className="space-y-4">\n <TextField\n label="Full Name"\n value={formData.name}\n onChange={(e) => setFormData({...formData, name: e.target.value})}\n />\n <TextField\n label="Email"\n type="email"\n value={formData.email}\n onChange={(e) => setFormData({...formData, email: e.target.value})}\n />\n <TextField\n label="Role"\n value={formData.role}\n onChange={(e) => setFormData({...formData, role: e.target.value})}\n />\n </form>\n </Panel.Body>\n <Panel.Footer className="flex justify-end gap-2">\n <Button \n variant="outline" \n color="secondary"\n onClick={() => setShowPanel(false)}\n >\n Cancel\n </Button>\n <Button \n color="primary"\n onClick={handleSubmit}\n >\n Save Changes\n </Button>\n </Panel.Footer>\n </Panel>\n </>\n );\n}\n```\n\n### Multi-Step Panel with Navigation\n\n```tsx\nimport { Panel } from "@components";\nimport { Button } from "@components";\nimport { useState } from "react";\n\nfunction MultiStepPanel() {\n const [showPanel, setShowPanel] = useState(false);\n const [step, setStep] = useState(1);\n \n const handleBack = () => setStep(step - 1);\n const handleNext = () => setStep(step + 1);\n const handleFinish = () => {\n // Complete process\n setShowPanel(false);\n setStep(1);\n };\n \n return (\n <>\n <Button onClick={() => setShowPanel(true)}>\n Start Wizard\n </Button>\n \n <Panel \n showPanel={showPanel} \n variant="extended"\n onClose={() => {\n setShowPanel(false);\n setStep(1);\n }}\n >\n <Panel.Header \n header={`Step ${step} of 3`}\n subHeader="Complete all steps to finish"\n showBackButton={step > 1}\n onBackHandler={handleBack}\n showCloseButton\n onCloseHandler={() => {\n setShowPanel(false);\n setStep(1);\n }}\n />\n <Panel.Body>\n {step === 1 && <div>Step 1 content</div>}\n {step === 2 && <div>Step 2 content</div>}\n {step === 3 && <div>Step 3 content</div>}\n </Panel.Body>\n <Panel.Footer className="flex justify-between">\n <Button \n variant="outline"\n disabled={step === 1}\n onClick={handleBack}\n >\n Previous\n </Button>\n {step < 3 ? (\n <Button onClick={handleNext}>\n Next\n </Button>\n ) : (\n <Button color="primary" onClick={handleFinish}>\n Finish\n </Button>\n )}\n </Panel.Footer>\n </Panel>\n </>\n );\n}\n```\n\n### Details Panel with Custom Actions\n\n```tsx\nimport { Panel } from "@components";\nimport { Button } from "@components";\nimport { useState } from "react";\n\nfunction DetailsPanel({ item }) {\n const [showPanel, setShowPanel] = useState(false);\n \n const customActions = (\n <div className="flex gap-2">\n <Button variant="outline" size="sm" prefixIcon="share">\n Share\n </Button>\n <Button variant="outline" size="sm" prefixIcon="download">\n Download\n </Button>\n </div>\n );\n \n return (\n <>\n <Button variant="text" onClick={() => setShowPanel(true)}>\n View Details\n </Button>\n \n <Panel \n showPanel={showPanel} \n variant="extended"\n onClose={() => setShowPanel(false)}\n >\n <Panel.Header \n header={item.title}\n subHeader={`Created on ${item.createdDate}`}\n showCloseButton\n onCloseHandler={() => setShowPanel(false)}\n customCTA={customActions}\n />\n <Panel.Body className="space-y-6">\n <section>\n <h3 className="font-semibold mb-2">Overview</h3>\n <p>{item.description}</p>\n </section>\n \n <section>\n <h3 className="font-semibold mb-2">Details</h3>\n <dl className="grid grid-cols-2 gap-4">\n <div>\n <dt className="text-gray-500">Status</dt>\n <dd className="font-medium">{item.status}</dd>\n </div>\n <div>\n <dt className="text-gray-500">Priority</dt>\n <dd className="font-medium">{item.priority}</dd>\n </div>\n <div>\n <dt className="text-gray-500">Assignee</dt>\n <dd className="font-medium">{item.assignee}</dd>\n </div>\n <div>\n <dt className="text-gray-500">Due Date</dt>\n <dd className="font-medium">{item.dueDate}</dd>\n </div>\n </dl>\n </section>\n </Panel.Body>\n <Panel.Footer className="flex justify-end gap-2">\n <Button variant="outline" color="secondary">\n Edit\n </Button>\n <Button color="error">\n Delete\n </Button>\n </Panel.Footer>\n </Panel>\n </>\n );\n}\n```\n\n### Filter Panel\n\n```tsx\nimport { Panel } from "@components";\nimport { Button } from "@components";\nimport { Select } from "@components";\nimport { TextField } from "@components";\nimport { useState } from "react";\n\nfunction FilterPanel({ onApplyFilters }) {\n const [showPanel, setShowPanel] = useState(false);\n const [filters, setFilters] = useState({\n status: \'\',\n category: \'\',\n dateFrom: \'\',\n dateTo: \'\'\n });\n \n const handleApply = () => {\n onApplyFilters(filters);\n setShowPanel(false);\n };\n \n const handleReset = () => {\n setFilters({ status: \'\', category: \'\', dateFrom: \'\', dateTo: \'\' });\n };\n \n return (\n <>\n <Button \n variant="outline" \n prefixIcon="filter"\n onClick={() => setShowPanel(true)}\n >\n Filters\n </Button>\n \n <Panel \n showPanel={showPanel} \n variant="compact"\n onClose={() => setShowPanel(false)}\n >\n <Panel.Header \n header="Filter Options"\n showCloseButton\n onCloseHandler={() => setShowPanel(false)}\n />\n <Panel.Body className="space-y-4">\n <Select\n label="Status"\n value={filters.status}\n onChange={(value) => setFilters({...filters, status: value})}\n options={[\n { label: \'All\', value: \'\' },\n { label: \'Active\', value: \'active\' },\n { label: \'Inactive\', value: \'inactive\' }\n ]}\n />\n <Select\n label="Category"\n value={filters.category}\n onChange={(value) => setFilters({...filters, category: value})}\n options={[\n { label: \'All\', value: \'\' },\n { label: \'Type A\', value: \'a\' },\n { label: \'Type B\', value: \'b\' }\n ]}\n />\n <TextField\n label="From Date"\n type="date"\n value={filters.dateFrom}\n onChange={(e) => setFilters({...filters, dateFrom: e.target.value})}\n />\n <TextField\n label="To Date"\n type="date"\n value={filters.dateTo}\n onChange={(e) => setFilters({...filters, dateTo: e.target.value})}\n />\n </Panel.Body>\n <Panel.Footer className="flex justify-between">\n <Button variant="text" color="secondary" onClick={handleReset}>\n Reset\n </Button>\n <div className="flex gap-2">\n <Button variant="outline" onClick={() => setShowPanel(false)}>\n Cancel\n </Button>\n <Button color="primary" onClick={handleApply}>\n Apply Filters\n </Button>\n </div>\n </Panel.Footer>\n </Panel>\n </>\n );\n}\n```\n\n### Settings Panel\n\n```tsx\nimport { Panel } from "@components";\nimport { Button } from "@components";\nimport { Toggle } from "@components";\nimport { Select } from "@components";\nimport { useState } from "react";\n\nfunction SettingsPanel() {\n const [showPanel, setShowPanel] = useState(false);\n const [settings, setSettings] = useState({\n notifications: true,\n theme: \'light\',\n language: \'en\',\n autoSave: false\n });\n \n const handleSave = () => {\n // Save settings\n localStorage.setItem(\'settings\', JSON.stringify(settings));\n setShowPanel(false);\n };\n \n return (\n <>\n <Button variant="outline" prefixIcon="settings" onClick={() => setShowPanel(true)}>\n Settings\n </Button>\n \n <Panel showPanel={showPanel} variant="compact" onClose={() => setShowPanel(false)}>\n <Panel.Header \n header="Application Settings"\n showCloseButton\n onCloseHandler={() => setShowPanel(false)}\n />\n <Panel.Body className="space-y-6">\n <div>\n <h3 className="font-semibold mb-3">Preferences</h3>\n <div className="space-y-3">\n <div className="flex items-center justify-between">\n <label>Enable Notifications</label>\n <Toggle\n checked={settings.notifications}\n onChange={(checked) => setSettings({...settings, notifications: checked})}\n />\n </div>\n <div className="flex items-center justify-between">\n <label>Auto Save</label>\n <Toggle\n checked={settings.autoSave}\n onChange={(checked) => setSettings({...settings, autoSave: checked})}\n />\n </div>\n </div>\n </div>\n \n <div>\n <h3 className="font-semibold mb-3">Appearance</h3>\n <Select\n label="Theme"\n value={settings.theme}\n onChange={(value) => setSettings({...settings, theme: value})}\n options={[\n { label: \'Light\', value: \'light\' },\n { label: \'Dark\', value: \'dark\' },\n { label: \'System\', value: \'system\' }\n ]}\n />\n </div>\n \n <div>\n <h3 className="font-semibold mb-3">Language</h3>\n <Select\n label="Language"\n value={settings.language}\n onChange={(value) => setSettings({...settings, language: value})}\n options={[\n { label: \'English\', value: \'en\' },\n { label: \'Spanish\', value: \'es\' },\n { label: \'French\', value: \'fr\' }\n ]}\n />\n </div>\n </Panel.Body>\n <Panel.Footer className="flex justify-end gap-2">\n <Button variant="outline" onClick={() => setShowPanel(false)}>\n Cancel\n </Button>\n <Button color="primary" onClick={handleSave}>\n Save Settings\n </Button>\n </Panel.Footer>\n </Panel>\n </>\n );\n}\n```\n\n## Styling and Customization\n\nUse the `className` prop for custom panel styling:\n\n```tsx\n<Panel \n showPanel={showPanel}\n variant="extended"\n className="custom-panel-styles"\n>\n <Panel.Header \n header="Custom Styled Panel"\n className="bg-blue-50 border-b-2"\n />\n <Panel.Body className="p-8">\n Custom body styling\n </Panel.Body>\n <Panel.Footer className="bg-gray-50">\n Custom footer\n </Panel.Footer>\n</Panel>\n```\n\n## Technical Details\n\n### Portal Rendering\n\n- Panel is rendered outside the normal DOM hierarchy using React Portal\n- Default portal target is `document.body`\n- Custom portal target can be specified via `portalTarget` prop\n- Ensures proper z-index layering above all other content\n\n### Focus Management\n\n- Uses react-focus-on for focus trapping\n- Focus moves to the first focusable element when the panel opens. Add `data-autofocus` to another element to start there instead\n- Tab key cycles through interactive elements within panel\n- Focus returns to trigger element when panel closes\n- Shards prop allows specified elements to remain accessible\n\n### Animation and Performance\n\n- Smooth slide-in/slide-out CSS transitions\n- `toggleVisibilityUsingCss` keeps panel mounted for faster re-opening\n- Without this flag, panel unmounts after closing (better for memory)\n\n### User Interaction\n\n**Keyboard:**\n- ESC key closes panel (triggers `onClose` callback)\n- Tab key navigates through interactive elements\n- Shift+Tab navigates backwards\n\n**Mouse:**\n- Clicking the overlay backdrop closes panel (triggers `onClose` callback)\n- Close button in header (if enabled) closes panel\n\n## Accessibility\n\nThe component includes built-in accessibility features:\n\n**Implemented:**\n- ARIA attributes for screen readers\n- The dialog is named by the `Panel.Header` `header` (an `<h2>`) through a per-instance `aria-labelledby`, or by `aria-label` when passed\n- With `toggleVisibilityUsingCss`, a closed panel is `inert`, so its content is out of the tab order and the accessibility tree\n- Below the `md` breakpoint the compact variant widens to the viewport minus its margins, so content reflows at 320px. A `w-*` class passed through `className` still overrides the width at `md` and above\n- Focus trapping prevents tabbing outside the panel\n- ESC key support for closing\n- Close button has proper ARIA labels\n- Portal rendering ensures proper screen reader announcement\n- Initial focus goes to the first focusable element, or to an element marked `data-autofocus`, in both display modes\n- Background scroll locking via react-focus-on\n\n**Best Practices:**\n- Always provide a Panel.Header with `header`, or pass `aria-label` to `Panel`, so the dialog has a name\n- Use descriptive header text\n- Ensure panel content is keyboard navigable\n- Provide clear action buttons for closing or completing panel flow\n- Test with keyboard navigation (Tab, Shift+Tab, ESC, Enter)\n- Test with screen readers to verify announcements\n- Consider using `variant="extended"` for content-heavy panels\n'
|
|
3007
3076
|
}
|
|
3008
3077
|
],
|
|
3009
3078
|
"directories": []
|