From 94feba527c1452c7cf255d8f4c2ab219d8156b11 Mon Sep 17 00:00:00 2001 From: pengYYY Date: Sun, 26 Jun 2022 14:21:39 +0800 Subject: [PATCH 1/7] feat: globalconfig 0625 --- src/_common | 2 +- src/config-provider/config-provider.md | 7 + src/config-provider/type.ts | 30 ++ src/dialog/RenderDialog.tsx | 6 +- src/drawer/Drawer.tsx | 7 +- src/input/Input.tsx | 2 +- src/pagination/Pagination.tsx | 2 + .../__snapshots__/pagination.test.tsx.snap | 360 ++++++++++++------ src/pagination/_example/more.jsx | 15 +- src/pagination/hooks/usePageNumber.tsx | 25 +- src/pagination/pagination.md | 1 + src/pagination/type.ts | 5 + src/select/base/Select.tsx | 2 +- test/ssr/__snapshots__/ssr.test.js.snap | 2 +- 14 files changed, 338 insertions(+), 128 deletions(-) diff --git a/src/_common b/src/_common index 1bb1de8836..0da827d33b 160000 --- a/src/_common +++ b/src/_common @@ -1 +1 @@ -Subproject commit 1bb1de8836bc4775cee81ea537d97e544a8357a7 +Subproject commit 0da827d33bf508aab7a72f284fc84558be327de4 diff --git a/src/config-provider/config-provider.md b/src/config-provider/config-provider.md index 603738b4cc..19a0ed5296 100644 --- a/src/config-provider/config-provider.md +++ b/src/config-provider/config-provider.md @@ -34,6 +34,7 @@ upload | Object | - | 上传组件全局配置。TS 类型:`UploadConfig` | N 名称 | 类型 | 默认值 | 说明 | 必传 -- | -- | -- | -- | -- +autocomplete | String | - | 是否开启自动填充功能 | N placeholder | String | - | 语言配置,“请输入”占位符描述文本 | N ### PaginationConfig @@ -129,6 +130,8 @@ yearAriaLabel | String | - | 语言配置,“年” 描述文本 | N 名称 | 类型 | 默认值 | 说明 | 必传 -- | -- | -- | -- | -- cancel | Object | - | 取消按钮风格。TS 类型:`string | ButtonProps`,[Button API Documents](./button?tab=api)。[详细类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/config-provider/type.ts) | N +closeOnEscKeydown | Boolean | - | 按下 ESC 时是否触发对话框关闭事件 | N +closeOnOverlayClick | Boolean | - | 点击蒙层时是否触发关闭事件 | N confirm | Object | - | 确认按钮风格。TS 类型:`string | ButtonProps` | N confirmBtnTheme | Object | - | 确认按钮主题色,即 Dialog 的 `theme` 和 确认按钮的 `theme` 映射关系。示例:{ danger: 'danger' }。TS 类型:`{ default: string; info: string; warning: string; danger: string; success: string; }` | N @@ -137,7 +140,10 @@ confirmBtnTheme | Object | - | 确认按钮主题色,即 Dialog 的 `theme` 名称 | 类型 | 默认值 | 说明 | 必传 -- | -- | -- | -- | -- cancel | String | - | 语言配置,“取消”描述文本。TS 类型:`string | ButtonProps` | N +closeOnEscKeydown | Boolean | - | 按下 ESC 时是否触发抽屉关闭事件 | N +closeOnOverlayClick | Boolean | - | 点击蒙层时是否触发关闭事件 | N confirm | String | - | 语言配置,“确认”描述文本。TS 类型:`string | ButtonProps` | N +size | String | - | 尺寸配置,配置Drawer尺寸 | N ### PopconfirmConfig @@ -178,6 +184,7 @@ treeExpandAndFoldIcon | Function | undefined | 树形结构,展开和折叠图 -- | -- | -- | -- | -- clearIcon | Function | - | 清除图标,【注意】使用渲染函数输出图标组件。TS 类型:`TNode`。[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N empty | String | - | 语言配置,“暂无数据”描述文本 | N +filterable | Boolean | - | 全局配置是否可筛选 | N loadingText | String | - | 语言配置,“加载中”描述文本 | N placeholder | String | - | 语言配置,“请选择”占位符描述文本 | N diff --git a/src/config-provider/type.ts b/src/config-provider/type.ts index 991b1c074d..c7d65a58be 100644 --- a/src/config-provider/type.ts +++ b/src/config-provider/type.ts @@ -110,6 +110,11 @@ export interface GlobalConfigProvider { } export interface InputConfig { + /** + * 是否开启自动填充功能 + * @default '' + */ + autocomplete?: string; /** * 语言配置,“请输入”占位符描述文本 * @default '' @@ -403,6 +408,14 @@ export interface DialogConfig { * 取消按钮风格 */ cancel?: string | ButtonProps; + /** + * 按下 ESC 时是否触发对话框关闭事件 + */ + closeOnEscKeydown?: boolean; + /** + * 点击蒙层时是否触发关闭事件 + */ + closeOnOverlayClick?: boolean; /** * 确认按钮风格 */ @@ -419,11 +432,24 @@ export interface DrawerConfig { * @default '' */ cancel?: string | ButtonProps; + /** + * 按下 ESC 时是否触发抽屉关闭事件 + */ + closeOnEscKeydown?: boolean; + /** + * 点击蒙层时是否触发关闭事件 + */ + closeOnOverlayClick?: boolean; /** * 语言配置,“确认”描述文本 * @default '' */ confirm?: string | ButtonProps; + /** + * 尺寸配置,配置Drawer尺寸 + * @default '' + */ + size?: string; } export interface PopconfirmConfig { @@ -549,6 +575,10 @@ export interface SelectConfig { * @default '' */ empty?: string; + /** + * 全局配置是否可筛选 + */ + filterable?: boolean; /** * 语言配置,“加载中”描述文本 * @default '' diff --git a/src/dialog/RenderDialog.tsx b/src/dialog/RenderDialog.tsx index 23bd23bfdb..6522c8e621 100644 --- a/src/dialog/RenderDialog.tsx +++ b/src/dialog/RenderDialog.tsx @@ -7,6 +7,7 @@ import useLayoutEffect from '../_util/useLayoutEffect'; import { DialogProps } from './Dialog'; import useDialogEsc from '../_util/useDialogEsc'; import { dialogDefaultProps } from './defaultProps'; +import { useLocaleReceiver } from '../locale/LocalReceiver'; enum KeyCode { ESC = 27, @@ -35,6 +36,7 @@ if (typeof window !== 'undefined' && window.document && window.document.document document.documentElement.addEventListener('click', getClickPosition, true); } const RenderDialog = forwardRef((props: RenderDialogProps, ref: React.Ref) => { + const [local] = useLocaleReceiver('dialog'); const { prefixCls, attach, @@ -149,7 +151,7 @@ const RenderDialog = forwardRef((props: RenderDialogProps, ref: React.Ref) => { - if (closeOnOverlayClick) { + if (local.closeOnOverlayClick ?? closeOnOverlayClick) { onOverlayClick({ e }); onClose({ e, trigger: 'overlay' }); } @@ -165,7 +167,7 @@ const RenderDialog = forwardRef((props: RenderDialogProps, ref: React.Ref) = visible, attach = '', showOverlay, - size, + size: propsSize, placement, onCancel, onConfirm, @@ -66,6 +66,7 @@ const Drawer = forwardRef((props: DrawerProps, ref: React.Ref) = // 国际化文本初始化 const [local, t] = useLocaleReceiver('drawer'); + const size = local.size ?? propsSize; const confirmText = t(local.confirm); const cancelText = t(local.cancel); @@ -142,7 +143,7 @@ const Drawer = forwardRef((props: DrawerProps, ref: React.Ref) = function onMaskClick(e: React.MouseEvent) { onOverlayClick?.({ e }); - closeOnOverlayClick && onClose?.({ e, trigger: CloseTriggerType.CLICK_OVERLAY }); + (local.closeOnOverlayClick ?? closeOnOverlayClick) && onClose?.({ e, trigger: CloseTriggerType.CLICK_OVERLAY }); } function onClickCloseBtn(e: React.MouseEvent) { onCloseBtnClick?.({ e }); @@ -152,7 +153,7 @@ const Drawer = forwardRef((props: DrawerProps, ref: React.Ref) = if (e.key !== 'Escape') return; onEscKeydown?.({ e }); - closeOnEscKeydown && onClose?.({ e, trigger: CloseTriggerType.KEYDOWN_ESC }); + (local.closeOnEscKeydown ?? closeOnEscKeydown) && onClose?.({ e, trigger: CloseTriggerType.KEYDOWN_ESC }); } function onCancelClick(e: React.MouseEvent) { onCancel?.({ e }); diff --git a/src/input/Input.tsx b/src/input/Input.tsx index 2115f4e6d9..799043b08d 100644 --- a/src/input/Input.tsx +++ b/src/input/Input.tsx @@ -136,7 +136,7 @@ const Input = forwardRefWithStatics( value={composingRef.current ? composingRefValue : value ?? ''} readOnly={readonly} disabled={disabled} - autoComplete={autocomplete} + autoComplete={local.autocomplete ?? autocomplete} autoFocus={autofocus} maxLength={maxlength} onChange={handleChange} diff --git a/src/pagination/Pagination.tsx b/src/pagination/Pagination.tsx index b24e42595f..eabc78111f 100644 --- a/src/pagination/Pagination.tsx +++ b/src/pagination/Pagination.tsx @@ -34,6 +34,7 @@ const Pagination = forwardRef((props: PaginationProps, ref: React.Ref -
-
- 共 100 项数据 -
+
+ + 展示首尾页码省略 +
+ 共 100 项数据 +
+
- - - 5 条/页 - - - + + - - - + 5 条/页 + + + + + + +
-
-
- - - -
-
    -
  • - 1 -
  • -
  • + + +
+
    - 2 - -
  • + 1 +
  • +
  • + 2 +
  • +
  • + 3 +
  • +
  • + 4 +
  • +
  • + 5 +
  • +
  • + + + +
  • +
  • + 20 +
  • +
+
- 3 - -
  • + + +
  • +
    + + 不展示首尾页码省略 + +
    +
    - 4 - -
  • +
    - 5 -
  • -
  • +
    +
    +
    +
    + + + 5 条/页 + + + + + + +
    +
    +
    +
    +
  • +
    - -
  • +
      - 20 - -
    -
    - + 1 +
  • +
  • + 2 +
  • +
  • + 3 +
  • +
  • + 4 +
  • +
  • + 5 +
  • + +
    - - + + + +
    diff --git a/src/pagination/_example/more.jsx b/src/pagination/_example/more.jsx index 1f7fd655e9..ac3a807a13 100644 --- a/src/pagination/_example/more.jsx +++ b/src/pagination/_example/more.jsx @@ -8,5 +8,18 @@ export default function PaginationExample() { console.log(pageInfo); }; - return changePageSize(v)} />; + return ( +
    + 展示首尾页码省略 + changePageSize(v)} /> + 不展示首尾页码省略 + changePageSize(v)} + /> +
    + ); } diff --git a/src/pagination/hooks/usePageNumber.tsx b/src/pagination/hooks/usePageNumber.tsx index 85672faac0..de23492e67 100644 --- a/src/pagination/hooks/usePageNumber.tsx +++ b/src/pagination/hooks/usePageNumber.tsx @@ -10,8 +10,18 @@ export default function usePageNumber(props) { const [hoverPreMore, toggleHoverPreMore] = useState(false); // 处理left ellipsis展示逻辑 const [hoverNextMore, toggleHoverNextMore] = useState(false); // 处理right ellipsis展示逻辑 - const { showPageNumber, maxPageBtn, disabled, current, pageCount, foldedMaxPageBtn, changeCurrent } = props; + const { + showPageNumber, + maxPageBtn, + disabled, + current, + pageCount, + foldedMaxPageBtn, + changeCurrent, + pageEllipsisMode, + } = props; + const isMidEllipsis = pageEllipsisMode === 'mid'; const pivot = Math.ceil((foldedMaxPageBtn - 1) / 2); const pageList = useMemo>(() => { @@ -26,8 +36,11 @@ export default function usePageNumber(props) { start = current - pivot; end = current + pivot; } else { - start = isPrevMoreShow ? pageCount - foldedMaxPageBtn + 1 : 2; - end = isPrevMoreShow ? pageCount - 1 : foldedMaxPageBtn; + const foldedStart = isMidEllipsis ? 2 : 1; + const foldedEnd = isMidEllipsis ? pageCount - 1 : pageCount; + start = isPrevMoreShow ? pageCount - foldedMaxPageBtn + 1 : foldedStart; + end = isPrevMoreShow ? foldedEnd : foldedMaxPageBtn; + console.log(end); } } else { start = 1; @@ -38,13 +51,13 @@ export default function usePageNumber(props) { array.push(i); } return array; - }, [current, pageCount, foldedMaxPageBtn, maxPageBtn, pivot]); + }, [current, pageCount, foldedMaxPageBtn, isMidEllipsis, maxPageBtn, pivot]); const isFolded = pageCount > maxPageBtn; // 判断是否为需要折叠 const pageNumberContrl = showPageNumber && (
      - {isFolded && ( + {isFolded && isMidEllipsis && ( <>
    • ))} - {isFolded && ( + {isFolded && isMidEllipsis && ( <> {pageCount - 1 - pivot > current && (
    • [5, 10, 20, 50] | 分页大小控制器,值为 [] 则不显示。TS 类型:`Array` | N diff --git a/src/pagination/type.ts b/src/pagination/type.ts index 082387a248..ab89f0b96e 100644 --- a/src/pagination/type.ts +++ b/src/pagination/type.ts @@ -32,6 +32,11 @@ export interface TdPaginationProps { * @default 10 */ maxPageBtn?: number; + /** + * 页码数量超出时,前后省略模式, `mid`表示中间省略, `both-ends` 表示两端省略 + * @default mid + */ + pageEllipsisMode?: 'mid' | 'both-ends'; /** * 分页总页数 * @default 10 diff --git a/src/select/base/Select.tsx b/src/select/base/Select.tsx index 4b1e1763b1..6986bbe063 100644 --- a/src/select/base/Select.tsx +++ b/src/select/base/Select.tsx @@ -403,7 +403,7 @@ const Select = forwardRefWithStatics( className={name} ref={ref} readonly={readonly} - allowInput={filterable} + allowInput={(local.filterable ?? filterable) || isFunction(filter)} multiple={multiple} value={selectedLabel} valueDisplay={renderValueDisplay()} diff --git a/test/ssr/__snapshots__/ssr.test.js.snap b/test/ssr/__snapshots__/ssr.test.js.snap index 358bbe51c9..86a851b0d3 100644 --- a/test/ssr/__snapshots__/ssr.test.js.snap +++ b/test/ssr/__snapshots__/ssr.test.js.snap @@ -516,7 +516,7 @@ exports[`ssr snapshot test renders ./src/pagination/_example/jump.jsx correctly exports[`ssr snapshot test renders ./src/pagination/_example/mini.jsx correctly 1`] = `"
      共 100 项数据
      请选择
      • 1
      • 2
      • 3
      • 4
      • 5
      • 20
      "`; -exports[`ssr snapshot test renders ./src/pagination/_example/more.jsx correctly 1`] = `"
      共 100 项数据
      请选择
      • 1
      • 2
      • 3
      • 4
      • 5
      • 20
      "`; +exports[`ssr snapshot test renders ./src/pagination/_example/more.jsx correctly 1`] = `"
      展示首尾页码省略
      共 100 项数据
      请选择
      • 1
      • 2
      • 3
      • 4
      • 5
      • 20
      不展示首尾页码省略
      共 100 项数据
      请选择
      • 1
      • 2
      • 3
      • 4
      • 5
      "`; exports[`ssr snapshot test renders ./src/pagination/_example/page-num.jsx correctly 1`] = `"
      共 645 项数据
      请选择
      • 1
      • 2
      • 3
      • 4
      • 5
      • 33
      "`; From f2ba6281a792487685934138b46e2601fb7700cc Mon Sep 17 00:00:00 2001 From: pengYYY Date: Mon, 27 Jun 2022 10:21:40 +0800 Subject: [PATCH 2/7] feat: update common --- src/_common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_common b/src/_common index 0da827d33b..5ed35782c4 160000 --- a/src/_common +++ b/src/_common @@ -1 +1 @@ -Subproject commit 0da827d33bf508aab7a72f284fc84558be327de4 +Subproject commit 5ed35782c4f7f491ed7b08e5a339d75acf327959 From c3528a011be40f023676789e6ba1fb861fb6e89e Mon Sep 17 00:00:00 2001 From: pengYYY Date: Mon, 27 Jun 2022 10:29:37 +0800 Subject: [PATCH 3/7] feat: common update --- src/_common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_common b/src/_common index 5ed35782c4..aa01163ea3 160000 --- a/src/_common +++ b/src/_common @@ -1 +1 @@ -Subproject commit 5ed35782c4f7f491ed7b08e5a339d75acf327959 +Subproject commit aa01163ea3d517b1fd3be7c7412d109a32faaa70 From ab1ef9d0fdb10807d6b917b0da98fdbcd5209542 Mon Sep 17 00:00:00 2001 From: pengYYY Date: Mon, 27 Jun 2022 11:53:09 +0800 Subject: [PATCH 4/7] feat: global config default update --- src/_common | 2 +- src/config-provider/ConfigContext.tsx | 4 +- src/config-provider/en_US_config.ts | 146 ----------------- src/config-provider/zh_CN_config.ts | 152 ------------------ src/dialog/RenderDialog.tsx | 2 +- src/dialog/defaultProps.ts | 2 - src/dialog/dialog.md | 2 +- src/dialog/type.ts | 4 +- src/drawer/Drawer.tsx | 7 +- src/drawer/defaultProps.ts | 3 - src/input/Input.tsx | 2 +- src/select/base/Select.tsx | 2 +- src/select/defaultProps.ts | 1 - .../__snapshots__/time-picker.test.tsx.snap | 8 +- test/ssr/__snapshots__/ssr.test.js.snap | 6 +- 15 files changed, 19 insertions(+), 324 deletions(-) delete mode 100644 src/config-provider/en_US_config.ts delete mode 100644 src/config-provider/zh_CN_config.ts diff --git a/src/_common b/src/_common index aa01163ea3..19f72c3a91 160000 --- a/src/_common +++ b/src/_common @@ -1 +1 @@ -Subproject commit aa01163ea3d517b1fd3be7c7412d109a32faaa70 +Subproject commit 19f72c3a9145193278e94bdeb62c8ab9f2afd52e diff --git a/src/config-provider/ConfigContext.tsx b/src/config-provider/ConfigContext.tsx index f33436a929..369a03d3d0 100644 --- a/src/config-provider/ConfigContext.tsx +++ b/src/config-provider/ConfigContext.tsx @@ -1,7 +1,7 @@ import { createContext } from 'react'; import merge from 'lodash/merge'; import defaultLocale from '../locale/zh_CN'; -import DEFAULT_GLOBAL_CONFIG from './zh_CN_config'; +import defaultConfig from '../_common/js/global-config/default-config'; import { GlobalConfigProvider } from './type'; export enum EAnimationType { @@ -20,7 +20,7 @@ export const defaultAnimation = { export const defaultGlobalConfig = { animation: defaultAnimation, classPrefix: defaultClassPrefix, - ...merge(defaultLocale, DEFAULT_GLOBAL_CONFIG), + ...merge(defaultLocale, defaultConfig), }; export type Locale = typeof defaultLocale; diff --git a/src/config-provider/en_US_config.ts b/src/config-provider/en_US_config.ts deleted file mode 100644 index c9503e079d..0000000000 --- a/src/config-provider/en_US_config.ts +++ /dev/null @@ -1,146 +0,0 @@ -/* eslint-disable no-template-curly-in-string */ -import { GlobalConfigProvider } from './type'; - -// 文件有效,为国际化做准备 -const GLOBAL_CONFIG_EN: GlobalConfigProvider = { - pagination: { - itemsPerPage: '{size} / page', - jumpTo: 'jump to', - page: '', - total: '{total} items', - }, - cascader: { - empty: 'Empty Data', - loadingText: 'loading...', - placeholder: '', - }, - calendar: { - firstDayOfWeek: 7, - fillWithZero: true, - yearSelection: '{year}', - monthSelection: '{month}', - yearRadio: 'year', - monthRadio: 'month', - hideWeekend: 'Hide Week', - showWeekend: 'Show Week', - today: 'Today', - thisMonth: 'This Month', - week: 'Monday,Tuesday,Wedsday,Thuresday,Friday,Staturday,Sunday', - cellMonth: 'January,February,March,April,May,June,July,August,September,October,November,December', - }, - transfer: { - title: '{checked} / {total}', - empty: 'Empty Data', - placeholder: 'type keyword to search', - }, - timePicker: { - now: 'Now', - confirm: 'Confirm', - anteMeridiem: 'AM', - postMeridiem: 'PM', - placeholder: '', - }, - dialog: { - confirm: 'Confirm', - cancel: 'Cancel', - confirmBtnTheme: { - default: 'primary', - info: 'primary', - warning: 'primary', - danger: 'primary', - success: 'primary', - }, - }, - drawer: { - confirm: 'Confirm', - cancel: 'Cancel', - }, - popconfirm: { - confirm: 'OK', - cancel: 'Cancel', - confirmBtnTheme: { - default: 'primary', - warning: 'primary', - danger: 'primary', - }, - }, - table: { - empty: 'Empty Data', - // 展开和收起图标(使用收起图标) - expandIcon: undefined, - // 排序图标(使用降序图标) - sortIcon: undefined, - }, - select: { - empty: 'Empty Data', - loadingText: 'loading...', - placeholder: '', - // 清除按钮 - clearIcon: undefined, - }, - tree: { - empty: 'Empty Data', - // 目录层级图标 - folderIcon: undefined, - }, - treeSelect: { - empty: 'Empty Data', - loadingText: 'loading...', - }, - datePicker: { - placeholder: { - date: 'select date', - month: 'select month', - year: 'select year', - }, - weekdays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], - months: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], - firstDayOfWeek: 7, - rangeSeparator: ' ~ ', - format: 'DD/MM/YYYY', - yearAriaLabel: '', - confirm: 'Confirm', - selectTime: 'Select Time', - selectDate: 'Select Date', - nextYear: 'Next Year', - preYear: 'Last Year', - nextMonth: 'Next Month', - preMonth: 'Last Month', - preDecade: 'Last Decade', - nextDecade: 'Next Decade', - now: 'Now', - }, - steps: { - errorIcon: undefined, - }, - upload: { - sizeLimitMessage: 'File is too large to upload. {sizeLimit}', - cancelUploadText: 'Cancel', - }, - tag: { - closeIcon: undefined, - }, - form: { - requiredMark: true, - errorMessage: { - date: '${name} is invalid', - url: '${name} is invalid', - required: '${name} is required', - max: '${name} must be at least ${validate} characters', - min: '${name} cannot be longer than ${validate} characters', - len: '${name} must be exactly ${validate} characters', - enum: '${name} must be one of ${validate}', - idcard: '${name} is invalid', - telnumber: '${name} is invalid', - pattern: '${name} is invalid', - validator: '${name} is invalid', - boolean: '${name} is not a boolean', - number: '${name} must be a number', - }, - }, - input: { - placeholder: '', - }, -}; - -export default GLOBAL_CONFIG_EN; diff --git a/src/config-provider/zh_CN_config.ts b/src/config-provider/zh_CN_config.ts deleted file mode 100644 index 7eddb1c4fe..0000000000 --- a/src/config-provider/zh_CN_config.ts +++ /dev/null @@ -1,152 +0,0 @@ -/* eslint-disable no-template-curly-in-string */ -import { GlobalConfigProvider } from './type'; - -const GLOBAL_CONFIG_ZH: GlobalConfigProvider = { - pagination: { - itemsPerPage: '{size} 条/页', - jumpTo: '跳至', - page: '页', - total: '共 {total} 项数据', - }, - cascader: { - empty: '暂无数据', - loadingText: '加载中', - placeholder: '请选择', - }, - calendar: { - firstDayOfWeek: 1, - fillWithZero: true, - yearSelection: '{year} 年', - monthSelection: '{month} 月', - yearRadio: '年', - monthRadio: '月', - hideWeekend: '隐藏周末', - showWeekend: '显示周末', - today: '今天', - thisMonth: '本月', - week: '一,二,三,四,五,六,日', - cellMonth: '一月,二月,三月,四月,五月,六月,七月,八月,九月,十月,十一月,十二月', - }, - transfer: { - title: '{checked} / {total} 项', - empty: '暂无数据', - placeholder: '请输入关键词搜索', - }, - timePicker: { - now: '此刻', - confirm: '确定', - anteMeridiem: '上午', - postMeridiem: '下午', - placeholder: '请选择时间', - }, - dialog: { - confirm: '确认', - cancel: '取消', - confirmBtnTheme: { - default: 'primary', - info: 'primary', - warning: 'primary', - danger: 'primary', - success: 'primary', - }, - }, - drawer: { - confirm: '确认', - cancel: '取消', - }, - popconfirm: { - confirm: { - content: '确定', - size: 'small', - }, - cancel: { - content: '取消', - size: 'small', - }, - confirmBtnTheme: { - default: 'primary', - warning: 'primary', - danger: 'primary', - }, - }, - table: { - empty: '暂无数据', - // 展开和收起图标(使用收起图标) - expandIcon: undefined, - // 排序图标(使用降序图标) - sortIcon: undefined, - }, - select: { - empty: '暂无数据', - loadingText: '加载中', - placeholder: '请选择', - // 清除按钮 - clearIcon: undefined, - }, - tree: { - empty: '暂无数据', - // 目录层级图标 - folderIcon: undefined, - }, - treeSelect: { - empty: '暂无数据', - loadingText: '加载中', - placeholder: '请选择', - }, - datePicker: { - placeholder: { - date: '请选择日期', - month: '请选择月份', - year: '请选择年份', - }, - weekdays: ['一', '二', '三', '四', '五', '六', '日'], - months: ['1 月', '2 月', '3 月', '4 月', '5 月', '6 月', '7 月', '8 月', '9 月', '10 月', '11 月', '12 月'], - firstDayOfWeek: 1, - rangeSeparator: ' 至 ', - format: 'YYYY-MM-DD', - yearAriaLabel: '年', - confirm: '确定', - selectTime: '选择时间', - selectDate: '选择日期', - nextYear: '下一年', - preYear: '上一年', - nextMonth: '下个月', - preMonth: '上个月', - preDecade: '上个十年', - nextDecade: '下个十年', - now: '当前', - }, - steps: { - errorIcon: undefined, - }, - upload: { - sizeLimitMessage: '文件大小不能超过 {sizeLimit}', - cancelUploadText: '取消上传', - }, - tag: { - closeIcon: undefined, - }, - form: { - requiredMark: true, - errorMessage: { - date: '请输入正确的${name}', - url: '请输入正确的${name}', - required: '${name}必填', - max: '${name}字符长度不能超过 ${validate} 个字符,一个中文等于两个字符', - min: '${name}字符长度不能少于 ${validate} 个字符,一个中文等于两个字符', - len: '${name}字符长度必须是 ${validate}', - enum: '${name}只能是${validate}等', - idcard: '请输入正确的${name}', - telnumber: '请输入正确的${name}', - pattern: '请输入正确的${name}', - validator: '${name}不符合要求', - boolean: '${name}数据类型必须是布尔类型', - number: '${name}必须是数字', - }, - }, - input: { - placeholder: '请输入', - }, -}; - -export default GLOBAL_CONFIG_ZH; diff --git a/src/dialog/RenderDialog.tsx b/src/dialog/RenderDialog.tsx index 6522c8e621..aa4e27dbc0 100644 --- a/src/dialog/RenderDialog.tsx +++ b/src/dialog/RenderDialog.tsx @@ -167,7 +167,7 @@ const RenderDialog = forwardRef((props: RenderDialogProps, ref: React.Ref document.body。TS 类型:`AttachNode`。[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N body | TNode | '' | 对话框内容。TS 类型:`string | TNode`。[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N -cancelBtn | TNode | '' | 取消按钮,可自定义。值为 null 则不显示取消按钮。值类型为字符串,则表示自定义按钮文本,值类型为 Object 则表示透传 Button 组件属性。使用 TNode 自定义按钮时,需自行控制取消事件。TS 类型:`string | ButtonProps | TNode`,[Button API Documents](./button?tab=api)。[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts)。[详细类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/dialog/type.ts) | N +cancelBtn | TNode | '' | 取消按钮,可自定义。值为 null 则不显示取消按钮。值类型为字符串,则表示自定义按钮文本,值类型为 Object 则表示透传 Button 组件属性。使用 TNode 自定义按钮时,需自行控制取消事件。TS 类型:`string | ButtonProps | TNode | null`,[Button API Documents](./button?tab=api)。[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts)。[详细类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/dialog/type.ts) | N children | TNode | - | 对话框内容,同 body。TS 类型:`string | TNode`。[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N closeBtn | TNode | true | 关闭按钮,可以自定义。值为 true 显示默认关闭按钮,值为 false 不显示关闭按钮。值类型为 string 则直接显示值,如:“关闭”。值类型为 TNode,则表示呈现自定义按钮示例。TS 类型:`string | boolean | TNode`。[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N closeOnEscKeydown | Boolean | true | 按下 ESC 时是否触发对话框关闭事件 | N diff --git a/src/dialog/type.ts b/src/dialog/type.ts index 475bea3626..a609c92be6 100644 --- a/src/dialog/type.ts +++ b/src/dialog/type.ts @@ -23,7 +23,7 @@ export interface TdDialogProps { * 取消按钮,可自定义。值为 null 则不显示取消按钮。值类型为字符串,则表示自定义按钮文本,值类型为 Object 则表示透传 Button 组件属性。使用 TNode 自定义按钮时,需自行控制取消事件 * @default '' */ - cancelBtn?: ButtonProps | TNode; + cancelBtn?: ButtonProps | TNode | null; /** * 对话框内容,同 body */ @@ -35,12 +35,10 @@ export interface TdDialogProps { closeBtn?: TNode; /** * 按下 ESC 时是否触发对话框关闭事件 - * @default true */ closeOnEscKeydown?: boolean; /** * 点击蒙层时是否触发关闭事件 - * @default true */ closeOnOverlayClick?: boolean; /** diff --git a/src/drawer/Drawer.tsx b/src/drawer/Drawer.tsx index dfd8ca7424..1c3f1d651b 100644 --- a/src/drawer/Drawer.tsx +++ b/src/drawer/Drawer.tsx @@ -66,7 +66,8 @@ const Drawer = forwardRef((props: DrawerProps, ref: React.Ref) = // 国际化文本初始化 const [local, t] = useLocaleReceiver('drawer'); - const size = local.size ?? propsSize; + console.log(local); + const size = propsSize ?? local.size; const confirmText = t(local.confirm); const cancelText = t(local.cancel); @@ -143,7 +144,7 @@ const Drawer = forwardRef((props: DrawerProps, ref: React.Ref) = function onMaskClick(e: React.MouseEvent) { onOverlayClick?.({ e }); - (local.closeOnOverlayClick ?? closeOnOverlayClick) && onClose?.({ e, trigger: CloseTriggerType.CLICK_OVERLAY }); + (closeOnOverlayClick ?? local.closeOnOverlayClick) && onClose?.({ e, trigger: CloseTriggerType.CLICK_OVERLAY }); } function onClickCloseBtn(e: React.MouseEvent) { onCloseBtnClick?.({ e }); @@ -153,7 +154,7 @@ const Drawer = forwardRef((props: DrawerProps, ref: React.Ref) = if (e.key !== 'Escape') return; onEscKeydown?.({ e }); - (local.closeOnEscKeydown ?? closeOnEscKeydown) && onClose?.({ e, trigger: CloseTriggerType.KEYDOWN_ESC }); + (closeOnEscKeydown ?? local.closeOnEscKeydown) && onClose?.({ e, trigger: CloseTriggerType.KEYDOWN_ESC }); } function onCancelClick(e: React.MouseEvent) { onCancel?.({ e }); diff --git a/src/drawer/defaultProps.ts b/src/drawer/defaultProps.ts index f015f7c32c..1c8fe9ed49 100644 --- a/src/drawer/defaultProps.ts +++ b/src/drawer/defaultProps.ts @@ -6,8 +6,6 @@ import { TdDrawerProps } from './type'; export const drawerDefaultProps: TdDrawerProps = { closeBtn: true, - closeOnEscKeydown: true, - closeOnOverlayClick: true, destroyOnClose: false, footer: true, header: true, @@ -16,7 +14,6 @@ export const drawerDefaultProps: TdDrawerProps = { preventScrollThrough: true, showInAttachedElement: false, showOverlay: true, - size: 'small', sizeDraggable: false, visible: false, }; diff --git a/src/input/Input.tsx b/src/input/Input.tsx index 799043b08d..105f79cee5 100644 --- a/src/input/Input.tsx +++ b/src/input/Input.tsx @@ -136,7 +136,7 @@ const Input = forwardRefWithStatics( value={composingRef.current ? composingRefValue : value ?? ''} readOnly={readonly} disabled={disabled} - autoComplete={local.autocomplete ?? autocomplete} + autoComplete={autocomplete ?? (local.autocomplete || undefined)} autoFocus={autofocus} maxLength={maxlength} onChange={handleChange} diff --git a/src/select/base/Select.tsx b/src/select/base/Select.tsx index 6986bbe063..a1d2dbf35a 100644 --- a/src/select/base/Select.tsx +++ b/src/select/base/Select.tsx @@ -403,7 +403,7 @@ const Select = forwardRefWithStatics( className={name} ref={ref} readonly={readonly} - allowInput={(local.filterable ?? filterable) || isFunction(filter)} + allowInput={(filterable ?? local.filterable) || isFunction(filter)} multiple={multiple} value={selectedLabel} valueDisplay={renderValueDisplay()} diff --git a/src/select/defaultProps.ts b/src/select/defaultProps.ts index f47574ca52..522fad3981 100644 --- a/src/select/defaultProps.ts +++ b/src/select/defaultProps.ts @@ -14,7 +14,6 @@ export const selectDefaultProps: TdSelectProps = { borderless: false, clearable: false, creatable: false, - filterable: false, loading: false, max: 0, minCollapsedNum: 0, diff --git a/src/time-picker/__tests__/__snapshots__/time-picker.test.tsx.snap b/src/time-picker/__tests__/__snapshots__/time-picker.test.tsx.snap index fc66d32275..7ecc880449 100644 --- a/src/time-picker/__tests__/__snapshots__/time-picker.test.tsx.snap +++ b/src/time-picker/__tests__/__snapshots__/time-picker.test.tsx.snap @@ -35,7 +35,7 @@ exports[`disabled.jsx 1`] = `
      "`; -exports[`ssr snapshot test renders ./src/time-picker/_example/disabled.jsx correctly 1`] = `"

      禁用整个选择器

      禁用指定时间

      "`; +exports[`ssr snapshot test renders ./src/time-picker/_example/disabled.jsx correctly 1`] = `"

      禁用整个选择器

      禁用指定时间

      "`; exports[`ssr snapshot test renders ./src/time-picker/_example/hide-clear-button.jsx correctly 1`] = `"

      禁止清空

      允许清空

      "`; @@ -870,9 +870,9 @@ exports[`ssr snapshot test renders ./src/time-picker/_example/panel.jsx correctl exports[`ssr snapshot test renders ./src/time-picker/_example/range.jsx correctly 1`] = `"
      -
      "`; -exports[`ssr snapshot test renders ./src/time-picker/_example/show-steps.jsx correctly 1`] = `"
      "`; +exports[`ssr snapshot test renders ./src/time-picker/_example/show-steps.jsx correctly 1`] = `"
      "`; -exports[`ssr snapshot test renders ./src/time-picker/_example/twelve-hour-meridian.jsx correctly 1`] = `"
      "`; +exports[`ssr snapshot test renders ./src/time-picker/_example/twelve-hour-meridian.jsx correctly 1`] = `"
      "`; exports[`ssr snapshot test renders ./src/tooltip/_example/arrow.jsx correctly 1`] = `"
      "`; From be979ff283855800f3e7d9f6a9c497fce60d787e Mon Sep 17 00:00:00 2001 From: pengYYY Date: Mon, 27 Jun 2022 11:58:16 +0800 Subject: [PATCH 5/7] chore: remove log --- src/drawer/Drawer.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/drawer/Drawer.tsx b/src/drawer/Drawer.tsx index 1c3f1d651b..b1c31b5632 100644 --- a/src/drawer/Drawer.tsx +++ b/src/drawer/Drawer.tsx @@ -66,7 +66,6 @@ const Drawer = forwardRef((props: DrawerProps, ref: React.Ref) = // 国际化文本初始化 const [local, t] = useLocaleReceiver('drawer'); - console.log(local); const size = propsSize ?? local.size; const confirmText = t(local.confirm); const cancelText = t(local.cancel); From 0846d051998eb6e5c84a3499358d78594c833225 Mon Sep 17 00:00:00 2001 From: pengYYY Date: Mon, 27 Jun 2022 13:10:46 +0800 Subject: [PATCH 6/7] chore: closeOnOverlayClick config --- src/dialog/RenderDialog.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dialog/RenderDialog.tsx b/src/dialog/RenderDialog.tsx index aa4e27dbc0..8baa82ed43 100644 --- a/src/dialog/RenderDialog.tsx +++ b/src/dialog/RenderDialog.tsx @@ -151,7 +151,7 @@ const RenderDialog = forwardRef((props: RenderDialogProps, ref: React.Ref) => { - if (local.closeOnOverlayClick ?? closeOnOverlayClick) { + if (closeOnOverlayClick ?? local.closeOnOverlayClick) { onOverlayClick({ e }); onClose({ e, trigger: 'overlay' }); } From 4f59ec578332c0c0162b0cbd7a38d3df7b9b5352 Mon Sep 17 00:00:00 2001 From: pengYYY Date: Mon, 27 Jun 2022 13:13:59 +0800 Subject: [PATCH 7/7] chore: pageEllipsisMode default --- src/pagination/Pagination.tsx | 2 +- src/pagination/defaultProps.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pagination/Pagination.tsx b/src/pagination/Pagination.tsx index eabc78111f..28cc46534e 100644 --- a/src/pagination/Pagination.tsx +++ b/src/pagination/Pagination.tsx @@ -34,7 +34,7 @@ const Pagination = forwardRef((props: PaginationProps, ref: React.Ref