locale.stories.jsx 16 KB

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