@propellerads/select 9.0.0 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -7
- package/dist/index.js +8 -12
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -87,19 +87,20 @@ Whether the field is drawn is decided by the props being passed, not by their
|
|
|
87
87
|
values: write `error={isValid ? undefined : '…'}`, so the select stays put while
|
|
88
88
|
the error comes and goes.
|
|
89
89
|
|
|
90
|
-
###
|
|
90
|
+
### Ids
|
|
91
91
|
|
|
92
|
-
`id` names
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
`id` names the wrapper, as it did up to v8: products' styles and QA tests find
|
|
93
|
+
the select by it and reach the input inside. The input is `inputId`, or
|
|
94
|
+
`${id}-input` when none is passed. The select's own `label` points at the input
|
|
95
|
+
by itself. A `Label` the form writes points at the input too, to focus the
|
|
96
|
+
select on a click and name it for a screen reader:
|
|
95
97
|
|
|
96
98
|
```tsx
|
|
97
|
-
<Label label="Brand" for="brand" />
|
|
99
|
+
<Label label="Brand" for="brand-input" />
|
|
98
100
|
<Select id="brand" options={brands} />
|
|
99
101
|
```
|
|
100
102
|
|
|
101
|
-
|
|
102
|
-
`id`. The `!` mark (`error-label-${id}`) and the clear cross (`${id}-clear`) keep
|
|
103
|
+
The `!` mark (`error-label-${id}`) and the clear cross (`${id}-clear`) keep
|
|
103
104
|
their ids.
|
|
104
105
|
|
|
105
106
|
### Inside another control's field
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import re from "react-select/async-creatable";
|
|
|
8
8
|
import ie from "react-select/creatable";
|
|
9
9
|
import { clsx as g } from "clsx";
|
|
10
10
|
import { Fragment as _, jsx as v, jsxs as y } from "react/jsx-runtime";
|
|
11
|
-
import './index.css'
|
|
11
|
+
import './index.css';// src/cn.ts
|
|
12
12
|
var b = (...e) => g(e), x = {
|
|
13
13
|
Danger: "danger",
|
|
14
14
|
Warning: "warning"
|
|
@@ -162,7 +162,7 @@ var b = (...e) => g(e), x = {
|
|
|
162
162
|
}
|
|
163
163
|
return e.split(/\s+/);
|
|
164
164
|
}, _e = (e) => e.flatMap((e) => e && typeof e == "object" && "options" in e ? [...e.options] : [e]), j = u((t, n) => {
|
|
165
|
-
let { id: r, inputId: a, elementId: o, errors: u = [], showErrors: f, isErrorLabelVisible: h, tone: g = x.Danger, icon: _ = null, isCreatable: S = !1, isAsync: C = !1, onCreateOption: w, createOptionPlaceholder: T = "Create ", minSearchLength: E, searchableKeys: D = he, promiseOptions: O, customStyles: k, actionColor: A, minHeightInput: j, styles: M, classNames: ve, components: N, className: ye, isMulti: P, isDisabled: F = !1, isLoading: be, isSearchable: xe, isOptionDisabled: Se, placeholder: Ce = "Select", menuPlacement: we = "auto", loadOptions: Te, noOptionsMessage:
|
|
165
|
+
let { id: r, inputId: a, elementId: o, errors: u = [], showErrors: f, isErrorLabelVisible: h, tone: g = x.Danger, icon: _ = null, isCreatable: S = !1, isAsync: C = !1, onCreateOption: w, createOptionPlaceholder: T = "Create ", minSearchLength: E, searchableKeys: D = he, promiseOptions: O, customStyles: k, actionColor: A, minHeightInput: j, styles: M, classNames: ve, components: N, className: ye, isMulti: P, isDisabled: F = !1, isLoading: be, isSearchable: xe, isOptionDisabled: Se, placeholder: Ce = "Select", menuPlacement: we = "auto", loadOptions: Te, noOptionsMessage: Ee, formatCreateLabel: I, options: L, value: R, onChange: z, ...B } = t, De = ee(), V = r ?? o ?? De, H = a ?? `${V}-input`, U = s(), Oe = c(), W = l(), ke = u.length > 0 || W !== void 0, Ae = W ?? g, [G, K] = te(!1), q = p(!0), J = p(null);
|
|
166
166
|
d(() => () => {
|
|
167
167
|
q.current = !1;
|
|
168
168
|
}, []);
|
|
@@ -197,11 +197,11 @@ var b = (...e) => g(e), x = {
|
|
|
197
197
|
Control: oe
|
|
198
198
|
}, Z = {
|
|
199
199
|
...B,
|
|
200
|
-
id:
|
|
200
|
+
id: V,
|
|
201
201
|
inputId: H,
|
|
202
202
|
"aria-invalid": B["aria-invalid"] ?? (U?.isInvalid || void 0),
|
|
203
203
|
library: {
|
|
204
|
-
id:
|
|
204
|
+
id: V,
|
|
205
205
|
inputId: H,
|
|
206
206
|
errors: u,
|
|
207
207
|
showErrors: f ?? h ?? !0,
|
|
@@ -228,17 +228,14 @@ var b = (...e) => g(e), x = {
|
|
|
228
228
|
},
|
|
229
229
|
classNames: me(ve),
|
|
230
230
|
components: Pe,
|
|
231
|
-
noOptionsMessage: (e) => e.inputValue.length < Y ? `Enter ${Y} or more characters` :
|
|
231
|
+
noOptionsMessage: (e) => e.inputValue.length < Y ? `Enter ${Y} or more characters` : Ee?.(e) ?? "No options",
|
|
232
232
|
ref: je
|
|
233
233
|
}, Q = {
|
|
234
|
-
formatCreateLabel:
|
|
234
|
+
formatCreateLabel: I ?? ((e) => `${T}"${e}"`),
|
|
235
235
|
...w && { onCreateOption: Me }
|
|
236
236
|
}, $ = { loadOptions: (e, t) => {
|
|
237
|
-
if (e.length < Y || !X)
|
|
238
|
-
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
return X(e, t);
|
|
237
|
+
if (e.length < Y || !X) t([]);
|
|
238
|
+
else return X(e, t);
|
|
242
239
|
} }, Fe = () => C && S ? /* @__PURE__ */ v(re, {
|
|
243
240
|
...Z,
|
|
244
241
|
...Q,
|
|
@@ -284,7 +281,6 @@ var b = (...e) => g(e), x = {
|
|
|
284
281
|
});
|
|
285
282
|
});
|
|
286
283
|
M.displayName = "Select";
|
|
287
|
-
//#endregion
|
|
288
284
|
export { M as Select, M as default, x as SelectTone, h as components };
|
|
289
285
|
|
|
290
286
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/cn.ts","../src/types.ts","../src/index.tsx"],"sourcesContent":["import {type ClassValue, clsx} from 'clsx';\n\n/**\n * Joins class names. There is no tailwind-merge here on purpose: the select\n * ships its own stylesheet instead of utility classes, so there is nothing to\n * deduplicate.\n */\nconst cn = (...inputs: ClassValue[]): string => clsx(inputs);\n\nexport {cn};\n","import type {FieldOwnProps as LabelFieldOwnProps} from '@propellerads/label';\nimport type {ReactNode, Ref} from 'react';\nimport type {GroupBase, SelectInstance, StylesConfig} from 'react-select';\nimport type {AsyncProps} from 'react-select/async';\nimport type {CreatableProps} from 'react-select/creatable';\n\nexport type Option = {\n value: number | string;\n label: ReactNode;\n /** Read by `isOptionDisabled` when the caller passes one. */\n isOptionDisabled?: boolean;\n /** A chosen value the product flags: its chip takes the danger colours. */\n isException?: boolean;\n};\n\nexport type OptionGroup<O = Option> = GroupBase<O>;\n\n/** Which colour the old `errors` are shown in. */\nexport const SelectTone = {\n Danger: 'danger',\n Warning: 'warning',\n} as const;\nexport type SelectTone = (typeof SelectTone)[keyof typeof SelectTone];\n\n/**\n * The field around the select: its label and its message, laid out by Label's\n * `Field`. Given any of `label`, `description`, `error` or `warning`, the\n * select draws the field itself, with the message behind a mark among the\n * indicators by default.\n */\ntype FieldOwnProps = LabelFieldOwnProps & {\n /** Sets `required`, which the input says with `aria-required`. No mark: the optional fields are the ones marked. */\n isRequired?: boolean;\n};\n\ntype OwnProps<O, M extends boolean, G extends GroupBase<O>> = FieldOwnProps & {\n /**\n * Names the select's input, so `<Label for={id}>` and a click on it find the\n * select; also its `!` mark (`error-label-${id}`) and its clear cross\n * (`${id}-clear`). react-select's `inputId`, when passed, names the input instead.\n */\n id?: string;\n /**\n * @deprecated Use `error`, or `warning` for the warning tone. The `!` mark\n * among the indicators and the contour in the tone.\n */\n errors?: ReadonlyArray<string>;\n /** @deprecated Hides the `!` mark of `errors` and keeps the contour. Use `error` with `messageDisplay`. @default true */\n showErrors?: boolean;\n /** @deprecated Use `warning` instead of `errors` with `tone=\"warning\"`. @default 'danger' */\n tone?: SelectTone;\n /** An icon at the start of the field. */\n icon?: ReactNode;\n /** Lets the user add an option that is not in the list. */\n isCreatable?: boolean;\n /** Loads the options with `loadOptions` as the user types. */\n isAsync?: boolean;\n /** Called with the text of a new option. A promise shows the spinner until it settles. */\n onCreateOption?: (inputValue: string) => void | Promise<void>;\n /** What the create row starts with: `Create \"…\"`. @default 'Create ' */\n createOptionPlaceholder?: string;\n /** How many characters an async search waits for; it says so until then. @default 0 */\n minSearchLength?: number;\n /**\n * The option keys a pasted list is matched against. Pasting \"a, b, c\" into a\n * multi select picks every option whose key equals one of the parts.\n * @default ['label']\n */\n searchableKeys?: Array<keyof O>;\n ref?: Ref<SelectInstance<O, M, G>>;\n\n /** @deprecated TagsInput's name for `id`. */\n elementId?: string;\n /** @deprecated TagsInput's name for `showErrors`. Use `error` with `messageDisplay`. */\n isErrorLabelVisible?: boolean;\n /** @deprecated TagsInput's name for `styles`. */\n customStyles?: StylesConfig<O, M, G>;\n /** @deprecated TagsInput's async loader: `loadOptions` with a two-character minimum. */\n promiseOptions?: (inputValue: string) => Promise<ReadonlyArray<O | G>>;\n /** @deprecated TagsInput's chip colour. Set `--select-chip-bg` on an ancestor instead. */\n actionColor?: string;\n /** @deprecated The field grows with its chips. Accepted and ignored. */\n minHeightInput?: number;\n};\n\n/**\n * Every prop of react-select, of its async and creatable flavours, and the\n * library's own. Nothing is dropped on the way to react-select.\n */\nexport type SelectProps<O = Option, M extends boolean = boolean, G extends GroupBase<O> = GroupBase<O>> = Omit<\n Partial<AsyncProps<O, M, G> & CreatableProps<O, M, G>>,\n 'id' | 'onCreateOption'\n> &\n OwnProps<O, M, G>;\n","import {Field as BaseField} from '@base-ui-components/react/field';\nimport ErrorLabel from '@propellerads/error-label';\nimport {\n ControlField,\n FieldMark,\n hasFieldProps,\n MessageDisplay,\n splitFieldProps,\n useFieldIds,\n useFieldMessage,\n useFieldTone,\n} from '@propellerads/label';\nimport {\n type ClipboardEvent,\n type ComponentType,\n type CSSProperties,\n type ForwardedRef,\n forwardRef,\n type KeyboardEvent,\n type MouseEvent,\n type ReactElement,\n type ReactNode,\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\nimport ReactSelect, {\n type ActionMeta,\n type ClassNamesConfig,\n type ClearIndicatorProps,\n type ControlProps,\n type DropdownIndicatorProps,\n type GroupBase,\n type IndicatorsContainerProps,\n type LoadingIndicatorProps,\n type MultiValueRemoveProps,\n type OnChangeValue,\n type OptionProps,\n components as reactSelectComponents,\n type SelectComponentsConfig,\n type SelectInstance,\n type StylesConfig,\n} from 'react-select';\nimport AsyncSelect from 'react-select/async';\nimport AsyncCreatableSelect from 'react-select/async-creatable';\nimport CreatableSelect from 'react-select/creatable';\nimport './select.css';\nimport {cn} from './cn';\nimport {type Option, type OptionGroup, type SelectProps, SelectTone} from './types';\n\n/*\n * react-select, unstyled, with every part given a class from select.css. The\n * behaviour — keyboard, search, async, creatable, multi, portals — is\n * react-select's own, and every prop it takes reaches it. What the library adds\n * rides on `selectProps.library`, so the parts below can stay the same\n * components across renders: a part created inside a render would remount the\n * menu on every keystroke.\n */\n\ntype Library = {\n id: string;\n inputId: string;\n errors: ReadonlyArray<string>;\n showErrors: boolean;\n tone: SelectTone;\n icon: ReactNode;\n /** The field's mark stands with the indicators in the compact display. */\n hasFieldMark: boolean;\n /** The ids of the field's message, which the input is described by. */\n describedBy: string | undefined;\n /** The control that draws the box: ours, or the one a product passed in `components`. */\n control: ComponentType<ControlProps<unknown, boolean, GroupBase<unknown>>>;\n};\n\ntype AnyProps = {selectProps: unknown};\n\nconst libraryOf = (props: AnyProps): Library => (props.selectProps as {library: Library}).library;\n\nconst ChevronIcon = () => (\n <svg viewBox=\"0 0 16 16\" width=\"16\" height=\"16\" fill=\"none\" aria-hidden=\"true\">\n <path d=\"M4 6l4 4 4-4\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n </svg>\n);\n\nconst CrossIcon = ({size = 16}: {size?: number}) => (\n <svg viewBox=\"0 0 16 16\" width={size} height={size} fill=\"none\" aria-hidden=\"true\">\n <path d=\"M4.5 4.5l7 7M11.5 4.5l-7 7\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n </svg>\n);\n\nconst CheckIcon = () => (\n <svg viewBox=\"0 0 16 16\" width=\"16\" height=\"16\" fill=\"none\" aria-hidden=\"true\">\n <path d=\"M3 8.5l3 3 7-7\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n </svg>\n);\n\n// A layout effect, so the ids are back before the browser paints or a screen\n// reader looks; on a server there is no DOM to fix, and React warns about one.\nconst useIsoLayoutEffect = typeof document === 'undefined' ? useEffect : useLayoutEffect;\n\n/** The ids in an `aria-describedby`. */\nconst idsOf = (value: string | null | undefined): string[] => (value ?? '').split(' ').filter(Boolean);\n\n/**\n * Describes the input by the field's message. react-select writes the input's\n * `aria-describedby` itself — the placeholder, the live region — and takes none\n * from outside, and the input of a select that is not searchable cannot be\n * replaced. So the ids are added to whatever react-select wrote, after every\n * render of react-select: React rewrites the attribute only when react-select's\n * own value changes, and then the ids go back on. `added` remembers what was\n * added last, so a message that is gone leaves no id behind.\n */\nconst useDescribedBy = (inputId: string, describedBy: string | undefined) => {\n const added = useRef<string[]>([]);\n\n useIsoLayoutEffect(() => {\n // Outside a field there is nothing to add.\n const input = describedBy || added.current.length > 0 ? document.getElementById(inputId) : null;\n if (!input) {\n return;\n }\n const next = idsOf(describedBy);\n const own = idsOf(input.getAttribute('aria-describedby')).filter(\n (id) => !added.current.includes(id) && !next.includes(id),\n );\n const value = [...own, ...next].join(' ');\n added.current = next;\n if (value === '') {\n input.removeAttribute('aria-describedby');\n } else if (input.getAttribute('aria-describedby') !== value) {\n input.setAttribute('aria-describedby', value);\n }\n });\n};\n\nconst Control = <O, M extends boolean, G extends GroupBase<O>>({children, ...props}: ControlProps<O, M, G>) => {\n const {icon} = libraryOf(props);\n\n return (\n <reactSelectComponents.Control {...props}>\n {icon && <span className=\"select__icon\">{icon}</span>}\n {children}\n </reactSelectComponents.Control>\n );\n};\n\n/**\n * Whichever control draws the box — ours, or a product's from `components` —\n * goes inside this one, which describes the input by the field's message. It\n * renders with every render of react-select, the moment react-select may have\n * rewritten the input's `aria-describedby`, so the ids go back on even when a\n * product replaces the control.\n */\nconst DescribedControl = <O, M extends boolean, G extends GroupBase<O>>(props: ControlProps<O, M, G>) => {\n const {inputId, describedBy, control: Own} = libraryOf(props);\n useDescribedBy(inputId, describedBy);\n\n return <Own {...(props as unknown as ControlProps<unknown, boolean, GroupBase<unknown>>)} />;\n};\n\n// The field opens its menu on mousedown, and on Space, which it then cancels:\n// a mark keeps both for itself, so a click or Space opens its bubble. Escape\n// goes on, for the bubble to close on.\nconst keepMouseDown = (event: MouseEvent) => event.stopPropagation();\nconst keepSpace = (event: KeyboardEvent) => {\n if (event.key === ' ') {\n event.stopPropagation();\n }\n};\n\n/** The `!` mark stands with the other indicators, before the clear cross and the chevron. */\nconst IndicatorsContainer = <O, M extends boolean, G extends GroupBase<O>>({\n children,\n ...props\n}: IndicatorsContainerProps<O, M, G>) => {\n const {id, errors, showErrors, tone, hasFieldMark} = libraryOf(props);\n\n return (\n <reactSelectComponents.IndicatorsContainer {...props}>\n {hasFieldMark && (\n <span className=\"select__mark\" onMouseDown={keepMouseDown} onKeyDown={keepSpace}>\n <FieldMark />\n </span>\n )}\n {showErrors && errors.length > 0 && (\n // The field opens its menu on mousedown; the mark keeps its own click.\n <span className=\"select__errors\" onMouseDown={(event) => event.stopPropagation()}>\n <ErrorLabel\n elementId={id}\n errors={[...errors]}\n errorColor={tone === SelectTone.Warning ? 'var(--color-warning)' : undefined}\n />\n </span>\n )}\n {children}\n </reactSelectComponents.IndicatorsContainer>\n );\n};\n\nconst DropdownIndicator = <O, M extends boolean, G extends GroupBase<O>>(props: DropdownIndicatorProps<O, M, G>) => (\n <reactSelectComponents.DropdownIndicator {...props}>\n <ChevronIcon />\n </reactSelectComponents.DropdownIndicator>\n);\n\n/** The clear cross keeps TagsInput's `${id}-clear`, which products and tests find it by. */\nconst ClearIndicator = <O, M extends boolean, G extends GroupBase<O>>(props: ClearIndicatorProps<O, M, G>) => {\n const {id} = libraryOf(props);\n\n return (\n <reactSelectComponents.ClearIndicator {...props} innerProps={{...props.innerProps, id: `${id}-clear`}}>\n <CrossIcon />\n </reactSelectComponents.ClearIndicator>\n );\n};\n\nconst MultiValueRemove = <O, M extends boolean, G extends GroupBase<O>>(props: MultiValueRemoveProps<O, M, G>) => (\n <reactSelectComponents.MultiValueRemove {...props}>\n <CrossIcon size={12} />\n </reactSelectComponents.MultiValueRemove>\n);\n\n/** A single select marks the chosen item with a check, as shadcn's does. */\nconst OptionWithCheck = <O, M extends boolean, G extends GroupBase<O>>({children, ...props}: OptionProps<O, M, G>) => (\n <reactSelectComponents.Option {...props}>\n {children}\n {props.isSelected && !props.isMulti && (\n <span className=\"select__option-check\">\n <CheckIcon />\n </span>\n )}\n </reactSelectComponents.Option>\n);\n\nconst LoadingIndicator = <O, M extends boolean, G extends GroupBase<O>>({\n innerProps,\n}: LoadingIndicatorProps<O, M, G>) => (\n <span {...innerProps} className=\"select__indicator select__loading-indicator\" role=\"status\" aria-label=\"Loading\" />\n);\n\n// What the field's control renders: nothing, see `registration` below.\nconst renderNothing = () => <></>;\n\n/** The class every part takes. A product's own `classNames` is added after ours. */\nconst partClassNames = <O, M extends boolean, G extends GroupBase<O>>(\n own: ClassNamesConfig<O, M, G> = {},\n): ClassNamesConfig<O, M, G> => {\n const ours: ClassNamesConfig<O, M, G> = {\n control: (state) =>\n cn(\n 'select__control',\n state.isFocused && 'select__control--focused',\n state.isDisabled && 'select__control--disabled',\n state.menuIsOpen && 'select__control--menu-is-open',\n ),\n valueContainer: (state) =>\n cn(\n 'select__value-container',\n state.isMulti && 'select__value-container--is-multi',\n state.hasValue && 'select__value-container--has-value',\n ),\n placeholder: () => 'select__placeholder',\n singleValue: () => 'select__single-value',\n input: () => 'select__input-container',\n indicatorsContainer: () => 'select__indicators',\n indicatorSeparator: () => 'select__indicator-separator',\n dropdownIndicator: () => 'select__indicator select__dropdown-indicator',\n clearIndicator: () => 'select__indicator select__clear-indicator',\n loadingIndicator: () => 'select__indicator select__loading-indicator',\n multiValue: (state) =>\n cn('select__multi-value', (state.data as Option).isException && 'select__multi-value--exception'),\n multiValueLabel: () => 'select__multi-value-label',\n multiValueRemove: () => 'select__multi-value-remove',\n menu: (state) => cn('select__menu', state.placement === 'top' && 'select__menu--top'),\n menuPortal: () => 'select__menu-portal',\n menuList: () => 'select__menu-list',\n option: (state) =>\n cn(\n 'select__option',\n state.isFocused && 'select__option--focused',\n state.isSelected && 'select__option--selected',\n state.isDisabled && 'select__option--disabled',\n ),\n group: () => 'select__group',\n groupHeading: () => 'select__group-heading',\n noOptionsMessage: () => 'select__menu-notice',\n loadingMessage: () => 'select__menu-notice',\n };\n\n const merged: ClassNamesConfig<O, M, G> = {...ours};\n\n for (const key of Object.keys(own) as Array<keyof ClassNamesConfig<O, M, G>>) {\n const mine = ours[key] as ((state: unknown) => string) | undefined;\n const theirs = own[key] as ((state: unknown) => string) | undefined;\n (merged as Record<string, (state: unknown) => string>)[key] = (state) => cn(mine?.(state), theirs?.(state));\n }\n\n return merged;\n};\n\nconst DEFAULT_KEYS = ['label'];\n\n/** The parts of a pasted list, split the way TagsInput did: by lines, by \", \", by \",\", or by spaces. */\nconst splitPasted = (text: string): string[] => {\n for (const separator of [/\\n+/, /,\\s/, /,+/]) {\n const parts = text.split(separator);\n if (parts.length > 1) {\n return parts;\n }\n }\n\n return text.split(/\\s+/);\n};\n\nconst flatten = <O, G extends GroupBase<O>>(options: ReadonlyArray<O | G>): O[] =>\n options.flatMap((item) =>\n item && typeof item === 'object' && 'options' in item ? [...(item as G).options] : [item as O],\n );\n\n/** The select in its box: the contour, the indicators and the old `errors` mark. */\nconst SelectBoxInner = <O = Option, M extends boolean = false, G extends GroupBase<O> = OptionGroup<O>>(\n props: SelectProps<O, M, G>,\n ref: ForwardedRef<SelectInstance<O, M, G>>,\n) => {\n const {\n id: idProp,\n inputId: inputIdProp,\n elementId,\n errors = [],\n showErrors,\n isErrorLabelVisible,\n tone = SelectTone.Danger,\n icon = null,\n isCreatable = false,\n isAsync = false,\n onCreateOption,\n createOptionPlaceholder = 'Create ',\n minSearchLength,\n searchableKeys = DEFAULT_KEYS as Array<keyof O>,\n promiseOptions,\n customStyles,\n actionColor,\n minHeightInput: _minHeightInput,\n styles,\n classNames,\n components,\n className,\n isMulti,\n isDisabled = false,\n isLoading,\n isSearchable,\n isOptionDisabled,\n placeholder = 'Select',\n menuPlacement = 'auto',\n loadOptions,\n noOptionsMessage,\n formatCreateLabel,\n options,\n value,\n onChange,\n ...rest\n } = props;\n\n const fallbackId = useId();\n const id = idProp ?? elementId ?? fallbackId;\n // The id goes to the input, where `<Label for>` and a click on the label find\n // it; react-select would give it to its wrapper and name the input itself.\n const inputId = inputIdProp ?? idProp ?? elementId ?? fallbackId;\n // The ids of the field the select stands in: react-select's input is not a\n // Base UI control, so it is described and marked invalid by hand.\n const fieldIds = useFieldIds();\n const fieldMessage = useFieldMessage();\n // The field's error or warning draws the contour in its tone.\n const fieldTone = useFieldTone();\n const isInvalid = errors.length > 0 || fieldTone !== undefined;\n const shownTone = fieldTone ?? tone;\n\n const [isCreating, setCreating] = useState(false);\n const isMounted = useRef(true);\n const selectRef = useRef<SelectInstance<O, M, G> | null>(null);\n\n useEffect(\n () => () => {\n isMounted.current = false;\n },\n [],\n );\n\n const setRef = (instance: SelectInstance<O, M, G> | null): void => {\n selectRef.current = instance;\n if (typeof ref === 'function') {\n ref(instance);\n } else if (ref) {\n ref.current = instance;\n }\n };\n\n // TagsInput waited for two characters before it asked the server.\n const minimum = minSearchLength ?? (promiseOptions ? 2 : 0);\n const loader = loadOptions ?? promiseOptions;\n\n const handleCreateOption = async (inputValue: string): Promise<void> => {\n if (!onCreateOption) {\n return;\n }\n\n try {\n setCreating(true);\n await onCreateOption(inputValue);\n } finally {\n if (isMounted.current) {\n setCreating(false);\n }\n }\n };\n\n // Pasting a list into a multi select picks the options it names.\n const handlePaste = (event: ClipboardEvent<HTMLDivElement>): void => {\n if (!isMulti || !options || !onChange) {\n return;\n }\n\n const parts = splitPasted(event.clipboardData.getData('text/plain'))\n .map((part) => part.trim().toLowerCase())\n .filter(Boolean);\n\n if (parts.length < 2) {\n return;\n }\n\n const found = flatten<O, G>(options).filter((option) =>\n searchableKeys.some((key: keyof O) => parts.includes(String(option[key]).toLowerCase())),\n );\n\n if (found.length === 0) {\n return;\n }\n\n const current = (Array.isArray(value) ? value : []) as O[];\n const next = [...current, ...found.filter((option) => !current.includes(option))];\n\n event.preventDefault();\n onChange(next as unknown as OnChangeValue<O, M>, {action: 'select-option', option: found[0]} as ActionMeta<O>);\n setTimeout(() => selectRef.current?.blur(), 0);\n };\n\n const parts: Partial<SelectComponentsConfig<O, M, G>> = {\n IndicatorsContainer,\n IndicatorSeparator: null,\n DropdownIndicator,\n ClearIndicator,\n MultiValueRemove,\n Option: OptionWithCheck,\n LoadingIndicator,\n ...components,\n // A product's control goes inside ours, which keeps the input described.\n Control: DescribedControl,\n };\n\n const selectProps = {\n ...rest,\n // The wrapper keeps the id only when the input has a name of its own.\n id: inputIdProp === undefined ? undefined : (idProp ?? elementId),\n inputId,\n 'aria-invalid': rest['aria-invalid'] ?? (fieldIds?.isInvalid || undefined),\n library: {\n id,\n inputId,\n errors,\n showErrors: showErrors ?? isErrorLabelVisible ?? true,\n tone,\n icon,\n hasFieldMark: fieldMessage?.display === MessageDisplay.Compact,\n describedBy: fieldIds?.describedBy,\n control: (components?.Control ?? Control) as Library['control'],\n } satisfies Library,\n unstyled: true,\n options,\n value,\n onChange,\n isMulti,\n placeholder,\n menuPlacement,\n // v5 of the single select was not searchable by default; TagsInput was.\n isSearchable: isSearchable ?? Boolean(isMulti),\n // v5 of the single select ignored `isDisabled` on options unless told otherwise.\n isOptionDisabled: isOptionDisabled ?? (isMulti ? undefined : () => false),\n isDisabled: isDisabled || isCreating,\n isLoading: isLoading || isCreating,\n styles: {...customStyles, ...styles} as StylesConfig<O, M, G>,\n classNames: partClassNames(classNames),\n components: parts,\n noOptionsMessage: (input: {inputValue: string}) =>\n input.inputValue.length < minimum\n ? `Enter ${minimum} or more characters`\n : (noOptionsMessage?.(input) ?? 'No options'),\n ref: setRef,\n };\n\n const creatableProps = {\n formatCreateLabel: formatCreateLabel ?? ((inputValue: string) => `${createOptionPlaceholder}\"${inputValue}\"`),\n ...(onCreateOption && {onCreateOption: handleCreateOption}),\n };\n\n const asyncProps = {\n loadOptions: (inputValue: string, callback: (options: ReadonlyArray<O | G>) => void) => {\n if (inputValue.length < minimum || !loader) {\n callback([]);\n return undefined;\n }\n\n return loader(inputValue, callback);\n },\n };\n\n // The four flavours of react-select share one set of props; the casts only\n // tell TypeScript which flavour it is looking at.\n const renderSelect = () => {\n if (isAsync && isCreatable) {\n return <AsyncCreatableSelect {...(selectProps as object)} {...creatableProps} {...asyncProps} />;\n }\n if (isAsync) {\n return <AsyncSelect {...(selectProps as object)} {...asyncProps} />;\n }\n if (isCreatable) {\n return <CreatableSelect {...(selectProps as object)} {...creatableProps} />;\n }\n return <ReactSelect {...(selectProps as object)} />;\n };\n\n // Base UI points the field's label at the control registered with the field\n // and keeps that registry to itself: `Field.Control` is the one way in. So it\n // registers the input's id and renders nothing — the input is react-select's,\n // named by the same id, and the label's `for` finds it.\n const registration = fieldIds && <BaseField.Control id={inputId} render={renderNothing} />;\n\n const style = actionColor\n ? ({'--select-chip-bg': actionColor, '--select-chip-text': 'var(--color-light)'} as CSSProperties)\n : undefined;\n\n return (\n <div\n className={cn(\n 'select',\n isInvalid && 'select--invalid',\n shownTone === SelectTone.Warning && 'select--warning',\n className,\n )}\n data-is-disabled={isDisabled}\n style={style}\n onPaste={handlePaste}\n >\n {registration}\n {renderSelect()}\n </div>\n );\n};\n\n// `forwardRef` does not keep the generics, so the types are written out by hand.\nconst SelectBox = forwardRef(SelectBoxInner) as unknown as <\n O = Option,\n M extends boolean = false,\n G extends GroupBase<O> = OptionGroup<O>,\n>(\n props: SelectProps<O, M, G> & {ref?: ForwardedRef<SelectInstance<O, M, G>>},\n) => ReactElement;\n\n/**\n * A select on react-select with the library's look: one field for a single\n * value, several as chips, a list that loads as the user types, and new values\n * the user creates. Every react-select prop is accepted and passed on.\n *\n * With a `label`, a `description`, an `error` or a `warning` it draws its\n * field: the label on top, on the left or hidden, and the message behind a mark\n * among the indicators or, with `messageDisplay=\"line\"`, under it.\n */\nconst SelectInner = <O = Option, M extends boolean = false, G extends GroupBase<O> = OptionGroup<O>>(\n props: SelectProps<O, M, G>,\n ref: ForwardedRef<SelectInstance<O, M, G>>,\n) => {\n const {field, rest} = splitFieldProps(props);\n const {isRequired, ...control} = rest;\n const required = isRequired || control.required;\n\n if (!hasFieldProps(props)) {\n return <SelectBox<O, M, G> {...control} ref={ref} required={required} />;\n }\n\n return (\n <ControlField\n field={field}\n errors={control.errors}\n tone={control.tone}\n isDisabled={control.isDisabled}\n className=\"select-field\"\n >\n {/* The errors are the field's now, written by it. */}\n <SelectBox<O, M, G> {...control} errors={undefined} ref={ref} required={required} />\n </ControlField>\n );\n};\n\nconst Select = forwardRef(SelectInner) as unknown as (<\n O = Option,\n M extends boolean = false,\n G extends GroupBase<O> = OptionGroup<O>,\n>(\n props: SelectProps<O, M, G>,\n) => ReactElement) & {displayName?: string};\nSelect.displayName = 'Select';\n\nexport default Select;\n\nexport type {Option, OptionGroup, SelectProps};\nexport {reactSelectComponents as components, Select, SelectTone};\n"],"mappings":";;;;;;;;;;;AAOA,IAAM,KAAM,GAAG,MAAiC,EAAK,EAAO,ECW/C,IAAa;CACxB,QAAQ;CACR,SAAS;CACV,ECyDK,KAAa,MAA8B,EAAM,YAAmC,SAEpF,UACJ,kBAAC,OAAD;CAAK,SAAQ;CAAY,OAAM;CAAK,QAAO;CAAK,MAAK;CAAO,eAAY;WACtE,kBAAC,QAAD;EAAM,GAAE;EAAe,QAAO;EAAe,aAAY;EAAM,eAAc;EAAQ,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AAS,QAAQ,KAAA;GAAgB;GAAe;GAAY,CAAA;EACvE,CAAA,GAbR,kBAAC,GAAD;EAAoB,GAAI;EAAc;EAAe;EAAY,CAAA;EAiBtC;AAOtC,EAAO,cAAc"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_Fragment","BaseField","ErrorLabel","ReactSelect","reactSelectComponents","AsyncSelect","AsyncCreatableSelect","CreatableSelect","cn","inputs","clsx","SelectTone","libraryOf","props","ChevronIcon","CrossIcon","size","CheckIcon","useIsoLayoutEffect","useEffect","useLayoutEffect","idsOf","value","useDescribedBy","added","useRef","input","describedBy","inputId","next","id","Control","icon","children","DescribedControl","Own","keepMouseDown","event","keepSpace","IndicatorsContainer","hasFieldMark","FieldMark","showErrors","errors","tone","DropdownIndicator","ClearIndicator","MultiValueRemove","OptionWithCheck","LoadingIndicator","innerProps","renderNothing","Fragment","partClassNames","ours","state","merged","key","own","mine","theirs","DEFAULT_KEYS","splitPasted","separator","parts","text","flatten","options","item","SelectBox","forwardRef","idProp","inputIdProp","_minHeightInput","rest","fallbackId","useId","elementId","fieldIds","useFieldIds","fieldMessage","useFieldMessage","fieldTone","useFieldTone","isInvalid","shownTone","isCreating","setCreating","useState","isMounted","selectRef","setRef","instance","ref","minimum","minSearchLength","promiseOptions","loader","loadOptions","handleCreateOption","onCreateOption","inputValue","handlePaste","isMulti","onChange","part","found","searchableKeys","option","current","components","selectProps","isErrorLabelVisible","MessageDisplay","isSearchable","isOptionDisabled","isDisabled","isLoading","customStyles","styles","classNames","noOptionsMessage","creatableProps","formatCreateLabel","createOptionPlaceholder","asyncProps","callback","renderSelect","isAsync","isCreatable","registration","Field","style","actionColor","className","Select","splitFieldProps","control","required","isRequired","hasFieldProps","ControlField"],"sources":["../src/cn.ts","../src/types.ts","../src/index.tsx"],"sourcesContent":["import {type ClassValue, clsx} from 'clsx';\n\n/**\n * Joins class names. There is no tailwind-merge here on purpose: the select\n * ships its own stylesheet instead of utility classes, so there is nothing to\n * deduplicate.\n */\nconst cn = (...inputs: ClassValue[]): string => clsx(inputs);\n\nexport {cn};\n","import type {FieldOwnProps as LabelFieldOwnProps} from '@propellerads/label';\nimport type {ReactNode, Ref} from 'react';\nimport type {GroupBase, SelectInstance, StylesConfig} from 'react-select';\nimport type {AsyncProps} from 'react-select/async';\nimport type {CreatableProps} from 'react-select/creatable';\n\nexport type Option = {\n value: number | string;\n label: ReactNode;\n /** Read by `isOptionDisabled` when the caller passes one. */\n isOptionDisabled?: boolean;\n /** A chosen value the product flags: its chip takes the danger colours. */\n isException?: boolean;\n};\n\nexport type OptionGroup<O = Option> = GroupBase<O>;\n\n/** Which colour the old `errors` are shown in. */\nexport const SelectTone = {\n Danger: 'danger',\n Warning: 'warning',\n} as const;\nexport type SelectTone = (typeof SelectTone)[keyof typeof SelectTone];\n\n/**\n * The field around the select: its label and its message, laid out by Label's\n * `Field`. Given any of `label`, `description`, `error` or `warning`, the\n * select draws the field itself, with the message behind a mark among the\n * indicators by default.\n */\ntype FieldOwnProps = LabelFieldOwnProps & {\n /** Sets `required`, which the input says with `aria-required`. No mark: the optional fields are the ones marked. */\n isRequired?: boolean;\n};\n\ntype OwnProps<O, M extends boolean, G extends GroupBase<O>> = FieldOwnProps & {\n /**\n * Names the select's input, so `<Label for={id}>` and a click on it find the\n * select; also its `!` mark (`error-label-${id}`) and its clear cross\n * (`${id}-clear`). react-select's `inputId`, when passed, names the input instead.\n */\n id?: string;\n /**\n * @deprecated Use `error`, or `warning` for the warning tone. The `!` mark\n * among the indicators and the contour in the tone.\n */\n errors?: ReadonlyArray<string>;\n /** @deprecated Hides the `!` mark of `errors` and keeps the contour. Use `error` with `messageDisplay`. @default true */\n showErrors?: boolean;\n /** @deprecated Use `warning` instead of `errors` with `tone=\"warning\"`. @default 'danger' */\n tone?: SelectTone;\n /** An icon at the start of the field. */\n icon?: ReactNode;\n /** Lets the user add an option that is not in the list. */\n isCreatable?: boolean;\n /** Loads the options with `loadOptions` as the user types. */\n isAsync?: boolean;\n /** Called with the text of a new option. A promise shows the spinner until it settles. */\n onCreateOption?: (inputValue: string) => void | Promise<void>;\n /** What the create row starts with: `Create \"…\"`. @default 'Create ' */\n createOptionPlaceholder?: string;\n /** How many characters an async search waits for; it says so until then. @default 0 */\n minSearchLength?: number;\n /**\n * The option keys a pasted list is matched against. Pasting \"a, b, c\" into a\n * multi select picks every option whose key equals one of the parts.\n * @default ['label']\n */\n searchableKeys?: Array<keyof O>;\n ref?: Ref<SelectInstance<O, M, G>>;\n\n /** @deprecated TagsInput's name for `id`. */\n elementId?: string;\n /** @deprecated TagsInput's name for `showErrors`. Use `error` with `messageDisplay`. */\n isErrorLabelVisible?: boolean;\n /** @deprecated TagsInput's name for `styles`. */\n customStyles?: StylesConfig<O, M, G>;\n /** @deprecated TagsInput's async loader: `loadOptions` with a two-character minimum. */\n promiseOptions?: (inputValue: string) => Promise<ReadonlyArray<O | G>>;\n /** @deprecated TagsInput's chip colour. Set `--select-chip-bg` on an ancestor instead. */\n actionColor?: string;\n /** @deprecated The field grows with its chips. Accepted and ignored. */\n minHeightInput?: number;\n};\n\n/**\n * Every prop of react-select, of its async and creatable flavours, and the\n * library's own. Nothing is dropped on the way to react-select.\n */\nexport type SelectProps<O = Option, M extends boolean = boolean, G extends GroupBase<O> = GroupBase<O>> = Omit<\n Partial<AsyncProps<O, M, G> & CreatableProps<O, M, G>>,\n 'id' | 'onCreateOption'\n> &\n OwnProps<O, M, G>;\n","import {Field as BaseField} from '@base-ui-components/react/field';\nimport ErrorLabel from '@propellerads/error-label';\nimport {\n ControlField,\n FieldMark,\n hasFieldProps,\n MessageDisplay,\n splitFieldProps,\n useFieldIds,\n useFieldMessage,\n useFieldTone,\n} from '@propellerads/label';\nimport {\n type ClipboardEvent,\n type ComponentType,\n type CSSProperties,\n type ForwardedRef,\n forwardRef,\n type KeyboardEvent,\n type MouseEvent,\n type ReactElement,\n type ReactNode,\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\nimport ReactSelect, {\n type ActionMeta,\n type ClassNamesConfig,\n type ClearIndicatorProps,\n type ControlProps,\n type DropdownIndicatorProps,\n type GroupBase,\n type IndicatorsContainerProps,\n type LoadingIndicatorProps,\n type MultiValueRemoveProps,\n type OnChangeValue,\n type OptionProps,\n components as reactSelectComponents,\n type SelectComponentsConfig,\n type SelectInstance,\n type StylesConfig,\n} from 'react-select';\nimport AsyncSelect from 'react-select/async';\nimport AsyncCreatableSelect from 'react-select/async-creatable';\nimport CreatableSelect from 'react-select/creatable';\nimport './select.css';\nimport {cn} from './cn';\nimport {type Option, type OptionGroup, type SelectProps, SelectTone} from './types';\n\n/*\n * react-select, unstyled, with every part given a class from select.css. The\n * behaviour — keyboard, search, async, creatable, multi, portals — is\n * react-select's own, and every prop it takes reaches it. What the library adds\n * rides on `selectProps.library`, so the parts below can stay the same\n * components across renders: a part created inside a render would remount the\n * menu on every keystroke.\n */\n\ntype Library = {\n id: string;\n inputId: string;\n errors: ReadonlyArray<string>;\n showErrors: boolean;\n tone: SelectTone;\n icon: ReactNode;\n /** The field's mark stands with the indicators in the compact display. */\n hasFieldMark: boolean;\n /** The ids of the field's message, which the input is described by. */\n describedBy: string | undefined;\n /** The control that draws the box: ours, or the one a product passed in `components`. */\n control: ComponentType<ControlProps<unknown, boolean, GroupBase<unknown>>>;\n};\n\ntype AnyProps = {selectProps: unknown};\n\nconst libraryOf = (props: AnyProps): Library => (props.selectProps as {library: Library}).library;\n\nconst ChevronIcon = () => (\n <svg viewBox=\"0 0 16 16\" width=\"16\" height=\"16\" fill=\"none\" aria-hidden=\"true\">\n <path d=\"M4 6l4 4 4-4\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n </svg>\n);\n\nconst CrossIcon = ({size = 16}: {size?: number}) => (\n <svg viewBox=\"0 0 16 16\" width={size} height={size} fill=\"none\" aria-hidden=\"true\">\n <path d=\"M4.5 4.5l7 7M11.5 4.5l-7 7\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n </svg>\n);\n\nconst CheckIcon = () => (\n <svg viewBox=\"0 0 16 16\" width=\"16\" height=\"16\" fill=\"none\" aria-hidden=\"true\">\n <path d=\"M3 8.5l3 3 7-7\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n </svg>\n);\n\n// A layout effect, so the ids are back before the browser paints or a screen\n// reader looks; on a server there is no DOM to fix, and React warns about one.\nconst useIsoLayoutEffect = typeof document === 'undefined' ? useEffect : useLayoutEffect;\n\n/** The ids in an `aria-describedby`. */\nconst idsOf = (value: string | null | undefined): string[] => (value ?? '').split(' ').filter(Boolean);\n\n/**\n * Describes the input by the field's message. react-select writes the input's\n * `aria-describedby` itself — the placeholder, the live region — and takes none\n * from outside, and the input of a select that is not searchable cannot be\n * replaced. So the ids are added to whatever react-select wrote, after every\n * render of react-select: React rewrites the attribute only when react-select's\n * own value changes, and then the ids go back on. `added` remembers what was\n * added last, so a message that is gone leaves no id behind.\n */\nconst useDescribedBy = (inputId: string, describedBy: string | undefined) => {\n const added = useRef<string[]>([]);\n\n useIsoLayoutEffect(() => {\n // Outside a field there is nothing to add.\n const input = describedBy || added.current.length > 0 ? document.getElementById(inputId) : null;\n if (!input) {\n return;\n }\n const next = idsOf(describedBy);\n const own = idsOf(input.getAttribute('aria-describedby')).filter(\n (id) => !added.current.includes(id) && !next.includes(id),\n );\n const value = [...own, ...next].join(' ');\n added.current = next;\n if (value === '') {\n input.removeAttribute('aria-describedby');\n } else if (input.getAttribute('aria-describedby') !== value) {\n input.setAttribute('aria-describedby', value);\n }\n });\n};\n\nconst Control = <O, M extends boolean, G extends GroupBase<O>>({children, ...props}: ControlProps<O, M, G>) => {\n const {icon} = libraryOf(props);\n\n return (\n <reactSelectComponents.Control {...props}>\n {icon && <span className=\"select__icon\">{icon}</span>}\n {children}\n </reactSelectComponents.Control>\n );\n};\n\n/**\n * Whichever control draws the box — ours, or a product's from `components` —\n * goes inside this one, which describes the input by the field's message. It\n * renders with every render of react-select, the moment react-select may have\n * rewritten the input's `aria-describedby`, so the ids go back on even when a\n * product replaces the control.\n */\nconst DescribedControl = <O, M extends boolean, G extends GroupBase<O>>(props: ControlProps<O, M, G>) => {\n const {inputId, describedBy, control: Own} = libraryOf(props);\n useDescribedBy(inputId, describedBy);\n\n return <Own {...(props as unknown as ControlProps<unknown, boolean, GroupBase<unknown>>)} />;\n};\n\n// The field opens its menu on mousedown, and on Space, which it then cancels:\n// a mark keeps both for itself, so a click or Space opens its bubble. Escape\n// goes on, for the bubble to close on.\nconst keepMouseDown = (event: MouseEvent) => event.stopPropagation();\nconst keepSpace = (event: KeyboardEvent) => {\n if (event.key === ' ') {\n event.stopPropagation();\n }\n};\n\n/** The `!` mark stands with the other indicators, before the clear cross and the chevron. */\nconst IndicatorsContainer = <O, M extends boolean, G extends GroupBase<O>>({\n children,\n ...props\n}: IndicatorsContainerProps<O, M, G>) => {\n const {id, errors, showErrors, tone, hasFieldMark} = libraryOf(props);\n\n return (\n <reactSelectComponents.IndicatorsContainer {...props}>\n {hasFieldMark && (\n <span className=\"select__mark\" onMouseDown={keepMouseDown} onKeyDown={keepSpace}>\n <FieldMark />\n </span>\n )}\n {showErrors && errors.length > 0 && (\n // The field opens its menu on mousedown; the mark keeps its own click.\n <span className=\"select__errors\" onMouseDown={(event) => event.stopPropagation()}>\n <ErrorLabel\n elementId={id}\n errors={[...errors]}\n errorColor={tone === SelectTone.Warning ? 'var(--color-warning)' : undefined}\n />\n </span>\n )}\n {children}\n </reactSelectComponents.IndicatorsContainer>\n );\n};\n\nconst DropdownIndicator = <O, M extends boolean, G extends GroupBase<O>>(props: DropdownIndicatorProps<O, M, G>) => (\n <reactSelectComponents.DropdownIndicator {...props}>\n <ChevronIcon />\n </reactSelectComponents.DropdownIndicator>\n);\n\n/** The clear cross keeps TagsInput's `${id}-clear`, which products and tests find it by. */\nconst ClearIndicator = <O, M extends boolean, G extends GroupBase<O>>(props: ClearIndicatorProps<O, M, G>) => {\n const {id} = libraryOf(props);\n\n return (\n <reactSelectComponents.ClearIndicator {...props} innerProps={{...props.innerProps, id: `${id}-clear`}}>\n <CrossIcon />\n </reactSelectComponents.ClearIndicator>\n );\n};\n\nconst MultiValueRemove = <O, M extends boolean, G extends GroupBase<O>>(props: MultiValueRemoveProps<O, M, G>) => (\n <reactSelectComponents.MultiValueRemove {...props}>\n <CrossIcon size={12} />\n </reactSelectComponents.MultiValueRemove>\n);\n\n/** A single select marks the chosen item with a check, as shadcn's does. */\nconst OptionWithCheck = <O, M extends boolean, G extends GroupBase<O>>({children, ...props}: OptionProps<O, M, G>) => (\n <reactSelectComponents.Option {...props}>\n {children}\n {props.isSelected && !props.isMulti && (\n <span className=\"select__option-check\">\n <CheckIcon />\n </span>\n )}\n </reactSelectComponents.Option>\n);\n\nconst LoadingIndicator = <O, M extends boolean, G extends GroupBase<O>>({\n innerProps,\n}: LoadingIndicatorProps<O, M, G>) => (\n <span {...innerProps} className=\"select__indicator select__loading-indicator\" role=\"status\" aria-label=\"Loading\" />\n);\n\n// What the field's control renders: nothing, see `registration` below.\nconst renderNothing = () => <></>;\n\n/** The class every part takes. A product's own `classNames` is added after ours. */\nconst partClassNames = <O, M extends boolean, G extends GroupBase<O>>(\n own: ClassNamesConfig<O, M, G> = {},\n): ClassNamesConfig<O, M, G> => {\n const ours: ClassNamesConfig<O, M, G> = {\n control: (state) =>\n cn(\n 'select__control',\n state.isFocused && 'select__control--focused',\n state.isDisabled && 'select__control--disabled',\n state.menuIsOpen && 'select__control--menu-is-open',\n ),\n valueContainer: (state) =>\n cn(\n 'select__value-container',\n state.isMulti && 'select__value-container--is-multi',\n state.hasValue && 'select__value-container--has-value',\n ),\n placeholder: () => 'select__placeholder',\n singleValue: () => 'select__single-value',\n input: () => 'select__input-container',\n indicatorsContainer: () => 'select__indicators',\n indicatorSeparator: () => 'select__indicator-separator',\n dropdownIndicator: () => 'select__indicator select__dropdown-indicator',\n clearIndicator: () => 'select__indicator select__clear-indicator',\n loadingIndicator: () => 'select__indicator select__loading-indicator',\n multiValue: (state) =>\n cn('select__multi-value', (state.data as Option).isException && 'select__multi-value--exception'),\n multiValueLabel: () => 'select__multi-value-label',\n multiValueRemove: () => 'select__multi-value-remove',\n menu: (state) => cn('select__menu', state.placement === 'top' && 'select__menu--top'),\n menuPortal: () => 'select__menu-portal',\n menuList: () => 'select__menu-list',\n option: (state) =>\n cn(\n 'select__option',\n state.isFocused && 'select__option--focused',\n state.isSelected && 'select__option--selected',\n state.isDisabled && 'select__option--disabled',\n ),\n group: () => 'select__group',\n groupHeading: () => 'select__group-heading',\n noOptionsMessage: () => 'select__menu-notice',\n loadingMessage: () => 'select__menu-notice',\n };\n\n const merged: ClassNamesConfig<O, M, G> = {...ours};\n\n for (const key of Object.keys(own) as Array<keyof ClassNamesConfig<O, M, G>>) {\n const mine = ours[key] as ((state: unknown) => string) | undefined;\n const theirs = own[key] as ((state: unknown) => string) | undefined;\n (merged as Record<string, (state: unknown) => string>)[key] = (state) => cn(mine?.(state), theirs?.(state));\n }\n\n return merged;\n};\n\nconst DEFAULT_KEYS = ['label'];\n\n/** The parts of a pasted list, split the way TagsInput did: by lines, by \", \", by \",\", or by spaces. */\nconst splitPasted = (text: string): string[] => {\n for (const separator of [/\\n+/, /,\\s/, /,+/]) {\n const parts = text.split(separator);\n if (parts.length > 1) {\n return parts;\n }\n }\n\n return text.split(/\\s+/);\n};\n\nconst flatten = <O, G extends GroupBase<O>>(options: ReadonlyArray<O | G>): O[] =>\n options.flatMap((item) =>\n item && typeof item === 'object' && 'options' in item ? [...(item as G).options] : [item as O],\n );\n\n/** The select in its box: the contour, the indicators and the old `errors` mark. */\nconst SelectBoxInner = <O = Option, M extends boolean = false, G extends GroupBase<O> = OptionGroup<O>>(\n props: SelectProps<O, M, G>,\n ref: ForwardedRef<SelectInstance<O, M, G>>,\n) => {\n const {\n id: idProp,\n inputId: inputIdProp,\n elementId,\n errors = [],\n showErrors,\n isErrorLabelVisible,\n tone = SelectTone.Danger,\n icon = null,\n isCreatable = false,\n isAsync = false,\n onCreateOption,\n createOptionPlaceholder = 'Create ',\n minSearchLength,\n searchableKeys = DEFAULT_KEYS as Array<keyof O>,\n promiseOptions,\n customStyles,\n actionColor,\n minHeightInput: _minHeightInput,\n styles,\n classNames,\n components,\n className,\n isMulti,\n isDisabled = false,\n isLoading,\n isSearchable,\n isOptionDisabled,\n placeholder = 'Select',\n menuPlacement = 'auto',\n loadOptions,\n noOptionsMessage,\n formatCreateLabel,\n options,\n value,\n onChange,\n ...rest\n } = props;\n\n const fallbackId = useId();\n const id = idProp ?? elementId ?? fallbackId;\n // Products' styles and QA tests find the select by the wrapper's id and reach\n // the input inside.\n const inputId = inputIdProp ?? `${id}-input`;\n // The ids of the field the select stands in: react-select's input is not a\n // Base UI control, so it is described and marked invalid by hand.\n const fieldIds = useFieldIds();\n const fieldMessage = useFieldMessage();\n // The field's error or warning draws the contour in its tone.\n const fieldTone = useFieldTone();\n const isInvalid = errors.length > 0 || fieldTone !== undefined;\n const shownTone = fieldTone ?? tone;\n\n const [isCreating, setCreating] = useState(false);\n const isMounted = useRef(true);\n const selectRef = useRef<SelectInstance<O, M, G> | null>(null);\n\n useEffect(\n () => () => {\n isMounted.current = false;\n },\n [],\n );\n\n const setRef = (instance: SelectInstance<O, M, G> | null): void => {\n selectRef.current = instance;\n if (typeof ref === 'function') {\n ref(instance);\n } else if (ref) {\n ref.current = instance;\n }\n };\n\n // TagsInput waited for two characters before it asked the server.\n const minimum = minSearchLength ?? (promiseOptions ? 2 : 0);\n const loader = loadOptions ?? promiseOptions;\n\n const handleCreateOption = async (inputValue: string): Promise<void> => {\n if (!onCreateOption) {\n return;\n }\n\n try {\n setCreating(true);\n await onCreateOption(inputValue);\n } finally {\n if (isMounted.current) {\n setCreating(false);\n }\n }\n };\n\n // Pasting a list into a multi select picks the options it names.\n const handlePaste = (event: ClipboardEvent<HTMLDivElement>): void => {\n if (!isMulti || !options || !onChange) {\n return;\n }\n\n const parts = splitPasted(event.clipboardData.getData('text/plain'))\n .map((part) => part.trim().toLowerCase())\n .filter(Boolean);\n\n if (parts.length < 2) {\n return;\n }\n\n const found = flatten<O, G>(options).filter((option) =>\n searchableKeys.some((key: keyof O) => parts.includes(String(option[key]).toLowerCase())),\n );\n\n if (found.length === 0) {\n return;\n }\n\n const current = (Array.isArray(value) ? value : []) as O[];\n const next = [...current, ...found.filter((option) => !current.includes(option))];\n\n event.preventDefault();\n onChange(next as unknown as OnChangeValue<O, M>, {action: 'select-option', option: found[0]} as ActionMeta<O>);\n setTimeout(() => selectRef.current?.blur(), 0);\n };\n\n const parts: Partial<SelectComponentsConfig<O, M, G>> = {\n IndicatorsContainer,\n IndicatorSeparator: null,\n DropdownIndicator,\n ClearIndicator,\n MultiValueRemove,\n Option: OptionWithCheck,\n LoadingIndicator,\n ...components,\n // A product's control goes inside ours, which keeps the input described.\n Control: DescribedControl,\n };\n\n const selectProps = {\n ...rest,\n id,\n inputId,\n 'aria-invalid': rest['aria-invalid'] ?? (fieldIds?.isInvalid || undefined),\n library: {\n id,\n inputId,\n errors,\n showErrors: showErrors ?? isErrorLabelVisible ?? true,\n tone,\n icon,\n hasFieldMark: fieldMessage?.display === MessageDisplay.Compact,\n describedBy: fieldIds?.describedBy,\n control: (components?.Control ?? Control) as Library['control'],\n } satisfies Library,\n unstyled: true,\n options,\n value,\n onChange,\n isMulti,\n placeholder,\n menuPlacement,\n // v5 of the single select was not searchable by default; TagsInput was.\n isSearchable: isSearchable ?? Boolean(isMulti),\n // v5 of the single select ignored `isDisabled` on options unless told otherwise.\n isOptionDisabled: isOptionDisabled ?? (isMulti ? undefined : () => false),\n isDisabled: isDisabled || isCreating,\n isLoading: isLoading || isCreating,\n styles: {...customStyles, ...styles} as StylesConfig<O, M, G>,\n classNames: partClassNames(classNames),\n components: parts,\n noOptionsMessage: (input: {inputValue: string}) =>\n input.inputValue.length < minimum\n ? `Enter ${minimum} or more characters`\n : (noOptionsMessage?.(input) ?? 'No options'),\n ref: setRef,\n };\n\n const creatableProps = {\n formatCreateLabel: formatCreateLabel ?? ((inputValue: string) => `${createOptionPlaceholder}\"${inputValue}\"`),\n ...(onCreateOption && {onCreateOption: handleCreateOption}),\n };\n\n const asyncProps = {\n loadOptions: (inputValue: string, callback: (options: ReadonlyArray<O | G>) => void) => {\n if (inputValue.length < minimum || !loader) {\n callback([]);\n return undefined;\n }\n\n return loader(inputValue, callback);\n },\n };\n\n // The four flavours of react-select share one set of props; the casts only\n // tell TypeScript which flavour it is looking at.\n const renderSelect = () => {\n if (isAsync && isCreatable) {\n return <AsyncCreatableSelect {...(selectProps as object)} {...creatableProps} {...asyncProps} />;\n }\n if (isAsync) {\n return <AsyncSelect {...(selectProps as object)} {...asyncProps} />;\n }\n if (isCreatable) {\n return <CreatableSelect {...(selectProps as object)} {...creatableProps} />;\n }\n return <ReactSelect {...(selectProps as object)} />;\n };\n\n // Base UI points the field's label at the control registered with the field\n // and keeps that registry to itself: `Field.Control` is the one way in. So it\n // registers the input's id and renders nothing — the input is react-select's,\n // named by the same id, and the label's `for` finds it.\n const registration = fieldIds && <BaseField.Control id={inputId} render={renderNothing} />;\n\n const style = actionColor\n ? ({'--select-chip-bg': actionColor, '--select-chip-text': 'var(--color-light)'} as CSSProperties)\n : undefined;\n\n return (\n <div\n className={cn(\n 'select',\n isInvalid && 'select--invalid',\n shownTone === SelectTone.Warning && 'select--warning',\n className,\n )}\n data-is-disabled={isDisabled}\n style={style}\n onPaste={handlePaste}\n >\n {registration}\n {renderSelect()}\n </div>\n );\n};\n\n// `forwardRef` does not keep the generics, so the types are written out by hand.\nconst SelectBox = forwardRef(SelectBoxInner) as unknown as <\n O = Option,\n M extends boolean = false,\n G extends GroupBase<O> = OptionGroup<O>,\n>(\n props: SelectProps<O, M, G> & {ref?: ForwardedRef<SelectInstance<O, M, G>>},\n) => ReactElement;\n\n/**\n * A select on react-select with the library's look: one field for a single\n * value, several as chips, a list that loads as the user types, and new values\n * the user creates. Every react-select prop is accepted and passed on.\n *\n * With a `label`, a `description`, an `error` or a `warning` it draws its\n * field: the label on top, on the left or hidden, and the message behind a mark\n * among the indicators or, with `messageDisplay=\"line\"`, under it.\n */\nconst SelectInner = <O = Option, M extends boolean = false, G extends GroupBase<O> = OptionGroup<O>>(\n props: SelectProps<O, M, G>,\n ref: ForwardedRef<SelectInstance<O, M, G>>,\n) => {\n const {field, rest} = splitFieldProps(props);\n const {isRequired, ...control} = rest;\n const required = isRequired || control.required;\n\n if (!hasFieldProps(props)) {\n return <SelectBox<O, M, G> {...control} ref={ref} required={required} />;\n }\n\n return (\n <ControlField\n field={field}\n errors={control.errors}\n tone={control.tone}\n isDisabled={control.isDisabled}\n className=\"select-field\"\n >\n {/* The errors are the field's now, written by it. */}\n <SelectBox<O, M, G> {...control} errors={undefined} ref={ref} required={required} />\n </ControlField>\n );\n};\n\nconst Select = forwardRef(SelectInner) as unknown as (<\n O = Option,\n M extends boolean = false,\n G extends GroupBase<O> = OptionGroup<O>,\n>(\n props: SelectProps<O, M, G>,\n) => ReactElement) & {displayName?: string};\nSelect.displayName = 'Select';\n\nexport default Select;\n\nexport type {Option, OptionGroup, SelectProps};\nexport {reactSelectComponents as components, Select, SelectTone};\n"],"mappings":";;;;;;;;;;;AAOA,IAAMQ,KAAM,GAAGC,MAAiCC,EAAKD,CAAM,GCW9CE,IAAa;CACxB,QAAQ;CACR,SAAS;AACX,GCyDMC,KAAa,MAA8BC,EAAM,YAAmC,SAEpFC,UACJ,kBAAC,OAAD;CAAK,SAAQ;CAAY,OAAM;CAAK,QAAO;CAAK,MAAK;CAAO,eAAY;CACtE,UAAA,kBAAC,QAAD;EAAM,GAAE;EAAe,QAAO;EAAe,aAAY;EAAM,eAAc;EAAQ,gBAAe;CAAS,CAAA;AAC1G,CAAA,GAGDC,KAAa,EAAC,UAAO,SACzB,kBAAC,OAAD;CAAK,SAAQ;CAAY,OAAOC;CAAM,QAAQA;CAAM,MAAK;CAAO,eAAY;C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EAAa,sBAAsB;CAAoB,IAC7E,KAAA;CAEJ,OACE,kBAAC,OAAD;EACE,WAAW7H,EACT,UACA4E,MAAa,mBACbC,OAAc1E,EAAW,WAAW,mBACpC2H,EACF;EACA,oBAAkBlB;EACX;EACP,SAASd;EATX,UAAA,CAWG4B,IACAH,GAAa,CACX;;AAET,CAG2C,GA2CrCQ,IAASjE,GAzBb,GACA,MACG;CACH,IAAM,EAAC,UAAO,YAAQkE,EAAgB3H,CAAK,GACrC,EAAC,eAAY,GAAG4H,MAAW/D,GAC3BgE,IAAWC,KAAcF,EAAQ;CAMvC,OAJKG,EAAc/H,CAAK,IAKtB,kBAACgI,GAAD;EACS;EACP,QAAQJ,EAAQ;EAChB,MAAMA,EAAQ;EACd,YAAYA,EAAQ;EACpB,WAAU;EAGV,UAAA,kBAACpE,GAAD;GAAoB,GAAIoE;GAAS,QAAQ,KAAA;GAAgB;GAAe;EAAW,CAAA;CACvE,CAAA,IAbP,kBAACpE,GAAD;EAAoB,GAAIoE;EAAc;EAAe;CAAW,CAAA;AAe3E,CAEqC;AAOrC,EAAO,cAAc"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@propellerads/select",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"style": "dist/index.css",
|
|
@@ -24,19 +24,19 @@
|
|
|
24
24
|
"url": "https://github.com/propellerads/ui-components/issues"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "tsc && vite build &&
|
|
27
|
+
"build": "tsc && vite build && rollup -c rollup.dts.config.mjs"
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/propellerads/ui-components#readme",
|
|
30
30
|
"private": false,
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@base-ui-components/react": "1.0.0-rc.0",
|
|
33
|
-
"@propellerads/error-label": "^
|
|
34
|
-
"@propellerads/label": "^
|
|
33
|
+
"@propellerads/error-label": "^9.0.0",
|
|
34
|
+
"@propellerads/label": "^7.0.0",
|
|
35
35
|
"clsx": "^2.1.1",
|
|
36
36
|
"react-select": "^5.10.2"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@propellerads/tokens": ">=0.
|
|
39
|
+
"@propellerads/tokens": ">=0.5.0",
|
|
40
40
|
"react": "^18.0.0 || ^19.0.0",
|
|
41
41
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
42
42
|
},
|