@a-type/ui 6.0.21 → 6.0.23
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/dist/components/chip/Chip.d.ts +1 -0
- package/dist/components/chip/Chip.js +2 -1
- package/dist/components/chip/Chip.js.map +1 -1
- package/dist/components/chip/Chip.module.css +12 -2
- package/dist/components/chip/Chip.stories.d.ts +1 -0
- package/dist/components/chip/Chip.stories.js +1 -0
- package/dist/components/chip/Chip.stories.js.map +1 -1
- package/dist/components/combobox/Combobox.d.ts +5 -1
- package/dist/components/combobox/Combobox.js +4 -2
- package/dist/components/combobox/Combobox.js.map +1 -1
- package/dist/components/combobox/Combobox.module.css +9 -7
- package/dist/components/combobox/Combobox.stories.js +1 -2
- package/dist/components/combobox/Combobox.stories.js.map +1 -1
- package/dist/components/forms/CheckboxField.d.ts +3 -1
- package/dist/components/forms/CheckboxField.js +5 -6
- package/dist/components/forms/CheckboxField.js.map +1 -1
- package/dist/components/forms/EmojiField.d.ts +3 -1
- package/dist/components/forms/EmojiField.js +10 -11
- package/dist/components/forms/EmojiField.js.map +1 -1
- package/dist/components/forms/Field.d.ts +16 -0
- package/dist/components/forms/Field.js +37 -0
- package/dist/components/forms/Field.js.map +1 -0
- package/dist/components/forms/Field.module.css +51 -0
- package/dist/components/forms/Form.module.css +1 -1
- package/dist/components/forms/FormikForm.d.ts +2 -2
- package/dist/components/forms/FormikForm.stories.d.ts +2 -2
- package/dist/components/forms/FormikForm.stories.js +1 -1
- package/dist/components/forms/FormikForm.stories.js.map +1 -1
- package/dist/components/forms/NumberStepperField.d.ts +3 -1
- package/dist/components/forms/NumberStepperField.js +6 -9
- package/dist/components/forms/NumberStepperField.js.map +1 -1
- package/dist/components/forms/SwitchField.d.ts +3 -1
- package/dist/components/forms/SwitchField.js +5 -6
- package/dist/components/forms/SwitchField.js.map +1 -1
- package/dist/components/forms/TextField.d.ts +7 -5
- package/dist/components/forms/TextField.js +5 -7
- package/dist/components/forms/TextField.js.map +1 -1
- package/dist/components/forms/ToggleGroupField.d.ts +3 -1
- package/dist/components/forms/ToggleGroupField.js +10 -11
- package/dist/components/forms/ToggleGroupField.js.map +1 -1
- package/dist/components/forms/index.d.ts +1 -1
- package/dist/components/forms/index.js +1 -1
- package/dist/components/forms/index.js.map +1 -1
- package/dist/components/switch/Switch.module.css +1 -1
- package/package.json +1 -1
- package/src/components/chip/Chip.module.css +12 -2
- package/src/components/chip/Chip.stories.tsx +1 -0
- package/src/components/chip/Chip.tsx +3 -1
- package/src/components/combobox/Combobox.module.css +9 -7
- package/src/components/combobox/Combobox.stories.tsx +4 -7
- package/src/components/combobox/Combobox.tsx +6 -2
- package/src/components/forms/CheckboxField.tsx +23 -15
- package/src/components/forms/EmojiField.tsx +50 -33
- package/src/components/forms/Field.module.css +51 -0
- package/src/components/forms/Field.tsx +43 -0
- package/src/components/forms/Form.module.css +1 -1
- package/src/components/forms/FormikForm.stories.tsx +25 -5
- package/src/components/forms/NumberStepperField.tsx +24 -17
- package/src/components/forms/SwitchField.tsx +23 -15
- package/src/components/forms/TextField.tsx +49 -25
- package/src/components/forms/ToggleGroupField.tsx +29 -19
- package/src/components/forms/index.tsx +1 -1
- package/src/components/switch/Switch.module.css +1 -1
- package/dist/components/forms/FieldLabel.d.ts +0 -2
- package/dist/components/forms/FieldLabel.js +0 -5
- package/dist/components/forms/FieldLabel.js.map +0 -1
- package/dist/components/forms/FieldLabel.module.css +0 -20
- package/src/components/forms/FieldLabel.module.css +0 -20
- package/src/components/forms/FieldLabel.tsx +0 -9
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
1
2
|
import { NumberStepperProps } from '../numberStepper/NumberStepper.js';
|
|
2
3
|
export interface NumberStepperFieldProps extends Omit<NumberStepperProps, 'value' | 'onChange'> {
|
|
3
4
|
name: string;
|
|
@@ -5,5 +6,6 @@ export interface NumberStepperFieldProps extends Omit<NumberStepperProps, 'value
|
|
|
5
6
|
className?: string;
|
|
6
7
|
id?: string;
|
|
7
8
|
onChange?: (value: number) => void;
|
|
9
|
+
description?: ReactNode;
|
|
8
10
|
}
|
|
9
|
-
export declare function NumberStepperField({ name, label, className, id: providedId, onChange, ...rest }: NumberStepperFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare function NumberStepperField({ name, label, className, id: providedId, onChange, description, ...rest }: NumberStepperFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -11,19 +11,16 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { useField } from 'formik';
|
|
14
|
-
import { withClassName } from '../../hooks.js';
|
|
15
14
|
import { useIdOrGenerated } from '../../hooks/useIdOrGenerated.js';
|
|
16
15
|
import { NumberStepper, } from '../numberStepper/NumberStepper.js';
|
|
17
|
-
import {
|
|
18
|
-
import cls from './NumberStepperField.module.css';
|
|
16
|
+
import { Field } from './Field.js';
|
|
19
17
|
export function NumberStepperField(_a) {
|
|
20
|
-
var { name, label, className, id: providedId, onChange } = _a, rest = __rest(_a, ["name", "label", "className", "id", "onChange"]);
|
|
18
|
+
var { name, label, className, id: providedId, onChange, description } = _a, rest = __rest(_a, ["name", "label", "className", "id", "onChange", "description"]);
|
|
21
19
|
const [_, field, tools] = useField({ name });
|
|
22
20
|
const id = useIdOrGenerated(providedId);
|
|
23
|
-
return (_jsxs(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
return (_jsxs(Field, { className: className, horizontal: true, children: [label && _jsx(Field.Label, { htmlFor: id, children: label }), _jsx(Field.Control, { children: _jsx(NumberStepper, Object.assign({ value: field.value, onChange: (v) => {
|
|
22
|
+
tools.setValue(v);
|
|
23
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(v);
|
|
24
|
+
}, id: id, "aria-describedby": description ? `${id}-description` : undefined }, rest)) }), description && (_jsx(Field.Description, { id: `${id}-description`, children: description }))] }));
|
|
27
25
|
}
|
|
28
|
-
const FieldRoot = withClassName('div', cls.root);
|
|
29
26
|
//# sourceMappingURL=NumberStepperField.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberStepperField.js","sourceRoot":"","sources":["../../../src/components/forms/NumberStepperField.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"NumberStepperField.js","sourceRoot":"","sources":["../../../src/components/forms/NumberStepperField.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EACN,aAAa,GAEb,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAYnC,MAAM,UAAU,kBAAkB,CAAC,EAQT;QARS,EAClC,IAAI,EACJ,KAAK,EACL,SAAS,EACT,EAAE,EAAE,UAAU,EACd,QAAQ,EACR,WAAW,OAEc,EADtB,IAAI,cAP2B,+DAQlC,CADO;IAEP,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,MAAM,EAAE,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACxC,OAAO,CACN,MAAC,KAAK,IAAC,SAAS,EAAE,SAAS,EAAE,UAAU,mBACrC,KAAK,IAAI,KAAC,KAAK,CAAC,KAAK,IAAC,OAAO,EAAE,EAAE,YAAG,KAAK,GAAe,EACzD,KAAC,KAAK,CAAC,OAAO,cACb,KAAC,aAAa,kBACb,KAAK,EAAE,KAAK,CAAC,KAAK,EAClB,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE;wBACf,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;wBAClB,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAG,CAAC,CAAC,CAAC;oBACf,CAAC,EACD,EAAE,EAAE,EAAE,sBACY,WAAW,CAAC,CAAC,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC,SAAS,IAC3D,IAAI,EACP,GACa,EACf,WAAW,IAAI,CACf,KAAC,KAAK,CAAC,WAAW,IAAC,EAAE,EAAE,GAAG,EAAE,cAAc,YACxC,WAAW,GACO,CACpB,IACM,CACR,CAAC;AACH,CAAC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
1
2
|
export interface SwitchFieldProps {
|
|
2
3
|
name: string;
|
|
3
4
|
label?: string;
|
|
4
5
|
required?: boolean;
|
|
5
6
|
className?: string;
|
|
6
7
|
id?: string;
|
|
8
|
+
description?: ReactNode;
|
|
7
9
|
}
|
|
8
|
-
export declare function SwitchField({ name, label, className, required, id: providedId, ...rest }: SwitchFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export declare function SwitchField({ name, label, className, required, id: providedId, description, ...rest }: SwitchFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -12,15 +12,14 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { useField } from 'formik';
|
|
14
14
|
import { useIdOrGenerated } from '../../hooks/useIdOrGenerated.js';
|
|
15
|
-
import { Box } from '../box/Box.js';
|
|
16
15
|
import { Switch } from '../switch/Switch.js';
|
|
17
|
-
import {
|
|
16
|
+
import { Field } from './Field.js';
|
|
18
17
|
export function SwitchField(_a) {
|
|
19
|
-
var { name, label, className, required, id: providedId } = _a, rest = __rest(_a, ["name", "label", "className", "required", "id"]);
|
|
18
|
+
var { name, label, className, required, id: providedId, description } = _a, rest = __rest(_a, ["name", "label", "className", "required", "id", "description"]);
|
|
20
19
|
const [props, _, tools] = useField({ name, required, type: 'checkbox' });
|
|
21
20
|
const id = useIdOrGenerated(providedId);
|
|
22
|
-
return (_jsxs(
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
return (_jsxs(Field, { horizontal: true, className: className, children: [_jsx(Field.Control, { children: _jsx(Switch, Object.assign({}, props, { checked: props.checked, onCheckedChange: (v) => {
|
|
22
|
+
tools.setValue(!!v);
|
|
23
|
+
}, id: id, "aria-describedby": description ? `${id}-description` : undefined }, rest)) }), label && _jsx(Field.Label, { htmlFor: id, children: label }), description && (_jsx(Field.Description, { id: `${id}-description`, children: description }))] }));
|
|
25
24
|
}
|
|
26
25
|
//# sourceMappingURL=SwitchField.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwitchField.js","sourceRoot":"","sources":["../../../src/components/forms/SwitchField.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"SwitchField.js","sourceRoot":"","sources":["../../../src/components/forms/SwitchField.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAWnC,MAAM,UAAU,WAAW,CAAC,EAQT;QARS,EAC3B,IAAI,EACJ,KAAK,EACL,SAAS,EACT,QAAQ,EACR,EAAE,EAAE,UAAU,EACd,WAAW,OAEO,EADf,IAAI,cAPoB,+DAQ3B,CADO;IAEP,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,GAAG,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;IACzE,MAAM,EAAE,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACxC,OAAO,CACN,MAAC,KAAK,IAAC,UAAU,QAAC,SAAS,EAAE,SAAS,aACrC,KAAC,KAAK,CAAC,OAAO,cACb,KAAC,MAAM,oBACF,KAAK,IACT,OAAO,EAAE,KAAK,CAAC,OAAO,EACtB,eAAe,EAAE,CAAC,CAAC,EAAE,EAAE;wBACtB,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;oBACrB,CAAC,EACD,EAAE,EAAE,EAAE,sBACY,WAAW,CAAC,CAAC,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC,SAAS,IAC3D,IAAI,EACP,GACa,EACf,KAAK,IAAI,KAAC,KAAK,CAAC,KAAK,IAAC,OAAO,EAAE,EAAE,YAAG,KAAK,GAAe,EACxD,WAAW,IAAI,CACf,KAAC,KAAK,CAAC,WAAW,IAAC,EAAE,EAAE,GAAG,EAAE,cAAc,YACxC,WAAW,GACO,CACpB,IACM,CACR,CAAC;AACH,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InputHTMLAttributes, Ref } from 'react';
|
|
1
|
+
import { InputHTMLAttributes, ReactNode, Ref } from 'react';
|
|
2
2
|
import { InputProps } from '../input/Input.js';
|
|
3
3
|
import { TextAreaProps } from '../textArea/TextArea.js';
|
|
4
4
|
export type TextFieldProps = {
|
|
@@ -9,8 +9,9 @@ export type TextFieldProps = {
|
|
|
9
9
|
inputRef?: Ref<HTMLInputElement>;
|
|
10
10
|
inputClassName?: string;
|
|
11
11
|
ref?: Ref<HTMLDivElement>;
|
|
12
|
+
description?: ReactNode;
|
|
12
13
|
} & Omit<InputProps, 'ref'>;
|
|
13
|
-
export declare const TextField: ({ ref, name, label, className, autoFocusDelay, autoFocus, inputRef, onChange, onFocus, onBlur, id: providedId, inputClassName, ...rest }: TextFieldProps) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export declare const TextField: ({ ref, name, label, className, autoFocusDelay, autoFocus, inputRef, onChange, onFocus, onBlur, id: providedId, inputClassName, description, ...rest }: TextFieldProps) => import("react/jsx-runtime").JSX.Element;
|
|
14
15
|
export type TextAreaFieldProps = {
|
|
15
16
|
name: string;
|
|
16
17
|
label?: string;
|
|
@@ -21,6 +22,7 @@ export type TextAreaFieldProps = {
|
|
|
21
22
|
inputRef?: Ref<HTMLTextAreaElement>;
|
|
22
23
|
submitOnEnter?: boolean;
|
|
23
24
|
textAreaClassName?: string;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
description?: ReactNode;
|
|
26
|
+
ref?: Ref<HTMLDivElement>;
|
|
27
|
+
} & Omit<TextAreaProps, 'ref'>;
|
|
28
|
+
export declare function TextAreaField({ name, label, className, inputRef, onKeyDown, submitOnEnter, id: providedId, textAreaClassName, description, ref, ...rest }: TextAreaFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -13,16 +13,15 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
13
13
|
import clsx from 'clsx';
|
|
14
14
|
import { useField, useFormikContext } from 'formik';
|
|
15
15
|
import { useCallback, useEffect, useRef, } from 'react';
|
|
16
|
-
import { withClassName } from '../../hooks.js';
|
|
17
16
|
import { useIdOrGenerated } from '../../hooks/useIdOrGenerated.js';
|
|
18
17
|
import useMergedRef from '../../hooks/useMergedRef.js';
|
|
19
18
|
import { Input } from '../input/Input.js';
|
|
20
19
|
import { TextArea } from '../textArea/TextArea.js';
|
|
21
|
-
import {
|
|
20
|
+
import { Field } from './Field.js';
|
|
22
21
|
import cls from './TextField.module.css';
|
|
23
22
|
const emptyRef = (() => { });
|
|
24
23
|
export const TextField = function TextField(_a) {
|
|
25
|
-
var { ref, name, label, className, autoFocusDelay, autoFocus, inputRef, onChange, onFocus, onBlur, id: providedId, inputClassName } = _a, rest = __rest(_a, ["ref", "name", "label", "className", "autoFocusDelay", "autoFocus", "inputRef", "onChange", "onFocus", "onBlur", "id", "inputClassName"]);
|
|
24
|
+
var { ref, name, label, className, autoFocusDelay, autoFocus, inputRef, onChange, onFocus, onBlur, id: providedId, inputClassName, description } = _a, rest = __rest(_a, ["ref", "name", "label", "className", "autoFocusDelay", "autoFocus", "inputRef", "onChange", "onFocus", "onBlur", "id", "inputClassName", "description"]);
|
|
26
25
|
const [props] = useField({
|
|
27
26
|
name,
|
|
28
27
|
onChange,
|
|
@@ -39,10 +38,10 @@ export const TextField = function TextField(_a) {
|
|
|
39
38
|
}, autoFocusDelay);
|
|
40
39
|
}
|
|
41
40
|
}, [autoFocusDelay]);
|
|
42
|
-
return (_jsxs(
|
|
41
|
+
return (_jsxs(Field, { className: className, stretch: true, ref: ref, children: [label && _jsx(Field.Label, { htmlFor: id, children: label }), _jsx(Field.Control, { render: _jsx(Input, Object.assign({}, props, rest, { id: id, autoFocus: autoFocus, className: clsx(cls.input, inputClassName), ref: useMergedRef(innerInputRef, inputRef || emptyRef), "aria-describedby": description ? `${id}-description` : undefined })) }), description && (_jsx(Field.Description, { id: `${id}-description`, children: description }))] }));
|
|
43
42
|
};
|
|
44
43
|
export function TextAreaField(_a) {
|
|
45
|
-
var { name, label, className, inputRef, onKeyDown, submitOnEnter, id: providedId, textAreaClassName } = _a, rest = __rest(_a, ["name", "label", "className", "inputRef", "onKeyDown", "submitOnEnter", "id", "textAreaClassName"]);
|
|
44
|
+
var { name, label, className, inputRef, onKeyDown, submitOnEnter, id: providedId, textAreaClassName, description, ref } = _a, rest = __rest(_a, ["name", "label", "className", "inputRef", "onKeyDown", "submitOnEnter", "id", "textAreaClassName", "description", "ref"]);
|
|
46
45
|
const [props] = useField(name);
|
|
47
46
|
const { submitForm } = useFormikContext();
|
|
48
47
|
const onKeyDownInner = useCallback((e) => {
|
|
@@ -53,7 +52,6 @@ export function TextAreaField(_a) {
|
|
|
53
52
|
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e);
|
|
54
53
|
}, [submitOnEnter, onKeyDown, submitForm]);
|
|
55
54
|
const id = useIdOrGenerated(providedId);
|
|
56
|
-
return (_jsxs(
|
|
55
|
+
return (_jsxs(Field, { stretch: true, className: className, ref: ref, children: [label && _jsx(Field.Label, { htmlFor: id, children: label }), _jsx(Field.Control, { render: _jsx(TextArea, Object.assign({ ref: inputRef }, props, rest, { className: clsx(cls.input, textAreaClassName), id: id, onKeyDown: onKeyDownInner, "aria-describedby": description ? `${id}-description` : undefined })) }), description && (_jsx(Field.Description, { id: `${id}-description`, children: description }))] }));
|
|
57
56
|
}
|
|
58
|
-
export const FieldRoot = withClassName('div', cls.root);
|
|
59
57
|
//# sourceMappingURL=TextField.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextField.js","sourceRoot":"","sources":["../../../src/components/forms/TextField.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AACpD,OAAO,
|
|
1
|
+
{"version":3,"file":"TextField.js","sourceRoot":"","sources":["../../../src/components/forms/TextField.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AACpD,OAAO,EAKN,WAAW,EACX,SAAS,EACT,MAAM,GACN,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,YAAY,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,KAAK,EAAc,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAiB,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,GAAG,MAAM,wBAAwB,CAAC;AAazC,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,GAAE,CAAC,CAAQ,CAA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EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,iBAAiB,CAAC,EAC7C,EAAE,EAAE,EAAE,EACN,SAAS,EAAE,cAAc,sBACP,WAAW,CAAC,CAAC,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC,SAAS,IAC9D,GAEF,EACD,WAAW,IAAI,CACf,KAAC,KAAK,CAAC,WAAW,IAAC,EAAE,EAAE,GAAG,EAAE,cAAc,YACxC,WAAW,GACO,CACpB,IACM,CACR,CAAC;AACH,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
1
2
|
import { ToggleGroupProps } from '../toggleGroup/toggleGroup.js';
|
|
2
3
|
export type ToggleGroupFieldProps<Value extends string> = ToggleGroupProps<Value> & {
|
|
3
4
|
name: string;
|
|
@@ -6,8 +7,9 @@ export type ToggleGroupFieldProps<Value extends string> = ToggleGroupProps<Value
|
|
|
6
7
|
className?: string;
|
|
7
8
|
id?: string;
|
|
8
9
|
type?: 'single' | 'multiple';
|
|
10
|
+
description?: ReactNode;
|
|
9
11
|
};
|
|
10
|
-
declare function ToggleGroupFieldDefault({ name, label, required, className, type, multiple, id, ...props }: ToggleGroupFieldProps<string>): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
declare function ToggleGroupFieldDefault({ name, label, required, className, type, multiple, description, id, ...props }: ToggleGroupFieldProps<string>): import("react/jsx-runtime").JSX.Element;
|
|
11
13
|
export declare const ToggleGroupField: typeof ToggleGroupFieldDefault & {
|
|
12
14
|
Item: import("react").FunctionComponent<import("@base-ui/react").Toggle.Props<string> & import("react").RefAttributes<HTMLButtonElement>>;
|
|
13
15
|
};
|
|
@@ -12,19 +12,18 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { useField } from 'formik';
|
|
14
14
|
import { ToggleGroup } from '../toggleGroup/toggleGroup.js';
|
|
15
|
-
import {
|
|
16
|
-
import { FieldRoot } from './TextField.js';
|
|
15
|
+
import { Field } from './Field.js';
|
|
17
16
|
function ToggleGroupFieldDefault(_a) {
|
|
18
|
-
var { name, label, required, className, type = 'single', multiple, id } = _a, props = __rest(_a, ["name", "label", "required", "className", "type", "multiple", "id"]);
|
|
17
|
+
var { name, label, required, className, type = 'single', multiple, description, id } = _a, props = __rest(_a, ["name", "label", "required", "className", "type", "multiple", "description", "id"]);
|
|
19
18
|
const [fieldProps, _, tools] = useField(Object.assign({ name, required }, props));
|
|
20
|
-
return (_jsxs(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
return (_jsxs(Field, { children: [label && _jsx(Field.Label, { htmlFor: id, children: label }), _jsx(Field.Control, { children: _jsx(ToggleGroup, Object.assign({}, fieldProps, { onValueChange: (v) => {
|
|
20
|
+
if (multiple || type === 'multiple') {
|
|
21
|
+
tools.setValue(v);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
tools.setValue(v[0]);
|
|
25
|
+
}
|
|
26
|
+
}, multiple: multiple || type === 'multiple' }, props, { id: id, className: className, "aria-describedby": description ? `${id}-description` : undefined })) }), description && (_jsx(Field.Description, { id: `${id}-description`, children: description }))] }));
|
|
28
27
|
}
|
|
29
28
|
export const ToggleGroupField = Object.assign(ToggleGroupFieldDefault, {
|
|
30
29
|
Item: ToggleGroup.Item,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToggleGroupField.js","sourceRoot":"","sources":["../../../src/components/forms/ToggleGroupField.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"ToggleGroupField.js","sourceRoot":"","sources":["../../../src/components/forms/ToggleGroupField.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,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,MAAM,CAAC,uBAAuB,EAAE;IACtE,IAAI,EAAE,WAAW,CAAC,IAAI;CACtB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/forms/index.tsx"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/forms/index.tsx"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC"}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
--mx-shadow-value: inset var(--m-shadow-sm);
|
|
16
16
|
|
|
17
17
|
@apply --mx-bg(var(--m-control-bg));
|
|
18
|
-
@apply --mx-borderColor(var(--m-control-
|
|
18
|
+
@apply --mx-borderColor(var(--m-control-borderColor));
|
|
19
19
|
border-radius: var(--m-radius-lg);
|
|
20
20
|
|
|
21
21
|
&[data-checked] {
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
.root {
|
|
2
2
|
display: inline-flex;
|
|
3
3
|
align-items: center;
|
|
4
|
-
gap: var(--m-space-
|
|
4
|
+
gap: var(--m-space-md);
|
|
5
5
|
white-space: nowrap;
|
|
6
6
|
|
|
7
|
-
@apply --mx-bg(var(--m-color-
|
|
7
|
+
@apply --mx-bg(var(--m-color-neutral-paper));
|
|
8
8
|
@apply --mx-fg(contrast-color(var(--mx-bg-ref)));
|
|
9
9
|
@apply --mx-borderColor(var(--m-color-main-heavy));
|
|
10
10
|
|
|
@@ -19,4 +19,14 @@
|
|
|
19
19
|
&:not(:is(button)) {
|
|
20
20
|
padding: var(--m-action-padding);
|
|
21
21
|
}
|
|
22
|
+
|
|
23
|
+
&[data-emphasis='primary'] {
|
|
24
|
+
@apply --mx-bg(var(--m-color-main-wash));
|
|
25
|
+
@apply --mx-borderColor(var(--m-color-main-heavy));
|
|
26
|
+
}
|
|
27
|
+
&[data-emphasis='ambient'] {
|
|
28
|
+
@apply --mx-bg(transparent);
|
|
29
|
+
@apply --mx-borderColor(transparent);
|
|
30
|
+
@apply --mx-fg(var(--m-color-neutral-ink));
|
|
31
|
+
}
|
|
22
32
|
}
|
|
@@ -5,13 +5,15 @@ import cls from './Chip.module.css';
|
|
|
5
5
|
|
|
6
6
|
export interface ChipProps extends SlotDivProps {
|
|
7
7
|
ref?: Ref<any>;
|
|
8
|
+
emphasis?: 'default' | 'primary' | 'ambient';
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export function Chip({ className, ...rest }: ChipProps) {
|
|
11
12
|
return (
|
|
12
13
|
<SlotDiv
|
|
13
|
-
className={classNames('@mode-
|
|
14
|
+
className={classNames('@mode-dense', cls.root, className)}
|
|
14
15
|
role={rest.onClick ? 'button' : undefined}
|
|
16
|
+
data-emphasis={rest.emphasis ?? 'default'}
|
|
15
17
|
{...rest}
|
|
16
18
|
/>
|
|
17
19
|
);
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
display: flex;
|
|
16
16
|
flex-direction: column;
|
|
17
17
|
overflow: clip;
|
|
18
|
-
padding: var(--m-space-
|
|
18
|
+
padding: var(--m-space-md);
|
|
19
19
|
gap: var(--m-space-xs);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
.groupItem {
|
|
23
|
-
@apply --mx-
|
|
23
|
+
@apply --mx-ring;
|
|
24
24
|
&[data-highlighted] {
|
|
25
|
-
--mx-ring
|
|
25
|
+
@apply --mx-ring(--fn-ring(var(--m-color-main-mid), 2px));
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -112,13 +112,15 @@
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
.item[data-selected] {
|
|
115
|
-
@apply --mx-fg(var(--m-color-
|
|
115
|
+
@apply --mx-fg(var(--m-color-main-ink));
|
|
116
|
+
@apply --mx-bg-heavier(1);
|
|
116
117
|
}
|
|
117
118
|
|
|
118
119
|
.itemIndicator {
|
|
119
120
|
margin-inline-start: auto;
|
|
120
|
-
height: 10px;
|
|
121
|
-
width: 10px;
|
|
121
|
+
height: --fn-literal(10px);
|
|
122
|
+
width: --fn-literal(10px);
|
|
123
|
+
stroke-width: var(--m-lineWidth-lg);
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
.list {
|
|
@@ -164,5 +166,5 @@
|
|
|
164
166
|
.details {
|
|
165
167
|
@apply --mx-prose-ambient;
|
|
166
168
|
@apply --mx-fg(var(--m-color-neutral-heavy));
|
|
167
|
-
padding: var(--m-space-
|
|
169
|
+
padding: var(--m-space-md);
|
|
168
170
|
}
|
|
@@ -2,7 +2,6 @@ import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
|
2
2
|
import { useState } from 'react';
|
|
3
3
|
import { Box } from '../box/Box.js';
|
|
4
4
|
import { Icon } from '../icon/Icon.js';
|
|
5
|
-
import { Text } from '../typography/typography.js';
|
|
6
5
|
import { Combobox } from './Combobox.js';
|
|
7
6
|
|
|
8
7
|
interface Args {
|
|
@@ -206,12 +205,10 @@ export const Grouped: Story = {
|
|
|
206
205
|
)}
|
|
207
206
|
</GroupedCombobox.Empty>
|
|
208
207
|
<GroupedCombobox.Separator />
|
|
209
|
-
<
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
</Text>
|
|
214
|
-
</Box>
|
|
208
|
+
<Combobox.Details>
|
|
209
|
+
Select your favorite fruit or berry.
|
|
210
|
+
{creatable ? ' Enter creates a new item.' : ''}
|
|
211
|
+
</Combobox.Details>
|
|
215
212
|
</GroupedCombobox.Content>
|
|
216
213
|
</GroupedCombobox>
|
|
217
214
|
);
|
|
@@ -484,12 +484,14 @@ export interface ComboboxGroupItemProps
|
|
|
484
484
|
replace?: BaseCombobox.ComboboxItemProps['render'];
|
|
485
485
|
render?: ChipProps['render'];
|
|
486
486
|
color?: ChipProps['color'];
|
|
487
|
+
emphasis?: ChipProps['emphasis'];
|
|
487
488
|
}
|
|
488
489
|
function ComboboxGroupItem({
|
|
489
490
|
className,
|
|
490
491
|
replace,
|
|
491
492
|
render,
|
|
492
493
|
color = 'gray',
|
|
494
|
+
emphasis = 'default',
|
|
493
495
|
children,
|
|
494
496
|
...props
|
|
495
497
|
}: ComboboxGroupItemProps) {
|
|
@@ -498,8 +500,7 @@ function ComboboxGroupItem({
|
|
|
498
500
|
render={
|
|
499
501
|
replace ?? (
|
|
500
502
|
<Button
|
|
501
|
-
emphasis=
|
|
502
|
-
render={<Chip render={render} color={color} />}
|
|
503
|
+
render={<Chip render={render} color={color} emphasis={emphasis} />}
|
|
503
504
|
/>
|
|
504
505
|
)
|
|
505
506
|
}
|
|
@@ -542,6 +543,8 @@ function ComboboxClear({ children, ...props }: ComboboxClearProps) {
|
|
|
542
543
|
);
|
|
543
544
|
}
|
|
544
545
|
|
|
546
|
+
const Details = withClassName(SlotDiv, cls.details);
|
|
547
|
+
|
|
545
548
|
const baseSubComponents = {
|
|
546
549
|
useFilter: BaseCombobox.Combobox.useFilter,
|
|
547
550
|
|
|
@@ -578,6 +581,7 @@ const baseSubComponents = {
|
|
|
578
581
|
GroupItem: ComboboxGroupItem,
|
|
579
582
|
|
|
580
583
|
Unstyled: BaseCombobox.Combobox,
|
|
584
|
+
Details,
|
|
581
585
|
};
|
|
582
586
|
|
|
583
587
|
function createCombobox<TItem>() {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useField } from 'formik';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
2
3
|
import { useIdOrGenerated } from '../../hooks/useIdOrGenerated.js';
|
|
3
|
-
import { Box } from '../box/Box.js';
|
|
4
4
|
import { Checkbox } from '../checkbox/index.js';
|
|
5
|
-
import {
|
|
5
|
+
import { Field } from './Field.js';
|
|
6
6
|
|
|
7
7
|
export interface CheckboxFieldProps {
|
|
8
8
|
name: string;
|
|
@@ -10,6 +10,7 @@ export interface CheckboxFieldProps {
|
|
|
10
10
|
required?: boolean;
|
|
11
11
|
className?: string;
|
|
12
12
|
id?: string;
|
|
13
|
+
description?: ReactNode;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export function CheckboxField({
|
|
@@ -18,24 +19,31 @@ export function CheckboxField({
|
|
|
18
19
|
className,
|
|
19
20
|
required,
|
|
20
21
|
id: providedId,
|
|
22
|
+
description,
|
|
21
23
|
...rest
|
|
22
24
|
}: CheckboxFieldProps) {
|
|
23
25
|
const [props, _, tools] = useField({ name, required, type: 'checkbox' });
|
|
24
26
|
const id = useIdOrGenerated(providedId);
|
|
25
27
|
return (
|
|
26
|
-
<
|
|
27
|
-
<
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
<Field horizontal className={className}>
|
|
29
|
+
<Field.Control>
|
|
30
|
+
<Checkbox
|
|
31
|
+
{...props}
|
|
32
|
+
checked={props.checked}
|
|
33
|
+
onCheckedChange={(v) => {
|
|
34
|
+
tools.setValue(!!v);
|
|
35
|
+
}}
|
|
36
|
+
id={id}
|
|
37
|
+
aria-describedby={description ? `${id}-description` : undefined}
|
|
38
|
+
{...rest}
|
|
39
|
+
/>
|
|
40
|
+
</Field.Control>
|
|
41
|
+
{label && <Field.Label htmlFor={id}>{label}</Field.Label>}
|
|
42
|
+
{description && (
|
|
43
|
+
<Field.Description id={`${id}-description`}>
|
|
44
|
+
{description}
|
|
45
|
+
</Field.Description>
|
|
38
46
|
)}
|
|
39
|
-
</
|
|
47
|
+
</Field>
|
|
40
48
|
);
|
|
41
49
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { useField } from 'formik';
|
|
2
|
-
import { useState } from 'react';
|
|
2
|
+
import { ReactNode, useState } from 'react';
|
|
3
3
|
import { useIdOrGenerated } from '../../hooks/useIdOrGenerated.js';
|
|
4
|
-
import { Box } from '../box/Box.js';
|
|
5
4
|
import { Button, ButtonProps } from '../button/Button.js';
|
|
6
5
|
import { EmojiPicker } from '../emojiPicker/EmojiPicker.js';
|
|
7
6
|
import { Icon } from '../icon/Icon.js';
|
|
8
7
|
import { Popover } from '../popover/Popover.js';
|
|
9
8
|
import cls from './EmojiField.module.css';
|
|
10
|
-
import {
|
|
9
|
+
import { Field } from './Field.js';
|
|
11
10
|
|
|
12
11
|
export type EmojiFieldProps = Omit<ButtonProps, 'className'> & {
|
|
13
12
|
name: string;
|
|
14
13
|
label?: string;
|
|
15
14
|
required?: string;
|
|
16
15
|
className?: string;
|
|
16
|
+
description?: ReactNode;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
export function EmojiField({
|
|
@@ -22,44 +22,61 @@ export function EmojiField({
|
|
|
22
22
|
className,
|
|
23
23
|
required,
|
|
24
24
|
id: providedId,
|
|
25
|
+
description,
|
|
25
26
|
...rest
|
|
26
27
|
}: EmojiFieldProps) {
|
|
27
28
|
const [props, _, tools] = useField({ name });
|
|
28
29
|
const id = useIdOrGenerated(providedId);
|
|
29
30
|
const [open, setOpen] = useState(false);
|
|
30
31
|
return (
|
|
31
|
-
<
|
|
32
|
-
<
|
|
33
|
-
<Popover
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
{props.value || <Icon name="smile" />}
|
|
38
|
-
</Button.Icon>
|
|
39
|
-
</Button>
|
|
40
|
-
}
|
|
41
|
-
/>
|
|
42
|
-
<Popover.Content>
|
|
43
|
-
<EmojiPicker
|
|
44
|
-
onValueChange={(v) => {
|
|
45
|
-
tools.setValue(v);
|
|
46
|
-
setOpen(false);
|
|
47
|
-
}}
|
|
48
|
-
onClear={
|
|
49
|
-
required
|
|
50
|
-
? undefined
|
|
51
|
-
: () => {
|
|
52
|
-
tools.setValue('');
|
|
53
|
-
setOpen(false);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
32
|
+
<Field horizontal className={className}>
|
|
33
|
+
<Field.Control>
|
|
34
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
35
|
+
<input
|
|
36
|
+
type="hidden"
|
|
37
|
+
{...props}
|
|
56
38
|
id={id}
|
|
39
|
+
aria-describedby={description ? `${id}-description` : undefined}
|
|
40
|
+
/>
|
|
41
|
+
<Popover.Trigger
|
|
42
|
+
render={
|
|
43
|
+
<Button
|
|
44
|
+
id={`${id}-trigger`}
|
|
45
|
+
aria-label="Select emoji"
|
|
46
|
+
size="wrapper"
|
|
47
|
+
{...rest}
|
|
48
|
+
>
|
|
49
|
+
<Button.Icon className={cls.triggerIcon}>
|
|
50
|
+
{props.value || <Icon name="smile" />}
|
|
51
|
+
</Button.Icon>
|
|
52
|
+
</Button>
|
|
53
|
+
}
|
|
57
54
|
/>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
<Popover.Content>
|
|
56
|
+
<EmojiPicker
|
|
57
|
+
onValueChange={(v) => {
|
|
58
|
+
tools.setValue(v);
|
|
59
|
+
setOpen(false);
|
|
60
|
+
}}
|
|
61
|
+
onClear={
|
|
62
|
+
required
|
|
63
|
+
? undefined
|
|
64
|
+
: () => {
|
|
65
|
+
tools.setValue('');
|
|
66
|
+
setOpen(false);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
id={id}
|
|
70
|
+
/>
|
|
71
|
+
</Popover.Content>
|
|
72
|
+
</Popover>
|
|
73
|
+
</Field.Control>
|
|
74
|
+
{label && <Field.Label htmlFor={id}>{label}</Field.Label>}
|
|
75
|
+
{description && (
|
|
76
|
+
<Field.Description id={`${id}-description`}>
|
|
77
|
+
{description}
|
|
78
|
+
</Field.Description>
|
|
62
79
|
)}
|
|
63
|
-
</
|
|
80
|
+
</Field>
|
|
64
81
|
);
|
|
65
82
|
}
|