@stackone/malachite 2.89.1 → 2.90.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/COMPONENTS.md +3 -2
- package/dist/components/FormActions.js +40 -0
- package/dist/components/FormActions.js.map +1 -0
- package/dist/components/SidePanel.js +124 -104
- package/dist/components/SidePanel.js.map +1 -1
- package/dist/components/Tabs.js +55 -28
- package/dist/components/Tabs.js.map +1 -1
- package/dist/index.d.ts +51 -0
- package/dist/index.js +368 -366
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SidePanel.js","sources":["../../src/components/SidePanel.tsx"],"sourcesContent":["import React, { useEffect, useId, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { ShadowRootWrapper } from '../ShadowRootWrapper';\nimport type { AlertType } from './Alert';\nimport CalloutStrip from './CalloutStrip';\nimport ArrowLeftIcon from './CustomIcons/ArrowLeftIcon';\nimport DismissIcon from './CustomIcons/DismissIcon';\nimport type { RenderLink } from './PageLayout/types';\nimport EllipsisText from './Typography/EllipsisText';\nimport { OVERLAY_ICON_BUTTON_CLASSES, useOverlayBehaviour } from './overlayBehaviour';\nimport { OVERLAY_ELEVATED_ATTR, overlayIdentity } from './portalOverlay';\n\nexport interface SidePanelProps {\n open: boolean;\n /** Dismiss handler — close button, ESC, or overlay click. */\n onClose: () => void;\n title: React.ReactNode;\n subtitle?: React.ReactNode;\n /** `below` stacks the subtitle under the title, so neither truncates the other. */\n subtitlePlacement?: 'inline' | 'below';\n /** Content at the end of the title row, after the subtitle (e.g. a status tag). */\n titleExtra?: React.ReactNode;\n /** Block paragraph below the title row, spanning the header width. Announced as the panel's description. */\n description?: React.ReactNode;\n /** Pinned between the header and the scrolling body. */\n toolbar?: React.ReactNode;\n /** Divider under the header. Default: false. */\n headerDivider?: boolean;\n /** Leading header slot, typically a logo or icon. */\n icon?: React.ReactNode;\n /** Content pinned right in the header, before the close button. */\n headerExtra?: React.ReactNode;\n footer?: React.ReactNode;\n /** Renders a back button before the header icon. */\n onBack?: () => void;\n /** Maximum panel width. Default: 1080. */\n maxWidth?: number | string;\n /** Accessible dialog name; required when `title` isn't a plain string. */\n 'aria-label'?: string;\n /** ID of a visible element naming the dialog (alternative to `aria-label`). */\n 'aria-labelledby'?: string;\n /** Whether the body gets default padding. Default: true. */\n bodyPadding?: boolean;\n /** `above-app-overlays` lifts the overlay stack clear of chrome pinned near max-int. */\n stacking?: 'default' | 'above-app-overlays';\n /** Full-width Alert bands at the top of the body, above `children`, in order. Unaffected by\n * `bodyPadding`, and announced ahead of `description`. The message is markdown. */\n callouts?: { type?: AlertType; message: string }[];\n /** Routes root-relative links in `callouts` through the app's router; see `MarkdownBlock`. */\n renderLink?: RenderLink;\n /** A full-height column opened to the left, as wide again as `maxWidth`. The panel's own\n * header, body and footer keep their width and place; the aside's header and footer line\n * up with them. The aside is never narrower than 360px: a window too narrow for both\n * columns scrolls the panel sideways. */\n aside?: SidePanelAside;\n children: React.ReactNode;\n}\n\nexport interface SidePanelAside {\n /** Shown in the aside's header, and names the column for assistive tech. */\n title: string;\n /** Content pinned right in the aside's header (e.g. a stepper). */\n headerExtra?: React.ReactNode;\n /** Pinned at the bottom, level with the panel's footer. */\n footer?: React.ReactNode;\n /** Whether the aside's body gets default padding, as the panel's `bodyPadding`. Default: true. */\n bodyPadding?: boolean;\n children: React.ReactNode;\n}\n\nconst TRANSITION_MS = 200;\nconst ASIDE_MIN_WIDTH = '360px';\n\ninterface ScrollingBodyProps {\n bodyPadding: boolean;\n callouts?: { type?: AlertType; message: string }[];\n /** Prefix for each callout's id, which the panel names in `aria-describedby`. */\n calloutId?: string;\n renderLink?: RenderLink;\n children: React.ReactNode;\n}\n\nconst ScrollingBody: React.FC<ScrollingBodyProps> = ({\n bodyPadding,\n callouts,\n calloutId,\n renderLink,\n children,\n}) => {\n const hasCallouts = !!callouts?.length;\n\n // Callouts move the horizontal padding inward so their strips run full-bleed.\n return (\n <div\n className={`min-h-0 flex-1 overflow-y-auto ${bodyPadding && !hasCallouts ? 'px-[28px]' : ''}`}\n >\n {callouts?.map((callout, index) => (\n <CalloutStrip\n key={index}\n id={calloutId ? `${calloutId}-${index}` : undefined}\n type={callout.type}\n message={callout.message}\n renderLink={renderLink}\n />\n ))}\n {bodyPadding ? (\n <div className={hasCallouts ? 'p-[28px]' : 'py-[28px]'}>{children}</div>\n ) : (\n children\n )}\n </div>\n );\n};\n\nconst toCssSize = (value: number | string): string =>\n typeof value === 'number' ? `${value}px` : value;\n\n/**\n * A right-hand slide-in overlay panel (drawer) for inspecting or editing an entity\n * without leaving the page. Portals to `document.body`, locks background scroll and\n * traps keyboard focus while open (restoring both on close), dismisses on ESC\n * (topmost open overlay only), overlay click or the close button, and exposes header\n * (back/icon/title/subtitle/extra), scrollable body and optional footer slots.\n */\nconst SidePanel: React.FC<SidePanelProps> = ({\n open,\n onClose,\n title,\n subtitle,\n subtitlePlacement = 'inline',\n titleExtra,\n description,\n toolbar,\n headerDivider = false,\n icon,\n headerExtra,\n footer,\n onBack,\n maxWidth = 1080,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n bodyPadding = true,\n stacking = 'default',\n callouts,\n renderLink,\n aside,\n children,\n}) => {\n const calloutId = useId();\n const descriptionId = useId();\n const [isVisible, setIsVisible] = useState(false);\n const [isMounted, setIsMounted] = useState(false);\n const frameRef = useRef<number | null>(null);\n const unmountTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const hostRef = useRef<HTMLDivElement | null>(null);\n const {\n ref: handlePanelRef,\n isTopmost,\n zIndex,\n elevated,\n } = useOverlayBehaviour({\n open,\n onClose,\n elevated: stacking === 'above-app-overlays',\n hostRef,\n });\n\n useEffect(() => {\n if (open) {\n setIsMounted(true);\n if (unmountTimerRef.current) {\n clearTimeout(unmountTimerRef.current);\n unmountTimerRef.current = null;\n }\n frameRef.current = requestAnimationFrame(() => {\n frameRef.current = null;\n setIsVisible(true);\n });\n } else {\n setIsVisible(false);\n unmountTimerRef.current = setTimeout(() => {\n unmountTimerRef.current = null;\n setIsMounted(false);\n }, TRANSITION_MS);\n }\n return () => {\n if (frameRef.current !== null) {\n cancelAnimationFrame(frameRef.current);\n frameRef.current = null;\n }\n if (unmountTimerRef.current) {\n clearTimeout(unmountTimerRef.current);\n unmountTimerRef.current = null;\n }\n };\n }, [open]);\n\n if (!isMounted) {\n return null;\n }\n\n const shownCallouts = callouts?.filter((callout) => callout.message.trim());\n const panelColumnWidth = `calc(${toCssSize(maxWidth)} - 2px)`;\n const dividerBelow = headerDivider\n ? 'border-0 border-b border-solid border-[var(--malachite-card-border)]'\n : '';\n // Each column is a subgrid of the panel's three rows, so the aside's header and footer\n // stay level with the panel's whatever their content. The panel's own column is always the\n // second, so opening or closing the aside never remounts it or reflows it mid-transition:\n // without an aside the first column is simply empty and narrows to nothing.\n const asideColumn = aside ? (\n <aside\n aria-label={aside.title}\n className=\"col-start-1 row-span-3 grid min-w-0 grid-cols-[minmax(0,1fr)] grid-rows-subgrid overflow-hidden border-0 border-r border-solid border-[var(--malachite-card-border)]\"\n >\n <div\n className={`flex min-w-0 items-center gap-[8px] px-[20px] py-[18px] ${dividerBelow}`}\n >\n <span className=\"flex min-w-0 shrink-0\">\n <EllipsisText\n tooltip={aside.title}\n tooltipWhenTruncated\n tooltipPlacement=\"bottom\"\n className=\"min-w-0 text-[length:var(--malachite-font-size-15,15px)] font-semibold\"\n >\n {aside.title}\n </EllipsisText>\n </span>\n {aside.headerExtra ? (\n <span className=\"ml-auto flex shrink-0 items-center\">{aside.headerExtra}</span>\n ) : null}\n </div>\n <div className={`flex min-h-0 flex-col ${aside.footer ? '' : 'row-span-2'}`}>\n <ScrollingBody bodyPadding={aside.bodyPadding ?? true}>\n {aside.children}\n </ScrollingBody>\n </div>\n {aside.footer ? (\n <div className=\"border-0 border-t border-solid border-[var(--malachite-card-border)] px-[24px] py-[16px]\">\n {aside.footer}\n </div>\n ) : null}\n </aside>\n ) : null;\n\n const subtitleBelow = subtitlePlacement === 'below' && !!subtitle;\n const titleNode = (\n <span\n className={subtitleBelow ? 'flex min-w-0 shrink' : 'flex min-w-0 max-w-full shrink-0'}\n >\n <EllipsisText\n tooltip={title}\n tooltipWhenTruncated\n tooltipPlacement=\"bottom\"\n className=\"min-w-0 text-[length:var(--malachite-font-size-15,15px)] font-semibold\"\n >\n {title}\n </EllipsisText>\n </span>\n );\n const subtitleNode = subtitle ? (\n <EllipsisText\n tooltip={subtitle}\n tooltipWhenTruncated\n tooltipPlacement=\"bottom\"\n color=\"secondary\"\n className=\"min-w-0 text-[13px]\"\n >\n {subtitle}\n </EllipsisText>\n ) : null;\n const titleExtraNode = titleExtra ? (\n <span className=\"flex shrink-0 items-center\">{titleExtra}</span>\n ) : null;\n const headerExtraNode = headerExtra ? (\n <span className=\"flex shrink-0 items-baseline\">{headerExtra}</span>\n ) : null;\n\n return createPortal(\n // Host carries the stacking context — ShadowRootWrapper's `isolation` would\n // otherwise flatten our z-index and let sticky page elements paint over us.\n <ShadowRootWrapper\n hostRef={hostRef}\n hostStyle={{ position: 'relative', zIndex }}\n hostProps={\n elevated\n ? { ...overlayIdentity('sidepanel'), [OVERLAY_ELEVATED_ATTR]: '' }\n : overlayIdentity('sidepanel')\n }\n >\n <div className=\"fixed inset-0 z-[1000]\">\n <div\n aria-hidden=\"true\"\n onClick={onClose}\n className={`absolute inset-0 bg-[var(--malachite-overlay-scrim)] transition-opacity duration-200 ease-in-out ${\n isVisible ? 'opacity-100' : 'opacity-0'\n }`}\n />\n <div\n ref={handlePanelRef}\n role=\"dialog\"\n // Only the topmost overlay may claim it, or a screen reader can still\n // browse the one underneath.\n aria-modal={isTopmost ? 'true' : undefined}\n aria-describedby={\n [\n ...(shownCallouts ?? []).map((_, index) => `${calloutId}-${index}`),\n description ? descriptionId : null,\n ]\n .filter(Boolean)\n .join(' ') || undefined\n }\n tabIndex={-1}\n // Prefer aria-labelledby; only fall back to aria-label when it's absent.\n aria-label={\n ariaLabelledBy\n ? undefined\n : (ariaLabel ?? (typeof title === 'string' ? title : undefined))\n }\n aria-labelledby={ariaLabelledBy}\n className={`absolute top-[8px] right-[8px] bottom-[8px] grid grid-rows-[auto_minmax(0,1fr)_auto] overflow-x-auto overflow-y-hidden rounded-[20px] border border-solid border-[var(--malachite-card-border)] bg-[var(--malachite-card-background)] text-[var(--malachite-card-foreground)] outline-none [box-shadow:var(--malachite-shadow-lg)]`}\n style={{\n width: `min(calc(100% - 16px), ${aside ? `calc(2 * ${toCssSize(maxWidth)})` : toCssSize(maxWidth)})`,\n // Inline: Tailwind translate utilities silently break inside\n // shadow roots (see CLAUDE.md Shadow DOM caveats).\n transform: isVisible ? 'translateX(0)' : 'translateX(calc(100% + 16px))',\n transition: `transform ${TRANSITION_MS}ms ease-in-out, width ${TRANSITION_MS}ms ease-in-out, grid-template-columns ${TRANSITION_MS}ms ease-in-out`,\n // The panel's own column is the width it has without an aside: `maxWidth`\n // less the 1px border either side, so opening the aside never widens it.\n // With an aside neither column gives way, so a narrow window scrolls the\n // panel instead. Both templates share one shape so the minimums animate\n // with the width rather than overflowing mid-transition.\n gridTemplateColumns: aside\n ? `minmax(${ASIDE_MIN_WIDTH}, 1fr) minmax(${panelColumnWidth}, ${panelColumnWidth})`\n : `minmax(0px, 1fr) minmax(0px, ${panelColumnWidth})`,\n }}\n >\n {asideColumn}\n {/* An explicit column: an implicit one is sized to its widest content and overflows the panel. */}\n <div className=\"col-start-2 row-span-3 grid min-w-0 grid-cols-[minmax(0,1fr)] grid-rows-subgrid\">\n <div\n className={`flex flex-col gap-[20px] px-[20px] py-[18px] ${dividerBelow}`}\n >\n <div className=\"flex items-center gap-[12px]\">\n {onBack ? (\n <button\n type=\"button\"\n aria-label=\"Back\"\n onClick={onBack}\n className={OVERLAY_ICON_BUTTON_CLASSES}\n >\n <ArrowLeftIcon size={16} />\n </button>\n ) : null}\n {icon ? (\n <span className=\"flex shrink-0 items-center\">{icon}</span>\n ) : null}\n {subtitleBelow ? (\n <div className=\"flex min-w-0 flex-1 items-center gap-[12px]\">\n <div className=\"flex min-w-0 flex-1 flex-col gap-[2px]\">\n <div className=\"flex min-w-0 items-baseline gap-[8px]\">\n {titleNode}\n {titleExtraNode}\n </div>\n {subtitleNode}\n </div>\n {headerExtraNode}\n </div>\n ) : (\n <div className=\"flex min-w-0 flex-1 items-baseline gap-[12px]\">\n <div className=\"flex min-w-0 flex-1 items-baseline gap-[8px]\">\n <div className=\"flex min-w-0 items-baseline gap-[8px]\">\n {titleNode}\n {subtitleNode}\n </div>\n {titleExtraNode}\n </div>\n {headerExtraNode}\n </div>\n )}\n <button\n type=\"button\"\n aria-label=\"Close\"\n onClick={onClose}\n className={OVERLAY_ICON_BUTTON_CLASSES}\n >\n <DismissIcon size={10} />\n </button>\n </div>\n {description ? (\n <div\n id={descriptionId}\n className=\"text-[13px] leading-[1.6] text-[var(--malachite-text-secondary)]\"\n >\n {description}\n </div>\n ) : null}\n </div>\n {/* The toolbar shares the body's row, so an aside's header and footer stay level. */}\n <div className={`flex min-h-0 flex-col ${footer ? '' : 'row-span-2'}`}>\n {toolbar ? (\n <div className=\"shrink-0 px-[16px] pt-[16px] pb-[8px]\">\n {toolbar}\n </div>\n ) : null}\n <ScrollingBody\n bodyPadding={bodyPadding}\n callouts={shownCallouts}\n calloutId={calloutId}\n renderLink={renderLink}\n >\n {children}\n </ScrollingBody>\n </div>\n {footer ? (\n <div className=\"border-0 border-t border-solid border-[var(--malachite-card-border)] px-[24px] py-[16px]\">\n {footer}\n </div>\n ) : null}\n </div>\n </div>\n </div>\n </ShadowRootWrapper>,\n document.body,\n );\n};\n\nexport default SidePanel;\nexport { SidePanel };\n"],"names":["TRANSITION_MS","ASIDE_MIN_WIDTH","ScrollingBody","bodyPadding","callouts","calloutId","renderLink","children","hasCallouts","jsxs","callout","index","jsx","CalloutStrip","toCssSize","value","SidePanel","open","onClose","title","subtitle","subtitlePlacement","titleExtra","description","toolbar","headerDivider","icon","headerExtra","footer","onBack","maxWidth","ariaLabel","ariaLabelledBy","stacking","aside","useId","descriptionId","isVisible","setIsVisible","useState","isMounted","setIsMounted","frameRef","useRef","unmountTimerRef","hostRef","handlePanelRef","isTopmost","zIndex","elevated","useOverlayBehaviour","useEffect","shownCallouts","panelColumnWidth","dividerBelow","asideColumn","EllipsisText","subtitleBelow","titleNode","subtitleNode","titleExtraNode","headerExtraNode","createPortal","ShadowRootWrapper","overlayIdentity","OVERLAY_ELEVATED_ATTR","_","OVERLAY_ICON_BUTTON_CLASSES","ArrowLeftIcon","DismissIcon"],"mappings":";;;;;;;;;;AAsEA,MAAMA,IAAgB,KAChBC,KAAkB,SAWlBC,IAA8C,CAAC;AAAA,EACjD,aAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,YAAAC;AAAA,EACA,UAAAC;AACJ,MAAM;AACF,QAAMC,IAAc,CAAC,EAACJ,KAAA,QAAAA,EAAU;AAGhC,SACI,gBAAAK;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,WAAW,kCAAkCN,KAAe,CAACK,IAAc,cAAc,EAAE;AAAA,MAE1F,UAAA;AAAA,QAAAJ,KAAA,gBAAAA,EAAU,IAAI,CAACM,GAASC,MACrB,gBAAAC;AAAA,UAACC;AAAA,UAAA;AAAA,YAEG,IAAIR,IAAY,GAAGA,CAAS,IAAIM,CAAK,KAAK;AAAA,YAC1C,MAAMD,EAAQ;AAAA,YACd,SAASA,EAAQ;AAAA,YACjB,YAAAJ;AAAA,UAAA;AAAA,UAJKK;AAAA,QAAA;AAAA,QAOZR,sBACI,OAAA,EAAI,WAAWK,IAAc,aAAa,aAAc,UAAAD,GAAS,IAElEA;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAIhB,GAEMO,IAAY,CAACC,MACf,OAAOA,KAAU,WAAW,GAAGA,CAAK,OAAOA,GASzCC,KAAsC,CAAC;AAAA,EACzC,MAAAC;AAAA,EACA,SAAAC;AAA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BAAA;AAAA,oBAAA;AAAA,kBACL,GACJ;AAAA,kBACCqB,IACG,gBAAAhB,EAAC,OAAA,EAAI,WAAU,4FACV,aACL,IACA;AAAA,gBAAA,EAAA,CACR;AAAA,cAAA;AAAA,YAAA;AAAA,UAAA;AAAA,QACJ,EAAA,CACJ;AAAA,MAAA;AAAA,IAAA;AAAA,IAEJ,SAAS;AAAA,EAAA;AAEjB;"}
|
|
1
|
+
{"version":3,"file":"SidePanel.js","sources":["../../src/components/SidePanel.tsx"],"sourcesContent":["import React, { useEffect, useId, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { ShadowRootWrapper } from '../ShadowRootWrapper';\nimport type { AlertType } from './Alert';\nimport CalloutStrip from './CalloutStrip';\nimport ArrowLeftIcon from './CustomIcons/ArrowLeftIcon';\nimport DismissIcon from './CustomIcons/DismissIcon';\nimport type { RenderLink } from './PageLayout/types';\nimport EllipsisText from './Typography/EllipsisText';\nimport { OVERLAY_ICON_BUTTON_CLASSES, useOverlayBehaviour } from './overlayBehaviour';\nimport { OVERLAY_ELEVATED_ATTR, overlayIdentity } from './portalOverlay';\n\nexport interface SidePanelProps {\n open: boolean;\n /** Dismiss handler — close button, ESC, or overlay click. */\n onClose: () => void;\n title: React.ReactNode;\n subtitle?: React.ReactNode;\n /** `below` stacks the subtitle under the title, so neither truncates the other. */\n subtitlePlacement?: 'inline' | 'below';\n /** Content at the end of the title row, after the subtitle (e.g. a status tag). */\n titleExtra?: React.ReactNode;\n /** Block paragraph below the title row, spanning the header width. Announced as the panel's description. */\n description?: React.ReactNode;\n /** Pinned between the header and the scrolling body. */\n toolbar?: React.ReactNode;\n /** Divider under the header. Default: false. */\n headerDivider?: boolean;\n /** Leading header slot, typically a logo or icon. */\n icon?: React.ReactNode;\n /** Content pinned right in the header, before the close button. */\n headerExtra?: React.ReactNode;\n footer?: React.ReactNode;\n /**\n * Makes the panel's header, body and footer one form. Enter in a field then submits through\n * a `type=\"submit\"` button in the footer (see `FormActions`), the way a browser form does:\n * not from a textarea, not mid-composition, and not while that button is disabled. The\n * event's default is prevented and validation is the caller's, so the form is `noValidate`.\n * Enter in the `toolbar` never submits. A field inside its own `MalachiteContext` sits in\n * another shadow root and is outside the form.\n */\n onSubmit?: (event: React.FormEvent<HTMLFormElement>) => void;\n /** Renders a back button before the header icon. */\n onBack?: () => void;\n /** Maximum panel width. Default: 1080. */\n maxWidth?: number | string;\n /** Accessible dialog name; required when `title` isn't a plain string. */\n 'aria-label'?: string;\n /** ID of a visible element naming the dialog (alternative to `aria-label`). */\n 'aria-labelledby'?: string;\n /** Whether the body gets default padding. Default: true. */\n bodyPadding?: boolean;\n /** `above-app-overlays` lifts the overlay stack clear of chrome pinned near max-int. */\n stacking?: 'default' | 'above-app-overlays';\n /** Full-width Alert bands at the top of the body, above `children`, in order. Unaffected by\n * `bodyPadding`, and announced ahead of `description`. The message is markdown. */\n callouts?: { type?: AlertType; message: string }[];\n /** Routes root-relative links in `callouts` through the app's router; see `MarkdownBlock`. */\n renderLink?: RenderLink;\n /** A full-height column opened to the left, as wide again as `maxWidth`. The panel's own\n * header, body and footer keep their width and place; the aside's header and footer line\n * up with them. The aside is never narrower than 360px: a window too narrow for both\n * columns scrolls the panel sideways. */\n aside?: SidePanelAside;\n children: React.ReactNode;\n}\n\nexport interface SidePanelAside {\n /** Shown in the aside's header, and names the column for assistive tech. */\n title: string;\n /** Content pinned right in the aside's header (e.g. a stepper). */\n headerExtra?: React.ReactNode;\n /** Pinned at the bottom, level with the panel's footer. */\n footer?: React.ReactNode;\n /** Whether the aside's body gets default padding, as the panel's `bodyPadding`. Default: true. */\n bodyPadding?: boolean;\n children: React.ReactNode;\n}\n\nconst TRANSITION_MS = 200;\nconst ASIDE_MIN_WIDTH = '360px';\n\ninterface ScrollingBodyProps {\n bodyPadding: boolean;\n callouts?: { type?: AlertType; message: string }[];\n /** Prefix for each callout's id, which the panel names in `aria-describedby`. */\n calloutId?: string;\n renderLink?: RenderLink;\n children: React.ReactNode;\n}\n\nconst ScrollingBody: React.FC<ScrollingBodyProps> = ({\n bodyPadding,\n callouts,\n calloutId,\n renderLink,\n children,\n}) => {\n const hasCallouts = !!callouts?.length;\n\n // Callouts move the horizontal padding inward so their strips run full-bleed.\n return (\n <div\n className={`min-h-0 flex-1 overflow-y-auto ${bodyPadding && !hasCallouts ? 'px-[28px]' : ''}`}\n >\n {callouts?.map((callout, index) => (\n <CalloutStrip\n key={index}\n id={calloutId ? `${calloutId}-${index}` : undefined}\n type={callout.type}\n message={callout.message}\n renderLink={renderLink}\n />\n ))}\n {bodyPadding ? (\n <div className={hasCallouts ? 'p-[28px]' : 'py-[28px]'}>{children}</div>\n ) : (\n children\n )}\n </div>\n );\n};\n\nconst toCssSize = (value: number | string): string =>\n typeof value === 'number' ? `${value}px` : value;\n\n// The toolbar holds filters, such as a Search over the list, never a field the form saves.\nconst cancelToolbarSubmit = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (event.key === 'Enter' && event.target instanceof HTMLInputElement) {\n event.preventDefault();\n }\n};\n\nconst PANEL_COLUMN_CLASSES =\n 'col-start-2 row-span-3 grid min-w-0 grid-cols-[minmax(0,1fr)] grid-rows-subgrid';\n\n// The panel's own column, which is the form when the panel has one, so the header, body and\n// footer stay the subgrid's three rows either way.\nconst PanelColumn: React.FC<{\n onSubmit?: (event: React.FormEvent<HTMLFormElement>) => void;\n children: React.ReactNode;\n}> = ({ onSubmit, children }) =>\n onSubmit ? (\n <form\n noValidate\n className={PANEL_COLUMN_CLASSES}\n onSubmit={(event) => {\n event.preventDefault();\n // React bubbles it through the portal to a consumer's own form around the panel.\n event.stopPropagation();\n onSubmit(event);\n }}\n >\n {children}\n </form>\n ) : (\n <div className={PANEL_COLUMN_CLASSES}>{children}</div>\n );\n\n/**\n * A right-hand slide-in overlay panel (drawer) for inspecting or editing an entity\n * without leaving the page. Portals to `document.body`, locks background scroll and\n * traps keyboard focus while open (restoring both on close), dismisses on ESC\n * (topmost open overlay only), overlay click or the close button, and exposes header\n * (back/icon/title/subtitle/extra), scrollable body and optional footer slots.\n */\nconst SidePanel: React.FC<SidePanelProps> = ({\n open,\n onClose,\n title,\n subtitle,\n subtitlePlacement = 'inline',\n titleExtra,\n description,\n toolbar,\n headerDivider = false,\n icon,\n headerExtra,\n footer,\n onSubmit,\n onBack,\n maxWidth = 1080,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n bodyPadding = true,\n stacking = 'default',\n callouts,\n renderLink,\n aside,\n children,\n}) => {\n const calloutId = useId();\n const descriptionId = useId();\n const [isVisible, setIsVisible] = useState(false);\n const [isMounted, setIsMounted] = useState(false);\n const frameRef = useRef<number | null>(null);\n const unmountTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const hostRef = useRef<HTMLDivElement | null>(null);\n const {\n ref: handlePanelRef,\n isTopmost,\n zIndex,\n elevated,\n } = useOverlayBehaviour({\n open,\n onClose,\n elevated: stacking === 'above-app-overlays',\n hostRef,\n });\n\n useEffect(() => {\n if (open) {\n setIsMounted(true);\n if (unmountTimerRef.current) {\n clearTimeout(unmountTimerRef.current);\n unmountTimerRef.current = null;\n }\n frameRef.current = requestAnimationFrame(() => {\n frameRef.current = null;\n setIsVisible(true);\n });\n } else {\n setIsVisible(false);\n unmountTimerRef.current = setTimeout(() => {\n unmountTimerRef.current = null;\n setIsMounted(false);\n }, TRANSITION_MS);\n }\n return () => {\n if (frameRef.current !== null) {\n cancelAnimationFrame(frameRef.current);\n frameRef.current = null;\n }\n if (unmountTimerRef.current) {\n clearTimeout(unmountTimerRef.current);\n unmountTimerRef.current = null;\n }\n };\n }, [open]);\n\n if (!isMounted) {\n return null;\n }\n\n const shownCallouts = callouts?.filter((callout) => callout.message.trim());\n const panelColumnWidth = `calc(${toCssSize(maxWidth)} - 2px)`;\n const dividerBelow = headerDivider\n ? 'border-0 border-b border-solid border-[var(--malachite-card-border)]'\n : '';\n // Each column is a subgrid of the panel's three rows, so the aside's header and footer\n // stay level with the panel's whatever their content. The panel's own column is always the\n // second, so opening or closing the aside never remounts it or reflows it mid-transition:\n // without an aside the first column is simply empty and narrows to nothing.\n const asideColumn = aside ? (\n <aside\n aria-label={aside.title}\n className=\"col-start-1 row-span-3 grid min-w-0 grid-cols-[minmax(0,1fr)] grid-rows-subgrid overflow-hidden border-0 border-r border-solid border-[var(--malachite-card-border)]\"\n >\n <div\n className={`flex min-w-0 items-center gap-[8px] px-[20px] py-[18px] ${dividerBelow}`}\n >\n <span className=\"flex min-w-0 shrink-0\">\n <EllipsisText\n tooltip={aside.title}\n tooltipWhenTruncated\n tooltipPlacement=\"bottom\"\n className=\"min-w-0 text-[length:var(--malachite-font-size-15,15px)] font-semibold\"\n >\n {aside.title}\n </EllipsisText>\n </span>\n {aside.headerExtra ? (\n <span className=\"ml-auto flex shrink-0 items-center\">{aside.headerExtra}</span>\n ) : null}\n </div>\n <div className={`flex min-h-0 flex-col ${aside.footer ? '' : 'row-span-2'}`}>\n <ScrollingBody bodyPadding={aside.bodyPadding ?? true}>\n {aside.children}\n </ScrollingBody>\n </div>\n {aside.footer ? (\n <div className=\"border-0 border-t border-solid border-[var(--malachite-card-border)] px-[24px] py-[16px]\">\n {aside.footer}\n </div>\n ) : null}\n </aside>\n ) : null;\n\n const subtitleBelow = subtitlePlacement === 'below' && !!subtitle;\n const titleNode = (\n <span\n className={subtitleBelow ? 'flex min-w-0 shrink' : 'flex min-w-0 max-w-full shrink-0'}\n >\n <EllipsisText\n tooltip={title}\n tooltipWhenTruncated\n tooltipPlacement=\"bottom\"\n className=\"min-w-0 text-[length:var(--malachite-font-size-15,15px)] font-semibold\"\n >\n {title}\n </EllipsisText>\n </span>\n );\n const subtitleNode = subtitle ? (\n <EllipsisText\n tooltip={subtitle}\n tooltipWhenTruncated\n tooltipPlacement=\"bottom\"\n color=\"secondary\"\n className=\"min-w-0 text-[13px]\"\n >\n {subtitle}\n </EllipsisText>\n ) : null;\n const titleExtraNode = titleExtra ? (\n <span className=\"flex shrink-0 items-center\">{titleExtra}</span>\n ) : null;\n const headerExtraNode = headerExtra ? (\n <span className=\"flex shrink-0 items-baseline\">{headerExtra}</span>\n ) : null;\n\n return createPortal(\n // Host carries the stacking context — ShadowRootWrapper's `isolation` would\n // otherwise flatten our z-index and let sticky page elements paint over us.\n <ShadowRootWrapper\n hostRef={hostRef}\n hostStyle={{ position: 'relative', zIndex }}\n hostProps={\n elevated\n ? { ...overlayIdentity('sidepanel'), [OVERLAY_ELEVATED_ATTR]: '' }\n : overlayIdentity('sidepanel')\n }\n >\n <div className=\"fixed inset-0 z-[1000]\">\n <div\n aria-hidden=\"true\"\n onClick={onClose}\n className={`absolute inset-0 bg-[var(--malachite-overlay-scrim)] transition-opacity duration-200 ease-in-out ${\n isVisible ? 'opacity-100' : 'opacity-0'\n }`}\n />\n <div\n ref={handlePanelRef}\n role=\"dialog\"\n // Only the topmost overlay may claim it, or a screen reader can still\n // browse the one underneath.\n aria-modal={isTopmost ? 'true' : undefined}\n aria-describedby={\n [\n ...(shownCallouts ?? []).map((_, index) => `${calloutId}-${index}`),\n description ? descriptionId : null,\n ]\n .filter(Boolean)\n .join(' ') || undefined\n }\n tabIndex={-1}\n // Prefer aria-labelledby; only fall back to aria-label when it's absent.\n aria-label={\n ariaLabelledBy\n ? undefined\n : (ariaLabel ?? (typeof title === 'string' ? title : undefined))\n }\n aria-labelledby={ariaLabelledBy}\n className={`absolute top-[8px] right-[8px] bottom-[8px] grid grid-rows-[auto_minmax(0,1fr)_auto] overflow-x-auto overflow-y-hidden rounded-[20px] border border-solid border-[var(--malachite-card-border)] bg-[var(--malachite-card-background)] text-[var(--malachite-card-foreground)] outline-none [box-shadow:var(--malachite-shadow-lg)]`}\n style={{\n width: `min(calc(100% - 16px), ${aside ? `calc(2 * ${toCssSize(maxWidth)})` : toCssSize(maxWidth)})`,\n // Inline: Tailwind translate utilities silently break inside\n // shadow roots (see CLAUDE.md Shadow DOM caveats).\n transform: isVisible ? 'translateX(0)' : 'translateX(calc(100% + 16px))',\n transition: `transform ${TRANSITION_MS}ms ease-in-out, width ${TRANSITION_MS}ms ease-in-out, grid-template-columns ${TRANSITION_MS}ms ease-in-out`,\n // The panel's own column is the width it has without an aside: `maxWidth`\n // less the 1px border either side, so opening the aside never widens it.\n // With an aside neither column gives way, so a narrow window scrolls the\n // panel instead. Both templates share one shape so the minimums animate\n // with the width rather than overflowing mid-transition.\n gridTemplateColumns: aside\n ? `minmax(${ASIDE_MIN_WIDTH}, 1fr) minmax(${panelColumnWidth}, ${panelColumnWidth})`\n : `minmax(0px, 1fr) minmax(0px, ${panelColumnWidth})`,\n }}\n >\n {asideColumn}\n {/* An explicit column: an implicit one is sized to its widest content and overflows the panel. */}\n <PanelColumn onSubmit={onSubmit}>\n <div\n className={`flex flex-col gap-[20px] px-[20px] py-[18px] ${dividerBelow}`}\n >\n <div className=\"flex items-center gap-[12px]\">\n {onBack ? (\n <button\n type=\"button\"\n aria-label=\"Back\"\n onClick={onBack}\n className={OVERLAY_ICON_BUTTON_CLASSES}\n >\n <ArrowLeftIcon size={16} />\n </button>\n ) : null}\n {icon ? (\n <span className=\"flex shrink-0 items-center\">{icon}</span>\n ) : null}\n {subtitleBelow ? (\n <div className=\"flex min-w-0 flex-1 items-center gap-[12px]\">\n <div className=\"flex min-w-0 flex-1 flex-col gap-[2px]\">\n <div className=\"flex min-w-0 items-baseline gap-[8px]\">\n {titleNode}\n {titleExtraNode}\n </div>\n {subtitleNode}\n </div>\n {headerExtraNode}\n </div>\n ) : (\n <div className=\"flex min-w-0 flex-1 items-baseline gap-[12px]\">\n <div className=\"flex min-w-0 flex-1 items-baseline gap-[8px]\">\n <div className=\"flex min-w-0 items-baseline gap-[8px]\">\n {titleNode}\n {subtitleNode}\n </div>\n {titleExtraNode}\n </div>\n {headerExtraNode}\n </div>\n )}\n <button\n type=\"button\"\n aria-label=\"Close\"\n onClick={onClose}\n className={OVERLAY_ICON_BUTTON_CLASSES}\n >\n <DismissIcon size={10} />\n </button>\n </div>\n {description ? (\n <div\n id={descriptionId}\n className=\"text-[13px] leading-[1.6] text-[var(--malachite-text-secondary)]\"\n >\n {description}\n </div>\n ) : null}\n </div>\n {/* The toolbar shares the body's row, so an aside's header and footer stay level. */}\n <div className={`flex min-h-0 flex-col ${footer ? '' : 'row-span-2'}`}>\n {toolbar ? (\n <div\n className=\"shrink-0 px-[16px] pt-[16px] pb-[8px]\"\n onKeyDown={onSubmit ? cancelToolbarSubmit : undefined}\n >\n {toolbar}\n </div>\n ) : null}\n <ScrollingBody\n bodyPadding={bodyPadding}\n callouts={shownCallouts}\n calloutId={calloutId}\n renderLink={renderLink}\n >\n {children}\n </ScrollingBody>\n </div>\n {footer ? (\n <div className=\"border-0 border-t border-solid border-[var(--malachite-card-border)] px-[24px] py-[16px]\">\n {footer}\n </div>\n ) : null}\n </PanelColumn>\n </div>\n </div>\n </ShadowRootWrapper>,\n document.body,\n );\n};\n\nexport default SidePanel;\nexport { SidePanel };\n"],"names":["TRANSITION_MS","ASIDE_MIN_WIDTH","ScrollingBody","bodyPadding","callouts","calloutId","renderLink","children","hasCallouts","jsxs","callout","index","jsx","CalloutStrip","toCssSize","value","cancelToolbarSubmit","event","PANEL_COLUMN_CLASSES","PanelColumn","onSubmit","SidePanel","open","onClose","title","subtitle","subtitlePlacement","titleExtra","description","toolbar","headerDivider","icon","headerExtra","footer","onBack","maxWidth","ariaLabel","ariaLabelledBy","stacking","aside","useId","descriptionId","isVisible","setIsVisible","useState","isMounted","setIsMounted","frameRef","useRef","unmountTimerRef","hostRef","handlePanelRef","isTopmost","zIndex","elevated","useOverlayBehaviour","useEffect","shownCallouts","panelColumnWidth","dividerBelow","asideColumn","EllipsisText","subtitleBelow","titleNode","subtitleNode","titleExtraNode","headerExtraNode","createPortal","ShadowRootWrapper","overlayIdentity","OVERLAY_ELEVATED_ATTR","_","OVERLAY_ICON_BUTTON_CLASSES","ArrowLeftIcon","DismissIcon"],"mappings":";;;;;;;;;;AA+EA,MAAMA,IAAgB,KAChBC,KAAkB,SA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AA,sBAACV;AAAA,sBAAA;AAAA,wBACG,aAAAC;AAAA,wBACA,UAAUsD;AAAA,wBACV,WAAApD;AAAA,wBACA,YAAAC;AAAA,wBAEC,UAAAC;AAAA,sBAAA;AAAA,oBAAA;AAAA,kBACL,GACJ;AAAA,kBACC0B,IACG,gBAAArB,EAAC,OAAA,EAAI,WAAU,4FACV,aACL,IACA;AAAA,gBAAA,EAAA,CACR;AAAA,cAAA;AAAA,YAAA;AAAA,UAAA;AAAA,QACJ,EAAA,CACJ;AAAA,MAAA;AAAA,IAAA;AAAA,IAEJ,SAAS;AAAA,EAAA;AAEjB;"}
|
package/dist/components/Tabs.js
CHANGED
|
@@ -1,56 +1,83 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { jsx as o, Fragment as v, jsxs as k } from "react/jsx-runtime";
|
|
2
|
+
import { useId as $, useState as I } from "react";
|
|
3
|
+
import { FOCUS_RING as C } from "./focusRing.js";
|
|
4
|
+
const R = ({
|
|
5
|
+
items: a,
|
|
6
|
+
activeKey: t,
|
|
7
|
+
onChange: y,
|
|
8
|
+
trailing: c,
|
|
9
|
+
destroyInactivePanels: i = !1,
|
|
10
|
+
className: b = "",
|
|
11
|
+
style: p
|
|
10
12
|
}) => {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
const h = $(), s = a.some((e) => e.content !== void 0), [n, g] = I([t]), d = i ? [t] : [
|
|
14
|
+
...n.filter(
|
|
15
|
+
(e) => e !== t && a.some((r) => r.key === e)
|
|
16
|
+
),
|
|
17
|
+
t
|
|
18
|
+
];
|
|
19
|
+
s && (d.length !== n.length || d.some((e) => !n.includes(e))) && g(d);
|
|
20
|
+
const x = (e) => `${h}tab-${encodeURIComponent(e)}`, u = (e) => `${h}panel-${encodeURIComponent(e)}`, m = /* @__PURE__ */ o(v, { children: a.map((e) => {
|
|
21
|
+
const r = e.key === t, l = e.disabled ? "text-[var(--malachite-text-dimmed)] cursor-not-allowed" : r ? "text-[var(--malachite-accent-foreground)]" : "text-[var(--malachite-text-secondary)] cursor-pointer hover:text-[var(--malachite-accent-foreground)]";
|
|
22
|
+
return /* @__PURE__ */ o(
|
|
14
23
|
"button",
|
|
15
24
|
{
|
|
16
25
|
type: "button",
|
|
17
26
|
role: "tab",
|
|
18
|
-
|
|
27
|
+
id: s ? x(e.key) : void 0,
|
|
28
|
+
"aria-controls": s ? u(e.key) : void 0,
|
|
29
|
+
"aria-selected": r,
|
|
19
30
|
disabled: e.disabled,
|
|
20
31
|
onClick: () => {
|
|
21
|
-
e.disabled ||
|
|
32
|
+
e.disabled || y(e.key);
|
|
22
33
|
},
|
|
23
|
-
className: `relative bg-transparent border-0 px-0 pt-2 pb-[14px] -mb-px text-[13px] leading-4 font-medium tracking-[0.13px] whitespace-nowrap transition-colors duration-150 ${
|
|
34
|
+
className: `relative bg-transparent border-0 px-0 pt-2 pb-[14px] -mb-px text-[13px] leading-4 font-medium tracking-[0.13px] whitespace-nowrap transition-colors duration-150 ${C} ${l}`,
|
|
24
35
|
style: {
|
|
25
|
-
borderBottom:
|
|
36
|
+
borderBottom: r ? "2px solid var(--malachite-accent-foreground)" : "2px solid transparent"
|
|
26
37
|
},
|
|
27
38
|
children: e.label
|
|
28
39
|
},
|
|
29
40
|
e.key
|
|
30
41
|
);
|
|
31
|
-
}) })
|
|
32
|
-
|
|
33
|
-
/* @__PURE__ */ r(
|
|
42
|
+
}) }), f = c ? /* @__PURE__ */ k("div", { className: "flex items-stretch border-b border-solid border-[var(--malachite-card-border)]", children: [
|
|
43
|
+
/* @__PURE__ */ o(
|
|
34
44
|
"div",
|
|
35
45
|
{
|
|
36
46
|
role: "tablist",
|
|
37
|
-
className: `flex items-stretch gap-5 shrink-0 ${
|
|
38
|
-
style:
|
|
39
|
-
children:
|
|
47
|
+
className: `flex items-stretch gap-5 shrink-0 ${b}`,
|
|
48
|
+
style: p,
|
|
49
|
+
children: m
|
|
40
50
|
}
|
|
41
51
|
),
|
|
42
|
-
/* @__PURE__ */
|
|
43
|
-
] }) : /* @__PURE__ */
|
|
52
|
+
/* @__PURE__ */ o("div", { className: "flex min-w-0 flex-1 items-center justify-end pl-4", children: c })
|
|
53
|
+
] }) : /* @__PURE__ */ o(
|
|
44
54
|
"div",
|
|
45
55
|
{
|
|
46
56
|
role: "tablist",
|
|
47
|
-
className: `flex items-stretch gap-5 border-b border-solid border-[var(--malachite-card-border)] ${
|
|
48
|
-
style:
|
|
49
|
-
children:
|
|
57
|
+
className: `flex items-stretch gap-5 border-b border-solid border-[var(--malachite-card-border)] ${b}`,
|
|
58
|
+
style: p,
|
|
59
|
+
children: m
|
|
50
60
|
}
|
|
51
61
|
);
|
|
62
|
+
return s ? /* @__PURE__ */ k(v, { children: [
|
|
63
|
+
f,
|
|
64
|
+
a.map((e) => {
|
|
65
|
+
const r = e.key === t, l = r || !i && n.includes(e.key);
|
|
66
|
+
return /* @__PURE__ */ o(
|
|
67
|
+
"div",
|
|
68
|
+
{
|
|
69
|
+
id: u(e.key),
|
|
70
|
+
role: "tabpanel",
|
|
71
|
+
"aria-labelledby": x(e.key),
|
|
72
|
+
hidden: !r,
|
|
73
|
+
children: l ? e.content : null
|
|
74
|
+
},
|
|
75
|
+
e.key
|
|
76
|
+
);
|
|
77
|
+
})
|
|
78
|
+
] }) : f;
|
|
52
79
|
};
|
|
53
80
|
export {
|
|
54
|
-
|
|
81
|
+
R as default
|
|
55
82
|
};
|
|
56
83
|
//# sourceMappingURL=Tabs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tabs.js","sources":["../../src/components/Tabs.tsx"],"sourcesContent":["import React from 'react';\nimport { FOCUS_RING } from './focusRing';\n\nexport interface TabItem {\n key: string;\n label: React.ReactNode;\n disabled?: boolean;\n}\n\nexport interface TabsProps {\n items: TabItem[];\n activeKey: string;\n onChange: (key: string) => void;\n trailing?: React.ReactNode;\n className?: string;\n style?: React.CSSProperties;\n}\n\nconst Tabs: React.FC<TabsProps> = ({\n items,\n activeKey,\n onChange,\n trailing,\n className = '',\n style,\n}) => {\n const tabs = (\n <>\n {items.map((item) => {\n const isActive = item.key === activeKey;\n const colorClass = item.disabled\n ? 'text-[var(--malachite-text-dimmed)] cursor-not-allowed'\n : isActive\n ? 'text-[var(--malachite-accent-foreground)]'\n : 'text-[var(--malachite-text-secondary)] cursor-pointer hover:text-[var(--malachite-accent-foreground)]';\n\n return (\n <button\n key={item.key}\n type=\"button\"\n role=\"tab\"\n aria-selected={isActive}\n disabled={item.disabled}\n onClick={() => {\n if (!item.disabled) {\n onChange(item.key);\n }\n }}\n // 8 (pt) + 16 (leading-4 label) + 14 (pb) + 2 (the underline) = 40, the height the design…\n className={`relative bg-transparent border-0 px-0 pt-2 pb-[14px] -mb-px text-[13px] leading-4 font-medium tracking-[0.13px] whitespace-nowrap transition-colors duration-150 ${FOCUS_RING} ${colorClass}`}\n style={{\n borderBottom: isActive\n ? '2px solid var(--malachite-accent-foreground)'\n : '2px solid transparent',\n }}\n >\n {item.label}\n </button>\n );\n })}\n </>\n );\n\n
|
|
1
|
+
{"version":3,"file":"Tabs.js","sources":["../../src/components/Tabs.tsx"],"sourcesContent":["import React, { useId, useState } from 'react';\nimport { FOCUS_RING } from './focusRing';\n\nexport interface TabItem {\n key: string;\n label: React.ReactNode;\n disabled?: boolean;\n /**\n * The tab's panel. Give it on any item and `Tabs` renders a `tabpanel` per item below the\n * strip; leave it off every item and the strip is all it renders, for a consumer that\n * switches its own content.\n */\n content?: React.ReactNode;\n}\n\nexport interface TabsProps {\n items: TabItem[];\n activeKey: string;\n onChange: (key: string) => void;\n trailing?: React.ReactNode;\n /**\n * Unmount a panel when its tab is left. By default a panel mounts the first time its tab is\n * opened and then stays mounted, hidden, so a filter, a search or a scroll position survives\n * a round trip and its data is not fetched again.\n */\n destroyInactivePanels?: boolean;\n className?: string;\n style?: React.CSSProperties;\n}\n\nconst Tabs: React.FC<TabsProps> = ({\n items,\n activeKey,\n onChange,\n trailing,\n destroyInactivePanels = false,\n className = '',\n style,\n}) => {\n const baseId = useId();\n const hasPanels = items.some((item) => item.content !== undefined);\n const [visitedKeys, setVisitedKeys] = useState<string[]>([activeKey]);\n // Only what is mounted now, so a removed tab or a stretch of destroyInactivePanels leaves no\n // history to remount from. Recorded during render rather than in an effect, so a newly opened\n // panel and the record of it arrive in the same commit.\n const nextVisitedKeys = destroyInactivePanels\n ? [activeKey]\n : [\n ...visitedKeys.filter(\n (key) => key !== activeKey && items.some((item) => item.key === key),\n ),\n activeKey,\n ];\n if (\n hasPanels &&\n (nextVisitedKeys.length !== visitedKeys.length ||\n nextVisitedKeys.some((key) => !visitedKeys.includes(key)))\n ) {\n setVisitedKeys(nextVisitedKeys);\n }\n // aria-controls and aria-labelledby are space-separated id lists, so a key with a space in it\n // would name two ids.\n const tabId = (key: string) => `${baseId}tab-${encodeURIComponent(key)}`;\n const panelId = (key: string) => `${baseId}panel-${encodeURIComponent(key)}`;\n\n const tabs = (\n <>\n {items.map((item) => {\n const isActive = item.key === activeKey;\n const colorClass = item.disabled\n ? 'text-[var(--malachite-text-dimmed)] cursor-not-allowed'\n : isActive\n ? 'text-[var(--malachite-accent-foreground)]'\n : 'text-[var(--malachite-text-secondary)] cursor-pointer hover:text-[var(--malachite-accent-foreground)]';\n\n return (\n <button\n key={item.key}\n type=\"button\"\n role=\"tab\"\n id={hasPanels ? tabId(item.key) : undefined}\n aria-controls={hasPanels ? panelId(item.key) : undefined}\n aria-selected={isActive}\n disabled={item.disabled}\n onClick={() => {\n if (!item.disabled) {\n onChange(item.key);\n }\n }}\n // 8 (pt) + 16 (leading-4 label) + 14 (pb) + 2 (the underline) = 40, the height the design…\n className={`relative bg-transparent border-0 px-0 pt-2 pb-[14px] -mb-px text-[13px] leading-4 font-medium tracking-[0.13px] whitespace-nowrap transition-colors duration-150 ${FOCUS_RING} ${colorClass}`}\n style={{\n borderBottom: isActive\n ? '2px solid var(--malachite-accent-foreground)'\n : '2px solid transparent',\n }}\n >\n {item.label}\n </button>\n );\n })}\n </>\n );\n\n const strip = trailing ? (\n <div className=\"flex items-stretch border-b border-solid border-[var(--malachite-card-border)]\">\n {/* `className`/`style` stay on the tablist in both branches, so a consumer's spacing\n still spaces tab against tab and a `[role=tablist]` selector still finds them. */}\n <div\n role=\"tablist\"\n className={`flex items-stretch gap-5 shrink-0 ${className}`}\n style={style}\n >\n {tabs}\n </div>\n <div className=\"flex min-w-0 flex-1 items-center justify-end pl-4\">{trailing}</div>\n </div>\n ) : (\n <div\n role=\"tablist\"\n className={`flex items-stretch gap-5 border-b border-solid border-[var(--malachite-card-border)] ${className}`}\n style={style}\n >\n {tabs}\n </div>\n );\n\n if (!hasPanels) {\n return strip;\n }\n\n // Panels are plain siblings of the strip with no overflow of their own, so a sticky toolbar or\n // table header inside one still pins to the page's scroll container. Every tab gets a panel\n // element, empty until first opened, so each tab's aria-controls always resolves.\n return (\n <>\n {strip}\n {items.map((item) => {\n const isActive = item.key === activeKey;\n const isMounted =\n isActive || (!destroyInactivePanels && visitedKeys.includes(item.key));\n return (\n <div\n key={item.key}\n id={panelId(item.key)}\n role=\"tabpanel\"\n aria-labelledby={tabId(item.key)}\n hidden={!isActive}\n >\n {isMounted ? item.content : null}\n </div>\n );\n })}\n </>\n );\n};\n\nexport default Tabs;\n"],"names":["Tabs","items","activeKey","onChange","trailing","destroyInactivePanels","className","style","baseId","useId","hasPanels","item","visitedKeys","setVisitedKeys","useState","nextVisitedKeys","key","tabId","panelId","tabs","jsx","Fragment","isActive","colorClass","FOCUS_RING","strip","jsxs","isMounted"],"mappings":";;;AA8BA,MAAMA,IAA4B,CAAC;AAAA,EAC/B,OAAAC;AAAA,EACA,WAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,uBAAAC,IAAwB;AAAA,EACxB,WAAAC,IAAY;AAAA,EACZ,OAAAC;AAC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AA;AAAA,EAuBtB,CAAC,EAAA,CACL,GAGEc,IAAQrB,IACV,gBAAAsB,EAAC,OAAA,EAAI,WAAU,kFAGX,UAAA;AAAA,IAAA,gBAAAN;AAAA,MAAC;AAAA,MAAA;AAAA,QACG,MAAK;AAAA,QACL,WAAW,qCAAqCd,CAAS;AAAA,QACzD,OAAAC;AAAA,QAEC,UAAAY;AAAA,MAAA;AAAA,IAAA;AAAA,IAEL,gBAAAC,EAAC,OAAA,EAAI,WAAU,qDAAqD,UAAAhB,EAAA,CAAS;AAAA,EAAA,EAAA,CACjF,IAEA,gBAAAgB;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,MAAK;AAAA,MACL,WAAW,wFAAwFd,CAAS;AAAA,MAC5G,OAAAC;AAAA,MAEC,UAAAY;AAAA,IAAA;AAAA,EAAA;AAIT,SAAKT,IAQD,gBAAAgB,EAAAL,GAAA,EACK,UAAA;AAAA,IAAAI;AAAA,IACAxB,EAAM,IAAI,CAACU,MAAS;AACjB,YAAMW,IAAWX,EAAK,QAAQT,GACxByB,IACFL,KAAa,CAACjB,KAAyBO,EAAY,SAASD,EAAK,GAAG;AACxE,aACI,gBAAAS;AAAA,QAAC;AAAA,QAAA;AAAA,UAEG,IAAIF,EAAQP,EAAK,GAAG;AAAA,UACpB,MAAK;AAAA,UACL,mBAAiBM,EAAMN,EAAK,GAAG;AAAA,UAC/B,QAAQ,CAACW;AAAA,UAER,UAAAK,IAAYhB,EAAK,UAAU;AAAA,QAAA;AAAA,QANvBA,EAAK;AAAA,MAAA;AAAA,IAStB,CAAC;AAAA,EAAA,GACL,IAzBOc;AA2Bf;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2046,6 +2046,26 @@ export declare const ForbiddenIcon: React.FC<IconProps_57>;
|
|
|
2046
2046
|
|
|
2047
2047
|
export declare const Form: default_2.FC<FormProps>;
|
|
2048
2048
|
|
|
2049
|
+
export declare interface FormAction {
|
|
2050
|
+
label: string;
|
|
2051
|
+
onClick?: () => void;
|
|
2052
|
+
disabled?: boolean;
|
|
2053
|
+
loading?: boolean;
|
|
2054
|
+
tooltip?: string;
|
|
2055
|
+
}
|
|
2056
|
+
|
|
2057
|
+
/** A form's Cancel and primary pair, end-aligned: a side panel's footer, or under a settings section. */
|
|
2058
|
+
export declare const FormActions: default_2.FC<FormActionsProps>;
|
|
2059
|
+
|
|
2060
|
+
export declare interface FormActionsProps {
|
|
2061
|
+
/** The filled action, last in the row. */
|
|
2062
|
+
primary?: FormPrimaryAction;
|
|
2063
|
+
/** The outline action before it, usually Cancel. */
|
|
2064
|
+
secondary?: FormAction;
|
|
2065
|
+
size?: 'small' | 'medium';
|
|
2066
|
+
className?: string;
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2049
2069
|
export declare const FormItem: default_2.FC<FormItemProps>;
|
|
2050
2070
|
|
|
2051
2071
|
export declare type FormItemChildren = default_2.ReactNode | ((state: FieldErrorState) => default_2.ReactNode);
|
|
@@ -2056,6 +2076,16 @@ declare interface FormItemProps {
|
|
|
2056
2076
|
children: FormItemChildren;
|
|
2057
2077
|
}
|
|
2058
2078
|
|
|
2079
|
+
export declare interface FormPrimaryAction extends FormAction {
|
|
2080
|
+
/** `destructive` for an action that deletes or revokes. */
|
|
2081
|
+
tone?: 'default' | 'destructive';
|
|
2082
|
+
/**
|
|
2083
|
+
* `submit` makes it the form's submit button, so Enter in a field presses it. Leave `onClick`
|
|
2084
|
+
* off then and handle the form's `onSubmit` (a `SidePanel`'s, say), or a click runs both.
|
|
2085
|
+
*/
|
|
2086
|
+
type?: 'button' | 'submit';
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2059
2089
|
declare interface FormProps {
|
|
2060
2090
|
children: default_2.ReactNode;
|
|
2061
2091
|
onFinish?: (data: FieldValues) => void;
|
|
@@ -4901,6 +4931,15 @@ export declare interface SidePanelProps {
|
|
|
4901
4931
|
/** Content pinned right in the header, before the close button. */
|
|
4902
4932
|
headerExtra?: default_2.ReactNode;
|
|
4903
4933
|
footer?: default_2.ReactNode;
|
|
4934
|
+
/**
|
|
4935
|
+
* Makes the panel's header, body and footer one form. Enter in a field then submits through
|
|
4936
|
+
* a `type="submit"` button in the footer (see `FormActions`), the way a browser form does:
|
|
4937
|
+
* not from a textarea, not mid-composition, and not while that button is disabled. The
|
|
4938
|
+
* event's default is prevented and validation is the caller's, so the form is `noValidate`.
|
|
4939
|
+
* Enter in the `toolbar` never submits. A field inside its own `MalachiteContext` sits in
|
|
4940
|
+
* another shadow root and is outside the form.
|
|
4941
|
+
*/
|
|
4942
|
+
onSubmit?: (event: default_2.FormEvent<HTMLFormElement>) => void;
|
|
4904
4943
|
/** Renders a back button before the header icon. */
|
|
4905
4944
|
onBack?: () => void;
|
|
4906
4945
|
/** Maximum panel width. Default: 1080. */
|
|
@@ -5353,6 +5392,12 @@ export declare interface TabItem {
|
|
|
5353
5392
|
key: string;
|
|
5354
5393
|
label: default_2.ReactNode;
|
|
5355
5394
|
disabled?: boolean;
|
|
5395
|
+
/**
|
|
5396
|
+
* The tab's panel. Give it on any item and `Tabs` renders a `tabpanel` per item below the
|
|
5397
|
+
* strip; leave it off every item and the strip is all it renders, for a consumer that
|
|
5398
|
+
* switches its own content.
|
|
5399
|
+
*/
|
|
5400
|
+
content?: default_2.ReactNode;
|
|
5356
5401
|
}
|
|
5357
5402
|
|
|
5358
5403
|
export declare const Table: <T = Record<string, unknown>>({ columns, data, loading, error, errorTitle, errorSubTitle, emptyTitle, emptySubTitle, bordered, showHeader, rowKey, scrollHeight, size, rowDensity, layout, headerVariant, title, subtitle, extra, rowClassName, rowVariant, onRow, onClickRow, selectedRowKey, scrollSelectedIntoView, rowSelection, pagination, className, style, stickyHeaderTop, scrollX, rowSection, renderSectionDivider, onVisibleOrderChange, virtual, virtualRowHeightEstimate, virtualScrollElement, }: TableProps<T>) => JSX_2.Element;
|
|
@@ -5530,6 +5575,12 @@ export declare interface TabsProps {
|
|
|
5530
5575
|
activeKey: string;
|
|
5531
5576
|
onChange: (key: string) => void;
|
|
5532
5577
|
trailing?: default_2.ReactNode;
|
|
5578
|
+
/**
|
|
5579
|
+
* Unmount a panel when its tab is left. By default a panel mounts the first time its tab is
|
|
5580
|
+
* opened and then stays mounted, hidden, so a filter, a search or a scroll position survives
|
|
5581
|
+
* a round trip and its data is not fetched again.
|
|
5582
|
+
*/
|
|
5583
|
+
destroyInactivePanels?: boolean;
|
|
5533
5584
|
className?: string;
|
|
5534
5585
|
style?: default_2.CSSProperties;
|
|
5535
5586
|
}
|