diff --git a/packages/common b/packages/common index bd0763a7d0..246d6814b5 160000 --- a/packages/common +++ b/packages/common @@ -1 +1 @@ -Subproject commit bd0763a7d021bf36763bdfad6e3f477c1ab3d8e7 +Subproject commit 246d6814b563b187ff5c2e3e29cca3c2ce0c448d diff --git a/packages/components/config-provider/config-provider.en-US.md b/packages/components/config-provider/config-provider.en-US.md index 6865d89170..ac44484f05 100644 --- a/packages/components/config-provider/config-provider.en-US.md +++ b/packages/components/config-provider/config-provider.en-US.md @@ -58,50 +58,51 @@ const globalConfig: GlobalConfigProvider = { name | type | default | description | required -- | -- | -- | -- | -- -globalConfig | Object | - | global config。Typescript: `GlobalConfigProvider` | N +globalConfig | Object | - | global config. Typescript: `GlobalConfigProvider` | N ### GlobalConfigProvider name | type | default | description | required -- | -- | -- | -- | -- -alert | Object | - | Alert global configs。Typescript: `AlertConfig` | N -anchor | Object | - | Anchor global configs。Typescript: `AnchorConfig` | N -animation | Object | - | Typescript: `Partial>>` `type AnimationType = 'ripple' \| 'expand' \| 'fade'`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N -attach | String / Object / Function | - | Typescript: `AttachNode \| { imageViewer?: AttachNode; popup?: AttachNode; dialog?: AttachNode; drawer?: AttachNode; }`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N -autoComplete | Object | - | AutoComplete global configs。Typescript: `AutoCompleteConfig` | N -calendar | Object | - | Calendar global configs。Typescript: `CalendarConfig` | N -cascader | Object | - | Cascader global configs。Typescript: `CascaderConfig` | N +alert | Object | - | Alert global configs. Typescript: `AlertConfig` | N +anchor | Object | - | Anchor global configs. Typescript: `AnchorConfig` | N +animation | Object | - | Typescript: `Partial>>` `type AnimationType = 'ripple' \| 'expand' \| 'fade'`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N +attach | String / Object / Function | - | Popup container, configured for all overlays or separately for imageViewer, popup, dialog and drawer. The component attach prop takes precedence. Unconfigured components retain their default mounting behavior. Typescript: `AttachNode \| { imageViewer?: AttachNode; popup?: AttachNode; dialog?: AttachNode; drawer?: AttachNode; }`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +autoComplete | Object | - | AutoComplete global configs. Typescript: `AutoCompleteConfig` | N +calendar | Object | - | Calendar global configs. Typescript: `CalendarConfig` | N +cascader | Object | - | Cascader global configs. Typescript: `CascaderConfig` | N classPrefix | String | t | \- | N -colorPicker | Object | - | ColorPicker global configs。Typescript: `ColorPickerConfig` | N -datePicker | Object | - | DatePicker global configs。Typescript: `DatePickerConfig` | N -descriptions | Object | - | Descriptions global configs。Typescript: `DescriptionsConfig` | N -dialog | Object | - | Dialog global configs。Typescript: `DialogConfig` | N -drawer | Object | - | Drawer global configs。Typescript: `DrawerConfig` | N -empty | Object | - | Empty global configs。Typescript: `EmptyConfig` | N -form | Object | - | Form global configs。Typescript: `FormConfig` | N -guide | Object | - | Guide global configs。Typescript: `GuideConfig` | N -icon | Object | - | icon config。Typescript: `IconConfig` `type IconConfig = GlobalIconConfig` `import { GlobalIconConfig } from '@icon'`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N -image | Object | - | image global configs。Typescript: `ImageConfig` | N -imageViewer | Object | - | imageViewer global configs。Typescript: `ImageViewerConfig` | N -input | Object | - | Input global configs。Typescript: `InputConfig` | N +colorPicker | Object | - | ColorPicker global configs. Typescript: `ColorPickerConfig` | N +datePicker | Object | - | DatePicker global configs. Typescript: `DatePickerConfig` | N +descriptions | Object | - | Descriptions global configs. Typescript: `DescriptionsConfig` | N +dialog | Object | - | Dialog global configs. Typescript: `DialogConfig` | N +drawer | Object | - | Drawer global configs. Typescript: `DrawerConfig` | N +empty | Object | - | Empty global configs. Typescript: `EmptyConfig` | N +form | Object | - | Form global configs. Typescript: `FormConfig` | N +guide | Object | - | Guide global configs. Typescript: `GuideConfig` | N +icon | Object | - | icon config. Typescript: `IconConfig` `type IconConfig = GlobalIconConfig` `import { GlobalIconConfig } from '@icon'`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N +image | Object | - | image global configs. Typescript: `ImageConfig` | N +imageViewer | Object | - | imageViewer global configs. Typescript: `ImageViewerConfig` | N +input | Object | - | Input global configs. Typescript: `InputConfig` | N isContextEffectPlugin | Boolean | false | Whether the global configuration affects the components used by the functional invocation method | N -list | Object | - | List global configs。Typescript: `ListConfig` | N -loading | Object | - | Loading global configs。Typescript: `LoadingConfig` | N -message | Object | - | Message Component global configs。Typescript: `MessageConfig` | N -pagination | Object | - | Pagination global configs。Typescript: `PaginationConfig` | N -popconfirm | Object | - | Popconfirm global configs。Typescript: `PopconfirmConfig` | N -qrcode | Object | - | QRCode global configs。Typescript: `QRCodeConfig` | N -rate | Object | - | Rate global configs。Typescript: `RateConfig` | N -select | Object | - | Select global configs。Typescript: `SelectConfig` | N -steps | Object | - | Steps global configs。Typescript: `StepsConfig` | N -table | Object | - | Table global configs。Typescript: `TableConfig` | N -tag | Object | - | Tag global configs。Typescript: `TagConfig` | N -timePicker | Object | - | TimePicker global configs。Typescript: `TimePickerConfig` | N -transfer | Object | - | Transfer global configs。Typescript: `TransferConfig` | N -tree | Object | - | Tree global configs。Typescript: `TreeConfig` | N -treeSelect | Object | - | TreeSelect global configs。Typescript: `TreeSelectConfig` | N -typography | Object | - | Typography global configs。Typescript: `TypographyConfig` | N -upload | Object | - | Upload global configs。Typescript: `UploadConfig` | N +list | Object | - | List global configs. Typescript: `ListConfig` | N +loading | Object | - | Loading global configs. Typescript: `LoadingConfig` | N +message | Object | - | Message Component global configs. Typescript: `MessageConfig` | N +pagination | Object | - | Pagination global configs. Typescript: `PaginationConfig` | N +popconfirm | Object | - | Popconfirm global configs. Typescript: `PopconfirmConfig` | N +qrcode | Object | - | QRCode global configs. Typescript: `QRCodeConfig` | N +rate | Object | - | Rate global configs. Typescript: `RateConfig` | N +select | Object | - | Select global configs. Typescript: `SelectConfig` | N +steps | Object | - | Steps global configs. Typescript: `StepsConfig` | N +table | Object | - | Table global configs. Typescript: `TableConfig` | N +tag | Object | - | Tag global configs. Typescript: `TagConfig` | N +textarea | Object | - | Textarea global configs. Typescript: `TextareaConfig` | N +timePicker | Object | - | TimePicker global configs. Typescript: `TimePickerConfig` | N +transfer | Object | - | Transfer global configs. Typescript: `TransferConfig` | N +tree | Object | - | Tree global configs. Typescript: `TreeConfig` | N +treeSelect | Object | - | TreeSelect global configs. Typescript: `TreeSelectConfig` | N +typography | Object | - | Typography global configs. Typescript: `TypographyConfig` | N +upload | Object | - | Upload global configs. Typescript: `UploadConfig` | N ### AlertConfig @@ -128,7 +129,7 @@ empty | String | - | \- | N name | type | default | description | required -- | -- | -- | -- | -- cellMonth | String | - | \- | N -controllerConfig | Object | - | Typescript: `CalendarController`,[Calendar API Documents](./calendar?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N +controllerConfig | Object | - | Typescript: `CalendarController`,[Calendar API Documents](./calendar?tab=api). [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N fillWithZero | Boolean | true | \- | N firstDayOfWeek | Number | 1 | options: 1/2/3/4/5/6/7 | N hideWeekend | String | - | \- | N @@ -177,7 +178,6 @@ placeholder | Object | - | Typescript: `{ date?: string; month?: string; year?: preDecade | String | - | pre decade text | N preMonth | String | - | pre month text | N preYear | String | - | pre year text | N -presets | Object | - | Typescript: `ConfigPresetDate` `interface ConfigPresetDate { [name: string]: DateConfigValue \| (() => DateConfigValue) }` `type DateConfigValue = string \| Date \| Array`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N quarters | Array | - | Typescript: `string[]` | N rangeSeparator | String | - | range separator text | N selectDate | String | - | select date text | N @@ -196,7 +196,7 @@ colonText | String | - | colon on the right of label, ":" | N name | type | default | description | required -- | -- | -- | -- | -- -cancel | Object | - | Typescript: `string \| ButtonProps`,[Button API Documents](./button?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N +cancel | Object | - | Typescript: `string \| ButtonProps`,[Button API Documents](./button?tab=api). [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N closeOnEscKeydown | Boolean | true | trigger dialog close on `ESC` keydown | N closeOnOverlayClick | Boolean | true | \- | N confirm | Object | - | Typescript: `string \| ButtonProps` | N @@ -218,7 +218,7 @@ size | String | 'small' | \- | N name | type | default | description | required -- | -- | -- | -- | -- -image | Object | - | Typescript: `{ maintenance: TNode; success: TNode; fail: TNode; empty: TNode; networkError: TNode; }`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +image | Object | - | Typescript: `{ maintenance: TNode; success: TNode; fail: TNode; empty: TNode; networkError: TNode; }`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N titleText | Object | - | Typescript: `{ maintenance: string; success: string; fail: string; empty: string; networkError: string; }` | N ### FormConfig @@ -226,18 +226,18 @@ titleText | Object | - | Typescript: `{ maintenance: string; success: string; fa name | type | default | description | required -- | -- | -- | -- | -- colonText | String | - | colon on the right of label ":" | N -errorMessage | Object | - | Typescript: `FormErrorMessage`,[Form API Documents](./form?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N +errorMessage | Object | - | Typescript: `FormErrorMessage`,[Form API Documents](./form?tab=api). [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N requiredMark | Boolean | true | \- | N -requiredMarkPosition | String | left | Display position of required symbols。options: left/right | N +requiredMarkPosition | String | left | Display position of required symbols. options: left/right | N ### GuideConfig name | type | default | description | required -- | -- | -- | -- | -- -finishButtonProps | Object | - | finish button in last step. `{ content: 'Finish', theme: 'primary' }`。Typescript: `ButtonProps` | N -nextButtonProps | Object | - | next step button. `{ content: 'Next Button', theme: 'primary' }`。Typescript: `ButtonProps` | N -prevButtonProps | Object | - | previous step button. `{ content: 'Previous Step', theme: 'default' }`。Typescript: `ButtonProps` | N -skipButtonProps | Object | - | skip button. `{ content: 'Skip', theme: 'default' }`。Typescript: `ButtonProps` | N +finishButtonProps | Object | - | finish button in last step. `{ content: 'Finish', theme: 'primary' }`. Typescript: `ButtonProps` | N +nextButtonProps | Object | - | next step button. `{ content: 'Next Button', theme: 'primary' }`. Typescript: `ButtonProps` | N +prevButtonProps | Object | - | previous step button. `{ content: 'Previous Step', theme: 'default' }`. Typescript: `ButtonProps` | N +skipButtonProps | Object | - | skip button. `{ content: 'Skip', theme: 'default' }`. Typescript: `ButtonProps` | N ### ImageConfig @@ -245,7 +245,7 @@ name | type | default | description | required -- | -- | -- | -- | -- errorText | String | - | loading text, default value is "Error" | N loadingText | String | - | loading text, default value is "loading" | N -replaceImageSrc | Function | - | replace all `src` attribute of images。Typescript: `(params: ImageProps) => string`,[Image API Documents](./image?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N +replaceImageSrc | Function | - | replace all `src` attribute of images. Typescript: `(params: ImageProps) => string`,[Image API Documents](./image?tab=api). [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N ### ImageViewerConfig @@ -262,7 +262,7 @@ rotateTipText | String | - | rotate operation text | N name | type | default | description | required -- | -- | -- | -- | -- autocomplete | String | - | \- | N -clearTrigger | String | focus | Trigger to show a clear icon, valid when the input has a value。options: always / focus | N +clearTrigger | String | focus | Trigger to show a clear icon, valid when the input has a value. options: always / focus | N placeholder | String | - | \- | N ### ListConfig @@ -296,13 +296,13 @@ total | String | - | \- | N name | params | return | description -- | -- | -- | -- -jumper | `(jumperProps: JumperProps)` | `TNode` | [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts)。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts)。
`interface JumperProps { current: number; pageCount: number; onChange: (current: number) => void; }`
+jumper | `(jumperProps: JumperProps)` | `TNode` | [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts). [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts).
`interface JumperProps { current: number; pageCount: number; onChange: (current: number) => void; }`
### PopconfirmConfig name | type | default | description | required -- | -- | -- | -- | -- -cancel | String / Object | - | Typescript: `string \| ButtonProps`,[Button API Documents](./button?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N +cancel | String / Object | - | Typescript: `string \| ButtonProps`,[Button API Documents](./button?tab=api). [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N confirm | String / Object | - | Typescript: `string \| ButtonProps` | N confirmBtnTheme | Object | - | Typescript: `{ default: string; warning: string; danger: string; }` | N @@ -324,7 +324,7 @@ rateText | Array | - | Typescript: `string[]` | N name | type | default | description | required -- | -- | -- | -- | -- -clearIcon | Function | - | Typescript: `TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +clearIcon | Function | - | Typescript: `TNode`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N empty | String | - | \- | N filterable | Boolean | false | \- | N loadingText | String | - | \- | N @@ -334,8 +334,8 @@ placeholder | String | - | placeholder text | N name | type | default | description | required -- | -- | -- | -- | -- -checkIcon | TElement | - | Typescript: `TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N -errorIcon | TElement | - | Typescript: `TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +checkIcon | TElement | - | Typescript: `TNode`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +errorIcon | TElement | - | Typescript: `TNode`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N ### TableConfig @@ -347,27 +347,34 @@ columnConfigButtonText | String | - | \- | N columnConfigDescriptionText | String | - | \- | N columnConfigTitleText | String | - | \- | N confirmText | String | - | \- | N -empty | TNode | - | Typescript: `string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N -expandIcon | TElement | undefined | Typescript: `TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N -filterIcon | TElement | undefined | Typescript: `TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +empty | TNode | - | Typescript: `string \| TNode`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +expandIcon | TElement | undefined | Typescript: `TNode`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +filterIcon | TElement | undefined | Typescript: `TNode`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N hideSortTips | Boolean | false | hide sort tips | N loadingMoreText | String | - | \- | N loadingText | String | - | \- | N resetText | String | - | \- | N searchResultText | String | - | \- | N selectAllText | String | - | \- | N -size | String | medium | options: small/medium/large。Typescript: `SizeEnum`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +size | String | medium | options: small/medium/large. Typescript: `SizeEnum`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N sortAscendingOperationText | String | - | \- | N sortCancelOperationText | String | - | \- | N sortDescendingOperationText | String | - | \- | N -sortIcon | TElement | undefined | Typescript: `TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N -treeExpandAndFoldIcon | Function | undefined | Typescript: `TNode<{ type: 'expand' \| 'fold' }>`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +sortIcon | TElement | undefined | Typescript: `TNode`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +treeExpandAndFoldIcon | Function | undefined | Typescript: `TNode<{ type: 'expand' \| 'fold' }>`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N ### TagConfig name | type | default | description | required -- | -- | -- | -- | -- -closeIcon | Function | - | Typescript: `TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +closeIcon | Function | - | Typescript: `TNode`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N + +### TextareaConfig + +name | type | default | description | required +-- | -- | -- | -- | -- +clearText | String | - | Clear button text | N +clearTrigger | String | focus | Trigger to show the clear button, valid when the textarea has a value. options: always/focus | N ### TimePickerConfig @@ -392,7 +399,7 @@ title | String | - | \- | N name | type | default | description | required -- | -- | -- | -- | -- empty | String | - | \- | N -folderIcon | Function | - | Typescript: `TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +folderIcon | Function | - | Typescript: `TNode`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N ### TreeSelectConfig @@ -419,7 +426,7 @@ dragger | Object | - | Typescript: `UploadConfigDragger` | N file | Object | - | Typescript: `UploadConfigFileList` | N progress | Object | - | Typescript: `UploadConfigProgress` | N sizeLimitMessage | String | - | \- | N -triggerUploadText | Object | - | Typescript: `UploadTriggerUploadText` `interface UploadTriggerUploadText { image?: string, normal?: string, fileInput?: string, reupload?: string, continueUpload?: string, delete?: string }`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N +triggerUploadText | Object | - | Typescript: `UploadTriggerUploadText` `interface UploadTriggerUploadText { image?: string, normal?: string, fileInput?: string, reupload?: string, continueUpload?: string, delete?: string }`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N ### UploadConfigDragger diff --git a/packages/components/config-provider/config-provider.md b/packages/components/config-provider/config-provider.md index 0d41645bca..dc0a8ed9e4 100644 --- a/packages/components/config-provider/config-provider.md +++ b/packages/components/config-provider/config-provider.md @@ -67,7 +67,7 @@ globalConfig | Object | - | 全局配置。TS 类型:`GlobalConfigProvider` | alert | Object | - | 警告全局配置。TS 类型:`AlertConfig` | N anchor | Object | - | 锚点全局配置。TS 类型:`AnchorConfig` | N animation | Object | - | 动画效果控制,`ripple` 指波纹动画, `expand` 指展开动画,`fade` 指渐变动画。默认为 `{ include: ['ripple','expand','fade'], exclude: [] }`。TS 类型:`Partial>>` `type AnimationType = 'ripple' \| 'expand' \| 'fade'`。[详细类型定义](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N -attach | String / Object / Function | - | TS 类型:`AttachNode \| { imageViewer?: AttachNode; popup?: AttachNode; dialog?: AttachNode; drawer?: AttachNode; }`。[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +attach | String / Object / Function | - | 浮层挂载节点,可统一设置或按 imageViewer、popup、dialog、drawer 分别设置。组件的 attach 属性优先于全局配置;未配置时保持各组件原有的默认挂载行为。TS 类型:`AttachNode \| { imageViewer?: AttachNode; popup?: AttachNode; dialog?: AttachNode; drawer?: AttachNode; }`。[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N autoComplete | Object | - | 自动填充组件全局配置。TS 类型:`AutoCompleteConfig` | N calendar | Object | - | 日历组件全局配置。TS 类型:`CalendarConfig` | N cascader | Object | - | 级联选择器全局配置。TS 类型:`CascaderConfig` | N @@ -96,6 +96,7 @@ select | Object | - | 选择器组件全局配置。TS 类型:`SelectConfig` | steps | Object | - | 步骤条组件全局配置。TS 类型:`StepsConfig` | N table | Object | - | 表格组件全局配置。TS 类型:`TableConfig` | N tag | Object | - | 标签全局配置。TS 类型:`TagConfig` | N +textarea | Object | - | 多行文本框组件全局配置。TS 类型:`TextareaConfig` | N timePicker | Object | - | 时间选择器全局配置。TS 类型:`TimePickerConfig` | N transfer | Object | - | 穿梭框全局配置。TS 类型:`TransferConfig` | N tree | Object | - | 树组件全局配置。TS 类型:`TreeConfig` | N @@ -177,7 +178,6 @@ placeholder | Object | - | 占位符文本提示,默认值:`{ date: '请选 preDecade | String | - | 语言配置,“上个十年” 描述文本 | N preMonth | String | - | 语言配置,“上个月” 描述文本 | N preYear | String | - | 语言配置,“上一年” 描述文本 | N -presets | Object | - | 【暂不支持,讨论确认中】预设快捷日期选择,示例:`{ '元旦': '2021-01-01', '昨天': dayjs().subtract(1, 'day').format('YYYY-MM-DD'), '特定日期': () => ['2021-02-01'] }`。TS 类型:`ConfigPresetDate` `interface ConfigPresetDate { [name: string]: DateConfigValue \| (() => DateConfigValue) }` `type DateConfigValue = string \| Date \| Array`。[详细类型定义](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N quarters | Array | - | 季度文本描述,默认值:['1 季度', '2 季度', '3 季度', '4 季度']。TS 类型:`string[]` | N rangeSeparator | String | - | 语言配置,“ 至 ” 范围分隔符描述文本,示例:' ~ ' | N selectDate | String | - | 语言配置,“选择日期” 描述文本 | N @@ -369,6 +369,13 @@ treeExpandAndFoldIcon | Function | undefined | 树形结构,展开和折叠图 -- | -- | -- | -- | -- closeIcon | Function | - | 关闭图标,【注意】使用渲染函数输出图标组件。TS 类型:`TNode`。[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +### TextareaConfig + +名称 | 类型 | 默认值 | 描述 | 必传 +-- | -- | -- | -- | -- +clearText | String | - | 语言配置,清空按钮文案 | N +clearTrigger | String | focus | 清空按钮触发方式,仅在文本框有值时有效。可选项:always/focus | N + ### TimePickerConfig 名称 | 类型 | 默认值 | 描述 | 必传 @@ -419,7 +426,7 @@ dragger | Object | - | 语言配置,拖拽相关。示例:{ dragDropText: ' file | Object | - | 语言配置,文件信息相关。示例:{ fileNameText: '文件名', fileSizeText: '文件尺寸', fileStatusText: '状态', fileOperationText: '操作', fileOperationDateText: '上传日期' }。TS 类型:`UploadConfigFileList` | N progress | Object | - | 语言配置,上传进度相关。示例:{ uploadText: '上传中', waitingText: '待上传', 'failText': '上传失败', successText: '上传成功' }。TS 类型:`UploadConfigProgress` | N sizeLimitMessage | String | - | 语言配置,文件大小超出限制时提醒文本。示例:`'文件大小不能超过 {sizeLimit}'` | N -triggerUploadText | Object | - | 语言配置,上传功能触发文案。示例:{ image: '点击上传图片', normal: '点击上传', fileInput: '选择文件', reupload: '重新上传', delete: '删除', continueUpload?: '继续选择' }。TS 类型:`UploadTriggerUploadText` `interface UploadTriggerUploadText { image?: string, normal?: string, fileInput?: string, reupload?: string, continueUpload?: string, delete?: string }`。[详细类型定义](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N +triggerUploadText | Object | - | 语言配置,上传功能触发文案。示例:{ image: '点击上传图片', normal: '点击上传', fileInput: '选择文件', reupload: '重新上传', delete: '删除', continueUpload?: '继续选择' }。TS 类型:`UploadTriggerUploadText` `interface UploadTriggerUploadText { image?: string, normal?: string, fileInput?: string, reupload?: string, continueUpload?: string, delete?: string }`。[详细类型定义](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N ### UploadConfigDragger diff --git a/packages/components/config-provider/type.ts b/packages/components/config-provider/type.ts index 4227f35ed9..e2fd0bcfaf 100644 --- a/packages/components/config-provider/type.ts +++ b/packages/components/config-provider/type.ts @@ -4,13 +4,13 @@ * 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC * */ -import { GlobalIconConfig } from 'tdesign-icons-react'; -import { CalendarController } from '../calendar'; -import { ButtonProps } from '../button'; -import { FormErrorMessage } from '../form'; -import { ImageProps } from '../image'; -import { LoadingProps } from '../loading'; -import { MessageOptions } from '../message'; +import type { GlobalIconConfig } from 'tdesign-icons-react'; +import type { CalendarController } from '../calendar'; +import type { ButtonProps } from '../button'; +import type { FormErrorMessage } from '../form'; +import type { ImageProps } from '../image'; +import type { LoadingProps } from '../loading'; +import type { MessageOptions } from '../message'; import type { TNode, TElement, SizeEnum, AttachNode } from '../common'; export interface TdConfigProviderProps { @@ -34,7 +34,7 @@ export interface GlobalConfigProvider { */ animation?: Partial>>; /** - * null + * 浮层挂载节点,可统一设置或按 imageViewer、popup、dialog、drawer 分别设置。组件的 attach 属性优先于全局配置;未配置时保持各组件原有的默认挂载行为 */ attach?: AttachNode | { imageViewer?: AttachNode; popup?: AttachNode; dialog?: AttachNode; drawer?: AttachNode }; /** @@ -151,6 +151,10 @@ export interface GlobalConfigProvider { * 标签全局配置 */ tag?: TagConfig; + /** + * 多行文本框组件全局配置 + */ + textarea?: TextareaConfig; /** * 时间选择器全局配置 */ @@ -392,10 +396,6 @@ export interface DatePickerConfig { * @default '' */ preYear?: string; - /** - * 【暂不支持,讨论确认中】预设快捷日期选择,示例:`{ '元旦': '2021-01-01', '昨天': dayjs().subtract(1, 'day').format('YYYY-MM-DD'), '特定日期': () => ['2021-02-01'] }` - */ - presets?: ConfigPresetDate; /** * 季度文本描述,默认值:['1 季度', '2 季度', '3 季度', '4 季度'] */ @@ -848,6 +848,19 @@ export interface TagConfig { closeIcon?: TNode; } +export interface TextareaConfig { + /** + * 语言配置,清空按钮文案 + * @default '' + */ + clearText?: string; + /** + * 清空按钮触发方式,仅在文本框有值时有效 + * @default focus + */ + clearTrigger?: 'always' | 'focus'; +} + export interface TimePickerConfig { /** * 语言配置,“上午”描述文本 diff --git a/packages/components/input/useLengthLimit.ts b/packages/components/hooks/useLengthLimit.ts similarity index 78% rename from packages/components/input/useLengthLimit.ts rename to packages/components/hooks/useLengthLimit.ts index c973f097da..c3fb30d1d0 100644 --- a/packages/components/input/useLengthLimit.ts +++ b/packages/components/hooks/useLengthLimit.ts @@ -2,21 +2,22 @@ import { useEffect, useMemo } from 'react'; import log from '@tdesign/common-js/log/index'; import { getCharacterLength, getUnicodeLength, limitUnicodeMaxLength } from '@tdesign/common-js/utils/helper'; -import type { TdInputProps } from './type'; - export interface UseLengthLimitParams { value: string; - maxlength: number; - maxcharacter: number; + maxlength?: number; + maxcharacter?: number; allowInputOverMax: boolean; - status: TdInputProps['status']; - onValidate: TdInputProps['onValidate']; + status?: 'default' | 'success' | 'warning' | 'error'; + onValidate?: (context: { error?: 'exceed-maximum' | 'below-minimum' }) => void; } export default function useLengthLimit(params: UseLengthLimitParams) { + const maxlength = params.maxlength ?? 0; + const maxcharacter = params.maxcharacter ?? 0; + const { allowInputOverMax, value, status, onValidate } = params; + // 文本超出数量限制时,是否允许继续输入 const getValueByLimitNumber = (inputValue: string) => { - const { allowInputOverMax, maxlength, maxcharacter } = params; if (!(maxlength || maxcharacter) || allowInputOverMax || !inputValue) return inputValue; if (maxlength) { // input value could be unicode 😊 @@ -31,7 +32,6 @@ export default function useLengthLimit(params: UseLengthLimitParams) { }; const limitNumber = useMemo(() => { - const { maxlength, maxcharacter, value } = params; if (typeof value === 'number') return String(value); if (maxlength && maxcharacter) { log.warn('Input', 'Pick one of maxlength and maxcharacter please.'); @@ -44,8 +44,7 @@ export default function useLengthLimit(params: UseLengthLimitParams) { return `${getCharacterLength(value || '')}/${maxcharacter}`; } return ''; - // eslint-disable-next-line - }, [params.maxcharacter, params.maxlength, params.value]); + }, [maxcharacter, maxlength, value]); const innerStatus = useMemo(() => { if (limitNumber) { @@ -55,10 +54,10 @@ export default function useLengthLimit(params: UseLengthLimitParams) { return ''; }, [limitNumber]); - const tStatus = useMemo(() => params.status || innerStatus, [params.status, innerStatus]); + const tStatus = useMemo(() => status || innerStatus, [status, innerStatus]); const onValidateChange = () => { - params.onValidate?.({ + onValidate?.({ error: innerStatus ? 'exceed-maximum' : undefined, }); }; diff --git a/packages/components/input/Input.tsx b/packages/components/input/Input.tsx index b3fd4238f1..0c1d3ff1f8 100644 --- a/packages/components/input/Input.tsx +++ b/packages/components/input/Input.tsx @@ -14,10 +14,10 @@ import useControlled from '../hooks/useControlled'; import useDefaultProps from '../hooks/useDefaultProps'; import useGlobalIcon from '../hooks/useGlobalIcon'; import useLayoutEffect from '../hooks/useLayoutEffect'; +import useLengthLimit from '../hooks/useLengthLimit'; import { useLocaleReceiver } from '../locale/LocalReceiver'; import { inputDefaultProps } from './defaultProps'; import InputGroup from './InputGroup'; -import useLengthLimit from './useLengthLimit'; import type { StyledProps, TElement, TNode } from '../common'; import type { TdInputProps } from './type'; @@ -123,10 +123,10 @@ const Input = forwardRefWithStatics( // inputPreRef 用于预存输入框宽度,应用在 auto width 模式中 const inputPreRef: React.RefObject = useRef(null); const wrapperRef: React.RefObject = useRef(null); + const [isHover, toggleIsHover] = useState(false); const [isFocused, toggleIsFocused] = useState(false); const [renderType, setRenderType] = useState(type); - const [composingValue, setComposingValue] = useState(''); // 组件内部 input 原生控件是否处于 readonly 状态,当整个组件 readonly 时,或者处于不可输入时 diff --git a/packages/components/textarea/Textarea.tsx b/packages/components/textarea/Textarea.tsx index 86f5d33c58..103197b7eb 100644 --- a/packages/components/textarea/Textarea.tsx +++ b/packages/components/textarea/Textarea.tsx @@ -1,7 +1,8 @@ -import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react'; +import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react'; import classNames from 'classnames'; +import { CloseCircleFilledIcon as TdCloseCircleFilledIcon } from 'tdesign-icons-react'; import calcTextareaHeight from '@tdesign/common-js/utils/calcTextareaHeight'; -import { getCharacterLength, getUnicodeLength, limitUnicodeMaxLength } from '@tdesign/common-js/utils/helper'; +import { getUnicodeLength } from '@tdesign/common-js/utils/helper'; import noop from '../_util/noop'; import parseTNode from '../_util/parseTNode'; @@ -9,15 +10,27 @@ import useConfig from '../hooks/useConfig'; import useControlled from '../hooks/useControlled'; import useDefaultProps from '../hooks/useDefaultProps'; import useEventCallback from '../hooks/useEventCallback'; +import useGlobalIcon from '../hooks/useGlobalIcon'; import useIsomorphicLayoutEffect from '../hooks/useLayoutEffect'; +import useLengthLimit from '../hooks/useLengthLimit'; import useResizeObserver from '../hooks/useResizeObserver'; +import { useLocaleReceiver } from '../locale/LocalReceiver'; import { textareaDefaultProps } from './defaultProps'; import type { StyledProps } from '../common'; -import type { TdTextareaProps } from './type'; +import type { TdTextareaProps, TextareaClearable } from './type'; const DEFAULT_TEXTAREA_STYLE = { height: 'auto', minHeight: 'auto' }; -const OMIT_PROPS = ['defaultValue', 'readonly']; +const OMIT_PROPS = ['defaultValue', 'readonly', 'clearable']; + +function resolveClearable(clearable?: boolean | TextareaClearable) { + if (!clearable) return null; + if (clearable === true) return { position: 'top' as const, type: 'icon' as const }; + return { + position: clearable.position ?? 'top', + type: clearable.type ?? 'icon', + }; +} export interface TextareaProps extends @@ -33,6 +46,12 @@ export interface TextareaRefInterface { } const Textarea = forwardRef((originalProps, ref) => { + const { classPrefix } = useConfig(); + const [locale, t] = useLocaleReceiver('textarea'); + const { CloseCircleFilledIcon } = useGlobalIcon({ + CloseCircleFilledIcon: TdCloseCircleFilledIcon, + }); + const props = useDefaultProps(originalProps, textareaDefaultProps); const { count, @@ -50,6 +69,8 @@ const Textarea = forwardRef((originalProps, tips, allowInputOverMax, rows, + clearable, + onValidate, ...otherProps } = props; @@ -58,8 +79,8 @@ const Textarea = forwardRef((originalProps, const [value = '', setValue] = useControlled(props, 'value', props.onChange); + const [isHover, setIsHover] = useState(false); const [isFocused, setIsFocused] = useState(false); - const [isOvermax, setIsOvermax] = useState(false); const [textareaStyle, setTextareaStyle] = useState>(DEFAULT_TEXTAREA_STYLE); const [composingValue, setComposingValue] = useState(''); @@ -68,14 +89,19 @@ const Textarea = forwardRef((originalProps, const textareaWidthRef = useRef(0); const wrapperRef = useRef(null); - const currentLength = useMemo(() => getUnicodeLength(value), [value]); - const characterLength = useMemo(() => { - const characterInfo = getCharacterLength(String(value), allowInputOverMax ? Infinity : maxcharacter); - if (typeof characterInfo === 'object') return characterInfo.length; - return characterInfo; - }, [value, allowInputOverMax, maxcharacter]); + const { limitNumber, getValueByLimitNumber } = useLengthLimit({ + value: String(value ?? ''), + status, + maxlength, + maxcharacter, + allowInputOverMax, + onValidate, + }); - const { classPrefix } = useConfig(); + const clearConfig = resolveClearable(clearable); + const readOnly = Boolean(props.readOnly || props.readonly); + const canClear = Boolean(clearConfig) && String(value ?? '') !== '' && !disabled && !readOnly; + const showClear = canClear && (locale.clearTrigger === 'always' || isHover); const textareaPropsNames = Object.keys(otherProps).filter( (key) => !/^on[A-Z]/.test(key) && !OMIT_PROPS.includes(key), @@ -98,6 +124,7 @@ const Textarea = forwardRef((originalProps, }, {}); const textareaClassNames = classNames(`${classPrefix}-textarea__inner`, className, { + [`${classPrefix}-textarea__inner--clear`]: canClear, [`${classPrefix}-is-${status}`]: status, [`${classPrefix}-is-disabled`]: disabled, [`${classPrefix}-is-focused`]: isFocused, @@ -144,13 +171,7 @@ const Textarea = forwardRef((originalProps, if (composingRef.current) { setComposingValue(val); } else { - if (!allowInputOverMax) { - val = limitUnicodeMaxLength(val, maxlength); - if (maxcharacter && maxcharacter >= 0) { - const stringInfo = getCharacterLength(val, maxcharacter); - val = typeof stringInfo === 'object' && stringInfo.characters; - } - } + val = getValueByLimitNumber(val) ?? val; setComposingValue(val); setValue(val, { e }); } @@ -167,9 +188,21 @@ const Textarea = forwardRef((originalProps, } } - const renderLimitText = (current: number, max: number) => { + const handleClear = useEventCallback((event: React.MouseEvent) => { + event.preventDefault(); + event.stopPropagation(); + if (disabled || readOnly) return; + composingRef.current = false; + setComposingValue(''); + setValue(''); + textareaRef.current?.focus(); + }); + + const renderLimitText = () => { if (count === false) return null; + const [currentText, maxText] = limitNumber.split('/'); + const current = limitNumber ? Number(currentText) : getUnicodeLength(String(value ?? '')); // 不设置 maxLength 或 maxCharacter,也支持渲染自定义节点 if (typeof count === 'function') { return parseTNode(count, { @@ -180,15 +213,12 @@ const Textarea = forwardRef((originalProps, }); } - if (!max) return; + if (!limitNumber) return null; + const isOvermax = allowInputOverMax && Number(currentText) > Number(maxText); return ( - {isOvermax && allowInputOverMax ? ( - {current} - ) : ( - `${current}` - )} - {`/${max}`} + {isOvermax ? {currentText} : currentText} + {`/${maxText}`} ); }; @@ -216,12 +246,6 @@ const Textarea = forwardRef((originalProps, handleAutoFocus(); }, [handleAutoFocus]); - useEffect(() => { - if (allowInputOverMax) { - setIsOvermax(!!(maxlength && currentLength > maxlength) || !!(maxcharacter && characterLength > maxcharacter)); - } - }, [allowInputOverMax, characterLength, currentLength, maxcharacter, maxlength]); - useImperativeHandle(ref, () => ({ currentElement: wrapperRef.current, textareaElement: textareaRef.current, @@ -237,13 +261,38 @@ const Textarea = forwardRef((originalProps, ); - const limitText = renderLimitText( - hasMaxcharacter ? characterLength : currentLength, - hasMaxcharacter ? maxcharacter : maxlength, - ); + const limitText = renderLimitText(); + + const clearNode = + showClear && clearConfig ? ( + event.preventDefault()} + > + {clearConfig.type === 'text' ? ( + + {t(locale.clearText)} + + ) : ( + + )} + + ) : null; return ( -
+
{ + if (!disabled && !readOnly) setIsHover(true); + }} + onMouseLeave={() => setIsHover(false)} + > +
+ + + + + text + + +
+ +
+ + + + +
+ + + +`; + exports[`csr snapshot test > csr test packages/components/textarea/_example/events.tsx 1`] = `
ssr test packages/components/tag-input/_example/the exports[`ssr snapshot test > ssr test packages/components/textarea/_example/base.tsx 1`] = `"
"`; +exports[`ssr snapshot test > ssr test packages/components/textarea/_example/clearable.tsx 1`] = `"
icon
text
"`; + exports[`ssr snapshot test > ssr test packages/components/textarea/_example/events.tsx 1`] = `"
"`; exports[`ssr snapshot test > ssr test packages/components/textarea/_example/maxlength.tsx 1`] = `"
这里可以放一些提示文字
0/20
0/20
0/20
0/20
0/20
"`; diff --git a/test/snap/__snapshots__/ssr.test.jsx.snap b/test/snap/__snapshots__/ssr.test.jsx.snap index 7a79e68be6..e5a611edf5 100644 --- a/test/snap/__snapshots__/ssr.test.jsx.snap +++ b/test/snap/__snapshots__/ssr.test.jsx.snap @@ -1118,6 +1118,8 @@ exports[`ssr snapshot test > ssr test packages/components/tag-input/_example/the exports[`ssr snapshot test > ssr test packages/components/textarea/_example/base.tsx 1`] = `"
"`; +exports[`ssr snapshot test > ssr test packages/components/textarea/_example/clearable.tsx 1`] = `"
icon
text
"`; + exports[`ssr snapshot test > ssr test packages/components/textarea/_example/events.tsx 1`] = `"
"`; exports[`ssr snapshot test > ssr test packages/components/textarea/_example/maxlength.tsx 1`] = `"
这里可以放一些提示文字
0/20
0/20
0/20
0/20
0/20
"`;