diff --git a/packages/design/src/date-picker/demo/basic.tsx b/packages/design/src/date-picker/demo/basic.tsx index 83cf516b5..0d298da4d 100644 --- a/packages/design/src/date-picker/demo/basic.tsx +++ b/packages/design/src/date-picker/demo/basic.tsx @@ -7,7 +7,7 @@ const onChange: DatePickerProps['onChange'] = (date, dateString) => { }; const App: React.FC = () => ( - + diff --git a/packages/design/src/date-picker/demo/format.tsx b/packages/design/src/date-picker/demo/format.tsx new file mode 100644 index 000000000..ad8ceb067 --- /dev/null +++ b/packages/design/src/date-picker/demo/format.tsx @@ -0,0 +1,39 @@ +import React from 'react'; +import { DatePicker, Space } from '@oceanbase/design'; +import type { DatePickerProps } from '@oceanbase/design'; +import dayjs from 'dayjs'; +import customParseFormat from 'dayjs/plugin/customParseFormat'; + +dayjs.extend(customParseFormat); + +const { RangePicker } = DatePicker; + +const dateFormat = 'YYYY/MM/DD'; +const weekFormat = 'MM/DD'; +const monthFormat = 'YYYY/MM'; + +const dateFormatList = ['DD/MM/YYYY', 'DD/MM/YY', 'DD-MM-YYYY', 'DD-MM-YY']; + +const customFormat: DatePickerProps['format'] = value => + `custom format: ${value.format(dateFormat)}`; + +const customWeekStartEndFormat: DatePickerProps['format'] = value => + `${dayjs(value).startOf('week').format(weekFormat)} ~ ${dayjs(value) + .endOf('week') + .format(weekFormat)}`; + +const App: React.FC = () => ( + + + + + + + + +); + +export default App; diff --git a/packages/design/src/date-picker/demo/global-format.tsx b/packages/design/src/date-picker/demo/global-format.tsx new file mode 100644 index 000000000..af7467eec --- /dev/null +++ b/packages/design/src/date-picker/demo/global-format.tsx @@ -0,0 +1,78 @@ +import React, { useState } from 'react'; +import { ConfigProvider, DatePicker, Radio, Space, Switch } from '@oceanbase/design'; +import type { DatePickerProps } from '@oceanbase/design'; +import enUS from '@oceanbase/design/locale/en-US'; +import zhCN from '@oceanbase/design/locale/zh-CN'; +import dayjs from 'dayjs'; + +const App: React.FC = () => { + const [locale, setLocale] = useState('en-US'); + const [timezone, setTimezone] = useState(false); + + const onChange: DatePickerProps['onChange'] = (_, dateStr) => { + console.log('onChange:', dateStr); + }; + + const timezoneFormat = (format: string) => { + return timezone ? `${format} (UTC+8)` : format; + }; + + const enUSLocale: typeof enUS = { + ...enUS, + DatePicker: { + ...enUS.DatePicker!, + lang: { + ...enUS.DatePicker?.lang, + fieldDateFormat: timezoneFormat('MM/DD/YYYY'), + fieldDateTimeFormat: timezoneFormat('MM/DD/YYYY HH:mm:ss'), + }, + }, + }; + + const zhCNLocale: typeof zhCN = { + ...zhCN, + DatePicker: { + ...zhCN.DatePicker!, + lang: { + ...zhCN.DatePicker?.lang, + fieldDateFormat: timezoneFormat('YYYY-MM-DD'), + fieldDateTimeFormat: timezoneFormat('YYYY-MM-DD HH:mm:ss'), + }, + }, + }; + + return ( + + + locale: + { + setLocale(e.target.value); + }} + > + en-US + zh-CN + + + + timezone: + { + setTimezone(value); + }} + /> + + + + + + + + + ); +}; + +export default App; diff --git a/packages/design/src/date-picker/index.md b/packages/design/src/date-picker/index.md index e125cf5f4..f03193404 100644 --- a/packages/design/src/date-picker/index.md +++ b/packages/design/src/date-picker/index.md @@ -15,6 +15,8 @@ demo: + + ## API diff --git a/packages/ui/src/locale/en-US.ts b/packages/ui/src/locale/en-US.ts index d12d5c0bc..fdd3c9c2a 100644 --- a/packages/ui/src/locale/en-US.ts +++ b/packages/ui/src/locale/en-US.ts @@ -1,4 +1,4 @@ -import enUS from '@oceanbase/design/es/locale/en-US'; +import enUS from '@oceanbase/design/locale/en-US'; import BasicLayout from '../BasicLayout/locale/en-US'; import BatchOperationBar from '../BatchOperationBar/locale/en-US'; import Boundary from '../Boundary/locale/en-US';