@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorField.js","sources":["../../../../src/components/ColorField/ColorField.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useUid, useControllableState } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps } from '../Field';\n\n/** `#abc` or `#aabbcc` as `#aabbcc`; anything else as `null`. */\nfunction toFullHex(text: string) {\n if (!/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(text)) return null;\n return (text.length === 4 ? text.replace(/[0-9a-f]/gi, (digit) => digit + digit) : text).toLowerCase();\n}\n\n/** The text of the color field, for other languages. */\nexport interface ColorFieldLabels {\n /** The name of the text input that holds the hex code, read by screen readers. */\n hex: string;\n}\n\nconst defaultColorFieldLabels: ColorFieldLabels = { hex: 'Hex color code' };\n\n/**\n * Every native `<input>` prop (`name`, `required`, `aria-*`, ...) is accepted and forwarded to the color input, with the\n * ref. `className` and `style` go to the field's wrapper.\n */\nexport interface ColorFieldProps\n extends FieldBaseProps, Omit<React.ComponentPropsWithoutRef<'input'>, 'type' | 'className' | 'style'> {\n /** The HTML ID attribute to be applied to the color field input element (optional). */\n id?: string;\n /** The name attribute to be applied to the color field input element (optional). */\n name?: string;\n /** Whether the color field input should be disabled (optional). */\n disabled?: boolean;\n /** The current value of the color field input (optional). */\n value?: string;\n /** The default value of the color field input (optional). */\n defaultValue?: string;\n /** Called with the new color when the user picks or types one. The native `onChange` gets the event. */\n onValueChange?(value: string): void;\n /** The text of the field, in English by default. */\n labels?: Partial<ColorFieldLabels>;\n}\n\n/** A color picker with a text field that shows and edits the hex value. */\nexport const ColorField = React.forwardRef<HTMLInputElement, ColorFieldProps>((props, ref) => {\n const {\n id,\n label,\n name,\n disabled,\n description,\n error,\n className,\n style,\n onChange,\n onValueChange,\n value,\n defaultValue,\n labels,\n ...others\n } = props;\n const text = { ...defaultColorFieldLabels, ...labels };\n const [internalValue, setInternalValue] = useControllableState({\n value,\n defaultValue: defaultValue ?? '',\n onChange: onValueChange,\n });\n const uid = useUid(id);\n\n // The hex text as typed: the color only follows once it is a whole code (#RGB or #RRGGBB).\n const [hexText, setHexText] = React.useState(internalValue);\n React.useEffect(() => {\n setHexText((typed) => (toFullHex(typed) === internalValue.toLowerCase() ? typed : internalValue));\n }, [internalValue]);\n\n // A whole code the value doesn't hold (a controlled field the parent didn't update) gives way to the value.\n const typedColor = toFullHex(hexText);\n const shownHex = typedColor && typedColor !== internalValue.toLowerCase() ? internalValue : hexText;\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n onChange?.(event);\n setInternalValue(event.currentTarget.value);\n };\n const handleHexChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n const typed = event.currentTarget.value;\n setHexText(typed);\n const color = toFullHex(typed);\n if (color) setInternalValue(color);\n };\n\n return (\n <Field
|
|
1
|
+
{"version":3,"file":"ColorField.js","sources":["../../../../src/components/ColorField/ColorField.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useUid, useControllableState } from '@/utils';\nimport { Field, fieldControlProps, type FieldBaseProps } from '../Field';\n\n/** `#abc` or `#aabbcc` as `#aabbcc`; anything else as `null`. */\nfunction toFullHex(text: string) {\n if (!/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(text)) return null;\n return (text.length === 4 ? text.replace(/[0-9a-f]/gi, (digit) => digit + digit) : text).toLowerCase();\n}\n\n/** The text of the color field, for other languages. */\nexport interface ColorFieldLabels {\n /** The name of the text input that holds the hex code, read by screen readers. */\n hex: string;\n}\n\nconst defaultColorFieldLabels: ColorFieldLabels = { hex: 'Hex color code' };\n\n/**\n * Every native `<input>` prop (`name`, `required`, `aria-*`, ...) is accepted and forwarded to the color input, with the\n * ref. `className` and `style` go to the field's wrapper.\n */\nexport interface ColorFieldProps\n extends FieldBaseProps, Omit<React.ComponentPropsWithoutRef<'input'>, 'type' | 'className' | 'style'> {\n /** The HTML ID attribute to be applied to the color field input element (optional). */\n id?: string;\n /** The name attribute to be applied to the color field input element (optional). */\n name?: string;\n /** Whether the color field input should be disabled (optional). */\n disabled?: boolean;\n /** The current value of the color field input (optional). */\n value?: string;\n /** The default value of the color field input (optional). */\n defaultValue?: string;\n /** Called with the new color when the user picks or types one. The native `onChange` gets the event. */\n onValueChange?(value: string): void;\n /** The text of the field, in English by default. */\n labels?: Partial<ColorFieldLabels>;\n}\n\n/** A color picker with a text field that shows and edits the hex value. */\nexport const ColorField = React.forwardRef<HTMLInputElement, ColorFieldProps>((props, ref) => {\n const {\n id,\n label,\n name,\n disabled,\n description,\n keepDescription,\n error,\n className,\n style,\n onChange,\n onValueChange,\n value,\n defaultValue,\n labels,\n ...others\n } = props;\n const text = { ...defaultColorFieldLabels, ...labels };\n const [internalValue, setInternalValue] = useControllableState({\n value,\n defaultValue: defaultValue ?? '',\n onChange: onValueChange,\n });\n const uid = useUid(id);\n\n // The hex text as typed: the color only follows once it is a whole code (#RGB or #RRGGBB).\n const [hexText, setHexText] = React.useState(internalValue);\n React.useEffect(() => {\n setHexText((typed) => (toFullHex(typed) === internalValue.toLowerCase() ? typed : internalValue));\n }, [internalValue]);\n\n // A whole code the value doesn't hold (a controlled field the parent didn't update) gives way to the value.\n const typedColor = toFullHex(hexText);\n const shownHex = typedColor && typedColor !== internalValue.toLowerCase() ? internalValue : hexText;\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n onChange?.(event);\n setInternalValue(event.currentTarget.value);\n };\n const handleHexChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n const typed = event.currentTarget.value;\n setHexText(typed);\n const color = toFullHex(typed);\n if (color) setInternalValue(color);\n };\n\n return (\n <Field\n controlId={uid}\n label={label}\n description={description}\n keepDescription={keepDescription}\n error={error}\n className={className}\n style={style}\n >\n <div className=\"roaster-merged-inputs\">\n <span className=\"roaster-color-swatch roaster-merged-inputs__start\">\n <span className=\"roaster-color-swatch__preview\" style={{ backgroundColor: internalValue }} />\n <input\n {...others}\n {...fieldControlProps(uid, { label, description, error, keepDescription }, others)}\n ref={ref}\n type=\"color\"\n className=\"roaster-color-swatch__input\"\n name={name}\n disabled={disabled}\n onChange={handleChange}\n value={internalValue}\n />\n </span>\n <input\n type=\"text\"\n className=\"roaster-input roaster-merged-inputs__end\"\n aria-label={text.hex}\n value={shownHex}\n onChange={handleHexChange}\n />\n </div>\n </Field>\n );\n});\n\nColorField.displayName = 'ColorField';\n"],"names":["React","useControllableState","useUid","jsx","Field","jsxs","fieldControlProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAKA,SAAS,SAAS,CAAC,IAAI,EAAE;AACzB,EAAE,IAAI,CAAC,+BAA+B,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,IAAI;AAC9D,EAAE,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,KAAK,KAAK,KAAK,GAAG,KAAK,CAAC,GAAG,IAAI,EAAE,WAAW,EAAE;AACxG;AACA,MAAM,uBAAuB,GAAG,EAAE,GAAG,EAAE,gBAAgB,EAAE;AAC7C,MAAC,UAAU,GAAGA,gBAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AAC3D,EAAE,MAAM;AACR,IAAI,EAAE;AACN,IAAI,KAAK;AACT,IAAI,IAAI;AACR,IAAI,Q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AAE,IAAI,CAAC,GAAG;AAClC,YAAY,KAAK,EAAE,QAAQ;AAC3B,YAAY,QAAQ,EAAE;AACtB;AACA;AACA,OAAO,EAAE;AACT;AACA,GAAG;AACH,CAAC;AACD,UAAU,CAAC,WAAW,GAAG,YAAY;;"}
|
|
@@ -7,8 +7,8 @@ var index = require('./utils/index.js');
|
|
|
7
7
|
var Calendar = require('./components/Calendar/Calendar.js');
|
|
8
8
|
var MonthGrid = require('./components/MonthGrid/MonthGrid.js');
|
|
9
9
|
var TextField = require('../TextField/TextField.js');
|
|
10
|
-
var react = require('@floating-ui/react');
|
|
11
10
|
var index$1 = require('../../utils/useControllableState/index.js');
|
|
11
|
+
var index$2 = require('../../utils/useMergeRefs/index.js');
|
|
12
12
|
|
|
13
13
|
function _interopNamespaceDefault(e) {
|
|
14
14
|
var n = Object.create(null);
|
|
@@ -67,7 +67,7 @@ const DatePickerBase = React__namespace.forwardRef(function DatePicker2(props, r
|
|
|
67
67
|
date instanceof Date ? index.formatDate(date, separator, dateFormat) : ""
|
|
68
68
|
);
|
|
69
69
|
const inputRef = React__namespace.useRef(null);
|
|
70
|
-
const mergedRef =
|
|
70
|
+
const mergedRef = index$2.useMergeRefs([inputRef, ref]);
|
|
71
71
|
const returningFocus = React__namespace.useRef(false);
|
|
72
72
|
const onFocus = () => {
|
|
73
73
|
if (returningFocus.current) returningFocus.current = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatePicker.js","sources":["../../../../src/components/DatePicker/DatePicker.tsx"],"sourcesContent":["import * as React from 'react';\nimport { dateStringParser, formatDate, getSeparatorIndex, isDateValid, pickCalendarProps } from './utils';\n\nimport { Calendar, CalendarProps } from './components';\nimport type { CalendarLabels } from './components/Calendar/Calendar';\nimport { TextField, TextFieldProps } from '../TextField';\nimport { useMergeRefs } from '@floating-ui/react';\nimport { useControllableState } from '@/utils';\nimport { MonthGrid } from './components/MonthGrid';\nimport { DateSeparator, DateFormat, DatePickerInputError } from './utils/types';\n\nexport interface DatePickerProps\n extends\n Omit<CalendarProps, 'handleDateSelection' | 'year' | 'month' | 'selected' | 'isOpen' | 'onClose'>,\n Omit<TextFieldProps, 'onChange' | 'onValueChange' | 'defaultValue' | 'value' | 'onAbort' | 'ref'> {\n /** The separator used for the date input fields. Defaults to '-' */\n separator?: DateSeparator;\n /** The format used as input mask. Defaults to 'YYYY MM DD' */\n dateFormat?: DateFormat;\n /** Callback function that will be called when an error occurs when parsing the date */\n onInputError?(type: DatePickerInputError): string;\n /** Called with the new date, or `null` when the field is cleared. */\n onValueChange?(date: Date | null): void;\n /** Default value for uncontrolled input */\n defaultValue?: Date | null;\n /** Selected date, required with controlled input */\n value?: Date | null;\n /** The month to show, from 0 to 11. 0 is January, 1 is February ... 11 is December */\n month?: number;\n /** The year to show */\n year?: number;\n /** The text of the calendar, in English by default. */\n labels?: Partial<CalendarLabels>;\n}\n\nconst DatePickerBase = React.forwardRef<HTMLInputElement, DatePickerProps>(function DatePicker(props, ref) {\n const { calendarProps, others } = pickCalendarProps(props);\n const { labels, ...inputProps } = others as typeof others & { labels?: Partial<CalendarLabels> };\n\n const {\n month,\n year,\n onValueChange,\n onInputError,\n value: passedValue,\n disableSpecificDates,\n dateFormat,\n separator,\n minDate,\n maxDate,\n defaultValue,\n onMonthChange,\n locale,\n weekStartsOn,\n } = calendarProps;\n\n const calendarRef = React.useRef<HTMLDivElement>(null);\n const [isTextFieldFocused, setIsTextFieldFocused] = React.useState(false);\n const [inputError, setInputError] = React.useState<string | boolean>(false);\n const [currentKey, setCurrentKey] = React.useState('');\n // The calendar opens on the default date's month, if there is one.\n const [{ currentDisplayedMonth, currentDisplayedYear }, setCalendarDate] = React.useState({\n currentDisplayedMonth: defaultValue ? defaultValue.getMonth() : month,\n currentDisplayedYear: defaultValue ? defaultValue.getFullYear() : year,\n });\n\n const separatorIndex = getSeparatorIndex(dateFormat);\n\n const handleMonthChange = React.useCallback(\n (targetMonth: number, targetYear: number) => {\n setCalendarDate({ currentDisplayedMonth: targetMonth, currentDisplayedYear: targetYear });\n onMonthChange?.(targetMonth, targetYear);\n },\n [onMonthChange]\n );\n\n const [date, setDate] = useControllableState<Date | null>({\n value: passedValue,\n defaultValue: defaultValue ?? null,\n onChange: onValueChange,\n });\n\n const [inputValue, setInputValue] = React.useState(\n date instanceof Date ? formatDate(date, separator, dateFormat) : ''\n );\n\n const inputRef = React.useRef<HTMLInputElement>(null);\n const mergedRef = useMergeRefs([inputRef, ref]);\n // Set while the focus goes back to the input after closing, so that focus doesn't open the calendar again.\n const returningFocus = React.useRef(false);\n const onFocus = () => {\n if (returningFocus.current) returningFocus.current = false;\n else setIsTextFieldFocused(true);\n };\n const onBlur = () => setIsTextFieldFocused(false);\n // Escape closes the calendar, and the focus goes back to the input.\n const closeToInput = React.useCallback(() => {\n setIsTextFieldFocused(false);\n // Only when the focus really moves: focusing the focused input fires no focus event to clear the flag.\n if (inputRef.current && document.activeElement !== inputRef.current) {\n returningFocus.current = true;\n inputRef.current.focus();\n }\n }, []);\n\n const handleDateSelection = React.useCallback(\n (selectedDate: Date) => {\n setInputValue(formatDate(selectedDate, separator, dateFormat));\n setDate(selectedDate);\n setCalendarDate({\n currentDisplayedMonth: selectedDate.getMonth(),\n currentDisplayedYear: selectedDate.getFullYear(),\n });\n setInputError('');\n // Chosen: the calendar closes and the focus goes back to the input.\n window.setTimeout(closeToInput, 10);\n },\n [setDate, separator, dateFormat, closeToInput]\n );\n\n // A controlled date picker shows the new value whenever the parent changes it. Compared by time, since the parent\n // may pass a new Date object for the same day on every render.\n const controlledTime = passedValue === undefined ? undefined : (passedValue?.getTime() ?? null);\n React.useEffect(() => {\n if (controlledTime === undefined) return;\n setInputValue(controlledTime === null ? '' : formatDate(new Date(controlledTime), separator, dateFormat));\n }, [controlledTime, separator, dateFormat]);\n\n function handleInputChange(value: string) {\n const valueLength = value.length;\n\n if (currentKey !== 'Backspace' && (valueLength === separatorIndex.first || valueLength === separatorIndex.second)) {\n return setInputValue(value + separator);\n }\n\n if (valueLength === 0) {\n setDate(null);\n }\n\n setInputValue(value);\n\n if (valueLength === 10) {\n const dateValue = dateStringParser(value, dateFormat, separator);\n if (!dateValue) {\n return setInputError(onInputError?.('INVALID_DATE') ?? true);\n }\n setInputError('');\n\n if (isDateValid({ date: dateValue, minDate, maxDate })) {\n return handleDateSelection(dateValue);\n }\n return setInputError(onInputError?.('OUT_OF_RANGE') ?? true);\n }\n // Still typing: the error, if any, waits for the field to lose the focus.\n setInputError('');\n }\n\n const handleInputBlur = (event: React.FocusEvent<HTMLInputElement>) => {\n others.onBlur?.(event);\n if (inputValue.length > 0 && inputValue.length < 10) setInputError(onInputError?.('INVALID_DATE') ?? true);\n };\n\n return (\n <div\n className=\"roaster-date-picker\"\n ref={calendarRef}\n // Close when the focus leaves the date picker (Tab past the calendar, or a click elsewhere).\n onBlur={(event) => {\n if (!event.currentTarget.contains(event.relatedTarget as Node | null)) onBlur();\n }}\n >\n <TextField\n {...inputProps}\n value={inputValue}\n ref={mergedRef}\n onFocus={onFocus}\n onBlur={handleInputBlur}\n maxLength={10}\n // The WAI-ARIA date picker combobox: a text input that opens a calendar dialog.\n role=\"combobox\"\n aria-haspopup=\"dialog\"\n aria-expanded={isTextFieldFocused}\n onValueChange={(value) => handleInputChange(value)}\n onKeyDown={(event) => {\n setCurrentKey(event.key);\n if (event.key === 'Escape') onBlur();\n }}\n // A typing error wins over the one the parent passes.\n error={inputError || others.error}\n />\n <Calendar\n selected={date ?? undefined}\n onClose={closeToInput}\n minDate={minDate}\n maxDate={maxDate}\n isOpen={isTextFieldFocused}\n year={currentDisplayedYear}\n month={currentDisplayedMonth}\n onMonthChange={handleMonthChange}\n handleDateSelection={handleDateSelection}\n disableSpecificDates={disableSpecificDates}\n locale={locale}\n weekStartsOn={weekStartsOn}\n labels={labels}\n />\n </div>\n );\n});\n\n/**\n * A text field with a calendar, to type or pick a date, with optional minimum and maximum dates. DatePicker.MonthGrid\n * chooses a range of whole months instead.\n */\nexport const DatePicker = Object.assign(DatePickerBase, { MonthGrid });\n"],"names":["React","pickCalendarProps","getSeparatorIndex","useControllableState","formatDate","useMergeRefs","dateStringParser","isDateValid","jsxs","jsx","TextField","Calendar","MonthGrid"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAM,cAAc,GAAGA,gBAAK,CAAC,UAAU,CAAC,SAAS,WAAW,CAAC,KAAK,EAAE,GAAG,EAAE;AACzE,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAGC,uBAAiB,CAAC,KAAK,CAAC;AAC5D,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,GAAG,MAAM;AAC1C,EAAE,MAAM;AACR,IAAI,KAAK;AACT,IAAI,IAAI;AACR,IAAI,aAAa;AACjB,IAAI,YAAY;AAChB,IAAI,KAAK,EAAE,WAAW;AACtB,IAAI,oBAAoB;AACxB,IAAI,UAAU;AACd,IAAI,SAAS;AACb,IAAI,OAAO;AACX,IAAI,OAAO;AACX,IAAI,YAAY;AAChB,IAAI,aAAa;AACjB,IAAI,MAAM;AACV,IAAI;AACJ,GAAG,GAAG,aAAa;AACnB,EAAE,MAAM,WAAW,GAAGD,gBAAK,CAAC,MAAM,CAAC,IAAI,CAAC;AACxC,EAAE,MAAM,CAAC,kBAAkB,EAAE,qBAAqB,CAAC,GAAGA,gBAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;AAC3E,EAAE,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAGA,gBAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;AAC3D,EAAE,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAGA,gBAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;AACxD,EAAE,MAAM,CAAC,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,EAAE,eAAe,CAAC,GAAGA,gBAAK,CAAC,QAAQ,CAAC;AAC5F,IAAI,qBAAqB,EAAE,YAAY,GAAG,YAAY,CAAC,QAAQ,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B;AACtC,YAAY,KAAK,EAAE,qBAAqB;AACxC,YAAY,aAAa,EAAE,iBAAiB;AAC5C,YAAY,mBAAmB;AAC/B,YAAY,oBAAoB;AAChC,YAAY,MAAM;AAClB,YAAY,YAAY;AACxB,YAAY;AACZ;AACA;AACA;AACA;AACA,GAAG;AACH,CAAC,CAAC;AACU,MAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,aAAEC,mBAAS,EAAE;;"}
|
|
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":["React","pickCalendarProps","getSeparatorIndex","useControllableState","formatDate","useMergeRefs","dateStringParser","isDateValid","jsxs","jsx","TextField","Calendar","MonthGrid"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAQA,MAAM,cAAc,GAAGA,gBAAK,CAAC,UAAU,CAAC,SAAS,WAAW,CAAC,KAAK,EAAE,GAAG,EAAE;AACzE,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAGC,uBAAiB,CAAC,KAAK,CAAC;AAC5D,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,GAAG,MAAM;AAC1C,EAAE,MAAM;AACR,IAAI,KAAK;AACT,IAAI,IAAI;AACR,IAAI,aAAa;AACjB,IAAI,YAAY;AAChB,IAAI,KAAK,EAAE,WAAW;AACtB,IAAI,oBAAoB;AACxB,IAAI,UAAU;AACd,IAAI,SAAS;AACb,IAAI,OAAO;AACX,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,YAAY,IAAI,EAAE,UAAU;AAC5B,YAAY,eAAe,EAAE,QAAQ;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,wBAAwBD,cAAG;AAC3B,UAAUE,iBAAQ;AAClB,UAAU;AACV,YAAY,QAAQ,EAAE,IAAI,IAAI,MAAM;AACpC,YAAY,OAAO,EAAE,YAAY;AACjC,YAAY,OAAO;AACnB,YAAY,OAAO;AACnB,YAAY,MAAM,EAAE,kBAAkB;AACtC,YAAY,IAAI,EAAE,oBAAoB;AACtC,YAAY,KAAK,EAAE,qBAAqB;AACxC,YAAY,aAAa,EAAE,iBAAiB;AAC5C,YAAY,mBAAmB;AAC/B,YAAY,oBAAoB;AAChC,YAAY,MAAM;AAClB,YAAY,YAAY;AACxB,YAAY;AACZ;AACA;AACA;AACA;AACA,GAAG;AACH,CAAC,CAAC;AACU,MAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,aAAEC,mBAAS,EAAE;;"}
|
|
@@ -5,8 +5,9 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var react = require('@floating-ui/react');
|
|
7
7
|
var DropdownCard_context = require('../DropdownCard.context.js');
|
|
8
|
-
var index = require('../../../utils/
|
|
9
|
-
var index$1 = require('../../../utils/
|
|
8
|
+
var index = require('../../../utils/useMergeRefs/index.js');
|
|
9
|
+
var index$1 = require('../../../utils/useMediaQuery/index.js');
|
|
10
|
+
var index$2 = require('../../../utils/classNames/index.js');
|
|
10
11
|
|
|
11
12
|
function _interopNamespaceDefault(e) {
|
|
12
13
|
var n = Object.create(null);
|
|
@@ -24,15 +25,15 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
24
25
|
const DropdownCardDropdown = React__namespace.forwardRef(
|
|
25
26
|
({ className, style, children, variant = "default", sheet = false, ...props }, propRef) => {
|
|
26
27
|
const { context: floatingContext, ...context } = DropdownCard_context.useDropdownCardContext();
|
|
27
|
-
const ref =
|
|
28
|
-
const asSheet = index.useMediaQuery(index.PHONE_QUERY) && sheet;
|
|
28
|
+
const ref = index.useMergeRefs([context.refs.setFloating, propRef]);
|
|
29
|
+
const asSheet = index$1.useMediaQuery(index$1.PHONE_QUERY) && sheet;
|
|
29
30
|
if (!context.open) return null;
|
|
30
31
|
return /* @__PURE__ */ jsxRuntime.jsx(react.FloatingFocusManager, { context: floatingContext, modal: false, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
31
32
|
"div",
|
|
32
33
|
{
|
|
33
34
|
ref,
|
|
34
35
|
...context.getFloatingProps(props),
|
|
35
|
-
className: index$
|
|
36
|
+
className: index$2.classNames(
|
|
36
37
|
"roaster-dropdown-card",
|
|
37
38
|
"roaster-dropdown-card--floating",
|
|
38
39
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DropdownCardDropdown.js","sources":["../../../../../src/components/DropdownCard/components/DropdownCardDropdown.tsx"],"sourcesContent":["import * as React from 'react';\nimport { FloatingFocusManager
|
|
1
|
+
{"version":3,"file":"DropdownCardDropdown.js","sources":["../../../../../src/components/DropdownCard/components/DropdownCardDropdown.tsx"],"sourcesContent":["import * as React from 'react';\nimport { FloatingFocusManager } from '@floating-ui/react';\nimport { useDropdownCardContext } from '../DropdownCard.context';\nimport { PHONE_QUERY, classNames, useMediaQuery, useMergeRefs } from '@/utils';\n\n/** Every native `<div>` prop (`aria-label`, `className`, `style`...) is accepted and forwarded to the card. */\nexport interface DropdownCardDropdownProps extends React.ComponentPropsWithoutRef<'div'> {\n /**\n * `compact`: a row or two of fields in a menu's frame, such as a sort order. `tabs`: a list of tabs beside the\n * content, with DropdownCard.Tabs.\n */\n variant?: 'default' | 'compact' | 'tabs';\n /**\n * On a phone (480px wide at most), the card rises from the window's bottom as a sheet, its full width, over the\n * dimmed page; on a wider screen it opens under its trigger as usual. Guidance: a sheet suits a large card, such as\n * filters or a date; a small one (`compact`) stays beside its trigger.\n * @defaultValue false\n */\n sheet?: boolean;\n}\n\n/**\n * The card: its content and actions. Rendered while the dropdown card is open, after its trigger, so Tab goes from one\n * to the other; fixed, so a parent's overflow doesn't cut it.\n */\nexport const DropdownCardDropdown = React.forwardRef<HTMLDivElement, DropdownCardDropdownProps>(\n ({ className, style, children, variant = 'default', sheet = false, ...props }, propRef) => {\n const { context: floatingContext, ...context } = useDropdownCardContext();\n const ref = useMergeRefs([context.refs.setFloating, propRef]);\n // A sheet on a phone is placed by the CSS, at the window's bottom, not beside its trigger.\n const asSheet = useMediaQuery(PHONE_QUERY) && sheet;\n if (!context.open) return null;\n\n return (\n <FloatingFocusManager context={floatingContext} modal={false}>\n <div\n ref={ref}\n {...context.getFloatingProps(props)}\n // After the spread, so a caller's className and style add to these instead of replacing them.\n className={classNames(\n 'roaster-dropdown-card',\n 'roaster-dropdown-card--floating',\n {\n 'roaster-dropdown-card--compact': variant === 'compact',\n 'roaster-dropdown-card--tabs': variant === 'tabs',\n 'roaster-dropdown-card--sheet': sheet,\n },\n className\n )}\n style={asSheet ? style : { ...context.floatingStyles, ...style }}\n >\n {children}\n </div>\n </FloatingFocusManager>\n );\n }\n);\n\nDropdownCardDropdown.displayName = 'DropdownCardDropdown';\n"],"names":["React","useDropdownCardContext","useMergeRefs","useMediaQuery","PHONE_QUERY","jsx","FloatingFocusManager","classNames"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAMY,MAAC,oBAAoB,GAAGA,gBAAK,CAAC,UAAU;AACpD,EAAE,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,GAAG,SAAS,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,OAAO,KAAK;AAC7F,IAAI,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,OAAO,EAAE,GAAGC,2CAAsB,EAAE;AAC7E,IAAI,MAAM,GAAG,GAAGC,kBAAY,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AACjE,IAAI,MAAM,OAAO,GAAGC,qBAAa,CAACC,mBAAW,CAAC,IAAI,KAAK;AACvD,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,IAAI;AAClC,IAAI,uBAAuBC,cAAG,CAACC,0BAAoB,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,kBAAkBD,cAAG;AAC5H,MAAM,KAAK;AACX,MAAM;AACN,QAAQ,GAAG;AACX,QAAQ,GAAG,OAAO,CAAC,gBAAgB,CAAC,KAAK,CAAC;AAC1C,QAAQ,SAAS,EAAEE,kBAAU;AAC7B,UAAU,uBAAuB;AACjC,UAAU,iCAAiC;AAC3C,UAAU;AACV,YAAY,gCAAgC,EAAE,OAAO,KAAK,SAAS;AACnE,YAAY,6BAA6B,EAAE,OAAO,KAAK,MAAM;AAC7D,YAAY,8BAA8B,EAAE;AAC5C,WAAW;AACX,UAAU;AACV,SAAS;AACT,QAAQ,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,EAAE,GAAG,OAAO,CAAC,cAAc,EAAE,GAAG,KAAK,EAAE;AACxE,QAAQ;AACR;AACA,KAAK,EAAE,CAAC;AACR,EAAE;AACF;AACA,oBAAoB,CAAC,WAAW,GAAG,sBAAsB;;"}
|
|
@@ -6,19 +6,39 @@ var index = require('../../utils/classNames/index.js');
|
|
|
6
6
|
|
|
7
7
|
const hasContent = (node) => !(node == null || typeof node === "boolean" || node === "");
|
|
8
8
|
const isInvalid = (error) => error != null && error !== false && error !== "";
|
|
9
|
-
function
|
|
10
|
-
const
|
|
9
|
+
function messageIds(controlId, { description, error, keepDescription }) {
|
|
10
|
+
const showsError = hasContent(error);
|
|
11
|
+
const showsDescription = hasContent(description) && (!showsError || !!keepDescription);
|
|
12
|
+
return {
|
|
13
|
+
descriptionId: showsDescription ? `${controlId}-message` : void 0,
|
|
14
|
+
errorId: showsError ? `${controlId}-${showsDescription ? "error" : "message"}` : void 0
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function fieldControlProps(controlId, messages, ariaProps = {}) {
|
|
18
|
+
const { descriptionId, errorId } = messageIds(controlId, messages);
|
|
11
19
|
return {
|
|
12
20
|
id: controlId,
|
|
13
|
-
"aria-invalid": isInvalid(error) ? true : void 0,
|
|
14
|
-
"aria-describedby": [ariaProps["aria-describedby"],
|
|
21
|
+
"aria-invalid": isInvalid(messages.error) ? true : void 0,
|
|
22
|
+
"aria-describedby": [ariaProps["aria-describedby"], descriptionId, errorId].filter(Boolean).join(" ") || void 0
|
|
15
23
|
};
|
|
16
24
|
}
|
|
17
|
-
function Field({
|
|
25
|
+
function Field({
|
|
26
|
+
controlId,
|
|
27
|
+
label,
|
|
28
|
+
description,
|
|
29
|
+
error,
|
|
30
|
+
keepDescription,
|
|
31
|
+
inline,
|
|
32
|
+
className,
|
|
33
|
+
style,
|
|
34
|
+
children
|
|
35
|
+
}) {
|
|
36
|
+
const { descriptionId, errorId } = messageIds(controlId, { description, error, keepDescription });
|
|
18
37
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: index.classNames("roaster-field", { "roaster-field--inline": inline }, className), style, children: [
|
|
19
38
|
hasContent(label) && /* @__PURE__ */ jsxRuntime.jsx("label", { className: "roaster-field__label", htmlFor: controlId, children: label }),
|
|
20
39
|
children,
|
|
21
|
-
|
|
40
|
+
descriptionId && /* @__PURE__ */ jsxRuntime.jsx("small", { className: "roaster-field__help", id: descriptionId, children: description }),
|
|
41
|
+
errorId && /* @__PURE__ */ jsxRuntime.jsx("small", { className: "roaster-field__error", id: errorId, children: error })
|
|
22
42
|
] });
|
|
23
43
|
}
|
|
24
44
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.js","sources":["../../../../src/components/Field/Field.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames } from '@/utils';\n\n/** The props every form field shares: its label, help text and error. */\nexport interface FieldBaseProps {\n /** The label shown above the control. */\n label?: React.ReactNode;\n /** Help text shown under the control. */\n description?: React.ReactNode;\n /**\n * An error shown under the control, in place of the help text
|
|
1
|
+
{"version":3,"file":"Field.js","sources":["../../../../src/components/Field/Field.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames } from '@/utils';\n\n/** The props every form field shares: its label, help text and error. */\nexport interface FieldBaseProps {\n /** The label shown above the control. */\n label?: React.ReactNode;\n /** Help text shown under the control. */\n description?: React.ReactNode;\n /**\n * An error shown under the control, in place of the help text unless `keepDescription`. It also marks the control as\n * invalid; `true` marks it invalid without a message.\n */\n error?: React.ReactNode;\n /**\n * Keeps the help text when there is an error, which then shows under it: for help that stays useful while the value\n * is wrong, such as the format it needs. A count of the characters goes in a Textarea's `footer`.\n * @defaultValue false\n */\n keepDescription?: boolean;\n /** Classes added to the field's wrapper (the label, the control and the text under it). */\n className?: string;\n /** Styles added to the field's wrapper. */\n style?: React.CSSProperties;\n}\n\n/** A field whose control can sit on its label's row: TextField and Select. */\nexport interface InlineFieldProps {\n /** The label at the start of a row and the control at its end, at its own width, such as a setting in a menu. */\n inline?: boolean;\n}\n\nexport interface FieldProps extends FieldBaseProps, InlineFieldProps {\n /** The id of the control, which the label points at. */\n controlId: string;\n /** The control, with the props that tie it to the label and the text under it (`fieldControlProps`). */\n children: React.ReactNode;\n}\n\n/** Whether there is something to show: not nothing, not a boolean, not an empty string. */\nconst hasContent = (node: React.ReactNode) => !(node == null || typeof node === 'boolean' || node === '');\nconst isInvalid = (error: React.ReactNode) => error != null && error !== false && error !== '';\n\n/**\n * The ids of the texts under the control: the help text or the error, both with `keepDescription`. The one shown alone\n * is `<id>-message`; with both, the error is `<id>-error`.\n */\nfunction messageIds(\n controlId: string,\n { description, error, keepDescription }: Pick<FieldBaseProps, 'description' | 'error' | 'keepDescription'>\n) {\n const showsError = hasContent(error);\n const showsDescription = hasContent(description) && (!showsError || !!keepDescription);\n return {\n descriptionId: showsDescription ? `${controlId}-message` : undefined,\n errorId: showsError ? `${controlId}-${showsDescription ? 'error' : 'message'}` : undefined,\n };\n}\n\n/** The ARIA props a control may already have, which the field keeps. */\nexport interface ControlAriaProps {\n 'aria-describedby'?: string;\n}\n\n/**\n * The props that tie a control to its field: its id, `aria-invalid` when there is an error, and `aria-describedby`\n * pointing at the help text, the error, or both (after any the control already has). The label names it through `for`.\n */\nexport function fieldControlProps(\n controlId: string,\n messages: Pick<FieldBaseProps, 'label' | 'description' | 'error' | 'keepDescription'>,\n ariaProps: ControlAriaProps = {}\n) {\n const { descriptionId, errorId } = messageIds(controlId, messages);\n return {\n id: controlId,\n 'aria-invalid': isInvalid(messages.error) ? true : undefined,\n 'aria-describedby': [ariaProps['aria-describedby'], descriptionId, errorId].filter(Boolean).join(' ') || undefined,\n };\n}\n\n/**\n * The frame of a form field: the label, the control, and the help text or error under it, or both. Each field renders\n * one, and passes `fieldControlProps` to its control.\n */\nexport function Field({\n controlId,\n label,\n description,\n error,\n keepDescription,\n inline,\n className,\n style,\n children,\n}: FieldProps) {\n const { descriptionId, errorId } = messageIds(controlId, { description, error, keepDescription });\n return (\n <div className={classNames('roaster-field', { 'roaster-field--inline': inline }, className)} style={style}>\n {hasContent(label) && (\n <label className=\"roaster-field__label\" htmlFor={controlId}>\n {label}\n </label>\n )}\n {children}\n {descriptionId && (\n <small className=\"roaster-field__help\" id={descriptionId}>\n {description}\n </small>\n )}\n {errorId && (\n <small className=\"roaster-field__error\" id={errorId}>\n {error}\n </small>\n )}\n </div>\n );\n}\n"],"names":["jsxs","classNames","j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AAC;AACtB,EAAE,SAAS;AACX,EAAE,KAAK;AACP,EAAE,WAAW;AACb,EAAE,KAAK;AACP,EAAE,eAAe;AACjB,EAAE,MAAM;AACR,EAAE,SAAS;AACX,EAAE,KAAK;AACP,EAAE;AACF,CAAC,EAAE;AACH,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC,SAAS,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC;AACnG,EAAE,uBAAuBA,eAAI,CAAC,KAAK,EAAE,EAAE,SAAS,EAAEC,gBAAU,CAAC,eAAe,EAAE,EAAE,uBAAuB,EAAE,MAAM,EAAE,EAAE,SAAS,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE;AAChJ,IAAI,UAAU,CAAC,KAAK,CAAC,oBAAoBC,cAAG,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,sBAAsB,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AACjI,IAAI,QAAQ;AACZ,IAAI,aAAa,oBAAoBA,cAAG,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,qBAAqB,EAAE,EAAE,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;AACjI,IAAI,OAAO,oBAAoBA,cAAG,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,sBAAsB,EAAE,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE;AAC/G,GAAG,EAAE,CAAC;AACN;;;"}
|
|
@@ -61,6 +61,7 @@ const FileField = React__namespace.forwardRef((props, ref) => {
|
|
|
61
61
|
name,
|
|
62
62
|
disabled,
|
|
63
63
|
description,
|
|
64
|
+
keepDescription,
|
|
64
65
|
error,
|
|
65
66
|
className,
|
|
66
67
|
style,
|
|
@@ -83,37 +84,49 @@ const FileField = React__namespace.forwardRef((props, ref) => {
|
|
|
83
84
|
onChange?.(event);
|
|
84
85
|
onValueChange?.(chosen);
|
|
85
86
|
};
|
|
86
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
87
|
-
|
|
87
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
88
|
+
Field.Field,
|
|
88
89
|
{
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
90
|
+
controlId: uid,
|
|
91
|
+
label,
|
|
92
|
+
description,
|
|
93
|
+
keepDescription,
|
|
94
|
+
error,
|
|
95
|
+
className,
|
|
96
|
+
style,
|
|
97
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
98
|
+
"div",
|
|
99
|
+
{
|
|
100
|
+
className: index$1.classNames("roaster-file", `roaster-file--${size}`),
|
|
101
|
+
"data-state": files.length > 0 ? "filled" : void 0,
|
|
102
|
+
children: [
|
|
103
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: type === "image" ? "roaster-file__image" : "roaster-file__preview", children: files.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx(EmptyMarkupPlaceholder, { type, defaultValue, noFileLabel: text.noFile }) : /* @__PURE__ */ jsxRuntime.jsx(Preview, { type, files }) }),
|
|
104
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "roaster-file__button", children: [
|
|
105
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
|
|
106
|
+
/* @__PURE__ */ jsxRuntime.jsx(Icon.Icon, { name: "arrow-up-from-bracket" }),
|
|
107
|
+
text.upload,
|
|
108
|
+
hint && /* @__PURE__ */ jsxRuntime.jsx("small", { className: "roaster-file__hint", children: hint })
|
|
109
|
+
] }),
|
|
110
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
111
|
+
"input",
|
|
112
|
+
{
|
|
113
|
+
...others,
|
|
114
|
+
...Field.fieldControlProps(uid, { description, error, keepDescription }, others),
|
|
115
|
+
name,
|
|
116
|
+
ref,
|
|
117
|
+
className: "roaster-file__input",
|
|
118
|
+
type: "file",
|
|
119
|
+
disabled,
|
|
120
|
+
accept,
|
|
121
|
+
onChange: handleChange
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
] })
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
)
|
|
115
128
|
}
|
|
116
|
-
)
|
|
129
|
+
);
|
|
117
130
|
});
|
|
118
131
|
FileField.displayName = "FileField";
|
|
119
132
|
|
|
@@ -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":["jsxs","Fragment","jsx","Icon","React","useUid","Field","classNames","fieldControlProps"],"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,uBAAuBA,eAAI,CAACC,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AAoBD,cAAG,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,oBAAoB,EAAE,QAAQ,EAAE,IAAI,EAAE;AACpG,WAAW,EAAE,CAAC;AACd,0BAA0BA,cAAG;AAC7B,YAAY,OAAO;AACnB,YAAY;AACZ,cAAc,GAAG,MAAM;AACvB,cAAc,GAAGM,uBAAiB,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":["jsxs","Fragment","jsx","Icon","React","useUid","Field","classNames","fieldControlProps"],"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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AACvF,8BAA8BA,eAAI,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE;AACvD,gCAAgCE,cAAG,CAACC,SAAI,EAAE,EAAE,IAAI,EAAE,uBAAuB,EAAE,CAAC;AAC5E,gBAAgB,IAAI,CAAC,MAAM;AAC3B,gBAAgB,IAAI,oBAAoBD,cAAG,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,oBAAoB,EAAE,QAAQ,EAAE,IAAI,EAAE;AACxG,eAAe,EAAE,CAAC;AAClB,8BAA8BA,cAAG;AACjC,gBAAgB,OAAO;AACvB,gBAAgB;AAChB,kBAAkB,GAAG,MAAM;AAC3B,kBAAkB,GAAGM,uBAAiB,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;;"}
|
|
@@ -28,6 +28,7 @@ const RangeField = React__namespace.forwardRef((props, ref) => {
|
|
|
28
28
|
value,
|
|
29
29
|
min = 0,
|
|
30
30
|
description,
|
|
31
|
+
keepDescription,
|
|
31
32
|
disabled,
|
|
32
33
|
onChange,
|
|
33
34
|
onValueChange,
|
|
@@ -52,27 +53,39 @@ const RangeField = React__namespace.forwardRef((props, ref) => {
|
|
|
52
53
|
onChange?.(event);
|
|
53
54
|
setInternalValue(Number(event.currentTarget.value));
|
|
54
55
|
};
|
|
55
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
56
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
57
|
+
Field.Field,
|
|
58
|
+
{
|
|
59
|
+
controlId: uid,
|
|
60
|
+
label,
|
|
61
|
+
description,
|
|
62
|
+
keepDescription,
|
|
63
|
+
error,
|
|
64
|
+
className,
|
|
65
|
+
style,
|
|
66
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "roaster-range", children: [
|
|
67
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
68
|
+
"input",
|
|
69
|
+
{
|
|
70
|
+
...others,
|
|
71
|
+
...Field.fieldControlProps(uid, { description, error, keepDescription }, others),
|
|
72
|
+
ref,
|
|
73
|
+
className: "roaster-range__input",
|
|
74
|
+
min,
|
|
75
|
+
max,
|
|
76
|
+
name,
|
|
77
|
+
step,
|
|
78
|
+
type: "range",
|
|
79
|
+
disabled,
|
|
80
|
+
value: current,
|
|
81
|
+
onChange: handleChange,
|
|
82
|
+
style: { "--roaster-range-percent": `${fillPercentage}%` }
|
|
83
|
+
}
|
|
84
|
+
),
|
|
85
|
+
/* @__PURE__ */ jsxRuntime.jsx("output", { className: "roaster-range__value", htmlFor: uid, children: current })
|
|
86
|
+
] })
|
|
87
|
+
}
|
|
88
|
+
);
|
|
76
89
|
});
|
|
77
90
|
RangeField.displayName = "RangeField";
|
|
78
91
|
|
|
@@ -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":["React","useControllableState","useUid","jsx","Field","jsxs","fieldControlProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAKY,MAAC,UAAU,GAAGA,gBAAK,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,GAAGC,0BAAoB,CAAC;AACjE,IAAI,KAAK;AACT,IAAI,YAAY;AAChB,IAAI,QAAQ,EAAE;AACd,GAAG,CAAC;AACJ,EAAE,MAAM,GAAG,GAAGC,cAAM,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,GAAG;AACzB,EAAE,MAAM,cAAc,GAAG,KAAK,GAAG,CAAC,GAAG,GAAG,IAAI,OAAO,GAAG,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC;AACtE,EAAE,MAAM,YAAY,GAAG,CAAC,KAAK,KAAK;AAClC,IAAI,QAAQ,GAAG,KAAK,CAAC;AACrB,IAAI,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AACvD,EAAE,CAAC;AACH,EAAE,uBAAuBC,cAAG;AAC5B,IAAIC,WAAK;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,kBAAkBC,eAAI,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,eAAe,EAAE,QAAQ,EAAE;AACpF,wBAAwBF,cAAG;AAC3B,UAAU,OAAO;AACjB,UAAU;AACV,YAAY,GAAG,MAAM;AACrB,YAAY,GAAGG,uBAAiB,CAAC,GAAG,EAAE,EAAS,WAAW,EAAE,KAAK,EAAE,eAAe,EAAE,EAAE,MAAM,CAAC;AAC7F,YAAY,GAAG;AACf,YAAY,SAAS,EAAE,sBAAsB;AAC7C,YAAY,GAAG;AACf,YAAY,GAAG;AACf,YAAY,IAAI;AAChB,YAAY,IAAI;AAChB,YAAY,IAAI,EAAE,OAAO;AACzB,YAAY,QAAQ;AACpB,YAAY,KAAK,EAAE,OAAO;AAC1B,YAAY,QAAQ,EAAE,YAAY;AAClC,YAAY,KAAK,EAAE,EAAE,yBAAyB,EAAE,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC;AACpE;AACA,SAAS;AACT,wBAAwBH,cAAG,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,sBAAsB,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE;AAC5G,OAAO,EAAE;AACT;AACA,GAAG;AACH,CAAC;AACD,UAAU,CAAC,WAAW,GAAG,YAAY;;"}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
-
var react = require('@floating-ui/react');
|
|
6
5
|
var React = require('react');
|
|
7
6
|
var Field = require('../Field/Field.js');
|
|
8
7
|
var index = require('../../utils/useUid/index.js');
|
|
9
|
-
var index$1 = require('../../utils/
|
|
8
|
+
var index$1 = require('../../utils/useMergeRefs/index.js');
|
|
9
|
+
var index$2 = require('../../utils/classNames/index.js');
|
|
10
10
|
|
|
11
11
|
function _interopNamespaceDefault(e) {
|
|
12
12
|
var n = Object.create(null);
|
|
@@ -46,6 +46,7 @@ const SelectBase = React__namespace.forwardRef((props, ref) => {
|
|
|
46
46
|
options,
|
|
47
47
|
placeholder,
|
|
48
48
|
description,
|
|
49
|
+
keepDescription,
|
|
49
50
|
prefix,
|
|
50
51
|
prefixWidth = prefix ? 24 : 12,
|
|
51
52
|
onChange,
|
|
@@ -62,7 +63,7 @@ const SelectBase = React__namespace.forwardRef((props, ref) => {
|
|
|
62
63
|
} = props;
|
|
63
64
|
const uid = index.useUid(id);
|
|
64
65
|
const selectRef = React__namespace.useRef(null);
|
|
65
|
-
const mergedRef =
|
|
66
|
+
const mergedRef = index$1.useMergeRefs([selectRef, ref]);
|
|
66
67
|
const items = options.map(optionResolver);
|
|
67
68
|
useSelectedContent(selectRef, rich && items.some((item) => item.description));
|
|
68
69
|
const optionElements = items.map((item) => /* @__PURE__ */ jsxRuntime.jsxs("option", { value: item.value, disabled: item.disabled, children: [
|
|
@@ -83,19 +84,20 @@ const SelectBase = React__namespace.forwardRef((props, ref) => {
|
|
|
83
84
|
controlId: uid,
|
|
84
85
|
label,
|
|
85
86
|
description,
|
|
87
|
+
keepDescription,
|
|
86
88
|
error,
|
|
87
89
|
inline,
|
|
88
90
|
className,
|
|
89
91
|
style,
|
|
90
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: index$
|
|
92
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: index$2.classNames({ "roaster-input-group": prefix }), children: [
|
|
91
93
|
prefix && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "roaster-input-group__prefix", children: prefix }),
|
|
92
94
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
93
95
|
"select",
|
|
94
96
|
{
|
|
95
97
|
...others,
|
|
96
|
-
...Field.fieldControlProps(uid, { description, error }, others),
|
|
98
|
+
...Field.fieldControlProps(uid, { description, error, keepDescription }, others),
|
|
97
99
|
ref: mergedRef,
|
|
98
|
-
className: index$
|
|
100
|
+
className: index$2.classNames("roaster-select", { "roaster-select--prefixed": prefix, "roaster-select--rich": rich }),
|
|
99
101
|
style: { paddingLeft: prefixWidth },
|
|
100
102
|
defaultValue: startValue,
|
|
101
103
|
onChange: handleChange,
|