Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 70 additions & 63 deletions packages/components/config-provider/config-provider.en-US.md

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions packages/components/config-provider/config-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<'include'\|'exclude', Array<AnimationType>>>` `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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<DateConfigValue>`。[详细类型定义](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
Expand Down Expand Up @@ -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

名称 | 类型 | 默认值 | 描述 | 必传
Expand Down Expand Up @@ -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

Expand Down
37 changes: 25 additions & 12 deletions packages/components/config-provider/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -34,7 +34,7 @@ export interface GlobalConfigProvider {
*/
animation?: Partial<Record<'include' | 'exclude', Array<AnimationType>>>;
/**
* null
* 浮层挂载节点,可统一设置或按 imageViewer、popup、dialog、drawer 分别设置。组件的 attach 属性优先于全局配置;未配置时保持各组件原有的默认挂载行为
*/
attach?: AttachNode | { imageViewer?: AttachNode; popup?: AttachNode; dialog?: AttachNode; drawer?: AttachNode };
/**
Expand Down Expand Up @@ -151,6 +151,10 @@ export interface GlobalConfigProvider {
* 标签全局配置
*/
tag?: TagConfig;
/**
* 多行文本框组件全局配置
*/
textarea?: TextareaConfig;
/**
* 时间选择器全局配置
*/
Expand Down Expand Up @@ -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 季度']
*/
Expand Down Expand Up @@ -848,6 +848,19 @@ export interface TagConfig {
closeIcon?: TNode;
}

export interface TextareaConfig {
/**
* 语言配置,清空按钮文案
* @default ''
*/
clearText?: string;
/**
* 清空按钮触发方式,仅在文本框有值时有效
* @default focus
*/
clearTrigger?: 'always' | 'focus';
}

export interface TimePickerConfig {
/**
* 语言配置,“上午”描述文本
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 😊
Expand All @@ -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.');
Expand All @@ -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) {
Expand All @@ -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,
});
};
Expand Down
4 changes: 2 additions & 2 deletions packages/components/input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -123,10 +123,10 @@ const Input = forwardRefWithStatics(
// inputPreRef 用于预存输入框宽度,应用在 auto width 模式中
const inputPreRef: React.RefObject<HTMLInputElement> = useRef(null);
const wrapperRef: React.RefObject<HTMLDivElement> = useRef(null);

const [isHover, toggleIsHover] = useState(false);
const [isFocused, toggleIsFocused] = useState(false);
const [renderType, setRenderType] = useState(type);

const [composingValue, setComposingValue] = useState<string>('');

// 组件内部 input 原生控件是否处于 readonly 状态,当整个组件 readonly 时,或者处于不可输入时
Expand Down
Loading
Loading