-
Notifications
You must be signed in to change notification settings - Fork 14
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
bd9d166
commit 8b6d8ff
Showing
7 changed files
with
73 additions
and
32 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
40 changes: 40 additions & 0 deletions
40
packages/bento-design-system/src/NumberField/NumberInput.tsx
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,40 @@ | ||
import { NumberFieldStateOptions, useNumberFieldState } from "@react-stately/numberfield"; | ||
import { FieldProps } from "../Field/FieldProps"; | ||
import { BaseNumberProps, FormatProps } from "./types"; | ||
import { useLocale } from "@react-aria/i18n"; | ||
import { useFormatOptions } from "./formatOptions"; | ||
import { HTMLAttributes, useRef } from "react"; | ||
import { useNumberField } from "@react-aria/numberfield"; | ||
import { InternalNumberInput } from "./InternalNumberInput"; | ||
import { AtLeast } from "../util/AtLeast"; | ||
|
||
type Props = AtLeast<Pick<HTMLAttributes<HTMLInputElement>, "aria-label" | "aria-labelledby">> & | ||
Pick< | ||
FieldProps<number | undefined, number>, | ||
"autoFocus" | "disabled" | "name" | "onBlur" | "onChange" | "value" | ||
> & | ||
BaseNumberProps & { | ||
validationState: "valid" | "invalid"; | ||
} & FormatProps & | ||
Pick<NumberFieldStateOptions, "minValue" | "maxValue" | "step">; | ||
|
||
export function NumberInput(props: Props) { | ||
const { locale } = useLocale(); | ||
const formatOptions = useFormatOptions(props); | ||
const state = useNumberFieldState({ ...props, locale, formatOptions }); | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
|
||
const { inputProps } = useNumberField( | ||
{ | ||
...props, | ||
isDisabled: props.disabled, | ||
formatOptions, | ||
}, | ||
state, | ||
inputRef | ||
); | ||
|
||
return <InternalNumberInput inputProps={inputProps} inputRef={inputRef} {...props} />; | ||
} | ||
|
||
export type { Props as NumberInputProps }; |
2 changes: 1 addition & 1 deletion
2
...n-system/src/NumberInput/formatOptions.ts → ...n-system/src/NumberField/formatOptions.ts
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,20 @@ | ||
import { Children } from "../util/Children"; | ||
import { LocalizedString } from "../util/LocalizedString"; | ||
|
||
export type BaseNumberProps = { | ||
placeholder?: LocalizedString; | ||
isReadOnly?: boolean; | ||
rightAccessory?: Children; | ||
}; | ||
|
||
export type FormatProps = | ||
| { | ||
kind: "currency"; | ||
currency: string; | ||
} | ||
| { | ||
kind: "percentage"; | ||
} | ||
| { | ||
kind?: "decimal"; | ||
}; |
11 changes: 0 additions & 11 deletions
11
packages/bento-design-system/src/NumberInput/FormatProps.ts
This file was deleted.
Oops, something went wrong.
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