-
Notifications
You must be signed in to change notification settings - Fork 839
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
b545ff4
commit 29e3702
Showing
6 changed files
with
47 additions
and
4 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
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,31 @@ | ||
import React, { ReactChild, ReactElement } from 'react'; | ||
import { EuiI18nConsumer } from '../context'; | ||
|
||
const defaultFormatter = new Intl.NumberFormat('en'); | ||
function defaultFormatNumber(value: number) { | ||
return defaultFormatter.format(value); | ||
} | ||
|
||
interface I18nNumberProps { | ||
value: number; | ||
default: ReactChild; | ||
children?: (x: ReactChild) => ReactElement<any>; | ||
} | ||
|
||
const I18nNumber: React.SFC<I18nNumberProps> = ({value, children}) => ( | ||
<EuiI18nConsumer> | ||
{ | ||
(i18nConfig) => { | ||
const { formatNumber } = i18nConfig; | ||
const formattedValue = (formatNumber || defaultFormatNumber)(value); | ||
if (children) { | ||
return children(formattedValue); | ||
} else { | ||
return formattedValue; | ||
} | ||
} | ||
} | ||
</EuiI18nConsumer> | ||
); | ||
|
||
export { I18nNumber }; |
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 +1,2 @@ | ||
export {I18n} from './i18n'; | ||
export { I18n } from './i18n'; | ||
export { I18nNumber } from './i18n_number'; |
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 |
---|---|---|
|
@@ -188,6 +188,7 @@ export { | |
|
||
export { | ||
I18n, | ||
I18nNumber, | ||
} from './i18n'; | ||
|
||
export { | ||
|