@trellixio/roaster-react 2.1.0 → 2.1.2
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/cjs/components/ActionList/components/ActionListDropdown.js +13 -5
- package/cjs/components/ActionList/components/ActionListDropdown.js.map +1 -1
- package/cjs/components/ActionList/components/ActionListItem.js +7 -6
- 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 +4 -3
- 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/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/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/DropdownCard/components/DropdownCardDropdown.js +10 -6
- package/cjs/components/DropdownCard/components/DropdownCardDropdown.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 +42 -29
- package/cjs/components/FileField/FileField.js.map +1 -1
- package/cjs/components/Modal/Modal.js +7 -1
- package/cjs/components/Modal/Modal.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 +35 -22
- package/cjs/components/Sidebar/Sidebar.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/Table.js +4 -1
- package/cjs/components/Table/Table.js.map +1 -1
- package/cjs/components/Table/components/TableCell.js +3 -1
- package/cjs/components/Table/components/TableCell.js.map +1 -1
- package/cjs/components/Table/components/TableHeadCell.js +2 -2
- package/cjs/components/Table/components/TableHeadCell.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/Tooltip/Tooltip.js +6 -5
- package/cjs/components/Tooltip/Tooltip.js.map +1 -1
- package/cjs/tokens/tokens.js +3 -0
- package/cjs/tokens/tokens.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/useMediaQuery/index.js +41 -0
- package/cjs/utils/useMediaQuery/index.js.map +1 -0
- package/cjs/utils/useMergeRefs/index.js +51 -0
- package/cjs/utils/useMergeRefs/index.js.map +1 -0
- package/esm/components/ActionList/components/ActionListDropdown.js +12 -4
- package/esm/components/ActionList/components/ActionListDropdown.js.map +1 -1
- package/esm/components/ActionList/components/ActionListItem.js +3 -2
- 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 +2 -1
- 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/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/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/DropdownCard/components/DropdownCardDropdown.js +8 -4
- package/esm/components/DropdownCard/components/DropdownCardDropdown.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 +42 -29
- package/esm/components/FileField/FileField.js.map +1 -1
- package/esm/components/Modal/Modal.js +7 -1
- package/esm/components/Modal/Modal.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 +35 -22
- package/esm/components/Sidebar/Sidebar.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/Table.js +4 -1
- package/esm/components/Table/Table.js.map +1 -1
- package/esm/components/Table/components/TableCell.js +3 -1
- package/esm/components/Table/components/TableCell.js.map +1 -1
- package/esm/components/Table/components/TableHeadCell.js +2 -2
- package/esm/components/Table/components/TableHeadCell.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/Tooltip/Tooltip.js +2 -1
- package/esm/components/Tooltip/Tooltip.js.map +1 -1
- package/esm/package.json +4 -1
- package/esm/tokens/tokens.js +3 -0
- package/esm/tokens/tokens.js.map +1 -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/useMediaQuery/index.js +25 -0
- package/esm/utils/useMediaQuery/index.js.map +1 -0
- package/esm/utils/useMergeRefs/index.js +36 -0
- package/esm/utils/useMergeRefs/index.js.map +1 -0
- package/lib/components/ActionList/ActionList.d.ts +1 -1
- package/lib/components/ActionList/components/ActionListDropdown.d.ts +10 -2
- package/lib/components/ActionList/components/ActionListDropdown.d.ts.map +1 -1
- 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/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/DropdownCard/components/DropdownCardDropdown.d.ts +7 -0
- package/lib/components/DropdownCard/components/DropdownCardDropdown.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/Modal/Modal.d.ts.map +1 -1
- package/lib/components/Modal/types/index.d.ts +6 -0
- package/lib/components/Modal/types/index.d.ts.map +1 -1
- package/lib/components/Modal/utils/reducer.d.ts +1 -0
- package/lib/components/Modal/utils/reducer.d.ts.map +1 -1
- package/lib/components/RangeField/RangeField.d.ts.map +1 -1
- package/lib/components/Select/Select.d.ts.map +1 -1
- package/lib/components/Sidebar/Sidebar.d.ts +6 -3
- package/lib/components/Sidebar/Sidebar.d.ts.map +1 -1
- package/lib/components/Switch/Switch.d.ts.map +1 -1
- package/lib/components/Table/Table.d.ts +4 -2
- package/lib/components/Table/Table.d.ts.map +1 -1
- package/lib/components/Table/Table.types.d.ts +9 -0
- package/lib/components/Table/Table.types.d.ts.map +1 -1
- package/lib/components/Table/components/TableCell.d.ts +3 -1
- package/lib/components/Table/components/TableCell.d.ts.map +1 -1
- package/lib/components/Table/components/TableHeadCell.d.ts +3 -1
- package/lib/components/Table/components/TableHeadCell.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/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/tokens/tokens.d.ts +3 -0
- package/lib/tokens/tokens.d.ts.map +1 -1
- package/lib/utils/Slot/index.d.ts.map +1 -1
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/useDropdown/DropdownTrigger.d.ts.map +1 -1
- package/lib/utils/useMediaQuery/index.d.ts +8 -0
- package/lib/utils/useMediaQuery/index.d.ts.map +1 -0
- package/lib/utils/useMergeRefs/index.d.ts +11 -0
- package/lib/utils/useMergeRefs/index.d.ts.map +1 -0
- package/package.json +1 -1
- package/roaster.css +1 -1
- package/themes/azoth.css +1 -1
- package/themes/coffee.css +1 -1
- package/themes/scalar.css +1 -1
|
@@ -17,6 +17,7 @@ const ColorField = React.forwardRef((props, ref) => {
|
|
|
17
17
|
name,
|
|
18
18
|
disabled,
|
|
19
19
|
description,
|
|
20
|
+
keepDescription,
|
|
20
21
|
error,
|
|
21
22
|
className,
|
|
22
23
|
style,
|
|
@@ -50,35 +51,47 @@ const ColorField = React.forwardRef((props, ref) => {
|
|
|
50
51
|
const color = toFullHex(typed);
|
|
51
52
|
if (color) setInternalValue(color);
|
|
52
53
|
};
|
|
53
|
-
return /* @__PURE__ */ jsx(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
54
|
+
return /* @__PURE__ */ jsx(
|
|
55
|
+
Field,
|
|
56
|
+
{
|
|
57
|
+
controlId: uid,
|
|
58
|
+
label,
|
|
59
|
+
description,
|
|
60
|
+
keepDescription,
|
|
61
|
+
error,
|
|
62
|
+
className,
|
|
63
|
+
style,
|
|
64
|
+
children: /* @__PURE__ */ jsxs("div", { className: "roaster-merged-inputs", children: [
|
|
65
|
+
/* @__PURE__ */ jsxs("span", { className: "roaster-color-swatch roaster-merged-inputs__start", children: [
|
|
66
|
+
/* @__PURE__ */ jsx("span", { className: "roaster-color-swatch__preview", style: { backgroundColor: internalValue } }),
|
|
67
|
+
/* @__PURE__ */ jsx(
|
|
68
|
+
"input",
|
|
69
|
+
{
|
|
70
|
+
...others,
|
|
71
|
+
...fieldControlProps(uid, { description, error, keepDescription }, others),
|
|
72
|
+
ref,
|
|
73
|
+
type: "color",
|
|
74
|
+
className: "roaster-color-swatch__input",
|
|
75
|
+
name,
|
|
76
|
+
disabled,
|
|
77
|
+
onChange: handleChange,
|
|
78
|
+
value: internalValue
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
] }),
|
|
82
|
+
/* @__PURE__ */ jsx(
|
|
83
|
+
"input",
|
|
84
|
+
{
|
|
85
|
+
type: "text",
|
|
86
|
+
className: "roaster-input roaster-merged-inputs__end",
|
|
87
|
+
"aria-label": text.hex,
|
|
88
|
+
value: shownHex,
|
|
89
|
+
onChange: handleHexChange
|
|
90
|
+
}
|
|
91
|
+
)
|
|
92
|
+
] })
|
|
93
|
+
}
|
|
94
|
+
);
|
|
82
95
|
});
|
|
83
96
|
ColorField.displayName = "ColorField";
|
|
84
97
|
|
|
@@ -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":[],"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,GAAG,KAAK,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;A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|
|
|
5
5
|
import { Calendar } from './components/Calendar/Calendar.js';
|
|
6
6
|
import { MonthGrid } from './components/MonthGrid/MonthGrid.js';
|
|
7
7
|
import { TextField } from '../TextField/TextField.js';
|
|
8
|
-
import { useMergeRefs } from '@floating-ui/react';
|
|
9
8
|
import { useControllableState } from '../../utils/useControllableState/index.js';
|
|
9
|
+
import { useMergeRefs } from '../../utils/useMergeRefs/index.js';
|
|
10
10
|
|
|
11
11
|
const DatePickerBase = React.forwardRef(function DatePicker2(props, ref) {
|
|
12
12
|
const { calendarProps, others } = pickCalendarProps(props);
|
|
@@ -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":[],"mappings":";;;;;;;;;;AASA,MAAM,cAAc,GAAG,KAAK,CAAC,UAAU,CAAC,SAAS,WAAW,CAAC,KAAK,EAAE,GAAG,EAAE;AACzE,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,iBAAiB,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,O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AACrC,YAAY,eAAe,EAAE,kBAAkB;AAC/C,YAAY,aAAa,EAAE,CAAC,KAAK,KAAK,iBAAiB,CAAC,KAAK,CAAC;AAC9D,YAAY,SAAS,EAAE,CAAC,KAAK,KAAK;AAClC,cAAc,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC;AACtC,cAAc,IAAI,KAAK,CAAC,GAAG,KAAK,QAAQ,EAAE,MAAM,EAAE;AAClD,YAAY,CAAC;AACb,YAAY,KAAK,EAAE,UAAU,IAAI,MAAM,CAAC;AACxC;AACA,SAAS;AACT,wBAAwB,GAAG;AAC3B,UAAU,QAAQ;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,EAAE,SAAS,EAAE;;"}
|
|
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 { 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":[],"mapp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MAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,EAAE,SAAS,EAAE;;"}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { FloatingFocusManager } from '@floating-ui/react';
|
|
5
5
|
import { useDropdownCardContext } from '../DropdownCard.context.js';
|
|
6
|
+
import { useMergeRefs } from '../../../utils/useMergeRefs/index.js';
|
|
7
|
+
import { useMediaQuery, PHONE_QUERY } from '../../../utils/useMediaQuery/index.js';
|
|
6
8
|
import { classNames } from '../../../utils/classNames/index.js';
|
|
7
9
|
|
|
8
10
|
const DropdownCardDropdown = React.forwardRef(
|
|
9
|
-
({ className, style, children, variant = "default", ...props }, propRef) => {
|
|
11
|
+
({ className, style, children, variant = "default", sheet = false, ...props }, propRef) => {
|
|
10
12
|
const { context: floatingContext, ...context } = useDropdownCardContext();
|
|
11
13
|
const ref = useMergeRefs([context.refs.setFloating, propRef]);
|
|
14
|
+
const asSheet = useMediaQuery(PHONE_QUERY) && sheet;
|
|
12
15
|
if (!context.open) return null;
|
|
13
16
|
return /* @__PURE__ */ jsx(FloatingFocusManager, { context: floatingContext, modal: false, children: /* @__PURE__ */ jsx(
|
|
14
17
|
"div",
|
|
@@ -20,11 +23,12 @@ const DropdownCardDropdown = React.forwardRef(
|
|
|
20
23
|
"roaster-dropdown-card--floating",
|
|
21
24
|
{
|
|
22
25
|
"roaster-dropdown-card--compact": variant === "compact",
|
|
23
|
-
"roaster-dropdown-card--tabs": variant === "tabs"
|
|
26
|
+
"roaster-dropdown-card--tabs": variant === "tabs",
|
|
27
|
+
"roaster-dropdown-card--sheet": sheet
|
|
24
28
|
},
|
|
25
29
|
className
|
|
26
30
|
),
|
|
27
|
-
style: { ...context.floatingStyles, ...style },
|
|
31
|
+
style: asSheet ? style : { ...context.floatingStyles, ...style },
|
|
28
32
|
children
|
|
29
33
|
}
|
|
30
34
|
) });
|
|
@@ -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":[],"mappings":";;;;;;;;;AAMY,MAAC,oBAAoB,GAAG,KAAK,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,GAAG,sBAAsB,EAAE;AAC7E,IAAI,MAAM,GAAG,GAAG,YAAY,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AACjE,IAAI,MAAM,OAAO,GAAG,aAAa,CAAC,WAAW,CAAC,IAAI,KAAK;AACvD,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,IAAI;AAClC,IAAI,uBAAuB,GAAG,CAAC,oBAAoB,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,kBAAkB,GAAG;AAC5H,MAAM,KAAK;AACX,MAAM;AACN,QAAQ,GAAG;AACX,QAAQ,GAAG,OAAO,CAAC,gBAAgB,CAAC,KAAK,CAAC;AAC1C,QAAQ,SAAS,EAAE,UAAU;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;;"}
|
|
@@ -4,19 +4,39 @@ import { classNames } from '../../utils/classNames/index.js';
|
|
|
4
4
|
|
|
5
5
|
const hasContent = (node) => !(node == null || typeof node === "boolean" || node === "");
|
|
6
6
|
const isInvalid = (error) => error != null && error !== false && error !== "";
|
|
7
|
-
function
|
|
8
|
-
const
|
|
7
|
+
function messageIds(controlId, { description, error, keepDescription }) {
|
|
8
|
+
const showsError = hasContent(error);
|
|
9
|
+
const showsDescription = hasContent(description) && (!showsError || !!keepDescription);
|
|
10
|
+
return {
|
|
11
|
+
descriptionId: showsDescription ? `${controlId}-message` : void 0,
|
|
12
|
+
errorId: showsError ? `${controlId}-${showsDescription ? "error" : "message"}` : void 0
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function fieldControlProps(controlId, messages, ariaProps = {}) {
|
|
16
|
+
const { descriptionId, errorId } = messageIds(controlId, messages);
|
|
9
17
|
return {
|
|
10
18
|
id: controlId,
|
|
11
|
-
"aria-invalid": isInvalid(error) ? true : void 0,
|
|
12
|
-
"aria-describedby": [ariaProps["aria-describedby"],
|
|
19
|
+
"aria-invalid": isInvalid(messages.error) ? true : void 0,
|
|
20
|
+
"aria-describedby": [ariaProps["aria-describedby"], descriptionId, errorId].filter(Boolean).join(" ") || void 0
|
|
13
21
|
};
|
|
14
22
|
}
|
|
15
|
-
function Field({
|
|
23
|
+
function Field({
|
|
24
|
+
controlId,
|
|
25
|
+
label,
|
|
26
|
+
description,
|
|
27
|
+
error,
|
|
28
|
+
keepDescription,
|
|
29
|
+
inline,
|
|
30
|
+
className,
|
|
31
|
+
style,
|
|
32
|
+
children
|
|
33
|
+
}) {
|
|
34
|
+
const { descriptionId, errorId } = messageIds(controlId, { description, error, keepDescription });
|
|
16
35
|
return /* @__PURE__ */ jsxs("div", { className: classNames("roaster-field", { "roaster-field--inline": inline }, className), style, children: [
|
|
17
36
|
hasContent(label) && /* @__PURE__ */ jsx("label", { className: "roaster-field__label", htmlFor: controlId, children: label }),
|
|
18
37
|
children,
|
|
19
|
-
|
|
38
|
+
descriptionId && /* @__PURE__ */ jsx("small", { className: "roaster-field__help", id: descriptionId, children: description }),
|
|
39
|
+
errorId && /* @__PURE__ */ jsx("small", { className: "roaster-field__error", id: errorId, children: error })
|
|
20
40
|
] });
|
|
21
41
|
}
|
|
22
42
|
|
|
@@ -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":[],"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,EAAE,OAAO;AACT,IAAI,aAAa,EAAE,gBAAgB,GAAG,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,GAAG,MAAM;AACrE,IAAI,OAAO,EAAE,UAAU,GAAG,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,gBAAgB,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC,GAAG;AACrF,GAAG;AACH;AACO,SAAS,iBAAiB,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,GAAG,EAAE,EAAE;AACvE,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC,SAAS,EAAE,QAAQ,CAAC;AACpE,EAAE,O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AG,EAAE,CAAC;AACN;;"}
|
|
@@ -46,6 +46,7 @@ const FileField = React.forwardRef((props, ref) => {
|
|
|
46
46
|
name,
|
|
47
47
|
disabled,
|
|
48
48
|
description,
|
|
49
|
+
keepDescription,
|
|
49
50
|
error,
|
|
50
51
|
className,
|
|
51
52
|
style,
|
|
@@ -68,37 +69,49 @@ const FileField = React.forwardRef((props, ref) => {
|
|
|
68
69
|
onChange?.(event);
|
|
69
70
|
onValueChange?.(chosen);
|
|
70
71
|
};
|
|
71
|
-
return /* @__PURE__ */ jsx(
|
|
72
|
-
|
|
72
|
+
return /* @__PURE__ */ jsx(
|
|
73
|
+
Field,
|
|
73
74
|
{
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
75
|
+
controlId: uid,
|
|
76
|
+
label,
|
|
77
|
+
description,
|
|
78
|
+
keepDescription,
|
|
79
|
+
error,
|
|
80
|
+
className,
|
|
81
|
+
style,
|
|
82
|
+
children: /* @__PURE__ */ jsxs(
|
|
83
|
+
"div",
|
|
84
|
+
{
|
|
85
|
+
className: classNames("roaster-file", `roaster-file--${size}`),
|
|
86
|
+
"data-state": files.length > 0 ? "filled" : void 0,
|
|
87
|
+
children: [
|
|
88
|
+
/* @__PURE__ */ jsx("div", { className: type === "image" ? "roaster-file__image" : "roaster-file__preview", children: files.length === 0 ? /* @__PURE__ */ jsx(EmptyMarkupPlaceholder, { type, defaultValue, noFileLabel: text.noFile }) : /* @__PURE__ */ jsx(Preview, { type, files }) }),
|
|
89
|
+
/* @__PURE__ */ jsxs("div", { className: "roaster-file__button", children: [
|
|
90
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
91
|
+
/* @__PURE__ */ jsx(Icon, { name: "arrow-up-from-bracket" }),
|
|
92
|
+
text.upload,
|
|
93
|
+
hint && /* @__PURE__ */ jsx("small", { className: "roaster-file__hint", children: hint })
|
|
94
|
+
] }),
|
|
95
|
+
/* @__PURE__ */ jsx(
|
|
96
|
+
"input",
|
|
97
|
+
{
|
|
98
|
+
...others,
|
|
99
|
+
...fieldControlProps(uid, { description, error, keepDescription }, others),
|
|
100
|
+
name,
|
|
101
|
+
ref,
|
|
102
|
+
className: "roaster-file__input",
|
|
103
|
+
type: "file",
|
|
104
|
+
disabled,
|
|
105
|
+
accept,
|
|
106
|
+
onChange: handleChange
|
|
107
|
+
}
|
|
108
|
+
)
|
|
109
|
+
] })
|
|
110
|
+
]
|
|
111
|
+
}
|
|
112
|
+
)
|
|
100
113
|
}
|
|
101
|
-
)
|
|
114
|
+
);
|
|
102
115
|
});
|
|
103
116
|
FileField.displayName = "FileField";
|
|
104
117
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileField.js","sources":["../../../../src/components/FileField/FileField.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, useUid } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps } from '../Field';\nimport { Icon } from '@/components/Icon';\n\n/**\n * Every native `<input>` prop (`name`, `required`, `aria-*`, ...) is accepted and forwarded to the file input, with the\n * ref. `className` and `style` go to the field's wrapper.\n */\nexport interface FileFieldProps\n extends\n FieldBaseProps,\n Omit<React.ComponentPropsWithoutRef<'input'>, 'type' | 'size' | 'defaultValue' | 'value' | 'className' | 'style'> {\n /** The HTML ID attribute to be applied to the file upload field input element (optional). */\n id?: string;\n /** The name attribute to be applied to the file upload field input element (optional). */\n name?: string;\n /**\n * The accept attribute to be applied to the file upload field input element (optional).\n * Specifies the types of accepted files.\n */\n accept?: string;\n /**\n * The size of the file upload field (optional).\n * - 'small': render a smaller file upload field\n * - 'medium': render a larger file upload field\n */\n size?: 'small' | 'medium';\n /** Whether the file upload field should be disabled (optional). */\n disabled?: boolean;\n /** The default value of the file upload field input (used to display a preview image when type is image). */\n defaultValue?: string | null;\n /**\n * Called with the chosen files when the user picks some: one, or several with `multiple`. The native `onChange`\n * gets the event.\n */\n onValueChange?(files: File[]): void;\n /**\n * The type of file to be uploaded (optional).\n * - 'image': upload an image file\n * - 'file': upload any file type\n */\n type?: 'image' | 'file';\n /** The text of the field, in English by default. */\n labels?: Partial<FileFieldLabels>;\n /** A line under the upload label, such as the files it takes. */\n hint?: React.ReactNode;\n}\n\n/** The text of the file field, for other languages. */\nexport interface FileFieldLabels {\n /** The upload button. */\n upload: React.ReactNode;\n /** Shown for a file field (`type=\"file\"`) with no file yet. */\n noFile: React.ReactNode;\n}\n\nconst defaultFileFieldLabels: FileFieldLabels = { upload: 'Upload a file', noFile: 'No file added' };\n\nfunction EmptyMarkupPlaceholder({\n type,\n defaultValue,\n noFileLabel,\n}: {\n type: 'image' | 'file';\n defaultValue?: string | null;\n noFileLabel: React.ReactNode;\n}) {\n if (type === 'file')\n return (\n <>\n <Icon name=\"file-csv\" className=\"roaster-file__icon\" />\n <span className=\"roaster-file__name\">{noFileLabel}</span>\n </>\n );\n\n if (defaultValue) {\n return <img src={defaultValue} alt=\"\" />;\n }\n\n return (\n <div className=\"roaster-file__placeholder\">\n <Icon name=\"image\" />\n </div>\n );\n}\n\nfunction Preview({ type, files }: { type: string; files: File[] }) {\n const file = files[0];\n const [imageUrl, setImageUrl] = React.useState<string>();\n\n // One object URL per file, released when the file changes or the preview goes away, so it doesn't leak memory.\n React.useEffect(() => {\n if (type !== 'image' || !file) return undefined;\n const url = URL.createObjectURL(file);\n setImageUrl(url);\n return () => URL.revokeObjectURL(url);\n }, [type, file]);\n\n if (type === 'image' && file) {\n return imageUrl ? <img src={imageUrl} alt={file.name} /> : null;\n }\n\n return (\n <>\n <Icon name=\"file-csv\" className=\"roaster-file__icon\" />\n <span className=\"roaster-file__name\">{files.map((chosen) => chosen.name).join(', ')}</span>\n </>\n );\n}\n\n/** A file upload field with a preview for images and the file name for other files. */\nexport const FileField = React.forwardRef<HTMLInputElement, FileFieldProps>((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 type = 'image',\n accept = type === 'image' ? 'image/*' : '.csv, .xls',\n size = 'small',\n defaultValue,\n labels,\n hint,\n ...others\n } = props;\n const text = { ...defaultFileFieldLabels, ...labels };\n const uid = useUid(id);\n // Every chosen file: several with `multiple`.\n const [files, setFiles] = React.useState<File[]>([]);\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n const chosen = [...(event.currentTarget.files ?? [])];\n setFiles(chosen);\n onChange?.(event);\n onValueChange?.(chosen);\n };\n\n return (\n <Field controlId={uid} label={label} description={description} error={error} className={className} style={style}>\n <div\n className={classNames('roaster-file', `roaster-file--${size}`)}\n data-state={files.length > 0 ? 'filled' : undefined}\n >\n <div className={type === 'image' ? 'roaster-file__image' : 'roaster-file__preview'}>\n {files.length === 0 ? (\n <EmptyMarkupPlaceholder type={type} defaultValue={defaultValue} noFileLabel={text.noFile} />\n ) : (\n <Preview type={type} files={files} />\n )}\n </div>\n <div className=\"roaster-file__button\">\n <span>\n <Icon name=\"arrow-up-from-bracket\" />\n {text.upload}\n {hint && <small className=\"roaster-file__hint\">{hint}</small>}\n </span>\n <input\n {...others}\n {...fieldControlProps(uid, { label, description, error }, others)}\n name={name}\n ref={ref}\n className=\"roaster-file__input\"\n type=\"file\"\n disabled={disabled}\n accept={accept}\n onChange={handleChange}\n />\n </div>\n </div>\n </Field>\n );\n});\n\nFileField.displayName = 'FileField';\n"],"names":[],"mappings":";;;;;;;;AAMA,MAAM,sBAAsB,GAAG,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,eAAe,EAAE;AACnF,SAAS,sBAAsB,CAAC;AAChC,EAAE,IAAI;AACN,EA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AAuB,EAAE,CAAC;AACxE,YAAY,IAAI,CAAC,MAAM;AACvB,YAAY,IAAI,oBAAoB,GAAG,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,oBAAoB,EAAE,QAAQ,EAAE,IAAI,EAAE;AACpG,WAAW,EAAE,CAAC;AACd,0BAA0B,GAAG;AAC7B,YAAY,OAAO;AACnB,YAAY;AACZ,cAAc,GAAG,MAAM;AACvB,cAAc,GAAG,iBAAiB,CAAC,GAAG,EAAE,EAAS,WAAW,EAAE,KAAK,EAAE,EAAE,MAAM,CAAC;AAC9E,cAAc,IAAI;AAClB,cAAc,GAAG;AACjB,cAAc,SAAS,EAAE,qBAAqB;AAC9C,cAAc,IAAI,EAAE,MAAM;AAC1B,cAAc,QAAQ;AACtB,cAAc,MAAM;AACpB,cAAc,QAAQ,EAAE;AACxB;AACA;AACA,SAAS,EAAE;AACX;AACA;AACA,GAAG,EAAE,CAAC;AACN,CAAC;AACD,SAAS,CAAC,WAAW,GAAG,WAAW;;"}
|
|
1
|
+
{"version":3,"file":"FileField.js","sources":["../../../../src/components/FileField/FileField.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, useUid } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps } from '../Field';\nimport { Icon } from '@/components/Icon';\n\n/**\n * Every native `<input>` prop (`name`, `required`, `aria-*`, ...) is accepted and forwarded to the file input, with the\n * ref. `className` and `style` go to the field's wrapper.\n */\nexport interface FileFieldProps\n extends\n FieldBaseProps,\n Omit<React.ComponentPropsWithoutRef<'input'>, 'type' | 'size' | 'defaultValue' | 'value' | 'className' | 'style'> {\n /** The HTML ID attribute to be applied to the file upload field input element (optional). */\n id?: string;\n /** The name attribute to be applied to the file upload field input element (optional). */\n name?: string;\n /**\n * The accept attribute to be applied to the file upload field input element (optional).\n * Specifies the types of accepted files.\n */\n accept?: string;\n /**\n * The size of the file upload field (optional).\n * - 'small': render a smaller file upload field\n * - 'medium': render a larger file upload field\n */\n size?: 'small' | 'medium';\n /** Whether the file upload field should be disabled (optional). */\n disabled?: boolean;\n /** The default value of the file upload field input (used to display a preview image when type is image). */\n defaultValue?: string | null;\n /**\n * Called with the chosen files when the user picks some: one, or several with `multiple`. The native `onChange`\n * gets the event.\n */\n onValueChange?(files: File[]): void;\n /**\n * The type of file to be uploaded (optional).\n * - 'image': upload an image file\n * - 'file': upload any file type\n */\n type?: 'image' | 'file';\n /** The text of the field, in English by default. */\n labels?: Partial<FileFieldLabels>;\n /** A line under the upload label, such as the files it takes. */\n hint?: React.ReactNode;\n}\n\n/** The text of the file field, for other languages. */\nexport interface FileFieldLabels {\n /** The upload button. */\n upload: React.ReactNode;\n /** Shown for a file field (`type=\"file\"`) with no file yet. */\n noFile: React.ReactNode;\n}\n\nconst defaultFileFieldLabels: FileFieldLabels = { upload: 'Upload a file', noFile: 'No file added' };\n\nfunction EmptyMarkupPlaceholder({\n type,\n defaultValue,\n noFileLabel,\n}: {\n type: 'image' | 'file';\n defaultValue?: string | null;\n noFileLabel: React.ReactNode;\n}) {\n if (type === 'file')\n return (\n <>\n <Icon name=\"file-csv\" className=\"roaster-file__icon\" />\n <span className=\"roaster-file__name\">{noFileLabel}</span>\n </>\n );\n\n if (defaultValue) {\n return <img src={defaultValue} alt=\"\" />;\n }\n\n return (\n <div className=\"roaster-file__placeholder\">\n <Icon name=\"image\" />\n </div>\n );\n}\n\nfunction Preview({ type, files }: { type: string; files: File[] }) {\n const file = files[0];\n const [imageUrl, setImageUrl] = React.useState<string>();\n\n // One object URL per file, released when the file changes or the preview goes away, so it doesn't leak memory.\n React.useEffect(() => {\n if (type !== 'image' || !file) return undefined;\n const url = URL.createObjectURL(file);\n setImageUrl(url);\n return () => URL.revokeObjectURL(url);\n }, [type, file]);\n\n if (type === 'image' && file) {\n return imageUrl ? <img src={imageUrl} alt={file.name} /> : null;\n }\n\n return (\n <>\n <Icon name=\"file-csv\" className=\"roaster-file__icon\" />\n <span className=\"roaster-file__name\">{files.map((chosen) => chosen.name).join(', ')}</span>\n </>\n );\n}\n\n/** A file upload field with a preview for images and the file name for other files. */\nexport const FileField = React.forwardRef<HTMLInputElement, FileFieldProps>((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 type = 'image',\n accept = type === 'image' ? 'image/*' : '.csv, .xls',\n size = 'small',\n defaultValue,\n labels,\n hint,\n ...others\n } = props;\n const text = { ...defaultFileFieldLabels, ...labels };\n const uid = useUid(id);\n // Every chosen file: several with `multiple`.\n const [files, setFiles] = React.useState<File[]>([]);\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n const chosen = [...(event.currentTarget.files ?? [])];\n setFiles(chosen);\n onChange?.(event);\n onValueChange?.(chosen);\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\n className={classNames('roaster-file', `roaster-file--${size}`)}\n data-state={files.length > 0 ? 'filled' : undefined}\n >\n <div className={type === 'image' ? 'roaster-file__image' : 'roaster-file__preview'}>\n {files.length === 0 ? (\n <EmptyMarkupPlaceholder type={type} defaultValue={defaultValue} noFileLabel={text.noFile} />\n ) : (\n <Preview type={type} files={files} />\n )}\n </div>\n <div className=\"roaster-file__button\">\n <span>\n <Icon name=\"arrow-up-from-bracket\" />\n {text.upload}\n {hint && <small className=\"roaster-file__hint\">{hint}</small>}\n </span>\n <input\n {...others}\n {...fieldControlProps(uid, { label, description, error, keepDescription }, others)}\n name={name}\n ref={ref}\n className=\"roaster-file__input\"\n type=\"file\"\n disabled={disabled}\n accept={accept}\n onChange={handleChange}\n />\n </div>\n </div>\n </Field>\n );\n});\n\nFileField.displayName = 'FileField';\n"],"names":[],"mappings":";;;;;;;;AAMA,MAAM,sBAAsB,GAAG,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,eAAe,EAAE;AACnF,SAAS,sBAAsB,CAAC;AAChC,EAAE,IAAI;AACN,EAAE,YA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AE,EAAE,QAAQ,EAAE;AACvD,gCAAgC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,uBAAuB,EAAE,CAAC;AAC5E,gBAAgB,IAAI,CAAC,MAAM;AAC3B,gBAAgB,IAAI,oBAAoB,GAAG,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,oBAAoB,EAAE,QAAQ,EAAE,IAAI,EAAE;AACxG,eAAe,EAAE,CAAC;AAClB,8BAA8B,GAAG;AACjC,gBAAgB,OAAO;AACvB,gBAAgB;AAChB,kBAAkB,GAAG,MAAM;AAC3B,kBAAkB,GAAG,iBAAiB,CAAC,GAAG,EAAE,EAAS,WAAW,EAAE,KAAK,EAAE,eAAe,EAAE,EAAE,MAAM,CAAC;AACnG,kBAAkB,IAAI;AACtB,kBAAkB,GAAG;AACrB,kBAAkB,SAAS,EAAE,qBAAqB;AAClD,kBAAkB,IAAI,EAAE,MAAM;AAC9B,kBAAkB,QAAQ;AAC1B,kBAAkB,MAAM;AACxB,kBAAkB,QAAQ,EAAE;AAC5B;AACA;AACA,aAAa,EAAE;AACf;AACA;AACA;AACA;AACA,GAAG;AACH,CAAC;AACD,SAAS,CAAC,WAAW,GAAG,WAAW;;"}
|
|
@@ -21,6 +21,7 @@ const Modal = React.forwardRef((props, ref) => {
|
|
|
21
21
|
title,
|
|
22
22
|
description,
|
|
23
23
|
size = "small",
|
|
24
|
+
sheet = false,
|
|
24
25
|
footer,
|
|
25
26
|
labels,
|
|
26
27
|
children,
|
|
@@ -65,7 +66,12 @@ const Modal = React.forwardRef((props, ref) => {
|
|
|
65
66
|
"aria-describedby": description ? descriptionId : void 0,
|
|
66
67
|
...others,
|
|
67
68
|
ref: setRefs,
|
|
68
|
-
className: classNames(
|
|
69
|
+
className: classNames(
|
|
70
|
+
"roaster-modal",
|
|
71
|
+
size !== "small" && `roaster-modal--${size}`,
|
|
72
|
+
sheet && "roaster-modal--sheet",
|
|
73
|
+
className
|
|
74
|
+
),
|
|
69
75
|
onCancel: (event) => {
|
|
70
76
|
onCancel?.(event);
|
|
71
77
|
event.preventDefault();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modal.js","sources":["../../../../src/components/Modal/Modal.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, useControllableState, useUid } from '@/utils';\nimport { ModalLabels, ModalProps } from './types';\nimport { ButtonIcon } from '../ButtonIcon';\nimport { Icon } from '@/components/Icon';\n\nconst defaultModalLabels: ModalLabels = { close: 'Close' };\n\n// A layout effect in the browser (the modal opens before it paints), and nothing on the server, which warns about one.\nconst useClientLayoutEffect = typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect;\n\n/** Whether the pointer event happened outside the dialog's box, on its backdrop. */\nfunction onBackdrop(dialog: HTMLDialogElement, event: React.MouseEvent) {\n const box = dialog.getBoundingClientRect();\n return event.clientX < box.left || event.clientX > box.right || event.clientY < box.top || event.clientY > box.bottom;\n}\n\n/**\n * A dialog over the page (`<dialog>` opened with `showModal()`), with a title, content and an optional footer. The page\n * behind is inert and doesn't scroll; the close button, Escape and a click outside ask to close it; the focus goes\n * back where it was. Open it with `open`, or with `useModal().openModal()` inside a ModalProvider.\n */\nexport const Modal = React.forwardRef<HTMLDialogElement, ModalProps>((props, ref) => {\n const {\n open: openProp,\n defaultOpen = false,\n onOpenChange,\n title,\n description,\n size = 'small',\n footer,\n labels,\n children,\n className,\n onCancel,\n onMouseDown,\n onClick,\n ...others\n } = props;\n const [open, setOpen] = useControllableState({ value: openProp, defaultValue: defaultOpen, onChange: onOpenChange });\n const text = { ...defaultModalLabels, ...labels };\n const titleId = useUid();\n const descriptionId = useUid();\n const dialogRef = React.useRef<HTMLDialogElement | null>(null);\n const setRefs = React.useCallback(\n (dialog: HTMLDialogElement | null) => {\n dialogRef.current = dialog;\n if (typeof ref === 'function') ref(dialog);\n else if (ref) ref.current = dialog;\n },\n [ref]\n );\n // Set on mousedown, so that a selection dragged from inside the dialog to outside doesn't close it.\n const pressedOutside = React.useRef(false);\n\n // Shown as a modal once mounted. Unmounting removes it without close(), so the focus goes back by hand.\n useClientLayoutEffect(() => {\n if (!open) return undefined;\n const dialog = dialogRef.current;\n const previous = document.activeElement;\n if (dialog && !dialog.open) dialog.showModal();\n return () => {\n if (dialog?.open) dialog.close();\n if (previous instanceof HTMLElement && previous.isConnected) previous.focus({ preventScroll: true });\n };\n }, [open]);\n\n if (!open) return null;\n\n return (\n // The mouse handlers only add a click outside to close it; the keyboard has Escape, through the cancel event.\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions\n <dialog\n aria-labelledby={title ? titleId : undefined}\n aria-describedby={description ? descriptionId : undefined}\n {...others}\n ref={setRefs}\n className={classNames('roaster-modal'
|
|
1
|
+
{"version":3,"file":"Modal.js","sources":["../../../../src/components/Modal/Modal.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, useControllableState, useUid } from '@/utils';\nimport { ModalLabels, ModalProps } from './types';\nimport { ButtonIcon } from '../ButtonIcon';\nimport { Icon } from '@/components/Icon';\n\nconst defaultModalLabels: ModalLabels = { close: 'Close' };\n\n// A layout effect in the browser (the modal opens before it paints), and nothing on the server, which warns about one.\nconst useClientLayoutEffect = typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect;\n\n/** Whether the pointer event happened outside the dialog's box, on its backdrop. */\nfunction onBackdrop(dialog: HTMLDialogElement, event: React.MouseEvent) {\n const box = dialog.getBoundingClientRect();\n return event.clientX < box.left || event.clientX > box.right || event.clientY < box.top || event.clientY > box.bottom;\n}\n\n/**\n * A dialog over the page (`<dialog>` opened with `showModal()`), with a title, content and an optional footer. The page\n * behind is inert and doesn't scroll; the close button, Escape and a click outside ask to close it; the focus goes\n * back where it was. Open it with `open`, or with `useModal().openModal()` inside a ModalProvider.\n */\nexport const Modal = React.forwardRef<HTMLDialogElement, ModalProps>((props, ref) => {\n const {\n open: openProp,\n defaultOpen = false,\n onOpenChange,\n title,\n description,\n size = 'small',\n sheet = false,\n footer,\n labels,\n children,\n className,\n onCancel,\n onMouseDown,\n onClick,\n ...others\n } = props;\n const [open, setOpen] = useControllableState({ value: openProp, defaultValue: defaultOpen, onChange: onOpenChange });\n const text = { ...defaultModalLabels, ...labels };\n const titleId = useUid();\n const descriptionId = useUid();\n const dialogRef = React.useRef<HTMLDialogElement | null>(null);\n const setRefs = React.useCallback(\n (dialog: HTMLDialogElement | null) => {\n dialogRef.current = dialog;\n if (typeof ref === 'function') ref(dialog);\n else if (ref) ref.current = dialog;\n },\n [ref]\n );\n // Set on mousedown, so that a selection dragged from inside the dialog to outside doesn't close it.\n const pressedOutside = React.useRef(false);\n\n // Shown as a modal once mounted. Unmounting removes it without close(), so the focus goes back by hand.\n useClientLayoutEffect(() => {\n if (!open) return undefined;\n const dialog = dialogRef.current;\n const previous = document.activeElement;\n if (dialog && !dialog.open) dialog.showModal();\n return () => {\n if (dialog?.open) dialog.close();\n if (previous instanceof HTMLElement && previous.isConnected) previous.focus({ preventScroll: true });\n };\n }, [open]);\n\n if (!open) return null;\n\n return (\n // The mouse handlers only add a click outside to close it; the keyboard has Escape, through the cancel event.\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions\n <dialog\n aria-labelledby={title ? titleId : undefined}\n aria-describedby={description ? descriptionId : undefined}\n {...others}\n ref={setRefs}\n className={classNames(\n 'roaster-modal',\n size !== 'small' && `roaster-modal--${size}`,\n sheet && 'roaster-modal--sheet',\n className\n )}\n onCancel={(event) => {\n onCancel?.(event);\n // Escape: the state closes the dialog, so a parent that keeps it open is obeyed.\n event.preventDefault();\n setOpen(false);\n }}\n onMouseDown={(event) => {\n onMouseDown?.(event);\n pressedOutside.current = event.target === event.currentTarget && onBackdrop(event.currentTarget, event);\n }}\n onClick={(event) => {\n onClick?.(event);\n const outside = event.target === event.currentTarget && onBackdrop(event.currentTarget, event);\n if (pressedOutside.current && outside) setOpen(false);\n pressedOutside.current = false;\n }}\n >\n <div className=\"roaster-modal__header\">\n {title && (\n <h2 className=\"roaster-modal__title\" id={titleId}>\n {title}\n </h2>\n )}\n <ButtonIcon size=\"medium\" aria-label={text.close} onClick={() => setOpen(false)}>\n <Icon name=\"xmark\" />\n </ButtonIcon>\n {description && (\n <p className=\"roaster-modal__description\" id={descriptionId}>\n {description}\n </p>\n )}\n </div>\n <div className=\"roaster-modal__body\">{children}</div>\n {footer && <div className=\"roaster-modal__footer\">{footer}</div>}\n </dialog>\n );\n});\n\nModal.displayName = 'Modal';\n"],"names":[],"mappings":";;;;;;;;;AAMA,MAAM,kBAAkB,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE;AAC7C,MAAM,qBAAqB,GAAG,OAAO,MAAM,KAAK,WAAW,GAAG,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC,eAAe;AACrG,SAAS,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE;AACnC,EAAE,MAAM,GAAG,GAAG,MAAM,CAAC,qBAAqB,EAAE;AAC5C,EAAE,OAAO,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,IAAI,IAAI,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG,IAAI,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,MAAM;AACvH;AACY,MAAC,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AACtD,EAAE,MAAM;AACR,IAAI,IAAI,EAAE,QAAQ;AAClB,IAAI,WAAW,GAAG,KAAK;AACvB,IAAI,YAAY;AAChB,IAAI,KAAK;AACT,IAAI,WAAW;AACf,IAAI,IAAI,GAAG,OAAO;AAClB,IAAI,KAAK,GAAG,KAAK;AACjB,IAAI,MAAM;AACV,IAAI,MAAM;AACV,IAAI,QAAQ;AACZ,IAAI,SAAS;AACb,IAAI,QAAQ;AACZ,IAAI,WAAW;AACf,IAAI,OAAO;AACX,IAAI,GAAG;AACP,GAAG,GAA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