-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cab196d
commit b976705
Showing
3 changed files
with
49 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Meta } from "@storybook/blocks"; | ||
|
||
<Meta title="hooks/useNumberFieldProps" /> | ||
|
||
# `useNumberFieldProps(field: NumberField)` | ||
|
||
A hook to control the numeric inputs e.g. `input[type=number]`, `input[type=range]`. | ||
|
||
```ts | ||
import { useNumberFieldProps } from "@form-atoms/field"; | ||
``` | ||
|
||
Works with | ||
|
||
- [numberField()](?path=/docs/fields-numberField--docs) | ||
- [digitField()](?path=/docs/fields-digitfield--docs) | ||
|
||
### Features | ||
|
||
- ✅ **Reads the `event.valueAsNumber` value** from the event handler. | ||
- ✅ Normalizes the the empty `NaN` value. | ||
|
||
### Example Usage | ||
|
||
```tsx | ||
import { NumberField, useNumberFieldProps } from "@form-atoms/field"; | ||
|
||
const NumberInput = ({ | ||
field, | ||
label, | ||
}: { | ||
field: NumberField; | ||
label: ReactNode; | ||
}) => { | ||
const props = useNumberFieldProps(field); | ||
|
||
return ( | ||
<div style={{ margin: "20px 0" }}> | ||
<FieldLabel field={field} label={label} /> | ||
<input type="number" {...props} /> | ||
<FieldErrors field={field} /> | ||
</div> | ||
); | ||
}; | ||
``` |