-
-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Add `useLocale` and `useTimeZone` * Add docs * Improve wording
- Loading branch information
Showing
6 changed files
with
75 additions
and
0 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,5 @@ | ||
import useIntlContext from './useIntlContext'; | ||
|
||
export default function useLocale() { | ||
return useIntlContext().locale; | ||
} |
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,5 @@ | ||
import useIntlContext from './useIntlContext'; | ||
|
||
export default function useTimeZone() { | ||
return useIntlContext().timeZone; | ||
} |
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,17 @@ | ||
import {render, screen} from '@testing-library/react'; | ||
import React from 'react'; | ||
import {IntlProvider, useLocale} from '../src'; | ||
|
||
it('returns the current locale', () => { | ||
function Component() { | ||
return <>{useLocale()}</>; | ||
} | ||
|
||
render( | ||
<IntlProvider locale="en"> | ||
<Component /> | ||
</IntlProvider> | ||
); | ||
|
||
screen.getByText('en'); | ||
}); |
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 {render, screen} from '@testing-library/react'; | ||
import React from 'react'; | ||
import {IntlProvider, useTimeZone} from '../src'; | ||
|
||
it('returns the time zone when it is configured', () => { | ||
function Component() { | ||
return <>{useTimeZone()}</>; | ||
} | ||
|
||
render( | ||
<IntlProvider locale="de" timeZone="Europe/Berlin"> | ||
<Component /> | ||
</IntlProvider> | ||
); | ||
|
||
screen.getByText('Europe/Berlin'); | ||
}); | ||
|
||
it('returns undefined when no time zone is configured', () => { | ||
function Component() { | ||
return <>{useTimeZone()}</>; | ||
} | ||
|
||
const {container} = render( | ||
<IntlProvider locale="de"> | ||
<Component /> | ||
</IntlProvider> | ||
); | ||
|
||
expect(container.textContent).toBe(''); | ||
}); |