@trellixio/roaster-react 2.1.1 → 2.2.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 +383 -0
- package/LICENSE.md +38 -2
- package/README.md +10 -10
- package/cjs/components/ActionList/components/ActionListDropdown.js +6 -5
- package/cjs/components/ActionList/components/ActionListDropdown.js.map +1 -1
- package/cjs/components/ActionList/components/ActionListItem.js +9 -7
- package/cjs/components/ActionList/components/ActionListItem.js.map +1 -1
- package/cjs/components/ActionList/components/ActionListSearch.js +24 -6
- package/cjs/components/ActionList/components/ActionListSearch.js.map +1 -1
- package/cjs/components/ActionList/components/ActionListSubmenu.js +7 -5
- package/cjs/components/ActionList/components/ActionListSubmenu.js.map +1 -1
- package/cjs/components/ActionList/components/ActionListSwitchItem.js +6 -5
- package/cjs/components/ActionList/components/ActionListSwitchItem.js.map +1 -1
- package/cjs/components/Alert/Alert.js +3 -2
- package/cjs/components/Alert/Alert.js.map +1 -1
- package/cjs/components/AppFrame/AppFrame.js.map +1 -1
- package/cjs/components/Avatar/Avatar.js +1 -1
- package/cjs/components/Avatar/Avatar.js.map +1 -1
- package/cjs/components/Button/Button.js +3 -2
- package/cjs/components/Button/Button.js.map +1 -1
- package/cjs/components/ButtonIcon/ButtonIcon.js.map +1 -1
- package/cjs/components/Checkbox/Checkbox.js +4 -4
- package/cjs/components/Checkbox/Checkbox.js.map +1 -1
- package/cjs/components/ColorField/ColorField.js +42 -29
- package/cjs/components/ColorField/ColorField.js.map +1 -1
- package/cjs/components/DatePicker/DatePicker.js +2 -2
- package/cjs/components/DatePicker/DatePicker.js.map +1 -1
- package/cjs/components/DatePicker/components/Calendar/Calendar.js +4 -3
- package/cjs/components/DatePicker/components/Calendar/Calendar.js.map +1 -1
- package/cjs/components/DropdownCard/components/DropdownCardDropdown.js +6 -5
- package/cjs/components/DropdownCard/components/DropdownCardDropdown.js.map +1 -1
- package/cjs/components/DropdownCard/components/DropdownCardTabs.js +3 -2
- package/cjs/components/DropdownCard/components/DropdownCardTabs.js.map +1 -1
- package/cjs/components/Field/Field.js +26 -6
- package/cjs/components/Field/Field.js.map +1 -1
- package/cjs/components/FileField/FileField.js +47 -33
- package/cjs/components/FileField/FileField.js.map +1 -1
- package/cjs/components/Icon/Icon.js.map +1 -1
- package/cjs/components/Icon/RoasterIcon.js +12 -0
- package/cjs/components/Icon/RoasterIcon.js.map +1 -0
- package/cjs/components/IconBadge/IconBadge.js.map +1 -1
- package/cjs/components/Modal/Modal.js +3 -2
- package/cjs/components/Modal/Modal.js.map +1 -1
- package/cjs/components/Pagination/Pagination.js +4 -3
- package/cjs/components/Pagination/Pagination.js.map +1 -1
- package/cjs/components/RangeField/RangeField.js +34 -21
- package/cjs/components/RangeField/RangeField.js.map +1 -1
- package/cjs/components/Select/Select.js +8 -6
- package/cjs/components/Select/Select.js.map +1 -1
- package/cjs/components/Sidebar/Sidebar.js +4 -3
- package/cjs/components/Sidebar/Sidebar.js.map +1 -1
- package/cjs/components/Sidebar/components/Back.js +7 -3
- package/cjs/components/Sidebar/components/Back.js.map +1 -1
- package/cjs/components/StatCard/StatCard.js +3 -2
- package/cjs/components/StatCard/StatCard.js.map +1 -1
- package/cjs/components/Switch/Switch.js +7 -1
- package/cjs/components/Switch/Switch.js.map +1 -1
- package/cjs/components/Table/components/TableHeadCell.js +4 -3
- package/cjs/components/Table/components/TableHeadCell.js.map +1 -1
- package/cjs/components/Tag/Tag.js +3 -2
- package/cjs/components/Tag/Tag.js.map +1 -1
- package/cjs/components/TextField/TextField.js +3 -1
- package/cjs/components/TextField/TextField.js.map +1 -1
- package/cjs/components/Textarea/Textarea.js +36 -4
- package/cjs/components/Textarea/Textarea.js.map +1 -1
- package/cjs/components/Thumbnail/Thumbnail.js +3 -2
- package/cjs/components/Thumbnail/Thumbnail.js.map +1 -1
- package/cjs/components/Toast/Toast.js +3 -2
- package/cjs/components/Toast/Toast.js.map +1 -1
- package/cjs/components/Tooltip/Tooltip.js +6 -5
- package/cjs/components/Tooltip/Tooltip.js.map +1 -1
- package/cjs/components/Tooltip/TooltipCallout.js +3 -2
- package/cjs/components/Tooltip/TooltipCallout.js.map +1 -1
- package/cjs/components/Visualizer/Visualizer.js +4 -3
- package/cjs/components/Visualizer/Visualizer.js.map +1 -1
- package/cjs/utils/Slot/index.js +5 -5
- package/cjs/utils/Slot/index.js.map +1 -1
- package/cjs/utils/useDropdown/DropdownTrigger.js +4 -4
- package/cjs/utils/useDropdown/DropdownTrigger.js.map +1 -1
- package/cjs/utils/useMergeRefs/index.js +51 -0
- package/cjs/utils/useMergeRefs/index.js.map +1 -0
- package/esm/components/ActionList/components/ActionListDropdown.js +2 -1
- package/esm/components/ActionList/components/ActionListDropdown.js.map +1 -1
- package/esm/components/ActionList/components/ActionListItem.js +5 -3
- package/esm/components/ActionList/components/ActionListItem.js.map +1 -1
- package/esm/components/ActionList/components/ActionListSearch.js +21 -3
- package/esm/components/ActionList/components/ActionListSearch.js.map +1 -1
- package/esm/components/ActionList/components/ActionListSubmenu.js +5 -3
- package/esm/components/ActionList/components/ActionListSubmenu.js.map +1 -1
- package/esm/components/ActionList/components/ActionListSwitchItem.js +2 -1
- package/esm/components/ActionList/components/ActionListSwitchItem.js.map +1 -1
- package/esm/components/Alert/Alert.js +3 -2
- package/esm/components/Alert/Alert.js.map +1 -1
- package/esm/components/AppFrame/AppFrame.js.map +1 -1
- package/esm/components/Avatar/Avatar.js +1 -1
- package/esm/components/Avatar/Avatar.js.map +1 -1
- package/esm/components/Button/Button.js +3 -2
- package/esm/components/Button/Button.js.map +1 -1
- package/esm/components/ButtonIcon/ButtonIcon.js.map +1 -1
- package/esm/components/Checkbox/Checkbox.js +1 -1
- package/esm/components/Checkbox/Checkbox.js.map +1 -1
- package/esm/components/ColorField/ColorField.js +42 -29
- package/esm/components/ColorField/ColorField.js.map +1 -1
- package/esm/components/DatePicker/DatePicker.js +1 -1
- package/esm/components/DatePicker/DatePicker.js.map +1 -1
- package/esm/components/DatePicker/components/Calendar/Calendar.js +4 -3
- package/esm/components/DatePicker/components/Calendar/Calendar.js.map +1 -1
- package/esm/components/DropdownCard/components/DropdownCardDropdown.js +2 -1
- package/esm/components/DropdownCard/components/DropdownCardDropdown.js.map +1 -1
- package/esm/components/DropdownCard/components/DropdownCardTabs.js +3 -2
- package/esm/components/DropdownCard/components/DropdownCardTabs.js.map +1 -1
- package/esm/components/Field/Field.js +26 -6
- package/esm/components/Field/Field.js.map +1 -1
- package/esm/components/FileField/FileField.js +47 -33
- package/esm/components/FileField/FileField.js.map +1 -1
- package/esm/components/Icon/Icon.js.map +1 -1
- package/esm/components/Icon/RoasterIcon.js +10 -0
- package/esm/components/Icon/RoasterIcon.js.map +1 -0
- package/esm/components/IconBadge/IconBadge.js.map +1 -1
- package/esm/components/Modal/Modal.js +3 -2
- package/esm/components/Modal/Modal.js.map +1 -1
- package/esm/components/Pagination/Pagination.js +4 -3
- package/esm/components/Pagination/Pagination.js.map +1 -1
- package/esm/components/RangeField/RangeField.js +34 -21
- package/esm/components/RangeField/RangeField.js.map +1 -1
- package/esm/components/Select/Select.js +4 -2
- package/esm/components/Select/Select.js.map +1 -1
- package/esm/components/Sidebar/Sidebar.js +4 -3
- package/esm/components/Sidebar/Sidebar.js.map +1 -1
- package/esm/components/Sidebar/components/Back.js +7 -3
- package/esm/components/Sidebar/components/Back.js.map +1 -1
- package/esm/components/StatCard/StatCard.js +3 -2
- package/esm/components/StatCard/StatCard.js.map +1 -1
- package/esm/components/Switch/Switch.js +7 -1
- package/esm/components/Switch/Switch.js.map +1 -1
- package/esm/components/Table/components/TableHeadCell.js +4 -3
- package/esm/components/Table/components/TableHeadCell.js.map +1 -1
- package/esm/components/Tag/Tag.js +3 -2
- package/esm/components/Tag/Tag.js.map +1 -1
- package/esm/components/TextField/TextField.js +3 -1
- package/esm/components/TextField/TextField.js.map +1 -1
- package/esm/components/Textarea/Textarea.js +38 -6
- package/esm/components/Textarea/Textarea.js.map +1 -1
- package/esm/components/Thumbnail/Thumbnail.js +3 -2
- package/esm/components/Thumbnail/Thumbnail.js.map +1 -1
- package/esm/components/Toast/Toast.js +3 -2
- package/esm/components/Toast/Toast.js.map +1 -1
- package/esm/components/Tooltip/Tooltip.js +2 -1
- package/esm/components/Tooltip/Tooltip.js.map +1 -1
- package/esm/components/Tooltip/TooltipCallout.js +3 -2
- package/esm/components/Tooltip/TooltipCallout.js.map +1 -1
- package/esm/components/Visualizer/Visualizer.js +4 -3
- package/esm/components/Visualizer/Visualizer.js.map +1 -1
- package/esm/package.json +4 -1
- package/esm/utils/Slot/index.js +1 -1
- package/esm/utils/Slot/index.js.map +1 -1
- package/esm/utils/useDropdown/DropdownTrigger.js +1 -1
- package/esm/utils/useDropdown/DropdownTrigger.js.map +1 -1
- package/esm/utils/useMergeRefs/index.js +36 -0
- package/esm/utils/useMergeRefs/index.js.map +1 -0
- package/lib/components/ActionList/components/ActionListItem.d.ts +4 -1
- package/lib/components/ActionList/components/ActionListItem.d.ts.map +1 -1
- package/lib/components/ActionList/components/ActionListSearch.d.ts.map +1 -1
- package/lib/components/ActionList/components/ActionListSubmenu.d.ts.map +1 -1
- package/lib/components/AppFrame/AppFrame.d.ts +5 -1
- package/lib/components/AppFrame/AppFrame.d.ts.map +1 -1
- package/lib/components/Avatar/Avatar.d.ts +4 -1
- package/lib/components/Avatar/Avatar.d.ts.map +1 -1
- package/lib/components/ButtonIcon/ButtonIcon.d.ts +1 -1
- package/lib/components/ButtonIcon/ButtonIcon.d.ts.map +1 -1
- package/lib/components/Checkbox/Checkbox.d.ts.map +1 -1
- package/lib/components/ColorField/ColorField.d.ts.map +1 -1
- package/lib/components/DatePicker/DatePicker.d.ts.map +1 -1
- package/lib/components/DatePicker/utils/index.d.ts +2 -1
- package/lib/components/DatePicker/utils/index.d.ts.map +1 -1
- package/lib/components/Field/Field.d.ts +13 -7
- package/lib/components/Field/Field.d.ts.map +1 -1
- package/lib/components/FileField/FileField.d.ts.map +1 -1
- package/lib/components/Icon/Icon.d.ts +13 -2
- package/lib/components/Icon/Icon.d.ts.map +1 -1
- package/lib/components/Icon/RoasterIcon.d.ts +13 -0
- package/lib/components/Icon/RoasterIcon.d.ts.map +1 -0
- package/lib/components/Icon/index.d.ts +2 -0
- package/lib/components/Icon/index.d.ts.map +1 -1
- package/lib/components/IconBadge/IconBadge.d.ts +2 -2
- package/lib/components/RangeField/RangeField.d.ts.map +1 -1
- package/lib/components/Select/Select.d.ts.map +1 -1
- package/lib/components/Sidebar/components/Back.d.ts.map +1 -1
- package/lib/components/Switch/Switch.d.ts.map +1 -1
- package/lib/components/TextField/TextField.d.ts.map +1 -1
- package/lib/components/Textarea/Textarea.d.ts +6 -1
- package/lib/components/Textarea/Textarea.d.ts.map +1 -1
- package/lib/components/Tooltip/Tooltip.d.ts.map +1 -1
- package/lib/utils/Slot/index.d.ts.map +1 -1
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/useDropdown/DropdownTrigger.d.ts.map +1 -1
- package/lib/utils/useMergeRefs/index.d.ts +11 -0
- package/lib/utils/useMergeRefs/index.d.ts.map +1 -0
- package/package.json +2 -2
- package/roaster.css +2 -1
- package/themes/azoth.css +1 -1
- package/themes/coffee.css +1 -1
- package/themes/scalar.css +1 -1
|
@@ -32,6 +32,7 @@ const ColorField = React__namespace.forwardRef((props, ref) => {
|
|
|
32
32
|
name,
|
|
33
33
|
disabled,
|
|
34
34
|
description,
|
|
35
|
+
keepDescription,
|
|
35
36
|
error,
|
|
36
37
|
className,
|
|
37
38
|
style,
|
|
@@ -65,35 +66,47 @@ const ColorField = React__namespace.forwardRef((props, ref) => {
|
|
|
65
66
|
const color = toFullHex(typed);
|
|
66
67
|
if (color) setInternalValue(color);
|
|
67
68
|
};
|
|
68
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
69
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
70
|
+
Field.Field,
|
|
71
|
+
{
|
|
72
|
+
controlId: uid,
|
|
73
|
+
label,
|
|
74
|
+
description,
|
|
75
|
+
keepDescription,
|
|
76
|
+
error,
|
|
77
|
+
className,
|
|
78
|
+
style,
|
|
79
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "roaster-merged-inputs", children: [
|
|
80
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "roaster-color-swatch roaster-merged-inputs__start", children: [
|
|
81
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "roaster-color-swatch__preview", style: { backgroundColor: internalValue } }),
|
|
82
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
83
|
+
"input",
|
|
84
|
+
{
|
|
85
|
+
...others,
|
|
86
|
+
...Field.fieldControlProps(uid, { description, error, keepDescription }, others),
|
|
87
|
+
ref,
|
|
88
|
+
type: "color",
|
|
89
|
+
className: "roaster-color-swatch__input",
|
|
90
|
+
name,
|
|
91
|
+
disabled,
|
|
92
|
+
onChange: handleChange,
|
|
93
|
+
value: internalValue
|
|
94
|
+
}
|
|
95
|
+
)
|
|
96
|
+
] }),
|
|
97
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
98
|
+
"input",
|
|
99
|
+
{
|
|
100
|
+
type: "text",
|
|
101
|
+
className: "roaster-input roaster-merged-inputs__end",
|
|
102
|
+
"aria-label": text.hex,
|
|
103
|
+
value: shownHex,
|
|
104
|
+
onChange: handleHexChange
|
|
105
|
+
}
|
|
106
|
+
)
|
|
107
|
+
] })
|
|
108
|
+
}
|
|
109
|
+
);
|
|
97
110
|
});
|
|
98
111
|
ColorField.displayName = "ColorField";
|
|
99
112
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorField.js","sources":["../../../../src/components/ColorField/ColorField.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useUid, useControllableState } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps } from '../Field';\n\n/** `#abc` or `#aabbcc` as `#aabbcc`; anything else as `null`. */\nfunction toFullHex(text: string) {\n if (!/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(text)) return null;\n return (text.length === 4 ? text.replace(/[0-9a-f]/gi, (digit) => digit + digit) : text).toLowerCase();\n}\n\n/** The text of the color field, for other languages. */\nexport interface ColorFieldLabels {\n /** The name of the text input that holds the hex code, read by screen readers. */\n hex: string;\n}\n\nconst defaultColorFieldLabels: ColorFieldLabels = { hex: 'Hex color code' };\n\n/**\n * Every native `<input>` prop (`name`, `required`, `aria-*`, ...) is accepted and forwarded to the color input, with the\n * ref. `className` and `style` go to the field's wrapper.\n */\nexport interface ColorFieldProps\n extends FieldBaseProps, Omit<React.ComponentPropsWithoutRef<'input'>, 'type' | 'className' | 'style'> {\n /** The HTML ID attribute to be applied to the color field input element (optional). */\n id?: string;\n /** The name attribute to be applied to the color field input element (optional). */\n name?: string;\n /** Whether the color field input should be disabled (optional). */\n disabled?: boolean;\n /** The current value of the color field input (optional). */\n value?: string;\n /** The default value of the color field input (optional). */\n defaultValue?: string;\n /** Called with the new color when the user picks or types one. The native `onChange` gets the event. */\n onValueChange?(value: string): void;\n /** The text of the field, in English by default. */\n labels?: Partial<ColorFieldLabels>;\n}\n\n/** A color picker with a text field that shows and edits the hex value. */\nexport const ColorField = React.forwardRef<HTMLInputElement, ColorFieldProps>((props, ref) => {\n const {\n id,\n label,\n name,\n disabled,\n description,\n error,\n className,\n style,\n onChange,\n onValueChange,\n value,\n defaultValue,\n labels,\n ...others\n } = props;\n const text = { ...defaultColorFieldLabels, ...labels };\n const [internalValue, setInternalValue] = useControllableState({\n value,\n defaultValue: defaultValue ?? '',\n onChange: onValueChange,\n });\n const uid = useUid(id);\n\n // The hex text as typed: the color only follows once it is a whole code (#RGB or #RRGGBB).\n const [hexText, setHexText] = React.useState(internalValue);\n React.useEffect(() => {\n setHexText((typed) => (toFullHex(typed) === internalValue.toLowerCase() ? typed : internalValue));\n }, [internalValue]);\n\n // A whole code the value doesn't hold (a controlled field the parent didn't update) gives way to the value.\n const typedColor = toFullHex(hexText);\n const shownHex = typedColor && typedColor !== internalValue.toLowerCase() ? internalValue : hexText;\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n onChange?.(event);\n setInternalValue(event.currentTarget.value);\n };\n const handleHexChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n const typed = event.currentTarget.value;\n setHexText(typed);\n const color = toFullHex(typed);\n if (color) setInternalValue(color);\n };\n\n return (\n <Field
|
|
1
|
+
{"version":3,"file":"ColorField.js","sources":["../../../../src/components/ColorField/ColorField.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useUid, useControllableState } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps } from '../Field';\n\n/** `#abc` or `#aabbcc` as `#aabbcc`; anything else as `null`. */\nfunction toFullHex(text: string) {\n if (!/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(text)) return null;\n return (text.length === 4 ? text.replace(/[0-9a-f]/gi, (digit) => digit + digit) : text).toLowerCase();\n}\n\n/** The text of the color field, for other languages. */\nexport interface ColorFieldLabels {\n /** The name of the text input that holds the hex code, read by screen readers. */\n hex: string;\n}\n\nconst defaultColorFieldLabels: ColorFieldLabels = { hex: 'Hex color code' };\n\n/**\n * Every native `<input>` prop (`name`, `required`, `aria-*`, ...) is accepted and forwarded to the color input, with the\n * ref. `className` and `style` go to the field's wrapper.\n */\nexport interface ColorFieldProps\n extends FieldBaseProps, Omit<React.ComponentPropsWithoutRef<'input'>, 'type' | 'className' | 'style'> {\n /** The HTML ID attribute to be applied to the color field input element (optional). */\n id?: string;\n /** The name attribute to be applied to the color field input element (optional). */\n name?: string;\n /** Whether the color field input should be disabled (optional). */\n disabled?: boolean;\n /** The current value of the color field input (optional). */\n value?: string;\n /** The default value of the color field input (optional). */\n defaultValue?: string;\n /** Called with the new color when the user picks or types one. The native `onChange` gets the event. */\n onValueChange?(value: string): void;\n /** The text of the field, in English by default. */\n labels?: Partial<ColorFieldLabels>;\n}\n\n/** A color picker with a text field that shows and edits the hex value. */\nexport const ColorField = React.forwardRef<HTMLInputElement, ColorFieldProps>((props, ref) => {\n const {\n id,\n label,\n name,\n disabled,\n description,\n keepDescription,\n error,\n className,\n style,\n onChange,\n onValueChange,\n value,\n defaultValue,\n labels,\n ...others\n } = props;\n const text = { ...defaultColorFieldLabels, ...labels };\n const [internalValue, setInternalValue] = useControllableState({\n value,\n defaultValue: defaultValue ?? '',\n onChange: onValueChange,\n });\n const uid = useUid(id);\n\n // The hex text as typed: the color only follows once it is a whole code (#RGB or #RRGGBB).\n const [hexText, setHexText] = React.useState(internalValue);\n React.useEffect(() => {\n setHexText((typed) => (toFullHex(typed) === internalValue.toLowerCase() ? typed : internalValue));\n }, [internalValue]);\n\n // A whole code the value doesn't hold (a controlled field the parent didn't update) gives way to the value.\n const typedColor = toFullHex(hexText);\n const shownHex = typedColor && typedColor !== internalValue.toLowerCase() ? internalValue : hexText;\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n onChange?.(event);\n setInternalValue(event.currentTarget.value);\n };\n const handleHexChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n const typed = event.currentTarget.value;\n setHexText(typed);\n const color = toFullHex(typed);\n if (color) setInternalValue(color);\n };\n\n return (\n <Field\n controlId={uid}\n label={label}\n description={description}\n keepDescription={keepDescription}\n error={error}\n className={className}\n style={style}\n >\n <div className=\"roaster-merged-inputs\">\n <span className=\"roaster-color-swatch roaster-merged-inputs__start\">\n <span className=\"roaster-color-swatch__preview\" style={{ backgroundColor: internalValue }} />\n <input\n {...others}\n {...fieldControlProps(uid, { label, description, error, keepDescription }, others)}\n ref={ref}\n type=\"color\"\n className=\"roaster-color-swatch__input\"\n name={name}\n disabled={disabled}\n onChange={handleChange}\n value={internalValue}\n />\n </span>\n <input\n type=\"text\"\n className=\"roaster-input roaster-merged-inputs__end\"\n aria-label={text.hex}\n value={shownHex}\n onChange={handleHexChange}\n />\n </div>\n </Field>\n );\n});\n\nColorField.displayName = 'ColorField';\n"],"names":["React","useControllableState","useUid","jsx","Field","jsxs","fieldControlProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAKA,SAAS,SAAS,CAAC,IAAI,EAAE;AACzB,EAAE,IAAI,CAAC,+BAA+B,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,IAAI;AAC9D,EAAE,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,KAAK,KAAK,KAAK,GAAG,KAAK,CAAC,GAAG,IAAI,EAAE,WAAW,EAAE;AACxG;AACA,MAAM,uBAAuB,GAAG,EAAE,GAAG,EAAE,gBAAgB,EAAE;AAC7C,MAAC,UAAU,GAAGA,gBAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AAC3D,EAAE,MAAM;AACR,IAAI,EAAE;AACN,IAAI,KAAK;AACT,IAAI,IAAI;AACR,IAAI,QAAQ;AACZ,IAAI,WAAW;AACf,IAAI,eAAe;AACnB,IAAI,KAAK;AACT,IAAI,SAAS;AACb,IAAI,KAAK;AACT,IAAI,QAAQ;AACZ,IAAI,aAAa;AACjB,IAAI,KAAK;AACT,IAAI,YAAY;AAChB,IAAI,MAAM;AACV,IAAI,GAAG;AACP,GAAG,GAAG,KAAK;AACX,EAAE,MAAM,IAAI,GAAG,EAAE,GAAG,uBAAuB,EAAE,GAAG,MAAM,EAAE;AACxD,EAAE,MAAM,CA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AAM,WAAW;AACjB,MAAM,eAAe;AACrB,MAAM,KAAK;AACX,MAAM,SAAS;AACf,MAAM,KAAK;AACX,MAAM,QAAQ,kBAAkBC,eAAI,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,uBAAuB,EAAE,QAAQ,EAAE;AAC5F,wBAAwBA,eAAI,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,mDAAmD,EAAE,QAAQ,EAAE;AACjH,0BAA0BF,cAAG,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,+BAA+B,EAAE,KAAK,EAAE,EAAE,eAAe,EAAE,aAAa,EAAE,EAAE,CAAC;AAChI,0BAA0BA,cAAG;AAC7B,YAAY,OAAO;AACnB,YAAY;AACZ,cAAc,GAAG,MAAM;AACvB,cAAc,GAAGG,uBAAiB,CAAC,GAAG,EAAE,EAAS,WAAW,EAAE,KAAK,EAAE,eAAe,EAAE,EAAE,MAAM,CAAC;AAC/F,cAAc,GAAG;AACjB,cAAc,IAAI,EAAE,OAAO;AAC3B,cAAc,SAAS,EAAE,6BAA6B;AACtD,cAAc,IAAI;AAClB,cAAc,QAAQ;AACtB,cAAc,QAAQ,EAAE,YAAY;AACpC,cAAc,KAAK,EAAE;AACrB;AACA;AACA,SAAS,EAAE,CAAC;AACZ,wBAAwBH,cAAG;AAC3B,UAAU,OAAO;AACjB,UAAU;AACV,YAAY,IAAI,EAAE,MAAM;AACxB,YAAY,SAAS,EAAE,0CAA0C;AACjE,YAAY,YAAY,EAAE,IAAI,CAAC,GAAG;AAClC,YAAY,KAAK,EAAE,QAAQ;AAC3B,YAAY,QAAQ,EAAE;AACtB;AACA;AACA,OAAO,EAAE;AACT;AACA,GAAG;AACH,CAAC;AACD,UAAU,CAAC,WAAW,GAAG,YAAY;;"}
|
|
@@ -7,8 +7,8 @@ var index = require('./utils/index.js');
|
|
|
7
7
|
var Calendar = require('./components/Calendar/Calendar.js');
|
|
8
8
|
var MonthGrid = require('./components/MonthGrid/MonthGrid.js');
|
|
9
9
|
var TextField = require('../TextField/TextField.js');
|
|
10
|
-
var react = require('@floating-ui/react');
|
|
11
10
|
var index$1 = require('../../utils/useControllableState/index.js');
|
|
11
|
+
var index$2 = require('../../utils/useMergeRefs/index.js');
|
|
12
12
|
|
|
13
13
|
function _interopNamespaceDefault(e) {
|
|
14
14
|
var n = Object.create(null);
|
|
@@ -67,7 +67,7 @@ const DatePickerBase = React__namespace.forwardRef(function DatePicker2(props, r
|
|
|
67
67
|
date instanceof Date ? index.formatDate(date, separator, dateFormat) : ""
|
|
68
68
|
);
|
|
69
69
|
const inputRef = React__namespace.useRef(null);
|
|
70
|
-
const mergedRef =
|
|
70
|
+
const mergedRef = index$2.useMergeRefs([inputRef, ref]);
|
|
71
71
|
const returningFocus = React__namespace.useRef(false);
|
|
72
72
|
const onFocus = () => {
|
|
73
73
|
if (returningFocus.current) returningFocus.current = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatePicker.js","sources":["../../../../src/components/DatePicker/DatePicker.tsx"],"sourcesContent":["import * as React from 'react';\nimport { dateStringParser, formatDate, getSeparatorIndex, isDateValid, pickCalendarProps } from './utils';\n\nimport { Calendar, CalendarProps } from './components';\nimport type { CalendarLabels } from './components/Calendar/Calendar';\nimport { TextField, TextFieldProps } from '../TextField';\nimport { useMergeRefs } from '@floating-ui/react';\nimport { useControllableState } from '@/utils';\nimport { MonthGrid } from './components/MonthGrid';\nimport { DateSeparator, DateFormat, DatePickerInputError } from './utils/types';\n\nexport interface DatePickerProps\n extends\n Omit<CalendarProps, 'handleDateSelection' | 'year' | 'month' | 'selected' | 'isOpen' | 'onClose'>,\n Omit<TextFieldProps, 'onChange' | 'onValueChange' | 'defaultValue' | 'value' | 'onAbort' | 'ref'> {\n /** The separator used for the date input fields. Defaults to '-' */\n separator?: DateSeparator;\n /** The format used as input mask. Defaults to 'YYYY MM DD' */\n dateFormat?: DateFormat;\n /** Callback function that will be called when an error occurs when parsing the date */\n onInputError?(type: DatePickerInputError): string;\n /** Called with the new date, or `null` when the field is cleared. */\n onValueChange?(date: Date | null): void;\n /** Default value for uncontrolled input */\n defaultValue?: Date | null;\n /** Selected date, required with controlled input */\n value?: Date | null;\n /** The month to show, from 0 to 11. 0 is January, 1 is February ... 11 is December */\n month?: number;\n /** The year to show */\n year?: number;\n /** The text of the calendar, in English by default. */\n labels?: Partial<CalendarLabels>;\n}\n\nconst DatePickerBase = React.forwardRef<HTMLInputElement, DatePickerProps>(function DatePicker(props, ref) {\n const { calendarProps, others } = pickCalendarProps(props);\n const { labels, ...inputProps } = others as typeof others & { labels?: Partial<CalendarLabels> };\n\n const {\n month,\n year,\n onValueChange,\n onInputError,\n value: passedValue,\n disableSpecificDates,\n dateFormat,\n separator,\n minDate,\n maxDate,\n defaultValue,\n onMonthChange,\n locale,\n weekStartsOn,\n } = calendarProps;\n\n const calendarRef = React.useRef<HTMLDivElement>(null);\n const [isTextFieldFocused, setIsTextFieldFocused] = React.useState(false);\n const [inputError, setInputError] = React.useState<string | boolean>(false);\n const [currentKey, setCurrentKey] = React.useState('');\n // The calendar opens on the default date's month, if there is one.\n const [{ currentDisplayedMonth, currentDisplayedYear }, setCalendarDate] = React.useState({\n currentDisplayedMonth: defaultValue ? defaultValue.getMonth() : month,\n currentDisplayedYear: defaultValue ? defaultValue.getFullYear() : year,\n });\n\n const separatorIndex = getSeparatorIndex(dateFormat);\n\n const handleMonthChange = React.useCallback(\n (targetMonth: number, targetYear: number) => {\n setCalendarDate({ currentDisplayedMonth: targetMonth, currentDisplayedYear: targetYear });\n onMonthChange?.(targetMonth, targetYear);\n },\n [onMonthChange]\n );\n\n const [date, setDate] = useControllableState<Date | null>({\n value: passedValue,\n defaultValue: defaultValue ?? null,\n onChange: onValueChange,\n });\n\n const [inputValue, setInputValue] = React.useState(\n date instanceof Date ? formatDate(date, separator, dateFormat) : ''\n );\n\n const inputRef = React.useRef<HTMLInputElement>(null);\n const mergedRef = useMergeRefs([inputRef, ref]);\n // Set while the focus goes back to the input after closing, so that focus doesn't open the calendar again.\n const returningFocus = React.useRef(false);\n const onFocus = () => {\n if (returningFocus.current) returningFocus.current = false;\n else setIsTextFieldFocused(true);\n };\n const onBlur = () => setIsTextFieldFocused(false);\n // Escape closes the calendar, and the focus goes back to the input.\n const closeToInput = React.useCallback(() => {\n setIsTextFieldFocused(false);\n // Only when the focus really moves: focusing the focused input fires no focus event to clear the flag.\n if (inputRef.current && document.activeElement !== inputRef.current) {\n returningFocus.current = true;\n inputRef.current.focus();\n }\n }, []);\n\n const handleDateSelection = React.useCallback(\n (selectedDate: Date) => {\n setInputValue(formatDate(selectedDate, separator, dateFormat));\n setDate(selectedDate);\n setCalendarDate({\n currentDisplayedMonth: selectedDate.getMonth(),\n currentDisplayedYear: selectedDate.getFullYear(),\n });\n setInputError('');\n // Chosen: the calendar closes and the focus goes back to the input.\n window.setTimeout(closeToInput, 10);\n },\n [setDate, separator, dateFormat, closeToInput]\n );\n\n // A controlled date picker shows the new value whenever the parent changes it. Compared by time, since the parent\n // may pass a new Date object for the same day on every render.\n const controlledTime = passedValue === undefined ? undefined : (passedValue?.getTime() ?? null);\n React.useEffect(() => {\n if (controlledTime === undefined) return;\n setInputValue(controlledTime === null ? '' : formatDate(new Date(controlledTime), separator, dateFormat));\n }, [controlledTime, separator, dateFormat]);\n\n function handleInputChange(value: string) {\n const valueLength = value.length;\n\n if (currentKey !== 'Backspace' && (valueLength === separatorIndex.first || valueLength === separatorIndex.second)) {\n return setInputValue(value + separator);\n }\n\n if (valueLength === 0) {\n setDate(null);\n }\n\n setInputValue(value);\n\n if (valueLength === 10) {\n const dateValue = dateStringParser(value, dateFormat, separator);\n if (!dateValue) {\n return setInputError(onInputError?.('INVALID_DATE') ?? true);\n }\n setInputError('');\n\n if (isDateValid({ date: dateValue, minDate, maxDate })) {\n return handleDateSelection(dateValue);\n }\n return setInputError(onInputError?.('OUT_OF_RANGE') ?? true);\n }\n // Still typing: the error, if any, waits for the field to lose the focus.\n setInputError('');\n }\n\n const handleInputBlur = (event: React.FocusEvent<HTMLInputElement>) => {\n others.onBlur?.(event);\n if (inputValue.length > 0 && inputValue.length < 10) setInputError(onInputError?.('INVALID_DATE') ?? true);\n };\n\n return (\n <div\n className=\"roaster-date-picker\"\n ref={calendarRef}\n // Close when the focus leaves the date picker (Tab past the calendar, or a click elsewhere).\n onBlur={(event) => {\n if (!event.currentTarget.contains(event.relatedTarget as Node | null)) onBlur();\n }}\n >\n <TextField\n {...inputProps}\n value={inputValue}\n ref={mergedRef}\n onFocus={onFocus}\n onBlur={handleInputBlur}\n maxLength={10}\n // The WAI-ARIA date picker combobox: a text input that opens a calendar dialog.\n role=\"combobox\"\n aria-haspopup=\"dialog\"\n aria-expanded={isTextFieldFocused}\n onValueChange={(value) => handleInputChange(value)}\n onKeyDown={(event) => {\n setCurrentKey(event.key);\n if (event.key === 'Escape') onBlur();\n }}\n // A typing error wins over the one the parent passes.\n error={inputError || others.error}\n />\n <Calendar\n selected={date ?? undefined}\n onClose={closeToInput}\n minDate={minDate}\n maxDate={maxDate}\n isOpen={isTextFieldFocused}\n year={currentDisplayedYear}\n month={currentDisplayedMonth}\n onMonthChange={handleMonthChange}\n handleDateSelection={handleDateSelection}\n disableSpecificDates={disableSpecificDates}\n locale={locale}\n weekStartsOn={weekStartsOn}\n labels={labels}\n />\n </div>\n );\n});\n\n/**\n * A text field with a calendar, to type or pick a date, with optional minimum and maximum dates. DatePicker.MonthGrid\n * chooses a range of whole months instead.\n */\nexport const DatePicker = Object.assign(DatePickerBase, { MonthGrid });\n"],"names":["React","pickCalendarProps","getSeparatorIndex","useControllableState","formatDate","useMergeRefs","dateStringParser","isDateValid","jsxs","jsx","TextField","Calendar","MonthGrid"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAM,cAAc,GAAGA,gBAAK,CAAC,UAAU,CAAC,SAAS,WAAW,CAAC,KAAK,EAAE,GAAG,EAAE;AACzE,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAGC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DatePicker.js","sources":["../../../../src/components/DatePicker/DatePicker.tsx"],"sourcesContent":["import * as React from 'react';\nimport { dateStringParser, formatDate, getSeparatorIndex, isDateValid, pickCalendarProps } from './utils';\n\nimport { Calendar, CalendarProps } from './components';\nimport type { CalendarLabels } from './components/Calendar/Calendar';\nimport { TextField, TextFieldProps } from '../TextField';\nimport { useControllableState, useMergeRefs } from '@/utils';\nimport { MonthGrid } from './components/MonthGrid';\nimport { DateSeparator, DateFormat, DatePickerInputError } from './utils/types';\n\nexport interface DatePickerProps\n extends\n Omit<CalendarProps, 'handleDateSelection' | 'year' | 'month' | 'selected' | 'isOpen' | 'onClose'>,\n Omit<TextFieldProps, 'onChange' | 'onValueChange' | 'defaultValue' | 'value' | 'onAbort' | 'ref'> {\n /** The separator used for the date input fields. Defaults to '-' */\n separator?: DateSeparator;\n /** The format used as input mask. Defaults to 'YYYY MM DD' */\n dateFormat?: DateFormat;\n /** Callback function that will be called when an error occurs when parsing the date */\n onInputError?(type: DatePickerInputError): string;\n /** Called with the new date, or `null` when the field is cleared. */\n onValueChange?(date: Date | null): void;\n /** Default value for uncontrolled input */\n defaultValue?: Date | null;\n /** Selected date, required with controlled input */\n value?: Date | null;\n /** The month to show, from 0 to 11. 0 is January, 1 is February ... 11 is December */\n month?: number;\n /** The year to show */\n year?: number;\n /** The text of the calendar, in English by default. */\n labels?: Partial<CalendarLabels>;\n}\n\nconst DatePickerBase = React.forwardRef<HTMLInputElement, DatePickerProps>(function DatePicker(props, ref) {\n const { calendarProps, others } = pickCalendarProps(props);\n const { labels, ...inputProps } = others as typeof others & { labels?: Partial<CalendarLabels> };\n\n const {\n month,\n year,\n onValueChange,\n onInputError,\n value: passedValue,\n disableSpecificDates,\n dateFormat,\n separator,\n minDate,\n maxDate,\n defaultValue,\n onMonthChange,\n locale,\n weekStartsOn,\n } = calendarProps;\n\n const calendarRef = React.useRef<HTMLDivElement>(null);\n const [isTextFieldFocused, setIsTextFieldFocused] = React.useState(false);\n const [inputError, setInputError] = React.useState<string | boolean>(false);\n const [currentKey, setCurrentKey] = React.useState('');\n // The calendar opens on the default date's month, if there is one.\n const [{ currentDisplayedMonth, currentDisplayedYear }, setCalendarDate] = React.useState({\n currentDisplayedMonth: defaultValue ? defaultValue.getMonth() : month,\n currentDisplayedYear: defaultValue ? defaultValue.getFullYear() : year,\n });\n\n const separatorIndex = getSeparatorIndex(dateFormat);\n\n const handleMonthChange = React.useCallback(\n (targetMonth: number, targetYear: number) => {\n setCalendarDate({ currentDisplayedMonth: targetMonth, currentDisplayedYear: targetYear });\n onMonthChange?.(targetMonth, targetYear);\n },\n [onMonthChange]\n );\n\n const [date, setDate] = useControllableState<Date | null>({\n value: passedValue,\n defaultValue: defaultValue ?? null,\n onChange: onValueChange,\n });\n\n const [inputValue, setInputValue] = React.useState(\n date instanceof Date ? formatDate(date, separator, dateFormat) : ''\n );\n\n const inputRef = React.useRef<HTMLInputElement>(null);\n const mergedRef = useMergeRefs([inputRef, ref]);\n // Set while the focus goes back to the input after closing, so that focus doesn't open the calendar again.\n const returningFocus = React.useRef(false);\n const onFocus = () => {\n if (returningFocus.current) returningFocus.current = false;\n else setIsTextFieldFocused(true);\n };\n const onBlur = () => setIsTextFieldFocused(false);\n // Escape closes the calendar, and the focus goes back to the input.\n const closeToInput = React.useCallback(() => {\n setIsTextFieldFocused(false);\n // Only when the focus really moves: focusing the focused input fires no focus event to clear the flag.\n if (inputRef.current && document.activeElement !== inputRef.current) {\n returningFocus.current = true;\n inputRef.current.focus();\n }\n }, []);\n\n const handleDateSelection = React.useCallback(\n (selectedDate: Date) => {\n setInputValue(formatDate(selectedDate, separator, dateFormat));\n setDate(selectedDate);\n setCalendarDate({\n currentDisplayedMonth: selectedDate.getMonth(),\n currentDisplayedYear: selectedDate.getFullYear(),\n });\n setInputError('');\n // Chosen: the calendar closes and the focus goes back to the input.\n window.setTimeout(closeToInput, 10);\n },\n [setDate, separator, dateFormat, closeToInput]\n );\n\n // A controlled date picker shows the new value whenever the parent changes it. Compared by time, since the parent\n // may pass a new Date object for the same day on every render.\n const controlledTime = passedValue === undefined ? undefined : (passedValue?.getTime() ?? null);\n React.useEffect(() => {\n if (controlledTime === undefined) return;\n setInputValue(controlledTime === null ? '' : formatDate(new Date(controlledTime), separator, dateFormat));\n }, [controlledTime, separator, dateFormat]);\n\n function handleInputChange(value: string) {\n const valueLength = value.length;\n\n if (currentKey !== 'Backspace' && (valueLength === separatorIndex.first || valueLength === separatorIndex.second)) {\n return setInputValue(value + separator);\n }\n\n if (valueLength === 0) {\n setDate(null);\n }\n\n setInputValue(value);\n\n if (valueLength === 10) {\n const dateValue = dateStringParser(value, dateFormat, separator);\n if (!dateValue) {\n return setInputError(onInputError?.('INVALID_DATE') ?? true);\n }\n setInputError('');\n\n if (isDateValid({ date: dateValue, minDate, maxDate })) {\n return handleDateSelection(dateValue);\n }\n return setInputError(onInputError?.('OUT_OF_RANGE') ?? true);\n }\n // Still typing: the error, if any, waits for the field to lose the focus.\n setInputError('');\n }\n\n const handleInputBlur = (event: React.FocusEvent<HTMLInputElement>) => {\n others.onBlur?.(event);\n if (inputValue.length > 0 && inputValue.length < 10) setInputError(onInputError?.('INVALID_DATE') ?? true);\n };\n\n return (\n <div\n className=\"roaster-date-picker\"\n ref={calendarRef}\n // Close when the focus leaves the date picker (Tab past the calendar, or a click elsewhere).\n onBlur={(event) => {\n if (!event.currentTarget.contains(event.relatedTarget as Node | null)) onBlur();\n }}\n >\n <TextField\n {...inputProps}\n value={inputValue}\n ref={mergedRef}\n onFocus={onFocus}\n onBlur={handleInputBlur}\n maxLength={10}\n // The WAI-ARIA date picker combobox: a text input that opens a calendar dialog.\n role=\"combobox\"\n aria-haspopup=\"dialog\"\n aria-expanded={isTextFieldFocused}\n onValueChange={(value) => handleInputChange(value)}\n onKeyDown={(event) => {\n setCurrentKey(event.key);\n if (event.key === 'Escape') onBlur();\n }}\n // A typing error wins over the one the parent passes.\n error={inputError || others.error}\n />\n <Calendar\n selected={date ?? undefined}\n onClose={closeToInput}\n minDate={minDate}\n maxDate={maxDate}\n isOpen={isTextFieldFocused}\n year={currentDisplayedYear}\n month={currentDisplayedMonth}\n onMonthChange={handleMonthChange}\n handleDateSelection={handleDateSelection}\n disableSpecificDates={disableSpecificDates}\n locale={locale}\n weekStartsOn={weekStartsOn}\n labels={labels}\n />\n </div>\n );\n});\n\n/**\n * A text field with a calendar, to type or pick a date, with optional minimum and maximum dates. DatePicker.MonthGrid\n * chooses a range of whole months instead.\n */\nexport const DatePicker = Object.assign(DatePickerBase, { MonthGrid });\n"],"names":["React","pickCalendarProps","getSeparatorIndex","useControllableState","formatDate","useMergeRefs","dateStringParser","isDateValid","jsxs","jsx","TextField","Calendar","MonthGrid"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAQA,MAAM,cAAc,GAAGA,gBAAK,CAAC,UAAU,CAAC,SAAS,WAAW,CAAC,KAAK,EAAE,GAAG,EAAE;AACzE,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAGC,uBAAiB,CAAC,KAAK,CAAC;AAC5D,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,GAAG,MAAM;AAC1C,EAAE,MAAM;AACR,IAAI,KAAK;AACT,IAAI,IAAI;AACR,IAAI,aAAa;AACjB,IAAI,YAAY;AAChB,IAAI,KAAK,EAAE,WAAW;AACtB,IAAI,oBAAoB;AACxB,IAAI,UAAU;AACd,IAAI,SAAS;AACb,IAAI,OAAO;AACX,IAAI,OAAO;AACX,IAAI,YAAY;AAChB,IAAI,aAAa;AACjB,IAAI,MAAM;AACV,IAAI;AACJ,GAAG,GAAG,aAAa;AACnB,EAAE,MAAM,WAAW,GAAGD,gBAAK,CAAC,MAAM,CAAC,IAAI,CAAC;AACxC,EAAE,MAAM,CAAC,kBAAkB,EAAE,qBAAqB,CAAC,GAAGA,gBAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;AAC3E,EAAE,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC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AE;AAClD,YAAY,CAAC;AACb,YAAY,KAAK,EAAE,UAAU,IAAI,MAAM,CAAC;AACxC;AACA,SAAS;AACT,wBAAwBD,cAAG;AAC3B,UAAUE,iBAAQ;AAClB,UAAU;AACV,YAAY,QAAQ,EAAE,IAAI,IAAI,MAAM;AACpC,YAAY,OAAO,EAAE,YAAY;AACjC,YAAY,OAAO;AACnB,YAAY,OAAO;AACnB,YAAY,MAAM,EAAE,kBAAkB;AACtC,YAAY,IAAI,EAAE,oBAAoB;AACtC,YAAY,KAAK,EAAE,qBAAqB;AACxC,YAAY,aAAa,EAAE,iBAAiB;AAC5C,YAAY,mBAAmB;AAC/B,YAAY,oBAAoB;AAChC,YAAY,MAAM;AAClB,YAAY,YAAY;AACxB,YAAY;AACZ;AACA;AACA;AACA;AACA,GAAG;AACH,CAAC,CAAC;AACU,MAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,aAAEC,mBAAS,EAAE;;"}
|
|
@@ -5,7 +5,8 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
5
5
|
var Button = require('../../../Button/Button.js');
|
|
6
6
|
var index = require('../../utils/index.js');
|
|
7
7
|
var Month = require('../Month/Month.js');
|
|
8
|
-
|
|
8
|
+
require('../../../Icon/Icon.js');
|
|
9
|
+
var RoasterIcon = require('../../../Icon/RoasterIcon.js');
|
|
9
10
|
|
|
10
11
|
const defaultCalendarLabels = {
|
|
11
12
|
calendar: "Choose a date",
|
|
@@ -46,7 +47,7 @@ function Calendar({
|
|
|
46
47
|
iconOnly: true,
|
|
47
48
|
"aria-label": text.previousMonth,
|
|
48
49
|
onClick: () => onMonthChange?.(showPreviousMonth, showPreviousYear),
|
|
49
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
50
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(RoasterIcon.RoasterIcon, { name: "arrow-left" })
|
|
50
51
|
}
|
|
51
52
|
),
|
|
52
53
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "roaster-date-picker__month", "aria-live": "polite", children: index.monthTitle(month, year, locale) }),
|
|
@@ -57,7 +58,7 @@ function Calendar({
|
|
|
57
58
|
iconOnly: true,
|
|
58
59
|
"aria-label": text.nextMonth,
|
|
59
60
|
onClick: () => onMonthChange?.(showNextMonth, showNextYear),
|
|
60
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
61
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(RoasterIcon.RoasterIcon, { name: "arrow-right" })
|
|
61
62
|
}
|
|
62
63
|
)
|
|
63
64
|
] }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Calendar.js","sources":["../../../../../../src/components/DatePicker/components/Calendar/Calendar.tsx"],"sourcesContent":["import { Button } from '@/components/Button';\nimport {\n getNextDisplayMonth,\n getNextDisplayYear,\n getPreviousDisplayMonth,\n getPreviousDisplayYear,\n monthTitle,\n type WeekStartsOn,\n noop,\n} from '../../utils';\n\nimport { Month } from '../Month';\nimport {
|
|
1
|
+
{"version":3,"file":"Calendar.js","sources":["../../../../../../src/components/DatePicker/components/Calendar/Calendar.tsx"],"sourcesContent":["import { Button } from '@/components/Button';\nimport {\n getNextDisplayMonth,\n getNextDisplayYear,\n getPreviousDisplayMonth,\n getPreviousDisplayYear,\n monthTitle,\n type WeekStartsOn,\n noop,\n} from '../../utils';\n\nimport { Month } from '../Month';\nimport { RoasterIcon } from '@/components/Icon';\n\nexport interface CalendarProps {\n /**\n * The language of the month and weekday names, as a BCP 47 tag such as `fr-FR`.\n * @defaultValue 'en-US'\n */\n locale?: string;\n /**\n * The day the week starts on: 0 is Sunday, 1 Monday ... 6 Saturday.\n * @defaultValue 0\n */\n weekStartsOn?: WeekStartsOn;\n /** Mounts Calendar if true */\n isOpen?: boolean;\n /** Callback to close the calendar. */\n onClose?(): void;\n /** The selected date */\n selected?: Date;\n /** The month to show, from 0 to 11. 0 is January, 1 is February ... 11 is December */\n month: number;\n /** The year to show */\n year: number;\n /** Disable selecting dates before this. */\n minDate?: Date;\n /** Disable selecting dates after this. */\n maxDate?: Date;\n /** Disable specific dates. */\n disableSpecificDates?: Date[];\n /** Callback when date is selected. */\n handleDateSelection?(date: Date): void;\n /** Callback when month is changed. */\n onMonthChange?(month: number, year: number): void;\n}\n\n/** The text of the calendar, for other languages. */\nexport interface CalendarLabels {\n /** The name of the calendar, read by screen readers. */\n calendar: string;\n /** The name of the previous month button. */\n previousMonth: string;\n /** The name of the next month button. */\n nextMonth: string;\n}\n\nexport const defaultCalendarLabels: CalendarLabels = {\n calendar: 'Choose a date',\n previousMonth: 'Previous month',\n nextMonth: 'Next month',\n};\n\nexport function Calendar({\n selected,\n month,\n year,\n minDate,\n maxDate,\n disableSpecificDates,\n onMonthChange,\n handleDateSelection = noop,\n isOpen = false,\n onClose,\n locale,\n weekStartsOn,\n labels,\n}: CalendarProps & { labels?: Partial<CalendarLabels> }) {\n const text = { ...defaultCalendarLabels, ...labels };\n const showNextYear = getNextDisplayYear(month, year);\n const showNextMonth = getNextDisplayMonth(month);\n\n const showPreviousYear = getPreviousDisplayYear(month, year);\n const showPreviousMonth = getPreviousDisplayMonth(month);\n\n if (!isOpen) return null;\n\n return (\n // A click in the calendar leaves the focus where it is: Safari doesn't focus a clicked button, so the click would\n // otherwise blur the input and close the calendar. Not an interaction of its own: the buttons inside are.\n // eslint-disable-next-line jsx-a11y/no-static-element-interactions\n <div className=\"roaster-date-picker__popup\" onMouseDown={(event) => event.preventDefault()}>\n <div className=\"roaster-date-picker__calendar\" role=\"dialog\" aria-label={text.calendar}>\n <div className=\"roaster-date-picker__nav\">\n <Button\n variant=\"secondary\"\n iconOnly\n aria-label={text.previousMonth}\n onClick={() => onMonthChange?.(showPreviousMonth, showPreviousYear)}\n >\n <RoasterIcon name=\"arrow-left\" />\n </Button>\n <span className=\"roaster-date-picker__month\" aria-live=\"polite\">\n {monthTitle(month, year, locale)}\n </span>\n <Button\n variant=\"secondary\"\n iconOnly\n aria-label={text.nextMonth}\n onClick={() => onMonthChange?.(showNextMonth, showNextYear)}\n >\n <RoasterIcon name=\"arrow-right\" />\n </Button>\n </div>\n <Month\n month={month}\n year={year}\n selected={selected}\n onChange={handleDateSelection}\n onMonthChange={onMonthChange}\n onEscape={onClose}\n minDate={minDate}\n maxDate={maxDate}\n disableSpecificDates={disableSpecificDates}\n locale={locale}\n weekStartsOn={weekStartsOn}\n />\n </div>\n </div>\n );\n}\n"],"names":["noop","getNextDisplayYear","getNextDisplayMonth","getPreviousDisplayYear","getPreviousDisplayMonth","jsx","jsxs","Button","RoasterIcon","monthTitle","Month"],"mappings":";;;;;;;;;;AAaY,MAAC,qBAAqB,GAAG;AACrC,EAAE,QAAQ,EAAE,eAAe;AAC3B,EAAE,aAAa,EAAE,gBAAgB;AACjC,EAAE,SAAS,EAAE;AACb;AACO,SAAS,QAAQ,CAAC;AACzB,EAAE,QAAQ;AACV,EAAE,KAAK;AACP,EAAE,IAAI;AACN,EAAE,OAAO;AACT,EAAE,OAAO;AACT,EAAE,oBAAoB;AACtB,EAAE,aAAa;AACf,EAAE,mBAAmB,GAAGA,UAAI;AAC5B,EAAE,MAAM,GAAG,KAAK;AAChB,EAAE,OAAO;AACT,EAAE,MAAM;AACR,EAAE,YAAY;AACd,EAAE;AACF,CAAC,EAAE;AACH,EAAE,MAAM,IAAI,GAAG,EAAE,GAAG,qBAAqB,EAAE,GAAG,MAAM,EAAE;AACtD,EAAE,MAAM,YAAY,GAAGC,wBAAkB,CAAC,KAAK,EAAE,IAAI,CAAC;AACtD,EAAE,MAAM,aAAa,GAAGC,yBAAmB,CAAC,KAAK,CAAC;AAClD,EAAE,MAAM,gBAAgB,GAAGC,4BAAsB,CAAC,KAAK,EAAE,IAAI,CAAC;AAC9D,EAAE,MAAM,iBAAiB,GAAGC,6BAAuB,CAAC,KAAK,CAAC;AAC1D,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,IAAI;AAC1B,EAAE;AACF;AACA;AACA;AACA,oBAAoBC,cAAG,C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AK;AACb,QAAQ;AACR,UAAU,KAAK;AACf,UAAU,IAAI;AACd,UAAU,QAAQ;AAClB,UAAU,QAAQ,EAAE,mBAAmB;AACvC,UAAU,aAAa;AACvB,UAAU,QAAQ,EAAE,OAAO;AAC3B,UAAU,OAAO;AACjB,UAAU,OAAO;AACjB,UAAU,oBAAoB;AAC9B,UAAU,MAAM;AAChB,UAAU;AACV;AACA;AACA,KAAK,EAAE,CAAC,EAAE;AACV;AACA;;;"}
|
|
@@ -5,8 +5,9 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var react = require('@floating-ui/react');
|
|
7
7
|
var DropdownCard_context = require('../DropdownCard.context.js');
|
|
8
|
-
var index = require('../../../utils/
|
|
9
|
-
var index$1 = require('../../../utils/
|
|
8
|
+
var index = require('../../../utils/useMergeRefs/index.js');
|
|
9
|
+
var index$1 = require('../../../utils/useMediaQuery/index.js');
|
|
10
|
+
var index$2 = require('../../../utils/classNames/index.js');
|
|
10
11
|
|
|
11
12
|
function _interopNamespaceDefault(e) {
|
|
12
13
|
var n = Object.create(null);
|
|
@@ -24,15 +25,15 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
24
25
|
const DropdownCardDropdown = React__namespace.forwardRef(
|
|
25
26
|
({ className, style, children, variant = "default", sheet = false, ...props }, propRef) => {
|
|
26
27
|
const { context: floatingContext, ...context } = DropdownCard_context.useDropdownCardContext();
|
|
27
|
-
const ref =
|
|
28
|
-
const asSheet = index.useMediaQuery(index.PHONE_QUERY) && sheet;
|
|
28
|
+
const ref = index.useMergeRefs([context.refs.setFloating, propRef]);
|
|
29
|
+
const asSheet = index$1.useMediaQuery(index$1.PHONE_QUERY) && sheet;
|
|
29
30
|
if (!context.open) return null;
|
|
30
31
|
return /* @__PURE__ */ jsxRuntime.jsx(react.FloatingFocusManager, { context: floatingContext, modal: false, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
31
32
|
"div",
|
|
32
33
|
{
|
|
33
34
|
ref,
|
|
34
35
|
...context.getFloatingProps(props),
|
|
35
|
-
className: index$
|
|
36
|
+
className: index$2.classNames(
|
|
36
37
|
"roaster-dropdown-card",
|
|
37
38
|
"roaster-dropdown-card--floating",
|
|
38
39
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DropdownCardDropdown.js","sources":["../../../../../src/components/DropdownCard/components/DropdownCardDropdown.tsx"],"sourcesContent":["import * as React from 'react';\nimport { FloatingFocusManager
|
|
1
|
+
{"version":3,"file":"DropdownCardDropdown.js","sources":["../../../../../src/components/DropdownCard/components/DropdownCardDropdown.tsx"],"sourcesContent":["import * as React from 'react';\nimport { FloatingFocusManager } from '@floating-ui/react';\nimport { useDropdownCardContext } from '../DropdownCard.context';\nimport { PHONE_QUERY, classNames, useMediaQuery, useMergeRefs } from '@/utils';\n\n/** Every native `<div>` prop (`aria-label`, `className`, `style`...) is accepted and forwarded to the card. */\nexport interface DropdownCardDropdownProps extends React.ComponentPropsWithoutRef<'div'> {\n /**\n * `compact`: a row or two of fields in a menu's frame, such as a sort order. `tabs`: a list of tabs beside the\n * content, with DropdownCard.Tabs.\n */\n variant?: 'default' | 'compact' | 'tabs';\n /**\n * On a phone (480px wide at most), the card rises from the window's bottom as a sheet, its full width, over the\n * dimmed page; on a wider screen it opens under its trigger as usual. Guidance: a sheet suits a large card, such as\n * filters or a date; a small one (`compact`) stays beside its trigger.\n * @defaultValue false\n */\n sheet?: boolean;\n}\n\n/**\n * The card: its content and actions. Rendered while the dropdown card is open, after its trigger, so Tab goes from one\n * to the other; fixed, so a parent's overflow doesn't cut it.\n */\nexport const DropdownCardDropdown = React.forwardRef<HTMLDivElement, DropdownCardDropdownProps>(\n ({ className, style, children, variant = 'default', sheet = false, ...props }, propRef) => {\n const { context: floatingContext, ...context } = useDropdownCardContext();\n const ref = useMergeRefs([context.refs.setFloating, propRef]);\n // A sheet on a phone is placed by the CSS, at the window's bottom, not beside its trigger.\n const asSheet = useMediaQuery(PHONE_QUERY) && sheet;\n if (!context.open) return null;\n\n return (\n <FloatingFocusManager context={floatingContext} modal={false}>\n <div\n ref={ref}\n {...context.getFloatingProps(props)}\n // After the spread, so a caller's className and style add to these instead of replacing them.\n className={classNames(\n 'roaster-dropdown-card',\n 'roaster-dropdown-card--floating',\n {\n 'roaster-dropdown-card--compact': variant === 'compact',\n 'roaster-dropdown-card--tabs': variant === 'tabs',\n 'roaster-dropdown-card--sheet': sheet,\n },\n className\n )}\n style={asSheet ? style : { ...context.floatingStyles, ...style }}\n >\n {children}\n </div>\n </FloatingFocusManager>\n );\n }\n);\n\nDropdownCardDropdown.displayName = 'DropdownCardDropdown';\n"],"names":["React","useDropdownCardContext","useMergeRefs","useMediaQuery","PHONE_QUERY","jsx","FloatingFocusManager","classNames"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAMY,MAAC,oBAAoB,GAAGA,gBAAK,CAAC,UAAU;AACpD,EAAE,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,GAAG,SAAS,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,OAAO,KAAK;AAC7F,IAAI,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,OAAO,EAAE,GAAGC,2CAAsB,EAAE;AAC7E,IAAI,MAAM,GAAG,GAAGC,kBAAY,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AACjE,IAAI,MAAM,OAAO,GAAGC,qBAAa,CAACC,mBAAW,CAAC,IAAI,KAAK;AACvD,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,IAAI;AAClC,IAAI,uBAAuBC,cAAG,CAACC,0BAAoB,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,kBAAkBD,cAAG;AAC5H,MAAM,KAAK;AACX,MAAM;AACN,QAAQ,GAAG;AACX,QAAQ,GAAG,OAAO,CAAC,gBAAgB,CAAC,KAAK,CAAC;AAC1C,QAAQ,SAAS,EAAEE,kBAAU;AAC7B,UAAU,uBAAuB;AACjC,UAAU,iCAAiC;AAC3C,UAAU;AACV,YAAY,gCAAgC,EAAE,OAAO,KAAK,SAAS;AACnE,YAAY,6BAA6B,EAAE,OAAO,KAAK,MAAM;AAC7D,YAAY,8BAA8B,EAAE;AAC5C,WAAW;AACX,UAAU;AACV,SAAS;AACT,QAAQ,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,EAAE,GAAG,OAAO,CAAC,cAAc,EAAE,GAAG,KAAK,EAAE;AACxE,QAAQ;AACR;AACA,KAAK,EAAE,CAAC;AACR,EAAE;AACF;AACA,oBAAoB,CAAC,WAAW,GAAG,sBAAsB;;"}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
5
|
var React = require('react');
|
|
6
|
-
|
|
6
|
+
require('../../Icon/Icon.js');
|
|
7
|
+
var RoasterIcon = require('../../Icon/RoasterIcon.js');
|
|
7
8
|
var index = require('../../../utils/classNames/index.js');
|
|
8
9
|
var index$1 = require('../../../utils/useControllableState/index.js');
|
|
9
10
|
var index$2 = require('../../../utils/useUid/index.js');
|
|
@@ -102,7 +103,7 @@ const DropdownCardTab = React__namespace.forwardRef(
|
|
|
102
103
|
children: [
|
|
103
104
|
icon,
|
|
104
105
|
children,
|
|
105
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
106
|
+
/* @__PURE__ */ jsxRuntime.jsx(RoasterIcon.RoasterIcon, { name: "chevron-right" })
|
|
106
107
|
]
|
|
107
108
|
}
|
|
108
109
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DropdownCardTabs.js","sources":["../../../../../src/components/DropdownCard/components/DropdownCardTabs.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, useControllableState, useUid } from '@/utils';\nimport { Icon } from '../../Icon';\n\ninterface TabsContextValue {\n value: string;\n setValue(value: string): void;\n baseId: string;\n}\n\nconst TabsContext = React.createContext<TabsContextValue | null>(null);\n\nfunction useTabsContext() {\n const context = React.useContext(TabsContext);\n if (context == null) throw new Error('DropdownCard.TabList, Tab and Panel must be wrapped in <DropdownCard.Tabs />');\n return context;\n}\n\nconst idOf = (baseId: string, part: 'tab' | 'panel', value: string) => `${baseId}-${part}-${value}`;\n\nexport interface DropdownCardTabsProps {\n /** The tab list and the panels. */\n children: React.ReactNode;\n /** The chosen tab's value, for controlled tabs. */\n value?: string;\n /** The tab chosen at first, for uncontrolled tabs. */\n defaultValue?: string;\n /** Called with the tab's value when the user chooses a tab. */\n onValueChange?(value: string): void;\n}\n\n/**\n * Tabs in a dropdown card (`variant=\"tabs\"` on DropdownCard.Dropdown): a list of tabs beside the content, one panel\n * per tab, such as one filter per tab. Compose it with DropdownCard.TabList, DropdownCard.Tab and DropdownCard.Panel.\n */\nexport function DropdownCardTabs({ children, value, defaultValue, onValueChange }: DropdownCardTabsProps) {\n const [current, setCurrent] = useControllableState({\n value,\n defaultValue: defaultValue ?? '',\n onChange: onValueChange,\n });\n const baseId = useUid();\n const context = React.useMemo(\n () => ({ value: current, setValue: setCurrent, baseId }),\n [current, setCurrent, baseId]\n );\n return <TabsContext.Provider value={context}>{children}</TabsContext.Provider>;\n}\n\n/** Every native `<div>` prop (`aria-label`, ...) is accepted and forwarded to the list. Name it with `aria-label`. */\nexport interface DropdownCardTabListProps extends React.ComponentPropsWithoutRef<'div'> {\n /** The tabs. */\n children: React.ReactNode;\n}\n\n/** The list of tabs (`role=\"tablist\"`), on the card's start side. The arrow keys, Home and End choose a tab. */\nexport const DropdownCardTabList = React.forwardRef<HTMLDivElement, DropdownCardTabListProps>(\n ({ className, children, onKeyDown, ...rest }, ref) => {\n const { setValue } = useTabsContext();\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(event);\n const tabs = [...event.currentTarget.querySelectorAll<HTMLElement>(':scope > [role=\"tab\"]:not(:disabled)')];\n const index = tabs.indexOf(event.target as HTMLElement);\n if (index === -1) return;\n const step = ({ ArrowDown: 1, ArrowRight: 1, ArrowUp: -1, ArrowLeft: -1 } as Record<string, number>)[event.key];\n let next: HTMLElement | undefined;\n if (step) next = tabs[(index + step + tabs.length) % tabs.length];\n else if (event.key === 'Home') next = tabs[0];\n else if (event.key === 'End') next = tabs[tabs.length - 1];\n if (!next) return;\n event.preventDefault();\n setValue(next.dataset.value ?? '');\n next.focus();\n };\n return (\n // The keys come from its tabs, which take the focus.\n // eslint-disable-next-line jsx-a11y/interactive-supports-focus\n <div\n role=\"tablist\"\n aria-orientation=\"vertical\"\n {...rest}\n ref={ref}\n onKeyDown={handleKeyDown}\n className={classNames('roaster-dropdown-card__tabs', className)}\n >\n {children}\n </div>\n );\n }\n);\nDropdownCardTabList.displayName = 'DropdownCardTabList';\n\n/** Every native `<button>` prop is accepted and forwarded to the tab. */\nexport interface DropdownCardTabProps extends Omit<React.ComponentPropsWithoutRef<'button'>, 'value'> {\n /** The tab's value, which names its panel. */\n value: string;\n /** The tab's name. */\n children: React.ReactNode;\n /** An `Icon` before the name. */\n icon?: React.ReactNode;\n}\n\n/** A tab: choosing it shows its panel. The chosen tab is the list's one tab stop, with a chevron at its end. */\nexport const DropdownCardTab = React.forwardRef<HTMLButtonElement, DropdownCardTabProps>(\n ({ value, icon, children, className, onClick, type = 'button', ...rest }, ref) => {\n const context = useTabsContext();\n const selected = context.value === value;\n return (\n <button\n {...rest}\n ref={ref}\n type={type}\n role=\"tab\"\n id={idOf(context.baseId, 'tab', value)}\n aria-controls={idOf(context.baseId, 'panel', value)}\n aria-selected={selected}\n tabIndex={selected ? 0 : -1}\n data-value={value}\n onClick={(event) => {\n onClick?.(event);\n if (!event.defaultPrevented) context.setValue(value);\n }}\n className={classNames('roaster-dropdown-card__tab', className)}\n >\n {icon}\n {children}\n <Icon name=\"angle-right\" />\n </button>\n );\n }\n);\nDropdownCardTab.displayName = 'DropdownCardTab';\n\n/** Every native `<div>` prop is accepted and forwarded to the panel. */\nexport interface DropdownCardPanelProps extends React.ComponentPropsWithoutRef<'div'> {\n /** The value of the tab that shows the panel. */\n value: string;\n /** The panel's fields. It scrolls when it is taller than the card. */\n children: React.ReactNode;\n}\n\n/** The content of one tab (`role=\"tabpanel\"`), hidden while another tab is chosen. */\nexport const DropdownCardPanel = React.forwardRef<HTMLDivElement, DropdownCardPanelProps>(\n ({ value, className, children, ...rest }, ref) => {\n const context = useTabsContext();\n return (\n <div\n {...rest}\n ref={ref}\n role=\"tabpanel\"\n id={idOf(context.baseId, 'panel', value)}\n aria-labelledby={idOf(context.baseId, 'tab', value)}\n hidden={context.value !== value}\n className={classNames('roaster-dropdown-card__content', className)}\n >\n {children}\n </div>\n );\n }\n);\nDropdownCardPanel.displayName = 'DropdownCardPanel';\n"],"names":["React","useControllableState","useUid","jsx","classNames","jsxs","Icon"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAKA,MAAM,WAAW,GAAGA,gBAAK,CAAC,aAAa,CAAC,IAAI,CAAC;AAC7C,SAAS,cAAc,GAAG;AAC1B,EAAE,MAAM,OAAO,GAAGA,gBAAK,CAAC,UAAU,CAAC,WAAW,CAAC;AAC/C,EAAE,IAAI,OAAO,IAAI,IAAI,EAAE,MAAM,IAAI,KAAK,CAAC,8EAA8E,CAAC;AACtH,EAAE,OAAO,OAAO;AAChB;AACA,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AAC3D,SAAS,gBAAgB,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,EAAE;AACnF,EAAE,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAGC,4BAAoB,CAAC;AACrD,IAAI,KAAK;AACT,IAAI,YAAY,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AK,CAAC;AAC7D,QAAQ,MAAM,EAAE,OAAO,CAAC,KAAK,KAAK,KAAK;AACvC,QAAQ,SAAS,EAAEC,gBAAU,CAAC,gCAAgC,EAAE,SAAS,CAAC;AAC1E,QAAQ;AACR;AACA,KAAK;AACL,EAAE;AACF;AACA,iBAAiB,CAAC,WAAW,GAAG,mBAAmB;;;;;"}
|
|
1
|
+
{"version":3,"file":"DropdownCardTabs.js","sources":["../../../../../src/components/DropdownCard/components/DropdownCardTabs.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, useControllableState, useUid } from '@/utils';\nimport { RoasterIcon } from '../../Icon';\n\ninterface TabsContextValue {\n value: string;\n setValue(value: string): void;\n baseId: string;\n}\n\nconst TabsContext = React.createContext<TabsContextValue | null>(null);\n\nfunction useTabsContext() {\n const context = React.useContext(TabsContext);\n if (context == null) throw new Error('DropdownCard.TabList, Tab and Panel must be wrapped in <DropdownCard.Tabs />');\n return context;\n}\n\nconst idOf = (baseId: string, part: 'tab' | 'panel', value: string) => `${baseId}-${part}-${value}`;\n\nexport interface DropdownCardTabsProps {\n /** The tab list and the panels. */\n children: React.ReactNode;\n /** The chosen tab's value, for controlled tabs. */\n value?: string;\n /** The tab chosen at first, for uncontrolled tabs. */\n defaultValue?: string;\n /** Called with the tab's value when the user chooses a tab. */\n onValueChange?(value: string): void;\n}\n\n/**\n * Tabs in a dropdown card (`variant=\"tabs\"` on DropdownCard.Dropdown): a list of tabs beside the content, one panel\n * per tab, such as one filter per tab. Compose it with DropdownCard.TabList, DropdownCard.Tab and DropdownCard.Panel.\n */\nexport function DropdownCardTabs({ children, value, defaultValue, onValueChange }: DropdownCardTabsProps) {\n const [current, setCurrent] = useControllableState({\n value,\n defaultValue: defaultValue ?? '',\n onChange: onValueChange,\n });\n const baseId = useUid();\n const context = React.useMemo(\n () => ({ value: current, setValue: setCurrent, baseId }),\n [current, setCurrent, baseId]\n );\n return <TabsContext.Provider value={context}>{children}</TabsContext.Provider>;\n}\n\n/** Every native `<div>` prop (`aria-label`, ...) is accepted and forwarded to the list. Name it with `aria-label`. */\nexport interface DropdownCardTabListProps extends React.ComponentPropsWithoutRef<'div'> {\n /** The tabs. */\n children: React.ReactNode;\n}\n\n/** The list of tabs (`role=\"tablist\"`), on the card's start side. The arrow keys, Home and End choose a tab. */\nexport const DropdownCardTabList = React.forwardRef<HTMLDivElement, DropdownCardTabListProps>(\n ({ className, children, onKeyDown, ...rest }, ref) => {\n const { setValue } = useTabsContext();\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(event);\n const tabs = [...event.currentTarget.querySelectorAll<HTMLElement>(':scope > [role=\"tab\"]:not(:disabled)')];\n const index = tabs.indexOf(event.target as HTMLElement);\n if (index === -1) return;\n const step = ({ ArrowDown: 1, ArrowRight: 1, ArrowUp: -1, ArrowLeft: -1 } as Record<string, number>)[event.key];\n let next: HTMLElement | undefined;\n if (step) next = tabs[(index + step + tabs.length) % tabs.length];\n else if (event.key === 'Home') next = tabs[0];\n else if (event.key === 'End') next = tabs[tabs.length - 1];\n if (!next) return;\n event.preventDefault();\n setValue(next.dataset.value ?? '');\n next.focus();\n };\n return (\n // The keys come from its tabs, which take the focus.\n // eslint-disable-next-line jsx-a11y/interactive-supports-focus\n <div\n role=\"tablist\"\n aria-orientation=\"vertical\"\n {...rest}\n ref={ref}\n onKeyDown={handleKeyDown}\n className={classNames('roaster-dropdown-card__tabs', className)}\n >\n {children}\n </div>\n );\n }\n);\nDropdownCardTabList.displayName = 'DropdownCardTabList';\n\n/** Every native `<button>` prop is accepted and forwarded to the tab. */\nexport interface DropdownCardTabProps extends Omit<React.ComponentPropsWithoutRef<'button'>, 'value'> {\n /** The tab's value, which names its panel. */\n value: string;\n /** The tab's name. */\n children: React.ReactNode;\n /** An `Icon` before the name. */\n icon?: React.ReactNode;\n}\n\n/** A tab: choosing it shows its panel. The chosen tab is the list's one tab stop, with a chevron at its end. */\nexport const DropdownCardTab = React.forwardRef<HTMLButtonElement, DropdownCardTabProps>(\n ({ value, icon, children, className, onClick, type = 'button', ...rest }, ref) => {\n const context = useTabsContext();\n const selected = context.value === value;\n return (\n <button\n {...rest}\n ref={ref}\n type={type}\n role=\"tab\"\n id={idOf(context.baseId, 'tab', value)}\n aria-controls={idOf(context.baseId, 'panel', value)}\n aria-selected={selected}\n tabIndex={selected ? 0 : -1}\n data-value={value}\n onClick={(event) => {\n onClick?.(event);\n if (!event.defaultPrevented) context.setValue(value);\n }}\n className={classNames('roaster-dropdown-card__tab', className)}\n >\n {icon}\n {children}\n <RoasterIcon name=\"chevron-right\" />\n </button>\n );\n }\n);\nDropdownCardTab.displayName = 'DropdownCardTab';\n\n/** Every native `<div>` prop is accepted and forwarded to the panel. */\nexport interface DropdownCardPanelProps extends React.ComponentPropsWithoutRef<'div'> {\n /** The value of the tab that shows the panel. */\n value: string;\n /** The panel's fields. It scrolls when it is taller than the card. */\n children: React.ReactNode;\n}\n\n/** The content of one tab (`role=\"tabpanel\"`), hidden while another tab is chosen. */\nexport const DropdownCardPanel = React.forwardRef<HTMLDivElement, DropdownCardPanelProps>(\n ({ value, className, children, ...rest }, ref) => {\n const context = useTabsContext();\n return (\n <div\n {...rest}\n ref={ref}\n role=\"tabpanel\"\n id={idOf(context.baseId, 'panel', value)}\n aria-labelledby={idOf(context.baseId, 'tab', value)}\n hidden={context.value !== value}\n className={classNames('roaster-dropdown-card__content', className)}\n >\n {children}\n </div>\n );\n }\n);\nDropdownCardPanel.displayName = 'DropdownCardPanel';\n"],"names":["React","useControllableState","useUid","jsx","classNames","jsxs","RoasterIcon"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAKA,MAAM,WAAW,GAAGA,gBAAK,CAAC,aAAa,CAAC,IAAI,CAAC;AAC7C,SAAS,cAAc,GAAG;AAC1B,EAAE,MAAM,OAAO,GAAGA,gBAAK,CAAC,UAAU,CAAC,WAAW,CAAC;AAC/C,EAAE,IAAI,OAAO,IAAI,IAAI,EAAE,MAAM,IAAI,KA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EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,EAAE,GAAG,KAAK;AACpD,IAAI,MAAM,OAAO,GAAG,cAAc,EAAE;AACpC,IAAI,uBAAuBG,cAAG;AAC9B,MAAM,KAAK;AACX,MAAM;AACN,QAAQ,GAAG,IAAI;AACf,QAAQ,GAAG;AACX,QAAQ,IAAI,EAAE,UAAU;AACxB,QAAQ,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC;AAChD,QAAQ,iBAAiB,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC;AAC7D,QAAQ,MAAM,EAAE,OAAO,CAAC,KAAK,KAAK,KAAK;AACvC,QAAQ,SAAS,EAAEC,gBAAU,CAAC,gCAAgC,EAAE,SAAS,CAAC;AAC1E,QAAQ;AACR;AACA,KAAK;AACL,EAAE;AACF;AACA,iBAAiB,CAAC,WAAW,GAAG,mBAAmB;;;;;"}
|
|
@@ -6,19 +6,39 @@ var index = require('../../utils/classNames/index.js');
|
|
|
6
6
|
|
|
7
7
|
const hasContent = (node) => !(node == null || typeof node === "boolean" || node === "");
|
|
8
8
|
const isInvalid = (error) => error != null && error !== false && error !== "";
|
|
9
|
-
function
|
|
10
|
-
const
|
|
9
|
+
function messageIds(controlId, { description, error, keepDescription }) {
|
|
10
|
+
const showsError = hasContent(error);
|
|
11
|
+
const showsDescription = hasContent(description) && (!showsError || !!keepDescription);
|
|
12
|
+
return {
|
|
13
|
+
descriptionId: showsDescription ? `${controlId}-message` : void 0,
|
|
14
|
+
errorId: showsError ? `${controlId}-${showsDescription ? "error" : "message"}` : void 0
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function fieldControlProps(controlId, messages, ariaProps = {}) {
|
|
18
|
+
const { descriptionId, errorId } = messageIds(controlId, messages);
|
|
11
19
|
return {
|
|
12
20
|
id: controlId,
|
|
13
|
-
"aria-invalid": isInvalid(error) ? true : void 0,
|
|
14
|
-
"aria-describedby": [ariaProps["aria-describedby"],
|
|
21
|
+
"aria-invalid": isInvalid(messages.error) ? true : void 0,
|
|
22
|
+
"aria-describedby": [ariaProps["aria-describedby"], descriptionId, errorId].filter(Boolean).join(" ") || void 0
|
|
15
23
|
};
|
|
16
24
|
}
|
|
17
|
-
function Field({
|
|
25
|
+
function Field({
|
|
26
|
+
controlId,
|
|
27
|
+
label,
|
|
28
|
+
description,
|
|
29
|
+
error,
|
|
30
|
+
keepDescription,
|
|
31
|
+
inline,
|
|
32
|
+
className,
|
|
33
|
+
style,
|
|
34
|
+
children
|
|
35
|
+
}) {
|
|
36
|
+
const { descriptionId, errorId } = messageIds(controlId, { description, error, keepDescription });
|
|
18
37
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: index.classNames("roaster-field", { "roaster-field--inline": inline }, className), style, children: [
|
|
19
38
|
hasContent(label) && /* @__PURE__ */ jsxRuntime.jsx("label", { className: "roaster-field__label", htmlFor: controlId, children: label }),
|
|
20
39
|
children,
|
|
21
|
-
|
|
40
|
+
descriptionId && /* @__PURE__ */ jsxRuntime.jsx("small", { className: "roaster-field__help", id: descriptionId, children: description }),
|
|
41
|
+
errorId && /* @__PURE__ */ jsxRuntime.jsx("small", { className: "roaster-field__error", id: errorId, children: error })
|
|
22
42
|
] });
|
|
23
43
|
}
|
|
24
44
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.js","sources":["../../../../src/components/Field/Field.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames } from '@/utils';\n\n/** The props every form field shares: its label, help text and error. */\nexport interface FieldBaseProps {\n /** The label shown above the control. */\n label?: React.ReactNode;\n /** Help text shown under the control. */\n description?: React.ReactNode;\n /**\n * An error shown under the control, in place of the help text
|
|
1
|
+
{"version":3,"file":"Field.js","sources":["../../../../src/components/Field/Field.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames } from '@/utils';\n\n/** The props every form field shares: its label, help text and error. */\nexport interface FieldBaseProps {\n /** The label shown above the control. */\n label?: React.ReactNode;\n /** Help text shown under the control. */\n description?: React.ReactNode;\n /**\n * An error shown under the control, in place of the help text unless `keepDescription`. It also marks the control as\n * invalid; `true` marks it invalid without a message.\n */\n error?: React.ReactNode;\n /**\n * Keeps the help text when there is an error, which then shows under it: for help that stays useful while the value\n * is wrong, such as the format it needs. A count of the characters goes in a Textarea's `footer`.\n * @defaultValue false\n */\n keepDescription?: boolean;\n /** Classes added to the field's wrapper (the label, the control and the text under it). */\n className?: string;\n /** Styles added to the field's wrapper. */\n style?: React.CSSProperties;\n}\n\n/** A field whose control can sit on its label's row: TextField and Select. */\nexport interface InlineFieldProps {\n /** The label at the start of a row and the control at its end, at its own width, such as a setting in a menu. */\n inline?: boolean;\n}\n\nexport interface FieldProps extends FieldBaseProps, InlineFieldProps {\n /** The id of the control, which the label points at. */\n controlId: string;\n /** The control, with the props that tie it to the label and the text under it (`fieldControlProps`). */\n children: React.ReactNode;\n}\n\n/** Whether there is something to show: not nothing, not a boolean, not an empty string. */\nconst hasContent = (node: React.ReactNode) => !(node == null || typeof node === 'boolean' || node === '');\nconst isInvalid = (error: React.ReactNode) => error != null && error !== false && error !== '';\n\n/**\n * The ids of the texts under the control: the help text or the error, both with `keepDescription`. The one shown alone\n * is `<id>-message`; with both, the error is `<id>-error`.\n */\nfunction messageIds(\n controlId: string,\n { description, error, keepDescription }: Pick<FieldBaseProps, 'description' | 'error' | 'keepDescription'>\n) {\n const showsError = hasContent(error);\n const showsDescription = hasContent(description) && (!showsError || !!keepDescription);\n return {\n descriptionId: showsDescription ? `${controlId}-message` : undefined,\n errorId: showsError ? `${controlId}-${showsDescription ? 'error' : 'message'}` : undefined,\n };\n}\n\n/** The ARIA props a control may already have, which the field keeps. */\nexport interface ControlAriaProps {\n 'aria-describedby'?: string;\n}\n\n/**\n * The props that tie a control to its field: its id, `aria-invalid` when there is an error, and `aria-describedby`\n * pointing at the help text, the error, or both (after any the control already has). The label names it through `for`.\n */\nexport function fieldControlProps(\n controlId: string,\n messages: Pick<FieldBaseProps, 'label' | 'description' | 'error' | 'keepDescription'>,\n ariaProps: ControlAriaProps = {}\n) {\n const { descriptionId, errorId } = messageIds(controlId, messages);\n return {\n id: controlId,\n 'aria-invalid': isInvalid(messages.error) ? true : undefined,\n 'aria-describedby': [ariaProps['aria-describedby'], descriptionId, errorId].filter(Boolean).join(' ') || undefined,\n };\n}\n\n/**\n * The frame of a form field: the label, the control, and the help text or error under it, or both. Each field renders\n * one, and passes `fieldControlProps` to its control.\n */\nexport function Field({\n controlId,\n label,\n description,\n error,\n keepDescription,\n inline,\n className,\n style,\n children,\n}: FieldProps) {\n const { descriptionId, errorId } = messageIds(controlId, { description, error, keepDescription });\n return (\n <div className={classNames('roaster-field', { 'roaster-field--inline': inline }, className)} style={style}>\n {hasContent(label) && (\n <label className=\"roaster-field__label\" htmlFor={controlId}>\n {label}\n </label>\n )}\n {children}\n {descriptionId && (\n <small className=\"roaster-field__help\" id={descriptionId}>\n {description}\n </small>\n )}\n {errorId && (\n <small className=\"roaster-field__error\" id={errorId}>\n {error}\n </small>\n )}\n </div>\n );\n}\n"],"names":["jsxs","classNames","jsx"],"mappings":";;;;;;AAGA,MAAM,UAAU,GAAG,CAAC,IAAI,KAAK,EAAE,IAAI,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,EAAE,CAAC;AACxF,MAAM,SAAS,GAAG,CAAC,KAAK,KAAK,KAAK,IAAI,IAAI,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,EAAE;AAC7E,SAAS,UAAU,CAAC,SAAS,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,eAAe,EAAE,EAAE;AACxE,EAAE,MAAM,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC;AACtC,EAAE,MAAM,gBAAgB,GAAG,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,UAAU,IAAI,CAAC,CAAC,eAAe,CAAC;AACxF,E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