-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/nexxtway/react-rainbow in…
…to feat-add-picklist-prop-size
- Loading branch information
Showing
22 changed files
with
521 additions
and
40 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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
const NUMBER = 100000.99; | ||
|
||
export default function getSeparator(locale, type, options) { | ||
const formatter = new Intl.NumberFormat(locale, options); | ||
export default function getSeparator({ locale, type, style, currency }) { | ||
const formatter = new Intl.NumberFormat(locale, { | ||
style, | ||
currency, | ||
minimumFractionDigits: 2, | ||
maximumFractionDigits: 2, | ||
}); | ||
const parts = formatter.formatToParts(NUMBER); | ||
return parts.find(part => part.type === type).value; | ||
} |
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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import { useMemo } from 'react'; | ||
import { getSeparator } from '../helpers'; | ||
|
||
export default function useDecimalSeparator(locale, options) { | ||
return useMemo(() => getSeparator(locale, 'decimal', options), [locale, options]); | ||
export default function useDecimalSeparator({ locale, style, currency }) { | ||
return useMemo(() => getSeparator({ locale, type: 'decimal', style, currency }), [ | ||
currency, | ||
locale, | ||
style, | ||
]); | ||
} |
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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import { useMemo } from 'react'; | ||
import { getSeparator } from '../helpers'; | ||
|
||
export default function useGroupSeparator(locale, options) { | ||
return useMemo(() => getSeparator(locale, 'group', options), [locale, options]); | ||
export default function useGroupSeparator({ locale, style, currency }) { | ||
return useMemo(() => getSeparator({ locale, type: 'group', style, currency }), [ | ||
currency, | ||
locale, | ||
style, | ||
]); | ||
} |
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
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,12 @@ | ||
export default function formatPercent({ value, locale, options }) { | ||
if (value === '-' || value === '' || value === null) { | ||
return value; | ||
} | ||
const number = Number(value); | ||
|
||
if (!Number.isNaN(number)) { | ||
return new Intl.NumberFormat(locale, options).format(number / 100); | ||
} | ||
|
||
return ''; | ||
} |
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,2 @@ | ||
export { default as formatPercent } from './formatPercent'; | ||
export { default as normalizeValue } from './normalizeValue'; |
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,19 @@ | ||
import formatInteger from '../../CurrencyInput/helpers/formatInteger'; | ||
|
||
export default function normalizeValue({ value, locale, decimalSeparator, options }) { | ||
const stringValue = String(value); | ||
if (value === '-' || value === '' || value === null) { | ||
return value; | ||
} | ||
|
||
if (!Number.isNaN(Number(value))) { | ||
const [integer, fraction] = stringValue.split('.'); | ||
const formattedInteger = formatInteger({ integer: Number(integer) / 100, locale, options }); | ||
|
||
return stringValue.indexOf('.') !== -1 | ||
? `${formattedInteger}${decimalSeparator}${fraction || ''}` | ||
: formattedInteger; | ||
} | ||
|
||
return ''; | ||
} |
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,28 @@ | ||
import { useMemo } from 'react'; | ||
|
||
export default function useOptions(props) { | ||
const { | ||
minimumIntegerDigits, | ||
minimumFractionDigits, | ||
maximumFractionDigits, | ||
minimumSignificantDigits, | ||
maximumSignificantDigits, | ||
} = props; | ||
return useMemo( | ||
() => ({ | ||
style: 'percent', | ||
minimumIntegerDigits, | ||
minimumFractionDigits, | ||
maximumFractionDigits, | ||
minimumSignificantDigits, | ||
maximumSignificantDigits, | ||
}), | ||
[ | ||
maximumFractionDigits, | ||
maximumSignificantDigits, | ||
minimumFractionDigits, | ||
minimumIntegerDigits, | ||
minimumSignificantDigits, | ||
], | ||
); | ||
} |
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,35 @@ | ||
import { ReactNode, MouseEvent, FocusEvent, KeyboardEvent } from 'react'; | ||
import { BaseProps, IconPosition, LabelAlignment } from '../types'; | ||
|
||
export interface PercentInputProps extends BaseProps { | ||
value?: number | string; | ||
name?: string; | ||
label?: ReactNode; | ||
labelAlignment?: LabelAlignment; | ||
hideLabel?: boolean; | ||
placeholder?: string; | ||
icon?: ReactNode; | ||
iconPosition?: IconPosition; | ||
bottomHelpText?: ReactNode; | ||
required?: boolean; | ||
error?: ReactNode; | ||
disabled?: boolean; | ||
readOnly?: boolean; | ||
tabIndex?: number | string; | ||
onChange?: (value?: string) => void; | ||
onClick?: (event: MouseEvent<HTMLInputElement>) => void; | ||
onFocus?: (event: FocusEvent<HTMLInputElement>) => void; | ||
onBlur?: (event: FocusEvent<HTMLInputElement>) => void; | ||
onKeyDown?: (event: KeyboardEvent<HTMLInputElement>) => void; | ||
id?: string; | ||
variant?: 'default' | 'shaded' | 'bare'; | ||
locale?: string; | ||
minimumIntegerDigits?: number; | ||
minimumFractionDigits?: number; | ||
maximumFractionDigits?: number; | ||
minimumSignificantDigits?: number; | ||
maximumSignificantDigits?: number; | ||
size?: 'small' | 'medium' | 'large'; | ||
} | ||
|
||
export default function(props: PercentInputProps): JSX.Element | null; |
Oops, something went wrong.