@milktop/react-ui 0.3.2 → 0.3.3
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/field/Field.d.ts +11 -2
- package/dist/field/Field.js +7 -1
- package/package.json +1 -1
package/dist/field/Field.d.ts
CHANGED
|
@@ -10,7 +10,10 @@
|
|
|
10
10
|
* - `label`, `hint`, `error` (shown instead of the hint), `required`
|
|
11
11
|
* - `span`: columns (of 12) to take inside Fields
|
|
12
12
|
* - without children it renders an Input, and the other props (value,
|
|
13
|
-
* onValueChange, type, placeholder, icon, suffix…) pass on to it
|
|
13
|
+
* onValueChange, type, placeholder, icon, suffix…) pass on to it; with
|
|
14
|
+
* type="number" a NumberInput (value a number or null, min, max, step…)
|
|
15
|
+
*
|
|
16
|
+
* <Field label="Rate" type="number" min={0} prefix="£" value={rate} onValueChange={setRate} />
|
|
14
17
|
*
|
|
15
18
|
* By hand, with Ark's Field parts:
|
|
16
19
|
*
|
|
@@ -23,11 +26,17 @@
|
|
|
23
26
|
import type { ComponentProps, ReactNode } from 'react';
|
|
24
27
|
import { Field as Ark } from '@ark-ui/react/field';
|
|
25
28
|
import { type InputProps } from '../input/Input.js';
|
|
29
|
+
import { type NumberInputProps } from '../number-input/NumberInput.js';
|
|
26
30
|
import { type Classes } from '../utils.js';
|
|
27
31
|
import '../theme.css';
|
|
28
32
|
import './field.css';
|
|
29
33
|
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
30
|
-
|
|
34
|
+
type Control = DistributiveOmit<Exclude<InputProps, {
|
|
35
|
+
type: 'number';
|
|
36
|
+
}>, 'label' | 'classes' | 'children'> | (Omit<NumberInputProps, 'label' | 'classes' | 'children'> & {
|
|
37
|
+
type: 'number';
|
|
38
|
+
});
|
|
39
|
+
export type FieldProps = Control & {
|
|
31
40
|
label?: ReactNode;
|
|
32
41
|
hint?: ReactNode;
|
|
33
42
|
error?: ReactNode;
|
package/dist/field/Field.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Field as Ark } from '@ark-ui/react/field';
|
|
3
3
|
import { Input } from '../input/Input.js';
|
|
4
|
+
import { NumberInput } from '../number-input/NumberInput.js';
|
|
4
5
|
import { cx, partsOf, withParts } from '../utils.js';
|
|
5
6
|
import '../theme.css';
|
|
6
7
|
import './field.css';
|
|
7
8
|
function FieldShortcut({ label = null, hint = null, error = null, required = false, disabled = false, span = 12, className, classes, style, children, ...inputProps }) {
|
|
8
9
|
const part = partsOf('field', classes);
|
|
9
|
-
return (_jsxs(Ark.Root, { ...part('root'), className: cx(className, classes?.root), style: { '--span': span, ...style }, invalid: !!error, required: required, disabled: disabled, children: [label && _jsxs(Ark.Label, { ...part('label'), children: [label, _jsx(Ark.RequiredIndicator, { ...part('required-indicator'), "aria-hidden": "true", children: " *" })] }), children ??
|
|
10
|
+
return (_jsxs(Ark.Root, { ...part('root'), className: cx(className, classes?.root), style: { '--span': span, ...style }, invalid: !!error, required: required, disabled: disabled, children: [label && _jsxs(Ark.Label, { ...part('label'), children: [label, _jsx(Ark.RequiredIndicator, { ...part('required-indicator'), "aria-hidden": "true", children: " *" })] }), children ?? control(inputProps), error ? _jsx(Ark.ErrorText, { ...part('error-text'), children: error })
|
|
10
11
|
: hint && _jsx(Ark.HelperText, { ...part('helper-text'), children: hint })] }));
|
|
11
12
|
}
|
|
13
|
+
function control({ type, ...props }) {
|
|
14
|
+
if (type === 'number')
|
|
15
|
+
return _jsx(NumberInput, { ...props });
|
|
16
|
+
return _jsx(Input, { type: type, ...props });
|
|
17
|
+
}
|
|
12
18
|
export const Field = withParts(FieldShortcut, {
|
|
13
19
|
Root: Ark.Root,
|
|
14
20
|
Label: Ark.Label,
|