@mohirlab/react 0.2.0 → 0.4.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/dist/components/badge/badge.css.d.ts +1 -5
- package/dist/components/badge/badge.css.d.ts.map +1 -1
- package/dist/components/button/button.css.d.ts +3 -4
- package/dist/components/button/button.css.d.ts.map +1 -1
- package/dist/components/choice/choice.d.ts +46 -0
- package/dist/components/choice/choice.d.ts.map +1 -0
- package/dist/components/choice/choice.js +184 -0
- package/dist/components/choice/choice.js.map +1 -0
- package/dist/components/choice/choice.styles.js +21 -0
- package/dist/components/choice/choice.styles.js.map +1 -0
- package/dist/components/choice/index.d.ts +2 -0
- package/dist/components/field/use-field-control.js +21 -0
- package/dist/components/field/use-field-control.js.map +1 -0
- package/dist/components/input/index.d.ts +2 -2
- package/dist/components/input/input.css.d.ts +2 -3
- package/dist/components/input/input.css.d.ts.map +1 -1
- package/dist/components/input/input.d.ts +12 -0
- package/dist/components/input/input.d.ts.map +1 -1
- package/dist/components/input/input.js +32 -11
- package/dist/components/input/input.js.map +1 -1
- package/dist/components/input/input.styles.js +3 -1
- package/dist/components/select/index.d.ts +2 -0
- package/dist/components/select/select.d.ts +14 -0
- package/dist/components/select/select.d.ts.map +1 -0
- package/dist/components/select/select.js +44 -0
- package/dist/components/select/select.js.map +1 -0
- package/dist/components/select/select.styles.js +7 -0
- package/dist/components/select/select.styles.js.map +1 -0
- package/dist/components/slider/index.d.ts +2 -0
- package/dist/components/slider/slider.d.ts +18 -0
- package/dist/components/slider/slider.d.ts.map +1 -0
- package/dist/components/slider/slider.js +50 -0
- package/dist/components/slider/slider.js.map +1 -0
- package/dist/components/slider/slider.styles.js +7 -0
- package/dist/components/slider/slider.styles.js.map +1 -0
- package/dist/components/text/text.css.d.ts +1 -2
- package/dist/components/text/text.css.d.ts.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.js +6 -3
- package/dist/styles.css +628 -274
- package/package.json +7 -6
|
@@ -2,10 +2,7 @@ import { RecipeVariants } from "@vanilla-extract/recipes";
|
|
|
2
2
|
declare const fill: `var(--${string})`;
|
|
3
3
|
declare const ink: `var(--${string})`;
|
|
4
4
|
declare const seal: `var(--${string})`;
|
|
5
|
-
/**
|
|
6
|
-
* Badges are stamps: monospaced, uppercase, tracked out, with a hard edge.
|
|
7
|
-
* They read as labels on a specimen drawer, not as candy pills.
|
|
8
|
-
*/
|
|
5
|
+
/** Soft pills in sentence case. The square seal is the Mohirlab mark. */
|
|
9
6
|
export declare const badge: import("@vanilla-extract/recipes").RuntimeFn<{
|
|
10
7
|
tone: {
|
|
11
8
|
neutral: {
|
|
@@ -50,7 +47,6 @@ export declare const badge: import("@vanilla-extract/recipes").RuntimeFn<{
|
|
|
50
47
|
[fill]: `var(--${string})`;
|
|
51
48
|
[ink]: `var(--${string})`;
|
|
52
49
|
};
|
|
53
|
-
boxShadow: "none";
|
|
54
50
|
};
|
|
55
51
|
false: {};
|
|
56
52
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"badge.css.d.ts","names":[],"sources":["../../../src/components/badge/badge.css.ts"],"mappings":";cAOM;cACA;cACA
|
|
1
|
+
{"version":3,"file":"badge.css.d.ts","names":[],"sources":["../../../src/components/badge/badge.css.ts"],"mappings":";cAOM;cACA;cACA;;qBAIO,0CAAK;;;;SAiBQ;SAA6B;SAAwB;;;;;SACtD;SAA0B;SAAyB;;;;;SAClD;SAA2B;SAA0B;;;;;SACrD;SAA2B;SAA0B;;;;;SACtD;SAA0B;SAAyB;;;;;;;SAGrD;SAAc;;;;;;YAOzB,gBAAgB,YAAY,sBAAsB"}
|
|
@@ -56,12 +56,11 @@ export declare const button: import("@vanilla-extract/recipes").RuntimeFn<{
|
|
|
56
56
|
backgroundColor: `var(--${string})`;
|
|
57
57
|
color: `var(--${string})`;
|
|
58
58
|
borderColor: `var(--${string})`;
|
|
59
|
-
|
|
59
|
+
boxShadow: `var(--${string})`;
|
|
60
60
|
selectors: {
|
|
61
61
|
'&:hover:not(:disabled):not([aria-disabled="true"])': {
|
|
62
|
-
borderColor: `color-mix(in oklch, var(--${string}), var(--${string})
|
|
63
|
-
|
|
64
|
-
backgroundColor: `color-mix(in oklch, var(--${string}), var(--${string}) 5%)`;
|
|
62
|
+
borderColor: `color-mix(in oklch, var(--${string}), var(--${string}) 35%)`;
|
|
63
|
+
backgroundColor: `color-mix(in oklch, var(--${string}), var(--${string}) 4%)`;
|
|
65
64
|
};
|
|
66
65
|
'&:active:not(:disabled):not([aria-disabled="true"])': {
|
|
67
66
|
backgroundColor: `color-mix(in oklch, var(--${string}), var(--${string}) 10%)`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button.css.d.ts","names":[],"sources":["../../../src/components/button/button.css.ts"],"mappings":";cAkBM;cACA;cACA;cACA;cACA;cACA;qBAIO,2CAAM;;;;SA8BR;SACA;SACA;SACA;SACA;SACA;;;;;SAKA;SACA;SACA;SACA;SACA;SACA;;;;;SAKA;SACA;SACA;SACA;SACA;SACA
|
|
1
|
+
{"version":3,"file":"button.css.d.ts","names":[],"sources":["../../../src/components/button/button.css.ts"],"mappings":";cAkBM;cACA;cACA;cACA;cACA;cACA;qBAIO,2CAAM;;;;SA8BR;SACA;SACA;SACA;SACA;SACA;;;;;SAKA;SACA;SACA;SACA;SACA;SACA;;;;;SAKA;SACA;SACA;SACA;SACA;SACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA0EC,iBAAiB,YAAY,sBAAsB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ComponentPropsWithRef, ReactNode } from "react";
|
|
2
|
+
type NativeInput = Omit<ComponentPropsWithRef<'input'>, 'type' | 'size'>;
|
|
3
|
+
interface ChoiceText {
|
|
4
|
+
/** Visible label. The whole row is clickable. */
|
|
5
|
+
label: ReactNode;
|
|
6
|
+
/** Secondary text under the label, linked with `aria-describedby`. */
|
|
7
|
+
description?: ReactNode;
|
|
8
|
+
invalid?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface CheckboxProps extends NativeInput, ChoiceText {
|
|
11
|
+
/** Mixed state, e.g. "some items selected". Shown as a dash; clicking resolves it. */
|
|
12
|
+
indeterminate?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** A native checkbox, drawn in the Mohirlab style. */
|
|
15
|
+
export declare function Checkbox({ label, description, invalid, indeterminate, className, ref, ...rest }: CheckboxProps): import("react").JSX.Element;
|
|
16
|
+
export interface SwitchProps extends NativeInput, ChoiceText {}
|
|
17
|
+
/**
|
|
18
|
+
* An on/off setting that applies immediately (no Save button). A native checkbox with
|
|
19
|
+
* `role="switch"`, so it is announced as a switch and submits with forms.
|
|
20
|
+
*/
|
|
21
|
+
export declare function Switch({ label, description, invalid, className, ...rest }: SwitchProps): import("react").JSX.Element;
|
|
22
|
+
export interface RadioGroupProps extends Omit<ComponentPropsWithRef<'fieldset'>, 'onChange' | 'defaultValue'> {
|
|
23
|
+
/** Names the group for assistive technology. */
|
|
24
|
+
legend: ReactNode;
|
|
25
|
+
/** Shared `name`; generated if omitted. */
|
|
26
|
+
name?: string;
|
|
27
|
+
value?: string;
|
|
28
|
+
defaultValue?: string;
|
|
29
|
+
onValueChange?: (value: string) => void;
|
|
30
|
+
hint?: ReactNode;
|
|
31
|
+
error?: ReactNode;
|
|
32
|
+
orientation?: 'vertical' | 'horizontal';
|
|
33
|
+
children: ReactNode;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A `<fieldset>` of radios: arrow keys move between options natively, the legend names
|
|
37
|
+
* the group, and hint and error are linked to it.
|
|
38
|
+
*/
|
|
39
|
+
export declare function RadioGroup({ legend, name, value, defaultValue, onValueChange, hint, error, orientation, disabled, className, children, ...rest }: RadioGroupProps): import("react").JSX.Element;
|
|
40
|
+
export interface RadioProps extends Omit<NativeInput, 'name'>, Omit<ChoiceText, 'invalid'> {
|
|
41
|
+
value: string;
|
|
42
|
+
}
|
|
43
|
+
/** One option of a `RadioGroup`. */
|
|
44
|
+
export declare function Radio({ label, description, value, className, ...rest }: RadioProps): import("react").JSX.Element;
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=choice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"choice.d.ts","names":[],"sources":["../../../src/components/choice/choice.tsx"],"mappings":";KAeK,cAAc,KAAK;UAEd;;EAER,OAAO;;EAEP,cAAc;EACd;;iBAmCe,sBAAsB,aAAa;;EAElD;;;wBAIc,WACd,OACA,aACA,SACA,eACA,WACA,QACG,QACF,gCAAa,IAAA;iBAkCC,oBAAoB,aAAa;;;;;wBAMlC,SAAS,OAAO,aAAa,SAAS,cAAc,QAAQ,8BAAW,IAAA;iBAwCtE,wBAAwB,KACvC;;EAIA,QAAQ;;EAER;EACA;EACA;EACA,iBAAiB;EACjB,OAAO;EACP,QAAQ;EACR;EACA,UAAU;;;;;;wBAOI,aACd,QACA,MACA,OACA,cACA,eACA,MACA,OACA,aACA,UACA,WACA,aACG,QACF,kCAAe,IAAA;iBAiDD,mBAAmB,KAAK,sBAAsB,KAAK;EAClE;;;wBAIc,QAAQ,OAAO,aAAa,OAAO,cAAc,QAAQ,6BAAU,IAAA"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { createContext, useContext, useEffect, useId, useRef } from "react";
|
|
2
|
+
import { iconCheck, iconMinus } from "@mohirlab/icons";
|
|
3
|
+
import { cx } from "../../utils/cx.js";
|
|
4
|
+
import { Icon } from "../icon/icon.js";
|
|
5
|
+
import { box, check, checkbox, dash, dot, group, item, label, legend, options, radio, row, thumb, track } from "./choice.styles.js";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
// src/components/choice/choice.tsx
|
|
8
|
+
function Row({ control, label: label$1, description: description$1, descriptionId, className, kind }) {
|
|
9
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
10
|
+
className: cx(item, className),
|
|
11
|
+
"data-kind": kind,
|
|
12
|
+
children: [/* @__PURE__ */ jsxs("label", {
|
|
13
|
+
className: row,
|
|
14
|
+
children: [control, /* @__PURE__ */ jsx("span", {
|
|
15
|
+
className: label,
|
|
16
|
+
children: label$1
|
|
17
|
+
})]
|
|
18
|
+
}), description$1 && /* @__PURE__ */ jsx("span", {
|
|
19
|
+
id: descriptionId,
|
|
20
|
+
className: "ml_m1yyzl3",
|
|
21
|
+
children: description$1
|
|
22
|
+
})]
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/** A native checkbox, drawn in the Mohirlab style. */
|
|
26
|
+
function Checkbox({ label, description, invalid, indeterminate = false, className, ref, ...rest }) {
|
|
27
|
+
const descriptionId = useId();
|
|
28
|
+
const inner = useRef(null);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (inner.current) inner.current.indeterminate = indeterminate;
|
|
31
|
+
}, [indeterminate]);
|
|
32
|
+
return /* @__PURE__ */ jsx(Row, {
|
|
33
|
+
className,
|
|
34
|
+
label,
|
|
35
|
+
description,
|
|
36
|
+
descriptionId,
|
|
37
|
+
control: /* @__PURE__ */ jsxs("span", {
|
|
38
|
+
className: box,
|
|
39
|
+
children: [
|
|
40
|
+
/* @__PURE__ */ jsx("input", {
|
|
41
|
+
...rest,
|
|
42
|
+
ref: (el) => {
|
|
43
|
+
inner.current = el;
|
|
44
|
+
if (typeof ref === "function") ref(el);
|
|
45
|
+
else if (ref) ref.current = el;
|
|
46
|
+
},
|
|
47
|
+
type: "checkbox",
|
|
48
|
+
className: checkbox,
|
|
49
|
+
"aria-invalid": invalid || void 0,
|
|
50
|
+
"aria-describedby": description ? descriptionId : rest["aria-describedby"]
|
|
51
|
+
}),
|
|
52
|
+
/* @__PURE__ */ jsx(Icon, {
|
|
53
|
+
icon: iconCheck,
|
|
54
|
+
size: 14,
|
|
55
|
+
strokeWidth: 2.25,
|
|
56
|
+
className: check
|
|
57
|
+
}),
|
|
58
|
+
/* @__PURE__ */ jsx(Icon, {
|
|
59
|
+
icon: iconMinus,
|
|
60
|
+
size: 14,
|
|
61
|
+
strokeWidth: 2.25,
|
|
62
|
+
className: dash
|
|
63
|
+
})
|
|
64
|
+
]
|
|
65
|
+
})
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* An on/off setting that applies immediately (no Save button). A native checkbox with
|
|
70
|
+
* `role="switch"`, so it is announced as a switch and submits with forms.
|
|
71
|
+
*/
|
|
72
|
+
function Switch({ label, description, invalid, className, ...rest }) {
|
|
73
|
+
const descriptionId = useId();
|
|
74
|
+
return /* @__PURE__ */ jsx(Row, {
|
|
75
|
+
kind: "switch",
|
|
76
|
+
className,
|
|
77
|
+
label,
|
|
78
|
+
description,
|
|
79
|
+
descriptionId,
|
|
80
|
+
control: /* @__PURE__ */ jsxs("span", {
|
|
81
|
+
className: box,
|
|
82
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
83
|
+
...rest,
|
|
84
|
+
type: "checkbox",
|
|
85
|
+
role: "switch",
|
|
86
|
+
className: track,
|
|
87
|
+
"aria-invalid": invalid || void 0,
|
|
88
|
+
"aria-describedby": description ? descriptionId : rest["aria-describedby"]
|
|
89
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
90
|
+
className: thumb,
|
|
91
|
+
"aria-hidden": "true"
|
|
92
|
+
})]
|
|
93
|
+
})
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
const RadioGroupContext = createContext(null);
|
|
97
|
+
/**
|
|
98
|
+
* A `<fieldset>` of radios: arrow keys move between options natively, the legend names
|
|
99
|
+
* the group, and hint and error are linked to it.
|
|
100
|
+
*/
|
|
101
|
+
function RadioGroup({ legend: legend$1, name, value, defaultValue, onValueChange, hint, error, orientation = "vertical", disabled, className, children, ...rest }) {
|
|
102
|
+
const generated = useId();
|
|
103
|
+
const hintId = useId();
|
|
104
|
+
const errorId = useId();
|
|
105
|
+
const legendId = useId();
|
|
106
|
+
const describedBy = [error ? errorId : null, hint ? hintId : null].filter(Boolean).join(" ") || void 0;
|
|
107
|
+
return /* @__PURE__ */ jsxs("fieldset", {
|
|
108
|
+
...rest,
|
|
109
|
+
role: "radiogroup",
|
|
110
|
+
disabled,
|
|
111
|
+
"aria-labelledby": legendId,
|
|
112
|
+
"aria-describedby": describedBy,
|
|
113
|
+
"aria-invalid": error ? true : void 0,
|
|
114
|
+
className: cx(group, className),
|
|
115
|
+
children: [
|
|
116
|
+
/* @__PURE__ */ jsx("legend", {
|
|
117
|
+
id: legendId,
|
|
118
|
+
className: legend,
|
|
119
|
+
children: legend$1
|
|
120
|
+
}),
|
|
121
|
+
/* @__PURE__ */ jsx(RadioGroupContext.Provider, {
|
|
122
|
+
value: {
|
|
123
|
+
name: name ?? `ml-radio-${generated}`,
|
|
124
|
+
value,
|
|
125
|
+
defaultValue,
|
|
126
|
+
disabled,
|
|
127
|
+
invalid: Boolean(error),
|
|
128
|
+
onChange: onValueChange ? (event) => onValueChange(event.target.value) : void 0
|
|
129
|
+
},
|
|
130
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
131
|
+
className: options,
|
|
132
|
+
"data-orientation": orientation,
|
|
133
|
+
children
|
|
134
|
+
})
|
|
135
|
+
}),
|
|
136
|
+
error && /* @__PURE__ */ jsx("p", {
|
|
137
|
+
id: errorId,
|
|
138
|
+
className: "ml_m1yyzlg",
|
|
139
|
+
children: error
|
|
140
|
+
}),
|
|
141
|
+
hint && /* @__PURE__ */ jsx("p", {
|
|
142
|
+
id: hintId,
|
|
143
|
+
className: "ml_m1yyzlf",
|
|
144
|
+
children: hint
|
|
145
|
+
})
|
|
146
|
+
]
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
/** One option of a `RadioGroup`. */
|
|
150
|
+
function Radio({ label, description, value, className, ...rest }) {
|
|
151
|
+
const group = useContext(RadioGroupContext);
|
|
152
|
+
const descriptionId = useId();
|
|
153
|
+
if (!group) throw new Error("<Radio> must be used inside <RadioGroup>.");
|
|
154
|
+
const controlled = group.value !== void 0;
|
|
155
|
+
return /* @__PURE__ */ jsx(Row, {
|
|
156
|
+
className,
|
|
157
|
+
label,
|
|
158
|
+
description,
|
|
159
|
+
descriptionId,
|
|
160
|
+
control: /* @__PURE__ */ jsxs("span", {
|
|
161
|
+
className: box,
|
|
162
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
163
|
+
...rest,
|
|
164
|
+
type: "radio",
|
|
165
|
+
name: group.name,
|
|
166
|
+
value,
|
|
167
|
+
checked: controlled ? group.value === value : void 0,
|
|
168
|
+
defaultChecked: !controlled && group.defaultValue !== void 0 ? group.defaultValue === value : void 0,
|
|
169
|
+
onChange: (event) => {
|
|
170
|
+
rest.onChange?.(event);
|
|
171
|
+
group.onChange?.(event);
|
|
172
|
+
},
|
|
173
|
+
className: radio,
|
|
174
|
+
"aria-describedby": description ? descriptionId : void 0
|
|
175
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
176
|
+
className: dot,
|
|
177
|
+
"aria-hidden": "true"
|
|
178
|
+
})]
|
|
179
|
+
})
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
export { Checkbox, Radio, RadioGroup, Switch };
|
|
183
|
+
|
|
184
|
+
//# sourceMappingURL=choice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"choice.js","names":["label","description","styles.item","styles.row","styles.label","styles.box","styles.checkbox","styles.check","styles.dash","styles.track","styles.thumb","legend","styles.group","styles.legend","styles.options","styles.radio","styles.dot"],"sources":["../../../src/components/choice/choice.tsx"],"sourcesContent":["import {\n createContext,\n useContext,\n useEffect,\n useId,\n useRef,\n type ChangeEvent,\n type ComponentPropsWithRef,\n type ReactNode,\n} from 'react';\nimport { iconCheck, iconMinus } from '@mohirlab/icons';\nimport { cx } from '../../utils/cx';\nimport { Icon } from '../icon';\nimport * as styles from './choice.css';\n\ntype NativeInput = Omit<ComponentPropsWithRef<'input'>, 'type' | 'size'>;\n\ninterface ChoiceText {\n /** Visible label. The whole row is clickable. */\n label: ReactNode;\n /** Secondary text under the label, linked with `aria-describedby`. */\n description?: ReactNode;\n invalid?: boolean;\n}\n\nfunction Row({\n control,\n label,\n description,\n descriptionId,\n className,\n kind,\n}: {\n control: ReactNode;\n label: ReactNode;\n description?: ReactNode;\n descriptionId: string;\n className?: string;\n kind?: 'switch';\n}) {\n // The description stays outside the <label>: inside, it would become part of the\n // accessible name. It is linked with aria-describedby instead.\n return (\n <div className={cx(styles.item, className)} data-kind={kind}>\n <label className={styles.row}>\n {control}\n <span className={styles.label}>{label}</span>\n </label>\n {description && (\n <span id={descriptionId} className={styles.description}>\n {description}\n </span>\n )}\n </div>\n );\n}\n\nexport interface CheckboxProps extends NativeInput, ChoiceText {\n /** Mixed state, e.g. \"some items selected\". Shown as a dash; clicking resolves it. */\n indeterminate?: boolean;\n}\n\n/** A native checkbox, drawn in the Mohirlab style. */\nexport function Checkbox({\n label,\n description,\n invalid,\n indeterminate = false,\n className,\n ref,\n ...rest\n}: CheckboxProps) {\n const descriptionId = useId();\n const inner = useRef<HTMLInputElement>(null);\n useEffect(() => {\n if (inner.current) inner.current.indeterminate = indeterminate;\n }, [indeterminate]);\n return (\n <Row\n className={className}\n label={label}\n description={description}\n descriptionId={descriptionId}\n control={\n <span className={styles.box}>\n <input\n {...rest}\n ref={(el) => {\n inner.current = el;\n if (typeof ref === 'function') ref(el);\n else if (ref) ref.current = el;\n }}\n type=\"checkbox\"\n className={styles.checkbox}\n aria-invalid={invalid || undefined}\n aria-describedby={description ? descriptionId : rest['aria-describedby']}\n />\n <Icon icon={iconCheck} size={14} strokeWidth={2.25} className={styles.check} />\n <Icon icon={iconMinus} size={14} strokeWidth={2.25} className={styles.dash} />\n </span>\n }\n />\n );\n}\n\nexport interface SwitchProps extends NativeInput, ChoiceText {}\n\n/**\n * An on/off setting that applies immediately (no Save button). A native checkbox with\n * `role=\"switch\"`, so it is announced as a switch and submits with forms.\n */\nexport function Switch({ label, description, invalid, className, ...rest }: SwitchProps) {\n const descriptionId = useId();\n return (\n <Row\n kind=\"switch\"\n className={className}\n label={label}\n description={description}\n descriptionId={descriptionId}\n control={\n <span className={styles.box}>\n <input\n {...rest}\n type=\"checkbox\"\n // The browser exposes a native checkbox's checked state to the switch role;\n // a hand-set aria-checked could only drift out of sync.\n // oxlint-disable-next-line jsx-a11y/role-has-required-aria-props\n role=\"switch\"\n className={styles.track}\n aria-invalid={invalid || undefined}\n aria-describedby={description ? descriptionId : rest['aria-describedby']}\n />\n <span className={styles.thumb} aria-hidden=\"true\" />\n </span>\n }\n />\n );\n}\n\ninterface RadioGroupContextValue {\n name: string;\n value?: string;\n defaultValue?: string;\n disabled?: boolean;\n invalid: boolean;\n onChange?: (event: ChangeEvent<HTMLInputElement>) => void;\n}\n\nconst RadioGroupContext = createContext<RadioGroupContextValue | null>(null);\n\nexport interface RadioGroupProps extends Omit<\n ComponentPropsWithRef<'fieldset'>,\n 'onChange' | 'defaultValue'\n> {\n /** Names the group for assistive technology. */\n legend: ReactNode;\n /** Shared `name`; generated if omitted. */\n name?: string;\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n hint?: ReactNode;\n error?: ReactNode;\n orientation?: 'vertical' | 'horizontal';\n children: ReactNode;\n}\n\n/**\n * A `<fieldset>` of radios: arrow keys move between options natively, the legend names\n * the group, and hint and error are linked to it.\n */\nexport function RadioGroup({\n legend,\n name,\n value,\n defaultValue,\n onValueChange,\n hint,\n error,\n orientation = 'vertical',\n disabled,\n className,\n children,\n ...rest\n}: RadioGroupProps) {\n const generated = useId();\n const hintId = useId();\n const errorId = useId();\n const legendId = useId();\n const describedBy = [error ? errorId : null, hint ? hintId : null].filter(Boolean).join(' ') || undefined;\n return (\n // role=\"radiogroup\" (rather than the fieldset's implicit \"group\") is what carries\n // aria-invalid for the whole set; individual radios cannot.\n <fieldset\n {...rest}\n role=\"radiogroup\"\n disabled={disabled}\n aria-labelledby={legendId}\n aria-describedby={describedBy}\n aria-invalid={error ? true : undefined}\n className={cx(styles.group, className)}\n >\n <legend id={legendId} className={styles.legend}>\n {legend}\n </legend>\n <RadioGroupContext.Provider\n value={{\n name: name ?? `ml-radio-${generated}`,\n value,\n defaultValue,\n disabled,\n invalid: Boolean(error),\n onChange: onValueChange ? (event) => onValueChange(event.target.value) : undefined,\n }}\n >\n <div className={styles.options} data-orientation={orientation}>\n {children}\n </div>\n </RadioGroupContext.Provider>\n {error && (\n <p id={errorId} className={styles.groupError}>\n {error}\n </p>\n )}\n {hint && (\n <p id={hintId} className={styles.groupHint}>\n {hint}\n </p>\n )}\n </fieldset>\n );\n}\n\nexport interface RadioProps extends Omit<NativeInput, 'name'>, Omit<ChoiceText, 'invalid'> {\n value: string;\n}\n\n/** One option of a `RadioGroup`. */\nexport function Radio({ label, description, value, className, ...rest }: RadioProps) {\n const group = useContext(RadioGroupContext);\n const descriptionId = useId();\n if (!group) throw new Error('<Radio> must be used inside <RadioGroup>.');\n const controlled = group.value !== undefined;\n return (\n <Row\n className={className}\n label={label}\n description={description}\n descriptionId={descriptionId}\n control={\n <span className={styles.box}>\n <input\n {...rest}\n type=\"radio\"\n name={group.name}\n value={value}\n checked={controlled ? group.value === value : undefined}\n defaultChecked={\n !controlled && group.defaultValue !== undefined ? group.defaultValue === value : undefined\n }\n onChange={(event) => {\n rest.onChange?.(event);\n group.onChange?.(event);\n }}\n className={styles.radio}\n aria-describedby={description ? descriptionId : undefined}\n />\n <span className={styles.dot} aria-hidden=\"true\" />\n </span>\n }\n />\n );\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/components/choice/choice.css.ts
|
|
2
|
+
var box = "ml_m1yyzl4";
|
|
3
|
+
var check = "ml_m1yyzl7";
|
|
4
|
+
var checkbox = "ml_m1yyzl5";
|
|
5
|
+
var dash = "ml_m1yyzl8";
|
|
6
|
+
var description = "ml_m1yyzl3";
|
|
7
|
+
var dot = "ml_m1yyzl9";
|
|
8
|
+
var group = "ml_m1yyzlc";
|
|
9
|
+
var groupError = "ml_m1yyzlg";
|
|
10
|
+
var groupHint = "ml_m1yyzlf";
|
|
11
|
+
var item = "ml_m1yyzl1";
|
|
12
|
+
var label = "ml_m1yyzl2";
|
|
13
|
+
var legend = "ml_m1yyzld";
|
|
14
|
+
var options = "ml_m1yyzle";
|
|
15
|
+
var radio = "ml_m1yyzl6";
|
|
16
|
+
var row = "ml_m1yyzl0";
|
|
17
|
+
var thumb = "ml_m1yyzlb";
|
|
18
|
+
var track = "ml_m1yyzla";
|
|
19
|
+
export { box, check, checkbox, dash, description, dot, group, groupError, groupHint, item, label, legend, options, radio, row, thumb, track };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=choice.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"choice.styles.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useField } from "./field-context.js";
|
|
2
|
+
// src/components/field/use-field-control.ts
|
|
3
|
+
/**
|
|
4
|
+
* Props a form control takes from the surrounding `<Field>`: id (for the label),
|
|
5
|
+
* required, disabled, invalid state and the hint/error description. Anything set
|
|
6
|
+
* on the control itself wins; descriptions are merged.
|
|
7
|
+
*/
|
|
8
|
+
function useFieldControl({ id, required, disabled, invalid, "aria-describedby": describedBy }) {
|
|
9
|
+
const field = useField();
|
|
10
|
+
const isInvalid = invalid ?? field?.invalid ?? false;
|
|
11
|
+
return {
|
|
12
|
+
id: id ?? field?.id,
|
|
13
|
+
required: required ?? field?.required,
|
|
14
|
+
disabled: disabled ?? field?.disabled,
|
|
15
|
+
"aria-invalid": isInvalid || void 0,
|
|
16
|
+
"aria-describedby": [field?.describedBy, describedBy].filter(Boolean).join(" ") || void 0
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export { useFieldControl };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=use-field-control.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-field-control.js","names":[],"sources":["../../../src/components/field/use-field-control.ts"],"sourcesContent":["import { useField } from './field-context';\n\ninterface ControlProps {\n id?: string;\n required?: boolean;\n disabled?: boolean;\n invalid?: boolean;\n 'aria-describedby'?: string;\n}\n\n/**\n * Props a form control takes from the surrounding `<Field>`: id (for the label),\n * required, disabled, invalid state and the hint/error description. Anything set\n * on the control itself wins; descriptions are merged.\n */\nexport function useFieldControl({\n id,\n required,\n disabled,\n invalid,\n 'aria-describedby': describedBy,\n}: ControlProps) {\n const field = useField();\n const isInvalid = invalid ?? field?.invalid ?? false;\n return {\n id: id ?? field?.id,\n required: required ?? field?.required,\n disabled: disabled ?? field?.disabled,\n 'aria-invalid': isInvalid || undefined,\n 'aria-describedby': [field?.describedBy, describedBy].filter(Boolean).join(' ') || undefined,\n } as const;\n}\n"],"mappings":";;;;;;;AAeA,SAAgB,gBAAgB,EAC9B,IACA,UACA,UACA,SACA,oBAAoB,eACL;CACf,MAAM,QAAQ,SAAS;CACvB,MAAM,YAAY,WAAW,OAAO,WAAW;CAC/C,OAAO;EACL,IAAI,MAAM,OAAO;EACjB,UAAU,YAAY,OAAO;EAC7B,UAAU,YAAY,OAAO;EAC7B,gBAAgB,aAAa,KAAA;EAC7B,oBAAoB,CAAC,OAAO,aAAa,WAAW,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,KAAK,KAAA;CACrF;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Input, InputProps } from "./input.js";
|
|
2
|
-
export { Input, type InputProps };
|
|
1
|
+
import { Input, InputProps, Textarea, TextareaProps } from "./input.js";
|
|
2
|
+
export { Input, type InputProps, Textarea, type TextareaProps };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { RecipeVariants } from "@vanilla-extract/recipes";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* rule in the accent color and warms the field slightly.
|
|
3
|
+
* A calm field: hairline border, soft lift, rounded corners. Focus turns the border
|
|
4
|
+
* to the accent and adds a soft halo; invalid does the same in the danger tone.
|
|
6
5
|
*/
|
|
7
6
|
export declare const input: import("@vanilla-extract/recipes").RuntimeFn<{
|
|
8
7
|
size: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.css.d.ts","names":[],"sources":["../../../src/components/input/input.css.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"input.css.d.ts","names":[],"sources":["../../../src/components/input/input.css.ts"],"mappings":";;;;;qBAgBa,0CAAK;;IAqCZ,mCAAE;IACF,mCAAE;IACF,mCAAE;;;YAMI,gBAAgB,YAAY,sBAAsB"}
|
|
@@ -6,4 +6,16 @@ export interface InputProps extends Omit<ComponentPropsWithRef<'input'>, 'size'>
|
|
|
6
6
|
invalid?: boolean;
|
|
7
7
|
}
|
|
8
8
|
export declare function Input({ size, invalid, className, id, required, disabled, ...rest }: InputProps): import("react").JSX.Element;
|
|
9
|
+
export interface TextareaProps extends ComponentPropsWithRef<'textarea'> {
|
|
10
|
+
invalid?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Grow with the content up to `maxRows`, where the browser supports CSS
|
|
13
|
+
* `field-sizing` (Chrome 123, Safari 26.2, Firefox 152). Elsewhere the user can
|
|
14
|
+
* resize it. Default true.
|
|
15
|
+
*/
|
|
16
|
+
autoGrow?: boolean;
|
|
17
|
+
/** Upper bound for auto-grow, in lines. Default 10. */
|
|
18
|
+
maxRows?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare function Textarea({ invalid, autoGrow, rows, maxRows, className, style, id, required, disabled, ...rest }: TextareaProps): import("react").JSX.Element;
|
|
9
21
|
//# sourceMappingURL=input.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.d.ts","names":[],"sources":["../../../src/components/input/input.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"input.d.ts","names":[],"sources":["../../../src/components/input/input.tsx"],"mappings":";;iBAMiB,mBAAmB,KAAK;EACvC,OAAO;;EAEP;;wBAGc,QAAQ,MAAM,SAAS,WAAW,IAAI,UAAU,aAAa,QAAQ,6BAAU,IAAA;iBAW9E,sBAAsB;EACrC;;;;;;EAMA;;EAEA;;wBAGc,WACd,SACA,UACA,MACA,SACA,WACA,OACA,IACA,UACA,aACG,QACF,gCAAa,IAAA"}
|
|
@@ -1,22 +1,43 @@
|
|
|
1
|
+
import { assignInlineVars } from "@vanilla-extract/dynamic";
|
|
1
2
|
import { cx } from "../../utils/cx.js";
|
|
2
|
-
import {
|
|
3
|
-
import { input } from "./input.styles.js";
|
|
3
|
+
import { useFieldControl } from "../field/use-field-control.js";
|
|
4
|
+
import { input, maxRows, textarea } from "./input.styles.js";
|
|
4
5
|
import { jsx } from "react/jsx-runtime";
|
|
5
6
|
// src/components/input/input.tsx
|
|
6
7
|
function Input({ size, invalid, className, id, required, disabled, ...rest }) {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const control = useFieldControl({
|
|
9
|
+
id,
|
|
10
|
+
required,
|
|
11
|
+
disabled,
|
|
12
|
+
invalid,
|
|
13
|
+
"aria-describedby": rest["aria-describedby"]
|
|
14
|
+
});
|
|
10
15
|
return /* @__PURE__ */ jsx("input", {
|
|
11
16
|
...rest,
|
|
12
|
-
|
|
13
|
-
required: required ?? field?.required,
|
|
14
|
-
disabled: disabled ?? field?.disabled,
|
|
15
|
-
"aria-describedby": describedBy,
|
|
16
|
-
"aria-invalid": isInvalid || void 0,
|
|
17
|
+
...control,
|
|
17
18
|
className: cx(input({ size }), className)
|
|
18
19
|
});
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
+
function Textarea({ invalid, autoGrow = true, rows = 3, maxRows: maxRows$1 = 10, className, style, id, required, disabled, ...rest }) {
|
|
22
|
+
const control = useFieldControl({
|
|
23
|
+
id,
|
|
24
|
+
required,
|
|
25
|
+
disabled,
|
|
26
|
+
invalid,
|
|
27
|
+
"aria-describedby": rest["aria-describedby"]
|
|
28
|
+
});
|
|
29
|
+
return /* @__PURE__ */ jsx("textarea", {
|
|
30
|
+
...rest,
|
|
31
|
+
...control,
|
|
32
|
+
rows,
|
|
33
|
+
"data-autogrow": autoGrow || void 0,
|
|
34
|
+
className: cx(input({ size: "md" }), textarea, className),
|
|
35
|
+
style: {
|
|
36
|
+
...style,
|
|
37
|
+
...assignInlineVars({ [maxRows]: String(maxRows$1) })
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export { Input, Textarea };
|
|
21
42
|
|
|
22
43
|
//# sourceMappingURL=input.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.js","names":[],"sources":["../../../src/components/input/input.tsx"],"sourcesContent":["import type { ComponentPropsWithRef } from 'react';\nimport { cx } from '../../utils/cx';\nimport {
|
|
1
|
+
{"version":3,"file":"input.js","names":["maxRows","maxRowsVar"],"sources":["../../../src/components/input/input.tsx"],"sourcesContent":["import type { ComponentPropsWithRef } from 'react';\nimport { assignInlineVars } from '@vanilla-extract/dynamic';\nimport { cx } from '../../utils/cx';\nimport { useFieldControl } from '../field/use-field-control';\nimport { input, maxRows as maxRowsVar, textarea, type InputVariants } from './input.css';\n\nexport interface InputProps extends Omit<ComponentPropsWithRef<'input'>, 'size'> {\n size?: InputVariants['size'];\n /** Mark as invalid. Inside a `<Field error>` this is set for you. */\n invalid?: boolean;\n}\n\nexport function Input({ size, invalid, className, id, required, disabled, ...rest }: InputProps) {\n const control = useFieldControl({\n id,\n required,\n disabled,\n invalid,\n 'aria-describedby': rest['aria-describedby'],\n });\n return <input {...rest} {...control} className={cx(input({ size }), className)} />;\n}\n\nexport interface TextareaProps extends ComponentPropsWithRef<'textarea'> {\n invalid?: boolean;\n /**\n * Grow with the content up to `maxRows`, where the browser supports CSS\n * `field-sizing` (Chrome 123, Safari 26.2, Firefox 152). Elsewhere the user can\n * resize it. Default true.\n */\n autoGrow?: boolean;\n /** Upper bound for auto-grow, in lines. Default 10. */\n maxRows?: number;\n}\n\nexport function Textarea({\n invalid,\n autoGrow = true,\n rows = 3,\n maxRows = 10,\n className,\n style,\n id,\n required,\n disabled,\n ...rest\n}: TextareaProps) {\n const control = useFieldControl({\n id,\n required,\n disabled,\n invalid,\n 'aria-describedby': rest['aria-describedby'],\n });\n return (\n <textarea\n {...rest}\n {...control}\n rows={rows}\n data-autogrow={autoGrow || undefined}\n className={cx(input({ size: 'md' }), textarea, className)}\n style={{ ...style, ...assignInlineVars({ [maxRowsVar]: String(maxRows) }) }}\n />\n );\n}\n"],"mappings":";;;;;;AAYA,SAAgB,MAAM,EAAE,MAAM,SAAS,WAAW,IAAI,UAAU,UAAU,GAAG,QAAoB;CAC/F,MAAM,UAAU,gBAAgB;EAC9B;EACA;EACA;EACA;EACA,oBAAoB,KAAK;CAC3B,CAAC;CACD,OAAO,oBAAC,SAAD;EAAO,GAAI;EAAM,GAAI;EAAS,WAAW,GAAG,MAAM,EAAE,KAAK,CAAC,GAAG,SAAS;CAAI,CAAA;AACnF;AAcA,SAAgB,SAAS,EACvB,SACA,WAAW,MACX,OAAO,GACPA,SAAAA,YAAU,IACV,WACA,OACA,IACA,UACA,UACA,GAAG,QACa;CAChB,MAAM,UAAU,gBAAgB;EAC9B;EACA;EACA;EACA;EACA,oBAAoB,KAAK;CAC3B,CAAC;CACD,OACE,oBAAC,YAAD;EACE,GAAI;EACJ,GAAI;EACE;EACN,iBAAe,YAAY,KAAA;EAC3B,WAAW,GAAG,MAAM,EAAE,MAAM,KAAK,CAAC,GAAG,UAAU,SAAS;EACxD,OAAO;GAAE,GAAG;GAAO,GAAG,iBAAiB,GAAGC,UAAa,OAAOD,SAAO,EAAE,CAAC;EAAE;CAC3E,CAAA;AAEL"}
|
|
@@ -10,6 +10,8 @@ var input = createRuntimeFn({
|
|
|
10
10
|
defaultVariants: { size: "md" },
|
|
11
11
|
compoundVariants: []
|
|
12
12
|
});
|
|
13
|
-
|
|
13
|
+
var maxRows = "var(--ml_18bh0934)";
|
|
14
|
+
var textarea = "ml_18bh0935";
|
|
15
|
+
export { input, maxRows, textarea };
|
|
14
16
|
|
|
15
17
|
//# sourceMappingURL=input.styles.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ComponentPropsWithRef } from "react";
|
|
2
|
+
import { InputVariants } from "../input/input.css.js";
|
|
3
|
+
export interface SelectProps extends Omit<ComponentPropsWithRef<'select'>, 'size'> {
|
|
4
|
+
size?: InputVariants['size'];
|
|
5
|
+
invalid?: boolean;
|
|
6
|
+
/** Shown first and not selectable again once a choice is made, e.g. "Choose a country". */
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The native `<select>`, styled like `Input`. Phones get the system picker, keyboards
|
|
11
|
+
* and screen readers get native behaviour, and forms submit it as is.
|
|
12
|
+
*/
|
|
13
|
+
export declare function Select({ size, invalid, placeholder, className, id, required, disabled, children, defaultValue, value, ...rest }: SelectProps): import("react").JSX.Element;
|
|
14
|
+
//# sourceMappingURL=select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.d.ts","names":[],"sources":["../../../src/components/select/select.tsx"],"mappings":";;iBAQiB,oBAAoB,KAAK;EACxC,OAAO;EACP;;EAEA;;;;;;wBAOc,SACd,MACA,SACA,aACA,WACA,IACA,UACA,UACA,UACA,cACA,UACG,QACF,8BAAW,IAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { iconChevronDown } from "@mohirlab/icons";
|
|
2
|
+
import { cx } from "../../utils/cx.js";
|
|
3
|
+
import { useFieldControl } from "../field/use-field-control.js";
|
|
4
|
+
import { Icon } from "../icon/icon.js";
|
|
5
|
+
import { input } from "../input/input.styles.js";
|
|
6
|
+
import { chevron, select, wrap } from "./select.styles.js";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
// src/components/select/select.tsx
|
|
9
|
+
/**
|
|
10
|
+
* The native `<select>`, styled like `Input`. Phones get the system picker, keyboards
|
|
11
|
+
* and screen readers get native behaviour, and forms submit it as is.
|
|
12
|
+
*/
|
|
13
|
+
function Select({ size, invalid, placeholder, className, id, required, disabled, children, defaultValue, value, ...rest }) {
|
|
14
|
+
const control = useFieldControl({
|
|
15
|
+
id,
|
|
16
|
+
required,
|
|
17
|
+
disabled,
|
|
18
|
+
invalid,
|
|
19
|
+
"aria-describedby": rest["aria-describedby"]
|
|
20
|
+
});
|
|
21
|
+
const initial = placeholder && value === void 0 && defaultValue === void 0 ? "" : defaultValue;
|
|
22
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
23
|
+
className: wrap,
|
|
24
|
+
children: [/* @__PURE__ */ jsxs("select", {
|
|
25
|
+
...rest,
|
|
26
|
+
...control,
|
|
27
|
+
value,
|
|
28
|
+
defaultValue: initial,
|
|
29
|
+
className: cx(input({ size }), select, className),
|
|
30
|
+
children: [placeholder && /* @__PURE__ */ jsx("option", {
|
|
31
|
+
value: "",
|
|
32
|
+
disabled: true,
|
|
33
|
+
children: placeholder
|
|
34
|
+
}), children]
|
|
35
|
+
}), /* @__PURE__ */ jsx(Icon, {
|
|
36
|
+
icon: iconChevronDown,
|
|
37
|
+
className: chevron,
|
|
38
|
+
size: 18
|
|
39
|
+
})]
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
export { Select };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.js","names":["styles.wrap","styles.select","styles.chevron"],"sources":["../../../src/components/select/select.tsx"],"sourcesContent":["import type { ComponentPropsWithRef } from 'react';\nimport { iconChevronDown } from '@mohirlab/icons';\nimport { cx } from '../../utils/cx';\nimport { useFieldControl } from '../field/use-field-control';\nimport { Icon } from '../icon';\nimport { input, type InputVariants } from '../input/input.css';\nimport * as styles from './select.css';\n\nexport interface SelectProps extends Omit<ComponentPropsWithRef<'select'>, 'size'> {\n size?: InputVariants['size'];\n invalid?: boolean;\n /** Shown first and not selectable again once a choice is made, e.g. \"Choose a country\". */\n placeholder?: string;\n}\n\n/**\n * The native `<select>`, styled like `Input`. Phones get the system picker, keyboards\n * and screen readers get native behaviour, and forms submit it as is.\n */\nexport function Select({\n size,\n invalid,\n placeholder,\n className,\n id,\n required,\n disabled,\n children,\n defaultValue,\n value,\n ...rest\n}: SelectProps) {\n const control = useFieldControl({\n id,\n required,\n disabled,\n invalid,\n 'aria-describedby': rest['aria-describedby'],\n });\n // With a placeholder and no value given, start on the placeholder option.\n const initial = placeholder && value === undefined && defaultValue === undefined ? '' : defaultValue;\n return (\n <span className={styles.wrap}>\n <select\n {...rest}\n {...control}\n value={value}\n defaultValue={initial}\n className={cx(input({ size }), styles.select, className)}\n >\n {placeholder && (\n <option value=\"\" disabled>\n {placeholder}\n </option>\n )}\n {children}\n </select>\n <Icon icon={iconChevronDown} className={styles.chevron} size={18} />\n </span>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAmBA,SAAgB,OAAO,EACrB,MACA,SACA,aACA,WACA,IACA,UACA,UACA,UACA,cACA,OACA,GAAG,QACW;CACd,MAAM,UAAU,gBAAgB;EAC9B;EACA;EACA;EACA;EACA,oBAAoB,KAAK;CAC3B,CAAC;CAED,MAAM,UAAU,eAAe,UAAU,KAAA,KAAa,iBAAiB,KAAA,IAAY,KAAK;CACxF,OACE,qBAAC,QAAD;EAAM,WAAWA;EAAjB,UAAA,CACE,qBAAC,UAAD;GACE,GAAI;GACJ,GAAI;GACG;GACP,cAAc;GACd,WAAW,GAAG,MAAM,EAAE,KAAK,CAAC,GAAGC,QAAe,SAAS;GALzD,UAAA,CAOG,eACC,oBAAC,UAAD;IAAQ,OAAM;IAAG,UAAA;IACd,UAAA;GACK,CAAA,GAET,QACK;EACR,CAAA,GAAA,oBAAC,MAAD;GAAM,MAAM;GAAiB,WAAWC;GAAgB,MAAM;EAAK,CAAA,CAC/D;;AAEV"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.styles.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ComponentPropsWithRef, ReactNode } from "react";
|
|
2
|
+
export interface SliderProps extends Omit<ComponentPropsWithRef<'input'>, 'type' | 'value' | 'defaultValue' | 'size'> {
|
|
3
|
+
value?: number;
|
|
4
|
+
defaultValue?: number;
|
|
5
|
+
onValueChange?: (value: number) => void;
|
|
6
|
+
min?: number;
|
|
7
|
+
max?: number;
|
|
8
|
+
step?: number;
|
|
9
|
+
/** Format the value for `aria-valuetext` and for `SliderValue`, e.g. `(v) => \`${v}%\``. */
|
|
10
|
+
format?: (value: number) => string;
|
|
11
|
+
}
|
|
12
|
+
/** A native range input with a filled track. Arrow keys, Page Up/Down, Home and End work natively. */
|
|
13
|
+
export declare function Slider({ value, defaultValue, onValueChange, min, max, step, format, className, style, id, required, disabled, onChange, ...rest }: SliderProps): import("react").JSX.Element;
|
|
14
|
+
/** Label row for a slider inside a `Field`: puts the current value at the end. */
|
|
15
|
+
export declare function SliderValue({ children }: {
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
}): import("react").JSX.Element;
|
|
18
|
+
//# sourceMappingURL=slider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slider.d.ts","names":[],"sources":["../../../src/components/slider/slider.tsx"],"mappings":";iBAMiB,oBAAoB,KACnC;EAGA;EACA;EACA,iBAAiB;EACjB;EACA;EACA;;EAEA,UAAU;;;wBAII,SACd,OACA,cACA,eACA,KACA,KACA,MACA,QACA,WACA,OACA,IACA,UACA,UACA,aACG,QACF,8BAAW,IAAA;;wBA4BE,cAAc;EAAc,UAAU;oBAAW,IAAA"}
|