Skip to content

Commit

Permalink
ts: Refine type Precision to use new type NumericPrecision.
Browse files Browse the repository at this point in the history
+ Desktop and mobile NumberInput now use NumericPrecision instead of 'number'.
  • Loading branch information
cnrudd committed Aug 12, 2024
1 parent b9088e0 commit 2cdf5e6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions desktop/cmp/input/NumberInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import composeRefs from '@seznam/compose-react-refs';
import {HoistInputModel, HoistInputProps, useHoistInputModel} from '@xh/hoist/cmp/input';
import {hoistCmp, HoistProps, HSide, LayoutProps, StyleProps} from '@xh/hoist/core';
import '@xh/hoist/desktop/register';
import {fmtNumber, parseNumber, Precision, ZeroPad} from '@xh/hoist/format';
import {fmtNumber, NumericPrecision, parseNumber, Precision, ZeroPad} from '@xh/hoist/format';
import {numericInput} from '@xh/hoist/kit/blueprint';
import {wait} from '@xh/hoist/promise';
import {TEST_ID, throwIf, withDefault} from '@xh/hoist/utils/js';
Expand Down Expand Up @@ -62,7 +62,7 @@ export interface NumberInputProps extends HoistProps, LayoutProps, StyleProps, H
placeholder?: string;

/** Max decimal precision of the value, defaults to 4. */
precision?: number;
precision?: NumericPrecision;

/** Element to display inline on the right side of the input. */
rightElement?: ReactNode;
Expand Down
5 changes: 3 additions & 2 deletions format/FormatNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ const UP_TICK = '▴',
neutral: 'xh-neutral-val'
};

export type Precision = 'auto' | IntRange<0, 13>;
export type ZeroPad = boolean | IntRange<1, 13>;
export type NumericPrecision = IntRange<0, 13>;
export type Precision = NumericPrecision | 'auto';
export type ZeroPad = NumericPrecision | boolean;

export interface NumberFormatOptions extends Omit<FormatOptions<number>, 'tooltip'> {
/**
Expand Down
4 changes: 2 additions & 2 deletions mobile/cmp/input/NumberInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import {HoistInputModel, HoistInputProps, useHoistInputModel} from '@xh/hoist/cmp/input';
import {hoistCmp, HoistProps, HSide, LayoutProps, StyleProps} from '@xh/hoist/core';
import {fmtNumber, Precision, ZeroPad} from '@xh/hoist/format';
import {fmtNumber, NumericPrecision, Precision, ZeroPad} from '@xh/hoist/format';
import {input} from '@xh/hoist/kit/onsen';
import '@xh/hoist/mobile/register';
import {wait} from '@xh/hoist/promise';
Expand Down Expand Up @@ -46,7 +46,7 @@ export interface NumberInputProps extends HoistProps, HoistInputProps, StyleProp
placeholder?: string;

/** Max decimal precision of the value, defaults to 4. */
precision?: number;
precision?: NumericPrecision;

/**
* Scale factor to apply when converting between the internal and external value. Useful for
Expand Down

0 comments on commit 2cdf5e6

Please sign in to comment.