@trellixio/roaster-react 2.1.1 → 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 +6 -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 +6 -5
- 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/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/Switch/Switch.js +7 -1
- package/cjs/components/Switch/Switch.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/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 +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 +2 -1
- 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/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/Switch/Switch.js +7 -1
- package/esm/components/Switch/Switch.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/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/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/RangeField/RangeField.d.ts.map +1 -1
- package/lib/components/Select/Select.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 +1 -1
- package/roaster.css +1 -1
|
@@ -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,EAAE,YAAY;AACd,EAAE;AACF,CAAC,EAAE;AACH,EAAE,IAAI,IAAI,KAAK,MAAM;AACrB,IAAI,uBAAuB,IAAI,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE;AACtD,sBAAsB,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,oBAAoB,EAAE,CAAC;AACtF,sBAAsB,GAAG,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,oBAAoB,EAAE,QAAQ,EAAE,WAAW,EAAE;AAC5F,KAAK,EAAE,CAAC;AACR,EAAE,IAAI,YAAY,EAAE;AACpB,IAAI,uBAAuB,GAAG,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;AACrE,EAAE;AACF,EAAE,uBAAuB,GAAG,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,2BAA2B,EAAE,QAAQ,kBAAkB,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;AACvI;AACA,SAAS,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;AAClC,EAAE,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC;AACvB,EAAE,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC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,CAAC,mBAAmB,GAAG,CAAC,sBAAsB,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,mBAAmB,GAAG,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AACnS,wBAAwB,IAAI,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,sBAAsB,EAAE,QAAQ,EAAE;AACnF,0BAA0B,IAAI,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE;AACnD,4BAA4B,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,uBAAuB,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,YAAY;AACd,EAAE;AACF,CAAC,EAAE;AACH,EAAE,IAAI,IAAI,KAAK,MAAM;AACrB,IAAI,uBAAuB,IAAI,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE;AACtD,sBAAsB,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,oBAAoB,EAAE,CAAC;AACtF,sBAAsB,GAAG,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,oBAAoB,EAAE,QAAQ,EAAE,WAAW,EAAE;AAC5F,KAAK,EAAE,CAAC;AACR,EAAE,IAAI,YAAY,EAAE;AACpB,IAAI,uBAAuB,GAAG,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;AACrE,EAAE;AACF,EAAE,uBAAuB,GAAG,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,2BAA2B,EAAE,QAAQ,kBAAkB,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;AACvI;AACA,SAAS,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;AAClC,EAAE,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC;AACvB,EAAE,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG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
|
|
15
15
|
description,
|
|
16
|
+
keepDescription,
|
|
16
17
|
disabled,
|
|
17
18
|
onChange,
|
|
18
19
|
onValueChange,
|
|
@@ -37,27 +38,39 @@ const RangeField = React.forwardRef((props, ref) => {
|
|
|
37
38
|
onChange?.(event);
|
|
38
39
|
setInternalValue(Number(event.currentTarget.value));
|
|
39
40
|
};
|
|
40
|
-
return /* @__PURE__ */ jsx(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
41
|
+
return /* @__PURE__ */ jsx(
|
|
42
|
+
Field,
|
|
43
|
+
{
|
|
44
|
+
controlId: uid,
|
|
45
|
+
label,
|
|
46
|
+
description,
|
|
47
|
+
keepDescription,
|
|
48
|
+
error,
|
|
49
|
+
className,
|
|
50
|
+
style,
|
|
51
|
+
children: /* @__PURE__ */ jsxs("div", { className: "roaster-range", children: [
|
|
52
|
+
/* @__PURE__ */ jsx(
|
|
53
|
+
"input",
|
|
54
|
+
{
|
|
55
|
+
...others,
|
|
56
|
+
...fieldControlProps(uid, { description, error, keepDescription }, others),
|
|
57
|
+
ref,
|
|
58
|
+
className: "roaster-range__input",
|
|
59
|
+
min,
|
|
60
|
+
max,
|
|
61
|
+
name,
|
|
62
|
+
step,
|
|
63
|
+
type: "range",
|
|
64
|
+
disabled,
|
|
65
|
+
value: current,
|
|
66
|
+
onChange: handleChange,
|
|
67
|
+
style: { "--roaster-range-percent": `${fillPercentage}%` }
|
|
68
|
+
}
|
|
69
|
+
),
|
|
70
|
+
/* @__PURE__ */ jsx("output", { className: "roaster-range__value", htmlFor: uid, children: current })
|
|
71
|
+
] })
|
|
72
|
+
}
|
|
73
|
+
);
|
|
61
74
|
});
|
|
62
75
|
RangeField.displayName = "RangeField";
|
|
63
76
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RangeField.js","sources":["../../../../src/components/RangeField/RangeField.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useUid, useControllableState } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps } from '../Field';\n\n/**\n * Every native `<input>` prop (`name`, `required`, `aria-*`, ...) is accepted and forwarded to the range input, with the\n * ref. `className` and `style` go to the field's wrapper.\n */\nexport interface RangeFieldProps\n extends FieldBaseProps, Omit<React.ComponentPropsWithoutRef<'input'>, 'type' | 'className' | 'style'> {\n /** The HTML ID attribute to be applied to the range input element (optional). */\n id?: string;\n /** The minimum value of the range input field (optional). */\n min?: number;\n /** The maximum value of the range input field (optional). */\n max?: number;\n /** The step value of the range input field (optional). */\n step?: number;\n /** The name attribute to be applied to the range input element (optional). */\n name?: string;\n /** The value of the range input field (optional). */\n value?: number;\n /** Whether the range input field should be disabled (optional). */\n disabled?: boolean;\n /** The default value of the range input field (optional). */\n defaultValue?: number;\n /** Called with the new value when the user moves the slider. The native `onChange` gets the event. */\n onValueChange?(value: number): void;\n}\n\n/** A slider to pick a number between a minimum and a maximum, with its current value shown. */\nexport const RangeField = React.forwardRef<HTMLInputElement, RangeFieldProps>((props, ref) => {\n const {\n id,\n name,\n label,\n value,\n min = 0,\n description,\n disabled,\n onChange,\n onValueChange,\n step = 1,\n max = 100,\n error,\n className,\n style,\n defaultValue = 0,\n ...others\n } = props;\n\n const [internalValue, setInternalValue] = useControllableState<number>({\n value,\n defaultValue,\n onChange: onValueChange,\n });\n const uid = useUid(id);\n\n // The browser clamps what the slider shows; clamp what we display and fill with the same number.\n const current = Math.min(Math.max(Number(internalValue), min), max);\n const range = max - min;\n const fillPercentage = range > 0 ? (100 * (current - min)) / range : 0;\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n onChange?.(event);\n setInternalValue(Number(event.currentTarget.value));\n };\n\n return (\n <Field
|
|
1
|
+
{"version":3,"file":"RangeField.js","sources":["../../../../src/components/RangeField/RangeField.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useUid, useControllableState } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps } from '../Field';\n\n/**\n * Every native `<input>` prop (`name`, `required`, `aria-*`, ...) is accepted and forwarded to the range input, with the\n * ref. `className` and `style` go to the field's wrapper.\n */\nexport interface RangeFieldProps\n extends FieldBaseProps, Omit<React.ComponentPropsWithoutRef<'input'>, 'type' | 'className' | 'style'> {\n /** The HTML ID attribute to be applied to the range input element (optional). */\n id?: string;\n /** The minimum value of the range input field (optional). */\n min?: number;\n /** The maximum value of the range input field (optional). */\n max?: number;\n /** The step value of the range input field (optional). */\n step?: number;\n /** The name attribute to be applied to the range input element (optional). */\n name?: string;\n /** The value of the range input field (optional). */\n value?: number;\n /** Whether the range input field should be disabled (optional). */\n disabled?: boolean;\n /** The default value of the range input field (optional). */\n defaultValue?: number;\n /** Called with the new value when the user moves the slider. The native `onChange` gets the event. */\n onValueChange?(value: number): void;\n}\n\n/** A slider to pick a number between a minimum and a maximum, with its current value shown. */\nexport const RangeField = React.forwardRef<HTMLInputElement, RangeFieldProps>((props, ref) => {\n const {\n id,\n name,\n label,\n value,\n min = 0,\n description,\n keepDescription,\n disabled,\n onChange,\n onValueChange,\n step = 1,\n max = 100,\n error,\n className,\n style,\n defaultValue = 0,\n ...others\n } = props;\n\n const [internalValue, setInternalValue] = useControllableState<number>({\n value,\n defaultValue,\n onChange: onValueChange,\n });\n const uid = useUid(id);\n\n // The browser clamps what the slider shows; clamp what we display and fill with the same number.\n const current = Math.min(Math.max(Number(internalValue), min), max);\n const range = max - min;\n const fillPercentage = range > 0 ? (100 * (current - min)) / range : 0;\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n onChange?.(event);\n setInternalValue(Number(event.currentTarget.value));\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-range\">\n <input\n {...others}\n {...fieldControlProps(uid, { label, description, error, keepDescription }, others)}\n ref={ref}\n className=\"roaster-range__input\"\n min={min}\n max={max}\n name={name}\n step={step}\n type=\"range\"\n disabled={disabled}\n value={current}\n onChange={handleChange}\n // The CSS fills the track up to this percentage, in the theme's colors.\n style={{ '--roaster-range-percent': `${fillPercentage}%` } as React.CSSProperties}\n />\n <output className=\"roaster-range__value\" htmlFor={uid}>\n {current}\n </output>\n </div>\n </Field>\n );\n});\n\nRangeField.displayName = 'RangeField';\n"],"names":[],"mappings":";;;;;;;AAKY,MAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AAC3D,EAAE,MAAM;AACR,IAAI,EAAE;AACN,IAAI,IAAI;AACR,IAAI,KAAK;AACT,IAAI,KAAK;AACT,IAAI,GAAG,GAAG,CAAC;AACX,IAAI,WAAW;AACf,IAAI,eAAe;AACnB,IAAI,QAAQ;AACZ,IAAI,QAAQ;AACZ,IAAI,aAAa;AACjB,IAAI,IAAI,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,GAAG;AACb,IAAI,KAAK;AACT,IAAI,SAAS;AACb,IAAI,KAAK;AACT,IAAI,YAAY,GAAG,CAAC;AACpB,IAAI,GAAG;AACP,GAAG,GAAG,KAAK;AACX,EAAE,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,oBAAoB,CAAC;AACjE,IAAI,KAAK;AACT,IAAI,YAAY;AAChB,IAAI,QAAQ,EAAE;AACd,GAAG,CAAC;AACJ,EAAE,MAAM,GAAG,GAAG,MAAM,CAAC,EAAE,CAAC;AACxB,EAAE,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC;AACrE,EAAE,MAAM,KAAK,GAAG,GAAG,GAAG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,EAAE;AACT;AACA,GAAG;AACH,CAAC;AACD,UAAU,CAAC,WAAW,GAAG,YAAY;;"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { useMergeRefs } from '@floating-ui/react';
|
|
4
3
|
import * as React from 'react';
|
|
5
4
|
import { Field, fieldControlProps } from '../Field/Field.js';
|
|
6
5
|
import { useUid } from '../../utils/useUid/index.js';
|
|
6
|
+
import { useMergeRefs } from '../../utils/useMergeRefs/index.js';
|
|
7
7
|
import { classNames } from '../../utils/classNames/index.js';
|
|
8
8
|
|
|
9
9
|
function defaultOptionResolver(item) {
|
|
@@ -31,6 +31,7 @@ const SelectBase = React.forwardRef((props, ref) => {
|
|
|
31
31
|
options,
|
|
32
32
|
placeholder,
|
|
33
33
|
description,
|
|
34
|
+
keepDescription,
|
|
34
35
|
prefix,
|
|
35
36
|
prefixWidth = prefix ? 24 : 12,
|
|
36
37
|
onChange,
|
|
@@ -68,6 +69,7 @@ const SelectBase = React.forwardRef((props, ref) => {
|
|
|
68
69
|
controlId: uid,
|
|
69
70
|
label,
|
|
70
71
|
description,
|
|
72
|
+
keepDescription,
|
|
71
73
|
error,
|
|
72
74
|
inline,
|
|
73
75
|
className,
|
|
@@ -78,7 +80,7 @@ const SelectBase = React.forwardRef((props, ref) => {
|
|
|
78
80
|
"select",
|
|
79
81
|
{
|
|
80
82
|
...others,
|
|
81
|
-
...fieldControlProps(uid, { description, error }, others),
|
|
83
|
+
...fieldControlProps(uid, { description, error, keepDescription }, others),
|
|
82
84
|
ref: mergedRef,
|
|
83
85
|
className: classNames("roaster-select", { "roaster-select--prefixed": prefix, "roaster-select--rich": rich }),
|
|
84
86
|
style: { paddingLeft: prefixWidth },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Select.js","sources":["../../../../src/components/Select/Select.tsx"],"sourcesContent":["import { useMergeRefs } from '@floating-ui/react';\nimport * as React from 'react';\nimport { classNames, useUid } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps, type InlineFieldProps } from '../Field';\n\n/** One option of the select, as rendered. */\nexport interface SelectOption {\n /** The submitted value. */\n value: string;\n /** The text shown. */\n label: string;\n /** Whether the option can't be chosen. */\n disabled?: boolean;\n /**\n * A line under the label in a `rich` select's list. Where the browser shows its own list, it follows the label after\n * a dot.\n */\n description?: string;\n}\n\n/** The items the select understands without an `optionResolver`. */\nexport type SelectItem = string | SelectOption | { id: string | number; name?: string; title?: string };\n\n/** Turns one item of `data` into the option to render. */\nexport type OptionResolver<T> = (item: T) => SelectOption;\n\n/**\n * Strings are their own value and label, `{ id, name }` and `{ id, title }` objects use the id as the value, and any\n * other object is read as an option (`{ value, label, disabled }`).\n */\nfunction defaultOptionResolver(item: unknown): SelectOption {\n if (typeof item === 'string') return { label: item, value: item };\n\n const record = (item ?? {}) as Record<string, unknown>;\n if ('id' in record && ('name' in record || 'title' in record)) {\n return { label: String(record.name ?? record.title), value: String(record.id) };\n }\n return { ...record, value: String(record.value), label: String(record.label) } as SelectOption;\n}\n\n/**\n * Every native `<select>` prop (`name`, `value`, `required`, `aria-*`, ...) is accepted and forwarded to the select,\n * with the ref. `className` and `style` go to the field's wrapper.\n */\nexport interface SelectProps<T = SelectItem>\n extends\n FieldBaseProps,\n InlineFieldProps,\n Omit<React.ComponentPropsWithoutRef<'select'>, 'prefix' | 'className' | 'style'> {\n /**\n * The options: strings, `{ value, label }` objects, `{ id, name }` objects, or any other shape together with an\n * `optionResolver`.\n */\n options: T[];\n /** A first, empty option such as \"Choose a country\", shown until one is chosen. It can't be chosen back. */\n placeholder?: string;\n /** The element to be displayed to the left of the select field (optional). */\n prefix?: React.ReactNode;\n /** The width of the prefix element (optional). */\n prefixWidth?: number;\n /** Called with the new value when the user picks an option. The native `onChange` gets the event. */\n onValueChange?(value: string): void;\n /** Turns each item of `options` into an option (`{ value, label, disabled }`). Needed for shapes the select doesn't know. */\n optionResolver?: OptionResolver<T>;\n /**\n * Draws the list itself, where the browser allows it (the customizable select: Chrome, Edge, Safari): a check on the\n * chosen option, the theme's hover, and the options' descriptions. Other browsers (Firefox) show their own list.\n */\n rich?: boolean;\n}\n\n/**\n * Keeps the descriptions out of a rich select's field: the field then shows the chosen option's content (a\n * `<selectedcontent>` in a `<button>`, first in the select), whose description the CSS hides. Added after rendering,\n * and only where the browser draws the list itself: React 18 doesn't allow a button in a select, and the other\n * browsers show the option's text.\n */\nfunction useSelectedContent(ref: React.RefObject<HTMLSelectElement | null>, enabled: boolean) {\n React.useEffect(() => {\n const select = ref.current;\n // jsdom has `CSS` without `supports`.\n const drawsItsList = typeof CSS?.supports === 'function' && CSS.supports('appearance', 'base-select');\n if (!enabled || !select || !drawsItsList) return undefined;\n const button = document.createElement('button');\n button.append(document.createElement('selectedcontent'));\n select.prepend(button);\n return () => button.remove();\n }, [ref, enabled]);\n}\n\nconst SelectBase = React.forwardRef<HTMLSelectElement, SelectProps<unknown>>((props, ref) => {\n const {\n label,\n options,\n placeholder,\n description,\n prefix,\n prefixWidth = prefix ? 24 : 12,\n onChange,\n onValueChange,\n id,\n error,\n optionResolver = defaultOptionResolver,\n rich = false,\n inline,\n className,\n style,\n defaultValue,\n ...others\n } = props;\n const uid = useUid(id);\n const selectRef = React.useRef<HTMLSelectElement>(null);\n const mergedRef = useMergeRefs([selectRef, ref]);\n const items = options.map(optionResolver);\n useSelectedContent(selectRef, rich && items.some((item) => item.description));\n const optionElements = items.map((item) => (\n <option key={item.value} value={item.value} disabled={item.disabled}>\n {item.label}\n {item.description && (\n <>\n <span className=\"roaster-select__separator\"> · </span>\n <small className=\"roaster-select__description\">{item.description}</small>\n </>\n )}\n </option>\n ));\n // Uncontrolled with a placeholder and no default: start on the placeholder, which a browser would skip as disabled.\n const startValue = defaultValue ?? (placeholder !== undefined && others.value === undefined ? '' : undefined);\n\n const handleChange = (event: React.ChangeEvent<HTMLSelectElement>) => {\n onChange?.(event);\n onValueChange?.(event.currentTarget.value);\n };\n\n return (\n <Field\n controlId={uid}\n label={label}\n description={description}\n error={error}\n inline={inline}\n className={className}\n style={style}\n >\n <div className={classNames({ 'roaster-input-group': prefix })}>\n {prefix && <span className=\"roaster-input-group__prefix\">{prefix}</span>}\n <select\n {...others}\n {...fieldControlProps(uid, { label, description, error }, others)}\n ref={mergedRef}\n className={classNames('roaster-select', { 'roaster-select--prefixed': prefix, 'roaster-select--rich': rich })}\n style={{ paddingLeft: prefixWidth }}\n defaultValue={startValue}\n onChange={handleChange}\n >\n {placeholder !== undefined && (\n <option value=\"\" disabled>\n {placeholder}\n </option>\n )}\n {optionElements}\n </select>\n </div>\n </Field>\n );\n});\n\nSelectBase.displayName = 'Select';\n\n/**\n * A dropdown to choose one option, from a list of strings or objects, with an optional prefix. The type of `options`'\n * items is passed to `optionResolver`.\n */\nexport const Select = SelectBase as (<T = SelectItem>(\n props: SelectProps<T> & React.RefAttributes<HTMLSelectElement>\n) => React.ReactElement | null) & { displayName?: string };\n"],"names":[],"mappings":";;;;;;;;AAMA,SAAS,qBAAqB,CAAC,IAAI,EAAE;AACrC,EAAE,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;AACnE,EAAE,MAAM,MAAM,GAAG,IAAI,IAAI,EAAE;AAC3B,EAAE,IAAI,IAAI,IAAI,MAAM,KAAK,MAAM,IAAI,MAAM,IAAI,OAAO,IAAI,MAAM,CAAC,EAAE;AACjE,IAAI,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AACnF,EAAE;AACF,EAAE,OAAO,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,M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x"],"sourcesContent":["import * as React from 'react';\nimport { classNames, useMergeRefs, useUid } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps, type InlineFieldProps } from '../Field';\n\n/** One option of the select, as rendered. */\nexport interface SelectOption {\n /** The submitted value. */\n value: string;\n /** The text shown. */\n label: string;\n /** Whether the option can't be chosen. */\n disabled?: boolean;\n /**\n * A line under the label in a `rich` select's list. Where the browser shows its own list, it follows the label after\n * a dot.\n */\n description?: string;\n}\n\n/** The items the select understands without an `optionResolver`. */\nexport type SelectItem = string | SelectOption | { id: string | number; name?: string; title?: string };\n\n/** Turns one item of `data` into the option to render. */\nexport type OptionResolver<T> = (item: T) => SelectOption;\n\n/**\n * Strings are their own value and label, `{ id, name }` and `{ id, title }` objects use the id as the value, and any\n * other object is read as an option (`{ value, label, disabled }`).\n */\nfunction defaultOptionResolver(item: unknown): SelectOption {\n if (typeof item === 'string') return { label: item, value: item };\n\n const record = (item ?? {}) as Record<string, unknown>;\n if ('id' in record && ('name' in record || 'title' in record)) {\n return { label: String(record.name ?? record.title), value: String(record.id) };\n }\n return { ...record, value: String(record.value), label: String(record.label) } as SelectOption;\n}\n\n/**\n * Every native `<select>` prop (`name`, `value`, `required`, `aria-*`, ...) is accepted and forwarded to the select,\n * with the ref. `className` and `style` go to the field's wrapper.\n */\nexport interface SelectProps<T = SelectItem>\n extends\n FieldBaseProps,\n InlineFieldProps,\n Omit<React.ComponentPropsWithoutRef<'select'>, 'prefix' | 'className' | 'style'> {\n /**\n * The options: strings, `{ value, label }` objects, `{ id, name }` objects, or any other shape together with an\n * `optionResolver`.\n */\n options: T[];\n /** A first, empty option such as \"Choose a country\", shown until one is chosen. It can't be chosen back. */\n placeholder?: string;\n /** The element to be displayed to the left of the select field (optional). */\n prefix?: React.ReactNode;\n /** The width of the prefix element (optional). */\n prefixWidth?: number;\n /** Called with the new value when the user picks an option. The native `onChange` gets the event. */\n onValueChange?(value: string): void;\n /** Turns each item of `options` into an option (`{ value, label, disabled }`). Needed for shapes the select doesn't know. */\n optionResolver?: OptionResolver<T>;\n /**\n * Draws the list itself, where the browser allows it (the customizable select: Chrome, Edge, Safari): a check on the\n * chosen option, the theme's hover, and the options' descriptions. Other browsers (Firefox) show their own list.\n */\n rich?: boolean;\n}\n\n/**\n * Keeps the descriptions out of a rich select's field: the field then shows the chosen option's content (a\n * `<selectedcontent>` in a `<button>`, first in the select), whose description the CSS hides. Added after rendering,\n * and only where the browser draws the list itself: React 18 doesn't allow a button in a select, and the other\n * browsers show the option's text.\n */\nfunction useSelectedContent(ref: React.RefObject<HTMLSelectElement | null>, enabled: boolean) {\n React.useEffect(() => {\n const select = ref.current;\n // jsdom has `CSS` without `supports`.\n const drawsItsList = typeof CSS?.supports === 'function' && CSS.supports('appearance', 'base-select');\n if (!enabled || !select || !drawsItsList) return undefined;\n const button = document.createElement('button');\n button.append(document.createElement('selectedcontent'));\n select.prepend(button);\n return () => button.remove();\n }, [ref, enabled]);\n}\n\nconst SelectBase = React.forwardRef<HTMLSelectElement, SelectProps<unknown>>((props, ref) => {\n const {\n label,\n options,\n placeholder,\n description,\n keepDescription,\n prefix,\n prefixWidth = prefix ? 24 : 12,\n onChange,\n onValueChange,\n id,\n error,\n optionResolver = defaultOptionResolver,\n rich = false,\n inline,\n className,\n style,\n defaultValue,\n ...others\n } = props;\n const uid = useUid(id);\n const selectRef = React.useRef<HTMLSelectElement>(null);\n const mergedRef = useMergeRefs([selectRef, ref]);\n const items = options.map(optionResolver);\n useSelectedContent(selectRef, rich && items.some((item) => item.description));\n const optionElements = items.map((item) => (\n <option key={item.value} value={item.value} disabled={item.disabled}>\n {item.label}\n {item.description && (\n <>\n <span className=\"roaster-select__separator\"> · </span>\n <small className=\"roaster-select__description\">{item.description}</small>\n </>\n )}\n </option>\n ));\n // Uncontrolled with a placeholder and no default: start on the placeholder, which a browser would skip as disabled.\n const startValue = defaultValue ?? (placeholder !== undefined && others.value === undefined ? '' : undefined);\n\n const handleChange = (event: React.ChangeEvent<HTMLSelectElement>) => {\n onChange?.(event);\n onValueChange?.(event.currentTarget.value);\n };\n\n return (\n <Field\n controlId={uid}\n label={label}\n description={description}\n keepDescription={keepDescription}\n error={error}\n inline={inline}\n className={className}\n style={style}\n >\n <div className={classNames({ 'roaster-input-group': prefix })}>\n {prefix && <span className=\"roaster-input-group__prefix\">{prefix}</span>}\n <select\n {...others}\n {...fieldControlProps(uid, { label, description, error, keepDescription }, others)}\n ref={mergedRef}\n className={classNames('roaster-select', { 'roaster-select--prefixed': prefix, 'roaster-select--rich': rich })}\n style={{ paddingLeft: prefixWidth }}\n defaultValue={startValue}\n onChange={handleChange}\n >\n {placeholder !== undefined && (\n <option value=\"\" disabled>\n {placeholder}\n </option>\n )}\n {optionElements}\n </select>\n </div>\n </Field>\n );\n});\n\nSelectBase.displayName = 'Select';\n\n/**\n * A dropdown to choose one option, from a list of strings or objects, with an optional prefix. The type of `options`'\n * items is passed to `optionResolver`.\n */\nexport const Select = SelectBase as (<T = SelectItem>(\n props: SelectProps<T> & React.RefAttributes<HTMLSelectElement>\n) => React.ReactElement | null) & { displayName?: string };\n"],"names":[],"mappings":";;;;;;;;AAKA,SAAS,qBAAqB,CAAC,IAAI,EAAE;AACrC,EAAE,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;AACnE,EAAE,MAAM,MAAM,GAAG,IAAI,IAAI,EAAE;AAC3B,EAAE,IAAI,IAAI,IAAI,MAAM,KAAK,MAAM,IAAI,MAAM,IAAI,OAAO,IAAI,MAAM,CAAC,EAAE;AACjE,IAAI,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AACnF,EAAE;AACF,EAAE,OAAO,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MA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AAW,GAAG,QAAQ;AACrB,MAAC,MAAM,GAAG;;"}
|
|
@@ -14,6 +14,7 @@ const Switch = React.forwardRef((props, ref) => {
|
|
|
14
14
|
checked: checkedProp,
|
|
15
15
|
defaultChecked = false,
|
|
16
16
|
description,
|
|
17
|
+
keepDescription,
|
|
17
18
|
error,
|
|
18
19
|
className,
|
|
19
20
|
style,
|
|
@@ -39,6 +40,7 @@ const Switch = React.forwardRef((props, ref) => {
|
|
|
39
40
|
controlId: uid,
|
|
40
41
|
label: beside ? void 0 : label,
|
|
41
42
|
description,
|
|
43
|
+
keepDescription,
|
|
42
44
|
error,
|
|
43
45
|
className,
|
|
44
46
|
style,
|
|
@@ -47,7 +49,11 @@ const Switch = React.forwardRef((props, ref) => {
|
|
|
47
49
|
"input",
|
|
48
50
|
{
|
|
49
51
|
...others,
|
|
50
|
-
...fieldControlProps(
|
|
52
|
+
...fieldControlProps(
|
|
53
|
+
uid,
|
|
54
|
+
{ description, error, keepDescription },
|
|
55
|
+
others
|
|
56
|
+
),
|
|
51
57
|
ref,
|
|
52
58
|
type: "checkbox",
|
|
53
59
|
role: "switch",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Switch.js","sources":["../../../../src/components/Switch/Switch.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useUid, useControllableState } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps } from '../Field';\n\n/**\n * Every native `<input>` prop (`name`, `required`, `aria-*`, ...) is accepted and forwarded to the switch input, with the\n * ref. `className` and `style` go to the field's wrapper.\n */\nexport interface SwitchProps\n extends FieldBaseProps, Omit<React.ComponentPropsWithoutRef<'input'>, 'type' | 'className' | 'style'> {\n /** The HTML ID attribute to be applied to the switch element (optional). */\n id?: string;\n /** The name attribute to be applied to the switch element (optional). */\n name?: string;\n /** Whether the switch toggle should be disabled (optional). */\n disabled?: boolean;\n /** The checked state of the switch toggle, for a controlled switch (optional). */\n checked?: boolean;\n /** The default checked state of the switch toggle, for an uncontrolled switch (optional). */\n defaultChecked?: boolean;\n /** Called with the new state when the user toggles the switch. The native `onChange` gets the event. */\n onCheckedChange?(value: boolean): void;\n /**\n * Where the label goes: over the switch, as a field's label (`top`), or beside it (`end`), as a checkbox's, such as\n * in a list of settings.\n * @defaultValue 'top'\n */\n labelPosition?: 'top' | 'end';\n}\n\n/**\n * A toggle switch with a label, over it or beside it. Control it with checked and onCheckedChange, or leave it\n * uncontrolled with defaultChecked.\n */\nexport const Switch = React.forwardRef<HTMLInputElement, SwitchProps>((props, ref) => {\n const {\n id,\n label,\n name,\n disabled,\n checked: checkedProp,\n defaultChecked = false,\n description,\n error,\n className,\n style,\n onChange,\n onCheckedChange,\n labelPosition = 'top',\n ...others\n } = props;\n const beside = labelPosition === 'end';\n const [checked, setChecked] = useControllableState<boolean>({\n value: checkedProp,\n defaultValue: defaultChecked ?? false,\n onChange: onCheckedChange,\n });\n\n const uid = useUid(id);\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n onChange?.(event);\n setChecked(event.currentTarget.checked);\n };\n\n return (\n <Field\n controlId={uid}\n label={beside ? undefined : label}\n description={description}\n error={error}\n className={className}\n style={style}\n >\n {/* Its own label too, so a click on the toggle reaches the input; beside it, it holds the text. */}\n <label className=\"roaster-switch\">\n <input\n {...others}\n {...fieldControlProps(uid
|
|
1
|
+
{"version":3,"file":"Switch.js","sources":["../../../../src/components/Switch/Switch.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useUid, useControllableState } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps } from '../Field';\n\n/**\n * Every native `<input>` prop (`name`, `required`, `aria-*`, ...) is accepted and forwarded to the switch input, with the\n * ref. `className` and `style` go to the field's wrapper.\n */\nexport interface SwitchProps\n extends FieldBaseProps, Omit<React.ComponentPropsWithoutRef<'input'>, 'type' | 'className' | 'style'> {\n /** The HTML ID attribute to be applied to the switch element (optional). */\n id?: string;\n /** The name attribute to be applied to the switch element (optional). */\n name?: string;\n /** Whether the switch toggle should be disabled (optional). */\n disabled?: boolean;\n /** The checked state of the switch toggle, for a controlled switch (optional). */\n checked?: boolean;\n /** The default checked state of the switch toggle, for an uncontrolled switch (optional). */\n defaultChecked?: boolean;\n /** Called with the new state when the user toggles the switch. The native `onChange` gets the event. */\n onCheckedChange?(value: boolean): void;\n /**\n * Where the label goes: over the switch, as a field's label (`top`), or beside it (`end`), as a checkbox's, such as\n * in a list of settings.\n * @defaultValue 'top'\n */\n labelPosition?: 'top' | 'end';\n}\n\n/**\n * A toggle switch with a label, over it or beside it. Control it with checked and onCheckedChange, or leave it\n * uncontrolled with defaultChecked.\n */\nexport const Switch = React.forwardRef<HTMLInputElement, SwitchProps>((props, ref) => {\n const {\n id,\n label,\n name,\n disabled,\n checked: checkedProp,\n defaultChecked = false,\n description,\n keepDescription,\n error,\n className,\n style,\n onChange,\n onCheckedChange,\n labelPosition = 'top',\n ...others\n } = props;\n const beside = labelPosition === 'end';\n const [checked, setChecked] = useControllableState<boolean>({\n value: checkedProp,\n defaultValue: defaultChecked ?? false,\n onChange: onCheckedChange,\n });\n\n const uid = useUid(id);\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n onChange?.(event);\n setChecked(event.currentTarget.checked);\n };\n\n return (\n <Field\n controlId={uid}\n label={beside ? undefined : label}\n description={description}\n keepDescription={keepDescription}\n error={error}\n className={className}\n style={style}\n >\n {/* Its own label too, so a click on the toggle reaches the input; beside it, it holds the text. */}\n <label className=\"roaster-switch\">\n <input\n {...others}\n {...fieldControlProps(\n uid,\n { label: beside ? undefined : label, description, error, keepDescription },\n others\n )}\n ref={ref}\n type=\"checkbox\"\n role=\"switch\"\n className=\"roaster-switch__input\"\n name={name}\n checked={checked}\n disabled={disabled}\n onChange={handleChange}\n />\n <span className=\"roaster-switch__track\" />\n {beside && label && <span className=\"roaster-switch__label\">{label}</span>}\n </label>\n </Field>\n );\n});\n\nSwitch.displayName = 'Switch';\n"],"names":[],"mappings":";;;;;;;AAKY,MAAC,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AACV,YAAY,GAAG,MAAM;AACrB,YAAY,GAAG,iBAAiB;AAChC,cAAc,GAAG;AACjB,cAAc,EAAkC,WAAW,EAAE,KAAK,EAAE,eAAe,EAAE;AACrF,cAAc;AACd,aAAa;AACb,YAAY,GAAG;AACf,YAAY,IAAI,EAAE,UAAU;AAC5B,YAAY,IAAI,EAAE,QAAQ;AAC1B,YAAY,SAAS,EAAE,uBAAuB;AAC9C,YAAY,IAAI;AAChB,YAAY,OAAO;AACnB,YAAY,QAAQ;AACpB,YAAY,QAAQ,EAAE;AACtB;AACA,SAAS;AACT,wBAAwB,GAAG,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,uBAAuB,EAAE,CAAC;AAC3E,QAAQ,MAAM,IAAI,KAAK,oBAAoB,GAAG,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,uBAAuB,EAAE,QAAQ,EAAE,KAAK,EAAE;AAC9G,OAAO,EAAE;AACT;AACA,GAAG;AACH,CAAC;AACD,MAAM,CAAC,WAAW,GAAG,QAAQ;;"}
|
|
@@ -16,6 +16,7 @@ const TextField = React.forwardRef((props, ref) => {
|
|
|
16
16
|
onChange,
|
|
17
17
|
onValueChange,
|
|
18
18
|
description,
|
|
19
|
+
keepDescription,
|
|
19
20
|
rightSection,
|
|
20
21
|
type = "text",
|
|
21
22
|
variant,
|
|
@@ -34,7 +35,7 @@ const TextField = React.forwardRef((props, ref) => {
|
|
|
34
35
|
"input",
|
|
35
36
|
{
|
|
36
37
|
...others,
|
|
37
|
-
...fieldControlProps(uid, { description, error }, others),
|
|
38
|
+
...fieldControlProps(uid, { description, error, keepDescription }, others),
|
|
38
39
|
ref,
|
|
39
40
|
type,
|
|
40
41
|
onChange: handleChange,
|
|
@@ -56,6 +57,7 @@ const TextField = React.forwardRef((props, ref) => {
|
|
|
56
57
|
controlId: uid,
|
|
57
58
|
label,
|
|
58
59
|
description,
|
|
60
|
+
keepDescription,
|
|
59
61
|
error,
|
|
60
62
|
inline,
|
|
61
63
|
className,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextField.js","sources":["../../../../src/components/TextField/TextField.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, Slot, useUid } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps, type InlineFieldProps } from '../Field';\n\n/**\n * Every native `<input>` prop (`name`, `required`, `aria-*`, ...) is accepted and forwarded to the input, with the\n * ref. `className` and `style` go to the field's wrapper.\n */\nexport interface TextFieldProps\n extends\n FieldBaseProps,\n InlineFieldProps,\n Omit<React.ComponentPropsWithoutRef<'input'>, 'prefix' | 'className' | 'style'> {\n /** `plain` has no edge or fill, such as a reply's field in a card's footer. The focus ring stays. */\n variant?: 'plain';\n /** A prefix to display before the input. */\n prefix?: React.ReactNode;\n /** A suffix to display after the input. */\n suffix?: React.ReactNode;\n /** A section to display on the right side of the input. */\n rightSection?: React.ReactNode;\n /** Called with the new value when the user changes it. The native `onChange` gets the event. */\n onValueChange?(value: string): void;\n /** The type of the input element, such as text, email, tel, url, number, or password. */\n type?: 'text' | 'email' | 'tel' | 'url' | 'number' | 'password';\n}\n\n/**\n * A single-line text field with a label, help text, error message, and an optional prefix, suffix or right-hand\n * section.\n */\nexport const TextField = React.forwardRef<HTMLInputElement, TextFieldProps>((props, ref) => {\n const {\n id,\n label,\n error,\n prefix,\n suffix,\n onChange,\n onValueChange,\n description,\n rightSection,\n type = 'text',\n variant,\n inline,\n className,\n style,\n ...others\n } = props;\n\n const uid = useUid(id);\n const hasRightSection = rightSection != null && rightSection !== false && rightSection !== '';\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n onChange?.(event);\n onValueChange?.(event.currentTarget.value);\n };\n\n const input = (\n <input\n {...others}\n {...fieldControlProps(uid, { label, description, error }, others)}\n ref={ref}\n type={type}\n onChange={handleChange}\n className={classNames('roaster-input', variant && `roaster-input--${variant}`, {\n 'roaster-merged-inputs__start': hasRightSection,\n 'roaster-input--prefixed': prefix,\n 'roaster-input--suffixed': suffix,\n })}\n />\n );\n // The prefix and suffix sit over the input, in a group as wide as it.\n const control =\n prefix || suffix ? (\n <div className=\"roaster-input-group\">\n {prefix && <span className=\"roaster-input-group__prefix\">{prefix}</span>}\n {input}\n {suffix && <span className=\"roaster-input-group__suffix\">{suffix}</span>}\n </div>\n ) : (\n input\n );\n\n return (\n <Field\n controlId={uid}\n label={label}\n description={description}\n error={error}\n inline={inline}\n className={className}\n style={style}\n >\n {hasRightSection ? (\n <div className=\"roaster-merged-inputs\">\n {control}\n {/* An element (a Button) takes the class; text is wrapped first. */}\n <Slot className=\"roaster-merged-inputs__end\">\n {React.isValidElement(rightSection) ? rightSection : <span>{rightSection}</span>}\n </Slot>\n </div>\n ) : (\n control\n )}\n </Field>\n );\n});\n\nTextField.displayName = 'TextField';\n"],"names":[],"mappings":";;;;;;;;AAKY,MAAC,SAAS,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AAC1D,EAAE,MAAM;AACR,IAAI,EAAE;AACN,IAAI,KAAK;AACT,IAAI,KAAK;AACT,IAAI,MAAM;AACV,IAAI,MAAM;AACV,IAAI,QAAQ;AACZ,IAAI,aAAa;AACjB,IAAI,WAAW;AACf,IAAI,YAAY;AAChB,IAAI,IAAI,GAAG,MAAM;AACjB,IAAI,OAAO;AACX,IAAI,MAAM;AACV,IAAI,SAAS;AACb,IAAI,KAAK;AACT,IAAI,GAAG;AACP,GAAG,GAAG,KAAK;AACX,EAAE,MAAM,GAAG,GAAG,MAAM,CAAC,EAAE,CAAC;AACxB,EAAE,MAAM,eAAe,GAAG,YAAY,IAAI,IAAI,IAAI,YAAY,KAAK,KAAK,IAAI,YAAY,KAAK,EAAE;AAC/F,EAAE,MAAM,YAAY,GAAG,CAAC,KAAK,KAAK;AAClC,IAAI,QAAQ,GAAG,KAAK,CAAC;AACrB,IAAI,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC;AAC9C,EAAE,CAAC;AACH,EAAE,MAAM,KAAK,mBAAmB,GAAG;AACnC,IAAI,OAAO;AACX,IAAI;AACJ,MAAM,GAAG,MAAM;AACf,MAAM,GAAG,iBAAiB,CAAC,GAAG,EAAE,EAAS,WAAW,EAAE,KAAK,EAAE,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"TextField.js","sources":["../../../../src/components/TextField/TextField.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, Slot, useUid } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps, type InlineFieldProps } from '../Field';\n\n/**\n * Every native `<input>` prop (`name`, `required`, `aria-*`, ...) is accepted and forwarded to the input, with the\n * ref. `className` and `style` go to the field's wrapper.\n */\nexport interface TextFieldProps\n extends\n FieldBaseProps,\n InlineFieldProps,\n Omit<React.ComponentPropsWithoutRef<'input'>, 'prefix' | 'className' | 'style'> {\n /** `plain` has no edge or fill, such as a reply's field in a card's footer. The focus ring stays. */\n variant?: 'plain';\n /** A prefix to display before the input. */\n prefix?: React.ReactNode;\n /** A suffix to display after the input. */\n suffix?: React.ReactNode;\n /** A section to display on the right side of the input. */\n rightSection?: React.ReactNode;\n /** Called with the new value when the user changes it. The native `onChange` gets the event. */\n onValueChange?(value: string): void;\n /** The type of the input element, such as text, email, tel, url, number, or password. */\n type?: 'text' | 'email' | 'tel' | 'url' | 'number' | 'password';\n}\n\n/**\n * A single-line text field with a label, help text, error message, and an optional prefix, suffix or right-hand\n * section.\n */\nexport const TextField = React.forwardRef<HTMLInputElement, TextFieldProps>((props, ref) => {\n const {\n id,\n label,\n error,\n prefix,\n suffix,\n onChange,\n onValueChange,\n description,\n keepDescription,\n rightSection,\n type = 'text',\n variant,\n inline,\n className,\n style,\n ...others\n } = props;\n\n const uid = useUid(id);\n const hasRightSection = rightSection != null && rightSection !== false && rightSection !== '';\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n onChange?.(event);\n onValueChange?.(event.currentTarget.value);\n };\n\n const input = (\n <input\n {...others}\n {...fieldControlProps(uid, { label, description, error, keepDescription }, others)}\n ref={ref}\n type={type}\n onChange={handleChange}\n className={classNames('roaster-input', variant && `roaster-input--${variant}`, {\n 'roaster-merged-inputs__start': hasRightSection,\n 'roaster-input--prefixed': prefix,\n 'roaster-input--suffixed': suffix,\n })}\n />\n );\n // The prefix and suffix sit over the input, in a group as wide as it.\n const control =\n prefix || suffix ? (\n <div className=\"roaster-input-group\">\n {prefix && <span className=\"roaster-input-group__prefix\">{prefix}</span>}\n {input}\n {suffix && <span className=\"roaster-input-group__suffix\">{suffix}</span>}\n </div>\n ) : (\n input\n );\n\n return (\n <Field\n controlId={uid}\n label={label}\n description={description}\n keepDescription={keepDescription}\n error={error}\n inline={inline}\n className={className}\n style={style}\n >\n {hasRightSection ? (\n <div className=\"roaster-merged-inputs\">\n {control}\n {/* An element (a Button) takes the class; text is wrapped first. */}\n <Slot className=\"roaster-merged-inputs__end\">\n {React.isValidElement(rightSection) ? rightSection : <span>{rightSection}</span>}\n </Slot>\n </div>\n ) : (\n control\n )}\n </Field>\n );\n});\n\nTextField.displayName = 'TextField';\n"],"names":[],"mappings":";;;;;;;;AAKY,MAAC,SAAS,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AAC1D,EAAE,MAAM;AACR,IAAI,EAAE;AACN,IAAI,KAAK;AACT,IAAI,KAAK;AACT,IAAI,MAAM;AACV,IAAI,MAAM;AACV,IAAI,QAAQ;AACZ,IAAI,aAAa;AACjB,IAAI,WAAW;AACf,IAAI,eAAe;AACnB,IAAI,YAAY;AAChB,IAAI,IAAI,GAAG,MAAM;AACjB,IAAI,OAAO;AACX,IAAI,MAAM;AACV,IAAI,SAAS;AACb,IAAI,KAAK;AACT,IAAI,GAAG;AACP,GAAG,GAAG,KAAK;AACX,EAAE,MAAM,GAAG,GAAG,MAAM,CAAC,EAAE,CAAC;AACxB,EAAE,MAAM,eAAe,GAAG,YAAY,IAAI,IAAI,IAAI,YAAY,KAAK,KA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AAK;AACX,MAAM,MAAM;AACZ,MAAM,SAAS;AACf,MAAM,KAAK;AACX,MAAM,QAAQ,EAAE,eAAe,mBAAmB,IAAI,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,uBAAuB,EAAE,QAAQ,EAAE;AAC9G,QAAQ,OAAO;AACf,wBAAwB,GAAG,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,4BAA4B,EAAE,QAAQ,EAAE,KAAK,CAAC,cAAc,CAAC,YAAY,CAAC,GAAG,YAAY,mBAAmB,GAAG,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC,EAAE;AACpM,OAAO,EAAE,CAAC,GAAG;AACb;AACA,GAAG;AACH,CAAC;AACD,SAAS,CAAC,WAAW,GAAG,WAAW;;"}
|
|
@@ -1,27 +1,59 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { fieldControlProps, Field } from '../Field/Field.js';
|
|
5
5
|
import { useUid } from '../../utils/useUid/index.js';
|
|
6
6
|
import { classNames } from '../../utils/classNames/index.js';
|
|
7
7
|
|
|
8
8
|
const Textarea = React.forwardRef((props, ref) => {
|
|
9
|
-
const {
|
|
9
|
+
const {
|
|
10
|
+
label,
|
|
11
|
+
error,
|
|
12
|
+
id,
|
|
13
|
+
description,
|
|
14
|
+
keepDescription,
|
|
15
|
+
onChange,
|
|
16
|
+
onValueChange,
|
|
17
|
+
variant,
|
|
18
|
+
footer,
|
|
19
|
+
className,
|
|
20
|
+
style,
|
|
21
|
+
...others
|
|
22
|
+
} = props;
|
|
10
23
|
const uid = useUid(id);
|
|
24
|
+
const hasFooter = !(footer == null || typeof footer === "boolean" || footer === "");
|
|
25
|
+
const footerId = `${uid}-footer`;
|
|
11
26
|
const handleChange = (event) => {
|
|
12
27
|
onChange?.(event);
|
|
13
28
|
onValueChange?.(event.currentTarget.value);
|
|
14
29
|
};
|
|
15
|
-
|
|
30
|
+
const describedBy = [others["aria-describedby"], hasFooter && footerId].filter(Boolean).join(" ") || void 0;
|
|
31
|
+
const textarea = /* @__PURE__ */ jsx(
|
|
16
32
|
"textarea",
|
|
17
33
|
{
|
|
18
34
|
...others,
|
|
19
|
-
...fieldControlProps(uid, { description, error },
|
|
35
|
+
...fieldControlProps(uid, { description, error, keepDescription }, { "aria-describedby": describedBy }),
|
|
20
36
|
ref,
|
|
21
37
|
className: classNames("roaster-textarea", variant && `roaster-input--${variant}`),
|
|
22
38
|
onChange: handleChange
|
|
23
39
|
}
|
|
24
|
-
)
|
|
40
|
+
);
|
|
41
|
+
return /* @__PURE__ */ jsx(
|
|
42
|
+
Field,
|
|
43
|
+
{
|
|
44
|
+
controlId: uid,
|
|
45
|
+
label,
|
|
46
|
+
description,
|
|
47
|
+
keepDescription,
|
|
48
|
+
error,
|
|
49
|
+
className,
|
|
50
|
+
style,
|
|
51
|
+
children: hasFooter ? /* @__PURE__ */ jsxs("div", { className: "roaster-textarea-group", children: [
|
|
52
|
+
textarea,
|
|
53
|
+
/* @__PURE__ */ jsx("div", { className: "roaster-textarea-group__footer", id: footerId, children: footer })
|
|
54
|
+
] }) : textarea
|
|
55
|
+
}
|
|
56
|
+
);
|
|
25
57
|
});
|
|
26
58
|
Textarea.displayName = "Textarea";
|
|
27
59
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Textarea.js","sources":["../../../../src/components/Textarea/Textarea.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, useUid } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps } from '../Field';\n\n/**\n * Every native `<textarea>` prop (`name`, `rows`, `required`, `aria-*`, ...) is accepted and forwarded to the\n * textarea, with the ref. `className` and `style` go to the field's wrapper.\n */\nexport interface TextareaProps\n extends FieldBaseProps, Omit<React.ComponentPropsWithoutRef<'textarea'>, 'className' | 'style'> {\n /** Called with the new value when the user changes it. The native `onChange` gets the event. */\n onValueChange?(value: string): void;\n /** `plain` has no edge or fill, such as a comment's text area in a card. The focus ring stays. */\n variant?: 'plain';\n}\n\n/** A multiline text field with a label, help text and error message. */\nexport const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>((props, ref) => {\n const {
|
|
1
|
+
{"version":3,"file":"Textarea.js","sources":["../../../../src/components/Textarea/Textarea.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, useUid } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps } from '../Field';\n\n/**\n * Every native `<textarea>` prop (`name`, `rows`, `required`, `aria-*`, ...) is accepted and forwarded to the\n * textarea, with the ref. `className` and `style` go to the field's wrapper.\n */\nexport interface TextareaProps\n extends FieldBaseProps, Omit<React.ComponentPropsWithoutRef<'textarea'>, 'className' | 'style'> {\n /** Called with the new value when the user changes it. The native `onChange` gets the event. */\n onValueChange?(value: string): void;\n /** `plain` has no edge or fill, such as a comment's text area in a card. The focus ring stays. */\n variant?: 'plain';\n /**\n * A short text in the box, under the text at its end, such as a count of the characters: `912 / 1000`. The textarea\n * is described by it. Not with `plain`, which has no box: put it beside the card's buttons.\n */\n footer?: React.ReactNode;\n}\n\n/** A multiline text field with a label, help text and error message, and an optional footer in its box. */\nexport const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>((props, ref) => {\n const {\n label,\n error,\n id,\n description,\n keepDescription,\n onChange,\n onValueChange,\n variant,\n footer,\n className,\n style,\n ...others\n } = props;\n\n const uid = useUid(id);\n const hasFooter = !(footer == null || typeof footer === 'boolean' || footer === '');\n const footerId = `${uid}-footer`;\n\n const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {\n onChange?.(event);\n onValueChange?.(event.currentTarget.value);\n };\n\n // The footer describes the textarea after any description it already has, and before the field's texts under it.\n const describedBy = [others['aria-describedby'], hasFooter && footerId].filter(Boolean).join(' ') || undefined;\n const textarea = (\n <textarea\n {...others}\n {...fieldControlProps(uid, { label, description, error, keepDescription }, { 'aria-describedby': describedBy })}\n ref={ref}\n className={classNames('roaster-textarea', variant && `roaster-input--${variant}`)}\n onChange={handleChange}\n />\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 {hasFooter ? (\n <div className=\"roaster-textarea-group\">\n {textarea}\n <div className=\"roaster-textarea-group__footer\" id={footerId}>\n {footer}\n </div>\n </div>\n ) : (\n textarea\n )}\n </Field>\n );\n});\n\nTextarea.displayName = 'Textarea';\n"],"names":[],"mappings":";;;;;;;AAKY,MAAC,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AACzD,EAAE,MAAM;AACR,IAAI,KAAK;AACT,IAAI,KAAK;AACT,IAAI,EAAE;AACN,IAAI,WAAW;AACf,IAAI,eAAe;AACnB,IAAI,QAAQ;AACZ,IAAI,aAAa;AACjB,IAAI,OAAO;AACX,IAAI,MAAM;AACV,IAAI,SAAS;AACb,IAAI,KAAK;AACT,IAAI,GAAG;AACP,GAAG,GAAG,KAAK;AACX,EAAE,MAAM,GAAG,GAAG,MAAM,CAAC,EAAE,CAAC;AACxB,EAAE,MAAM,SAAS,GAAG,EAAE,MAAM,IAAI,IAAI,IAAI,OAAO,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,EAAE,CAAC;AACrF,EAAE,MAAM,QAAQ,GAAG,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;AAClC,EAAE,MAAM,YAAY,GAAG,CAAC,KAAK,KAAK;AAClC,IAAI,QAAQ,GAAG,KAAK,CAAC;AACrB,IAAI,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC;AAC9C,EAAE,CAAC;AACH,EAAE,MAAM,WAAW,GAAG,CAAC,MAAM,CAAC,kBAAkB,CAAC,EAAE,SAAS,IAAI,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,MAAM;AAC7G,EAAE,MAAM,QAAQ,mBAAmB,GAAG;AACtC,IAAI,UAAU;AACd,IAAI;AACJ,MAAM,GAAG,MAAM;AACf,MAAM,GAAG,iBAAiB,CAAC,GAAG,EAAE,EAAS,WAAW,EAAE,KAAK,EAAE,eAAe,EAAE,EAAE,EAAE,kBAAkB,EAAE,WAAW,EAAE,CAAC;AACpH,MAAM,GAAG;AACT,MAAM,SAAS,EAAE,UAAU,CAAC,kBAAkB,EAAE,OAAO,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,CAAC;AACvF,MAAM,QAAQ,EAAE;AAChB;AACA,GAAG;AACH,EAAE,uBAAuB,GAAG;AAC5B,IAAI,KAAK;AACT,IAAI;AACJ,MAAM,SAAS,EAAE,GAAG;AACpB,MAAM,KAAK;AACX,MAAM,WAAW;AACjB,MAAM,eAAe;AACrB,MAAM,KAAK;AACX,MAAM,SAAS;AACf,MAAM,KAAK;AACX,MAAM,QAAQ,EAAE,SAAS,mBAAmB,IAAI,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,wBAAwB,EAAE,QAAQ,EAAE;AACzG,QAAQ,QAAQ;AAChB,wBAAwB,GAAG,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,gCAAgC,EAAE,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE;AAClH,OAAO,EAAE,CAAC,GAAG;AACb;AACA,GAAG;AACH,CAAC;AACD,QAAQ,CAAC,WAAW,GAAG,UAAU;;"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { FloatingPortal } from '@floating-ui/react';
|
|
5
5
|
import { Slot } from '../../utils/Slot/index.js';
|
|
6
6
|
import { useTooltip } from './useTooltip.js';
|
|
7
7
|
import { TooltipCallout } from './TooltipCallout.js';
|
|
8
8
|
import { useControllableState } from '../../utils/useControllableState/index.js';
|
|
9
|
+
import { useMergeRefs } from '../../utils/useMergeRefs/index.js';
|
|
9
10
|
import { classNames } from '../../utils/classNames/index.js';
|
|
10
11
|
|
|
11
12
|
const TooltipBase = React.forwardRef((props, ref) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.js","sources":["../../../../src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["import * as React from 'react';\nimport {
|
|
1
|
+
{"version":3,"file":"Tooltip.js","sources":["../../../../src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["import * as React from 'react';\nimport { FloatingPortal, Placement } from '@floating-ui/react';\nimport { Slot } from '@/utils/Slot';\nimport { classNames, useControllableState, useMergeRefs } from '@/utils';\nimport { useTooltip } from './useTooltip';\nimport { TooltipCallout } from './TooltipCallout';\n\nexport type FloatingSide = Placement;\n\n/** Every native `<div>` prop (`id`, `className`, `style`, ...) is accepted and forwarded to the tooltip. */\nexport interface TooltipProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'children'> {\n /** The target: one element that takes the focus (a button, a link, or an element with `tabIndex={0}`). */\n children: React.ReactNode;\n /** The text of the tooltip. */\n label: React.ReactNode;\n /**\n * Where the tooltip goes relative to its target. It moves to the other side when there is no room.\n * @defaultValue 'top'\n */\n placement?: FloatingSide;\n /** Whether the tooltip is open, when the parent controls it. Leave it out to let hover and focus open it. */\n open?: boolean;\n /**\n * Whether the tooltip starts open, when it is not controlled.\n * @defaultValue false\n */\n defaultOpen?: boolean;\n /** Called when hover, focus or Escape opens or closes the tooltip, controlled or not. */\n onOpenChange?(open: boolean): void;\n /**\n * The distance in pixels between the tooltip and its target.\n * @defaultValue 4\n */\n offset?: number;\n /** Set it when the target is text that may wrap over several lines, so the tooltip follows the hovered line. */\n inline?: boolean;\n}\n\nconst TooltipBase = React.forwardRef<HTMLElement, TooltipProps>((props, ref) => {\n const {\n children,\n label,\n placement = 'top',\n open: openProp,\n defaultOpen = false,\n onOpenChange,\n offset = 4,\n inline = false,\n className,\n style,\n ...others\n } = props;\n\n const [open, setOpen] = useControllableState({ value: openProp, defaultValue: defaultOpen, onChange: onOpenChange });\n const tooltip = useTooltip({ placement, open, onOpenChange: setOpen, offset, inline });\n const targetRef = useMergeRefs([tooltip.refs.setReference, ref]);\n\n return (\n <>\n <Slot {...tooltip.getReferenceProps()} ref={targetRef}>\n {children}\n </Slot>\n {open && (\n <FloatingPortal>\n <div\n {...tooltip.getFloatingProps(others)}\n ref={tooltip.refs.setFloating}\n className={classNames('roaster-tooltip', 'roaster-tooltip--floating', className)}\n style={{ ...tooltip.floatingStyles, ...style }}\n data-placement={tooltip.placement}\n >\n {label}\n </div>\n </FloatingPortal>\n )}\n </>\n );\n});\n\nTooltipBase.displayName = 'Tooltip';\n\n/**\n * A short description of its target, shown while the target is hovered or has the focus, and hidden with Escape. The\n * target is described by it (`aria-describedby`). The ref goes to the target. Tooltip.Callout stays open beside its\n * host until it is closed.\n */\nexport const Tooltip = Object.assign(TooltipBase, { Callout: TooltipCallout });\n"],"names":[],"mappings":";;;;;;;;;;;AAQA,MAAM,WAAW,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AACrD,EAAE,MAAM;AACR,IAAI,QAAQ;AACZ,IAAI,KAAK;AACT,IAAI,SAAS,GAAG,KAAK;AACrB,IAAI,IAAI,EAAE,QAAQ;AAClB,IAAI,WAAW,GAAG,KAAK;AACvB,IAAI,YAAY;AAChB,IAAI,MAAM,GAAG,CAAC;AACd,IAAI,MAAM,GAAG,KAAK;AAClB,IAAI,SAAS;AACb,IAAI,KAAK;AACT,IAAI,GAAG;AACP,GAAG,GAAG,KAAK;AACX,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,oBAAoB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,CA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
import { classNames } from '../classNames/index.js';
|
|
5
4
|
import { getElementRef } from '../getElementRef/index.js';
|
|
5
|
+
import { useMergeRefs } from '../useMergeRefs/index.js';
|
|
6
6
|
|
|
7
7
|
function mergeProps(slotProps, childProps) {
|
|
8
8
|
const merged = { ...slotProps, ...childProps };
|