@keboola/design 16.1.0 → 17.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/CHANGELOG.md +54 -0
- package/dist/{AIKit-Cf5plya2.js → AIKit-DyysN1kS.js} +35 -45
- package/dist/AIKit-DyysN1kS.js.map +1 -0
- package/dist/{Alert-DziS8n1H.js → Alert-BQB-og_I.js} +2 -2
- package/dist/{Alert-DziS8n1H.js.map → Alert-BQB-og_I.js.map} +1 -1
- package/dist/{AlertModal-De04fFoy.js → AlertModal-BkmyEvsR.js} +2 -2
- package/dist/{AlertModal-De04fFoy.js.map → AlertModal-BkmyEvsR.js.map} +1 -1
- package/dist/{AppShell-BUa3U7-e.js → AppShell-CDbecT-t.js} +2 -2
- package/dist/{AppShell-BUa3U7-e.js.map → AppShell-CDbecT-t.js.map} +1 -1
- package/dist/{BrandEditor-hiLBX7az.js → BrandEditor-BHE6nsob.js} +6 -6
- package/dist/{BrandEditor-hiLBX7az.js.map → BrandEditor-BHE6nsob.js.map} +1 -1
- package/dist/{BrandLogo-Dn7hhp2c.js → BrandLogo-n4Qhi1tI.js} +2 -2
- package/dist/{BrandLogo-Dn7hhp2c.js.map → BrandLogo-n4Qhi1tI.js.map} +1 -1
- package/dist/{Breadcrumb-uGFEIjFF.js → Breadcrumb-BAwQTo0c.js} +3 -3
- package/dist/{Breadcrumb-uGFEIjFF.js.map → Breadcrumb-BAwQTo0c.js.map} +1 -1
- package/dist/{Button-DbvGzEDb.js → Button-BAMX1iuI.js} +2 -2
- package/dist/{Button-DbvGzEDb.js.map → Button-BAMX1iuI.js.map} +1 -1
- package/dist/{Checkbox-B2jLlyaO.js → Checkbox-CfjpwIcg.js} +2 -2
- package/dist/{Checkbox-B2jLlyaO.js.map → Checkbox-CfjpwIcg.js.map} +1 -1
- package/dist/{Clipboard-fAkDdpEu.js → Clipboard-BaU3cDi5.js} +7 -5
- package/dist/Clipboard-BaU3cDi5.js.map +1 -0
- package/dist/{ClipboardButton-71Ugbl8c.js → ClipboardButton-BWeaQEM2.js} +5 -4
- package/dist/ClipboardButton-BWeaQEM2.js.map +1 -0
- package/dist/{CodeEditor-D_b-ZCng.js → CodeEditor-BdTxkPD4.js} +4 -4
- package/dist/{CodeEditor-D_b-ZCng.js.map → CodeEditor-BdTxkPD4.js.map} +1 -1
- package/dist/{ColorInput-Cjr1jkvy.js → ColorInput-BoVdBxJ7.js} +3 -3
- package/dist/{ColorInput-Cjr1jkvy.js.map → ColorInput-BoVdBxJ7.js.map} +1 -1
- package/dist/{ColorModeSwitch-CuPYnJ2V.js → ColorModeSwitch-BDkdmHYl.js} +2 -2
- package/dist/{ColorModeSwitch-CuPYnJ2V.js.map → ColorModeSwitch-BDkdmHYl.js.map} +1 -1
- package/dist/{Combobox-DYjvYgl3.js → Combobox-RZ0i3w8u.js} +4 -4
- package/dist/{Combobox-DYjvYgl3.js.map → Combobox-RZ0i3w8u.js.map} +1 -1
- package/dist/{Command-BcTb6GsR.js → Command-D6XYzzJf.js} +2 -2
- package/dist/{Command-BcTb6GsR.js.map → Command-D6XYzzJf.js.map} +1 -1
- package/dist/{CopyField-CnwAvQz9.js → CopyField-9WBU8thS.js} +2 -2
- package/dist/{CopyField-CnwAvQz9.js.map → CopyField-9WBU8thS.js.map} +1 -1
- package/dist/{DateInput-DJNX7Vdx.js → DateInput-CCYG0AtT.js} +3 -3
- package/dist/{DateInput-DJNX7Vdx.js.map → DateInput-CCYG0AtT.js.map} +1 -1
- package/dist/{DateRangeInput-B3g8cyS0.js → DateRangeInput-CpZK1IFp.js} +3 -3
- package/dist/{DateRangeInput-B3g8cyS0.js.map → DateRangeInput-CpZK1IFp.js.map} +1 -1
- package/dist/{DateRangePicker-48yOB2qV.js → DateRangePicker-B2AUKX7u.js} +2 -2
- package/dist/{DateRangePicker-48yOB2qV.js.map → DateRangePicker-B2AUKX7u.js.map} +1 -1
- package/dist/{FieldItem-D7eCMfMB.js → FieldItem-eM7IHBt5.js} +3 -3
- package/dist/{FieldItem-D7eCMfMB.js.map → FieldItem-eM7IHBt5.js.map} +1 -1
- package/dist/{FileUpload-DskvxhAr.js → FileUpload-d-hNPfPV.js} +2 -2
- package/dist/{FileUpload-DskvxhAr.js.map → FileUpload-d-hNPfPV.js.map} +1 -1
- package/dist/{Form-BUNW7nlt.js → Form-B_9sNehB.js} +7 -7
- package/dist/{Form-BUNW7nlt.js.map → Form-B_9sNehB.js.map} +1 -1
- package/dist/{FormGroup-QJB21LKp.js → FormGroup-D7ahkK1q.js} +3 -3
- package/dist/{FormGroup-QJB21LKp.js.map → FormGroup-D7ahkK1q.js.map} +1 -1
- package/dist/{FullScreenModal-RzY5XxiG.js → FullScreenModal-CiRKNsls.js} +2 -2
- package/dist/{FullScreenModal-RzY5XxiG.js.map → FullScreenModal-CiRKNsls.js.map} +1 -1
- package/dist/{InlineEdit-CXL0ZslO.js → InlineEdit-BzOox46S.js} +4 -4
- package/dist/{InlineEdit-CXL0ZslO.js.map → InlineEdit-BzOox46S.js.map} +1 -1
- package/dist/{InputGroup-BWeanEo7.js → InputGroup-DnGP9-ZQ.js} +2 -2
- package/dist/{InputGroup-BWeanEo7.js.map → InputGroup-DnGP9-ZQ.js.map} +1 -1
- package/dist/{Kbd-BprYCICe.js → Kbd-6velz9J-.js} +2 -2
- package/dist/{Kbd-BprYCICe.js.map → Kbd-6velz9J-.js.map} +1 -1
- package/dist/{MermaidDiagram-E3azndPk.js → MermaidDiagram-l83gco3r.js} +2 -2
- package/dist/{MermaidDiagram-E3azndPk.js.map → MermaidDiagram-l83gco3r.js.map} +1 -1
- package/dist/{Modal-Cf_kPEBW.js → Modal-CLu6Eg5p.js} +2 -2
- package/dist/{Modal-Cf_kPEBW.js.map → Modal-CLu6Eg5p.js.map} +1 -1
- package/dist/{MultiActionButtonGroup-8WQwL4UQ.js → MultiActionButtonGroup-B3-wNw7w.js} +3 -3
- package/dist/{MultiActionButtonGroup-8WQwL4UQ.js.map → MultiActionButtonGroup-B3-wNw7w.js.map} +1 -1
- package/dist/{Navbar-CRjxVboE.js → Navbar-BEc-Pqo5.js} +2 -2
- package/dist/{Navbar-CRjxVboE.js.map → Navbar-BEc-Pqo5.js.map} +1 -1
- package/dist/{PageLayout-LcvJccOW.js → PageLayout-kY31oUix.js} +2 -2
- package/dist/{PageLayout-LcvJccOW.js.map → PageLayout-kY31oUix.js.map} +1 -1
- package/dist/{PageToolbar-By2HznxO.js → PageToolbar-NmiausP7.js} +2 -2
- package/dist/{PageToolbar-By2HznxO.js.map → PageToolbar-NmiausP7.js.map} +1 -1
- package/dist/{Pagination-DrXTrvfD.js → Pagination-DidOPSPB.js} +2 -2
- package/dist/{Pagination-DrXTrvfD.js.map → Pagination-DidOPSPB.js.map} +1 -1
- package/dist/{Popconfirm-BJuDOHdv.js → Popconfirm-C4ryoeGP.js} +2 -2
- package/dist/{Popconfirm-BJuDOHdv.js.map → Popconfirm-C4ryoeGP.js.map} +1 -1
- package/dist/{RadioGroup-B9oC8P15.js → RadioGroup-BIElT-nH.js} +2 -2
- package/dist/{RadioGroup-B9oC8P15.js.map → RadioGroup-BIElT-nH.js.map} +1 -1
- package/dist/{Search-OgaNjqQM.js → Search-xDWaQ2z3.js} +2 -2
- package/dist/{Search-OgaNjqQM.js.map → Search-xDWaQ2z3.js.map} +1 -1
- package/dist/{SearchInput-eLS-uvOn.js → SearchInput-BwlJ77mV.js} +3 -3
- package/dist/{SearchInput-eLS-uvOn.js.map → SearchInput-BwlJ77mV.js.map} +1 -1
- package/dist/{SectionNav-L81iJBo3.js → SectionNav-DV3Hwj-5.js} +14 -8
- package/dist/SectionNav-DV3Hwj-5.js.map +1 -0
- package/dist/{Select-DRdkdzBp.js → Select-C3Q_Xk_Z.js} +2 -2
- package/dist/{Select-DRdkdzBp.js.map → Select-C3Q_Xk_Z.js.map} +1 -1
- package/dist/{Sheet-DVb4XoJ5.js → Sheet-D7NnOyud.js} +2 -2
- package/dist/{Sheet-DVb4XoJ5.js.map → Sheet-D7NnOyud.js.map} +1 -1
- package/dist/{Sidebar-DYvodJWN.js → Sidebar-DaUDM8jm.js} +5 -5
- package/dist/{Sidebar-DYvodJWN.js.map → Sidebar-DaUDM8jm.js.map} +1 -1
- package/dist/{Slider-B9IskDxf.js → Slider-Cdl8FOvI.js} +3 -3
- package/dist/{Slider-B9IskDxf.js.map → Slider-Cdl8FOvI.js.map} +1 -1
- package/dist/{Table-BwgBm3hJ.js → Table-DtLrXt4i.js} +39 -7
- package/dist/Table-DtLrXt4i.js.map +1 -0
- package/dist/{Tabs-DmJB4l_N.js → Tabs-DUOUQKh7.js} +2 -2
- package/dist/{Tabs-DmJB4l_N.js.map → Tabs-DUOUQKh7.js.map} +1 -1
- package/dist/{TextInput--1CfZybC.js → TextInput-BAL-zOAN.js} +3 -3
- package/dist/{TextInput--1CfZybC.js.map → TextInput-BAL-zOAN.js.map} +1 -1
- package/dist/{ThemeProvider-BCHllN7d.js → ThemeProvider-MzVbTDBj.js} +2 -2
- package/dist/{ThemeProvider-BCHllN7d.js.map → ThemeProvider-MzVbTDBj.js.map} +1 -1
- package/dist/{ToggleAllTooltip-BFmA6TXf.js → ToggleAllTooltip-DQE5Lw6w.js} +2 -2
- package/dist/{ToggleAllTooltip-BFmA6TXf.js.map → ToggleAllTooltip-DQE5Lw6w.js.map} +1 -1
- package/dist/{ZoomableSvg-BRPGgaWJ.js → ZoomableSvg-CIOqAYpd.js} +4 -4
- package/dist/{ZoomableSvg-BRPGgaWJ.js.map → ZoomableSvg-CIOqAYpd.js.map} +1 -1
- package/dist/editors.js +3 -3
- package/dist/flint.js +1 -1
- package/dist/index.d.ts +409 -365
- package/dist/index.js +52 -50
- package/dist/internal/blocks/AIKit.js +1 -1
- package/dist/internal/blocks/AppShell.js +1 -1
- package/dist/internal/blocks/AuthLayout.js +1 -1
- package/dist/internal/blocks/BrandEditor.js +1 -1
- package/dist/internal/blocks/BulkActionsBar.js +55 -0
- package/dist/internal/blocks/BulkActionsBar.js.map +1 -0
- package/dist/internal/blocks/ChipEditor.js +2 -2
- package/dist/internal/blocks/ClipboardButton.js +1 -1
- package/dist/internal/blocks/ColorInput.js +1 -1
- package/dist/internal/blocks/ColorModeSwitch.js +1 -1
- package/dist/internal/blocks/Command.js +1 -1
- package/dist/internal/blocks/CopyField.js +1 -1
- package/dist/internal/blocks/DateInput.js +1 -1
- package/dist/internal/blocks/DateRangeInput.js +1 -1
- package/dist/internal/blocks/EmptyState.js +7 -2
- package/dist/internal/blocks/EmptyState.js.map +1 -1
- package/dist/internal/blocks/ExportMenu.js +2 -2
- package/dist/internal/blocks/Form/connectors/ComboboxField.js +2 -2
- package/dist/internal/blocks/Form/connectors/MultiComboboxField.js +1 -1
- package/dist/internal/blocks/Form.js +2 -2
- package/dist/internal/blocks/FormGroup.js +1 -1
- package/dist/internal/blocks/InlineEdit.js +1 -1
- package/dist/internal/blocks/MultiActionButtonGroup.js +1 -1
- package/dist/internal/blocks/MultiCombobox.js +3 -3
- package/dist/internal/blocks/NumberInput.js +1 -1
- package/dist/internal/blocks/PageLayout.js +1 -1
- package/dist/internal/blocks/PageSection.js +31 -0
- package/dist/internal/blocks/PageSection.js.map +1 -0
- package/dist/internal/blocks/PageToolbar.js +1 -1
- package/dist/internal/blocks/PasswordInput.js +2 -2
- package/dist/internal/blocks/SearchInput.js +1 -1
- package/dist/internal/blocks/SearchInputWithNavigation.js +3 -3
- package/dist/internal/blocks/SectionNav.js +1 -1
- package/dist/internal/blocks/SplitButton.js +1 -1
- package/dist/internal/blocks/TextInput.js +1 -1
- package/dist/internal/blocks/Textarea.js +1 -1
- package/dist/internal/blocks/TimeInput.js +2 -2
- package/dist/internal/components/Alert.js +1 -1
- package/dist/internal/components/AlertModal.js +1 -1
- package/dist/internal/components/Avatar.js +1 -1
- package/dist/internal/components/BrandLogo.js +1 -1
- package/dist/internal/components/Breadcrumb.js +1 -1
- package/dist/internal/components/Button.js +1 -1
- package/dist/internal/components/Checkbox.js +1 -1
- package/dist/internal/components/Clipboard.js +1 -1
- package/dist/internal/components/CollapsiblePanel.js +1 -1
- package/dist/internal/components/Combobox.js +1 -1
- package/dist/internal/components/DateRangePicker.js +1 -1
- package/dist/internal/components/FileUpload.js +1 -1
- package/dist/internal/components/FullScreenModal.js +1 -1
- package/dist/internal/components/InputGroup.js +1 -1
- package/dist/internal/components/Kbd.js +1 -1
- package/dist/internal/components/Modal.js +1 -1
- package/dist/internal/components/Navbar.js +1 -1
- package/dist/internal/components/Pagination.js +1 -1
- package/dist/internal/components/Popconfirm.js +1 -1
- package/dist/internal/components/RadioGroup.js +1 -1
- package/dist/internal/components/Search.js +1 -1
- package/dist/internal/components/Select.js +1 -1
- package/dist/internal/components/Sheet.js +1 -1
- package/dist/internal/components/Sidebar.js +1 -1
- package/dist/internal/components/Slider.js +1 -1
- package/dist/internal/components/Table.js +1 -1
- package/dist/internal/components/Tabs.js +1 -1
- package/dist/internal/components/ThemeProvider.js +1 -1
- package/dist/internal/components/Tooltip.js +1 -1
- package/dist/internal/components/Truncated.js +1 -1
- package/dist/internal/components/ZoomableSvg.js +1 -1
- package/dist/internal/utils.js +1 -1
- package/dist/markdown-editor.js +6 -6
- package/dist/mermaid.js +1 -1
- package/dist/rjsf.js +11 -11
- package/dist/rjsf.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/testing.js +1 -1
- package/dist/{utils-DjFceY3H.js → utils-BxEJOnFD.js} +2 -2
- package/dist/{utils-DjFceY3H.js.map → utils-BxEJOnFD.js.map} +1 -1
- package/package.json +3 -3
- package/src/styles.css +50 -0
- package/src/theme.css +10 -8
- package/dist/AIKit-Cf5plya2.js.map +0 -1
- package/dist/Clipboard-fAkDdpEu.js.map +0 -1
- package/dist/ClipboardButton-71Ugbl8c.js.map +0 -1
- package/dist/SectionNav-L81iJBo3.js.map +0 -1
- package/dist/Table-BwgBm3hJ.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { cn } from "./classNames-DkX30VJU.js";
|
|
2
2
|
import { Check, Circle } from "./icons-DDR9dFSr.js";
|
|
3
3
|
import { ScrollArea } from "./internal/components/ScrollArea.js";
|
|
4
|
-
import { TextInput } from "./TextInput
|
|
4
|
+
import { TextInput } from "./TextInput-BAL-zOAN.js";
|
|
5
5
|
import { createContext, use } from "react";
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
import { Command, CommandInput, defaultFilter, useCommandState } from "cmdk";
|
|
@@ -107,4 +107,4 @@ Command$1.Input = CommandInput$1;
|
|
|
107
107
|
Command$1.Item = CommandItem;
|
|
108
108
|
export { Command$1 as Command, CommandGroup, CommandInput$1 as CommandInput, CommandItem, CommandList, defaultFilter, useCommandState };
|
|
109
109
|
|
|
110
|
-
//# sourceMappingURL=Command-
|
|
110
|
+
//# sourceMappingURL=Command-D6XYzzJf.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Command-BcTb6GsR.js","names":["CommandPrimitive","CommandPrimitive","CommandInput","CmdInput","CommandPrimitive","CommandPrimitive","CommandPrimitive","Command","CommandPrimitive","CommandInput"],"sources":["../src/blocks/Command/CommandContext.tsx","../src/blocks/Command/CommandContent.tsx","../src/blocks/Command/CommandEmpty.tsx","../src/blocks/Command/CommandGroup.tsx","../src/blocks/Command/CommandInput.tsx","../src/blocks/Command/CommandItem/CheckIndicator.tsx","../src/blocks/Command/CommandItem/CommandItem.tsx","../src/blocks/Command/CommandList.tsx","../src/blocks/Command/CommandSeparator.tsx","../src/blocks/Command/Command.tsx"],"sourcesContent":["import { createContext, use } from 'react';\n\n/** Whether the enclosing `Command` is `compact`. */\nexport const CommandContext = createContext(false);\n\nexport const useCommandCompact = () => use(CommandContext);\n","import type { ComponentProps } from 'react';\n\nimport { cn } from '../../utils';\n\nimport { useCommandCompact } from './CommandContext';\n\ntype Props = ComponentProps<'div'>;\n\nexport const CommandContent = ({ className, ...rest }: Props) => {\n const compact = useCommandCompact();\n\n return (\n <div\n {...rest}\n className={cn('tw:flex', 'tw:flex-col', compact ? 'tw:p-2' : 'tw:p-4', 'tw:gap-2', className)}\n />\n );\n};\n","import type { ComponentProps } from 'react';\nimport { Command as CommandPrimitive } from 'cmdk';\n\ntype Props = ComponentProps<typeof CommandPrimitive.Empty>;\n\nexport const CommandEmpty = ({ ...props }: Props) => <CommandPrimitive.Empty {...props} />;\n","import type { ComponentProps } from 'react';\nimport { Command as CommandPrimitive } from 'cmdk';\n\nimport { cn } from '../../utils';\n\ntype Props = ComponentProps<typeof CommandPrimitive.Group>;\n\nexport const CommandGroup = ({ className, ...props }: Props) => (\n <CommandPrimitive.Group\n className={cn(\n 'tw:[&_[cmdk-group-heading]]:font-semibold',\n 'tw:[&_[cmdk-group-heading]]:font-sans',\n 'tw:[&_[cmdk-group-heading]]:px-4',\n 'tw:[&_[cmdk-group-heading]]:py-0.5',\n 'tw:[&_[cmdk-group-heading]]:uppercase',\n 'tw:[&_[cmdk-group-heading]]:text-[11px]',\n 'tw:[&_[cmdk-group-heading]]:text-muted-foreground',\n 'tw:[&_[cmdk-group-heading]]:tracking-[1px]',\n 'tw:[&_[cmdk-group-heading]]:border-b',\n 'tw:[&_[cmdk-group-heading]]:border-border',\n 'tw:[&_[cmdk-group-heading]]:my-2',\n className,\n )}\n {...props}\n />\n);\n","import type { ComponentProps } from 'react';\nimport { CommandInput as CmdInput } from 'cmdk';\n\nimport { cn } from '../../utils';\nimport { TextInput } from '../TextInput';\n\nimport { useCommandCompact } from './CommandContext';\n\ntype Props = ComponentProps<typeof TextInput>;\n\n/** The search field; a bare full-width row unless the `Command` is `compact`. */\nexport const CommandInput = ({ ref, className, ...props }: Props) => {\n const compact = useCommandCompact();\n\n return (\n <CmdInput ref={ref} asChild>\n <TextInput\n {...props}\n className={cn(\n !compact &&\n 'tw:!bg-transparent tw:!border-transparent tw:!rounded-none tw:max-h-12 tw:h-12',\n className,\n )}\n />\n </CmdInput>\n );\n};\n","import { Check, Circle } from '../../../icons';\nimport { cn } from '../../../utils';\n\ntype Props = {\n variant?: 'checkbox' | 'radio' | 'default';\n};\n\nexport const CheckIndicator = ({ variant = 'default' }: Props) => {\n if (variant === 'default') return null;\n\n return (\n <span\n data-variant={variant}\n className={cn(\n 'tw:group/check-indicator',\n // positioning\n 'tw:pointer-events-none',\n\n // sizing\n 'tw:size-4',\n 'tw:flex',\n 'tw:items-center',\n 'tw:justify-center',\n\n // border\n 'tw:border',\n 'tw:border-solid',\n 'tw:rounded',\n 'tw:border-input',\n\n 'tw:data-[variant=radio]:rounded-full',\n\n 'tw:data-[variant=checkbox]:rounded',\n 'tw:data-[variant=checkbox]:group-data-[checked=true]/command-item:border-primary',\n 'tw:data-[variant=checkbox]:group-data-[checked=true]/command-item:bg-primary',\n 'tw:shrink-0',\n )}\n >\n {variant === 'checkbox' ? (\n <Check\n className={cn(\n 'tw:hidden',\n // Lucide SVGs default to 24×24; constrain to the 16px indicator slot.\n 'tw:size-3',\n 'tw:stroke-[4px]',\n 'tw:group-data-[checked=true]/command-item:block',\n 'tw:group-data-[variant=checkbox]/check-indicator:text-primary-foreground',\n )}\n />\n ) : (\n <Circle\n className={cn(\n 'tw:hidden',\n // Lucide Circle is stroke-only — force fill to match the stroke so\n // the indicator reads as a solid dot.\n 'tw:size-3',\n 'tw:fill-current',\n 'tw:group-data-[checked=true]/command-item:block',\n 'tw:group-data-[variant=radio]/check-indicator:text-primary',\n )}\n />\n )}\n </span>\n );\n};\n","import type { ComponentProps, ReactNode } from 'react';\nimport { Command as CommandPrimitive } from 'cmdk';\n\nimport { Check } from '../../../icons';\nimport { cn } from '../../../utils';\n\nimport { CheckIndicator } from './CheckIndicator';\n\ntype Props = ComponentProps<typeof CommandPrimitive.Item> & {\n icon?: ReactNode;\n checked?: boolean;\n variant?: ComponentProps<typeof CheckIndicator>['variant'];\n actions?: ReactNode;\n};\n\nexport const CommandItem = ({\n className,\n icon,\n children,\n checked = false,\n variant = 'default',\n actions,\n ...props\n}: Props) => (\n <div className=\"tw:group tw:flex tw:items-center tw:justify-center\">\n <CommandPrimitive.Item\n {...props}\n data-checked={checked}\n data-variant={variant}\n className={cn(\n 'tw:group/command-item',\n 'tw:peer/command-item',\n\n // positioning\n 'tw:relative',\n 'tw:flex',\n 'tw:items-center',\n 'tw:gap-2',\n 'tw:flex-1',\n 'tw:p-2',\n\n // typography\n 'tw:font-sans',\n 'tw:text-sm',\n 'tw:leading-6',\n 'tw:cursor-pointer',\n 'tw:select-none',\n 'tw:outline-hidden',\n\n // The keyboard highlight is the only fill; a checked row shows its indicator or check instead.\n // No colour transition: a fading row would read as a second highlight on ↑/↓.\n 'tw:rounded-md',\n 'tw:data-[selected=true]:bg-hover',\n\n // disabled\n 'tw:aria-disabled:opacity-disabled',\n\n 'tw:aria-disabled:cursor-not-allowed',\n 'tw:aria-disabled:hover:bg-transparent',\n\n // reset styles for checked and disabled\n 'tw:data-[checked=true]:aria-disabled:opacity-100',\n 'tw:data-[checked=true]:aria-disabled:cursor-default',\n className,\n )}\n >\n <CheckIndicator variant={variant} />\n {icon && (\n <span className=\"tw:inline-flex tw:size-4 tw:shrink-0 tw:items-center tw:justify-center tw:text-muted-foreground tw:[&_svg:not([class*='tw:size-'])]:size-4\">\n {icon}\n </span>\n )}\n {children}\n {checked && variant === 'default' && (\n <Check aria-hidden className=\"tw:ml-auto tw:size-4 tw:shrink-0 tw:text-primary\" />\n )}\n </CommandPrimitive.Item>\n\n {actions && (\n <span\n data-slot=\"command-item-actions\"\n className={cn(\n 'tw:hidden',\n 'tw:mx-2',\n 'tw:group-hover:flex',\n 'tw:peer-hover/command-item:flex',\n 'tw:peer-data-[selected=true]/command-item:flex',\n )}\n >\n {actions}\n </span>\n )}\n </div>\n);\n","import type { ComponentProps } from 'react';\nimport { Command as CommandPrimitive } from 'cmdk';\n\nimport { ScrollArea } from '../../components/ScrollArea';\nimport { cn } from '../../utils';\n\nimport { useCommandCompact } from './CommandContext';\n\ntype Props = ComponentProps<typeof CommandPrimitive.List> &\n Pick<ComponentProps<typeof ScrollArea>, 'viewPortClassName'>;\n\nexport const CommandList = ({ ref, className, children, viewPortClassName, ...props }: Props) => {\n const compact = useCommandCompact();\n\n return (\n <ScrollArea\n ref={ref}\n className={cn(!compact && 'tw:px-4 tw:pb-4', className)}\n viewPortClassName={cn(\n 'tw:[&_[cmdk-list-sizer]]:flex',\n 'tw:[&_[cmdk-list-sizer]]:flex-col',\n viewPortClassName,\n )}\n >\n <CommandPrimitive.List {...props}>{children}</CommandPrimitive.List>\n </ScrollArea>\n );\n};\n","import type { ComponentProps } from 'react';\nimport { Command as CommandPrimitive } from 'cmdk';\n\nimport { cn } from '../../utils';\n\ntype Props = ComponentProps<typeof CommandPrimitive.Separator>;\n\nexport const CommandSeparator = ({ className, ...props }: Props) => (\n <CommandPrimitive.Separator\n className={cn('tw:h-px', 'tw:bg-border', 'tw:my-2', className)}\n {...props}\n />\n);\n","import type { ComponentProps } from 'react';\nimport { Command as CommandPrimitive } from 'cmdk';\n\nimport { cn } from '../../utils';\n\nimport { CommandContent } from './CommandContent';\nimport { CommandContext } from './CommandContext';\nimport { CommandEmpty } from './CommandEmpty';\nimport { CommandGroup } from './CommandGroup';\nimport { CommandInput } from './CommandInput';\nimport { CommandItem } from './CommandItem';\nimport { CommandList } from './CommandList';\nimport { CommandSeparator } from './CommandSeparator';\n\ntype Props = ComponentProps<typeof CommandPrimitive> & {\n /** Drops the palette padding and the bare search row; suits small surfaces like popovers. */\n compact?: boolean;\n};\n\nexport const Command = ({ className, compact = false, ...rest }: Props) => (\n <CommandContext value={compact}>\n <CommandPrimitive\n className={cn('tw:group/command', 'tailwindcss-preflight', className)}\n {...rest}\n />\n </CommandContext>\n);\n\nCommand.Content = CommandContent;\n\nCommand.Separator = CommandSeparator;\nCommand.List = CommandList;\nCommand.Group = CommandGroup;\nCommand.Empty = CommandEmpty;\nCommand.Input = CommandInput;\n\n// items\nCommand.Item = CommandItem;\n"],"mappings":";;;;;;;;;AAGA,MAAa,iBAAiB,cAAc,KAAK;AAEjD,MAAa,0BAA0B,IAAI,cAAc;;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UAAQ,OAAO"}
|
|
1
|
+
{"version":3,"file":"Command-D6XYzzJf.js","names":["CommandPrimitive","CommandPrimitive","CommandInput","CmdInput","CommandPrimitive","CommandPrimitive","CommandPrimitive","Command","CommandPrimitive","CommandInput"],"sources":["../src/blocks/Command/CommandContext.tsx","../src/blocks/Command/CommandContent.tsx","../src/blocks/Command/CommandEmpty.tsx","../src/blocks/Command/CommandGroup.tsx","../src/blocks/Command/CommandInput.tsx","../src/blocks/Command/CommandItem/CheckIndicator.tsx","../src/blocks/Command/CommandItem/CommandItem.tsx","../src/blocks/Command/CommandList.tsx","../src/blocks/Command/CommandSeparator.tsx","../src/blocks/Command/Command.tsx"],"sourcesContent":["import { createContext, use } from 'react';\n\n/** Whether the enclosing `Command` is `compact`. */\nexport const CommandContext = createContext(false);\n\nexport const useCommandCompact = () => use(CommandContext);\n","import type { ComponentProps } from 'react';\n\nimport { cn } from '../../utils';\n\nimport { useCommandCompact } from './CommandContext';\n\ntype Props = ComponentProps<'div'>;\n\nexport const CommandContent = ({ className, ...rest }: Props) => {\n const compact = useCommandCompact();\n\n return (\n <div\n {...rest}\n className={cn('tw:flex', 'tw:flex-col', compact ? 'tw:p-2' : 'tw:p-4', 'tw:gap-2', className)}\n />\n );\n};\n","import type { ComponentProps } from 'react';\nimport { Command as CommandPrimitive } from 'cmdk';\n\ntype Props = ComponentProps<typeof CommandPrimitive.Empty>;\n\nexport const CommandEmpty = ({ ...props }: Props) => <CommandPrimitive.Empty {...props} />;\n","import type { ComponentProps } from 'react';\nimport { Command as CommandPrimitive } from 'cmdk';\n\nimport { cn } from '../../utils';\n\ntype Props = ComponentProps<typeof CommandPrimitive.Group>;\n\nexport const CommandGroup = ({ className, ...props }: Props) => (\n <CommandPrimitive.Group\n className={cn(\n 'tw:[&_[cmdk-group-heading]]:font-semibold',\n 'tw:[&_[cmdk-group-heading]]:font-sans',\n 'tw:[&_[cmdk-group-heading]]:px-4',\n 'tw:[&_[cmdk-group-heading]]:py-0.5',\n 'tw:[&_[cmdk-group-heading]]:uppercase',\n 'tw:[&_[cmdk-group-heading]]:text-[11px]',\n 'tw:[&_[cmdk-group-heading]]:text-muted-foreground',\n 'tw:[&_[cmdk-group-heading]]:tracking-[1px]',\n 'tw:[&_[cmdk-group-heading]]:border-b',\n 'tw:[&_[cmdk-group-heading]]:border-border',\n 'tw:[&_[cmdk-group-heading]]:my-2',\n className,\n )}\n {...props}\n />\n);\n","import type { ComponentProps } from 'react';\nimport { CommandInput as CmdInput } from 'cmdk';\n\nimport { cn } from '../../utils';\nimport { TextInput } from '../TextInput';\n\nimport { useCommandCompact } from './CommandContext';\n\ntype Props = ComponentProps<typeof TextInput>;\n\n/** The search field; a bare full-width row unless the `Command` is `compact`. */\nexport const CommandInput = ({ ref, className, ...props }: Props) => {\n const compact = useCommandCompact();\n\n return (\n <CmdInput ref={ref} asChild>\n <TextInput\n {...props}\n className={cn(\n !compact &&\n 'tw:!bg-transparent tw:!border-transparent tw:!rounded-none tw:max-h-12 tw:h-12',\n className,\n )}\n />\n </CmdInput>\n );\n};\n","import { Check, Circle } from '../../../icons';\nimport { cn } from '../../../utils';\n\ntype Props = {\n variant?: 'checkbox' | 'radio' | 'default';\n};\n\nexport const CheckIndicator = ({ variant = 'default' }: Props) => {\n if (variant === 'default') return null;\n\n return (\n <span\n data-variant={variant}\n className={cn(\n 'tw:group/check-indicator',\n // positioning\n 'tw:pointer-events-none',\n\n // sizing\n 'tw:size-4',\n 'tw:flex',\n 'tw:items-center',\n 'tw:justify-center',\n\n // border\n 'tw:border',\n 'tw:border-solid',\n 'tw:rounded',\n 'tw:border-input',\n\n 'tw:data-[variant=radio]:rounded-full',\n\n 'tw:data-[variant=checkbox]:rounded',\n 'tw:data-[variant=checkbox]:group-data-[checked=true]/command-item:border-primary',\n 'tw:data-[variant=checkbox]:group-data-[checked=true]/command-item:bg-primary',\n 'tw:shrink-0',\n )}\n >\n {variant === 'checkbox' ? (\n <Check\n className={cn(\n 'tw:hidden',\n // Lucide SVGs default to 24×24; constrain to the 16px indicator slot.\n 'tw:size-3',\n 'tw:stroke-[4px]',\n 'tw:group-data-[checked=true]/command-item:block',\n 'tw:group-data-[variant=checkbox]/check-indicator:text-primary-foreground',\n )}\n />\n ) : (\n <Circle\n className={cn(\n 'tw:hidden',\n // Lucide Circle is stroke-only — force fill to match the stroke so\n // the indicator reads as a solid dot.\n 'tw:size-3',\n 'tw:fill-current',\n 'tw:group-data-[checked=true]/command-item:block',\n 'tw:group-data-[variant=radio]/check-indicator:text-primary',\n )}\n />\n )}\n </span>\n );\n};\n","import type { ComponentProps, ReactNode } from 'react';\nimport { Command as CommandPrimitive } from 'cmdk';\n\nimport { Check } from '../../../icons';\nimport { cn } from '../../../utils';\n\nimport { CheckIndicator } from './CheckIndicator';\n\ntype Props = ComponentProps<typeof CommandPrimitive.Item> & {\n icon?: ReactNode;\n checked?: boolean;\n variant?: ComponentProps<typeof CheckIndicator>['variant'];\n actions?: ReactNode;\n};\n\nexport const CommandItem = ({\n className,\n icon,\n children,\n checked = false,\n variant = 'default',\n actions,\n ...props\n}: Props) => (\n <div className=\"tw:group tw:flex tw:items-center tw:justify-center\">\n <CommandPrimitive.Item\n {...props}\n data-checked={checked}\n data-variant={variant}\n className={cn(\n 'tw:group/command-item',\n 'tw:peer/command-item',\n\n // positioning\n 'tw:relative',\n 'tw:flex',\n 'tw:items-center',\n 'tw:gap-2',\n 'tw:flex-1',\n 'tw:p-2',\n\n // typography\n 'tw:font-sans',\n 'tw:text-sm',\n 'tw:leading-6',\n 'tw:cursor-pointer',\n 'tw:select-none',\n 'tw:outline-hidden',\n\n // The keyboard highlight is the only fill; a checked row shows its indicator or check instead.\n // No colour transition: a fading row would read as a second highlight on ↑/↓.\n 'tw:rounded-md',\n 'tw:data-[selected=true]:bg-hover',\n\n // disabled\n 'tw:aria-disabled:opacity-disabled',\n\n 'tw:aria-disabled:cursor-not-allowed',\n 'tw:aria-disabled:hover:bg-transparent',\n\n // reset styles for checked and disabled\n 'tw:data-[checked=true]:aria-disabled:opacity-100',\n 'tw:data-[checked=true]:aria-disabled:cursor-default',\n className,\n )}\n >\n <CheckIndicator variant={variant} />\n {icon && (\n <span className=\"tw:inline-flex tw:size-4 tw:shrink-0 tw:items-center tw:justify-center tw:text-muted-foreground tw:[&_svg:not([class*='tw:size-'])]:size-4\">\n {icon}\n </span>\n )}\n {children}\n {checked && variant === 'default' && (\n <Check aria-hidden className=\"tw:ml-auto tw:size-4 tw:shrink-0 tw:text-primary\" />\n )}\n </CommandPrimitive.Item>\n\n {actions && (\n <span\n data-slot=\"command-item-actions\"\n className={cn(\n 'tw:hidden',\n 'tw:mx-2',\n 'tw:group-hover:flex',\n 'tw:peer-hover/command-item:flex',\n 'tw:peer-data-[selected=true]/command-item:flex',\n )}\n >\n {actions}\n </span>\n )}\n </div>\n);\n","import type { ComponentProps } from 'react';\nimport { Command as CommandPrimitive } from 'cmdk';\n\nimport { ScrollArea } from '../../components/ScrollArea';\nimport { cn } from '../../utils';\n\nimport { useCommandCompact } from './CommandContext';\n\ntype Props = ComponentProps<typeof CommandPrimitive.List> &\n Pick<ComponentProps<typeof ScrollArea>, 'viewPortClassName'>;\n\nexport const CommandList = ({ ref, className, children, viewPortClassName, ...props }: Props) => {\n const compact = useCommandCompact();\n\n return (\n <ScrollArea\n ref={ref}\n className={cn(!compact && 'tw:px-4 tw:pb-4', className)}\n viewPortClassName={cn(\n 'tw:[&_[cmdk-list-sizer]]:flex',\n 'tw:[&_[cmdk-list-sizer]]:flex-col',\n viewPortClassName,\n )}\n >\n <CommandPrimitive.List {...props}>{children}</CommandPrimitive.List>\n </ScrollArea>\n );\n};\n","import type { ComponentProps } from 'react';\nimport { Command as CommandPrimitive } from 'cmdk';\n\nimport { cn } from '../../utils';\n\ntype Props = ComponentProps<typeof CommandPrimitive.Separator>;\n\nexport const CommandSeparator = ({ className, ...props }: Props) => (\n <CommandPrimitive.Separator\n className={cn('tw:h-px', 'tw:bg-border', 'tw:my-2', className)}\n {...props}\n />\n);\n","import type { ComponentProps } from 'react';\nimport { Command as CommandPrimitive } from 'cmdk';\n\nimport { cn } from '../../utils';\n\nimport { CommandContent } from './CommandContent';\nimport { CommandContext } from './CommandContext';\nimport { CommandEmpty } from './CommandEmpty';\nimport { CommandGroup } from './CommandGroup';\nimport { CommandInput } from './CommandInput';\nimport { CommandItem } from './CommandItem';\nimport { CommandList } from './CommandList';\nimport { CommandSeparator } from './CommandSeparator';\n\ntype Props = ComponentProps<typeof CommandPrimitive> & {\n /** Drops the palette padding and the bare search row; suits small surfaces like popovers. */\n compact?: boolean;\n};\n\nexport const Command = ({ className, compact = false, ...rest }: Props) => (\n <CommandContext value={compact}>\n <CommandPrimitive\n className={cn('tw:group/command', 'tailwindcss-preflight', className)}\n {...rest}\n />\n </CommandContext>\n);\n\nCommand.Content = CommandContent;\n\nCommand.Separator = CommandSeparator;\nCommand.List = CommandList;\nCommand.Group = CommandGroup;\nCommand.Empty = CommandEmpty;\nCommand.Input = CommandInput;\n\n// items\nCommand.Item = CommandItem;\n"],"mappings":";;;;;;;;;AAGA,MAAa,iBAAiB,cAAc,KAAK;AAEjD,MAAa,0BAA0B,IAAI,cAAc;;ACGzD,MAAa,kBAAkB,EAAE,WAAW,GAAG,WAAkB;CAC/D,MAAM,UAAU,kBAAkB;CAElC,OACE,oBAAC,OAAD;EACE,GAAI;EACJ,WAAW,GAAG,WAAW,eAAe,UAAU,WAAW,UAAU,YAAY,SAAS;CAC7F,CAAA;AAEL;;ACZA,MAAa,gBAAgB,EAAE,GAAG,YAAmB,oBAACA,QAAiB,OAAlB,EAAwB,GAAI,MAAQ,CAAA;;ACEzF,MAAa,gBAAgB,EAAE,WAAW,GAAG,YAC3C,oBAACC,QAAiB,OAAlB;CACE,WAAW,GACT,6CACA,yCACA,oCACA,sCACA,yCACA,2CACA,qDACA,8CACA,wCACA,6CACA,oCACA,SACF;CACA,GAAI;AACL,CAAA;;;ACbH,MAAaC,kBAAgB,EAAE,KAAK,WAAW,GAAG,YAA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a,eAAe,EAAE,KAAK,WAAW,UAAU,mBAAmB,GAAG,YAAmB;CAC/F,MAAM,UAAU,kBAAkB;CAElC,OACE,oBAAC,YAAD;EACO;EACL,WAAW,GAAG,CAAC,WAAW,mBAAmB,SAAS;EACtD,mBAAmB,GACjB,iCACA,qCACA,iBACF;EAEA,UAAA,oBAACC,QAAiB,MAAlB;GAAuB,GAAI;GAAQ;EAAgC,CAAA;CACzD,CAAA;AAEhB;;ACpBA,MAAa,oBAAoB,EAAE,WAAW,GAAG,YAC/C,oBAACC,QAAiB,WAAlB;CACE,WAAW,GAAG,WAAW,gBAAgB,WAAW,SAAS;CAC7D,GAAI;AACL,CAAA;;ACQH,MAAaC,aAAW,EAAE,WAAW,UAAU,OAAO,GAAG,WACvD,oBAAC,gBAAD;CAAgB,OAAO;CACrB,UAAA,oBAACC,SAAD;EACE,WAAW,GAAG,oBAAoB,yBAAyB,SAAS;EACpE,GAAI;CACL,CAAA;AACa,CAAA;AAGlB,UAAQ,UAAU;AAElB,UAAQ,YAAY;AACpB,UAAQ,OAAO;AACf,UAAQ,QAAQ;AAChB,UAAQ,QAAQ;AAChB,UAAQ,QAAQC;AAGhB,UAAQ,OAAO"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cn } from "./classNames-DkX30VJU.js";
|
|
2
|
-
import { Tooltip, copyToClipboard } from "./utils-
|
|
2
|
+
import { Tooltip, copyToClipboard } from "./utils-BxEJOnFD.js";
|
|
3
3
|
import { Check, Copy, Eye, EyeOff } from "./icons-DDR9dFSr.js";
|
|
4
4
|
import { Label } from "./internal/components/Label.js";
|
|
5
5
|
import { createContext, use, useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
@@ -271,4 +271,4 @@ const CopyField = {
|
|
|
271
271
|
};
|
|
272
272
|
export { CopyField };
|
|
273
273
|
|
|
274
|
-
//# sourceMappingURL=CopyField-
|
|
274
|
+
//# sourceMappingURL=CopyField-9WBU8thS.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CopyField-CnwAvQz9.js","names":["CopyIcon"],"sources":["../src/blocks/CopyField/CopyContext.tsx","../src/blocks/CopyField/CopyBox.tsx","../src/blocks/CopyField/CopyButton.tsx","../src/blocks/CopyField/CopyChildren.tsx","../src/blocks/CopyField/CopyFooter.tsx","../src/blocks/CopyField/CopyHidden.tsx","../src/blocks/CopyField/CopyLabel.tsx","../src/blocks/CopyField/CopyPrefix.tsx","../src/blocks/CopyField/CopyReveal.tsx","../src/blocks/CopyField/CopyRoot.tsx","../src/blocks/CopyField/CopySuffix.tsx","../src/blocks/CopyField/CopyField.tsx"],"sourcesContent":["import { createContext, use } from 'react';\n\ntype CopyContextValue = {\n /** Whether a copy just happened (drives the Copy → Check feedback for ~1.5s). */\n copied: boolean;\n /** Copies the real `value` to the clipboard, guarded against drag-select. */\n handleCopy: () => void;\n /** The real value copied to the clipboard, regardless of masking. */\n value: string;\n /** Render displayed content in monospace/code style. */\n mono: boolean;\n /** Whether to show the \"Copy\" hint tooltip on hover (else only \"Copied\" on copy). */\n hoverHint: boolean;\n /** Whether revealable `CopyField.Hidden` content is currently masked. */\n hidden: boolean;\n /** Toggles the masked ↔ revealed state. */\n toggleHidden: () => void;\n /**\n * Registers a revealable `CopyField.Hidden` so `CopyField.Reveal` knows to render.\n * Returns a cleanup that unregisters on unmount.\n */\n registerRevealable: () => () => void;\n /** True once at least one revealable `CopyField.Hidden` is mounted. */\n hasRevealable: boolean;\n /**\n * Registers the visible `CopyField.Label` so `CopyField.Box` only points `aria-labelledby`\n * at it when a label actually exists. Returns a cleanup that unregisters on unmount.\n */\n registerLabel: () => () => void;\n /** True once a `CopyField.Label` is mounted. */\n hasLabel: boolean;\n /** Minimum number of visible text lines for a multi-line box. */\n minLines: number;\n /** Maximum number of visible text lines before the box scrolls. */\n maxLines: number;\n /** Stable id of the visible label element (for `aria-labelledby`). */\n labelId: string;\n /** Stable id of the clickable box element. */\n boxId: string;\n};\n\nexport const CopyContext = createContext<CopyContextValue | null>(null);\n\nexport const useCopyContext = () => {\n const ctx = use(CopyContext);\n if (!ctx) throw new Error('CopyField.* components must be used within a CopyField.Root');\n return ctx;\n};\n","import type { CSSProperties, KeyboardEvent, ReactNode } from 'react';\n\nimport { Tooltip } from '../../components/Tooltip';\nimport { cn } from '../../utils';\n\nimport { useCopyContext } from './CopyContext';\n\ntype CopyBoxProps = {\n /** Additional CSS classes on the box. */\n className?: string;\n children: ReactNode;\n};\n\nconst LINE_HEIGHT_REM = 1.25;\nconst VERTICAL_PADDING_REM = 1.25;\n\n// Long delay — the hover \"Copy\" hint doesn't really help UX, it just pulls focus.\nconst COPY_HINT_DELAY_MS = 2000;\n\n/**\n * The clickable copy target. Click anywhere to copy; text stays drag-selectable.\n *\n * Rendered as a `role=\"button\"` div (not a native `<button>`) so it can host\n * genuinely interactive children like `CopyField.Reveal` — nesting a `<button>`\n * inside a `<button>` is invalid HTML.\n */\nexport const CopyBox = ({ className, children }: CopyBoxProps) => {\n const { copied, handleCopy, mono, minLines, maxLines, boxId, labelId, hasLabel, hoverHint } =\n useCopyContext();\n\n const multiline = maxLines > 1;\n const multilineStyle: CSSProperties | undefined = multiline\n ? {\n minHeight: `${minLines * LINE_HEIGHT_REM + VERTICAL_PADDING_REM}rem`,\n maxHeight: `${maxLines * LINE_HEIGHT_REM + VERTICAL_PADDING_REM}rem`,\n }\n : undefined;\n\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n if (event.target !== event.currentTarget) return;\n if (event.key !== 'Enter' && event.key !== ' ') return;\n event.preventDefault();\n handleCopy();\n };\n\n return (\n <Tooltip\n triggerAsChild\n placement=\"top\"\n tooltip={copied ? 'Copied' : hoverHint ? 'Copy' : null}\n forceShow={copied}\n delayDuration={COPY_HINT_DELAY_MS}\n >\n <div\n role=\"button\"\n tabIndex={0}\n id={boxId}\n aria-labelledby={hasLabel ? labelId : undefined}\n onClick={handleCopy}\n onKeyDown={handleKeyDown}\n style={multilineStyle}\n className={cn(\n 'tw:group tw:relative tw:flex tw:w-fit tw:max-w-full tw:cursor-pointer tw:gap-2 tw:rounded-2xl tw:[corner-shape:superellipse(2)] tw:border tw:border-border tw:bg-card tw:px-3 tw:py-2.5 tw:text-left tw:shadow-sm tw:transition-colors tw:hover:bg-muted',\n multiline ? 'tw:items-start tw:overflow-auto' : 'tw:items-center tw:overflow-hidden',\n mono && 'tw:font-mono tw:text-[13px]',\n className,\n )}\n >\n {children}\n </div>\n </Tooltip>\n );\n};\n","import { Check, Copy as CopyIcon } from '../../icons';\nimport { cn } from '../../utils';\n\nimport { useCopyContext } from './CopyContext';\n\ntype CopyButtonProps = {\n className?: string;\n};\n\n/** Copy affordance icon — shows Copy/Check with feedback. */\nexport const CopyButton = ({ className }: CopyButtonProps) => {\n const { copied, maxLines } = useCopyContext();\n\n return (\n <span\n aria-hidden\n className={cn(\n 'tw:pointer-events-none tw:flex tw:shrink-0 tw:items-center tw:text-muted-foreground tw:group-hover:text-foreground',\n maxLines > 1 && 'tw:self-start tw:pt-0.5',\n className,\n )}\n >\n {copied ? <Check className=\"tw:size-4\" /> : <CopyIcon className=\"tw:size-4\" />}\n </span>\n );\n};\n","import type { ReactNode } from 'react';\n\nimport { cn } from '../../utils';\n\nimport { useCopyContext } from './CopyContext';\n\ntype CopyChildrenProps = {\n children: ReactNode;\n className?: string;\n};\n\n/** The displayed value. Truncates on a single line, wraps when multi-line. */\nexport const CopyChildren = ({ children, className }: CopyChildrenProps) => {\n const { maxLines } = useCopyContext();\n const multiline = maxLines > 1;\n\n return (\n <span\n className={cn(\n 'tw:min-w-0 tw:flex-1 tw:select-text tw:text-card-foreground',\n multiline ? 'tw:whitespace-pre-wrap tw:break-words' : 'tw:truncate',\n className,\n )}\n >\n {children}\n </span>\n );\n};\n","import type { ReactNode } from 'react';\n\nimport { cn } from '../../utils';\n\ntype CopyFooterProps = {\n children: ReactNode;\n className?: string;\n};\n\n/** Small helper text below the box (mirrors `FormGroup.Help` / `HelpBlock` styling). */\nexport const CopyFooter = ({ children, className }: CopyFooterProps) => {\n if (!children) return null;\n\n return <p className={cn('tw:m-0 tw:text-xs tw:text-muted-foreground', className)}>{children}</p>;\n};\n","import { useEffect } from 'react';\nimport type { ReactNode } from 'react';\n\nimport { cn } from '../../utils';\n\nimport { useCopyContext } from './CopyContext';\n\ntype CopyHiddenProps = {\n children: ReactNode;\n /**\n * When true (default), `CopyField.Reveal` can unmask this content. When false the\n * content is always masked (e.g. an implicit token inside a longer string).\n */\n revealable?: boolean;\n className?: string;\n};\n\nconst MASK = '*'.repeat(12);\n\n/**\n * Masks its children with asterisks. The real value still lives on `CopyField.Root`,\n * so copy always copies the real value regardless of mask state.\n */\nexport const CopyHidden = ({ children, revealable = true, className }: CopyHiddenProps) => {\n const { hidden, registerRevealable } = useCopyContext();\n\n useEffect(() => {\n if (!revealable) return undefined;\n return registerRevealable();\n }, [revealable, registerRevealable]);\n\n const masked = revealable ? hidden : true;\n\n return <span className={cn('tw:select-none', className)}>{masked ? MASK : children}</span>;\n};\n","import { useEffect } from 'react';\nimport type { ReactNode } from 'react';\n\nimport { Label } from '../../components/Label';\nimport { cn } from '../../utils';\n\nimport { useCopyContext } from './CopyContext';\n\ntype CopyLabelProps = {\n children: ReactNode;\n /** Content rendered right after the label text (e.g. an Info tooltip button). */\n leading?: ReactNode;\n /** Content pushed to the trailing edge of the row (e.g. a Switch). */\n trailing?: ReactNode;\n className?: string;\n};\n\n/**\n * Visible label above the box. The label carries an id and the box is wired via\n * `aria-labelledby` (not `htmlFor`, which would turn label clicks into a copy).\n *\n * Row layout: label text, then `leading` (gap), then `trailing` pushed to the far\n * edge with the space between them growing.\n */\nexport const CopyLabel = ({ children, leading, trailing, className }: CopyLabelProps) => {\n const { labelId, registerLabel } = useCopyContext();\n\n useEffect(() => registerLabel(), [registerLabel]);\n\n return (\n <div className={cn('tw:flex tw:items-center tw:gap-1', className)}>\n <Label id={labelId}>{children}</Label>\n {leading}\n {trailing != null && <span className=\"tw:ml-auto tw:flex tw:items-center\">{trailing}</span>}\n </div>\n );\n};\n","import type { ReactNode } from 'react';\n\nimport { cn } from '../../utils';\n\ntype CopyAddonProps = {\n children: ReactNode;\n className?: string;\n};\n\n/** Muted, non-selectable prefix addon with a trailing divider (not part of the copied value). */\nexport const CopyPrefix = ({ children, className }: CopyAddonProps) => (\n <span\n aria-hidden\n className={cn(\n 'tw:shrink-0 tw:select-none tw:self-stretch tw:border-r tw:border-border tw:pr-2 tw:text-muted-foreground',\n className,\n )}\n >\n {children}\n </span>\n);\n","import type { MouseEvent } from 'react';\n\nimport { Eye, EyeOff } from '../../icons';\nimport { cn } from '../../utils';\n\nimport { useCopyContext } from './CopyContext';\n\ntype CopyRevealProps = {\n className?: string;\n /** Names what the eye reveals, e.g. `password` → \"Show password\"; defaults to `value`. */\n subject?: string;\n};\n\n/** Eye toggle that reveals/masks `CopyField.Hidden` content. Renders nothing without revealable content. */\nexport const CopyReveal = ({ className, subject = 'value' }: CopyRevealProps) => {\n const { hidden, toggleHidden, hasRevealable, maxLines } = useCopyContext();\n\n if (!hasRevealable) return null;\n\n const handleClick = (event: MouseEvent<HTMLButtonElement>) => {\n event.stopPropagation();\n toggleHidden();\n };\n\n return (\n <button\n type=\"button\"\n onClick={handleClick}\n aria-label={`${hidden ? 'Show' : 'Hide'} ${subject}`}\n className={cn(\n 'tw:flex tw:shrink-0 tw:items-center tw:text-muted-foreground tw:hover:text-foreground',\n maxLines > 1 && 'tw:self-start tw:pt-0.5',\n className,\n )}\n >\n {hidden ? <Eye className=\"tw:size-4\" /> : <EyeOff className=\"tw:size-4\" />}\n </button>\n );\n};\n","import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';\nimport type { ReactNode } from 'react';\n\nimport { cn, copyToClipboard } from '../../utils';\n\nimport { CopyContext } from './CopyContext';\n\ntype CopyRootProps = {\n /** The value copied to the clipboard on click. */\n value: string;\n /** Render displayed content in monospace/code style. */\n mono?: boolean;\n /** Callback fired after a successful copy. */\n onCopy?: () => void;\n /** Start with revealable `CopyField.Hidden` content masked. */\n hiddenByDefault?: boolean;\n /** Minimum number of visible text lines for a multi-line box. */\n minLines?: number;\n /** Maximum number of visible text lines before the box scrolls. */\n maxLines?: number;\n /** Show the \"Copy\" hover hint (set `false` to only show \"Copied\" on copy). Defaults to `true`. */\n hoverHint?: boolean;\n /** Additional CSS classes on the outer container. */\n className?: string;\n children: ReactNode;\n};\n\n/**\n * Container for the Copy block. Owns the copied `value`, copy/mask state, and the\n * shared context consumed by `CopyField.Box`, `CopyField.Reveal`, `CopyField.Button`, etc.\n */\nexport const CopyRoot = ({\n value,\n mono = false,\n onCopy,\n hiddenByDefault = false,\n minLines = 1,\n maxLines,\n hoverHint = true,\n className,\n children,\n}: CopyRootProps) => {\n const [copied, setCopied] = useState(false);\n const [hidden, setHidden] = useState(hiddenByDefault);\n const [revealableCount, setRevealableCount] = useState(0);\n const [labelCount, setLabelCount] = useState(0);\n const resetTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n\n const generatedId = useId();\n const labelId = `${generatedId}-label`;\n const boxId = `${generatedId}-box`;\n\n useEffect(() => () => clearTimeout(resetTimerRef.current), []);\n\n const handleCopy = useCallback(() => {\n const selection = window.getSelection();\n const boxEl = document.getElementById(boxId);\n if (\n selection &&\n !selection.isCollapsed &&\n selection.anchorNode &&\n boxEl?.contains(selection.anchorNode)\n ) {\n return;\n }\n\n copyToClipboard(value)\n .then(() => {\n onCopy?.();\n setCopied(true);\n clearTimeout(resetTimerRef.current);\n resetTimerRef.current = setTimeout(() => setCopied(false), 1500);\n })\n .catch((error: unknown) => {\n // eslint-disable-next-line no-console\n console.error('Copy to clipboard failed', error);\n });\n }, [value, onCopy, boxId]);\n\n const toggleHidden = useCallback(() => setHidden((prev) => !prev), []);\n\n const registerRevealable = useCallback(() => {\n setRevealableCount((count) => count + 1);\n return () => setRevealableCount((count) => count - 1);\n }, []);\n\n const registerLabel = useCallback(() => {\n setLabelCount((count) => count + 1);\n return () => setLabelCount((count) => count - 1);\n }, []);\n\n const contextValue = useMemo(\n () => ({\n copied,\n handleCopy,\n value,\n mono,\n hidden,\n toggleHidden,\n registerRevealable,\n hasRevealable: revealableCount > 0,\n registerLabel,\n hasLabel: labelCount > 0,\n minLines,\n maxLines: maxLines ?? minLines,\n hoverHint,\n labelId,\n boxId,\n }),\n [\n copied,\n handleCopy,\n value,\n mono,\n hidden,\n toggleHidden,\n registerRevealable,\n revealableCount,\n registerLabel,\n labelCount,\n minLines,\n maxLines,\n hoverHint,\n labelId,\n boxId,\n ],\n );\n\n return (\n <CopyContext value={contextValue}>\n <div className={cn('tw:flex tw:w-fit tw:max-w-full tw:flex-col tw:gap-1', className)}>\n {children}\n </div>\n </CopyContext>\n );\n};\n","import type { ReactNode } from 'react';\n\nimport { cn } from '../../utils';\n\ntype CopyAddonProps = {\n children: ReactNode;\n className?: string;\n};\n\n/** Muted, non-selectable suffix addon with a leading divider (not part of the copied value). */\nexport const CopySuffix = ({ children, className }: CopyAddonProps) => (\n <span\n aria-hidden\n className={cn(\n 'tw:shrink-0 tw:select-none tw:self-stretch tw:border-l tw:border-border tw:pl-2 tw:text-muted-foreground',\n className,\n )}\n >\n {children}\n </span>\n);\n","import { CopyBox } from './CopyBox';\nimport { CopyButton } from './CopyButton';\nimport { CopyChildren } from './CopyChildren';\nimport { CopyFooter } from './CopyFooter';\nimport { CopyHidden } from './CopyHidden';\nimport { CopyLabel } from './CopyLabel';\nimport { CopyPrefix } from './CopyPrefix';\nimport { CopyReveal } from './CopyReveal';\nimport { CopyRoot } from './CopyRoot';\nimport { CopySuffix } from './CopySuffix';\n\n/**\n * Readonly value/command box that copies `value` on click.\n *\n * - A click that ends a text selection does not copy.\n * - `mono` for commands; `maxLines > 1` wraps and scrolls between `minLines` and `maxLines`.\n * - `CopyField.Hidden` masks content; copy still copies the real `value`.\n */\nexport const CopyField = {\n /** Owns `value`, mask and copy state. */\n Root: CopyRoot,\n /** Label above the box, with `leading`/`trailing` slots. */\n Label: CopyLabel,\n /** The clickable copy target. */\n Box: CopyBox,\n /** Not copied. */\n Prefix: CopyPrefix,\n /** The displayed value. */\n Children: CopyChildren,\n /** Not copied. */\n Suffix: CopySuffix,\n /** Masked display only; copy still copies the real value. */\n Hidden: CopyHidden,\n /** Toggles revealable `CopyField.Hidden` content. */\n Reveal: CopyReveal,\n /** Copy icon with Copy → Check feedback. */\n Button: CopyButton,\n /** Helper text below the box. */\n Footer: CopyFooter,\n};\n"],"mappings":";;;;;;;AAyCA,MAAa,cAAc,cAAuC,IAAI;AAEtE,MAAa,uBAAuB;CAClC,MAAM,MAAM,IAAI,WAAW;CAC3B,IAAI,CAAC,KAAK,MAAM,IAAI,MAAM,6DAA6D;CACvF,OAAO;AACT;;AClCA,MAAM,kBAAkB;AACxB,MAAM,uBAAuB;AAG7B,MAAM,qBAAqB;;;;;;;;AAS3B,MAAa,WAAW,EAAE,WAAW,eAA6B;CAChE,MAAM,EAAE,QAAQ,YAAY,MAAM,UAAU,UAAU,OAAO,SAAS,UAAU,cAC9E,eAAe;CAEjB,MAAM,YAAY,WAAW;CAC7B,MAAM,iBAA4C,YAC9C;EACE,WAAW,GAAG,WAAW,kBAAkB,qBAAqB;EAChE,WAAW,GAAG,WAAW,kBAAkB,qBAAqB;CAClE,IACA,KAAA;CAEJ,MAAM,iBAAiB,UAAyC;EAC9D,IAAI,MAAM,WAAW,MAAM,eAAe;EAC1C,IAAI,MAAM,QAAQ,WAAW,MAAM,QAAQ,KAAK;EAChD,MAAM,eAAe;EACrB,WAAW;CACb;CAEA,OACE,oBAAC,SAAD;EACE,gBAAA;EACA,WAAU;EACV,SAAS,SAAS,WAAW,YAAY,SAAS;EAClD,WAAW;EACX,eAAe;EAEf,UAAA,oBAAC,OAAD;GACE,MAAK;GACL,UAAU;GACV,IAAI;GACJ,mBAAiB,WAAW,UAAU,KAAA;GACtC,SAAS;GACT,WAAW;GACX,OAAO;GACP,WAAW,GACT,4PACA,YAAY,oCAAoC,sCAChD,QAAQ,+BAC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CAER,UAAU;;CAEV,QAAQ;;CAER,QAAQ;;CAER,QAAQ;;CAER,QAAQ;;CAER,QAAQ;AACV"}
|
|
1
|
+
{"version":3,"file":"CopyField-9WBU8thS.js","names":["CopyIcon"],"sources":["../src/blocks/CopyField/CopyContext.tsx","../src/blocks/CopyField/CopyBox.tsx","../src/blocks/CopyField/CopyButton.tsx","../src/blocks/CopyField/CopyChildren.tsx","../src/blocks/CopyField/CopyFooter.tsx","../src/blocks/CopyField/CopyHidden.tsx","../src/blocks/CopyField/CopyLabel.tsx","../src/blocks/CopyField/CopyPrefix.tsx","../src/blocks/CopyField/CopyReveal.tsx","../src/blocks/CopyField/CopyRoot.tsx","../src/blocks/CopyField/CopySuffix.tsx","../src/blocks/CopyField/CopyField.tsx"],"sourcesContent":["import { createContext, use } from 'react';\n\ntype CopyContextValue = {\n /** Whether a copy just happened (drives the Copy → Check feedback for ~1.5s). */\n copied: boolean;\n /** Copies the real `value` to the clipboard, guarded against drag-select. */\n handleCopy: () => void;\n /** The real value copied to the clipboard, regardless of masking. */\n value: string;\n /** Render displayed content in monospace/code style. */\n mono: boolean;\n /** Whether to show the \"Copy\" hint tooltip on hover (else only \"Copied\" on copy). */\n hoverHint: boolean;\n /** Whether revealable `CopyField.Hidden` content is currently masked. */\n hidden: boolean;\n /** Toggles the masked ↔ revealed state. */\n toggleHidden: () => void;\n /**\n * Registers a revealable `CopyField.Hidden` so `CopyField.Reveal` knows to render.\n * Returns a cleanup that unregisters on unmount.\n */\n registerRevealable: () => () => void;\n /** True once at least one revealable `CopyField.Hidden` is mounted. */\n hasRevealable: boolean;\n /**\n * Registers the visible `CopyField.Label` so `CopyField.Box` only points `aria-labelledby`\n * at it when a label actually exists. Returns a cleanup that unregisters on unmount.\n */\n registerLabel: () => () => void;\n /** True once a `CopyField.Label` is mounted. */\n hasLabel: boolean;\n /** Minimum number of visible text lines for a multi-line box. */\n minLines: number;\n /** Maximum number of visible text lines before the box scrolls. */\n maxLines: number;\n /** Stable id of the visible label element (for `aria-labelledby`). */\n labelId: string;\n /** Stable id of the clickable box element. */\n boxId: string;\n};\n\nexport const CopyContext = createContext<CopyContextValue | null>(null);\n\nexport const useCopyContext = () => {\n const ctx = use(CopyContext);\n if (!ctx) throw new Error('CopyField.* components must be used within a CopyField.Root');\n return ctx;\n};\n","import type { CSSProperties, KeyboardEvent, ReactNode } from 'react';\n\nimport { Tooltip } from '../../components/Tooltip';\nimport { cn } from '../../utils';\n\nimport { useCopyContext } from './CopyContext';\n\ntype CopyBoxProps = {\n /** Additional CSS classes on the box. */\n className?: string;\n children: ReactNode;\n};\n\nconst LINE_HEIGHT_REM = 1.25;\nconst VERTICAL_PADDING_REM = 1.25;\n\n// Long delay — the hover \"Copy\" hint doesn't really help UX, it just pulls focus.\nconst COPY_HINT_DELAY_MS = 2000;\n\n/**\n * The clickable copy target. Click anywhere to copy; text stays drag-selectable.\n *\n * Rendered as a `role=\"button\"` div (not a native `<button>`) so it can host\n * genuinely interactive children like `CopyField.Reveal` — nesting a `<button>`\n * inside a `<button>` is invalid HTML.\n */\nexport const CopyBox = ({ className, children }: CopyBoxProps) => {\n const { copied, handleCopy, mono, minLines, maxLines, boxId, labelId, hasLabel, hoverHint } =\n useCopyContext();\n\n const multiline = maxLines > 1;\n const multilineStyle: CSSProperties | undefined = multiline\n ? {\n minHeight: `${minLines * LINE_HEIGHT_REM + VERTICAL_PADDING_REM}rem`,\n maxHeight: `${maxLines * LINE_HEIGHT_REM + VERTICAL_PADDING_REM}rem`,\n }\n : undefined;\n\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n if (event.target !== event.currentTarget) return;\n if (event.key !== 'Enter' && event.key !== ' ') return;\n event.preventDefault();\n handleCopy();\n };\n\n return (\n <Tooltip\n triggerAsChild\n placement=\"top\"\n tooltip={copied ? 'Copied' : hoverHint ? 'Copy' : null}\n forceShow={copied}\n delayDuration={COPY_HINT_DELAY_MS}\n >\n <div\n role=\"button\"\n tabIndex={0}\n id={boxId}\n aria-labelledby={hasLabel ? labelId : undefined}\n onClick={handleCopy}\n onKeyDown={handleKeyDown}\n style={multilineStyle}\n className={cn(\n 'tw:group tw:relative tw:flex tw:w-fit tw:max-w-full tw:cursor-pointer tw:gap-2 tw:rounded-2xl tw:[corner-shape:superellipse(2)] tw:border tw:border-border tw:bg-card tw:px-3 tw:py-2.5 tw:text-left tw:shadow-sm tw:transition-colors tw:hover:bg-muted',\n multiline ? 'tw:items-start tw:overflow-auto' : 'tw:items-center tw:overflow-hidden',\n mono && 'tw:font-mono tw:text-[13px]',\n className,\n )}\n >\n {children}\n </div>\n </Tooltip>\n );\n};\n","import { Check, Copy as CopyIcon } from '../../icons';\nimport { cn } from '../../utils';\n\nimport { useCopyContext } from './CopyContext';\n\ntype CopyButtonProps = {\n className?: string;\n};\n\n/** Copy affordance icon — shows Copy/Check with feedback. */\nexport const CopyButton = ({ className }: CopyButtonProps) => {\n const { copied, maxLines } = useCopyContext();\n\n return (\n <span\n aria-hidden\n className={cn(\n 'tw:pointer-events-none tw:flex tw:shrink-0 tw:items-center tw:text-muted-foreground tw:group-hover:text-foreground',\n maxLines > 1 && 'tw:self-start tw:pt-0.5',\n className,\n )}\n >\n {copied ? <Check className=\"tw:size-4\" /> : <CopyIcon className=\"tw:size-4\" />}\n </span>\n );\n};\n","import type { ReactNode } from 'react';\n\nimport { cn } from '../../utils';\n\nimport { useCopyContext } from './CopyContext';\n\ntype CopyChildrenProps = {\n children: ReactNode;\n className?: string;\n};\n\n/** The displayed value. Truncates on a single line, wraps when multi-line. */\nexport const CopyChildren = ({ children, className }: CopyChildrenProps) => {\n const { maxLines } = useCopyContext();\n const multiline = maxLines > 1;\n\n return (\n <span\n className={cn(\n 'tw:min-w-0 tw:flex-1 tw:select-text tw:text-card-foreground',\n multiline ? 'tw:whitespace-pre-wrap tw:break-words' : 'tw:truncate',\n className,\n )}\n >\n {children}\n </span>\n );\n};\n","import type { ReactNode } from 'react';\n\nimport { cn } from '../../utils';\n\ntype CopyFooterProps = {\n children: ReactNode;\n className?: string;\n};\n\n/** Small helper text below the box (mirrors `FormGroup.Help` / `HelpBlock` styling). */\nexport const CopyFooter = ({ children, className }: CopyFooterProps) => {\n if (!children) return null;\n\n return <p className={cn('tw:m-0 tw:text-xs tw:text-muted-foreground', className)}>{children}</p>;\n};\n","import { useEffect } from 'react';\nimport type { ReactNode } from 'react';\n\nimport { cn } from '../../utils';\n\nimport { useCopyContext } from './CopyContext';\n\ntype CopyHiddenProps = {\n children: ReactNode;\n /**\n * When true (default), `CopyField.Reveal` can unmask this content. When false the\n * content is always masked (e.g. an implicit token inside a longer string).\n */\n revealable?: boolean;\n className?: string;\n};\n\nconst MASK = '*'.repeat(12);\n\n/**\n * Masks its children with asterisks. The real value still lives on `CopyField.Root`,\n * so copy always copies the real value regardless of mask state.\n */\nexport const CopyHidden = ({ children, revealable = true, className }: CopyHiddenProps) => {\n const { hidden, registerRevealable } = useCopyContext();\n\n useEffect(() => {\n if (!revealable) return undefined;\n return registerRevealable();\n }, [revealable, registerRevealable]);\n\n const masked = revealable ? hidden : true;\n\n return <span className={cn('tw:select-none', className)}>{masked ? MASK : children}</span>;\n};\n","import { useEffect } from 'react';\nimport type { ReactNode } from 'react';\n\nimport { Label } from '../../components/Label';\nimport { cn } from '../../utils';\n\nimport { useCopyContext } from './CopyContext';\n\ntype CopyLabelProps = {\n children: ReactNode;\n /** Content rendered right after the label text (e.g. an Info tooltip button). */\n leading?: ReactNode;\n /** Content pushed to the trailing edge of the row (e.g. a Switch). */\n trailing?: ReactNode;\n className?: string;\n};\n\n/**\n * Visible label above the box. The label carries an id and the box is wired via\n * `aria-labelledby` (not `htmlFor`, which would turn label clicks into a copy).\n *\n * Row layout: label text, then `leading` (gap), then `trailing` pushed to the far\n * edge with the space between them growing.\n */\nexport const CopyLabel = ({ children, leading, trailing, className }: CopyLabelProps) => {\n const { labelId, registerLabel } = useCopyContext();\n\n useEffect(() => registerLabel(), [registerLabel]);\n\n return (\n <div className={cn('tw:flex tw:items-center tw:gap-1', className)}>\n <Label id={labelId}>{children}</Label>\n {leading}\n {trailing != null && <span className=\"tw:ml-auto tw:flex tw:items-center\">{trailing}</span>}\n </div>\n );\n};\n","import type { ReactNode } from 'react';\n\nimport { cn } from '../../utils';\n\ntype CopyAddonProps = {\n children: ReactNode;\n className?: string;\n};\n\n/** Muted, non-selectable prefix addon with a trailing divider (not part of the copied value). */\nexport const CopyPrefix = ({ children, className }: CopyAddonProps) => (\n <span\n aria-hidden\n className={cn(\n 'tw:shrink-0 tw:select-none tw:self-stretch tw:border-r tw:border-border tw:pr-2 tw:text-muted-foreground',\n className,\n )}\n >\n {children}\n </span>\n);\n","import type { MouseEvent } from 'react';\n\nimport { Eye, EyeOff } from '../../icons';\nimport { cn } from '../../utils';\n\nimport { useCopyContext } from './CopyContext';\n\ntype CopyRevealProps = {\n className?: string;\n /** Names what the eye reveals, e.g. `password` → \"Show password\"; defaults to `value`. */\n subject?: string;\n};\n\n/** Eye toggle that reveals/masks `CopyField.Hidden` content. Renders nothing without revealable content. */\nexport const CopyReveal = ({ className, subject = 'value' }: CopyRevealProps) => {\n const { hidden, toggleHidden, hasRevealable, maxLines } = useCopyContext();\n\n if (!hasRevealable) return null;\n\n const handleClick = (event: MouseEvent<HTMLButtonElement>) => {\n event.stopPropagation();\n toggleHidden();\n };\n\n return (\n <button\n type=\"button\"\n onClick={handleClick}\n aria-label={`${hidden ? 'Show' : 'Hide'} ${subject}`}\n className={cn(\n 'tw:flex tw:shrink-0 tw:items-center tw:text-muted-foreground tw:hover:text-foreground',\n maxLines > 1 && 'tw:self-start tw:pt-0.5',\n className,\n )}\n >\n {hidden ? <Eye className=\"tw:size-4\" /> : <EyeOff className=\"tw:size-4\" />}\n </button>\n );\n};\n","import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';\nimport type { ReactNode } from 'react';\n\nimport { cn, copyToClipboard } from '../../utils';\n\nimport { CopyContext } from './CopyContext';\n\ntype CopyRootProps = {\n /** The value copied to the clipboard on click. */\n value: string;\n /** Render displayed content in monospace/code style. */\n mono?: boolean;\n /** Callback fired after a successful copy. */\n onCopy?: () => void;\n /** Start with revealable `CopyField.Hidden` content masked. */\n hiddenByDefault?: boolean;\n /** Minimum number of visible text lines for a multi-line box. */\n minLines?: number;\n /** Maximum number of visible text lines before the box scrolls. */\n maxLines?: number;\n /** Show the \"Copy\" hover hint (set `false` to only show \"Copied\" on copy). Defaults to `true`. */\n hoverHint?: boolean;\n /** Additional CSS classes on the outer container. */\n className?: string;\n children: ReactNode;\n};\n\n/**\n * Container for the Copy block. Owns the copied `value`, copy/mask state, and the\n * shared context consumed by `CopyField.Box`, `CopyField.Reveal`, `CopyField.Button`, etc.\n */\nexport const CopyRoot = ({\n value,\n mono = false,\n onCopy,\n hiddenByDefault = false,\n minLines = 1,\n maxLines,\n hoverHint = true,\n className,\n children,\n}: CopyRootProps) => {\n const [copied, setCopied] = useState(false);\n const [hidden, setHidden] = useState(hiddenByDefault);\n const [revealableCount, setRevealableCount] = useState(0);\n const [labelCount, setLabelCount] = useState(0);\n const resetTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n\n const generatedId = useId();\n const labelId = `${generatedId}-label`;\n const boxId = `${generatedId}-box`;\n\n useEffect(() => () => clearTimeout(resetTimerRef.current), []);\n\n const handleCopy = useCallback(() => {\n const selection = window.getSelection();\n const boxEl = document.getElementById(boxId);\n if (\n selection &&\n !selection.isCollapsed &&\n selection.anchorNode &&\n boxEl?.contains(selection.anchorNode)\n ) {\n return;\n }\n\n copyToClipboard(value)\n .then(() => {\n onCopy?.();\n setCopied(true);\n clearTimeout(resetTimerRef.current);\n resetTimerRef.current = setTimeout(() => setCopied(false), 1500);\n })\n .catch((error: unknown) => {\n // eslint-disable-next-line no-console\n console.error('Copy to clipboard failed', error);\n });\n }, [value, onCopy, boxId]);\n\n const toggleHidden = useCallback(() => setHidden((prev) => !prev), []);\n\n const registerRevealable = useCallback(() => {\n setRevealableCount((count) => count + 1);\n return () => setRevealableCount((count) => count - 1);\n }, []);\n\n const registerLabel = useCallback(() => {\n setLabelCount((count) => count + 1);\n return () => setLabelCount((count) => count - 1);\n }, []);\n\n const contextValue = useMemo(\n () => ({\n copied,\n handleCopy,\n value,\n mono,\n hidden,\n toggleHidden,\n registerRevealable,\n hasRevealable: revealableCount > 0,\n registerLabel,\n hasLabel: labelCount > 0,\n minLines,\n maxLines: maxLines ?? minLines,\n hoverHint,\n labelId,\n boxId,\n }),\n [\n copied,\n handleCopy,\n value,\n mono,\n hidden,\n toggleHidden,\n registerRevealable,\n revealableCount,\n registerLabel,\n labelCount,\n minLines,\n maxLines,\n hoverHint,\n labelId,\n boxId,\n ],\n );\n\n return (\n <CopyContext value={contextValue}>\n <div className={cn('tw:flex tw:w-fit tw:max-w-full tw:flex-col tw:gap-1', className)}>\n {children}\n </div>\n </CopyContext>\n );\n};\n","import type { ReactNode } from 'react';\n\nimport { cn } from '../../utils';\n\ntype CopyAddonProps = {\n children: ReactNode;\n className?: string;\n};\n\n/** Muted, non-selectable suffix addon with a leading divider (not part of the copied value). */\nexport const CopySuffix = ({ children, className }: CopyAddonProps) => (\n <span\n aria-hidden\n className={cn(\n 'tw:shrink-0 tw:select-none tw:self-stretch tw:border-l tw:border-border tw:pl-2 tw:text-muted-foreground',\n className,\n )}\n >\n {children}\n </span>\n);\n","import { CopyBox } from './CopyBox';\nimport { CopyButton } from './CopyButton';\nimport { CopyChildren } from './CopyChildren';\nimport { CopyFooter } from './CopyFooter';\nimport { CopyHidden } from './CopyHidden';\nimport { CopyLabel } from './CopyLabel';\nimport { CopyPrefix } from './CopyPrefix';\nimport { CopyReveal } from './CopyReveal';\nimport { CopyRoot } from './CopyRoot';\nimport { CopySuffix } from './CopySuffix';\n\n/**\n * Readonly value/command box that copies `value` on click.\n *\n * - A click that ends a text selection does not copy.\n * - `mono` for commands; `maxLines > 1` wraps and scrolls between `minLines` and `maxLines`.\n * - `CopyField.Hidden` masks content; copy still copies the real `value`.\n */\nexport const CopyField = {\n /** Owns `value`, mask and copy state. */\n Root: CopyRoot,\n /** Label above the box, with `leading`/`trailing` slots. */\n Label: CopyLabel,\n /** The clickable copy target. */\n Box: CopyBox,\n /** Not copied. */\n Prefix: CopyPrefix,\n /** The displayed value. */\n Children: CopyChildren,\n /** Not copied. */\n Suffix: CopySuffix,\n /** Masked display only; copy still copies the real value. */\n Hidden: CopyHidden,\n /** Toggles revealable `CopyField.Hidden` content. */\n Reveal: CopyReveal,\n /** Copy icon with Copy → Check feedback. */\n Button: CopyButton,\n /** Helper text below the box. */\n Footer: CopyFooter,\n};\n"],"mappings":";;;;;;;AAyCA,MAAa,cAAc,cAAuC,IAAI;AAEtE,MAAa,uBAAuB;CAClC,MAAM,MAAM,IAAI,WAAW;CAC3B,IAAI,CAAC,KAAK,MAAM,IAAI,MAAM,6DAA6D;CACvF,OAAO;AACT;;AClCA,MAAM,kBAAkB;AACxB,MAAM,uBAAuB;AAG7B,MAAM,qBAAqB;;;;;;;;AAS3B,MAAa,WAAW,EAAE,WAAW,eAA6B;CAChE,MAAM,EAAE,QAAQ,YAAY,MAAM,UAAU,UAAU,OAAO,SAAS,UAAU,cAC9E,eAAe;CAEjB,MAAM,YAAY,WAAW;CAC7B,MAAM,iBAA4C,YAC9C;EACE,WAAW,GAAG,WAAW,kBAAkB,qBAAqB;EAChE,WAAW,GAAG,WAAW,kBAAkB,qBAAqB;CAClE,IACA,KAAA;CAEJ,MAAM,iBAAiB,UAAyC;EAC9D,IAAI,MAAM,WAAW,MAAM,eAAe;EAC1C,IAAI,MAAM,QAAQ,WAAW,MAAM,QAAQ,KAAK;EAChD,MAAM,eAAe;EACrB,WAAW;CACb;CAEA,OACE,oBAAC,SAAD;EACE,gBAAA;EACA,WAAU;EACV,SAAS,SAAS,WAAW,YAAY,SAAS;EAClD,WAAW;EACX,eAAe;EAEf,UAAA,oBAAC,OAAD;GACE,MAAK;GACL,UAAU;GACV,IAAI;GACJ,mBAAiB,WAAW,UAAU,KAAA;GACtC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;;;;;;;ACDR,MAAa,YAAY;;CAEvB,MAAM;;CAEN,OAAO;;CAEP,KAAK;;CAEL,QAAQ;;CAER,UAAU;;CAEV,QAAQ;;CAER,QAAQ;;CAER,QAAQ;;CAER,QAAQ;;CAER,QAAQ;AACV"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { createChangeInputEvent } from "./utils-
|
|
1
|
+
import { createChangeInputEvent } from "./utils-BxEJOnFD.js";
|
|
2
2
|
import { mergeRefs } from "./internal/utils/mergeRefs.js";
|
|
3
3
|
import { Calendar, X } from "./icons-DDR9dFSr.js";
|
|
4
|
-
import { InputGroup } from "./InputGroup-
|
|
4
|
+
import { InputGroup } from "./InputGroup-DnGP9-ZQ.js";
|
|
5
5
|
import { useControllableState } from "./useControllableState-BCvUOC6G.js";
|
|
6
6
|
import { DatePicker } from "./DatePicker-CI59gF3S.js";
|
|
7
7
|
import { useRef, useState } from "react";
|
|
@@ -134,4 +134,4 @@ const DateInput = ({ ref, state, focusVariant, className, value, defaultValue, o
|
|
|
134
134
|
};
|
|
135
135
|
export { DateInput };
|
|
136
136
|
|
|
137
|
-
//# sourceMappingURL=DateInput-
|
|
137
|
+
//# sourceMappingURL=DateInput-CCYG0AtT.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateInput-DJNX7Vdx.js","names":["CalendarIcon"],"sources":["../src/blocks/DateInput/helpers.ts","../src/blocks/DateInput/DateInput.tsx"],"sourcesContent":["export const formatDate = (date: Date | null | undefined, inputValue: string): string => {\n if (!date) {\n return inputValue;\n }\n return date.toLocaleDateString();\n};\n\n// Detect locale day/month/year order once, matching toLocaleDateString() output\nconst datePartOrder = new Intl.DateTimeFormat()\n .formatToParts(new Date(2000, 0, 2))\n .filter(\n (p): p is { type: 'day' | 'month' | 'year'; value: string } =>\n p.type === 'day' || p.type === 'month' || p.type === 'year',\n )\n .map((p) => p.type);\n\nexport const parseDate = (value: string): Date | null => {\n if (!value.trim()) return null;\n\n // Try locale-aware parsing first (matches toLocaleDateString round-trip)\n const nums = value.match(/\\d+/g)?.map(Number);\n if (nums && nums.length >= 3) {\n const parts = Object.fromEntries(datePartOrder.map((type, i) => [type, nums[i]]));\n const year = parts.year;\n const month = parts.month;\n const day = parts.day;\n\n if (\n year != null &&\n month != null &&\n day != null &&\n month >= 1 &&\n month <= 12 &&\n day >= 1 &&\n day <= 31\n ) {\n const date = new Date(year, month - 1, day);\n if (date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day) {\n return date;\n }\n }\n }\n\n // Fallback: detect ISO YYYY-MM-DD and construct as local midnight to avoid UTC offset issues\n const isoMatch = value.match(/^(\\d{4})-(\\d{1,2})-(\\d{1,2})$/);\n if (isoMatch) {\n const y = Number(isoMatch[1]);\n const m = Number(isoMatch[2]) - 1;\n const d = Number(isoMatch[3]);\n const date = new Date(y, m, d);\n if (date.getFullYear() === y && date.getMonth() === m && date.getDate() === d) {\n return date;\n }\n return null;\n }\n\n const fallback = new Date(value);\n return isNaN(fallback.getTime()) ? null : fallback;\n};\n","import { useRef, useState } from 'react';\nimport type {\n ChangeEventHandler,\n ComponentProps,\n ComponentRef,\n FocusEventHandler,\n MouseEventHandler,\n} from 'react';\nimport type { Matcher } from 'react-day-picker';\n\nimport { DatePicker } from '../../components/DatePicker';\nimport { InputGroup } from '../../components/InputGroup';\nimport { useControllableState } from '../../hooks/useControllableState';\nimport { Calendar as CalendarIcon, X } from '../../icons';\nimport { createChangeInputEvent, mergeRefs } from '../../utils';\n\nimport { formatDate, parseDate } from './helpers';\n\ntype InputGroupProps = Pick<ComponentProps<typeof InputGroup>, 'focusVariant' | 'state'>;\n\ntype InputGroupInputProps = Omit<\n ComponentProps<typeof InputGroup.Input>,\n 'value' | 'defaultValue' | 'type'\n>;\n\ntype Props = InputGroupProps &\n InputGroupInputProps & {\n value?: Date | null;\n defaultValue?: Date | null;\n onValueChange?: (value: Date | null) => void;\n onValueBlur?: (value: Date | null) => void;\n allowClear?: boolean;\n disabledDays?: Matcher | Matcher[];\n endMonth?: Date;\n startMonth?: Date;\n };\n\nexport const DateInput = ({\n ref,\n\n // group props\n state,\n focusVariant,\n className,\n\n // own props\n value,\n defaultValue,\n onValueChange,\n onValueBlur,\n onChange,\n onBlur,\n onFocus,\n allowClear = false,\n disabledDays,\n endMonth,\n startMonth,\n\n // input props\n disabled,\n readOnly,\n placeholder = 'Select a date',\n ...restInputProps\n}: Props) => {\n const inputRef = useRef<ComponentRef<'input'>>(null);\n\n const [inputValue, setInputValue] = useState('');\n const [hasFocus, setHasFocus] = useState(false);\n const [isOpen, setIsOpen] = useState(false);\n const [month, setMonth] = useState<Date>(new Date());\n\n // `onValueChange` is fired explicitly per-path below (not through the hook), because commits\n // happen on blur / picker-select rather than on every keystroke.\n const [currentValue, setCurrentValue] = useControllableState<Date | null>({\n prop: value,\n defaultProp: defaultValue ?? null,\n });\n\n const canClear = allowClear && !!currentValue && !disabled && !readOnly;\n const showPicker = !disabled && !readOnly;\n\n const handleChange: ChangeEventHandler<HTMLInputElement> = (event) => {\n const newValue = event.target.value;\n setInputValue(newValue);\n onChange?.(event);\n\n const parsedDate = parseDate(newValue);\n if (parsedDate !== null || !newValue.trim()) {\n onValueChange?.(parsedDate);\n }\n };\n\n const handleFocus: FocusEventHandler<HTMLInputElement> = (event) => {\n const formatted = formatDate(currentValue, '');\n setInputValue(formatted);\n setHasFocus(true);\n onFocus?.(event);\n };\n\n const handleBlur: FocusEventHandler<HTMLInputElement> = (event) => {\n setHasFocus(false);\n onBlur?.(event);\n\n // If the field still shows the formatted current value (focused and blurred\n // without editing), keep it as-is. `formatDate` uses `toLocaleDateString`,\n // whose output is not reliably parseable by `parseDate` in every locale, so\n // round-tripping an untouched value could wrongly null it.\n const text = event.target.value;\n const parsedDate = text === formatDate(currentValue, '') ? currentValue : parseDate(text);\n onValueBlur?.(parsedDate);\n\n setCurrentValue(parsedDate);\n };\n\n const handleDatePickerChange = (newValue?: Date) => {\n const dateValue = newValue ?? null;\n\n setCurrentValue(dateValue);\n onValueChange?.(dateValue);\n\n setHasFocus(false);\n setIsOpen(false);\n };\n\n const handleClear: MouseEventHandler<HTMLButtonElement> = () => {\n if (!inputRef.current) return;\n inputRef.current.value = '';\n setInputValue('');\n setCurrentValue(null);\n onValueChange?.(null);\n onChange?.(createChangeInputEvent(inputRef.current));\n };\n\n const handleOpenChange = (open: boolean) => {\n if (open) {\n setMonth(currentValue ?? new Date());\n }\n setIsOpen(open);\n };\n\n const displayValue = hasFocus ? inputValue : formatDate(currentValue, '');\n\n return (\n <InputGroup state={state} focusVariant={focusVariant} className={className}>\n <InputGroup.Input\n {...restInputProps}\n ref={mergeRefs(ref ?? null, inputRef)}\n type=\"text\"\n value={displayValue}\n placeholder={placeholder}\n onChange={handleChange}\n onFocus={handleFocus}\n onBlur={handleBlur}\n disabled={disabled}\n readOnly={readOnly}\n />\n\n {(canClear || showPicker) && (\n <InputGroup.Addon align=\"inline-end\">\n {canClear && (\n <InputGroup.Button\n aria-label=\"Clear date\"\n onMouseDown={(event) => event.preventDefault()}\n onClick={handleClear}\n >\n <X className=\"tw:size-4\" />\n </InputGroup.Button>\n )}\n {showPicker && (\n <DatePicker\n disabled={disabledDays}\n endMonth={endMonth}\n mode=\"single\"\n month={month}\n onMonthChange={setMonth}\n onOpenChange={handleOpenChange}\n onSelect={handleDatePickerChange}\n open={isOpen}\n selected={currentValue ?? undefined}\n startMonth={startMonth}\n >\n <InputGroup.Button aria-label=\"Select Date\">\n <CalendarIcon className=\"tw:size-4\" />\n </InputGroup.Button>\n </DatePicker>\n )}\n </InputGroup.Addon>\n )}\n </InputGroup>\n );\n};\n"],"mappings":";;;;;;;;;AAAA,MAAa,cAAc,MAA+B,eAA+B;CACvF,IAAI,CAAC,MACH,OAAO;CAET,OAAO,KAAK,mBAAmB;AACjC;AAGA,MAAM,gBAAgB,IAAI,KAAK,eAAe,CAAC,CAC5C,cAAc,IAAI,KAAK,KAAM,GAAG,CAAC,CAAC,CAAC,CACnC,QACE,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AAW,uBAAuB,SAAS,OAAO,CAAC;CACrD;CAEA,MAAM,oBAAoB,SAAkB;EAC1C,IAAI,MACF,SAAS,gCAAgB,IAAI,KAAK,CAAC;EAErC,UAAU,IAAI;CAChB;CAEA,MAAM,eAAe,WAAW,aAAa,WAAW,cAAc,EAAE;CAExE,OACE,qBAAC,YAAD;EAAmB;EAAqB;EAAyB;EAAjE,UAAA,CACE,oBAAC,WAAW,OAAZ;GACE,GAAI;GACJ,KAAK,UAAU,OAAO,MAAM,QAAQ;GACpC,MAAK;GACL,OAAO;GACM;GACb,UAAU;GACV,SAAS;GACT,QAAQ;GACE;GACA;EACX,CAAA,IAEC,YAAY,eACZ,qBAAC,WAAW,OAAZ;GAAkB,OAAM;GAAxB,UAAA,CACG,YACC,oBAAC,WAAW,QAAZ;IACE,cAAW;IACX,cAAc,UAAU,MAAM,eAAe;IAC7C,SAAS;IAET,UAAA,oBAAC,GAAD,EAAG,WAAU,YAAa,CAAA;GACT,CAAA,GAEpB,cACC,oBAAC,YAAD;IACE,UAAU;IACA;IACV,MAAK;IACE;IACP,eAAe;IACf,cAAc;IACd,UAAU;IACV,MAAM;IACN,UAAU,gBAAgB,KAAA;IACd;IAEZ,UAAA,oBAAC,WAAW,QAAZ;KAAmB,cAAW;KAC5B,UAAA,oBAACA,UAAD,EAAc,WAAU,YAAa,CAAA;IACpB,CAAA;GACT,CAAA,CAEE;EAEV,CAAA,CAAA;;AAEhB"}
|
|
1
|
+
{"version":3,"file":"DateInput-CCYG0AtT.js","names":["CalendarIcon"],"sources":["../src/blocks/DateInput/helpers.ts","../src/blocks/DateInput/DateInput.tsx"],"sourcesContent":["export const formatDate = (date: Date | null | undefined, inputValue: string): string => {\n if (!date) {\n return inputValue;\n }\n return date.toLocaleDateString();\n};\n\n// Detect locale day/month/year order once, matching toLocaleDateString() output\nconst datePartOrder = new Intl.DateTimeFormat()\n .formatToParts(new Date(2000, 0, 2))\n .filter(\n (p): p is { type: 'day' | 'month' | 'year'; value: string } =>\n p.type === 'day' || p.type === 'month' || p.type === 'year',\n )\n .map((p) => p.type);\n\nexport const parseDate = (value: string): Date | null => {\n if (!value.trim()) return null;\n\n // Try locale-aware parsing first (matches toLocaleDateString round-trip)\n const nums = value.match(/\\d+/g)?.map(Number);\n if (nums && nums.length >= 3) {\n const parts = Object.fromEntries(datePartOrder.map((type, i) => [type, nums[i]]));\n const year = parts.year;\n const month = parts.month;\n const day = parts.day;\n\n if (\n year != null &&\n month != null &&\n day != null &&\n month >= 1 &&\n month <= 12 &&\n day >= 1 &&\n day <= 31\n ) {\n const date = new Date(year, month - 1, day);\n if (date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day) {\n return date;\n }\n }\n }\n\n // Fallback: detect ISO YYYY-MM-DD and construct as local midnight to avoid UTC offset issues\n const isoMatch = value.match(/^(\\d{4})-(\\d{1,2})-(\\d{1,2})$/);\n if (isoMatch) {\n const y = Number(isoMatch[1]);\n const m = Number(isoMatch[2]) - 1;\n const d = Number(isoMatch[3]);\n const date = new Date(y, m, d);\n if (date.getFullYear() === y && date.getMonth() === m && date.getDate() === d) {\n return date;\n }\n return null;\n }\n\n const fallback = new Date(value);\n return isNaN(fallback.getTime()) ? null : fallback;\n};\n","import { useRef, useState } from 'react';\nimport type {\n ChangeEventHandler,\n ComponentProps,\n ComponentRef,\n FocusEventHandler,\n MouseEventHandler,\n} from 'react';\nimport type { Matcher } from 'react-day-picker';\n\nimport { DatePicker } from '../../components/DatePicker';\nimport { InputGroup } from '../../components/InputGroup';\nimport { useControllableState } from '../../hooks/useControllableState';\nimport { Calendar as CalendarIcon, X } from '../../icons';\nimport { createChangeInputEvent, mergeRefs } from '../../utils';\n\nimport { formatDate, parseDate } from './helpers';\n\ntype InputGroupProps = Pick<ComponentProps<typeof InputGroup>, 'focusVariant' | 'state'>;\n\ntype InputGroupInputProps = Omit<\n ComponentProps<typeof InputGroup.Input>,\n 'value' | 'defaultValue' | 'type'\n>;\n\ntype Props = InputGroupProps &\n InputGroupInputProps & {\n value?: Date | null;\n defaultValue?: Date | null;\n onValueChange?: (value: Date | null) => void;\n onValueBlur?: (value: Date | null) => void;\n allowClear?: boolean;\n disabledDays?: Matcher | Matcher[];\n endMonth?: Date;\n startMonth?: Date;\n };\n\nexport const DateInput = ({\n ref,\n\n // group props\n state,\n focusVariant,\n className,\n\n // own props\n value,\n defaultValue,\n onValueChange,\n onValueBlur,\n onChange,\n onBlur,\n onFocus,\n allowClear = false,\n disabledDays,\n endMonth,\n startMonth,\n\n // input props\n disabled,\n readOnly,\n placeholder = 'Select a date',\n ...restInputProps\n}: Props) => {\n const inputRef = useRef<ComponentRef<'input'>>(null);\n\n const [inputValue, setInputValue] = useState('');\n const [hasFocus, setHasFocus] = useState(false);\n const [isOpen, setIsOpen] = useState(false);\n const [month, setMonth] = useState<Date>(new Date());\n\n // `onValueChange` is fired explicitly per-path below (not through the hook), because commits\n // happen on blur / picker-select rather than on every keystroke.\n const [currentValue, setCurrentValue] = useControllableState<Date | null>({\n prop: value,\n defaultProp: defaultValue ?? null,\n });\n\n const canClear = allowClear && !!currentValue && !disabled && !readOnly;\n const showPicker = !disabled && !readOnly;\n\n const handleChange: ChangeEventHandler<HTMLInputElement> = (event) => {\n const newValue = event.target.value;\n setInputValue(newValue);\n onChange?.(event);\n\n const parsedDate = parseDate(newValue);\n if (parsedDate !== null || !newValue.trim()) {\n onValueChange?.(parsedDate);\n }\n };\n\n const handleFocus: FocusEventHandler<HTMLInputElement> = (event) => {\n const formatted = formatDate(currentValue, '');\n setInputValue(formatted);\n setHasFocus(true);\n onFocus?.(event);\n };\n\n const handleBlur: FocusEventHandler<HTMLInputElement> = (event) => {\n setHasFocus(false);\n onBlur?.(event);\n\n // If the field still shows the formatted current value (focused and blurred\n // without editing), keep it as-is. `formatDate` uses `toLocaleDateString`,\n // whose output is not reliably parseable by `parseDate` in every locale, so\n // round-tripping an untouched value could wrongly null it.\n const text = event.target.value;\n const parsedDate = text === formatDate(currentValue, '') ? currentValue : parseDate(text);\n onValueBlur?.(parsedDate);\n\n setCurrentValue(parsedDate);\n };\n\n const handleDatePickerChange = (newValue?: Date) => {\n const dateValue = newValue ?? null;\n\n setCurrentValue(dateValue);\n onValueChange?.(dateValue);\n\n setHasFocus(false);\n setIsOpen(false);\n };\n\n const handleClear: MouseEventHandler<HTMLButtonElement> = () => {\n if (!inputRef.current) return;\n inputRef.current.value = '';\n setInputValue('');\n setCurrentValue(null);\n onValueChange?.(null);\n onChange?.(createChangeInputEvent(inputRef.current));\n };\n\n const handleOpenChange = (open: boolean) => {\n if (open) {\n setMonth(currentValue ?? new Date());\n }\n setIsOpen(open);\n };\n\n const displayValue = hasFocus ? inputValue : formatDate(currentValue, '');\n\n return (\n <InputGroup state={state} focusVariant={focusVariant} className={className}>\n <InputGroup.Input\n {...restInputProps}\n ref={mergeRefs(ref ?? null, inputRef)}\n type=\"text\"\n value={displayValue}\n placeholder={placeholder}\n onChange={handleChange}\n onFocus={handleFocus}\n onBlur={handleBlur}\n disabled={disabled}\n readOnly={readOnly}\n />\n\n {(canClear || showPicker) && (\n <InputGroup.Addon align=\"inline-end\">\n {canClear && (\n <InputGroup.Button\n aria-label=\"Clear date\"\n onMouseDown={(event) => event.preventDefault()}\n onClick={handleClear}\n >\n <X className=\"tw:size-4\" />\n </InputGroup.Button>\n )}\n {showPicker && (\n <DatePicker\n disabled={disabledDays}\n endMonth={endMonth}\n mode=\"single\"\n month={month}\n onMonthChange={setMonth}\n onOpenChange={handleOpenChange}\n onSelect={handleDatePickerChange}\n open={isOpen}\n selected={currentValue ?? undefined}\n startMonth={startMonth}\n >\n <InputGroup.Button aria-label=\"Select Date\">\n <CalendarIcon className=\"tw:size-4\" />\n </InputGroup.Button>\n </DatePicker>\n )}\n </InputGroup.Addon>\n )}\n </InputGroup>\n );\n};\n"],"mappings":";;;;;;;;;AAAA,MAAa,cAAc,MAA+B,eAA+B;CACvF,IAAI,CAAC,MACH,OAAO;CAET,OAAO,KAAK,mBAAmB;AACjC;AAGA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,SAAS,SAAS;EACvB,SAAS,QAAQ,QAAQ;EACzB,cAAc,EAAE;EAChB,gBAAgB,IAAI;EACpB,gBAAgB,IAAI;EACpB,WAAW,uBAAuB,SAAS,OAAO,CAAC;CACrD;CAEA,MAAM,oBAAoB,SAAkB;EAC1C,IAAI,MACF,SAAS,gCAAgB,IAAI,KAAK,CAAC;EAErC,UAAU,IAAI;CAChB;CAEA,MAAM,eAAe,WAAW,aAAa,WAAW,cAAc,EAAE;CAExE,OACE,qBAAC,YAAD;EAAmB;EAAqB;EAAyB;EAAjE,UAAA,CACE,oBAAC,WAAW,OAAZ;GACE,GAAI;GACJ,KAAK,UAAU,OAAO,MAAM,QAAQ;GACpC,MAAK;GACL,OAAO;GACM;GACb,UAAU;GACV,SAAS;GACT,QAAQ;GACE;GACA;EACX,CAAA,IAEC,YAAY,eACZ,qBAAC,WAAW,OAAZ;GAAkB,OAAM;GAAxB,UAAA,CACG,YACC,oBAAC,WAAW,QAAZ;IACE,cAAW;IACX,cAAc,UAAU,MAAM,eAAe;IAC7C,SAAS;IAET,UAAA,oBAAC,GAAD,EAAG,WAAU,YAAa,CAAA;GACT,CAAA,GAEpB,cACC,oBAAC,YAAD;IACE,UAAU;IACA;IACV,MAAK;IACE;IACP,eAAe;IACf,cAAc;IACd,UAAU;IACV,MAAM;IACN,UAAU,gBAAgB,KAAA;IACd;IAEZ,UAAA,oBAAC,WAAW,QAAZ;KAAmB,cAAW;KAC5B,UAAA,oBAACA,UAAD,EAAc,WAAU,YAAa,CAAA;IACpB,CAAA;GACT,CAAA,CAEE;EAEV,CAAA,CAAA;;AAEhB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { createChangeInputEvent } from "./utils-
|
|
1
|
+
import { createChangeInputEvent } from "./utils-BxEJOnFD.js";
|
|
2
2
|
import { mergeRefs } from "./internal/utils/mergeRefs.js";
|
|
3
3
|
import { Calendar, X } from "./icons-DDR9dFSr.js";
|
|
4
|
-
import { InputGroup } from "./InputGroup-
|
|
4
|
+
import { InputGroup } from "./InputGroup-DnGP9-ZQ.js";
|
|
5
5
|
import { useControllableState } from "./useControllableState-BCvUOC6G.js";
|
|
6
6
|
import { DatePicker } from "./DatePicker-CI59gF3S.js";
|
|
7
7
|
import { useRef, useState } from "react";
|
|
@@ -128,4 +128,4 @@ const DateRangeInput = ({ ref, state, focusVariant, className, value: valueProp,
|
|
|
128
128
|
};
|
|
129
129
|
export { DateRangeInput };
|
|
130
130
|
|
|
131
|
-
//# sourceMappingURL=DateRangeInput-
|
|
131
|
+
//# sourceMappingURL=DateRangeInput-CpZK1IFp.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateRangeInput-
|
|
1
|
+
{"version":3,"file":"DateRangeInput-CpZK1IFp.js","names":["CalendarIcon"],"sources":["../src/blocks/DateRangeInput/helpers.ts","../src/blocks/DateRangeInput/DateRangeInput.tsx"],"sourcesContent":["import type { DateRange } from 'react-day-picker';\n\nexport const formatDateRange = (\n range: DateRange | null | undefined,\n inputValue: string,\n): string => {\n if (!range) {\n return inputValue;\n }\n\n const { from, to } = range;\n const fromStr = from?.toLocaleDateString();\n const toStr = to?.toLocaleDateString();\n return `${fromStr} - ${toStr}`;\n};\n\nconst ISO_DATE_ONLY = /^\\d{4}-\\d{2}-\\d{2}$/;\n\n/**\n * Parses date-only ISO (`2024-01-15`) as local time, not UTC midnight.\n *\n * - UTC midnight reads back as the previous day west of UTC.\n * - Keeps `new Date` validation; `new Date(y, m - 1, d)` would roll `2024-13-45` over.\n * - Other accepted formats already parse as local time.\n */\nconst parseLocalDate = (value: string): Date =>\n ISO_DATE_ONLY.test(value) ? new Date(`${value}T00:00:00`) : new Date(value);\n\nexport const parseDateRange = (value: string): DateRange | null => {\n const parts = value.split(' - ');\n if (parts.length !== 2) {\n return null;\n }\n\n const [fromPart, toPart] = parts;\n if (!fromPart || !toPart) {\n return null;\n }\n\n const from = parseLocalDate(fromPart.trim());\n const to = parseLocalDate(toPart.trim());\n\n if (isNaN(from.getTime()) || isNaN(to.getTime())) {\n return null;\n }\n\n return { from, to };\n};\n","import { useRef, useState } from 'react';\nimport type { ChangeEventHandler, ComponentProps, ComponentRef, FocusEventHandler } from 'react';\nimport type { DateRange } from 'react-day-picker';\n\nimport { DatePicker } from '../../components/DatePicker';\nimport { InputGroup } from '../../components/InputGroup';\nimport { useControllableState } from '../../hooks/useControllableState';\nimport { Calendar as CalendarIcon, X } from '../../icons';\nimport { createChangeInputEvent, mergeRefs } from '../../utils';\n\nimport { formatDateRange, parseDateRange } from './helpers';\n\ntype InputGroupProps = Pick<ComponentProps<typeof InputGroup>, 'focusVariant' | 'state'>;\n\ntype InputGroupInputProps = Omit<\n ComponentProps<typeof InputGroup.Input>,\n 'value' | 'defaultValue' | 'type'\n>;\n\ntype Props = InputGroupProps &\n InputGroupInputProps & {\n value?: DateRange | null;\n defaultValue?: DateRange | null;\n onValueChange?: (value: DateRange | null) => void;\n onValueBlur?: (value: DateRange | null) => void;\n allowClear?: boolean;\n startMonth?: Date;\n endMonth?: Date;\n };\n\nexport const DateRangeInput = ({\n ref,\n\n // group props\n state,\n focusVariant,\n className,\n\n // own props\n value: valueProp,\n defaultValue,\n onValueChange,\n onValueBlur,\n onChange,\n onBlur,\n onFocus,\n allowClear = false,\n startMonth,\n endMonth,\n\n // input props\n disabled,\n readOnly,\n placeholder = 'Select a date range',\n ...restInputProps\n}: Props) => {\n const inputRef = useRef<ComponentRef<'input'>>(null);\n\n const [inputValue, setInputValue] = useState('');\n const [hasFocus, setHasFocus] = useState(false);\n const [isOpen, setIsOpen] = useState(false);\n const [month, setMonth] = useState<Date>(new Date());\n\n // `onValueChange` is fired explicitly per-path below (not through the hook), because commits\n // happen on blur / picker-select rather than on every keystroke.\n const [currentValue, setCurrentValue] = useControllableState<DateRange | null>({\n prop: valueProp,\n defaultProp: defaultValue ?? null,\n });\n\n const canClear = allowClear && !!currentValue && !disabled && !readOnly;\n const showPicker = !disabled && !readOnly;\n\n const handleChange: ChangeEventHandler<HTMLInputElement> = (event) => {\n const newValue = event.target.value;\n setInputValue(newValue);\n onChange?.(event);\n\n const parsedRange = parseDateRange(newValue);\n if (parsedRange !== null || !newValue.trim()) {\n onValueChange?.(parsedRange);\n }\n };\n\n const handleFocus: FocusEventHandler<HTMLInputElement> = (event) => {\n setInputValue(formatDateRange(currentValue, ''));\n setHasFocus(true);\n onFocus?.(event);\n };\n\n const handleBlur: FocusEventHandler<HTMLInputElement> = (event) => {\n setHasFocus(false);\n onBlur?.(event);\n\n // If the field still shows the formatted current value (focused and blurred\n // without editing), keep it as-is. `formatDateRange` uses `toLocaleDateString`,\n // whose output is not reliably parseable by `new Date(...)` in every locale, so\n // round-tripping an untouched value through `parseDateRange` could wrongly null it.\n const text = event.target.value;\n const parsedRange =\n text === formatDateRange(currentValue, '') ? currentValue : parseDateRange(text);\n onValueBlur?.(parsedRange);\n\n setCurrentValue(parsedRange);\n };\n\n const handleDatePickerChange = (newValue: DateRange | undefined) => {\n const rangeValue = newValue ?? null;\n\n setCurrentValue(rangeValue);\n onValueChange?.(rangeValue);\n\n setHasFocus(false);\n };\n\n const handleClear = () => {\n if (!inputRef.current) return;\n inputRef.current.value = '';\n setInputValue('');\n setCurrentValue(null);\n onValueChange?.(null);\n onChange?.(createChangeInputEvent(inputRef.current));\n };\n\n const handleOpenChange = (open: boolean) => {\n if (open) {\n setMonth(currentValue?.from ?? new Date());\n }\n setIsOpen(open);\n };\n\n const displayValue = hasFocus ? inputValue : formatDateRange(currentValue, '');\n\n return (\n <InputGroup state={state} focusVariant={focusVariant} className={className}>\n <InputGroup.Input\n {...restInputProps}\n ref={mergeRefs(ref ?? null, inputRef)}\n type=\"text\"\n value={displayValue}\n placeholder={placeholder}\n onChange={handleChange}\n onFocus={handleFocus}\n onBlur={handleBlur}\n disabled={disabled}\n readOnly={readOnly}\n />\n\n {(canClear || showPicker) && (\n <InputGroup.Addon align=\"inline-end\">\n {canClear && (\n <InputGroup.Button\n aria-label=\"Clear date range\"\n onMouseDown={(event) => event.preventDefault()}\n onClick={handleClear}\n >\n <X className=\"tw:size-4\" />\n </InputGroup.Button>\n )}\n {showPicker && (\n <DatePicker\n endMonth={endMonth}\n mode=\"range\"\n month={month}\n onMonthChange={setMonth}\n onOpenChange={handleOpenChange}\n onSelect={handleDatePickerChange}\n open={isOpen}\n startMonth={startMonth}\n selected={currentValue ?? undefined}\n >\n <InputGroup.Button aria-label=\"Select date range\">\n <CalendarIcon className=\"tw:size-4\" />\n </InputGroup.Button>\n </DatePicker>\n )}\n </InputGroup.Addon>\n )}\n </InputGroup>\n );\n};\n"],"mappings":";;;;;;;;;AAEA,MAAa,mBACX,OACA,eACW;CACX,IAAI,CAAC,OACH,OAAO;CAGT,MAAM,EAAE,MAAM,OAAO;CAGrB,OAAO,GAFS,MAAM,mBAAmB,EAEvB,KADJ,IAAI,mBAAmB;AAEvC;AAEA,MAAM,gBAAgB;;;;;;;;AAStB,MAAM,kBAAkB,UACtB,cAAc,KAAK,KAAK,oBAAI,IAAI,KAAK,GAAG,MAAM,UAAU,IAAI,IAAI,KAAK,KAAK;AAE5E,MAAa,kBAAkB,UAAoC;CACjE,MAAM,QAAQ,MAAM,MAAM,KAAK;CAC/B,IAAI,MAAM,WAAW,GACnB,OAAO;CAGT,MAAM,CAAC,UAAU,UAAU;CAC3B,IAAI,CAAC,YAAY,CAAC,QAChB,OAAO;CAGT,MAAM,OAAO,eAAe,SAAS,KAAK,CAAC;CAC3C,MAAM,KAAK,eAAe,OAAO,KAAK,CAAC;CAEvC,IAAI,MAAM,KAAK,QAAQ,CAAC,KAAK,MAAM,GAAG,QAAQ,CAAC,GAC7C,OAAO;CAGT,OAAO;EAAE;EAAM;CAAG;AACpB;;ACjBA,MAAa,kBAAkB,EAC7B,KAGA,OACA,cACA,WAGA,OAAO,WACP,cACA,eACA,aACA,UACA,QACA,SACA,aAAa,OACb,YACA,UAGA,UACA,UACA,cAAc,uBACd,GAAG,qBACQ;CACX,MAAM,WAAW,OAA8B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C1C,IAAI,MACF,SAAS,cAAc,wBAAQ,IAAI,KAAK,CAAC;EAE3C,UAAU,IAAI;CAChB;CAEA,MAAM,eAAe,WAAW,aAAa,gBAAgB,cAAc,EAAE;CAE7E,OACE,qBAAC,YAAD;EAAmB;EAAqB;EAAyB;EAAjE,UAAA,CACE,oBAAC,WAAW,OAAZ;GACE,GAAI;GACJ,KAAK,UAAU,OAAO,MAAM,QAAQ;GACpC,MAAK;GACL,OAAO;GACM;GACb,UAAU;GACV,SAAS;GACT,QAAQ;GACE;GACA;EACX,CAAA,IAEC,YAAY,eACZ,qBAAC,WAAW,OAAZ;GAAkB,OAAM;GAAxB,UAAA,CACG,YACC,oBAAC,WAAW,QAAZ;IACE,cAAW;IACX,cAAc,UAAU,MAAM,eAAe;IAC7C,SAAS;IAET,UAAA,oBAAC,GAAD,EAAG,WAAU,YAAa,CAAA;GACT,CAAA,GAEpB,cACC,oBAAC,YAAD;IACY;IACV,MAAK;IACE;IACP,eAAe;IACf,cAAc;IACd,UAAU;IACV,MAAM;IACM;IACZ,UAAU,gBAAgB,KAAA;IAE1B,UAAA,oBAAC,WAAW,QAAZ;KAAmB,cAAW;KAC5B,UAAA,oBAACA,UAAD,EAAc,WAAU,YAAa,CAAA;IACpB,CAAA;GACT,CAAA,CAEE;EAEV,CAAA,CAAA;;AAEhB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cn } from "./classNames-DkX30VJU.js";
|
|
2
2
|
import { ChevronDown } from "./icons-DDR9dFSr.js";
|
|
3
|
-
import { Button } from "./Button-
|
|
3
|
+
import { Button } from "./Button-BAMX1iuI.js";
|
|
4
4
|
import { Popover } from "./Popover-DhOPlWgF.js";
|
|
5
5
|
import { Calendar } from "./Calendar-lJBTETbk.js";
|
|
6
6
|
import { overlayTriggerVariants } from "./styles-BXXXosW_.js";
|
|
@@ -146,4 +146,4 @@ const DateRangePicker = ({ align = "start", alignOffset, className, defaultOpen,
|
|
|
146
146
|
DateRangePicker.displayName = "DateRangePicker";
|
|
147
147
|
export { DateRangePicker };
|
|
148
148
|
|
|
149
|
-
//# sourceMappingURL=DateRangePicker-
|
|
149
|
+
//# sourceMappingURL=DateRangePicker-B2AUKX7u.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateRangePicker-48yOB2qV.js","names":[],"sources":["../src/components/DateRangePicker/DateRangePicker.tsx"],"sourcesContent":["import { useState } from 'react';\nimport type { ReactNode } from 'react';\nimport type { DateRange as DayPickerDateRange, Matcher } from 'react-day-picker';\nimport type { PopoverContentProps, PopoverProps } from '@radix-ui/react-popover';\n\nimport { ChevronDown } from '../../icons';\nimport { cn } from '../../utils';\nimport { Button } from '../Button';\nimport { Calendar } from '../Calendar';\nimport { overlayTriggerVariants } from '../OverlayTrigger/styles';\nimport { Popover } from '../Popover';\nimport { TimePicker } from '../TimePicker';\nimport { formatTime, pad, parseTime } from '../TimePicker/utils';\n\nexport type DateRange = {\n from: Date;\n to?: Date;\n};\n\nexport type DateRangePreset = {\n label: string;\n /** Omit for a `value` preset, or for a clear preset (\"All time\") that calls `onChange(undefined)`. */\n range?: DateRange;\n /** Echoed through `onPresetSelect` instead of `range` — e.g. a server-resolved token like `-7 days`. */\n value?: string;\n};\n\ntype DateRangePickerProps = {\n value: DateRange | undefined;\n onChange: (range: DateRange | undefined) => void;\n /** Replaces the trigger's whole range text, e.g. the active preset name; to restyle dates use `formatDate`. */\n label?: ReactNode;\n /** Formats each end of the range on the trigger in place of ISO; the from → to join stays. */\n formatDate?: (date: Date) => string;\n placeholder?: string;\n presets?: readonly DateRangePreset[];\n /** Called instead of `onChange` when a preset is picked, with the preset itself. */\n onPresetSelect?: (preset: DateRangePreset) => void;\n /** Adds a start/end time-of-day row; the emitted `from` / `to` then carry hours and minutes. */\n withTime?: boolean;\n /** Hold edits in a draft and emit only on Apply, so one range costs one `onChange`. */\n requireApply?: boolean;\n /** Days that cannot be picked, as a react-day-picker matcher — e.g. `{ after: new Date() }`. */\n disabledDays?: Matcher | Matcher[];\n disabled?: boolean;\n className?: string;\n} & Pick<PopoverProps, 'open' | 'onOpenChange' | 'defaultOpen'> &\n Pick<PopoverContentProps, 'align' | 'alignOffset' | 'sideOffset'>;\n\nconst timeOf = (date: Date) => formatTime(date.getHours(), date.getMinutes());\n\nconst isoDate = (date: Date) =>\n `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;\n\nconst formatRange = (\n range: DateRange | undefined,\n format: (date: Date) => string,\n): string | null => {\n if (!range?.from) return null;\n return range.to ? `${format(range.from)} → ${format(range.to)}` : format(range.from);\n};\n\nconst withHoursMinutes = (target: Date, hour: number, minute: number) => {\n const next = new Date(target);\n next.setHours(hour, minute, 0, 0);\n return next;\n};\n\nconst withTimeOf = (target: Date, source: Date) =>\n withHoursMinutes(target, source.getHours(), source.getMinutes());\n\n/** Returns `target` at `time` (\"HH:mm\"); unparseable input leaves it alone. */\nconst atTime = (target: Date, time: string) => {\n const { hour, minute } = parseTime(time);\n return hour === null || minute === null ? target : withHoursMinutes(target, hour, minute);\n};\n\ntype TimeFieldProps = {\n label: string;\n date: Date | undefined;\n onChange: (time: string) => void;\n};\n\n/** Time-of-day for one end of the range, on the same `TimePicker` the rest of the app uses. */\nconst TimeField = ({ label, date, onChange }: TimeFieldProps) => (\n <div className=\"tw:flex tw:items-center tw:gap-2 tw:text-sm\">\n <span className=\"tw:text-muted-foreground\">{label}</span>\n <TimePicker selected={date ? timeOf(date) : null} onSelect={onChange}>\n <Button variant=\"outline\" size=\"small\" disabled={!date} aria-label={`${label} time`}>\n {date ? timeOf(date) : '--:--'}\n </Button>\n </TimePicker>\n </div>\n);\n\n/** Picks a `{ from, to }` range, with optional presets, time row and Apply step; single date: `DatePicker`. */\nexport const DateRangePicker = ({\n align = 'start',\n alignOffset,\n className,\n defaultOpen,\n disabled = false,\n disabledDays,\n formatDate,\n label,\n onChange,\n onOpenChange,\n onPresetSelect,\n open,\n placeholder = 'Pick a date range',\n presets,\n requireApply = false,\n sideOffset,\n value,\n withTime = false,\n}: DateRangePickerProps) => {\n const [draft, setDraft] = useState<DateRange | undefined>(value);\n\n const handleOpenChange = (nextOpen: boolean) => {\n // Reopening discards a cancelled draft.\n if (nextOpen) setDraft(value);\n onOpenChange?.(nextOpen);\n };\n\n const current = requireApply ? draft : value;\n\n const edit = (range: DateRange | undefined) => {\n if (requireApply) setDraft(range);\n else onChange(range);\n };\n\n const handleSelect = (range: DayPickerDateRange | undefined) => {\n if (!range?.from) {\n edit(undefined);\n return;\n }\n\n // Keeps the set time-of-day; otherwise a day click resets it to midnight.\n edit({\n from: current?.from ? withTimeOf(range.from, current.from) : range.from,\n to: range.to && current?.to ? withTimeOf(range.to, current.to) : range.to,\n });\n };\n\n const format =\n formatDate ?? ((date: Date) => (withTime ? `${isoDate(date)} ${timeOf(date)}` : isoDate(date)));\n const triggerLabel = label ?? formatRange(value, format);\n\n return (\n <Popover open={open} defaultOpen={defaultOpen} onOpenChange={handleOpenChange}>\n <Popover.Trigger disabled={disabled} className={cn(overlayTriggerVariants(), className)}>\n <span className={cn('tw:truncate', !triggerLabel && 'tw:text-muted-foreground')}>\n {triggerLabel ?? placeholder}\n </span>\n <ChevronDown className=\"tw:size-4 tw:text-muted-foreground\" />\n </Popover.Trigger>\n <Popover.Content\n align={align}\n alignOffset={alignOffset}\n sideOffset={sideOffset}\n className=\"tw:w-auto tw:p-0\"\n >\n <div className=\"tw:flex\">\n {presets && presets.length > 0 ? (\n <div className=\"tw:flex tw:flex-col tw:gap-1 tw:border-r tw:border-solid tw:border-border tw:p-2\">\n {presets.map((preset) => (\n <Popover.Close asChild key={preset.label}>\n <Button\n variant=\"invisible\"\n size=\"small\"\n className=\"tw:justify-start\"\n onClick={() =>\n onPresetSelect ? onPresetSelect(preset) : onChange(preset.range)\n }\n >\n {preset.label}\n </Button>\n </Popover.Close>\n ))}\n </div>\n ) : null}\n <Calendar\n mode=\"range\"\n selected={current}\n onSelect={handleSelect}\n numberOfMonths={2}\n defaultMonth={current?.from}\n disabled={disabledDays}\n />\n </div>\n {(withTime || requireApply) && (\n <div className=\"tw:flex tw:items-center tw:gap-3 tw:border-t tw:border-solid tw:border-border tw:p-3\">\n {withTime && (\n <>\n <TimeField\n label=\"From\"\n date={current?.from}\n onChange={(time) =>\n current?.from && edit({ ...current, from: atTime(current.from, time) })\n }\n />\n <TimeField\n label=\"To\"\n date={current?.to}\n onChange={(time) =>\n current?.to && edit({ ...current, to: atTime(current.to, time) })\n }\n />\n </>\n )}\n {requireApply && (\n <div className=\"tw:ml-auto tw:flex tw:gap-2\">\n <Popover.Close asChild>\n <Button variant=\"outline\" size=\"small\">\n Cancel\n </Button>\n </Popover.Close>\n <Popover.Close asChild>\n <Button size=\"small\" disabled={!draft?.from} onClick={() => onChange(draft)}>\n Apply\n </Button>\n </Popover.Close>\n </div>\n )}\n </div>\n )}\n </Popover.Content>\n </Popover>\n );\n};\n\nDateRangePicker.displayName = 'DateRangePicker';\n"],"mappings":";;;;;;;;;;AAiDA,MAAM,UAAU,SAAe,WAAW,KAAK,SAAS,GAAG,KAAK,WAAW,CAAC;AAE5E,MAAM,WAAW,SACf,GAAG,KAAK,YAAY,EAAE,GAAG,IAAI,KAAK,SAAS,IAAI,CAAC,EAAE,GAAG,IAAI,KAAK,QAAQ,CAAC;AAEzE,MAAM,eACJ,OACA,WACkB;CAClB,IAAI,CAAC,OAAO,MAAM,OAAO;CACzB,OAAO,MAAM,KAAK,GAAG,OAAO,MAAM,IAAI,EAAE,KAAK,OAAO,MAAM,EAAE,MAAM,OAAO,MAAM,IAAI;AACrF;AAEA,MAAM,oBAAoB,QAAc,MAAc,WAAmB;CACvE,MAAM,OAAO,IAAI,KAAK,MAAM;CAC5B,KAAK,SAAS,MAAM,QAAQ,GAAG,CAAC;CAChC,OAAO;AACT;AAEA,MAAM,cAAc,QAAc,WAChC,iBAAiB,QAAQ,OAAO,SAAS,GAAG,OAAO,WAAW,CAAC;;AAGjE,MAAM,UAAU,QAAc,SAAi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AAS,IAAI,OAAO,QAAQ,IAAI,IAAI;KAAE,CAAC;IAEnE,CAAA,CACD,EAAA,CAAA,GAEH,gBACC,qBAAC,OAAD;KAAK,WAAU;KAAf,UAAA,CACE,oBAAC,QAAQ,OAAT;MAAe,SAAA;MACb,UAAA,oBAAC,QAAD;OAAQ,SAAQ;OAAU,MAAK;OAAQ,UAAA;MAE/B,CAAA;KACK,CAAA,GACf,oBAAC,QAAQ,OAAT;MAAe,SAAA;MACb,UAAA,oBAAC,QAAD;OAAQ,MAAK;OAAQ,UAAU,CAAC,OAAO;OAAM,eAAe,SAAS,KAAK;OAAG,UAAA;MAErE,CAAA;KACK,CAAA,CACZ;IAEJ,CAAA,CAAA;GAEQ,CAAA,CAAA;EACV,CAAA,CAAA;;AAEb;AAEA,gBAAgB,cAAc"}
|
|
1
|
+
{"version":3,"file":"DateRangePicker-B2AUKX7u.js","names":[],"sources":["../src/components/DateRangePicker/DateRangePicker.tsx"],"sourcesContent":["import { useState } from 'react';\nimport type { ReactNode } from 'react';\nimport type { DateRange as DayPickerDateRange, Matcher } from 'react-day-picker';\nimport type { PopoverContentProps, PopoverProps } from '@radix-ui/react-popover';\n\nimport { ChevronDown } from '../../icons';\nimport { cn } from '../../utils';\nimport { Button } from '../Button';\nimport { Calendar } from '../Calendar';\nimport { overlayTriggerVariants } from '../OverlayTrigger/styles';\nimport { Popover } from '../Popover';\nimport { TimePicker } from '../TimePicker';\nimport { formatTime, pad, parseTime } from '../TimePicker/utils';\n\nexport type DateRange = {\n from: Date;\n to?: Date;\n};\n\nexport type DateRangePreset = {\n label: string;\n /** Omit for a `value` preset, or for a clear preset (\"All time\") that calls `onChange(undefined)`. */\n range?: DateRange;\n /** Echoed through `onPresetSelect` instead of `range` — e.g. a server-resolved token like `-7 days`. */\n value?: string;\n};\n\ntype DateRangePickerProps = {\n value: DateRange | undefined;\n onChange: (range: DateRange | undefined) => void;\n /** Replaces the trigger's whole range text, e.g. the active preset name; to restyle dates use `formatDate`. */\n label?: ReactNode;\n /** Formats each end of the range on the trigger in place of ISO; the from → to join stays. */\n formatDate?: (date: Date) => string;\n placeholder?: string;\n presets?: readonly DateRangePreset[];\n /** Called instead of `onChange` when a preset is picked, with the preset itself. */\n onPresetSelect?: (preset: DateRangePreset) => void;\n /** Adds a start/end time-of-day row; the emitted `from` / `to` then carry hours and minutes. */\n withTime?: boolean;\n /** Hold edits in a draft and emit only on Apply, so one range costs one `onChange`. */\n requireApply?: boolean;\n /** Days that cannot be picked, as a react-day-picker matcher — e.g. `{ after: new Date() }`. */\n disabledDays?: Matcher | Matcher[];\n disabled?: boolean;\n className?: string;\n} & Pick<PopoverProps, 'open' | 'onOpenChange' | 'defaultOpen'> &\n Pick<PopoverContentProps, 'align' | 'alignOffset' | 'sideOffset'>;\n\nconst timeOf = (date: Date) => formatTime(date.getHours(), date.getMinutes());\n\nconst isoDate = (date: Date) =>\n `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;\n\nconst formatRange = (\n range: DateRange | undefined,\n format: (date: Date) => string,\n): string | null => {\n if (!range?.from) return null;\n return range.to ? `${format(range.from)} → ${format(range.to)}` : format(range.from);\n};\n\nconst withHoursMinutes = (target: Date, hour: number, minute: number) => {\n const next = new Date(target);\n next.setHours(hour, minute, 0, 0);\n return next;\n};\n\nconst withTimeOf = (target: Date, source: Date) =>\n withHoursMinutes(target, source.getHours(), source.getMinutes());\n\n/** Returns `target` at `time` (\"HH:mm\"); unparseable input leaves it alone. */\nconst atTime = (target: Date, time: string) => {\n const { hour, minute } = parseTime(time);\n return hour === null || minute === null ? target : withHoursMinutes(target, hour, minute);\n};\n\ntype TimeFieldProps = {\n label: string;\n date: Date | undefined;\n onChange: (time: string) => void;\n};\n\n/** Time-of-day for one end of the range, on the same `TimePicker` the rest of the app uses. */\nconst TimeField = ({ label, date, onChange }: TimeFieldProps) => (\n <div className=\"tw:flex tw:items-center tw:gap-2 tw:text-sm\">\n <span className=\"tw:text-muted-foreground\">{label}</span>\n <TimePicker selected={date ? timeOf(date) : null} onSelect={onChange}>\n <Button variant=\"outline\" size=\"small\" disabled={!date} aria-label={`${label} time`}>\n {date ? timeOf(date) : '--:--'}\n </Button>\n </TimePicker>\n </div>\n);\n\n/** Picks a `{ from, to }` range, with optional presets, time row and Apply step; single date: `DatePicker`. */\nexport const DateRangePicker = ({\n align = 'start',\n alignOffset,\n className,\n defaultOpen,\n disabled = false,\n disabledDays,\n formatDate,\n label,\n onChange,\n onOpenChange,\n onPresetSelect,\n open,\n placeholder = 'Pick a date range',\n presets,\n requireApply = false,\n sideOffset,\n value,\n withTime = false,\n}: DateRangePickerProps) => {\n const [draft, setDraft] = useState<DateRange | undefined>(value);\n\n const handleOpenChange = (nextOpen: boolean) => {\n // Reopening discards a cancelled draft.\n if (nextOpen) setDraft(value);\n onOpenChange?.(nextOpen);\n };\n\n const current = requireApply ? draft : value;\n\n const edit = (range: DateRange | undefined) => {\n if (requireApply) setDraft(range);\n else onChange(range);\n };\n\n const handleSelect = (range: DayPickerDateRange | undefined) => {\n if (!range?.from) {\n edit(undefined);\n return;\n }\n\n // Keeps the set time-of-day; otherwise a day click resets it to midnight.\n edit({\n from: current?.from ? withTimeOf(range.from, current.from) : range.from,\n to: range.to && current?.to ? withTimeOf(range.to, current.to) : range.to,\n });\n };\n\n const format =\n formatDate ?? ((date: Date) => (withTime ? `${isoDate(date)} ${timeOf(date)}` : isoDate(date)));\n const triggerLabel = label ?? formatRange(value, format);\n\n return (\n <Popover open={open} defaultOpen={defaultOpen} onOpenChange={handleOpenChange}>\n <Popover.Trigger disabled={disabled} className={cn(overlayTriggerVariants(), className)}>\n <span className={cn('tw:truncate', !triggerLabel && 'tw:text-muted-foreground')}>\n {triggerLabel ?? placeholder}\n </span>\n <ChevronDown className=\"tw:size-4 tw:text-muted-foreground\" />\n </Popover.Trigger>\n <Popover.Content\n align={align}\n alignOffset={alignOffset}\n sideOffset={sideOffset}\n className=\"tw:w-auto tw:p-0\"\n >\n <div className=\"tw:flex\">\n {presets && presets.length > 0 ? (\n <div className=\"tw:flex tw:flex-col tw:gap-1 tw:border-r tw:border-solid tw:border-border tw:p-2\">\n {presets.map((preset) => (\n <Popover.Close asChild key={preset.label}>\n <Button\n variant=\"invisible\"\n size=\"small\"\n className=\"tw:justify-start\"\n onClick={() =>\n onPresetSelect ? onPresetSelect(preset) : onChange(preset.range)\n }\n >\n {preset.label}\n </Button>\n </Popover.Close>\n ))}\n </div>\n ) : null}\n <Calendar\n mode=\"range\"\n selected={current}\n onSelect={handleSelect}\n numberOfMonths={2}\n defaultMonth={current?.from}\n disabled={disabledDays}\n />\n </div>\n {(withTime || requireApply) && (\n <div className=\"tw:flex tw:items-center tw:gap-3 tw:border-t tw:border-solid tw:border-border tw:p-3\">\n {withTime && (\n <>\n <TimeField\n label=\"From\"\n date={current?.from}\n onChange={(time) =>\n current?.from && edit({ ...current, from: atTime(current.from, time) })\n }\n />\n <TimeField\n label=\"To\"\n date={current?.to}\n onChange={(time) =>\n current?.to && edit({ ...current, to: atTime(current.to, time) })\n }\n />\n </>\n )}\n {requireApply && (\n <div className=\"tw:ml-auto tw:flex tw:gap-2\">\n <Popover.Close asChild>\n <Button variant=\"outline\" size=\"small\">\n Cancel\n </Button>\n </Popover.Close>\n <Popover.Close asChild>\n <Button size=\"small\" disabled={!draft?.from} onClick={() => onChange(draft)}>\n Apply\n </Button>\n </Popover.Close>\n </div>\n )}\n </div>\n )}\n </Popover.Content>\n </Popover>\n );\n};\n\nDateRangePicker.displayName = 'DateRangePicker';\n"],"mappings":";;;;;;;;;;AAiDA,MAAM,UAAU,SAAe,WAAW,KAAK,SAAS,GAAG,KAAK,WAAW,CAAC;AAE5E,MAAM,WAAW,SACf,GAAG,KAAK,YAAY,EAAE,GAAG,IAAI,KAAK,SAAS,IAAI,CAAC,EAAE,GAAG,IAAI,KAAK,QAAQ,CAAC;AAEzE,MAAM,eACJ,OACA,WACkB;CAClB,IAAI,CAAC,OAAO,MAAM,OAAO;CACzB,OAAO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H,CAAA,IAAA,YAAY,iBACZ,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA,CACG,YACC,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,WAAD;KACE,OAAM;KACN,MAAM,SAAS;KACf,WAAW,SACT,SAAS,QAAQ,KAAK;MAAE,GAAG;MAAS,MAAM,OAAO,QAAQ,MAAM,IAAI;KAAE,CAAC;IAEzE,CAAA,GACD,oBAAC,WAAD;KACE,OAAM;KACN,MAAM,SAAS;KACf,WAAW,SACT,SAAS,MAAM,KAAK;MAAE,GAAG;MAAS,IAAI,OAAO,QAAQ,IAAI,IAAI;KAAE,CAAC;IAEnE,CAAA,CACD,EAAA,CAAA,GAEH,gBACC,qBAAC,OAAD;KAAK,WAAU;KAAf,UAAA,CACE,oBAAC,QAAQ,OAAT;MAAe,SAAA;MACb,UAAA,oBAAC,QAAD;OAAQ,SAAQ;OAAU,MAAK;OAAQ,UAAA;MAE/B,CAAA;KACK,CAAA,GACf,oBAAC,QAAQ,OAAT;MAAe,SAAA;MACb,UAAA,oBAAC,QAAD;OAAQ,MAAK;OAAQ,UAAU,CAAC,OAAO;OAAM,eAAe,SAAS,KAAK;OAAG,UAAA;MAErE,CAAA;KACK,CAAA,CACZ;IAEJ,CAAA,CAAA;GAEQ,CAAA,CAAA;EACV,CAAA,CAAA;;AAEb;AAEA,gBAAgB,cAAc"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Tooltip } from "./utils-
|
|
1
|
+
import { Tooltip } from "./utils-BxEJOnFD.js";
|
|
2
2
|
import { Info } from "./icons-DDR9dFSr.js";
|
|
3
3
|
import { Label } from "./internal/components/Label.js";
|
|
4
|
-
import { FormGroup } from "./FormGroup-
|
|
4
|
+
import { FormGroup } from "./FormGroup-D7ahkK1q.js";
|
|
5
5
|
import { useRef } from "react";
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
import { createFormHookContexts, useStore } from "@tanstack/react-form";
|
|
@@ -90,4 +90,4 @@ const FieldItem = ({ label, action, required, requiredMark = "required", labelli
|
|
|
90
90
|
};
|
|
91
91
|
export { FieldItem, fieldContext, formContext, useFieldContext, useFormContext };
|
|
92
92
|
|
|
93
|
-
//# sourceMappingURL=FieldItem-
|
|
93
|
+
//# sourceMappingURL=FieldItem-eM7IHBt5.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldItem-
|
|
1
|
+
{"version":3,"file":"FieldItem-eM7IHBt5.js","names":[],"sources":["../src/blocks/Form/contexts.ts","../src/blocks/Form/connectors/FieldItem.tsx"],"sourcesContent":["import { createFormHookContexts } from '@tanstack/react-form';\n\nexport const { fieldContext, useFieldContext, formContext, useFormContext } =\n createFormHookContexts();\n","import { type ReactNode, useRef } from 'react';\nimport { useStore } from '@tanstack/react-form';\n\nimport { Label } from '../../../components/Label';\nimport { Tooltip } from '../../../components/Tooltip';\nimport { Info } from '../../../icons';\nimport { FormGroup } from '../../FormGroup';\nimport { useFieldContext, useFormContext } from '../contexts';\n\n/** The a11y wiring `FieldItem` derives for the control — spread it onto the rendered element. */\ntype FieldControlProps = {\n id: string;\n name: string;\n 'aria-required'?: true;\n 'aria-invalid'?: true;\n 'aria-describedby'?: string;\n /** Present only under `labelling: 'aria-labelledby'` — see the prop. */\n 'aria-labelledby'?: string;\n};\n\n/** Which marker sits next to the label. Purely visual — `aria-required` is driven by `required`. */\ntype RequiredMark = 'required' | 'optional' | 'hidden';\n\n/**\n * How the control takes its accessible name from the label.\n *\n * - `'for'` (default) — `<label for>` at the control's `id`; for labelable elements (`input` etc.).\n * - `'aria-labelledby'` — the label id comes back in `control['aria-labelledby']`, no `for`. For\n * non-labelable controls (CodeMirror, Lexical, `div[role]`), which `<label for>` never names.\n */\ntype Labelling = 'for' | 'aria-labelledby';\n\ntype Props = {\n label?: ReactNode;\n /** Trailing node on the label row (e.g. a `Link`); not part of the accessible name. */\n action?: ReactNode;\n required?: boolean;\n /**\n * Gated by `required`: `'required'` shows `*` only if required, `'optional'` shows `(optional)`\n * only if not, `'hidden'` neither. Defaults to `'required'`.\n */\n requiredMark?: RequiredMark;\n /** See {@link Labelling}. Defaults to `'for'`. */\n labelling?: Labelling;\n help?: ReactNode;\n tooltip?: ReactNode;\n className?: string;\n 'aria-describedby'?: string;\n children: (control: FieldControlProps) => ReactNode;\n};\n\n/**\n * The frame props a connector re-exposes to its callers.\n *\n * - No `labelling`: the connector picks it from what its control is.\n * - Left in, it would fall into the rest spread and reach the DOM `<input>`.\n */\nexport type FieldItemProps = Omit<Props, 'children' | 'labelling'>;\n\n/**\n * Shared form-field frame: label, control, help/error text. Owns validity, ids and `aria-*` wiring,\n * so a connector only picks a control and binds its value.\n */\nexport const FieldItem = ({\n label,\n action,\n required,\n requiredMark = 'required',\n labelling = 'for',\n help,\n tooltip,\n className,\n 'aria-describedby': ariaDescribedBy,\n children,\n}: Props) => {\n const field = useFieldContext();\n const form = useFormContext();\n const { errors, isBlurred } = field.state.meta;\n const submissionAttempts = useStore(form.store, (state) => state.submissionAttempts);\n\n /**\n * The submit count as of this field's first render.\n *\n * - A bare `> 0` would flag fields mounted after a failed submit.\n * - `form.reset()` zeroes the counter, so the baseline follows it down.\n */\n const attemptsAtMountRef = useRef(submissionAttempts);\n if (submissionAttempts < attemptsAtMountRef.current)\n attemptsAtMountRef.current = submissionAttempts;\n\n /**\n * ⚠️ Blurred, not touched.\n *\n * - `setFieldValue` and `validateField` set `isTouched`, so code-filled fields would show errors.\n * - Only a real blur sets `isBlurred` — and `setServerFieldErrors`, for failures outside a submit.\n * - A submit attempt reveals every field that was on screen for it.\n */\n const isInvalid =\n (isBlurred || submissionAttempts > attemptsAtMountRef.current) && errors.length > 0;\n\n const errorId = `${field.name}-error`;\n const descriptionId = `${field.name}-description`;\n const labelId = `${field.name}-label`;\n const namesByAria = labelling === 'aria-labelledby';\n // Help and error can both apply; `undefined` when empty so the attr is omitted.\n const describedBy =\n [ariaDescribedBy, !!help && descriptionId, isInvalid && errorId].filter(Boolean).join(' ') ||\n undefined;\n\n return (\n <FormGroup className={className}>\n {(label || action) && (\n <div className=\"tw:flex tw:items-center tw:justify-between tw:gap-2\">\n <div className=\"tw:flex tw:items-center tw:gap-1\">\n {/* Marker binds to the label text; the interactive tooltip button is a sibling. */}\n {label && (\n // `htmlFor` only for labelable controls — see `Labelling`.\n <Label\n htmlFor={namesByAria ? undefined : field.name}\n id={namesByAria ? labelId : undefined}\n >\n {label}\n {requiredMark === 'required' && required && <Label.Required />}\n {requiredMark === 'optional' && !required && <Label.Optional />}\n </Label>\n )}\n\n {tooltip && (\n <Tooltip tooltip={tooltip} placement=\"top\" triggerAsChild>\n <button\n type=\"button\"\n aria-label={\n typeof label === 'string'\n ? `More information about ${label}`\n : 'More information'\n }\n className=\"tw:text-muted-foreground tw:focus:outline-hidden tw:focus-visible:text-primary tailwindcss-preflight\"\n >\n <Info className=\"tw:size-3\" />\n </button>\n </Tooltip>\n )}\n </div>\n\n {action}\n </div>\n )}\n\n {children({\n id: field.name,\n name: field.name,\n 'aria-required': required || undefined,\n 'aria-invalid': isInvalid || undefined,\n 'aria-describedby': describedBy,\n 'aria-labelledby': namesByAria && label ? labelId : undefined,\n })}\n\n {(help || isInvalid) && (\n <div>\n {help && <FormGroup.Help id={descriptionId}>{help}</FormGroup.Help>}\n {isInvalid && <FormGroup.Error id={errorId} errors={errors} />}\n </div>\n )}\n </FormGroup>\n );\n};\n"],"mappings":";;;;;;;;AAEA,MAAa,EAAE,cAAc,iBAAiB,aAAa,mBACzD,uBAAuB;;;;;;AC4DzB,MAAa,aAAa,EACxB,OACA,QACA,UACA,eAAe,YACf,YAAY,OACZ,MACA,SACA,WACA,oBAAoB,iBACpB,eACW;CACX,MAAM,QAAQ,gBAAgB;CAC9B,MAAM,OAAO,eAAe;CAC5B,MAAM,EAAE,QAAQ,cAAc,MAAM,MAAM;CAC1C,MAAM,qBAAqB,SAAS,KAAK,QAAQ,UAAU,MAAM,kBAAkB;;;;;;;CAQnF,MAAM,q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qBAAC,OAAD,EAAA,UAAA,CACG,QAAQ,oBAAC,UAAU,MAAX;IAAgB,IAAI;IAAgB,UAAA;GAAqB,CAAA,GACjE,aAAa,oBAAC,UAAU,OAAX;IAAiB,IAAI;IAAiB;GAAS,CAAA,CAC1D,EAAA,CAAA;EAEE;;AAEf"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __commonJSMin, __toESM } from "./rolldown-runtime-BrwM56v-.js";
|
|
2
2
|
import { cn } from "./classNames-DkX30VJU.js";
|
|
3
3
|
import { File, FileSpreadsheet, FileText, Upload, X } from "./icons-DDR9dFSr.js";
|
|
4
|
-
import { Button } from "./Button-
|
|
4
|
+
import { Button } from "./Button-BAMX1iuI.js";
|
|
5
5
|
import React, { Fragment, createContext, forwardRef, use, useCallback, useEffect, useImperativeHandle, useMemo, useReducer, useRef } from "react";
|
|
6
6
|
import { cva } from "class-variance-authority";
|
|
7
7
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -2499,4 +2499,4 @@ const FileUpload = Object.assign(FileUploadInner, {
|
|
|
2499
2499
|
});
|
|
2500
2500
|
export { FileUpload, useFileDropTarget, useFileUploadRejections };
|
|
2501
2501
|
|
|
2502
|
-
//# sourceMappingURL=FileUpload-
|
|
2502
|
+
//# sourceMappingURL=FileUpload-d-hNPfPV.js.map
|