@milktop/react-ui 0.3.13 → 0.3.15
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/avatar/avatar.css
CHANGED
|
@@ -61,7 +61,9 @@
|
|
|
61
61
|
&[data-spacing=tight] { --overlap-scale: 1.5; }
|
|
62
62
|
&[data-spacing=loose] { --overlap-scale: 0.4; }
|
|
63
63
|
& > :is([data-scope=avatar], [data-part=more]) { box-shadow: 0 0 0 2px var(--ui-avatar-ring); }
|
|
64
|
-
& > :is([data-scope=avatar], [data-part=more]):not(:first-child) { margin-left: calc(var(--overlap) * -1); }
|
|
64
|
+
& > :is([data-scope=avatar], [data-part=more]):not(:first-child) { margin-left: calc(var(--overlap) * -1); }
|
|
65
|
+
/* Each dot stays in view over the next avatar's edge */
|
|
66
|
+
& [data-scope=avatar][data-part=status] { z-index: 1; } }
|
|
65
67
|
[data-scope=avatar-group][data-part=more] {
|
|
66
68
|
display: inline-grid; place-items: center; flex-shrink: 0; width: 2.5rem; height: 2.5rem; border-radius: 9999px; box-sizing: border-box;
|
|
67
69
|
background: var(--ui-hover); color: var(--ui-muted); font-family: var(--ui-font); font-size: 12px; font-weight: 600; cursor: default;
|
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
* - `onValueChange`: called with the new number (or null)
|
|
8
8
|
* - `min`, `max`, `step`
|
|
9
9
|
* - `prefix`, `suffix`: text before or after it ('£', 'kg'); `icon`: an Iconify name before it
|
|
10
|
-
* - `formatOptions`: Intl.NumberFormat options, e.g. { style: 'currency', currency: 'GBP' }
|
|
10
|
+
* - `formatOptions`: Intl.NumberFormat options, e.g. { style: 'currency', currency: 'GBP' }
|
|
11
|
+
* - `locale`: the number's language ('fr-FR' writes 4,25), else the LocaleProvider's; where the
|
|
12
|
+
* decimal is a comma and a point isn't a thousands separator (French), a typed point is a comma
|
|
11
13
|
* - `allowMouseWheel`: scroll over the focused input to step
|
|
12
14
|
* - `steppers`: false to hide the buttons
|
|
13
15
|
* - `name`: for plain form posts
|
|
@@ -41,7 +43,7 @@ export type NumberInputProps = Omit<Ark.RootProps, 'value' | 'defaultValue' | 'o
|
|
|
41
43
|
placeholder?: string;
|
|
42
44
|
classes?: Classes<'root' | 'label' | 'control' | 'icon' | 'prefix' | 'input' | 'suffix' | 'decrementTrigger' | 'incrementTrigger'>;
|
|
43
45
|
};
|
|
44
|
-
declare function NumberInputShortcut({ label, value, defaultValue, onValueChange, prefix, suffix, icon, steppers, placeholder, className, classes, ...rest }: NumberInputProps): import("react").JSX.Element;
|
|
46
|
+
declare function NumberInputShortcut({ label, value, defaultValue, onValueChange, prefix, suffix, icon, steppers, placeholder, locale: localeProp, formatOptions: formatProp, className, classes, ...rest }: NumberInputProps): import("react").JSX.Element;
|
|
45
47
|
export declare const NumberInput: typeof NumberInputShortcut & {
|
|
46
48
|
Root: import("react").ForwardRefExoticComponent<Ark.RootProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
47
49
|
Label: import("react").ForwardRefExoticComponent<Ark.LabelProps & import("react").RefAttributes<HTMLLabelElement>>;
|
|
@@ -8,7 +8,9 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
8
8
|
* - `onValueChange`: called with the new number (or null)
|
|
9
9
|
* - `min`, `max`, `step`
|
|
10
10
|
* - `prefix`, `suffix`: text before or after it ('£', 'kg'); `icon`: an Iconify name before it
|
|
11
|
-
* - `formatOptions`: Intl.NumberFormat options, e.g. { style: 'currency', currency: 'GBP' }
|
|
11
|
+
* - `formatOptions`: Intl.NumberFormat options, e.g. { style: 'currency', currency: 'GBP' }
|
|
12
|
+
* - `locale`: the number's language ('fr-FR' writes 4,25), else the LocaleProvider's; where the
|
|
13
|
+
* decimal is a comma and a point isn't a thousands separator (French), a typed point is a comma
|
|
12
14
|
* - `allowMouseWheel`: scroll over the focused input to step
|
|
13
15
|
* - `steppers`: false to hide the buttons
|
|
14
16
|
* - `name`: for plain form posts
|
|
@@ -24,35 +26,91 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
24
26
|
* </NumberInput.Control>
|
|
25
27
|
* </NumberInput.Root>
|
|
26
28
|
*/
|
|
27
|
-
import { useState } from 'react';
|
|
29
|
+
import { useMemo, useState } from 'react';
|
|
28
30
|
import { NumberInput as Ark } from '@ark-ui/react/number-input';
|
|
29
31
|
import { useFieldContext } from '@ark-ui/react/field';
|
|
32
|
+
import { useLocaleContext } from '@ark-ui/react/locale';
|
|
33
|
+
import { NumberParser } from '@internationalized/number';
|
|
30
34
|
import '../icons.js';
|
|
31
35
|
import { cx, partsOf, withParts } from '../utils.js';
|
|
32
36
|
import { useMessages } from '../format/LocaleProvider.js';
|
|
33
37
|
import '../theme.css';
|
|
34
38
|
import './number-input.css';
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
// Without formatOptions zag reads the text with parseFloat, which stops at a decimal comma.
|
|
40
|
+
const plain = { maximumFractionDigits: 15, useGrouping: false };
|
|
41
|
+
// A French keypad's decimal key types a point. Caught natively, before zag's
|
|
42
|
+
// onBeforeInput refuses it: on keydown, and on beforeinput for text typed
|
|
43
|
+
// without one (Chrome fires beforeinput before the textInput React reads).
|
|
44
|
+
const pointAsComma = (parser) => (input) => {
|
|
45
|
+
if (!input)
|
|
46
|
+
return;
|
|
47
|
+
const insert = (event, typed) => {
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
const text = typed.replaceAll('.', ',');
|
|
50
|
+
const start = input.selectionStart ?? input.value.length, end = input.selectionEnd ?? start;
|
|
51
|
+
if (!parser.isValidPartialNumber(input.value.slice(0, start) + text + input.value.slice(end)))
|
|
52
|
+
return;
|
|
53
|
+
input.setRangeText(text, start, end, 'end');
|
|
54
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
55
|
+
};
|
|
56
|
+
const key = (event) => {
|
|
57
|
+
if (event.key === '.' && !event.ctrlKey && !event.metaKey && !event.altKey && !event.isComposing)
|
|
58
|
+
insert(event, '.');
|
|
59
|
+
};
|
|
60
|
+
const beforeInput = (event) => {
|
|
61
|
+
if (event.inputType === 'insertText' && event.data?.includes('.'))
|
|
62
|
+
insert(event, event.data);
|
|
63
|
+
};
|
|
64
|
+
input.addEventListener('keydown', key);
|
|
65
|
+
input.addEventListener('beforeinput', beforeInput);
|
|
66
|
+
return () => {
|
|
67
|
+
input.removeEventListener('keydown', key);
|
|
68
|
+
input.removeEventListener('beforeinput', beforeInput);
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
function numbers(locale, given) {
|
|
72
|
+
const parts = new Intl.NumberFormat(locale).formatToParts(1234567.5);
|
|
73
|
+
const decimal = parts.find((p) => p.type === 'decimal')?.value;
|
|
74
|
+
const group = parts.find((p) => p.type === 'group')?.value;
|
|
75
|
+
const formatOptions = given ?? (decimal === '.' ? undefined : plain);
|
|
76
|
+
const format = new Intl.NumberFormat(locale, formatOptions);
|
|
77
|
+
const parser = new NumberParser(locale, formatOptions);
|
|
78
|
+
return {
|
|
79
|
+
formatOptions,
|
|
80
|
+
// Not where a point groups thousands (de-DE's 1.234).
|
|
81
|
+
inputRef: decimal === ',' && group !== '.' ? pointAsComma(parser) : undefined,
|
|
82
|
+
// As zag writes its value, so it reads it back.
|
|
83
|
+
toText: (value) => (value == null ? '' : formatOptions ? format.format(value) : String(value)),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function NumberInputShortcut({ label = null, value, defaultValue, onValueChange, prefix = null, suffix = null, icon = null, steppers = true, placeholder = '', locale: localeProp, formatOptions: formatProp, className, classes, ...rest }) {
|
|
37
87
|
const t = useMessages();
|
|
38
88
|
const field = useFieldContext();
|
|
39
89
|
const part = partsOf('number-input', classes);
|
|
40
|
-
|
|
41
|
-
|
|
90
|
+
const appLocale = useLocaleContext().locale;
|
|
91
|
+
const locale = localeProp ?? appLocale;
|
|
92
|
+
const key = JSON.stringify(formatProp ?? null);
|
|
93
|
+
const { formatOptions, inputRef, toText } = useMemo(() => numbers(locale, formatProp), [locale, key]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
94
|
+
// Zag works on the text ('1,', '' while typing); `value` is its number.
|
|
95
|
+
// The text follows a controlled value that changes from outside, not the
|
|
96
|
+
// number it just reported.
|
|
42
97
|
const [text, setText] = useState(() => toText(value !== undefined ? value : defaultValue));
|
|
43
98
|
const [seen, setSeen] = useState(value);
|
|
99
|
+
const [sent, setSent] = useState(value);
|
|
44
100
|
if (value !== seen) {
|
|
45
101
|
setSeen(value);
|
|
46
|
-
|
|
47
|
-
if (value !==
|
|
102
|
+
setSent(value);
|
|
103
|
+
if (value !== sent)
|
|
48
104
|
setText(toText(value));
|
|
49
105
|
}
|
|
50
106
|
function change(details) {
|
|
107
|
+
const number = Number.isNaN(details.valueAsNumber) ? null : details.valueAsNumber;
|
|
51
108
|
setText(details.value);
|
|
52
|
-
|
|
109
|
+
setSent(number);
|
|
110
|
+
onValueChange?.(number, details);
|
|
53
111
|
}
|
|
54
|
-
return (_jsxs(Ark.Root, { ...(t.zag.numberInput && { translations: t.zag.numberInput }), ...rest, ...part('root'), className: cx(className, classes?.root), value: text, onValueChange: change, children: [label && !field && _jsx(Ark.Label, { ...part('label'), children: label }), _jsxs(Ark.Control, { ...part('control'), children: [icon ? _jsx("iconify-icon", { ...part('icon'), icon: icon, "aria-hidden": "true" })
|
|
55
|
-
: prefix != null && _jsx("span", { ...part('prefix'), children: prefix }), _jsx(Ark.Input, { ...part('input'), placeholder: placeholder }), suffix != null && _jsx("span", { ...part('suffix'), children: suffix }), steppers && _jsxs(_Fragment, { children: [_jsx(Ark.DecrementTrigger, { ...part('decrement-trigger'), children: _jsx("iconify-icon", { icon: "lucide:minus" }) }), _jsx(Ark.IncrementTrigger, { ...part('increment-trigger'), children: _jsx("iconify-icon", { icon: "lucide:plus" }) })] })] })] }));
|
|
112
|
+
return (_jsxs(Ark.Root, { ...(t.zag.numberInput && { translations: t.zag.numberInput }), ...rest, ...part('root'), className: cx(className, classes?.root), locale: locale, ...(formatOptions && { formatOptions }), value: text, onValueChange: change, children: [label && !field && _jsx(Ark.Label, { ...part('label'), children: label }), _jsxs(Ark.Control, { ...part('control'), children: [icon ? _jsx("iconify-icon", { ...part('icon'), icon: icon, "aria-hidden": "true" })
|
|
113
|
+
: prefix != null && _jsx("span", { ...part('prefix'), children: prefix }), _jsx(Ark.Input, { ...part('input'), placeholder: placeholder, ref: inputRef }), suffix != null && _jsx("span", { ...part('suffix'), children: suffix }), steppers && _jsxs(_Fragment, { children: [_jsx(Ark.DecrementTrigger, { ...part('decrement-trigger'), children: _jsx("iconify-icon", { icon: "lucide:minus" }) }), _jsx(Ark.IncrementTrigger, { ...part('increment-trigger'), children: _jsx("iconify-icon", { icon: "lucide:plus" }) })] })] })] }));
|
|
56
114
|
}
|
|
57
115
|
export const NumberInput = withParts(NumberInputShortcut, {
|
|
58
116
|
Root: Ark.Root,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milktop/react-ui",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.15",
|
|
4
4
|
"description": "React components on Ark UI (Zag state machines), with imba-ui's API and design",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "André Goldstein",
|
|
@@ -49,9 +49,10 @@
|
|
|
49
49
|
"dev": "vite playground --port 5194",
|
|
50
50
|
"build": "vite build playground",
|
|
51
51
|
"build:lib": "rm -rf dist && tsc -p tsconfig.build.json && node scripts/after-tsc.js",
|
|
52
|
-
"check": "tsc && eslint src playground",
|
|
52
|
+
"check": "tsc && eslint src playground test",
|
|
53
|
+
"test": "vitest run",
|
|
53
54
|
"prepublishOnly": "npm run build:lib",
|
|
54
|
-
"preversion": "npm run check && npm run build:lib",
|
|
55
|
+
"preversion": "npm run check && npm test && npm run build:lib",
|
|
55
56
|
"postversion": "git push --follow-tags",
|
|
56
57
|
"release:patch": "npm version patch",
|
|
57
58
|
"release:minor": "npm version minor",
|
|
@@ -68,6 +69,7 @@
|
|
|
68
69
|
"@dnd-kit/sortable": "^10.0.0",
|
|
69
70
|
"@dnd-kit/utilities": "^3.2.2",
|
|
70
71
|
"@internationalized/date": "^3.12.4",
|
|
72
|
+
"@internationalized/number": "^3.6.9",
|
|
71
73
|
"@tiptap/core": "^3.31.4",
|
|
72
74
|
"@tiptap/extension-image": "^3.31.4",
|
|
73
75
|
"@tiptap/extensions": "^3.31.4",
|
|
@@ -88,16 +90,20 @@
|
|
|
88
90
|
"@fontsource-variable/inter": "^5.3.0",
|
|
89
91
|
"@fontsource-variable/plus-jakarta-sans": "^5.3.0",
|
|
90
92
|
"@tailwindcss/vite": "^4.3.3",
|
|
93
|
+
"@testing-library/react": "^16.3.3",
|
|
94
|
+
"@testing-library/user-event": "^14.6.9",
|
|
91
95
|
"@types/react": "^19.3.0",
|
|
92
96
|
"@types/react-dom": "^19.3.0",
|
|
93
97
|
"@vitejs/plugin-react": "^6.1.2",
|
|
94
98
|
"eslint": "^10.12.0",
|
|
95
99
|
"eslint-plugin-react-hooks": "^7.1.1",
|
|
100
|
+
"jsdom": "^31.0.0",
|
|
96
101
|
"react": "^19.3.0",
|
|
97
102
|
"react-dom": "^19.3.0",
|
|
98
103
|
"tailwindcss": "^4.3.3",
|
|
99
104
|
"typescript": "^6.0.3",
|
|
100
105
|
"typescript-eslint": "^8.71.1",
|
|
101
|
-
"vite": "^8.3.4"
|
|
106
|
+
"vite": "^8.3.4",
|
|
107
|
+
"vitest": "^5.1.0"
|
|
102
108
|
}
|
|
103
109
|
}
|