@milktop/react-ui 0.3.2 → 0.3.4

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.
@@ -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
- export type FieldProps = DistributiveOmit<InputProps, 'label' | 'classes' | 'children'> & {
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;
@@ -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 ?? _jsx(Input, { ...inputProps }), error ? _jsx(Ark.ErrorText, { ...part('error-text'), children: error })
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,
@@ -9,6 +9,8 @@
9
9
  * - `open`, `defaultOpen`; `onOpenChange`: called with the new open state.
10
10
  * In an `accordion` Sidebar, opening one closes the others.
11
11
  *
12
+ * Opening it scrolls the sidebar just enough to show its items.
13
+ *
12
14
  * In the rail only its icon shows, and its items open beside it as a flyout:
13
15
  * on hover, or on click for keyboard and touch. Escape, leaving it or
14
16
  * following a link closes it. It moves up when it would run past the bottom
@@ -10,6 +10,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
10
10
  * - `open`, `defaultOpen`; `onOpenChange`: called with the new open state.
11
11
  * In an `accordion` Sidebar, opening one closes the others.
12
12
  *
13
+ * Opening it scrolls the sidebar just enough to show its items.
14
+ *
13
15
  * In the rail only its icon shows, and its items open beside it as a flyout:
14
16
  * on hover, or on click for keyboard and touch. Escape, leaving it or
15
17
  * following a link closes it. It moves up when it would run past the bottom
@@ -64,9 +66,21 @@ export function NavGroup({ label, icon = null, open: openProp, defaultOpen = fal
64
66
  setPosition({ top: box.top, left: box.right });
65
67
  setFlyout(true);
66
68
  }
69
+ // Scrolls the sidebar just enough to show the opened items (the heading
70
+ // stays in view when the group is taller than the sidebar).
71
+ const revealing = useRef(false);
72
+ useEffect(() => {
73
+ if (!open || !revealing.current)
74
+ return;
75
+ revealing.current = false;
76
+ const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches;
77
+ root.current?.scrollIntoView({ block: 'nearest', behavior: reduce ? 'auto' : 'smooth' });
78
+ }, [open]);
67
79
  function toggle() {
68
- if (!rail)
80
+ if (!rail) {
81
+ revealing.current = !open;
69
82
  setOpen(!open);
83
+ }
70
84
  else if (showing)
71
85
  setFlyout(false);
72
86
  else
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milktop/react-ui",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
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",