From a8e95107e5e3ecb62c71e8deb85d4fc680624cac Mon Sep 17 00:00:00 2001 From: woksin Date: Wed, 2 Sep 2026 23:55:54 +0200 Subject: [PATCH] Add locale-aware NumberInput --- .../CommandForm/number-input-field.md | 31 + Documentation/CommandForm/toc.yml | 2 + Documentation/Common/basic-controls.md | 5 + Documentation/Common/index.md | 2 + Documentation/Common/number-input.md | 120 ++++ Documentation/Common/toc.yml | 2 + Documentation/Migration/3-to-4.md | 40 +- Documentation/Styling/pass-through.md | 4 +- Source/CommandForm/fields/Fields.stories.tsx | 32 ++ .../CommandForm/fields/NumberInputField.tsx | 71 +++ Source/CommandForm/fields/index.ts | 1 + .../when_reusing_number_input.tsx | 133 +++++ Source/Common/NumberInput.css | 153 +++++ Source/Common/NumberInput.stories.tsx | 260 +++++++++ Source/Common/NumberInput.tsx | 530 ++++++++++++++++++ Source/Common/NumberInputCommitReason.ts | 14 + Source/Common/NumberInputPartAttributes.ts | 14 + .../for_NumberInput/given/a_number_input.tsx | 126 +++++ .../when_committing_values.tsx | 272 +++++++++ .../when_editing_locale_values.tsx | 244 ++++++++ .../when_guarding_parts_and_tokens.ts | 44 ++ .../when_rendering_semantics.tsx | 284 ++++++++++ Source/Common/index.ts | 3 + .../when_scanning_foundation_surfaces.tsx | 10 + Source/scripts/generate-parts.mjs | 25 + Source/scripts/verify-parts-manifest.mjs | 6 +- Source/styles.css | 1 + Source/tokens.css | 3 + Source/types/parts.ts | 20 + Storybook/README.md | 2 +- Storybook/scripts/run-story-matrix.mjs | 4 +- .../scripts/verify-storybook-indexes.mjs | 12 +- yarn.lock | 7 + 33 files changed, 2453 insertions(+), 24 deletions(-) create mode 100644 Documentation/CommandForm/number-input-field.md create mode 100644 Documentation/Common/number-input.md create mode 100644 Source/CommandForm/fields/NumberInputField.tsx create mode 100644 Source/CommandForm/for_NumberInputField/when_reusing_number_input.tsx create mode 100644 Source/Common/NumberInput.css create mode 100644 Source/Common/NumberInput.stories.tsx create mode 100644 Source/Common/NumberInput.tsx create mode 100644 Source/Common/NumberInputCommitReason.ts create mode 100644 Source/Common/NumberInputPartAttributes.ts create mode 100644 Source/Common/for_NumberInput/given/a_number_input.tsx create mode 100644 Source/Common/for_NumberInput/when_committing_values.tsx create mode 100644 Source/Common/for_NumberInput/when_editing_locale_values.tsx create mode 100644 Source/Common/for_NumberInput/when_guarding_parts_and_tokens.ts create mode 100644 Source/Common/for_NumberInput/when_rendering_semantics.tsx diff --git a/Documentation/CommandForm/number-input-field.md b/Documentation/CommandForm/number-input-field.md new file mode 100644 index 00000000..4c3a3674 --- /dev/null +++ b/Documentation/CommandForm/number-input-field.md @@ -0,0 +1,31 @@ +# NumberInputField + +`NumberInputField` binds the standalone locale-aware [`NumberInput`](../Common/number-input.md) to a non-null number property in an Arc `CommandForm`. + +```tsx +import { CommandDialog } from '@cratis/components/CommandDialog'; +import { NumberInputField } from '@cratis/components/CommandForm'; +import { UpdateSample } from './UpdateSample'; + + + + value={(command) => command.amount} + title='Amount' + required + min={0} + step={0.01} + minimumFractionDigits={2} + maximumFractionDigits={2} + suffix='kg' + /> +; +``` + +The adapter does not parse or format a second time. It reuses `NumberInput` and adds only CommandForm binding, title/error association, required-state propagation, blur validation, and the non-null command policy: + +- the command default is `0`; +- clearing the nullable edit state writes `0` to the command property; +- extracted `null`, `undefined`, or non-finite values become `0`; +- all locale, grouping, fraction, range, step, adornment, callback, part, and token behavior belongs to `NumberInput`. + +Use [`NumberField`](number-field.md) instead when the native `input[type=number]` behavior and its clear-to-zero contract are sufficient. The existing native field remains the smaller surface and does not add locale grouping, adornments, or a separate commit callback. diff --git a/Documentation/CommandForm/toc.yml b/Documentation/CommandForm/toc.yml index e192c4a4..bd3697fc 100644 --- a/Documentation/CommandForm/toc.yml +++ b/Documentation/CommandForm/toc.yml @@ -18,6 +18,8 @@ href: multi-select-field.md - name: NumberField href: number-field.md +- name: NumberInputField + href: number-input-field.md - name: PasswordField href: password-field.md - name: RadioButtonField diff --git a/Documentation/Common/basic-controls.md b/Documentation/Common/basic-controls.md index 07e7941d..90e8620c 100644 --- a/Documentation/Common/basic-controls.md +++ b/Documentation/Common/basic-controls.md @@ -10,6 +10,7 @@ import { Button, Checkbox, IconButton, + NumberInput, Radio, Surface, Switch, @@ -25,6 +26,7 @@ import { onChange={(value) => console.log(value)} />