@langchain/macaw-components 1.0.0-beta.9 → 1.1.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/README.md +3 -3
- package/dist/_chunks/{ErrorState-CmPX01HV.js → ErrorState-BY6VBCRB.js} +2 -2
- package/dist/_chunks/{ErrorState-CmPX01HV.js.map → ErrorState-BY6VBCRB.js.map} +1 -1
- package/dist/_chunks/{LoadingIndicator-DujSAzqj.js → LoadingIndicator-Itl4c0WV.js} +10 -10
- package/dist/_chunks/LoadingIndicator-Itl4c0WV.js.map +1 -0
- package/dist/base.css +19 -6
- package/dist/catalog.json +493 -480
- package/dist/components/BarChart/AnimatedBar.js +1 -1
- package/dist/components/BarChart/AnimatedBar.js.map +1 -1
- package/dist/components/BarChart/BarChartPlot.js +1 -1
- package/dist/components/BarChart/BarChartPlot.js.map +1 -1
- package/dist/components/Button/constants.js +4 -4
- package/dist/components/Button/constants.js.map +1 -1
- package/dist/components/ChartLegend/ChartLegend.js +1 -1
- package/dist/components/ChartLegend/ChartLegend.js.map +1 -1
- package/dist/components/ChartLegend/ChartLegendItemRenderer.js +2 -2
- package/dist/components/ChartLegend/ChartLegendItemRenderer.js.map +1 -1
- package/dist/components/ChartTooltip/ChartTooltip.js +2 -2
- package/dist/components/ChartTooltip/ChartTooltip.js.map +1 -1
- package/dist/components/Checkbox/constants.d.ts +1 -1
- package/dist/components/Checkbox/constants.js +1 -1
- package/dist/components/Checkbox/constants.js.map +1 -1
- package/dist/components/Code/CodeLite.js +2 -2
- package/dist/components/Code/CodeLite.js.map +1 -1
- package/dist/components/Code/JsonHighlighterExtension.js +1 -1
- package/dist/components/Code/JsonHighlighterExtension.js.map +1 -1
- package/dist/components/Command/Command.js +1 -1
- package/dist/components/Command/Command.js.map +1 -1
- package/dist/components/Command/CommandMenu.js +2 -2
- package/dist/components/Command/CommandMenu.js.map +1 -1
- package/dist/components/ContextMenu/ContextMenu.js +2 -2
- package/dist/components/ContextMenu/ContextMenu.js.map +1 -1
- package/dist/components/CopyButton/CopyButton.d.ts +3 -2
- package/dist/components/CopyButton/CopyButton.js +5 -0
- package/dist/components/CopyButton/CopyButton.js.map +1 -1
- package/dist/components/Dialog/index.d.ts +3 -2
- package/dist/components/Dialog/index.js +44 -17
- package/dist/components/Dialog/index.js.map +1 -1
- package/dist/components/DonutChart/DonutChart.js +1 -1
- package/dist/components/DonutChart/DonutChart.js.map +1 -1
- package/dist/components/DropdownMenu/DropdownMenu.js +3 -3
- package/dist/components/DropdownMenu/DropdownMenu.js.map +1 -1
- package/dist/components/ErrorState/ErrorState.js +1 -1
- package/dist/components/ErrorState/index.js +1 -1
- package/dist/components/GroupedTabs/GroupedTabs.d.ts +3 -2
- package/dist/components/GroupedTabs/GroupedTabs.js +3 -1
- package/dist/components/GroupedTabs/GroupedTabs.js.map +1 -1
- package/dist/components/Input/Input.js +7 -6
- package/dist/components/Input/Input.js.map +1 -1
- package/dist/components/Input/inputStyles.js +5 -5
- package/dist/components/Input/inputStyles.js.map +1 -1
- package/dist/components/Link/Link.js +3 -3
- package/dist/components/Link/Link.js.map +1 -1
- package/dist/components/Pane/Pane.d.ts +3 -2
- package/dist/components/Pane/Pane.js +107 -101
- package/dist/components/Pane/Pane.js.map +1 -1
- package/dist/components/Popover/Popover.js +15 -4
- package/dist/components/Popover/Popover.js.map +1 -1
- package/dist/components/Popover/constants.d.ts +1 -1
- package/dist/components/Popover/constants.js +1 -1
- package/dist/components/Popover/constants.js.map +1 -1
- package/dist/components/RadioButton/constants.d.ts +1 -1
- package/dist/components/RadioButton/constants.js +1 -1
- package/dist/components/RadioButton/constants.js.map +1 -1
- package/dist/components/RadioGroup/RadioGroupItem.js +1 -1
- package/dist/components/RadioGroup/RadioGroupItem.js.map +1 -1
- package/dist/components/SankeyChart/AnimatedSankeyLink.js +1 -1
- package/dist/components/SankeyChart/AnimatedSankeyLink.js.map +1 -1
- package/dist/components/SankeyChart/AnimatedSankeyNode.js +1 -1
- package/dist/components/SankeyChart/AnimatedSankeyNode.js.map +1 -1
- package/dist/components/Select/Select.d.ts +2 -1
- package/dist/components/Select/Select.js +5 -3
- package/dist/components/Select/Select.js.map +1 -1
- package/dist/components/Select/SelectPrimitive.js +6 -4
- package/dist/components/Select/SelectPrimitive.js.map +1 -1
- package/dist/components/Slider/Slider.js +1 -1
- package/dist/components/Slider/Slider.js.map +1 -1
- package/dist/components/SplitViewPane/SplitViewPane.js +1 -1
- package/dist/components/SplitViewPane/SplitViewPane.js.map +1 -1
- package/dist/components/Switch/Switch.js +1 -1
- package/dist/components/Switch/Switch.js.map +1 -1
- package/dist/components/Tabs/index.d.ts +3 -2
- package/dist/components/Tabs/index.js +5 -3
- package/dist/components/Tabs/index.js.map +1 -1
- package/dist/components/Textarea/Textarea.js +9 -9
- package/dist/components/Textarea/Textarea.js.map +1 -1
- package/dist/components/ThinkingState/LoadingIndicator.js +1 -1
- package/dist/components/ThinkingState/ThinkingState.js +1 -1
- package/dist/components/ThinkingState/index.js +1 -1
- package/dist/components/Toast/index.js +2 -2
- package/dist/components/Toast/index.js.map +1 -1
- package/dist/components/Tooltip/Tooltip.js +1 -1
- package/dist/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/components/Typeahead/TypeaheadParts.js +1 -1
- package/dist/components/Typeahead/TypeaheadParts.js.map +1 -1
- package/dist/components/Typeahead/TypeaheadView.js +9 -9
- package/dist/components/Typeahead/TypeaheadView.js.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components.css +2 -105
- package/dist/index.js +1 -1
- package/dist/utilities.css +2 -2
- package/dist/utils/ModalLayerContext.d.ts +23 -0
- package/dist/utils/ModalLayerContext.js +92 -0
- package/dist/utils/ModalLayerContext.js.map +1 -0
- package/dist/utils/cn.js +21 -11
- package/dist/utils/cn.js.map +1 -1
- package/dist/utils/dataAttributes.d.ts +9 -0
- package/dist/utils/dataAttributes.js +13 -0
- package/dist/utils/dataAttributes.js.map +1 -0
- package/docs/DESIGN.md +33 -3
- package/docs/STYLES.md +96 -46
- package/package.json +10 -9
- package/tailwind.preset.cjs +292 -332
- package/dist/_chunks/LoadingIndicator-DujSAzqj.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DonutChart.js","names":[],"sources":["../../../src/components/DonutChart/DonutChart.tsx"],"sourcesContent":["import {\n useState,\n type AriaAttributes,\n type FocusEvent,\n type FocusEventHandler,\n type HTMLAttributes,\n type PointerEvent,\n type PointerEventHandler,\n type ReactNode,\n} from 'react';\n\nimport {\n animated,\n type SpringValue,\n useReducedMotion,\n useSpring,\n} from '@react-spring/web';\nimport { Group } from '@visx/group';\nimport { Pie as Donut } from '@visx/shape';\n\nimport { CHART_DIMMED_OPACITY } from '../../utils/chartConstants';\nimport { cn } from '../../utils/cn';\nimport { ChartLegend, type ChartLegendProps } from '../ChartLegend';\nimport { Text } from '../Text';\nimport {\n collateDonutSegments,\n getDonutLegendItems,\n getDrawnSegments,\n sumSegmentValues,\n} from './DonutChart.utils';\n\n// Viewport-invariant units. The donut renders into a fixed-size viewBox and\n// scales via `preserveAspectRatio=\"xMidYMid meet\"`.\nconst DONUT_VIEWBOX = 200;\nconst DONUT_CENTER = DONUT_VIEWBOX / 2;\nconst DONUT_OUTER_RADIUS = DONUT_CENTER - 8;\nconst DONUT_INNER_RADIUS = DONUT_OUTER_RADIUS * 0.64;\n\nconst numberFormatter = new Intl.NumberFormat('en-US');\n\nconst formatSegmentValue = (value: number) => numberFormatter.format(value);\n\n/**\n * Sizes the center number against the donut hole: `1cqi` is 1% of the hole's\n * width, so a longer value resolves to a smaller size, capped at the heading\n * size so short values do not balloon.\n */\nconst getFittedCenterFontSize = (value: string) =>\n `min(1.75rem, ${100 / (value.length * 0.7)}cqi)`;\n\nexport type DonutChartSegment = {\n id: string;\n label: ReactNode;\n value: number;\n /** Use DS CSS color token; typically a `var(--chart-...)` reference. */\n color: string;\n /**\n * Marks a segment that already stands for a group of others — a remainder the\n * data source rolled up, say. `otherCollationThreshold` merges it with the\n * tail it collates instead of drawing a second \"Other\" beside it.\n */\n isOther?: boolean;\n};\n\ntype DonutArcDatumLike<Datum> = {\n data: Datum;\n value: number;\n index: number;\n startAngle: number;\n endAngle: number;\n padAngle: number;\n};\n\n/**\n * Everything `ChartLegend` accepts except `items`, which the donut derives from\n * `segments`. Namespacing these under `legendProps` keeps `className` and the\n * other DOM attributes on the chart root unambiguous.\n */\ntype DonutChartLegendProps = Omit<ChartLegendProps, 'items'>;\n\n/**\n * `legendProps` only exists while there is a legend to configure: with\n * `showLegend={false}` it narrows to `never`, so autocomplete stops offering it\n * and passing it is a type error rather than a silently ignored prop.\n */\ntype DonutChartLegendConfig =\n | {\n /** Defaults to true. */\n showLegend?: true;\n /** Forwarded to the rendered `ChartLegend`. */\n legendProps?: DonutChartLegendProps;\n }\n | {\n showLegend: false;\n legendProps?: never;\n };\n\nexport type DonutChartProps = Omit<\n HTMLAttributes<HTMLDivElement>,\n 'children' | 'onPointerOut'\n> &\n DonutChartLegendConfig & {\n segments: readonly DonutChartSegment[];\n /**\n * When provided and non-empty, only segments whose IDs are in the set are\n * rendered in the donut. Unselected segments stay in the legend with a 0%\n * share. IDs address the collated list, so the segments behind an \"Other\"\n * slice are selected as `DONUT_OTHER_SEGMENT_ID` rather than individually. A\n * set naming none of those IDs draws everything, so a selection outliving\n * the data it was made against cannot empty the chart.\n */\n selectedIds?: ReadonlySet<string>;\n /**\n * Number to render in the donut hole.\n */\n centerNumber?: string;\n /**\n * Descriptor for the number in the donut hole.\n */\n centerDescriptor?: string;\n /**\n * Scales `centerNumber` to the width of the donut hole.\n */\n scaleCenterNumberSize?: boolean;\n /** Emphasizes one segment and dims the rest. */\n activeSegmentId?: string | null;\n /** Emphasizes the segment represented by one external legend item. Built-in legends set this automatically. */\n activeLegendItemId?: string | null;\n /** Animates segments when they are drawn. Defaults to true. */\n shouldAnimate?: boolean;\n /** Names segments and makes them focusable. */\n getSegmentAriaLabel?: (\n segment: DonutChartSegment\n ) => AriaAttributes['aria-label'];\n /**\n * Set to false to skip drawing the donut. Use it to avoid the work while a\n * parent container is actively resizing. Defaults to true.\n */\n isRendering?: boolean;\n /**\n * Collates segments less than this set number to an \"Other\" slice, automatically merging any segment flagged `isOther`. Do not pass a value to render all segments, even if they are tiny.\n */\n otherCollationThreshold?: number;\n /**\n * Formats each segment's value for the legend. Defaults to a plain\n * `en-US` number; pass a unit-aware formatter for durations, bytes, cost.\n */\n formatValue?: (value: number) => ReactNode;\n onSegmentPointerMove?: (\n segment: DonutChartSegment,\n event: PointerEvent<SVGPathElement>\n ) => void;\n onSegmentPointerOut?: () => void;\n onSegmentPointerUp?: (\n segment: DonutChartSegment,\n event: PointerEvent<SVGPathElement>\n ) => void;\n onSegmentFocus?: (\n segment: DonutChartSegment,\n event: FocusEvent<SVGPathElement>\n ) => void;\n onSegmentBlur?: (\n segment: DonutChartSegment,\n event: FocusEvent<SVGPathElement>\n ) => void;\n };\n\ntype AnimatedDonutArcProps = {\n arc: DonutArcDatumLike<DonutChartSegment>;\n path: (arc: DonutArcDatumLike<DonutChartSegment>) => string | null;\n animationProgress: SpringValue<number>;\n animationStartAngle: number;\n animationEndAngle: number;\n 'aria-label'?: AriaAttributes['aria-label'];\n isDimmed: boolean;\n onPointerMove?: PointerEventHandler<SVGPathElement>;\n onPointerOut?: () => void;\n onPointerUp?: PointerEventHandler<SVGPathElement>;\n onFocus?: FocusEventHandler<SVGPathElement>;\n onBlur?: FocusEventHandler<SVGPathElement>;\n};\n\nconst AnimatedDonutArc = ({\n arc,\n path,\n animationProgress,\n animationStartAngle,\n animationEndAngle,\n isDimmed,\n onPointerMove,\n onPointerOut,\n onPointerUp,\n onFocus,\n onBlur,\n ...ariaProps\n}: AnimatedDonutArcProps) => {\n const isInteractive =\n onPointerMove != null || onPointerOut != null || onPointerUp != null;\n const handlePointerDown = (event: PointerEvent<SVGPathElement>) => {\n // Chromium can match :focus-visible when a focusable SVG path is clicked.\n // Keep the focus indicator for keyboard navigation without showing it for\n // pointer interaction.\n if (\n (event.pointerType === 'mouse' || event.pointerType === 'pen') &&\n event.currentTarget.hasAttribute('tabindex')\n ) {\n event.preventDefault();\n }\n };\n\n return (\n <animated.path\n fill={arc.data.color}\n opacity={isDimmed ? CHART_DIMMED_OPACITY : 1}\n className={cn(\n 'transition-opacity duration-fast focus:outline-none focus-visible:stroke-focus focus-visible:stroke-2 motion-reduce:transition-none',\n isInteractive && 'cursor-pointer'\n )}\n d={animationProgress.to((progress) => {\n const revealAngle =\n animationStartAngle +\n (animationEndAngle - animationStartAngle) * progress;\n const endAngle = Math.min(\n arc.endAngle,\n Math.max(arc.startAngle, revealAngle)\n );\n return path({ ...arc, endAngle }) ?? '';\n })}\n role={ariaProps['aria-label'] == null ? undefined : 'graphics-symbol img'}\n tabIndex={ariaProps['aria-label'] == null ? undefined : 0}\n {...ariaProps}\n onPointerMove={onPointerMove}\n onPointerDown={handlePointerDown}\n onPointerOut={onPointerOut}\n onPointerUp={onPointerUp}\n onFocus={onFocus}\n onBlur={onBlur}\n />\n );\n};\n\n/**\n * DonutChart renders a donut and its `ChartLegend` from a flat list of\n * segments. Consumers own the segment palette and pair the chart\n * with `ChartCard` and their own tooltip.\n *\n * The legend sits below the donut in narrow containers and beside it once the\n * container passes 496px. Pass `showLegend={false}` for the donut alone,\n * `legendProps` to configure the legend, and `legendProps.onItemClick` with\n * `selectedIds` to make legend entries filter the donut. A long tail of tiny\n * slices collapses into one \"Other\" slice via `otherCollationThreshold`, which\n * absorbs any segment flagged `isOther`.\n\n */\nexport const DonutChart = ({\n segments,\n selectedIds,\n centerNumber,\n centerDescriptor,\n scaleCenterNumberSize = false,\n activeSegmentId,\n activeLegendItemId,\n shouldAnimate = true,\n getSegmentAriaLabel,\n isRendering = true,\n otherCollationThreshold,\n showLegend = true,\n legendProps,\n formatValue = formatSegmentValue,\n onSegmentPointerMove,\n onSegmentPointerOut,\n onSegmentPointerUp,\n onSegmentFocus,\n onSegmentBlur,\n className,\n ...rest\n}: DonutChartProps) => {\n const [activeBuiltInLegendItemId, setActiveBuiltInLegendItemId] = useState<\n string | null\n >(null);\n const isReducedMotion = (useReducedMotion() ?? false) || !shouldAnimate;\n const ariaProps = { 'aria-label': rest['aria-label'] };\n const rootProps: HTMLAttributes<HTMLDivElement> = { ...rest };\n delete rootProps['aria-label'];\n\n // Collation happens before the selection, so the legend lists the same rows\n // the donut draws arcs for and neither reflows while filtering.\n const collatedSegments = collateDonutSegments(\n segments,\n otherCollationThreshold\n );\n const drawnSegments = getDrawnSegments(collatedSegments, selectedIds);\n const renderedSegments = drawnSegments.filter((segment) => segment.value > 0);\n const drawnTotal = sumSegmentValues(drawnSegments);\n const drawnIds = new Set(drawnSegments.map((segment) => segment.id));\n const drawnArcIds = new Set(renderedSegments.map((segment) => segment.id));\n const hasDrawnSegments = isRendering && drawnTotal > 0;\n const segmentAnimationKey = JSON.stringify(\n renderedSegments.map((segment) => [segment.id, segment.value])\n );\n // A single sweep angle reveals the arcs in sequence, leaving only one moving\n // boundary regardless of how many colored segments the donut contains.\n const [animation] = useSpring(\n () => ({\n from: { progress: 0 },\n to: { progress: hasDrawnSegments ? 1 : 0 },\n reset: true,\n immediate: isReducedMotion,\n }),\n [segmentAnimationKey, hasDrawnSegments, isReducedMotion]\n );\n\n const legendItems = getDonutLegendItems({\n segments: collatedSegments,\n selectedIds,\n drawnIds,\n drawnTotal,\n formatValue,\n });\n const hasLegend = showLegend && collatedSegments.length > 0;\n const legendLayout = legendProps?.layout ?? 'list';\n const requestedActiveLegendItemId =\n (hasLegend ? activeBuiltInLegendItemId : null) ?? activeLegendItemId;\n const renderedActiveLegendItemId =\n requestedActiveLegendItemId != null &&\n drawnArcIds.has(requestedActiveLegendItemId)\n ? requestedActiveLegendItemId\n : null;\n const renderedActiveSegmentId =\n activeSegmentId != null && drawnArcIds.has(activeSegmentId)\n ? activeSegmentId\n : null;\n const activeId = renderedActiveLegendItemId ?? renderedActiveSegmentId;\n\n const donut = (\n <div className=\"relative flex size-full min-h-0 min-w-0 items-center justify-center [&>svg]:max-h-[22.5rem] [&>svg]:max-w-[22.5rem]\">\n <svg\n viewBox={`0 0 ${DONUT_VIEWBOX} ${DONUT_VIEWBOX}`}\n preserveAspectRatio=\"xMidYMid meet\"\n className=\"size-full\"\n role={getSegmentAriaLabel == null ? 'img' : 'graphics-document group'}\n {...ariaProps}\n >\n {isRendering && (\n <>\n {drawnTotal > 0 && (\n <Group\n top={DONUT_CENTER}\n left={DONUT_CENTER}\n className={cn(\n activeId == null &&\n '[&:focus-within>path:not(:focus)]:opacity-[0.45] [&>path:focus]:opacity-100'\n )}\n >\n <Donut\n data={renderedSegments}\n pieValue={(segment) => segment.value}\n pieSort={null}\n pieSortValues={null}\n outerRadius={DONUT_OUTER_RADIUS}\n innerRadius={DONUT_INNER_RADIUS}\n >\n {(donut) => {\n const animationStartAngle = donut.arcs[0]?.startAngle ?? 0;\n const animationEndAngle =\n donut.arcs.at(-1)?.endAngle ?? animationStartAngle;\n return donut.arcs.map((arc) => (\n <AnimatedDonutArc\n key={arc.data.id}\n arc={arc}\n path={donut.path}\n animationProgress={animation.progress}\n animationStartAngle={animationStartAngle}\n animationEndAngle={animationEndAngle}\n aria-label={getSegmentAriaLabel?.(arc.data)}\n isDimmed={activeId != null && activeId !== arc.data.id}\n onPointerMove={\n onSegmentPointerMove == null\n ? undefined\n : (event) => onSegmentPointerMove(arc.data, event)\n }\n onPointerOut={onSegmentPointerOut}\n onPointerUp={\n onSegmentPointerUp == null\n ? undefined\n : (event) => onSegmentPointerUp(arc.data, event)\n }\n onFocus={\n onSegmentFocus == null\n ? undefined\n : (event) => onSegmentFocus(arc.data, event)\n }\n onBlur={\n onSegmentBlur == null\n ? undefined\n : (event) => onSegmentBlur(arc.data, event)\n }\n />\n ));\n }}\n </Donut>\n </Group>\n )}\n {(centerNumber || centerDescriptor) != null && (\n <foreignObject\n x={DONUT_CENTER - DONUT_INNER_RADIUS}\n y={DONUT_CENTER - DONUT_INNER_RADIUS}\n width={DONUT_INNER_RADIUS * 2}\n height={DONUT_INNER_RADIUS * 2}\n className=\"pointer-events-none\"\n >\n <div\n className=\"flex size-full min-w-0 flex-col items-center justify-center\"\n style={{ containerType: 'inline-size' }}\n >\n <Text\n as=\"span\"\n variant=\"h2\"\n weight=\"semibold\"\n className={cn(\n scaleCenterNumberSize && 'block w-full text-center'\n )}\n style={\n scaleCenterNumberSize && centerNumber != null\n ? { fontSize: getFittedCenterFontSize(centerNumber) }\n : undefined\n }\n >\n {centerNumber}\n </Text>\n <Text as=\"span\" variant=\"xs\" color=\"tertiary\">\n {centerDescriptor}\n </Text>\n </div>\n </foreignObject>\n )}\n </>\n )}\n </svg>\n </div>\n );\n\n const legend = (\n <ChartLegend\n aria-label={\n ariaProps['aria-label'] == null\n ? undefined\n : `${ariaProps['aria-label']} legend`\n }\n {...legendProps}\n layout={legendLayout}\n items={legendItems}\n onItemActiveChange={(item) => {\n setActiveBuiltInLegendItemId(item?.id ?? null);\n legendProps?.onItemActiveChange?.(item);\n }}\n />\n );\n\n return (\n <div\n className={cn('size-full min-h-0 min-w-0 @container', className)}\n {...rootProps}\n >\n {hasLegend ? (\n <div\n className={cn(\n 'grid size-full min-h-0 min-w-0 grid-cols-1 items-center justify-stretch',\n legendLayout === 'list'\n ? 'grid-rows-[minmax(0,1fr)_minmax(0,45%)] gap-space-3 @[496px]:grid-cols-2 @[496px]:grid-rows-[minmax(0,1fr)] @[496px]:justify-center @[496px]:gap-space-5'\n : 'grid-rows-[minmax(0,1fr)_auto] gap-space-2'\n )}\n >\n {donut}\n {legendLayout === 'list' ? (\n <div className=\"scroll-mask-t scroll-mask-b h-full min-h-0 min-w-0 overflow-y-auto overflow-x-hidden\">\n <div className=\"flex min-h-full flex-col\">\n <div className=\"my-auto\">{legend}</div>\n </div>\n </div>\n ) : (\n legend\n )}\n </div>\n ) : (\n donut\n )}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;AAiCA,IAAM,gBAAgB;AACtB,IAAM,eAAe,gB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gB,OACrC,EAAE,UAAU,wBAAwB,YAAY,EAAE,IAClD,KAAA;MAGL,UAAA;KACG,CAAA,GACN,oBAAC,MAAD;MAAM,IAAG;MAAO,SAAQ;MAAK,OAAM;MAChC,UAAA;KACG,CAAA,CACH;;GACQ,CAAA,CAEjB,EAAA,CAAA;EAED,CAAA;CACF,CAAA;CAGP,MAAM,SACJ,oBAAC,aAAD;EACE,cACE,UAAU,iBAAiB,OACvB,KAAA,IACA,GAAG,UAAU,cAAc;EAEjC,GAAI;EACJ,QAAQ;EACR,OAAO;EACP,qBAAqB,SAAS;GAC5B,6BAA6B,MAAM,MAAM,IAAI;GAC7C,aAAa,qBAAqB,IAAI;EACxC;CACD,CAAA;CAGH,OACE,oBAAC,OAAD;EACE,WAAW,GAAG,wCAAwC,SAAS;EAC/D,GAAI;EAEH,UAAA,YACC,qBAAC,OAAD;GACE,WAAW,GACT,2EACA,iBAAiB,SACb,6JACA,4CACN;GANF,UAAA,CAQG,OACA,iBAAiB,SAChB,oBAAC,OAAD;IAAK,WAAU;IACb,UAAA,oBAAC,OAAD;KAAK,WAAU;KACb,UAAA,oBAAC,OAAD;MAAK,WAAU;MAAW,UAAA;KAAY,CAAA;IACnC,CAAA;GACF,CAAA,IAEL,MAEC;EAEL,CAAA,IAAA;CAEC,CAAA;AAET"}
|
|
1
|
+
{"version":3,"file":"DonutChart.js","names":[],"sources":["../../../src/components/DonutChart/DonutChart.tsx"],"sourcesContent":["import {\n useState,\n type AriaAttributes,\n type FocusEvent,\n type FocusEventHandler,\n type HTMLAttributes,\n type PointerEvent,\n type PointerEventHandler,\n type ReactNode,\n} from 'react';\n\nimport {\n animated,\n type SpringValue,\n useReducedMotion,\n useSpring,\n} from '@react-spring/web';\nimport { Group } from '@visx/group';\nimport { Pie as Donut } from '@visx/shape';\n\nimport { CHART_DIMMED_OPACITY } from '../../utils/chartConstants';\nimport { cn } from '../../utils/cn';\nimport { ChartLegend, type ChartLegendProps } from '../ChartLegend';\nimport { Text } from '../Text';\nimport {\n collateDonutSegments,\n getDonutLegendItems,\n getDrawnSegments,\n sumSegmentValues,\n} from './DonutChart.utils';\n\n// Viewport-invariant units. The donut renders into a fixed-size viewBox and\n// scales via `preserveAspectRatio=\"xMidYMid meet\"`.\nconst DONUT_VIEWBOX = 200;\nconst DONUT_CENTER = DONUT_VIEWBOX / 2;\nconst DONUT_OUTER_RADIUS = DONUT_CENTER - 8;\nconst DONUT_INNER_RADIUS = DONUT_OUTER_RADIUS * 0.64;\n\nconst numberFormatter = new Intl.NumberFormat('en-US');\n\nconst formatSegmentValue = (value: number) => numberFormatter.format(value);\n\n/**\n * Sizes the center number against the donut hole: `1cqi` is 1% of the hole's\n * width, so a longer value resolves to a smaller size, capped at the heading\n * size so short values do not balloon.\n */\nconst getFittedCenterFontSize = (value: string) =>\n `min(1.75rem, ${100 / (value.length * 0.7)}cqi)`;\n\nexport type DonutChartSegment = {\n id: string;\n label: ReactNode;\n value: number;\n /** Use DS CSS color token; typically a `var(--chart-...)` reference. */\n color: string;\n /**\n * Marks a segment that already stands for a group of others — a remainder the\n * data source rolled up, say. `otherCollationThreshold` merges it with the\n * tail it collates instead of drawing a second \"Other\" beside it.\n */\n isOther?: boolean;\n};\n\ntype DonutArcDatumLike<Datum> = {\n data: Datum;\n value: number;\n index: number;\n startAngle: number;\n endAngle: number;\n padAngle: number;\n};\n\n/**\n * Everything `ChartLegend` accepts except `items`, which the donut derives from\n * `segments`. Namespacing these under `legendProps` keeps `className` and the\n * other DOM attributes on the chart root unambiguous.\n */\ntype DonutChartLegendProps = Omit<ChartLegendProps, 'items'>;\n\n/**\n * `legendProps` only exists while there is a legend to configure: with\n * `showLegend={false}` it narrows to `never`, so autocomplete stops offering it\n * and passing it is a type error rather than a silently ignored prop.\n */\ntype DonutChartLegendConfig =\n | {\n /** Defaults to true. */\n showLegend?: true;\n /** Forwarded to the rendered `ChartLegend`. */\n legendProps?: DonutChartLegendProps;\n }\n | {\n showLegend: false;\n legendProps?: never;\n };\n\nexport type DonutChartProps = Omit<\n HTMLAttributes<HTMLDivElement>,\n 'children' | 'onPointerOut'\n> &\n DonutChartLegendConfig & {\n segments: readonly DonutChartSegment[];\n /**\n * When provided and non-empty, only segments whose IDs are in the set are\n * rendered in the donut. Unselected segments stay in the legend with a 0%\n * share. IDs address the collated list, so the segments behind an \"Other\"\n * slice are selected as `DONUT_OTHER_SEGMENT_ID` rather than individually. A\n * set naming none of those IDs draws everything, so a selection outliving\n * the data it was made against cannot empty the chart.\n */\n selectedIds?: ReadonlySet<string>;\n /**\n * Number to render in the donut hole.\n */\n centerNumber?: string;\n /**\n * Descriptor for the number in the donut hole.\n */\n centerDescriptor?: string;\n /**\n * Scales `centerNumber` to the width of the donut hole.\n */\n scaleCenterNumberSize?: boolean;\n /** Emphasizes one segment and dims the rest. */\n activeSegmentId?: string | null;\n /** Emphasizes the segment represented by one external legend item. Built-in legends set this automatically. */\n activeLegendItemId?: string | null;\n /** Animates segments when they are drawn. Defaults to true. */\n shouldAnimate?: boolean;\n /** Names segments and makes them focusable. */\n getSegmentAriaLabel?: (\n segment: DonutChartSegment\n ) => AriaAttributes['aria-label'];\n /**\n * Set to false to skip drawing the donut. Use it to avoid the work while a\n * parent container is actively resizing. Defaults to true.\n */\n isRendering?: boolean;\n /**\n * Collates segments less than this set number to an \"Other\" slice, automatically merging any segment flagged `isOther`. Do not pass a value to render all segments, even if they are tiny.\n */\n otherCollationThreshold?: number;\n /**\n * Formats each segment's value for the legend. Defaults to a plain\n * `en-US` number; pass a unit-aware formatter for durations, bytes, cost.\n */\n formatValue?: (value: number) => ReactNode;\n onSegmentPointerMove?: (\n segment: DonutChartSegment,\n event: PointerEvent<SVGPathElement>\n ) => void;\n onSegmentPointerOut?: () => void;\n onSegmentPointerUp?: (\n segment: DonutChartSegment,\n event: PointerEvent<SVGPathElement>\n ) => void;\n onSegmentFocus?: (\n segment: DonutChartSegment,\n event: FocusEvent<SVGPathElement>\n ) => void;\n onSegmentBlur?: (\n segment: DonutChartSegment,\n event: FocusEvent<SVGPathElement>\n ) => void;\n };\n\ntype AnimatedDonutArcProps = {\n arc: DonutArcDatumLike<DonutChartSegment>;\n path: (arc: DonutArcDatumLike<DonutChartSegment>) => string | null;\n animationProgress: SpringValue<number>;\n animationStartAngle: number;\n animationEndAngle: number;\n 'aria-label'?: AriaAttributes['aria-label'];\n isDimmed: boolean;\n onPointerMove?: PointerEventHandler<SVGPathElement>;\n onPointerOut?: () => void;\n onPointerUp?: PointerEventHandler<SVGPathElement>;\n onFocus?: FocusEventHandler<SVGPathElement>;\n onBlur?: FocusEventHandler<SVGPathElement>;\n};\n\nconst AnimatedDonutArc = ({\n arc,\n path,\n animationProgress,\n animationStartAngle,\n animationEndAngle,\n isDimmed,\n onPointerMove,\n onPointerOut,\n onPointerUp,\n onFocus,\n onBlur,\n ...ariaProps\n}: AnimatedDonutArcProps) => {\n const isInteractive =\n onPointerMove != null || onPointerOut != null || onPointerUp != null;\n const handlePointerDown = (event: PointerEvent<SVGPathElement>) => {\n // Chromium can match :focus-visible when a focusable SVG path is clicked.\n // Keep the focus indicator for keyboard navigation without showing it for\n // pointer interaction.\n if (\n (event.pointerType === 'mouse' || event.pointerType === 'pen') &&\n event.currentTarget.hasAttribute('tabindex')\n ) {\n event.preventDefault();\n }\n };\n\n return (\n <animated.path\n fill={arc.data.color}\n opacity={isDimmed ? CHART_DIMMED_OPACITY : 1}\n className={cn(\n 'transition-opacity duration-fast focus:outline-hidden focus-visible:stroke-focus focus-visible:stroke-2 motion-reduce:transition-none',\n isInteractive && 'cursor-pointer'\n )}\n d={animationProgress.to((progress) => {\n const revealAngle =\n animationStartAngle +\n (animationEndAngle - animationStartAngle) * progress;\n const endAngle = Math.min(\n arc.endAngle,\n Math.max(arc.startAngle, revealAngle)\n );\n return path({ ...arc, endAngle }) ?? '';\n })}\n role={ariaProps['aria-label'] == null ? undefined : 'graphics-symbol img'}\n tabIndex={ariaProps['aria-label'] == null ? undefined : 0}\n {...ariaProps}\n onPointerMove={onPointerMove}\n onPointerDown={handlePointerDown}\n onPointerOut={onPointerOut}\n onPointerUp={onPointerUp}\n onFocus={onFocus}\n onBlur={onBlur}\n />\n );\n};\n\n/**\n * DonutChart renders a donut and its `ChartLegend` from a flat list of\n * segments. Consumers own the segment palette and pair the chart\n * with `ChartCard` and their own tooltip.\n *\n * The legend sits below the donut in narrow containers and beside it once the\n * container passes 496px. Pass `showLegend={false}` for the donut alone,\n * `legendProps` to configure the legend, and `legendProps.onItemClick` with\n * `selectedIds` to make legend entries filter the donut. A long tail of tiny\n * slices collapses into one \"Other\" slice via `otherCollationThreshold`, which\n * absorbs any segment flagged `isOther`.\n\n */\nexport const DonutChart = ({\n segments,\n selectedIds,\n centerNumber,\n centerDescriptor,\n scaleCenterNumberSize = false,\n activeSegmentId,\n activeLegendItemId,\n shouldAnimate = true,\n getSegmentAriaLabel,\n isRendering = true,\n otherCollationThreshold,\n showLegend = true,\n legendProps,\n formatValue = formatSegmentValue,\n onSegmentPointerMove,\n onSegmentPointerOut,\n onSegmentPointerUp,\n onSegmentFocus,\n onSegmentBlur,\n className,\n ...rest\n}: DonutChartProps) => {\n const [activeBuiltInLegendItemId, setActiveBuiltInLegendItemId] = useState<\n string | null\n >(null);\n const isReducedMotion = (useReducedMotion() ?? false) || !shouldAnimate;\n const ariaProps = { 'aria-label': rest['aria-label'] };\n const rootProps: HTMLAttributes<HTMLDivElement> = { ...rest };\n delete rootProps['aria-label'];\n\n // Collation happens before the selection, so the legend lists the same rows\n // the donut draws arcs for and neither reflows while filtering.\n const collatedSegments = collateDonutSegments(\n segments,\n otherCollationThreshold\n );\n const drawnSegments = getDrawnSegments(collatedSegments, selectedIds);\n const renderedSegments = drawnSegments.filter((segment) => segment.value > 0);\n const drawnTotal = sumSegmentValues(drawnSegments);\n const drawnIds = new Set(drawnSegments.map((segment) => segment.id));\n const drawnArcIds = new Set(renderedSegments.map((segment) => segment.id));\n const hasDrawnSegments = isRendering && drawnTotal > 0;\n const segmentAnimationKey = JSON.stringify(\n renderedSegments.map((segment) => [segment.id, segment.value])\n );\n // A single sweep angle reveals the arcs in sequence, leaving only one moving\n // boundary regardless of how many colored segments the donut contains.\n const [animation] = useSpring(\n () => ({\n from: { progress: 0 },\n to: { progress: hasDrawnSegments ? 1 : 0 },\n reset: true,\n immediate: isReducedMotion,\n }),\n [segmentAnimationKey, hasDrawnSegments, isReducedMotion]\n );\n\n const legendItems = getDonutLegendItems({\n segments: collatedSegments,\n selectedIds,\n drawnIds,\n drawnTotal,\n formatValue,\n });\n const hasLegend = showLegend && collatedSegments.length > 0;\n const legendLayout = legendProps?.layout ?? 'list';\n const requestedActiveLegendItemId =\n (hasLegend ? activeBuiltInLegendItemId : null) ?? activeLegendItemId;\n const renderedActiveLegendItemId =\n requestedActiveLegendItemId != null &&\n drawnArcIds.has(requestedActiveLegendItemId)\n ? requestedActiveLegendItemId\n : null;\n const renderedActiveSegmentId =\n activeSegmentId != null && drawnArcIds.has(activeSegmentId)\n ? activeSegmentId\n : null;\n const activeId = renderedActiveLegendItemId ?? renderedActiveSegmentId;\n\n const donut = (\n <div className=\"relative flex size-full min-h-0 min-w-0 items-center justify-center [&>svg]:max-h-[22.5rem] [&>svg]:max-w-[22.5rem]\">\n <svg\n viewBox={`0 0 ${DONUT_VIEWBOX} ${DONUT_VIEWBOX}`}\n preserveAspectRatio=\"xMidYMid meet\"\n className=\"size-full\"\n role={getSegmentAriaLabel == null ? 'img' : 'graphics-document group'}\n {...ariaProps}\n >\n {isRendering && (\n <>\n {drawnTotal > 0 && (\n <Group\n top={DONUT_CENTER}\n left={DONUT_CENTER}\n className={cn(\n activeId == null &&\n '[&:focus-within>path:not(:focus)]:opacity-[0.45] [&>path:focus]:opacity-100'\n )}\n >\n <Donut\n data={renderedSegments}\n pieValue={(segment) => segment.value}\n pieSort={null}\n pieSortValues={null}\n outerRadius={DONUT_OUTER_RADIUS}\n innerRadius={DONUT_INNER_RADIUS}\n >\n {(donut) => {\n const animationStartAngle = donut.arcs[0]?.startAngle ?? 0;\n const animationEndAngle =\n donut.arcs.at(-1)?.endAngle ?? animationStartAngle;\n return donut.arcs.map((arc) => (\n <AnimatedDonutArc\n key={arc.data.id}\n arc={arc}\n path={donut.path}\n animationProgress={animation.progress}\n animationStartAngle={animationStartAngle}\n animationEndAngle={animationEndAngle}\n aria-label={getSegmentAriaLabel?.(arc.data)}\n isDimmed={activeId != null && activeId !== arc.data.id}\n onPointerMove={\n onSegmentPointerMove == null\n ? undefined\n : (event) => onSegmentPointerMove(arc.data, event)\n }\n onPointerOut={onSegmentPointerOut}\n onPointerUp={\n onSegmentPointerUp == null\n ? undefined\n : (event) => onSegmentPointerUp(arc.data, event)\n }\n onFocus={\n onSegmentFocus == null\n ? undefined\n : (event) => onSegmentFocus(arc.data, event)\n }\n onBlur={\n onSegmentBlur == null\n ? undefined\n : (event) => onSegmentBlur(arc.data, event)\n }\n />\n ));\n }}\n </Donut>\n </Group>\n )}\n {(centerNumber || centerDescriptor) != null && (\n <foreignObject\n x={DONUT_CENTER - DONUT_INNER_RADIUS}\n y={DONUT_CENTER - DONUT_INNER_RADIUS}\n width={DONUT_INNER_RADIUS * 2}\n height={DONUT_INNER_RADIUS * 2}\n className=\"pointer-events-none\"\n >\n <div\n className=\"flex size-full min-w-0 flex-col items-center justify-center\"\n style={{ containerType: 'inline-size' }}\n >\n <Text\n as=\"span\"\n variant=\"h2\"\n weight=\"semibold\"\n className={cn(\n scaleCenterNumberSize && 'block w-full text-center'\n )}\n style={\n scaleCenterNumberSize && centerNumber != null\n ? { fontSize: getFittedCenterFontSize(centerNumber) }\n : undefined\n }\n >\n {centerNumber}\n </Text>\n <Text as=\"span\" variant=\"xs\" color=\"tertiary\">\n {centerDescriptor}\n </Text>\n </div>\n </foreignObject>\n )}\n </>\n )}\n </svg>\n </div>\n );\n\n const legend = (\n <ChartLegend\n aria-label={\n ariaProps['aria-label'] == null\n ? undefined\n : `${ariaProps['aria-label']} legend`\n }\n {...legendProps}\n layout={legendLayout}\n items={legendItems}\n onItemActiveChange={(item) => {\n setActiveBuiltInLegendItemId(item?.id ?? null);\n legendProps?.onItemActiveChange?.(item);\n }}\n />\n );\n\n return (\n <div\n className={cn('size-full min-h-0 min-w-0 @container', className)}\n {...rootProps}\n >\n {hasLegend ? (\n <div\n className={cn(\n 'grid size-full min-h-0 min-w-0 grid-cols-1 items-center justify-stretch',\n legendLayout === 'list'\n ? 'grid-rows-[minmax(0,1fr)_minmax(0,45%)] gap-space-3 @[496px]:grid-cols-2 @[496px]:grid-rows-[minmax(0,1fr)] @[496px]:justify-center @[496px]:gap-space-5'\n : 'grid-rows-[minmax(0,1fr)_auto] gap-space-2'\n )}\n >\n {donut}\n {legendLayout === 'list' ? (\n <div className=\"scroll-mask-t scroll-mask-b h-full min-h-0 min-w-0 overflow-y-auto overflow-x-hidden\">\n <div className=\"flex min-h-full flex-col\">\n <div className=\"my-auto\">{legend}</div>\n </div>\n </div>\n ) : (\n legend\n )}\n </div>\n ) : (\n donut\n )}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;AAiCA,IAAM,gBAAgB;AACtB,IAAM,eAAe,gBAAgB;AACrC,IAAM,qBAAqB;AAC3B,IAAM,qBAAqB,qBAAqB;AAEhD,IAAM,kBAAkB,IAAI,KAAK,aAAa,OAAO;AAErD,IAAM,sBAAsB,UAAkB,gBAAgB,OAAO,KAAK;;;;;;AAO1E,IAAM,2BAA2B,UAC/B,gBAAgB,OAAO,MAAM,SAAS,IAAK;AAsI7C,IAAM,oBAAoB,EACxB,KACA,MACA,mBACA,qBACA,mBACA,UACA,eACA,cACA,aACA,SACA,QACA,GAAG,gBACwB;CAC3B,MAAM,gBACJ,iBAAiB,QAAQ,gBAAgB,QAAQ,eAAe;CAClE,MAAM,qBAAqB,UAAwC;EAIjE,KACG,MAAM,gBAAgB,WAAW,MAAM,gBAAgB,UACxD,MAAM,cAAc,aAAa,UAAU,GAE3C,MAAM,eAAe;CAEzB;CAEA,OACE,oBAAC,SAAS,MAAV;EACE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ACE,WAAW,GACT,2EACA,iBAAiB,SACb,6JACA,4CACN;GANF,UAAA,CAQG,OACA,iBAAiB,SAChB,oBAAC,OAAD;IAAK,WAAU;IACb,UAAA,oBAAC,OAAD;KAAK,WAAU;KACb,UAAA,oBAAC,OAAD;MAAK,WAAU;MAAW,UAAA;KAAY,CAAA;IACnC,CAAA;GACF,CAAA,IAEL,MAEC;EAEL,CAAA,IAAA;CAEC,CAAA;AAET"}
|
|
@@ -112,20 +112,20 @@ var DropdownMenuContent = React$1.forwardRef(({ className, sideOffset = 4, child
|
|
|
112
112
|
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;
|
|
113
113
|
var DropdownMenuItem = React$1.forwardRef(({ className, inset, size = "md", ...props }, ref) => /* @__PURE__ */ jsx(DropdownMenuPrimitive.Item, {
|
|
114
114
|
ref,
|
|
115
|
-
className: cn("flex cursor-pointer select-none items-center rounded-sm px-space-2 py-space-1 outline-
|
|
115
|
+
className: cn("flex cursor-pointer select-none items-center rounded-sm px-space-2 py-space-1 outline-hidden transition-colors focus:bg-elevated-hover data-[disabled]:pointer-events-none data-[disabled]:opacity-50", OPTION_ROW_SIZES[size].minHeightClassName, size === "sm" ? "text-xs leading-4" : "text-sm", inset && "pl-space-6", className),
|
|
116
116
|
...props
|
|
117
117
|
}));
|
|
118
118
|
DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName;
|
|
119
119
|
var DropdownMenuSeparator = React$1.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(DropdownMenuPrimitive.Separator, {
|
|
120
120
|
ref,
|
|
121
|
-
className: cn("my-space-1 h-px
|
|
121
|
+
className: cn("my-space-1 h-px border-b border-subtle", className),
|
|
122
122
|
...props
|
|
123
123
|
}));
|
|
124
124
|
DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName;
|
|
125
125
|
var DropdownMenuSub = DropdownMenuPrimitive.Sub;
|
|
126
126
|
var DropdownMenuSubTrigger = React$1.forwardRef(({ className, inset, children, size = "md", ...props }, ref) => /* @__PURE__ */ jsx(DropdownMenuPrimitive.SubTrigger, {
|
|
127
127
|
ref,
|
|
128
|
-
className: cn("flex cursor-pointer select-none items-center rounded-sm px-space-2 py-space-1 outline-
|
|
128
|
+
className: cn("flex cursor-pointer select-none items-center rounded-sm px-space-2 py-space-1 outline-hidden transition-colors focus:bg-elevated-hover data-[state=open]:bg-elevated-hover", OPTION_ROW_SIZES[size].minHeightClassName, size === "sm" ? "text-xs leading-4" : "text-sm", inset && "pl-space-6", className),
|
|
129
129
|
...props,
|
|
130
130
|
children
|
|
131
131
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DropdownMenu.js","names":[],"sources":["../../../src/components/DropdownMenu/DropdownMenu.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\n\nimport { cn } from '../../utils/cn';\nimport {\n OPTION_ROW_SIZES,\n type OptionRowSize,\n} from '../../utils/componentSizes';\nimport { useZIndex } from '../../utils/useZIndex';\nimport { ZIndexProvider } from '../../utils/ZIndexContext';\nimport zIndices from '../../utils/zIndices';\n\nexport const DropdownMenu: typeof DropdownMenuPrimitive.Root = (props) => {\n const [open = false, onOpenChange] = useControllableState({\n prop: props.open,\n defaultProp: props.defaultOpen ?? false,\n onChange: props.onOpenChange,\n });\n\n return (\n <DropdownMenuPrimitive.Root\n {...props}\n open={open}\n onOpenChange={onOpenChange}\n defaultOpen={undefined}\n />\n );\n};\n\nexport const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;\n\nexport const DropdownMenuPortal = DropdownMenuPrimitive.Portal;\n\nexport const DropdownMenuGroup = DropdownMenuPrimitive.Group;\n\nexport const DropdownMenuLabel = DropdownMenuPrimitive.Label;\n\n/**\n * Stops clicks outside an open dropdown from reaching elements underneath it\n * (e.g. a table row's `onClick`) without covering the viewport, so scrolling\n * the content behind the menu keeps working natively.\n *\n * React delegates `onClick` at the root in the bubble phase, so a capture-phase\n * `click` listener on `document` runs first and can stop the event before it\n * gets there. pointerdown is left alone so Radix's outside-dismiss keeps\n * working; the wheel listener is passive so native scroll is never interrupted,\n * it just also dismisses the menu (an open menu jitters as Radix repositions it\n * to follow its trigger while scrolling).\n *\n * \"Inside\" is any element with `role=\"menu\"` in its ancestry — Radix gives that\n * role to both the content and its submenus (which portal out separately), so\n * clicks and scrolls inside a submenu are correctly treated as inside.\n */\nconst OutsideClickGuard = () => {\n const cleanupTimerRef =\n React.useRef<ReturnType<typeof setTimeout>>(undefined);\n const pointerDownOutsideRef = React.useRef(false);\n\n React.useLayoutEffect(() => {\n clearTimeout(cleanupTimerRef.current);\n pointerDownOutsideRef.current = false;\n\n const isOutside = (target: EventTarget | null) =>\n !(target instanceof Element) || !target.closest('[role=\"menu\"]');\n\n // Observe (don't block) outside pointerdowns: Radix dismisses on them, so\n // this tells us the trailing click needs absorbing on cleanup.\n const onPointerDown = (event: PointerEvent) => {\n if (isOutside(event.target)) pointerDownOutsideRef.current = true;\n };\n document.addEventListener('pointerdown', onPointerDown, true);\n\n // Block clicks that land outside the menu from reaching the content beneath.\n const onClick = (event: MouseEvent) => {\n if (isOutside(event.target)) {\n event.preventDefault();\n event.stopPropagation();\n }\n };\n document.addEventListener('click', onClick, true);\n\n // Dismiss on scroll of the content behind the menu: an anchored menu that\n // stays open jitters as Radix repositions it to chase its trigger. Passive,\n // so the wheel still scrolls the content natively on the same gesture.\n // Scrolling inside the menu (e.g. a details panel) leaves it open.\n const onWheel = (event: WheelEvent) => {\n if (isOutside(event.target)) {\n document.dispatchEvent(\n new KeyboardEvent('keydown', { key: 'Escape', bubbles: true })\n );\n }\n };\n document.addEventListener('wheel', onWheel, { passive: true });\n\n return () => {\n document.removeEventListener('pointerdown', onPointerDown, true);\n document.removeEventListener('click', onClick, true);\n document.removeEventListener('wheel', onWheel);\n\n // Radix dismisses on the outside pointerdown and unmounts this guard\n // before the trailing click fires, so absorb that one click here. Only\n // for pointer dismissals — Escape / item selection have no trailing\n // outside click, and absorbing an unrelated later click would be wrong.\n if (!pointerDownOutsideRef.current) return;\n\n const absorb = (event: Event) => {\n event.preventDefault();\n event.stopPropagation();\n };\n const opts = { capture: true, once: true } as const;\n document.addEventListener('pointerup', absorb, opts);\n document.addEventListener('mouseup', absorb, opts);\n document.addEventListener('click', absorb, opts);\n\n cleanupTimerRef.current = setTimeout(() => {\n if (typeof document === 'undefined') return;\n document.removeEventListener('pointerup', absorb, { capture: true });\n document.removeEventListener('mouseup', absorb, { capture: true });\n document.removeEventListener('click', absorb, { capture: true });\n }, 300);\n };\n }, []);\n\n return null;\n};\n\nexport const DropdownMenuContent = React.forwardRef<\n React.ElementRef<typeof DropdownMenuPrimitive.Content>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content> & {\n /**\n * When true, stops clicks outside the open menu from reaching elements\n * underneath (e.g. table rows), while leaving scrolling of that content\n * intact. Radix's outside-click dismiss still works normally.\n */\n preventClickThrough?: boolean;\n }\n>(\n (\n { className, sideOffset = 4, children, preventClickThrough, ...props },\n ref\n ) => {\n const zIndex = useZIndex(zIndices.popover);\n\n return (\n <DropdownMenuPrimitive.Portal>\n <DropdownMenuPrimitive.Content\n ref={ref}\n sideOffset={sideOffset}\n className={cn(\n 'min-w-[8rem] overflow-hidden rounded-md border border-subtle bg-popover p-space-1 shadow-lg',\n className\n )}\n {...props}\n style={{ zIndex, ...props.style }}\n >\n {preventClickThrough && <OutsideClickGuard />}\n <ZIndexProvider value={zIndex}>{children}</ZIndexProvider>\n </DropdownMenuPrimitive.Content>\n </DropdownMenuPrimitive.Portal>\n );\n }\n);\nDropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;\n\nexport const DropdownMenuItem = React.forwardRef<\n React.ElementRef<typeof DropdownMenuPrimitive.Item>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {\n inset?: boolean;\n /**\n * Controls minimum row height and default label typography.\n * Rich or multiline content grows intrinsically.\n */\n size?: OptionRowSize;\n }\n>(({ className, inset, size = 'md', ...props }, ref) => (\n <DropdownMenuPrimitive.Item\n ref={ref}\n className={cn(\n 'flex cursor-pointer select-none items-center rounded-sm px-space-2 py-space-1 outline-none transition-colors focus:bg-surface-level-2 data-[disabled]:pointer-events-none data-[disabled]:opacity-50',\n OPTION_ROW_SIZES[size].minHeightClassName,\n size === 'sm' ? 'text-xs leading-4' : 'text-sm',\n inset && 'pl-space-6',\n className\n )}\n {...props}\n />\n));\nDropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName;\n\nexport const DropdownMenuSeparator = React.forwardRef<\n React.ElementRef<typeof DropdownMenuPrimitive.Separator>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>\n>(({ className, ...props }, ref) => (\n <DropdownMenuPrimitive.Separator\n ref={ref}\n className={cn('my-space-1 h-px bg-surface-level-2', className)}\n {...props}\n />\n));\nDropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName;\n\nexport const DropdownMenuSub = DropdownMenuPrimitive.Sub;\n\nexport const DropdownMenuSubTrigger = React.forwardRef<\n React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & {\n inset?: boolean;\n /**\n * Controls minimum row height and default label typography.\n * Rich or multiline content grows intrinsically.\n */\n size?: OptionRowSize;\n }\n>(({ className, inset, children, size = 'md', ...props }, ref) => (\n <DropdownMenuPrimitive.SubTrigger\n ref={ref}\n className={cn(\n 'flex cursor-pointer select-none items-center rounded-sm px-space-2 py-space-1 outline-none transition-colors focus:bg-surface-level-2 data-[state=open]:bg-surface-level-2',\n OPTION_ROW_SIZES[size].minHeightClassName,\n size === 'sm' ? 'text-xs leading-4' : 'text-sm',\n inset && 'pl-space-6',\n className\n )}\n {...props}\n >\n {children}\n </DropdownMenuPrimitive.SubTrigger>\n));\nDropdownMenuSubTrigger.displayName =\n DropdownMenuPrimitive.SubTrigger.displayName;\n\nexport const DropdownMenuSubContent = React.forwardRef<\n React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>\n>(({ className, children, ...props }, ref) => {\n const zIndex = useZIndex(zIndices.popover);\n\n return (\n <DropdownMenuPrimitive.Portal>\n <DropdownMenuPrimitive.SubContent\n ref={ref}\n className={cn(\n 'min-w-[8rem] overflow-hidden rounded-md border border-subtle bg-popover p-space-1 shadow-lg',\n className\n )}\n style={{ zIndex }}\n {...props}\n >\n <ZIndexProvider value={zIndex}>{children}</ZIndexProvider>\n </DropdownMenuPrimitive.SubContent>\n </DropdownMenuPrimitive.Portal>\n );\n});\nDropdownMenuSubContent.displayName =\n DropdownMenuPrimitive.SubContent.displayName;\n"],"mappings":";;;;;;;;;;AAcA,IAAa,gBAAmD,UAAU;CACxE,MAAM,CAAC,OAAO,OAAO,gBAAgB,qBAAqB;EACxD,MAAM,MAAM;EACZ,aAAa,MAAM,eAAe;EAClC,UAAU,MAAM;CAClB,CAAC;CAED,OACE,oBAAC,sBAAsB,MAAvB;EACE,GAAI;EACE;EACQ;EACd,aAAa,KAAA;CACd,CAAA;AAEL;AAEA,IAAa,sBAAsB,sBAAsB;AAEzD,IAAa,qBAAqB,sBAAsB;AAExD,IAAa,oBAAoB,sBAAsB;AAEvD,IAAa,oBAAoB,sBAAsB;;;;;;;;;;;;;;;;;AAkBvD,IAAM,0BAA0B;CAC9B,MAAM,kBACJ,QAAM,OAAsC,KAAA,CAAS;CACvD,MAAM,wBAAwB,QAAM,OAAO,KAAK;CAEhD,QAAM,sBAAsB;EAC1B,aAAa,gBAAgB,OAAO;EACpC,sBAAsB,UAAU;EAEhC,MAAM,aAAa,WACjB,EAAE,kBAAkB,YAAY,CAAC,OAAO,QAAQ,iBAAe;EAIjE,MAAM,iBAAiB,UAAwB;GAC7C,IAAI,UAAU,MAAM,MAAM,GAAG,sBAAsB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AA,UACE,oBAAC,sBAAsB,YAAvB;EACO;EACL,WAAW,GACT,+FACA,SACF;EACA,OAAO,EAAE,OAAO;EAChB,GAAI;EAEJ,UAAA,oBAAC,gBAAD;GAAgB,OAAO;GAAS;EAAyB,CAAA;CACzB,CAAA,EACN,CAAA;AAElC,CAAC;AACD,uBAAuB,cACrB,sBAAsB,WAAW"}
|
|
1
|
+
{"version":3,"file":"DropdownMenu.js","names":[],"sources":["../../../src/components/DropdownMenu/DropdownMenu.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\n\nimport { cn } from '../../utils/cn';\nimport {\n OPTION_ROW_SIZES,\n type OptionRowSize,\n} from '../../utils/componentSizes';\nimport { useZIndex } from '../../utils/useZIndex';\nimport { ZIndexProvider } from '../../utils/ZIndexContext';\nimport zIndices from '../../utils/zIndices';\n\nexport const DropdownMenu: typeof DropdownMenuPrimitive.Root = (props) => {\n const [open = false, onOpenChange] = useControllableState({\n prop: props.open,\n defaultProp: props.defaultOpen ?? false,\n onChange: props.onOpenChange,\n });\n\n return (\n <DropdownMenuPrimitive.Root\n {...props}\n open={open}\n onOpenChange={onOpenChange}\n defaultOpen={undefined}\n />\n );\n};\n\nexport const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;\n\nexport const DropdownMenuPortal = DropdownMenuPrimitive.Portal;\n\nexport const DropdownMenuGroup = DropdownMenuPrimitive.Group;\n\nexport const DropdownMenuLabel = DropdownMenuPrimitive.Label;\n\n/**\n * Stops clicks outside an open dropdown from reaching elements underneath it\n * (e.g. a table row's `onClick`) without covering the viewport, so scrolling\n * the content behind the menu keeps working natively.\n *\n * React delegates `onClick` at the root in the bubble phase, so a capture-phase\n * `click` listener on `document` runs first and can stop the event before it\n * gets there. pointerdown is left alone so Radix's outside-dismiss keeps\n * working; the wheel listener is passive so native scroll is never interrupted,\n * it just also dismisses the menu (an open menu jitters as Radix repositions it\n * to follow its trigger while scrolling).\n *\n * \"Inside\" is any element with `role=\"menu\"` in its ancestry — Radix gives that\n * role to both the content and its submenus (which portal out separately), so\n * clicks and scrolls inside a submenu are correctly treated as inside.\n */\nconst OutsideClickGuard = () => {\n const cleanupTimerRef =\n React.useRef<ReturnType<typeof setTimeout>>(undefined);\n const pointerDownOutsideRef = React.useRef(false);\n\n React.useLayoutEffect(() => {\n clearTimeout(cleanupTimerRef.current);\n pointerDownOutsideRef.current = false;\n\n const isOutside = (target: EventTarget | null) =>\n !(target instanceof Element) || !target.closest('[role=\"menu\"]');\n\n // Observe (don't block) outside pointerdowns: Radix dismisses on them, so\n // this tells us the trailing click needs absorbing on cleanup.\n const onPointerDown = (event: PointerEvent) => {\n if (isOutside(event.target)) pointerDownOutsideRef.current = true;\n };\n document.addEventListener('pointerdown', onPointerDown, true);\n\n // Block clicks that land outside the menu from reaching the content beneath.\n const onClick = (event: MouseEvent) => {\n if (isOutside(event.target)) {\n event.preventDefault();\n event.stopPropagation();\n }\n };\n document.addEventListener('click', onClick, true);\n\n // Dismiss on scroll of the content behind the menu: an anchored menu that\n // stays open jitters as Radix repositions it to chase its trigger. Passive,\n // so the wheel still scrolls the content natively on the same gesture.\n // Scrolling inside the menu (e.g. a details panel) leaves it open.\n const onWheel = (event: WheelEvent) => {\n if (isOutside(event.target)) {\n document.dispatchEvent(\n new KeyboardEvent('keydown', { key: 'Escape', bubbles: true })\n );\n }\n };\n document.addEventListener('wheel', onWheel, { passive: true });\n\n return () => {\n document.removeEventListener('pointerdown', onPointerDown, true);\n document.removeEventListener('click', onClick, true);\n document.removeEventListener('wheel', onWheel);\n\n // Radix dismisses on the outside pointerdown and unmounts this guard\n // before the trailing click fires, so absorb that one click here. Only\n // for pointer dismissals — Escape / item selection have no trailing\n // outside click, and absorbing an unrelated later click would be wrong.\n if (!pointerDownOutsideRef.current) return;\n\n const absorb = (event: Event) => {\n event.preventDefault();\n event.stopPropagation();\n };\n const opts = { capture: true, once: true } as const;\n document.addEventListener('pointerup', absorb, opts);\n document.addEventListener('mouseup', absorb, opts);\n document.addEventListener('click', absorb, opts);\n\n cleanupTimerRef.current = setTimeout(() => {\n if (typeof document === 'undefined') return;\n document.removeEventListener('pointerup', absorb, { capture: true });\n document.removeEventListener('mouseup', absorb, { capture: true });\n document.removeEventListener('click', absorb, { capture: true });\n }, 300);\n };\n }, []);\n\n return null;\n};\n\nexport const DropdownMenuContent = React.forwardRef<\n React.ElementRef<typeof DropdownMenuPrimitive.Content>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content> & {\n /**\n * When true, stops clicks outside the open menu from reaching elements\n * underneath (e.g. table rows), while leaving scrolling of that content\n * intact. Radix's outside-click dismiss still works normally.\n */\n preventClickThrough?: boolean;\n }\n>(\n (\n { className, sideOffset = 4, children, preventClickThrough, ...props },\n ref\n ) => {\n const zIndex = useZIndex(zIndices.popover);\n\n return (\n <DropdownMenuPrimitive.Portal>\n <DropdownMenuPrimitive.Content\n ref={ref}\n sideOffset={sideOffset}\n className={cn(\n 'min-w-[8rem] overflow-hidden rounded-md border border-subtle bg-popover p-space-1 shadow-lg',\n className\n )}\n {...props}\n style={{ zIndex, ...props.style }}\n >\n {preventClickThrough && <OutsideClickGuard />}\n <ZIndexProvider value={zIndex}>{children}</ZIndexProvider>\n </DropdownMenuPrimitive.Content>\n </DropdownMenuPrimitive.Portal>\n );\n }\n);\nDropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;\n\nexport const DropdownMenuItem = React.forwardRef<\n React.ElementRef<typeof DropdownMenuPrimitive.Item>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {\n inset?: boolean;\n /**\n * Controls minimum row height and default label typography.\n * Rich or multiline content grows intrinsically.\n */\n size?: OptionRowSize;\n }\n>(({ className, inset, size = 'md', ...props }, ref) => (\n <DropdownMenuPrimitive.Item\n ref={ref}\n className={cn(\n 'flex cursor-pointer select-none items-center rounded-sm px-space-2 py-space-1 outline-hidden transition-colors focus:bg-elevated-hover data-[disabled]:pointer-events-none data-[disabled]:opacity-50',\n OPTION_ROW_SIZES[size].minHeightClassName,\n size === 'sm' ? 'text-xs leading-4' : 'text-sm',\n inset && 'pl-space-6',\n className\n )}\n {...props}\n />\n));\nDropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName;\n\nexport const DropdownMenuSeparator = React.forwardRef<\n React.ElementRef<typeof DropdownMenuPrimitive.Separator>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>\n>(({ className, ...props }, ref) => (\n <DropdownMenuPrimitive.Separator\n ref={ref}\n className={cn('my-space-1 h-px border-b border-subtle', className)}\n {...props}\n />\n));\nDropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName;\n\nexport const DropdownMenuSub = DropdownMenuPrimitive.Sub;\n\nexport const DropdownMenuSubTrigger = React.forwardRef<\n React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & {\n inset?: boolean;\n /**\n * Controls minimum row height and default label typography.\n * Rich or multiline content grows intrinsically.\n */\n size?: OptionRowSize;\n }\n>(({ className, inset, children, size = 'md', ...props }, ref) => (\n <DropdownMenuPrimitive.SubTrigger\n ref={ref}\n className={cn(\n 'flex cursor-pointer select-none items-center rounded-sm px-space-2 py-space-1 outline-hidden transition-colors focus:bg-elevated-hover data-[state=open]:bg-elevated-hover',\n OPTION_ROW_SIZES[size].minHeightClassName,\n size === 'sm' ? 'text-xs leading-4' : 'text-sm',\n inset && 'pl-space-6',\n className\n )}\n {...props}\n >\n {children}\n </DropdownMenuPrimitive.SubTrigger>\n));\nDropdownMenuSubTrigger.displayName =\n DropdownMenuPrimitive.SubTrigger.displayName;\n\nexport const DropdownMenuSubContent = React.forwardRef<\n React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>\n>(({ className, children, ...props }, ref) => {\n const zIndex = useZIndex(zIndices.popover);\n\n return (\n <DropdownMenuPrimitive.Portal>\n <DropdownMenuPrimitive.SubContent\n ref={ref}\n className={cn(\n 'min-w-[8rem] overflow-hidden rounded-md border border-subtle bg-popover p-space-1 shadow-lg',\n className\n )}\n style={{ zIndex }}\n {...props}\n >\n <ZIndexProvider value={zIndex}>{children}</ZIndexProvider>\n </DropdownMenuPrimitive.SubContent>\n </DropdownMenuPrimitive.Portal>\n );\n});\nDropdownMenuSubContent.displayName =\n DropdownMenuPrimitive.SubContent.displayName;\n"],"mappings":";;;;;;;;;;AAcA,IAAa,gBAAmD,UAAU;CACxE,MAAM,CAAC,OAAO,OAAO,gBAAgB,qBAAqB;EACxD,MAAM,MAAM;EACZ,aAAa,MAAM,eAAe;EAClC,UAAU,MAAM;CAClB,CAAC;CAED,OACE,oBAAC,sBAAsB,MAAvB;EACE,GAAI;EACE;EACQ;EACd,aAAa,KAAA;CACd,CAAA;AAEL;AAEA,IAAa,sBAAsB,sBAAsB;AAEzD,IAAa,qBAAqB,sBAAsB;AAExD,IAAa,oBAAoB,sBAAsB;AAEvD,IAAa,oBAAoB,sBAAsB;;;;;;;;;;;;;;;;;AAkBvD,IAAM,0BAA0B;CAC9B,MAAM,kBACJ,QAAM,OAAsC,KAAA,CAAS;CACvD,MAAM,wBAAwB,QAAM,OAAO,KAAK;CAEhD,QAAM,sBAAsB;EAC1B,aAAa,gBAAgB,OAAO;EACpC,sBAAsB,UAAU;EAEhC,MAAM,aAAa,WACjB,EAAE,kBAAkB,YAAY,CAAC,OAAO,QAAQ,iBAAe;EAIjE,MAAM,iBAAiB,UAAwB;GAC7C,IAAI,UAAU,MAAM,MAAM,GAAG,sBAAsB,UAAU;EAC/D;EACA,SAAS,iBAAiB,eAAe,eAAe,IAAI;EAG5D,MAAM,WAAW,UAAsB;GACrC,IAAI,UAAU,MAAM,MAAM,GAAG;IAC3B,MAAM,eAAe;IACrB,MAAM,gBAAgB;GACxB;EACF;EACA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EACN,CAAA;AAElC,CAAC;AACD,uBAAuB,cACrB,sBAAsB,WAAW"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as ErrorState } from "../../_chunks/ErrorState-
|
|
1
|
+
import { t as ErrorState } from "../../_chunks/ErrorState-BY6VBCRB.js";
|
|
2
2
|
export { ErrorState };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as ErrorState } from "../../_chunks/ErrorState-
|
|
1
|
+
import { t as ErrorState } from "../../_chunks/ErrorState-BY6VBCRB.js";
|
|
2
2
|
export { ErrorState };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import { type ControlSize } from '../../utils/componentSizes.js';
|
|
3
|
+
import { type DataAttributes } from '../../utils/dataAttributes.js';
|
|
3
4
|
import type { IconComponent, IconWeight } from '../../utils/icon-types.js';
|
|
4
5
|
import type { TooltipProps } from '../Tooltip/index.js';
|
|
5
6
|
type GroupedTabsSize = Exclude<ControlSize, 'lg'>;
|
|
@@ -29,6 +30,6 @@ export type GroupedTabsProps<T extends string | number> = {
|
|
|
29
30
|
selectionClassName?: string;
|
|
30
31
|
/** Optional class for the indicator (e.g. to override top/height for custom margins) */
|
|
31
32
|
indicatorClassName?: string;
|
|
32
|
-
};
|
|
33
|
-
export declare const GroupedTabs: <T extends string | number>({ value, onChange, options, className, size, disabled, tooltip, selectionClassName, indicatorClassName, }: GroupedTabsProps<T>) => import("react").JSX.Element;
|
|
33
|
+
} & DataAttributes;
|
|
34
|
+
export declare const GroupedTabs: <T extends string | number>({ value, onChange, options, className, size, disabled, tooltip, selectionClassName, indicatorClassName, ...rest }: GroupedTabsProps<T>) => import("react").JSX.Element;
|
|
34
35
|
export {};
|
|
@@ -2,10 +2,11 @@ import { cn } from "../../utils/cn.js";
|
|
|
2
2
|
import { CONTROL_SIZES } from "../../utils/componentSizes.js";
|
|
3
3
|
import { Text } from "../Text/Text.js";
|
|
4
4
|
import { Tooltip } from "../Tooltip/Tooltip.js";
|
|
5
|
+
import { pickDataAttributes } from "../../utils/dataAttributes.js";
|
|
5
6
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
6
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
8
|
//#region packages/components/src/components/GroupedTabs/GroupedTabs.tsx
|
|
8
|
-
var GroupedTabs = ({ value, onChange, options, className, size = "sm", disabled, tooltip, selectionClassName, indicatorClassName }) => {
|
|
9
|
+
var GroupedTabs = ({ value, onChange, options, className, size = "sm", disabled, tooltip, selectionClassName, indicatorClassName, ...rest }) => {
|
|
9
10
|
const containerRef = useRef(null);
|
|
10
11
|
const buttonRefs = useRef([]);
|
|
11
12
|
const [clipState, setClipState] = useState({
|
|
@@ -46,6 +47,7 @@ var GroupedTabs = ({ value, onChange, options, className, size = "sm", disabled,
|
|
|
46
47
|
return /* @__PURE__ */ jsx(Tooltip, {
|
|
47
48
|
title: tooltip,
|
|
48
49
|
children: /* @__PURE__ */ jsxs("div", {
|
|
50
|
+
...pickDataAttributes(rest),
|
|
49
51
|
ref: containerRef,
|
|
50
52
|
className: cn("relative box-border flex w-fit border border-subtle bg-surface-level-1 dark:border-muted", CONTROL_SIZES[size].heightClassName, size === "md" ? "p-0.5" : "p-px", size === "xs" ? "gap-px" : "gap-0.5", size === "xs" ? "rounded-[2px]" : size === "sm" ? "rounded-[3px]" : "rounded-sm", className),
|
|
51
53
|
children: [clipState.path && /* @__PURE__ */ jsx("div", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroupedTabs.js","names":[],"sources":["../../../src/components/GroupedTabs/GroupedTabs.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\n\nimport { cn } from '../../utils/cn';\nimport { CONTROL_SIZES, type ControlSize } from '../../utils/componentSizes';\nimport type { IconComponent, IconWeight } from '../../utils/icon-types';\nimport { Text } from '../Text';\nimport type { TooltipProps } from '../Tooltip';\nimport { Tooltip } from '../Tooltip';\n\ntype GroupedTabsSize = Exclude<ControlSize, 'lg'>;\n\nexport interface GroupedTabOption<T> {\n display?: ReactNode | ((isActive: boolean) => ReactNode);\n value: T;\n disabled?: boolean;\n tooltip?: string | ReactNode;\n tooltipProps?: Omit<TooltipProps, 'children' | 'title'>;\n icon?: IconComponent;\n iconWeight?: IconWeight;\n leftDecorator?: ReactNode;\n rightDecorator?: ReactNode;\n className?: string;\n textClassName?: string;\n 'aria-label'?: string;\n}\n\nexport type GroupedTabsProps<T extends string | number> = {\n value: T;\n onChange: (value: T) => void;\n options: readonly GroupedTabOption<T>[];\n className?: string;\n /** Exact outer group height: xs=20px, sm=24px, md=32px. */\n size?: GroupedTabsSize;\n disabled?: boolean;\n tooltip?: string | ReactNode;\n selectionClassName?: string;\n /** Optional class for the indicator (e.g. to override top/height for custom margins) */\n indicatorClassName?: string;\n};\n\nexport const GroupedTabs = <T extends string | number>({\n value,\n onChange,\n options,\n className,\n size = 'sm',\n disabled,\n tooltip,\n selectionClassName,\n indicatorClassName,\n}: GroupedTabsProps<T>) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const buttonRefs = useRef<(HTMLButtonElement | null)[]>([]);\n const [clipState, setClipState] = useState<{\n path: string;\n isFirst: boolean;\n shouldAnimate: boolean;\n }>({ path: '', isFirst: true, shouldAnimate: false });\n const activeIndex = useMemo(\n () => options.findIndex((option) => option.value === value),\n [options, value]\n );\n\n const updateClipState = useCallback(\n (\n container: HTMLDivElement,\n activeButton: HTMLButtonElement,\n shouldAnimate: boolean\n ) => {\n const containerRect = container.getBoundingClientRect();\n const buttonRect = activeButton.getBoundingClientRect();\n const roundValue = size === 'xs' ? '1px' : size === 'sm' ? '2px' : '4px';\n\n const top = buttonRect.top - containerRect.top - container.clientTop;\n const bottom =\n containerRect.bottom - buttonRect.bottom - container.clientTop;\n const left = buttonRect.left - containerRect.left - container.clientLeft;\n const right =\n containerRect.right - buttonRect.right - container.clientLeft;\n\n const path = `inset(${top}px ${right}px ${bottom}px ${left}px round ${roundValue})`;\n setClipState((prev) =>\n prev.path === path\n ? prev\n : {\n path,\n isFirst: false,\n shouldAnimate: shouldAnimate && !prev.isFirst,\n }\n );\n },\n [size]\n );\n\n useEffect(() => {\n const container = containerRef.current;\n const activeButton = buttonRefs.current[activeIndex];\n if (!activeButton || !container) return;\n\n updateClipState(container, activeButton, true);\n\n const observer = new ResizeObserver(() =>\n updateClipState(container, activeButton, false)\n );\n observer.observe(container);\n observer.observe(activeButton);\n\n return () => observer.disconnect();\n }, [activeIndex, updateClipState, value]);\n\n const isActive = (option: GroupedTabOption<T>) => option.value === value;\n return (\n <Tooltip title={tooltip}>\n <div\n ref={containerRef}\n className={cn(\n 'relative box-border flex w-fit border border-subtle bg-surface-level-1 dark:border-muted',\n CONTROL_SIZES[size].heightClassName,\n size === 'md' ? 'p-0.5' : 'p-px',\n size === 'xs' ? 'gap-px' : 'gap-0.5',\n size === 'xs'\n ? 'rounded-[2px]'\n : size === 'sm'\n ? 'rounded-[3px]'\n : 'rounded-sm',\n className\n )}\n >\n {/* Clip-path animated background indicator */}\n {clipState.path && (\n <div\n aria-hidden\n className={cn(\n 'pointer-events-none absolute inset-0 bg-surface-level-4',\n selectionClassName,\n indicatorClassName\n )}\n style={{\n clipPath: clipState.path,\n transition: clipState.shouldAnimate\n ? 'clip-path 0.25s ease-out, background-color 0.25s ease-out'\n : 'none',\n }}\n />\n )}\n\n {options.map((option, idx) => (\n <Tooltip\n key={option.value}\n title={option.tooltip}\n {...option.tooltipProps}\n >\n {/* eslint-disable-next-line react/forbid-elements */}\n <button\n ref={(el) => {\n buttonRefs.current[idx] = el;\n }}\n type=\"button\"\n aria-label={option['aria-label']}\n onClick={() => onChange(option.value)}\n disabled={option.disabled || disabled}\n className={cn(\n 'relative flex h-full items-center gap-space-1',\n 'transition-colors duration-fast',\n {\n 'rounded-xs px-space-1': size === 'xs',\n 'rounded-xs px-space-2': size === 'sm',\n 'rounded-sm px-space-2': size === 'md',\n },\n {\n 'text-primary': isActive(option),\n 'text-secondary hover:bg-surface-level-1-hover':\n !isActive(option),\n },\n (option.disabled || disabled) &&\n 'text-disabled hover:bg-transparent',\n option.className\n )}\n >\n {option.icon && (\n <option.icon\n aria-hidden\n className={size === 'xs' ? 'size-3' : 'size-4'}\n weight={option.iconWeight}\n />\n )}\n {option.leftDecorator}\n {option.display &&\n (typeof option.display === 'function' ? (\n option.display(isActive(option))\n ) : (\n <Text\n variant={size === 'xs' ? 'xs' : 'sm'}\n className={cn('font-medium', option.textClassName)}\n >\n {option.display}\n </Text>\n ))}\n {option.rightDecorator}\n </button>\n </Tooltip>\n ))}\n </div>\n </Tooltip>\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"GroupedTabs.js","names":[],"sources":["../../../src/components/GroupedTabs/GroupedTabs.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\n\nimport { cn } from '../../utils/cn';\nimport { CONTROL_SIZES, type ControlSize } from '../../utils/componentSizes';\nimport {\n type DataAttributes,\n pickDataAttributes,\n} from '../../utils/dataAttributes';\nimport type { IconComponent, IconWeight } from '../../utils/icon-types';\nimport { Text } from '../Text';\nimport type { TooltipProps } from '../Tooltip';\nimport { Tooltip } from '../Tooltip';\n\ntype GroupedTabsSize = Exclude<ControlSize, 'lg'>;\n\nexport interface GroupedTabOption<T> {\n display?: ReactNode | ((isActive: boolean) => ReactNode);\n value: T;\n disabled?: boolean;\n tooltip?: string | ReactNode;\n tooltipProps?: Omit<TooltipProps, 'children' | 'title'>;\n icon?: IconComponent;\n iconWeight?: IconWeight;\n leftDecorator?: ReactNode;\n rightDecorator?: ReactNode;\n className?: string;\n textClassName?: string;\n 'aria-label'?: string;\n}\n\nexport type GroupedTabsProps<T extends string | number> = {\n value: T;\n onChange: (value: T) => void;\n options: readonly GroupedTabOption<T>[];\n className?: string;\n /** Exact outer group height: xs=20px, sm=24px, md=32px. */\n size?: GroupedTabsSize;\n disabled?: boolean;\n tooltip?: string | ReactNode;\n selectionClassName?: string;\n /** Optional class for the indicator (e.g. to override top/height for custom margins) */\n indicatorClassName?: string;\n} & DataAttributes;\n\nexport const GroupedTabs = <T extends string | number>({\n value,\n onChange,\n options,\n className,\n size = 'sm',\n disabled,\n tooltip,\n selectionClassName,\n indicatorClassName,\n ...rest\n}: GroupedTabsProps<T>) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const buttonRefs = useRef<(HTMLButtonElement | null)[]>([]);\n const [clipState, setClipState] = useState<{\n path: string;\n isFirst: boolean;\n shouldAnimate: boolean;\n }>({ path: '', isFirst: true, shouldAnimate: false });\n const activeIndex = useMemo(\n () => options.findIndex((option) => option.value === value),\n [options, value]\n );\n\n const updateClipState = useCallback(\n (\n container: HTMLDivElement,\n activeButton: HTMLButtonElement,\n shouldAnimate: boolean\n ) => {\n const containerRect = container.getBoundingClientRect();\n const buttonRect = activeButton.getBoundingClientRect();\n const roundValue = size === 'xs' ? '1px' : size === 'sm' ? '2px' : '4px';\n\n const top = buttonRect.top - containerRect.top - container.clientTop;\n const bottom =\n containerRect.bottom - buttonRect.bottom - container.clientTop;\n const left = buttonRect.left - containerRect.left - container.clientLeft;\n const right =\n containerRect.right - buttonRect.right - container.clientLeft;\n\n const path = `inset(${top}px ${right}px ${bottom}px ${left}px round ${roundValue})`;\n setClipState((prev) =>\n prev.path === path\n ? prev\n : {\n path,\n isFirst: false,\n shouldAnimate: shouldAnimate && !prev.isFirst,\n }\n );\n },\n [size]\n );\n\n useEffect(() => {\n const container = containerRef.current;\n const activeButton = buttonRefs.current[activeIndex];\n if (!activeButton || !container) return;\n\n updateClipState(container, activeButton, true);\n\n const observer = new ResizeObserver(() =>\n updateClipState(container, activeButton, false)\n );\n observer.observe(container);\n observer.observe(activeButton);\n\n return () => observer.disconnect();\n }, [activeIndex, updateClipState, value]);\n\n const isActive = (option: GroupedTabOption<T>) => option.value === value;\n return (\n <Tooltip title={tooltip}>\n <div\n {...pickDataAttributes(rest)}\n ref={containerRef}\n className={cn(\n 'relative box-border flex w-fit border border-subtle bg-surface-level-1 dark:border-muted',\n CONTROL_SIZES[size].heightClassName,\n size === 'md' ? 'p-0.5' : 'p-px',\n size === 'xs' ? 'gap-px' : 'gap-0.5',\n size === 'xs'\n ? 'rounded-[2px]'\n : size === 'sm'\n ? 'rounded-[3px]'\n : 'rounded-sm',\n className\n )}\n >\n {/* Clip-path animated background indicator */}\n {clipState.path && (\n <div\n aria-hidden\n className={cn(\n 'pointer-events-none absolute inset-0 bg-surface-level-4',\n selectionClassName,\n indicatorClassName\n )}\n style={{\n clipPath: clipState.path,\n transition: clipState.shouldAnimate\n ? 'clip-path 0.25s ease-out, background-color 0.25s ease-out'\n : 'none',\n }}\n />\n )}\n\n {options.map((option, idx) => (\n <Tooltip\n key={option.value}\n title={option.tooltip}\n {...option.tooltipProps}\n >\n {/* eslint-disable-next-line react/forbid-elements */}\n <button\n ref={(el) => {\n buttonRefs.current[idx] = el;\n }}\n type=\"button\"\n aria-label={option['aria-label']}\n onClick={() => onChange(option.value)}\n disabled={option.disabled || disabled}\n className={cn(\n 'relative flex h-full items-center gap-space-1',\n 'transition-colors duration-fast',\n {\n 'rounded-xs px-space-1': size === 'xs',\n 'rounded-xs px-space-2': size === 'sm',\n 'rounded-sm px-space-2': size === 'md',\n },\n {\n 'text-primary': isActive(option),\n 'text-secondary hover:bg-surface-level-1-hover':\n !isActive(option),\n },\n (option.disabled || disabled) &&\n 'text-disabled hover:bg-transparent',\n option.className\n )}\n >\n {option.icon && (\n <option.icon\n aria-hidden\n className={size === 'xs' ? 'size-3' : 'size-4'}\n weight={option.iconWeight}\n />\n )}\n {option.leftDecorator}\n {option.display &&\n (typeof option.display === 'function' ? (\n option.display(isActive(option))\n ) : (\n <Text\n variant={size === 'xs' ? 'xs' : 'sm'}\n className={cn('font-medium', option.textClassName)}\n >\n {option.display}\n </Text>\n ))}\n {option.rightDecorator}\n </button>\n </Tooltip>\n ))}\n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OAAO;KACF;;GACD,GApDF,OAAO,KAoDL,CACV,CACE;;CACE,CAAA;AAEb"}
|
|
@@ -33,19 +33,19 @@ function InputIconSlot({ icon, action, size, disabled }) {
|
|
|
33
33
|
weight: "regular"
|
|
34
34
|
}) : null;
|
|
35
35
|
}
|
|
36
|
-
function FileSelection({ size, fileNames, placeholder }) {
|
|
36
|
+
function FileSelection({ size, fileNames, placeholder, disabled }) {
|
|
37
37
|
const summary = fileNames.length > 1 ? `${fileNames.length} files selected` : fileNames[0];
|
|
38
38
|
const textClasses = INPUT_TEXT_CLASSES[size];
|
|
39
39
|
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Text, {
|
|
40
40
|
"aria-hidden": true,
|
|
41
41
|
as: "span",
|
|
42
|
-
className: cn(textClasses, "min-w-0 flex-1 truncate", summary ? "text-primary" : "text-placeholder"),
|
|
42
|
+
className: cn(textClasses, "min-w-0 flex-1 truncate", summary ? "text-primary" : "text-placeholder", disabled && "text-disabled"),
|
|
43
43
|
children: summary ?? placeholder ?? "No file selected"
|
|
44
44
|
}), /* @__PURE__ */ jsx(Text, {
|
|
45
45
|
"aria-hidden": true,
|
|
46
46
|
as: "span",
|
|
47
47
|
weight: "medium",
|
|
48
|
-
className: cn(textClasses, "shrink-0 text-secondary"),
|
|
48
|
+
className: cn(textClasses, "shrink-0 text-secondary", disabled && "text-disabled"),
|
|
49
49
|
children: "Browse"
|
|
50
50
|
})] });
|
|
51
51
|
}
|
|
@@ -177,14 +177,15 @@ var Input = forwardRef(({ size = "lg", variant = "outlined", leftIcon, rightIcon
|
|
|
177
177
|
onClick: isFileInput ? openFilePicker : void 0,
|
|
178
178
|
children: [
|
|
179
179
|
effectiveLeftDecorator && /* @__PURE__ */ jsx("div", {
|
|
180
|
-
className: "flex items-center text-tertiary",
|
|
180
|
+
className: cn("flex items-center text-tertiary", disabled && "text-disabled"),
|
|
181
181
|
style: { marginInlineStart: leftActionOffset },
|
|
182
182
|
children: effectiveLeftDecorator
|
|
183
183
|
}),
|
|
184
184
|
isFileInput && /* @__PURE__ */ jsx(FileSelection, {
|
|
185
185
|
size,
|
|
186
186
|
fileNames: selectedFileNames,
|
|
187
|
-
placeholder
|
|
187
|
+
placeholder,
|
|
188
|
+
disabled
|
|
188
189
|
}),
|
|
189
190
|
isDateInput ? /* @__PURE__ */ jsxs("div", {
|
|
190
191
|
className: cn("relative flex min-w-0 flex-1 items-center", CONTROL_ICON_SIZES[size].sizeVariableClassName),
|
|
@@ -198,7 +199,7 @@ var Input = forwardRef(({ size = "lg", variant = "outlined", leftIcon, rightIcon
|
|
|
198
199
|
})]
|
|
199
200
|
}) : nativeInput,
|
|
200
201
|
effectiveRightDecorator && /* @__PURE__ */ jsx("div", {
|
|
201
|
-
className: cn("flex items-center text-tertiary", "gap-space-1"),
|
|
202
|
+
className: cn("flex items-center text-tertiary", "gap-space-1", disabled && "text-disabled"),
|
|
202
203
|
style: { marginInlineEnd: rightActionOffset },
|
|
203
204
|
children: effectiveRightDecorator
|
|
204
205
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.js","names":[],"sources":["../../../src/components/Input/Input.tsx"],"sourcesContent":["import type { ComponentProps, ReactNode } from 'react';\nimport { forwardRef, useEffect, useId, useRef, useState } from 'react';\n\nimport { useDebouncedCallback } from 'use-debounce';\n\nimport { CalendarBlankIcon } from '@phosphor-icons/react/dist/ssr/CalendarBlank';\nimport { EyeIcon } from '@phosphor-icons/react/dist/ssr/Eye';\nimport { EyeSlashIcon } from '@phosphor-icons/react/dist/ssr/EyeSlash';\nimport { PaperclipIcon } from '@phosphor-icons/react/dist/ssr/Paperclip';\n\nimport { cn } from '../../utils/cn';\nimport { CONTROL_ICON_SIZES } from '../../utils/controlIconSizes';\nimport type { IconComponent } from '../../utils/icon-types';\nimport { mergeRefs } from '../../utils/merge-refs';\nimport { Icon } from '../Icon';\nimport { IconButton } from '../IconButton';\nimport { Text } from '../Text';\nimport {\n DECORATOR_CLASSES,\n getInputContainerClasses,\n getInputElementClasses,\n INPUT_TEXT_CLASSES,\n} from './inputStyles';\nimport type { InputSize } from './inputStyles';\n\nexport type InputIconAction = Pick<\n ComponentProps<typeof IconButton>,\n 'icon' | 'label' | 'disabled' | 'tooltipProps'\n> & {\n onClick: NonNullable<ComponentProps<typeof IconButton>['onClick']>;\n};\n\nexport interface InputProps {\n /** Exact outer height. The default lg tier preserves the legacy 40px field. */\n size?: InputSize;\n variant?: 'outlined' | 'plain';\n /** Decorative icon. Input owns its size and color. */\n leftIcon?: IconComponent;\n /** Decorative icon. Input owns its size and color. */\n rightIcon?: IconComponent;\n /** Plain icon button. Takes precedence over leftIcon. */\n leftAction?: InputIconAction;\n /** Plain icon button. Takes precedence over rightIcon; precedes the password toggle. */\n rightAction?: InputIconAction;\n /** Custom content; overrides leftIcon/leftAction and the default file icon. */\n leftDecorator?: ReactNode;\n /** Custom content; overrides rightIcon/rightAction. The password toggle remains last. */\n rightDecorator?: ReactNode;\n /** Whether the input is disabled */\n disabled?: boolean;\n /** Whether the input has an error state */\n isError?: boolean;\n /** Label text displayed above the input */\n label?: string | ReactNode;\n /** Hint text displayed below the input */\n hintText?: string;\n /** Current input value */\n value?: string | null;\n /** Change handler that will be debounced */\n onChange: (\n value: string,\n event?: React.ChangeEvent<HTMLInputElement>\n ) => void;\n /** Placeholder text */\n placeholder?: string;\n /**\n * Input type. Limited to the \"text-like\" native types that share this\n * component's styled-text rendering and string value contract. `password`\n * renders a masked secret field with a show/hide toggle. `date` uses the\n * browser's native date picker; its value is a `YYYY-MM-DD` string.\n * `datetime-local` uses the native date+time picker; its value is a\n * `YYYY-MM-DDTHH:mm` string in the viewer's local time. `file` is\n * uncontrolled: read the selection from `event.target.files` on the change\n * event, and scope it with `accept`/`multiple`.\n */\n type?:\n | 'text'\n | 'email'\n | 'password'\n | 'number'\n | 'url'\n | 'date'\n | 'datetime-local'\n | 'file';\n /** Debounce delay in milliseconds (default: 300). Ignored for `type=\"file\"`. */\n debounceMs?: number;\n /** Additional CSS classes */\n className?: string;\n /** Input ID for accessibility */\n id?: string;\n /** Input name for forms */\n name?: string;\n /** Whether the field is required */\n required?: boolean;\n /** Auto focus on mount */\n autoFocus?: boolean;\n /** CSS class for the input container */\n inputContainerClassName?: string;\n /**\n * Which files the picker offers, as a comma-separated list of extensions or\n * MIME types (`'.csv,.json'`, `'image/*'`). `type=\"file\"` only. The browser\n * treats this as a filter, not a guarantee — validate the selection too.\n */\n accept?: string;\n /** Whether more than one file can be picked. `type=\"file\"` only. */\n multiple?: boolean;\n}\n\nfunction InputIconSlot({\n icon,\n action,\n size,\n disabled,\n}: {\n icon?: IconComponent;\n action?: InputIconAction;\n size: InputSize;\n disabled: boolean;\n}) {\n const isDisabled = disabled || action?.disabled;\n const colorClassName = isDisabled\n ? 'text-icon-disabled'\n : 'text-icon-secondary';\n\n return action ? (\n <IconButton\n {...action}\n color=\"secondary\"\n variant=\"plain\"\n size={CONTROL_ICON_SIZES[size].buttonSize}\n className={colorClassName}\n iconWeight=\"regular\"\n disabled={isDisabled}\n onMouseDown={(event) => event.preventDefault()}\n />\n ) : icon ? (\n <Icon\n aria-hidden\n icon={icon}\n iconClassName={CONTROL_ICON_SIZES[size].iconClassName}\n className={colorClassName}\n weight=\"regular\"\n />\n ) : null;\n}\n\nfunction FileSelection({\n size,\n fileNames,\n placeholder,\n}: {\n size: InputSize;\n fileNames: string[];\n placeholder?: string;\n}) {\n const summary =\n fileNames.length > 1 ? `${fileNames.length} files selected` : fileNames[0];\n const textClasses = INPUT_TEXT_CLASSES[size];\n\n return (\n <>\n <Text\n aria-hidden\n as=\"span\"\n className={cn(\n textClasses,\n 'min-w-0 flex-1 truncate',\n summary ? 'text-primary' : 'text-placeholder'\n )}\n >\n {summary ?? placeholder ?? 'No file selected'}\n </Text>\n <Text\n aria-hidden\n as=\"span\"\n weight=\"medium\"\n className={cn(textClasses, 'shrink-0 text-secondary')}\n >\n Browse\n </Text>\n </>\n );\n}\n\nexport const Input = forwardRef<\n HTMLInputElement,\n InputProps &\n Omit<React.InputHTMLAttributes<HTMLInputElement>, keyof InputProps>\n>(\n (\n {\n size = 'lg',\n variant = 'outlined',\n leftIcon,\n rightIcon,\n leftAction,\n rightAction,\n leftDecorator,\n rightDecorator,\n disabled = false,\n isError = false,\n label,\n hintText,\n value,\n onChange,\n placeholder,\n type = 'text',\n debounceMs = 0,\n className,\n inputContainerClassName,\n id,\n name,\n required = false,\n autoFocus = false,\n accept,\n multiple,\n 'aria-describedby': ariaDescribedBy,\n ...rest\n },\n ref\n ) => {\n const generatedId = useId();\n const inputId = id || generatedId;\n const hintTextId = `${inputId}-hint`;\n const describedBy =\n [hintText ? hintTextId : undefined, ariaDescribedBy]\n .filter(Boolean)\n .join(' ') || undefined;\n const shouldDebounce = debounceMs > 0;\n const isFileInput = type === 'file';\n const isPasswordInput = type === 'password';\n const isDateInput = type === 'date' || type === 'datetime-local';\n const [internalValue, setInternalValue] = useState(value);\n const [isPasswordVisible, setIsPasswordVisible] = useState(false);\n const [selectedFileNames, setSelectedFileNames] = useState<string[]>([]);\n const debouncedOnChange = useDebouncedCallback(onChange, debounceMs);\n const fileInputRef = useRef<HTMLInputElement>(null);\n\n useEffect(() => {\n if (!shouldDebounce) return;\n return () => debouncedOnChange.flush();\n }, [shouldDebounce, debouncedOnChange]);\n\n // Skip the click forwarded below, which would otherwise re-enter here.\n const openFilePicker = (event: React.MouseEvent<HTMLDivElement>) => {\n const target = event.target;\n if (\n disabled ||\n (target instanceof Element &&\n target.closest(\n 'button, a, input, select, textarea, summary, [role=\"button\"], [role=\"link\"], [contenteditable=\"true\"]'\n ))\n ) {\n return;\n }\n fileInputRef.current?.click();\n };\n\n useEffect(() => {\n if (shouldDebounce) setInternalValue(value);\n }, [shouldDebounce, value]);\n\n useEffect(() => {\n if (!isPasswordInput) {\n setIsPasswordVisible(false);\n }\n }, [isPasswordInput]);\n\n useEffect(() => {\n const form = isFileInput ? fileInputRef.current?.form : null;\n if (!form) return;\n\n const clearFileSelection = () => setSelectedFileNames([]);\n form.addEventListener('reset', clearFileSelection);\n return () => form.removeEventListener('reset', clearFileSelection);\n }, [isFileInput]);\n\n const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const newValue = e.target.value;\n if (isFileInput) {\n onChange(newValue, e);\n setSelectedFileNames(\n Array.from(e.target.files ?? []).map((file) => file.name)\n );\n return;\n }\n\n if (shouldDebounce) {\n setInternalValue(newValue);\n debouncedOnChange(newValue);\n } else {\n onChange(newValue, e);\n }\n };\n\n const inputContainerClasses = getInputContainerClasses({\n size,\n variant,\n isError,\n disabled,\n className: inputContainerClassName,\n });\n\n const inputClasses = isFileInput\n ? 'sr-only'\n : getInputElementClasses({\n size,\n disabled,\n className: cn(\n isPasswordInput && !isPasswordVisible && 'text-security',\n isDateInput && [\n 'supports-[selector(input::-webkit-calendar-picker-indicator)]:[&::-webkit-calendar-picker-indicator]:size-[var(--control-icon-size)]',\n 'supports-[selector(input::-webkit-calendar-picker-indicator)]:[&::-webkit-calendar-picker-indicator]:m-0',\n 'supports-[selector(input::-webkit-calendar-picker-indicator)]:[&::-webkit-calendar-picker-indicator]:p-0',\n 'supports-[selector(input::-webkit-calendar-picker-indicator)]:[&::-webkit-calendar-picker-indicator]:opacity-0',\n ]\n ),\n });\n\n const effectiveLeftIcon =\n leftIcon ?? (isFileInput ? PaperclipIcon : undefined);\n const hasCustomLeftDecorator = leftDecorator != null;\n const hasCustomRightDecorator = rightDecorator != null;\n const effectiveLeftDecorator =\n leftDecorator ??\n (effectiveLeftIcon || leftAction ? (\n <InputIconSlot\n icon={effectiveLeftIcon}\n action={leftAction}\n size={size}\n disabled={disabled}\n />\n ) : null);\n const rightContent =\n rightDecorator ??\n (rightIcon || rightAction ? (\n <InputIconSlot\n icon={rightIcon}\n action={rightAction}\n size={size}\n disabled={disabled}\n />\n ) : null);\n // Offset only known edge buttons by their glyph inset, including the border.\n const leftActionOffset =\n !hasCustomLeftDecorator && leftAction\n ? CONTROL_ICON_SIZES[size].actionOffset\n : undefined;\n const rightActionOffset =\n isPasswordInput || (!hasCustomRightDecorator && rightAction)\n ? CONTROL_ICON_SIZES[size].actionOffset\n : undefined;\n const effectiveRightDecorator =\n rightContent || isPasswordInput ? (\n <>\n {rightContent}\n {isPasswordInput && (\n <InputIconSlot\n size={size}\n disabled={disabled}\n action={{\n icon: isPasswordVisible ? EyeSlashIcon : EyeIcon,\n label: 'toggle password visibility',\n tooltipProps: { disabled: true },\n onClick: () => setIsPasswordVisible((show) => !show),\n }}\n />\n )}\n </>\n ) : null;\n\n const nativeInput = (\n // eslint-disable-next-line react/forbid-elements\n <input\n ref={isFileInput ? mergeRefs([fileInputRef, ref]) : ref}\n id={inputId}\n name={name ?? (typeof label === 'string' ? label : undefined)}\n type={\n isPasswordInput ? (isPasswordVisible ? 'text' : 'password') : type\n }\n value={\n isFileInput\n ? undefined\n : shouldDebounce\n ? (internalValue ?? '')\n : value === null\n ? ''\n : value\n }\n onChange={handleInputChange}\n placeholder={placeholder}\n disabled={disabled}\n required={required}\n autoFocus={autoFocus}\n accept={accept}\n multiple={multiple}\n aria-describedby={describedBy}\n aria-invalid={isError || undefined}\n className={inputClasses}\n {...rest}\n />\n );\n\n return (\n <div className={cn('w-full', className)}>\n {label && (\n <Text\n as=\"label\"\n htmlFor={inputId}\n className={cn(\n 'mb-space-1 block text-sm font-medium text-primary',\n disabled && 'text-disabled'\n )}\n variant=\"xs\"\n >\n {label}\n {required && (\n <span className=\"ml-space-1 text-error-secondary\">*</span>\n )}\n </Text>\n )}\n\n <div\n className={cn(\n inputContainerClasses,\n isFileInput && !disabled && 'cursor-pointer'\n )}\n onClick={isFileInput ? openFilePicker : undefined}\n >\n {effectiveLeftDecorator && (\n <div\n className={DECORATOR_CLASSES}\n style={{ marginInlineStart: leftActionOffset }}\n >\n {effectiveLeftDecorator}\n </div>\n )}\n\n {isFileInput && (\n <FileSelection\n size={size}\n fileNames={selectedFileNames}\n placeholder={placeholder}\n />\n )}\n\n {isDateInput ? (\n <div\n className={cn(\n 'relative flex min-w-0 flex-1 items-center',\n CONTROL_ICON_SIZES[size].sizeVariableClassName\n )}\n >\n {nativeInput}\n {/* The native picker target stays interactive beneath this glyph. */}\n <span className=\"pointer-events-none absolute inset-y-0 end-0 hidden items-center supports-[selector(input::-webkit-calendar-picker-indicator)]:flex\">\n <InputIconSlot\n icon={CalendarBlankIcon}\n size={size}\n disabled={disabled}\n />\n </span>\n </div>\n ) : (\n nativeInput\n )}\n\n {effectiveRightDecorator && (\n <div\n className={cn(DECORATOR_CLASSES, 'gap-space-1')}\n style={{ marginInlineEnd: rightActionOffset }}\n >\n {effectiveRightDecorator}\n </div>\n )}\n </div>\n\n {hintText && (\n <Text\n id={hintTextId}\n className={cn(\n 'mt-space-1 text-xs',\n isError ? 'text-error-secondary' : 'text-tertiary'\n )}\n variant=\"xs\"\n weight=\"normal\"\n >\n {hintText}\n </Text>\n )}\n </div>\n );\n }\n);\n\nInput.displayName = 'Input';\n"],"mappings":";;;;;;;;;;;;;;;AA4GA,SAAS,cAAc,EACrB,MACA,QACA,MACA,YAMC;CACD,MAAM,aAAa,YAAY,QAAQ;CACvC,MAAM,iBAAiB,aACnB,uBACA;CAEJ,OAAO,SACL,oBAAC,YAAD;EACE,GAAI;EACJ,OAAM;EACN,SAAQ;EACR,MAAM,mBAAmB,KAAK,CAAC;EAC/B,WAAW;EACX,YAAW;EACX,UAAU;EACV,cAAc,UAAU,MAAM,eAAe;CAC9C,CAAA,IACC,OACF,oBAAC,MAAD;EACE,eAAA;EACM;EACN,eAAe,mBAAmB,KAAK,CAAC;EACxC,WAAW;EACX,QAAO;CACR,CAAA,IACC;AACN;AAEA,SAAS,cAAc,EACrB,MACA,WACA,eAKC;CACD,MAAM,UACJ,UAAU,SAAS,IAAI,GAAG,UAAU,OAAO,mBAAmB,UAAU;CAC1E,MAAM,cAAc,mBAAmB;CAEvC,OACE,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,MAAD;EACE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AD;MACQ;MACN,WAAW;MACE;KACd,CAAA;KAGF,cACC,qBAAC,OAAD;MACE,WAAW,GACT,6CACA,mBAAmB,KAAK,CAAC,qBAC3B;MAJF,UAAA,CAMG,aAED,oBAAC,QAAD;OAAM,WAAU;OACd,UAAA,oBAAC,eAAD;QACE,MAAM;QACA;QACI;OACX,CAAA;MACG,CAAA,CACH;KAEL,CAAA,IAAA;KAGD,2BACC,oBAAC,OAAD;MACE,WAAW,GAAA,mCAAsB,aAAa;MAC9C,OAAO,EAAE,iBAAiB,kBAAkB;MAE3C,UAAA;KACE,CAAA;IAEJ;;GAEJ,YACC,oBAAC,MAAD;IACE,IAAI;IACJ,WAAW,GACT,sBACA,UAAU,yBAAyB,eACrC;IACA,SAAQ;IACR,QAAO;IAEN,UAAA;GACG,CAAA;EAEL;;AAET,CACF;AAEA,MAAM,cAAc"}
|
|
1
|
+
{"version":3,"file":"Input.js","names":[],"sources":["../../../src/components/Input/Input.tsx"],"sourcesContent":["import type { ComponentProps, ReactNode } from 'react';\nimport { forwardRef, useEffect, useId, useRef, useState } from 'react';\n\nimport { useDebouncedCallback } from 'use-debounce';\n\nimport { CalendarBlankIcon } from '@phosphor-icons/react/dist/ssr/CalendarBlank';\nimport { EyeIcon } from '@phosphor-icons/react/dist/ssr/Eye';\nimport { EyeSlashIcon } from '@phosphor-icons/react/dist/ssr/EyeSlash';\nimport { PaperclipIcon } from '@phosphor-icons/react/dist/ssr/Paperclip';\n\nimport { cn } from '../../utils/cn';\nimport { CONTROL_ICON_SIZES } from '../../utils/controlIconSizes';\nimport type { IconComponent } from '../../utils/icon-types';\nimport { mergeRefs } from '../../utils/merge-refs';\nimport { Icon } from '../Icon';\nimport { IconButton } from '../IconButton';\nimport { Text } from '../Text';\nimport {\n DECORATOR_CLASSES,\n getInputContainerClasses,\n getInputElementClasses,\n INPUT_TEXT_CLASSES,\n} from './inputStyles';\nimport type { InputSize } from './inputStyles';\n\nexport type InputIconAction = Pick<\n ComponentProps<typeof IconButton>,\n 'icon' | 'label' | 'disabled' | 'tooltipProps'\n> & {\n onClick: NonNullable<ComponentProps<typeof IconButton>['onClick']>;\n};\n\nexport interface InputProps {\n /** Exact outer height. The default lg tier preserves the legacy 40px field. */\n size?: InputSize;\n variant?: 'outlined' | 'plain';\n /** Decorative icon. Input owns its size and color. */\n leftIcon?: IconComponent;\n /** Decorative icon. Input owns its size and color. */\n rightIcon?: IconComponent;\n /** Plain icon button. Takes precedence over leftIcon. */\n leftAction?: InputIconAction;\n /** Plain icon button. Takes precedence over rightIcon; precedes the password toggle. */\n rightAction?: InputIconAction;\n /** Custom content; overrides leftIcon/leftAction and the default file icon. */\n leftDecorator?: ReactNode;\n /** Custom content; overrides rightIcon/rightAction. The password toggle remains last. */\n rightDecorator?: ReactNode;\n /** Whether the input is disabled */\n disabled?: boolean;\n /** Whether the input has an error state */\n isError?: boolean;\n /** Label text displayed above the input */\n label?: string | ReactNode;\n /** Hint text displayed below the input */\n hintText?: string;\n /** Current input value */\n value?: string | null;\n /** Change handler that will be debounced */\n onChange: (\n value: string,\n event?: React.ChangeEvent<HTMLInputElement>\n ) => void;\n /** Placeholder text */\n placeholder?: string;\n /**\n * Input type. Limited to the \"text-like\" native types that share this\n * component's styled-text rendering and string value contract. `password`\n * renders a masked secret field with a show/hide toggle. `date` uses the\n * browser's native date picker; its value is a `YYYY-MM-DD` string.\n * `datetime-local` uses the native date+time picker; its value is a\n * `YYYY-MM-DDTHH:mm` string in the viewer's local time. `file` is\n * uncontrolled: read the selection from `event.target.files` on the change\n * event, and scope it with `accept`/`multiple`.\n */\n type?:\n | 'text'\n | 'email'\n | 'password'\n | 'number'\n | 'url'\n | 'date'\n | 'datetime-local'\n | 'file';\n /** Debounce delay in milliseconds (default: 300). Ignored for `type=\"file\"`. */\n debounceMs?: number;\n /** Additional CSS classes */\n className?: string;\n /** Input ID for accessibility */\n id?: string;\n /** Input name for forms */\n name?: string;\n /** Whether the field is required */\n required?: boolean;\n /** Auto focus on mount */\n autoFocus?: boolean;\n /** CSS class for the input container */\n inputContainerClassName?: string;\n /**\n * Which files the picker offers, as a comma-separated list of extensions or\n * MIME types (`'.csv,.json'`, `'image/*'`). `type=\"file\"` only. The browser\n * treats this as a filter, not a guarantee — validate the selection too.\n */\n accept?: string;\n /** Whether more than one file can be picked. `type=\"file\"` only. */\n multiple?: boolean;\n}\n\nfunction InputIconSlot({\n icon,\n action,\n size,\n disabled,\n}: {\n icon?: IconComponent;\n action?: InputIconAction;\n size: InputSize;\n disabled: boolean;\n}) {\n const isDisabled = disabled || action?.disabled;\n const colorClassName = isDisabled\n ? 'text-icon-disabled'\n : 'text-icon-secondary';\n\n return action ? (\n <IconButton\n {...action}\n color=\"secondary\"\n variant=\"plain\"\n size={CONTROL_ICON_SIZES[size].buttonSize}\n className={colorClassName}\n iconWeight=\"regular\"\n disabled={isDisabled}\n onMouseDown={(event) => event.preventDefault()}\n />\n ) : icon ? (\n <Icon\n aria-hidden\n icon={icon}\n iconClassName={CONTROL_ICON_SIZES[size].iconClassName}\n className={colorClassName}\n weight=\"regular\"\n />\n ) : null;\n}\n\nfunction FileSelection({\n size,\n fileNames,\n placeholder,\n disabled,\n}: {\n size: InputSize;\n fileNames: string[];\n placeholder?: string;\n disabled: boolean;\n}) {\n const summary =\n fileNames.length > 1 ? `${fileNames.length} files selected` : fileNames[0];\n const textClasses = INPUT_TEXT_CLASSES[size];\n\n return (\n <>\n <Text\n aria-hidden\n as=\"span\"\n className={cn(\n textClasses,\n 'min-w-0 flex-1 truncate',\n summary ? 'text-primary' : 'text-placeholder',\n disabled && 'text-disabled'\n )}\n >\n {summary ?? placeholder ?? 'No file selected'}\n </Text>\n <Text\n aria-hidden\n as=\"span\"\n weight=\"medium\"\n className={cn(\n textClasses,\n 'shrink-0 text-secondary',\n disabled && 'text-disabled'\n )}\n >\n Browse\n </Text>\n </>\n );\n}\n\nexport const Input = forwardRef<\n HTMLInputElement,\n InputProps &\n Omit<React.InputHTMLAttributes<HTMLInputElement>, keyof InputProps>\n>(\n (\n {\n size = 'lg',\n variant = 'outlined',\n leftIcon,\n rightIcon,\n leftAction,\n rightAction,\n leftDecorator,\n rightDecorator,\n disabled = false,\n isError = false,\n label,\n hintText,\n value,\n onChange,\n placeholder,\n type = 'text',\n debounceMs = 0,\n className,\n inputContainerClassName,\n id,\n name,\n required = false,\n autoFocus = false,\n accept,\n multiple,\n 'aria-describedby': ariaDescribedBy,\n ...rest\n },\n ref\n ) => {\n const generatedId = useId();\n const inputId = id || generatedId;\n const hintTextId = `${inputId}-hint`;\n const describedBy =\n [hintText ? hintTextId : undefined, ariaDescribedBy]\n .filter(Boolean)\n .join(' ') || undefined;\n const shouldDebounce = debounceMs > 0;\n const isFileInput = type === 'file';\n const isPasswordInput = type === 'password';\n const isDateInput = type === 'date' || type === 'datetime-local';\n const [internalValue, setInternalValue] = useState(value);\n const [isPasswordVisible, setIsPasswordVisible] = useState(false);\n const [selectedFileNames, setSelectedFileNames] = useState<string[]>([]);\n const debouncedOnChange = useDebouncedCallback(onChange, debounceMs);\n const fileInputRef = useRef<HTMLInputElement>(null);\n\n useEffect(() => {\n if (!shouldDebounce) return;\n return () => debouncedOnChange.flush();\n }, [shouldDebounce, debouncedOnChange]);\n\n // Skip the click forwarded below, which would otherwise re-enter here.\n const openFilePicker = (event: React.MouseEvent<HTMLDivElement>) => {\n const target = event.target;\n if (\n disabled ||\n (target instanceof Element &&\n target.closest(\n 'button, a, input, select, textarea, summary, [role=\"button\"], [role=\"link\"], [contenteditable=\"true\"]'\n ))\n ) {\n return;\n }\n fileInputRef.current?.click();\n };\n\n useEffect(() => {\n if (shouldDebounce) setInternalValue(value);\n }, [shouldDebounce, value]);\n\n useEffect(() => {\n if (!isPasswordInput) {\n setIsPasswordVisible(false);\n }\n }, [isPasswordInput]);\n\n useEffect(() => {\n const form = isFileInput ? fileInputRef.current?.form : null;\n if (!form) return;\n\n const clearFileSelection = () => setSelectedFileNames([]);\n form.addEventListener('reset', clearFileSelection);\n return () => form.removeEventListener('reset', clearFileSelection);\n }, [isFileInput]);\n\n const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const newValue = e.target.value;\n if (isFileInput) {\n onChange(newValue, e);\n setSelectedFileNames(\n Array.from(e.target.files ?? []).map((file) => file.name)\n );\n return;\n }\n\n if (shouldDebounce) {\n setInternalValue(newValue);\n debouncedOnChange(newValue);\n } else {\n onChange(newValue, e);\n }\n };\n\n const inputContainerClasses = getInputContainerClasses({\n size,\n variant,\n isError,\n disabled,\n className: inputContainerClassName,\n });\n\n const inputClasses = isFileInput\n ? 'sr-only'\n : getInputElementClasses({\n size,\n disabled,\n className: cn(\n isPasswordInput && !isPasswordVisible && 'text-security',\n isDateInput && [\n 'supports-[selector(input::-webkit-calendar-picker-indicator)]:[&::-webkit-calendar-picker-indicator]:size-[var(--control-icon-size)]',\n 'supports-[selector(input::-webkit-calendar-picker-indicator)]:[&::-webkit-calendar-picker-indicator]:m-0',\n 'supports-[selector(input::-webkit-calendar-picker-indicator)]:[&::-webkit-calendar-picker-indicator]:p-0',\n 'supports-[selector(input::-webkit-calendar-picker-indicator)]:[&::-webkit-calendar-picker-indicator]:opacity-0',\n ]\n ),\n });\n\n const effectiveLeftIcon =\n leftIcon ?? (isFileInput ? PaperclipIcon : undefined);\n const hasCustomLeftDecorator = leftDecorator != null;\n const hasCustomRightDecorator = rightDecorator != null;\n const effectiveLeftDecorator =\n leftDecorator ??\n (effectiveLeftIcon || leftAction ? (\n <InputIconSlot\n icon={effectiveLeftIcon}\n action={leftAction}\n size={size}\n disabled={disabled}\n />\n ) : null);\n const rightContent =\n rightDecorator ??\n (rightIcon || rightAction ? (\n <InputIconSlot\n icon={rightIcon}\n action={rightAction}\n size={size}\n disabled={disabled}\n />\n ) : null);\n // Offset only known edge buttons by their glyph inset, including the border.\n const leftActionOffset =\n !hasCustomLeftDecorator && leftAction\n ? CONTROL_ICON_SIZES[size].actionOffset\n : undefined;\n const rightActionOffset =\n isPasswordInput || (!hasCustomRightDecorator && rightAction)\n ? CONTROL_ICON_SIZES[size].actionOffset\n : undefined;\n const effectiveRightDecorator =\n rightContent || isPasswordInput ? (\n <>\n {rightContent}\n {isPasswordInput && (\n <InputIconSlot\n size={size}\n disabled={disabled}\n action={{\n icon: isPasswordVisible ? EyeSlashIcon : EyeIcon,\n label: 'toggle password visibility',\n tooltipProps: { disabled: true },\n onClick: () => setIsPasswordVisible((show) => !show),\n }}\n />\n )}\n </>\n ) : null;\n\n const nativeInput = (\n // eslint-disable-next-line react/forbid-elements\n <input\n ref={isFileInput ? mergeRefs([fileInputRef, ref]) : ref}\n id={inputId}\n name={name ?? (typeof label === 'string' ? label : undefined)}\n type={\n isPasswordInput ? (isPasswordVisible ? 'text' : 'password') : type\n }\n value={\n isFileInput\n ? undefined\n : shouldDebounce\n ? (internalValue ?? '')\n : value === null\n ? ''\n : value\n }\n onChange={handleInputChange}\n placeholder={placeholder}\n disabled={disabled}\n required={required}\n autoFocus={autoFocus}\n accept={accept}\n multiple={multiple}\n aria-describedby={describedBy}\n aria-invalid={isError || undefined}\n className={inputClasses}\n {...rest}\n />\n );\n\n return (\n <div className={cn('w-full', className)}>\n {label && (\n <Text\n as=\"label\"\n htmlFor={inputId}\n className={cn(\n 'mb-space-1 block text-sm font-medium text-primary',\n disabled && 'text-disabled'\n )}\n variant=\"xs\"\n >\n {label}\n {required && (\n <span className=\"ml-space-1 text-error-secondary\">*</span>\n )}\n </Text>\n )}\n\n <div\n className={cn(\n inputContainerClasses,\n isFileInput && !disabled && 'cursor-pointer'\n )}\n onClick={isFileInput ? openFilePicker : undefined}\n >\n {effectiveLeftDecorator && (\n <div\n className={cn(DECORATOR_CLASSES, disabled && 'text-disabled')}\n style={{ marginInlineStart: leftActionOffset }}\n >\n {effectiveLeftDecorator}\n </div>\n )}\n\n {isFileInput && (\n <FileSelection\n size={size}\n fileNames={selectedFileNames}\n placeholder={placeholder}\n disabled={disabled}\n />\n )}\n\n {isDateInput ? (\n <div\n className={cn(\n 'relative flex min-w-0 flex-1 items-center',\n CONTROL_ICON_SIZES[size].sizeVariableClassName\n )}\n >\n {nativeInput}\n {/* The native picker target stays interactive beneath this glyph. */}\n <span className=\"pointer-events-none absolute inset-y-0 end-0 hidden items-center supports-[selector(input::-webkit-calendar-picker-indicator)]:flex\">\n <InputIconSlot\n icon={CalendarBlankIcon}\n size={size}\n disabled={disabled}\n />\n </span>\n </div>\n ) : (\n nativeInput\n )}\n\n {effectiveRightDecorator && (\n <div\n className={cn(\n DECORATOR_CLASSES,\n 'gap-space-1',\n disabled && 'text-disabled'\n )}\n style={{ marginInlineEnd: rightActionOffset }}\n >\n {effectiveRightDecorator}\n </div>\n )}\n </div>\n\n {hintText && (\n <Text\n id={hintTextId}\n className={cn(\n 'mt-space-1 text-xs',\n isError ? 'text-error-secondary' : 'text-tertiary'\n )}\n variant=\"xs\"\n weight=\"normal\"\n >\n {hintText}\n </Text>\n )}\n </div>\n );\n }\n);\n\nInput.displayName = 'Input';\n"],"mappings":";;;;;;;;;;;;;;;AA4GA,SAAS,cAAc,EACrB,MACA,QACA,MACA,YAMC;CACD,MAAM,aAAa,YAAY,QAAQ;CACvC,MAAM,iBAAiB,aACnB,uBACA;CAEJ,OAAO,SACL,oBAAC,YAAD;EACE,GAAI;EACJ,OAAM;EACN,SAAQ;EACR,MAAM,mBAAmB,KAAK,CAAC;EAC/B,WAAW;EACX,YAAW;EACX,UAAU;EACV,cAAc,UAAU,MAAM,eAAe;CAC9C,CAAA,IACC,OACF,oBAAC,MAAD;EACE,eAAA;EACM;EACN,eAAe,mBAAmB,KAAK,CAAC;EACxC,WAAW;EACX,QAAO;CACR,CAAA,IACC;AACN;AAEA,SAAS,cAAc,EACrB,MACA,WACA,aACA,YAMC;CACD,MAAM,UACJ,UAAU,SAAS,IAAI,GAAG,UAAU,OAAO,mBAAmB,UAAU;CAC1E,MAAM,cAAc,mBAAmB;CAEvC,OACE,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,MAAD;EACE,eAAA;EAC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AA;KACE,CAAA;KAGN,eACC,oBAAC,eAAD;MACQ;MACN,WAAW;MACE;MACH;KACX,CAAA;KAGF,cACC,qBAAC,OAAD;MACE,WAAW,GACT,6CACA,mBAAmB,KAAK,CAAC,qBAC3B;MAJF,UAAA,CAMG,aAED,oBAAC,QAAD;OAAM,WAAU;OACd,UAAA,oBAAC,eAAD;QACE,MAAM;QACA;QACI;OACX,CAAA;MACG,CAAA,CACH;KAEL,CAAA,IAAA;KAGD,2BACC,oBAAC,OAAD;MACE,WAAW,GAAA,mCAET,eACA,YAAY,eACd;MACA,OAAO,EAAE,iBAAiB,kBAAkB;MAE3C,UAAA;KACE,CAAA;IAEJ;;GAEJ,YACC,oBAAC,MAAD;IACE,IAAI;IACJ,WAAW,GACT,sBACA,UAAU,yBAAyB,eACrC;IACA,SAAQ;IACR,QAAO;IAEN,UAAA;GACG,CAAA;EAEL;;AAET,CACF;AAEA,MAAM,cAAc"}
|
|
@@ -25,17 +25,17 @@ var INPUT_TEXT_CLASSES = {
|
|
|
25
25
|
*/
|
|
26
26
|
function getInputContainerClasses({ size, variant, isError = false, disabled = false, className }) {
|
|
27
27
|
const outlined = variant === "outlined";
|
|
28
|
-
return cn("box-border flex w-full items-center gap-space-2 transition-[border-color,box-shadow,background-color]", CONTROL_SIZES[size].heightClassName, INPUT_HORIZONTAL_PADDING_CLASSES[size], INPUT_RADIUS_CLASSES[size], "focus-within:outline-
|
|
29
|
-
"border border-
|
|
30
|
-
"border border-transparent bg-
|
|
31
|
-
}, outlined && !disabled && !isError && "[&:hover:not(:focus-within)]:border-
|
|
28
|
+
return cn("box-border flex w-full items-center gap-space-2 transition-[border-color,box-shadow,background-color]", CONTROL_SIZES[size].heightClassName, INPUT_HORIZONTAL_PADDING_CLASSES[size], INPUT_RADIUS_CLASSES[size], "focus-within:outline-hidden", {
|
|
29
|
+
"border border-muted bg-input": variant === "outlined",
|
|
30
|
+
"border border-transparent bg-input": variant === "plain"
|
|
31
|
+
}, outlined && !disabled && !isError && "[&:hover:not(:focus-within)]:border-subtle", !disabled && !isError && (outlined ? "focus-within:border-focus focus-within:shadow-[0_0_0_1px_var(--border-focus)]" : "focus-within:border-focus"), !disabled && isError && (outlined ? "border-error-strong focus-within:border-error-strong focus-within:shadow-[0_0_0_1px_var(--border-error-strong)]" : "border-error-strong focus-within:border-error-strong"), disabled && "cursor-not-allowed border-muted bg-input-disabled text-disabled", className);
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* Shared styling for the inner input element (unstyled, fills container).
|
|
35
35
|
* Used by both the design system Input and CommandInput.
|
|
36
36
|
*/
|
|
37
37
|
function getInputElementClasses({ size, disabled = false, className }) {
|
|
38
|
-
return cn("min-w-0 max-w-full flex-1 border-none bg-transparent p-0 outline-
|
|
38
|
+
return cn("min-w-0 max-w-full flex-1 border-none bg-transparent p-0 outline-hidden", INPUT_TEXT_CLASSES[size], "placeholder:text-placeholder", disabled && "cursor-not-allowed text-disabled placeholder:text-disabled", className);
|
|
39
39
|
}
|
|
40
40
|
/** Shared styling for decorator wrappers. */
|
|
41
41
|
var DECORATOR_CLASSES = "flex items-center text-tertiary";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputStyles.js","names":[],"sources":["../../../src/components/Input/inputStyles.ts"],"sourcesContent":["import { cn } from '../../utils/cn';\nimport { CONTROL_SIZES, type ControlSize } from '../../utils/componentSizes';\n\nexport type InputSize = ControlSize;\nexport type InputVariant = 'outlined' | 'plain';\n\nexport const INPUT_HORIZONTAL_PADDING_CLASSES: Record<InputSize, string> = {\n xs: 'px-space-1',\n sm: 'px-space-2',\n md: 'px-space-3',\n lg: 'px-space-3',\n};\n\nexport const INPUT_RADIUS_CLASSES: Record<InputSize, string> = {\n xs: 'rounded-xs',\n sm: 'rounded-sm',\n md: 'rounded-md',\n lg: 'rounded-md',\n};\n\nexport const INPUT_TEXT_CLASSES: Record<InputSize, string> = {\n xs: 'text-xxs leading-[1.15]',\n sm: 'text-xs',\n md: 'text-sm leading-normal',\n lg: 'text-sm leading-normal',\n};\n\n/**\n * Shared styling for input containers (border, padding, rounding, variant).\n * Used by both the design system Input and CommandInput.\n */\nexport function getInputContainerClasses({\n size,\n variant,\n isError = false,\n disabled = false,\n className,\n}: {\n size: InputSize;\n variant: InputVariant;\n isError?: boolean;\n disabled?: boolean;\n className?: string;\n}) {\n const outlined = variant === 'outlined';\n return cn(\n 'box-border flex w-full items-center gap-space-2 transition-[border-color,box-shadow,background-color]',\n CONTROL_SIZES[size].heightClassName,\n INPUT_HORIZONTAL_PADDING_CLASSES[size],\n INPUT_RADIUS_CLASSES[size],\n 'focus-within:outline-
|
|
1
|
+
{"version":3,"file":"inputStyles.js","names":[],"sources":["../../../src/components/Input/inputStyles.ts"],"sourcesContent":["import { cn } from '../../utils/cn';\nimport { CONTROL_SIZES, type ControlSize } from '../../utils/componentSizes';\n\nexport type InputSize = ControlSize;\nexport type InputVariant = 'outlined' | 'plain';\n\nexport const INPUT_HORIZONTAL_PADDING_CLASSES: Record<InputSize, string> = {\n xs: 'px-space-1',\n sm: 'px-space-2',\n md: 'px-space-3',\n lg: 'px-space-3',\n};\n\nexport const INPUT_RADIUS_CLASSES: Record<InputSize, string> = {\n xs: 'rounded-xs',\n sm: 'rounded-sm',\n md: 'rounded-md',\n lg: 'rounded-md',\n};\n\nexport const INPUT_TEXT_CLASSES: Record<InputSize, string> = {\n xs: 'text-xxs leading-[1.15]',\n sm: 'text-xs',\n md: 'text-sm leading-normal',\n lg: 'text-sm leading-normal',\n};\n\n/**\n * Shared styling for input containers (border, padding, rounding, variant).\n * Used by both the design system Input and CommandInput.\n */\nexport function getInputContainerClasses({\n size,\n variant,\n isError = false,\n disabled = false,\n className,\n}: {\n size: InputSize;\n variant: InputVariant;\n isError?: boolean;\n disabled?: boolean;\n className?: string;\n}) {\n const outlined = variant === 'outlined';\n return cn(\n 'box-border flex w-full items-center gap-space-2 transition-[border-color,box-shadow,background-color]',\n CONTROL_SIZES[size].heightClassName,\n INPUT_HORIZONTAL_PADDING_CLASSES[size],\n INPUT_RADIUS_CLASSES[size],\n 'focus-within:outline-hidden',\n {\n 'border border-muted bg-input': variant === 'outlined',\n 'border border-transparent bg-input': variant === 'plain',\n },\n outlined &&\n !disabled &&\n !isError &&\n '[&:hover:not(:focus-within)]:border-subtle',\n !disabled &&\n !isError &&\n (outlined\n ? 'focus-within:border-focus focus-within:shadow-[0_0_0_1px_var(--border-focus)]'\n : 'focus-within:border-focus'),\n !disabled &&\n isError &&\n (outlined\n ? 'border-error-strong focus-within:border-error-strong focus-within:shadow-[0_0_0_1px_var(--border-error-strong)]'\n : 'border-error-strong focus-within:border-error-strong'),\n disabled &&\n 'cursor-not-allowed border-muted bg-input-disabled text-disabled',\n className\n );\n}\n\n/**\n * Shared styling for the inner input element (unstyled, fills container).\n * Used by both the design system Input and CommandInput.\n */\nexport function getInputElementClasses({\n size,\n disabled = false,\n className,\n}: {\n size: InputSize;\n disabled?: boolean;\n className?: string;\n}) {\n return cn(\n 'min-w-0 max-w-full flex-1 border-none bg-transparent p-0 outline-hidden',\n INPUT_TEXT_CLASSES[size],\n 'placeholder:text-placeholder',\n disabled && 'cursor-not-allowed text-disabled placeholder:text-disabled',\n className\n );\n}\n\n/** Shared styling for decorator wrappers. */\nexport const DECORATOR_CLASSES = 'flex items-center text-tertiary';\n"],"mappings":";;;AAMA,IAAa,mCAA8D;CACzE,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AAEA,IAAa,uBAAkD;CAC7D,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AAEA,IAAa,qBAAgD;CAC3D,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;;;;;AAMA,SAAgB,yBAAyB,EACvC,MACA,SACA,UAAU,OACV,WAAW,OACX,aAOC;CACD,MAAM,WAAW,YAAY;CAC7B,OAAO,GACL,yGACA,cAAc,KAAK,CAAC,iBACpB,iCAAiC,OACjC,qBAAqB,OACrB,+BACA;EACE,gCAAgC,YAAY;EAC5C,sCAAsC,YAAY;CACpD,GACA,YACE,CAAC,YACD,CAAC,WACD,8CACF,CAAC,YACC,CAAC,YACA,WACG,kFACA,8BACN,CAAC,YACC,YACC,WACG,oHACA,yDACN,YACE,mEACF,SACF;AACF;;;;;AAMA,SAAgB,uBAAuB,EACrC,MACA,WAAW,OACX,aAKC;CACD,OAAO,GACL,2EACA,mBAAmB,OACnB,gCACA,YAAY,8DACZ,SACF;AACF;;AAGA,IAAa,oBAAoB"}
|
|
@@ -9,16 +9,16 @@ var TextContent = (children, leftDecorator, rightDecorator, iconWeight) => {
|
|
|
9
9
|
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
10
10
|
LeftIcon && /* @__PURE__ */ jsx(LeftIcon, {
|
|
11
11
|
"aria-hidden": true,
|
|
12
|
-
className: "h-[1em] w-[1em] flex-shrink-0 text-link dark:text-
|
|
12
|
+
className: "h-[1em] w-[1em] flex-shrink-0 text-link dark:text-link dark:group-hover:text-link-hover",
|
|
13
13
|
weight: iconWeight
|
|
14
14
|
}),
|
|
15
15
|
/* @__PURE__ */ jsx("span", {
|
|
16
|
-
className: "text-link underline-offset-2 hover:text-link-hover hover:underline hover:decoration-ls-neutral-300 hover:decoration-1 dark:text-
|
|
16
|
+
className: "text-link underline-offset-2 hover:text-link-hover hover:underline hover:decoration-ls-neutral-300 hover:decoration-1 dark:text-link dark:hover:text-link-hover dark:hover:decoration-ls-neutral-400",
|
|
17
17
|
children
|
|
18
18
|
}),
|
|
19
19
|
RightIcon && /* @__PURE__ */ jsx(RightIcon, {
|
|
20
20
|
"aria-hidden": true,
|
|
21
|
-
className: "h-[1em] w-[1em] flex-shrink-0 text-link dark:text-
|
|
21
|
+
className: "h-[1em] w-[1em] flex-shrink-0 text-link dark:text-link dark:group-hover:text-link-hover",
|
|
22
22
|
weight: iconWeight
|
|
23
23
|
})
|
|
24
24
|
] });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Link.js","names":[],"sources":["../../../src/components/Link/Link.tsx"],"sourcesContent":["import {\n cloneElement,\n forwardRef,\n isValidElement,\n type AnchorHTMLAttributes,\n type ReactElement,\n type ReactNode,\n} from 'react';\n\nimport { cn } from '../../utils/cn';\nimport type { IconComponent, IconWeight } from '../../utils/icon-types';\nimport { textVariantClasses } from '../Text';\nimport type { TextProps } from '../Text';\n\ntype LinkRenderElement = ReactElement<{\n children?: ReactNode;\n className?: string;\n [key: string]: unknown;\n}>;\n\ntype LinkProps = {\n /** Typography size — mirrors <Text> styles */\n variant?: TextProps['variant'];\n leftDecorator?: IconComponent;\n rightDecorator?: IconComponent;\n /** Phosphor weight used for decorator icons. */\n iconWeight?: IconWeight;\n} & (\n
|
|
1
|
+
{"version":3,"file":"Link.js","names":[],"sources":["../../../src/components/Link/Link.tsx"],"sourcesContent":["import {\n cloneElement,\n forwardRef,\n isValidElement,\n type AnchorHTMLAttributes,\n type ReactElement,\n type ReactNode,\n} from 'react';\n\nimport { cn } from '../../utils/cn';\nimport type { IconComponent, IconWeight } from '../../utils/icon-types';\nimport { textVariantClasses } from '../Text';\nimport type { TextProps } from '../Text';\n\ntype LinkRenderElement = ReactElement<{\n children?: ReactNode;\n className?: string;\n [key: string]: unknown;\n}>;\n\ntype LinkProps = {\n /** Typography size — mirrors <Text> styles */\n variant?: TextProps['variant'];\n leftDecorator?: IconComponent;\n rightDecorator?: IconComponent;\n /** Phosphor weight used for decorator icons. */\n iconWeight?: IconWeight;\n} & (\n | (AnchorHTMLAttributes<HTMLAnchorElement> & {\n /** Render a native anchor with this URL. */\n href: string;\n as?: never;\n })\n | (Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> & {\n /**\n * Render link styling through a routing framework's anchor component.\n * For example: `as={<RouterLink to=\"/runs\" />}`.\n */\n as: LinkRenderElement;\n href?: never;\n })\n );\n\nconst TextContent = (\n children: React.ReactNode,\n leftDecorator: IconComponent | undefined,\n rightDecorator: IconComponent | undefined,\n iconWeight: IconWeight | undefined\n) => {\n const LeftIcon = leftDecorator;\n const RightIcon = rightDecorator;\n return (\n <>\n {LeftIcon && (\n <LeftIcon\n aria-hidden\n className=\"h-[1em] w-[1em] flex-shrink-0 text-link dark:text-link dark:group-hover:text-link-hover\"\n weight={iconWeight}\n />\n )}\n <span className=\"text-link underline-offset-2 hover:text-link-hover hover:underline hover:decoration-ls-neutral-300 hover:decoration-1 dark:text-link dark:hover:text-link-hover dark:hover:decoration-ls-neutral-400\">\n {children}\n </span>\n {RightIcon && (\n <RightIcon\n aria-hidden\n className=\"h-[1em] w-[1em] flex-shrink-0 text-link dark:text-link dark:group-hover:text-link-hover\"\n weight={iconWeight}\n />\n )}\n </>\n );\n};\n\nconst Link = forwardRef<HTMLAnchorElement, LinkProps>(\n (\n {\n variant = 'body',\n leftDecorator,\n rightDecorator,\n iconWeight,\n className,\n children,\n as,\n ...props\n },\n ref\n ) => {\n const containerClass = cn(\n 'group inline-flex items-center gap-[2px]',\n textVariantClasses[variant],\n className\n );\n\n const content = TextContent(\n children,\n leftDecorator,\n rightDecorator,\n iconWeight\n );\n\n if (as) {\n if (!isValidElement(as)) return null;\n\n return cloneElement(as, {\n ...props,\n ref,\n className: cn(as.props.className, containerClass),\n children: content,\n });\n }\n\n const { href, ...anchorProps } = props;\n return (\n // eslint-disable-next-line react/forbid-elements\n <a ref={ref} href={href} className={containerClass} {...anchorProps}>\n {content}\n </a>\n );\n }\n);\n\nLink.displayName = 'Link';\n\nexport { Link };\nexport type { LinkProps };\n"],"mappings":";;;;;AA2CA,IAAM,eACJ,UACA,eACA,gBACA,eACG;CACH,MAAM,WAAW;CACjB,MAAM,YAAY;CAClB,OACE,qBAAA,YAAA,EAAA,UAAA;EACG,YACC,oBAAC,UAAD;GACE,eAAA;GACA,WAAU;GACV,QAAQ;EACT,CAAA;EAEH,oBAAC,QAAD;GAAM,WAAU;GACb;EACG,CAAA;EACL,aACC,oBAAC,WAAD;GACE,eAAA;GACA,WAAU;GACV,QAAQ;EACT,CAAA;CAEH,EAAA,CAAA;AAEN;AAEA,IAAM,OAAO,YAET,EACE,UAAU,QACV,eACA,gBACA,YACA,WACA,UACA,IACA,GAAG,SAEL,QACG;CACH,MAAM,iBAAiB,GACrB,4CACA,mBAAmB,UACnB,SACF;CAEA,MAAM,UAAU,YACd,UACA,eACA,gBACA,UACF;CAEA,IAAI,IAAI;EACN,IAAI,CAAC,eAAe,EAAE,GAAG,OAAO;EAEhC,OAAO,aAAa,IAAI;GACtB,GAAG;GACH;GACA,WAAW,GAAG,GAAG,MAAM,WAAW,cAAc;GAChD,UAAU;EACZ,CAAC;CACH;CAEA,MAAM,EAAE,MAAM,GAAG,gBAAgB;CACjC,OAEE,oBAAC,KAAD;EAAQ;EAAW;EAAM,WAAW;EAAgB,GAAI;EACrD,UAAA;CACA,CAAA;AAEP,CACF;AAEA,KAAK,cAAc"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CSSProperties, ReactNode } from 'react';
|
|
2
|
-
|
|
2
|
+
import { type DataAttributes } from '../../utils/dataAttributes.js';
|
|
3
|
+
interface CorePaneProps extends DataAttributes {
|
|
3
4
|
open: boolean;
|
|
4
5
|
animation?: boolean;
|
|
5
6
|
onClose: () => void;
|
|
@@ -25,5 +26,5 @@ export interface PaneProps extends CorePaneProps {
|
|
|
25
26
|
onBack?: () => void;
|
|
26
27
|
scrollRef?: React.RefObject<HTMLDivElement | null>;
|
|
27
28
|
}
|
|
28
|
-
export declare function Pane({ open, animation, onClose, onBack, title, description, children, className, noBackArrow, headerClassName, titleClassName, descriptionClassName, topBarRightElement, dialogStyle, transparentBackdrop, scrollRef, handleScroll, preventInteractOutside, onEscapeKeyDown, requireConfirmationOnClose, zIndex, }: PaneProps): import("react").JSX.Element;
|
|
29
|
+
export declare function Pane({ open, animation, onClose, onBack, title, description, children, className, noBackArrow, headerClassName, titleClassName, descriptionClassName, topBarRightElement, dialogStyle, transparentBackdrop, scrollRef, handleScroll, preventInteractOutside, onEscapeKeyDown, requireConfirmationOnClose, zIndex, ...rest }: PaneProps): import("react").JSX.Element;
|
|
29
30
|
export {};
|