-
Notifications
You must be signed in to change notification settings - Fork 287
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
Showing
9 changed files
with
75 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import locales from '../../../src/components/LocaleProvider/locales'; | ||
|
||
interface LangSwitcherProps { | ||
value: string; | ||
onChange: (lang: string) => void; | ||
} | ||
|
||
export const LangSwitcher = ({ value, onChange }: LangSwitcherProps) => ( | ||
<select | ||
value={value} | ||
onChange={(e) => { | ||
onChange(e.target.value); | ||
}} | ||
> | ||
{Object.keys(locales).map((t) => ( | ||
<option value={t} key={t}> | ||
{t} | ||
</option> | ||
))} | ||
</select> | ||
); |
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,2 +1,3 @@ | ||
export { DemoPage } from './DemoPage'; | ||
export { DemoSection } from './DemoSection'; | ||
export { LangSwitcher } from './LangSwitcher'; |
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,42 @@ | ||
import React, { useState } from 'react'; | ||
import { DemoPage, DemoSection, LangSwitcher } from '../components'; | ||
import { Time, LocaleProvider } from '../../../src'; | ||
import '../../../src/styles/index.less'; | ||
|
||
const now = Date.now(); | ||
const MS_A_DAY = 24 * 60 * 60 * 1000; | ||
const MS_A_WEEK = MS_A_DAY * 7; | ||
|
||
export default () => { | ||
const [lang, setLang] = useState('zh-CN'); | ||
|
||
return ( | ||
<DemoPage> | ||
<DemoSection title="基础用法"> | ||
<LangSwitcher value={lang} onChange={setLang} /> | ||
<LocaleProvider locale={lang}> | ||
<p> | ||
<span>现在:</span> | ||
<Time date={now} /> | ||
</p> | ||
<p> | ||
<span>刚才:</span> | ||
<Time date={now - 120000} /> | ||
</p> | ||
<p> | ||
<span>昨天:</span> | ||
<Time date={now - MS_A_DAY} /> | ||
</p> | ||
<p> | ||
<span>前天:</span> | ||
<Time date={now - MS_A_DAY * 2} /> | ||
</p> | ||
<p> | ||
<span>上上周:</span> | ||
<Time date={now - MS_A_WEEK * 2} /> | ||
</p> | ||
</LocaleProvider> | ||
</DemoSection> | ||
</DemoPage> | ||
); | ||
}; |
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 |
---|---|---|
|
@@ -14,4 +14,4 @@ export const Time: React.FC<TimeProps> = ({ date }) => { | |
{formatDate(date, trans())} | ||
</time> | ||
); | ||
} | ||
}; |
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 { Time } from './Time'; | ||
export type { TimeProps } from './Time'; |
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