locale.stories.jsx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. import React from 'react';
  2. import { useState, useMemo } from 'react';
  3. import {
  4. Pagination,
  5. Cascader,
  6. LocaleProvider,
  7. ConfigProvider,
  8. Space,
  9. Modal,
  10. Button,
  11. Select,
  12. DatePicker,
  13. TreeSelect,
  14. Table,
  15. TimePicker,
  16. List,
  17. Calendar,
  18. Typography,
  19. Transfer,
  20. ImagePreview,
  21. Image,
  22. Form,
  23. Nav,
  24. InputNumber
  25. } from '../../index';
  26. import zh_CN from '@douyinfe/semi-ui/locale/source/zh_CN';
  27. import en_GB from '@douyinfe/semi-ui/locale/source/en_GB';
  28. import en_US from '@douyinfe/semi-ui/locale/source/en_US';
  29. import ko_KR from '@douyinfe/semi-ui/locale/source/ko_KR';
  30. import ja_JP from '@douyinfe/semi-ui/locale/source/ja_JP';
  31. import ru_RU from '@douyinfe/semi-ui/locale/source/ru_RU';
  32. import vi_VN from '@douyinfe/semi-ui/locale/source/vi_VN';
  33. import ar from '@douyinfe/semi-ui/locale/source/ar';
  34. import id_ID from '@douyinfe/semi-ui/locale/source/id_ID';
  35. import ms_MY from '@douyinfe/semi-ui/locale/source/ms_MY';
  36. import th_TH from '@douyinfe/semi-ui/locale/source/th_TH';
  37. import tr_TR from '@douyinfe/semi-ui/locale/source/tr_TR';
  38. import pt_BR from '@douyinfe/semi-ui/locale/source/pt_BR';
  39. import zh_TW from '@douyinfe/semi-ui/locale/source/zh_TW';
  40. import sv_SE from '@douyinfe/semi-ui/locale/source/sv_SE';
  41. import pl_PL from '@douyinfe/semi-ui/locale/source/pl_PL';
  42. import nl_NL from '@douyinfe/semi-ui/locale/source/nl_NL';
  43. import es from '@douyinfe/semi-ui/locale/source/es';
  44. import it from '@douyinfe/semi-ui/locale/source/it';
  45. import de from '@douyinfe/semi-ui/locale/source/de';
  46. import fr from '@douyinfe/semi-ui/locale/source/fr';
  47. import ro from '@douyinfe/semi-ui/locale/source/ro';
  48. import { IconUser, IconSemiLogo, IconStar } from '@douyinfe/semi-icons';
  49. const { Option } = Select;
  50. export default {
  51. title: 'LocaleProvider',
  52. };
  53. // -√ Pagination
  54. // -√ Modal
  55. // -× DatePicker
  56. // -√ Table
  57. // -√ Select
  58. // -× Calendar
  59. // -√ Timepicker
  60. const TableDemo = () => {};
  61. const CascaderDemo = () => {
  62. const treeData = [
  63. {
  64. label: '亚洲',
  65. value: 'yazhou',
  66. children: [
  67. {
  68. label: '中国',
  69. value: 'zhongguo',
  70. children: [
  71. {
  72. label: '北京',
  73. value: 'beijing',
  74. },
  75. {
  76. label: '上海',
  77. value: 'shanghai',
  78. },
  79. ],
  80. },
  81. {
  82. label: '日本',
  83. value: 'riben',
  84. children: [
  85. {
  86. label: '大阪',
  87. value: 'daban',
  88. },
  89. ],
  90. },
  91. ],
  92. },
  93. ];
  94. return <Cascader style={{ width: 300, margin: 10 }} treeData={treeData} filterTreeNode />;
  95. };
  96. const I18nComponent = () => {
  97. const [modalVisible, setModalVisible] = useState(false);
  98. const style = { margin: 10 };
  99. const presets = [
  100. {
  101. text: 'Today',
  102. start: new Date(),
  103. end: new Date(),
  104. },
  105. {
  106. text: 'Tomorrow',
  107. start: new Date(new Date().valueOf() + 1000 * 3600 * 24),
  108. end: new Date(new Date().valueOf() + 1000 * 3600 * 24),
  109. },
  110. ];
  111. const columns = useMemo(() => [
  112. {
  113. title: 'Name',
  114. width: 250,
  115. dataIndex: 'name',
  116. },
  117. {
  118. title: 'Age',
  119. width: 150,
  120. dataIndex: 'age',
  121. },
  122. {
  123. title: 'Address',
  124. dataIndex: 'address',
  125. },
  126. ]);
  127. const dataSource = useMemo(() => {
  128. const data = [];
  129. for (let i = 0; i < 1; i++) {
  130. data.push({
  131. key: '' + i,
  132. name: `Bytedance ${i}`,
  133. age: 32,
  134. address: `Beijing, Haidian. Zhichun Road ${i}`,
  135. });
  136. }
  137. return data;
  138. });
  139. return (
  140. <>
  141. <Pagination total={100} showTotal showSizeChanger style={style} />
  142. <Table columns={columns} dataSource={dataSource} scroll={{ y: 320 }} />
  143. <div style={style}>
  144. <Button onClick={() => setModalVisible(true)}>Show Modal</Button>
  145. </div>
  146. <div style={style}>
  147. <Select filter style={{ width: '180px' }}>
  148. <Option value="abc">abc</Option>
  149. <Option value="vigo" disabled>
  150. vigo
  151. </Option>
  152. <Option value="hotsoon">hotsoon</Option>
  153. </Select>
  154. <CascaderDemo />
  155. </div>
  156. <Modal
  157. title="Modal"
  158. visible={modalVisible}
  159. onOk={() => setModalVisible(false)}
  160. onCancel={() => setModalVisible(false)}
  161. >
  162. <p>This is the content of a basic modal.</p>
  163. <p>More content...</p>
  164. </Modal>
  165. <div>
  166. <DatePicker style={{ ...style, width: 200 }} open defaultPickerValue={[new Date('2024-09-08 00:00'), new Date('2024-09-09 12:00')]} />
  167. <DatePicker style={{ ...style,marginLeft:120, width: 250 }} open type="dateTime" presets={presets} presetPosition="left" defaultPickerValue={[new Date('2024-09-08 00:00'), new Date('2024-09-09 12:00')]} />
  168. {/* <DatePicker style={{ ...style, width: 250 }} type="dateRange" /> */}
  169. <DatePicker style={{ ...style, marginLeft:240, width: 400 }} open type="dateTimeRange" defaultPickerValue={[new Date('2024-09-08 00:00'), new Date('2024-09-09 12:00')]} />
  170. </div>
  171. <div style={{ marginTop: 400 }}>
  172. <DatePicker style={{ ...style, width: 200 }} open autoAdjustOverflow={false} position='bottomLeft' density='compact' defaultPickerValue={[new Date('2024-09-08 00:00'), new Date('2024-09-09 12:00')]} />
  173. <DatePicker style={{ ...style,marginLeft:120, width: 250 }} open type="dateTime" presets={presets} presetPosition="left" autoAdjustOverflow={false} position='bottomLeft' density='compact' defaultPickerValue={[new Date('2024-09-08 00:00'), new Date('2024-09-09 12:00')]} />
  174. {/* <DatePicker style={{ ...style, width: 250 }} type="dateRange" /> */}
  175. <DatePicker style={{ ...style, marginLeft:240, width: 400 }} open type="dateTimeRange" autoAdjustOverflow={false} position='bottomLeft' density='compact' defaultPickerValue={[new Date('2024-09-08 00:00'), new Date('2024-09-09 12:00')]} />
  176. </div>
  177. <br />
  178. <br />
  179. <div style={{ marginTop: 400 }}>
  180. <TimePicker style={style} />
  181. <TimePicker use12Hours style={style} />
  182. </div>
  183. <br />
  184. <br />
  185. </>
  186. );
  187. };
  188. export const LocaleZhCn = () => (
  189. <LocaleProvider locale={zh_CN}>
  190. <I18nComponent />
  191. </LocaleProvider>
  192. );
  193. export const LocaleEnGb = () => (
  194. <LocaleProvider locale={en_GB}>
  195. <I18nComponent />
  196. </LocaleProvider>
  197. );
  198. export const LocaleEnUs = () => (
  199. <LocaleProvider locale={en_US}>
  200. <I18nComponent />
  201. </LocaleProvider>
  202. );
  203. export const LocaleJaJp = () => (
  204. <LocaleProvider locale={ja_JP}>
  205. <I18nComponent />
  206. </LocaleProvider>
  207. );
  208. export const LocaleKoKr = () => (
  209. <LocaleProvider locale={ko_KR}>
  210. <I18nComponent />
  211. </LocaleProvider>
  212. );
  213. export const LocaleAr = () => (
  214. <LocaleProvider locale={ar}>
  215. <I18nComponent />
  216. </LocaleProvider>
  217. );
  218. export const LocaleViVn = () => (
  219. <LocaleProvider locale={vi_VN}>
  220. <I18nComponent />
  221. </LocaleProvider>
  222. );
  223. export const LocaleRuRu = () => (
  224. <LocaleProvider locale={ru_RU}>
  225. <I18nComponent />
  226. </LocaleProvider>
  227. );
  228. export const LocaleIdID = () => (
  229. <LocaleProvider locale={id_ID}>
  230. <I18nComponent />
  231. </LocaleProvider>
  232. );
  233. export const LocaleMsMY = () => (
  234. <LocaleProvider locale={ms_MY}>
  235. <I18nComponent />
  236. </LocaleProvider>
  237. );
  238. export const LocaleThTH = () => (
  239. <LocaleProvider locale={th_TH}>
  240. <I18nComponent />
  241. </LocaleProvider>
  242. );
  243. export const LocaleTrTR = () => (
  244. <LocaleProvider locale={tr_TR}>
  245. <I18nComponent />
  246. </LocaleProvider>
  247. );
  248. export const LocalePtBR = () => (
  249. <LocaleProvider locale={pt_BR}>
  250. <I18nComponent />
  251. </LocaleProvider>
  252. );
  253. export const LocaleES = () => (
  254. <LocaleProvider locale={es}>
  255. <I18nComponent />
  256. </LocaleProvider>
  257. );
  258. export const LocaleDe = () => (
  259. <LocaleProvider locale={de}>
  260. <I18nComponent />
  261. </LocaleProvider>
  262. );
  263. export const LocaleIt = () => (
  264. <LocaleProvider locale={it}>
  265. <I18nComponent />
  266. </LocaleProvider>
  267. );
  268. export const LocaleFr = () => (
  269. <LocaleProvider locale={fr}>
  270. <I18nComponent />
  271. </LocaleProvider>
  272. );
  273. export const LocaleRo = () => (
  274. <LocaleProvider locale={ro}>
  275. <I18nComponent />
  276. </LocaleProvider>
  277. );
  278. const treeData = [
  279. {
  280. label: 'Asia',
  281. value: 'asia',
  282. key: '1',
  283. children: [
  284. {
  285. label: 'China',
  286. value: 'china',
  287. key: '1-0',
  288. children: [
  289. { label: 'Beijing', value: 'beijing', key: '1-0-0' },
  290. { label: 'Shanghai', value: 'shanghai', key: '1-0-1' },
  291. ],
  292. },
  293. {
  294. label: 'Japan',
  295. value: 'japan',
  296. key: '1-1',
  297. children: [{ label: 'Osaka', value: 'osaka', key: '1-1-0' }],
  298. },
  299. ],
  300. },
  301. ];
  302. const I18nComponent2 = (props) => {
  303. const [modalVisible, setModalVisible] = useState(false);
  304. const columns = useMemo(() => [
  305. {
  306. title: 'Name',
  307. width: 250,
  308. dataIndex: 'name',
  309. },
  310. {
  311. title: 'Age',
  312. width: 150,
  313. dataIndex: 'age',
  314. },
  315. {
  316. title: 'Address',
  317. dataIndex: 'address',
  318. },
  319. ]);
  320. const dataSource = useMemo(() => {
  321. const data = [];
  322. for (let i = 0; i < 46; i++) {
  323. data.push({
  324. key: '' + i,
  325. name: `Bytedance ${i}`,
  326. age: 32,
  327. address: `Beijing, Haidian. Zhichun Road ${i}`,
  328. });
  329. }
  330. return data;
  331. });
  332. const transferData = useMemo(() => {
  333. return Array.from({ length: 100 }, (v, i) => {
  334. return {
  335. label: `选项名称 ${i}`,
  336. value: i,
  337. disabled: false,
  338. key: i,
  339. };
  340. });
  341. });
  342. const srcList = useMemo(
  343. () => [
  344. 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/abstract.jpg',
  345. 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/sky.jpg',
  346. 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/greenleaf.jpg',
  347. 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/colorful.jpg',
  348. ],
  349. []
  350. );
  351. const style = { margin: 10 };
  352. return (
  353. <>
  354. <h5>Pagination</h5>
  355. <Pagination total={100} showTotal showSizeChanger style={style} />
  356. <h5>Modal</h5>
  357. <div style={style}>
  358. <Button onClick={() => setModalVisible(true)}>Show Modal</Button>
  359. <Modal
  360. title="Modal"
  361. visible={modalVisible}
  362. onOk={() => setModalVisible(false)}
  363. onCancel={() => setModalVisible(false)}
  364. >
  365. <p>This is the content of a basic modal.</p>
  366. <p>More content...</p>
  367. </Modal>
  368. </div>
  369. <h5>InputNumber</h5>
  370. <InputNumber mode="currency" key={props.localeCode} defaultValue={1234567.89} />
  371. <h5>Select & Cascader</h5>
  372. <div style={style}>
  373. <Select filter style={{ width: '180px' }}>
  374. <Select.Option value="abc">abc</Select.Option>
  375. <Select.Option value="vigo" disabled>
  376. vigo
  377. </Select.Option>
  378. <Select.Option value="hotsoon">hotsoon</Select.Option>
  379. </Select>
  380. <Cascader
  381. style={{ width: 300, margin: 10 }}
  382. treeData={treeData}
  383. filterTreeNode
  384. insetLabel="Cascader"
  385. />
  386. </div>
  387. <h5>DatePicker</h5>
  388. <DatePicker style={{ ...style, width: 250 }} />
  389. <DatePicker style={{ ...style, width: 300 }} type="dateTime" />
  390. <DatePicker style={{ ...style, width: 300 }} type="dateRange" />
  391. <DatePicker style={{ ...style, width: 450 }} type="dateTimeRange" />
  392. <h5>TimePicker</h5>
  393. <TimePicker style={style} />
  394. <TimePicker use12Hours style={style} />
  395. <br />
  396. <br />
  397. <h5>TreeSelect</h5>
  398. <TreeSelect
  399. style={{ ...style, width: 300 }}
  400. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  401. treeData={treeData}
  402. filterTreeNode
  403. />
  404. <h5>Table</h5>
  405. <Table columns={columns} dataSource={dataSource} scroll={{ y: 320 }} />
  406. <h5>Table - Empty</h5>
  407. <Table columns={columns} dataSource={[]} scroll={{ y: 320 }} />
  408. <h5>List - Empty</h5>
  409. <List header={<div>List</div>} dataSource={[]} />
  410. <h5>Calendar</h5>
  411. <Calendar mode="month" displayValue={new Date('2024-02-01')} />
  412. <h5>Typography - Copyable</h5>
  413. <Typography.Paragraph copyable>Click to copy text.</Typography.Paragraph>
  414. <h5>Typography - Collapsible</h5>
  415. <Typography.Paragraph
  416. ellipsis={{ rows: 3, expandable: true, collapsible: true }}
  417. style={{ width: 300 }}
  418. >
  419. 支持展开和折叠:Semi Design 是由抖音前端团队与 UED
  420. 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的
  421. Web 应用。
  422. </Typography.Paragraph>
  423. <h5>Transfer</h5>
  424. <Transfer style={{ width: 568, height: 416 }} dataSource={transferData} />
  425. <h5>Image</h5>
  426. <ImagePreview showTooltip>
  427. {srcList.map((src, index) => {
  428. return (
  429. <Image
  430. key={index}
  431. src={src}
  432. width={200}
  433. alt={`lamp${index + 1}`}
  434. style={{ marginRight: 5 }}
  435. />
  436. );
  437. })}
  438. </ImagePreview>
  439. <h5>Form</h5>
  440. <Form layout="horizontal" onValueChange={values => console.log(values)}>
  441. <Form.Input field="UserName" label={{ text: '角色', optional: true }} style={{ width: 200 }} />
  442. </Form>
  443. <h5>Navigation</h5>
  444. <Nav
  445. bodyStyle={{ height: 320 }}
  446. items={[
  447. { itemKey: 'user', text: '用户管理', icon: <IconUser /> },
  448. { itemKey: 'union', text: '活动管理', icon: <IconStar /> },
  449. ]}
  450. header={{
  451. logo: <IconSemiLogo style={{ height: '36px', fontSize: 36 }} />,
  452. text: 'Semi 数据后台',
  453. }}
  454. footer={{
  455. collapseButton: true,
  456. }}
  457. />
  458. </>
  459. );
  460. };
  461. class I18nDemo extends React.Component {
  462. constructor(props) {
  463. super(props);
  464. this.state = {
  465. locale: zh_CN,
  466. localeCode: 'zh_CN',
  467. };
  468. this.onLanguageChange = this.onLanguageChange.bind(this);
  469. }
  470. onLanguageChange(code) {
  471. let language = {
  472. zh_CN: zh_CN,
  473. en_GB: en_GB,
  474. ko_KR: ko_KR,
  475. ja_JP: ja_JP,
  476. ar: ar,
  477. vi_VN: vi_VN,
  478. ru_RU: ru_RU,
  479. id_ID: id_ID,
  480. ms_MY: ms_MY,
  481. th_TH: th_TH,
  482. tr_TR: tr_TR,
  483. pt_BR: pt_BR,
  484. zh_TW: zh_TW,
  485. es: es,
  486. sv_SE: sv_SE,
  487. pl_PL: pl_PL,
  488. nl_NL: nl_NL,
  489. de,
  490. it,
  491. fr,
  492. ro,
  493. };
  494. this.setState({ locale: language[code], localeCode: code });
  495. }
  496. render() {
  497. const { locale, localeCode } = this.state;
  498. return (
  499. <>
  500. <div style={{ borderBottom: '1px solid var(--semi-color-border)', paddingBottom: 20 }}>
  501. <Select
  502. onChange={this.onLanguageChange}
  503. insetLabel="切换语言"
  504. style={{ width: 250 }}
  505. defaultValue="zh_CN"
  506. >
  507. <Select.Option value="zh_CN">简体中文</Select.Option>
  508. <Select.Option value="en_GB">英语(英)</Select.Option>
  509. <Select.Option value="ja_JP">日语</Select.Option>
  510. <Select.Option value="ko_KR">韩语</Select.Option>
  511. <Select.Option value="ar">阿拉伯语</Select.Option>
  512. <Select.Option value="vi_VN">越南语</Select.Option>
  513. <Select.Option value="ru_RU">俄罗斯语</Select.Option>
  514. <Select.Option value="id_ID">印尼语</Select.Option>
  515. <Select.Option value="ms_MY">马来语</Select.Option>
  516. <Select.Option value="th_TH">泰语</Select.Option>
  517. <Select.Option value="tr_TR">土耳其语</Select.Option>
  518. <Select.Option value="pt_BR">葡萄牙语(巴西)</Select.Option>
  519. <Select.Option value="zh_TW">繁体中文</Select.Option>
  520. <Select.Option value="es">西班牙语</Select.Option>
  521. <Select.Option value="de">德语</Select.Option>
  522. <Select.Option value="it">意大利语</Select.Option>
  523. <Select.Option value="fr">法语</Select.Option>
  524. <Select.Option value="ro">罗马尼亚语</Select.Option>
  525. </Select>
  526. </div>
  527. <LocaleProvider locale={locale}>
  528. <ConfigProvider direction={localeCode === 'ar' ? 'rtl' : 'ltr'} locale={locale}>
  529. <I18nComponent2 localeCode={localeCode}/>
  530. </ConfigProvider>
  531. </LocaleProvider>
  532. </>
  533. );
  534. }
  535. }
  536. export const Locale = () => <I18nDemo />;