@milktop/react-ui 0.3.1 → 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.
@@ -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,
@@ -25,7 +25,10 @@
25
25
  &:hover { background: var(--ui-sidebar-hover); color: var(--ui-sidebar-hover-text); }
26
26
  &:focus-visible { outline: 2px solid var(--ui-ring-soft); }
27
27
  [data-part=footer] > & { margin: 0 auto; } }
28
- [data-scope=sidebar][data-part=nav] { display: flex; flex-direction: column; gap: 1rem; flex-grow: 1; overflow-y: auto; padding: 0.5rem; }
28
+ [data-scope=sidebar][data-part=nav] { display: flex; flex-direction: column; gap: 1rem; flex-grow: 1; overflow-y: auto; padding: 0.5rem;
29
+ scrollbar-width: thin; scrollbar-color: color-mix(in srgb, currentColor 25%, transparent) transparent;
30
+ /* The rail has no room for a scrollbar; it still scrolls. */
31
+ [data-rail] > & { scrollbar-width: none; } }
29
32
  /* A faint line above the footer (SidebarUser), like the top bar's. */
30
33
  [data-scope=sidebar][data-part=footer] { display: flex; flex-direction: column; gap: 0.25rem; padding: 0.75rem 0.5rem; flex-shrink: 0;
31
34
  border-top: 1px solid var(--ui-sidebar-divider); }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milktop/react-ui",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
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",