Skip to content

Commit

Permalink
feat: 调整useConfig 路径 & 新增 useGlobalIcon hook
Browse files Browse the repository at this point in the history
  • Loading branch information
honkinglin committed Jul 28, 2022
1 parent 51534d5 commit bf40856
Show file tree
Hide file tree
Showing 138 changed files with 160 additions and 140 deletions.
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "^13.5.0",
"@types/classnames": "^2.3.1",
"@types/estree": "0.0.50",
"@types/hoist-non-react-statics": "^3.3.1",
"@types/jest": "^27.0.3",
Expand All @@ -133,10 +132,7 @@
"@types/react-transition-group": "^4.4.2",
"@types/rimraf": "^3.0.2",
"@types/testing-library__jest-dom": "^5.14.2",
"@types/validator": "^13.1.3",
"@types/react-is": "^17.0.3",
"@types/sortablejs": "^1.10.7",
"@types/tinycolor2": "^1.4.3",
"@typescript-eslint/eslint-plugin": "^5.13.0",
"@typescript-eslint/parser": "^5.13.0",
"@vitejs/plugin-react": "^1.3.2",
Expand Down Expand Up @@ -208,6 +204,9 @@
"dependencies": {
"@babel/runtime": "~7.17.2",
"@popperjs/core": "~2.11.2",
"@types/sortablejs": "^1.10.7",
"@types/tinycolor2": "^1.4.3",
"@types/validator": "^13.1.3",
"classnames": "~2.3.1",
"dayjs": "~1.11.4",
"hoist-non-react-statics": "~3.3.2",
Expand Down
2 changes: 1 addition & 1 deletion src/_util/useAnimation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback } from 'react';
import useConfig from './useConfig';
import useConfig from '../hooks/useConfig';
import { EAnimationType } from '../config-provider/ConfigContext';

export default function useAnimation() {
Expand Down
2 changes: 1 addition & 1 deletion src/_util/useClickOutside.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MutableRefObject, useEffect } from 'react';
import useConfig from './useConfig';
import useConfig from '../hooks/useConfig';

export default function useClickOutside<T extends HTMLElement>(
refs: MutableRefObject<T>[],
Expand Down
2 changes: 1 addition & 1 deletion src/_util/useCommonClassName.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo } from 'react';
import useConfig from './useConfig';
import useConfig from '../hooks/useConfig';

export default function useCommonClassName() {
const { classPrefix } = useConfig();
Expand Down
2 changes: 1 addition & 1 deletion src/_util/useRipple.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useCallback, RefObject, useMemo } from 'react';
import useConfig from './useConfig';
import useConfig from '../hooks/useConfig';
import useAnimation from './useAnimation';
import setStyle from './setStyle';
import { canUseDocument } from './dom';
Expand Down
2 changes: 1 addition & 1 deletion src/affix/Affix.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import isFunction from 'lodash/isFunction';
import { StyledProps, ScrollContainerElement } from '../common';
import { TdAffixProps } from './type';
import { getScrollContainer } from '../_util/dom';
import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';
import { affixDefaultProps } from './defaultProps';

export interface AffixProps extends TdAffixProps, StyledProps {
Expand Down
2 changes: 1 addition & 1 deletion src/alert/Alert.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { forwardRef } from 'react';
import classNames from 'classnames';
import { InfoCircleFilledIcon, CloseIcon, CheckCircleFilledIcon, ErrorCircleFilledIcon } from 'tdesign-icons-react';
import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';
import { useLocaleReceiver } from '../locale/LocalReceiver';
import { TdAlertProps } from './type';
import { StyledProps } from '../common';
Expand Down
2 changes: 1 addition & 1 deletion src/anchor/Anchor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import isEmpty from 'lodash/isEmpty';
import isFunction from 'lodash/isFunction';
import { StyledProps } from '../common';
import { TdAnchorProps } from './type';
import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';
import forwardRefWithStatics from '../_util/forwardRefWithStatics';
import { canUseDocument, getScrollContainer } from '../_util/dom';
import Affix from '../affix';
Expand Down
2 changes: 1 addition & 1 deletion src/anchor/AnchorItem.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { FunctionComponent, useContext, useEffect } from 'react';
import classNames from 'classnames';
import { TdAnchorItemProps } from './type';
import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';
import { StyledProps } from '../common';
import { AnchorContext } from './AnchorContext';
import { anchorItemDefaultProps } from './defaultProps';
Expand Down
2 changes: 1 addition & 1 deletion src/anchor/AnchorTarget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import classNames from 'classnames';
import { FileCopyIcon } from 'tdesign-icons-react';
import Popup from '../popup';
import { MessagePlugin } from '../message';
import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';
import copyText from '../_util/copyText';

import { TdAnchorTargetProps } from './type';
Expand Down
2 changes: 1 addition & 1 deletion src/avatar/AvararGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import classNames from 'classnames';
import Avatar from './Avatar';
import Popup from '../popup/Popup';
import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';
import { AvatarContextProvider } from './AvatarContext';
import { TdAvatarGroupProps } from './type';
import { StyledProps } from '../common';
Expand Down
2 changes: 1 addition & 1 deletion src/avatar/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useRef, useState, useEffect, useContext, Ref } from 'react';
import useResizeObserver from 'use-resize-observer';
import classNames from 'classnames';
import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';
import forwardRefWithStatics from '../_util/forwardRefWithStatics';
import useCommonClassName from '../_util/useCommonClassName';
import composeRefs from '../_util/composeRefs';
Expand Down
2 changes: 1 addition & 1 deletion src/badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { forwardRef } from 'react';
import classNames from 'classnames';
import { StyledProps } from '../common';
import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';
import { TdBadgeProps } from './type';
import { badgeDefaultProps } from './defaultProps';

Expand Down
2 changes: 1 addition & 1 deletion src/breadcrumb/Breadcrumb.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import classNames from 'classnames';
import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';
import forwardRefWithStatics from '../_util/forwardRefWithStatics';
import BreadcrumbItem from './BreadcrumbItem';
import { BreadcrumbProps } from './BreadcrumbProps';
Expand Down
2 changes: 1 addition & 1 deletion src/breadcrumb/BreadcrumbItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { forwardRef, useContext, useMemo } from 'react';
import classNames from 'classnames';

import { ChevronRightIcon } from 'tdesign-icons-react';
import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';
import useCommonClassName from '../_util/useCommonClassName';

import { BreadcrumbItemProps } from './BreadcrumbProps';
Expand Down
2 changes: 1 addition & 1 deletion src/button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { forwardRef, useRef, useMemo } from 'react';
import classNames from 'classnames';
import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';
import useRipple from '../_util/useRipple';
import Loading from '../loading';
import { TdButtonProps } from './type';
Expand Down
2 changes: 1 addition & 1 deletion src/calendar/CalendarCellComp.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { MouseEvent } from 'react';
import { CalendarCell, TdCalendarProps } from './type';
import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';
import usePrefixClass from './hooks/usePrefixClass';
import { useLocaleReceiver } from '../locale/LocalReceiver';
import { blockName } from './_util';
Expand Down
2 changes: 1 addition & 1 deletion src/calendar/hooks/usePrefixClass.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback } from 'react';
import useConfig from '../../_util/useConfig';
import useConfig from '../../hooks/useConfig';

export default function usePrefixClass() {
const { classPrefix } = useConfig();
Expand Down
2 changes: 1 addition & 1 deletion src/card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TdCardProps } from './type';
import Loading from '../loading';
import { StyledProps } from '../common';

import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';
import useCommonClassName from '../_util/useCommonClassName';
import { cardDefaultProps } from './defaultProps';

Expand Down
2 changes: 1 addition & 1 deletion src/cascader/Cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Panel from './components/Panel';
import SelectInput from '../select-input';
import FakeArrow from '../common/FakeArrow';

import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';
import useCommonClassName from '../_util/useCommonClassName';
import { useLocaleReceiver } from '../locale/LocalReceiver';

Expand Down
2 changes: 1 addition & 1 deletion src/cascader/components/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ChevronRightIcon } from 'tdesign-icons-react';
import TLoading from '../../loading';
import Checkbox from '../../checkbox/Checkbox';

import useConfig from '../../_util/useConfig';
import useConfig from '../../hooks/useConfig';
import useCommonClassName from '../../_util/useCommonClassName';
import useRipple from '../../_util/useRipple';

Expand Down
2 changes: 1 addition & 1 deletion src/cascader/components/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useMemo } from 'react';
import classNames from 'classnames';
import Item from './Item';

import useConfig from '../../_util/useConfig';
import useConfig from '../../hooks/useConfig';
import { useLocaleReceiver } from '../../locale/LocalReceiver';
import { getPanels } from '../core/helper';
import { expendClickEffect, valueChangeEffect } from '../core/effect';
Expand Down
6 changes: 3 additions & 3 deletions src/checkbox/CheckboxGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { ReactElement, useEffect, useMemo, useState } from 'react';
import classNames from 'classnames';
import isNumber from 'lodash/isNumber';
import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';
import { CheckContext, CheckContextValue } from '../common/Check';
import { CheckboxOption, CheckboxOptionObj, TdCheckboxGroupProps, TdCheckboxProps } from './type';
import { StyledProps } from '../common';
Expand Down Expand Up @@ -151,9 +151,9 @@ const CheckboxGroup = (props: CheckboxGroupProps) => {
const vs = v as CheckboxOptionObj;
// CheckAll 的 checkBox 不存在 value,故用 checkAll_index 来保证尽量不和用户的 value 冲突.
return vs.checkAll ? (
<Checkbox {...v} key={`checkAll_${index}`} indeterminate={indeterminate} />
<Checkbox {...vs} key={`checkAll_${index}`} indeterminate={indeterminate} />
) : (
<Checkbox {...v} key={index} disabled={vs.disabled || disabled} />
<Checkbox {...vs} key={index} disabled={vs.disabled || disabled} />
);
}
default:
Expand Down
2 changes: 1 addition & 1 deletion src/collapse/Collapse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import classnames from 'classnames';
import { TdCollapseProps, CollapsePanelValue, CollapseValue } from './type';
import { StyledProps } from '../common';
import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';
import forwardRefWithStatics from '../_util/forwardRefWithStatics';
import useControlled from '../hooks/useControlled';
import CollapsePanel from './CollapsePanel';
Expand Down
2 changes: 1 addition & 1 deletion src/collapse/CollapsePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import classnames from 'classnames';
import { CSSTransition } from 'react-transition-group';
import { useCollapseContext } from './CollapseContext';
import FakeArrow from '../common/FakeArrow';
import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';
import { TdCollapsePanelProps } from './type';
import { StyledProps } from '../common';
import { collapsePanelDefaultProps } from './defaultProps';
Expand Down
2 changes: 1 addition & 1 deletion src/color-picker/hooks/useClassname.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import useConfig from '../../_util/useConfig';
import useConfig from '../../hooks/useConfig';

const useClassname = () => {
const { classPrefix } = useConfig();
Expand Down
2 changes: 1 addition & 1 deletion src/comment/Comment.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { forwardRef } from 'react';
import classNames from 'classnames';
import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';
import { StyledProps } from '../common';
import { TdCommentProps } from './type';
import { commentDefaultProps } from './defaultProps';
Expand Down
2 changes: 1 addition & 1 deletion src/common/Check.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import classNames from 'classnames';
import isBoolean from 'lodash/isBoolean';
import { omit } from '../_util/helper';
import { StyledProps } from '../common';
import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';
import useControlled from '../hooks/useControlled';
import { TdCheckboxProps } from '../checkbox/type';

Expand Down
2 changes: 1 addition & 1 deletion src/common/FakeArrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import classNames from 'classnames';
import { ClassName } from '../common';

import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';

// 翻转箭头统一组件
function FakeArrow(props: {
Expand Down
2 changes: 1 addition & 1 deletion src/common/Portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { forwardRef, useEffect, useMemo, useImperativeHandle } from 'reac
import { createPortal } from 'react-dom';
import { AttachNode, AttachNodeReturnValue } from '../common';
import { canUseDocument } from '../_util/dom';
import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';

export interface PortalProps {
/**
Expand Down
8 changes: 8 additions & 0 deletions src/config-provider/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import { FormErrorMessage } from '../form';
import { TNode, TElement } from '../common';

export interface GlobalConfigProvider {
/**
* icon 全局配置,用来覆盖内置 tdesign-icons
*/
icon?: IconConfig;
/**
* 警告全局配置
*/
Expand Down Expand Up @@ -800,3 +804,7 @@ export interface UploadTriggerUploadText {
continueUpload: string;
delete?: string;
}

export interface IconConfig {
[name: string]: any;
}
2 changes: 1 addition & 1 deletion src/date-picker/DatePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { forwardRef, useEffect } from 'react';
import classNames from 'classnames';
import dayjs from 'dayjs';
import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';
import { StyledProps } from '../common';
import { TdDatePickerProps } from './type';
import SelectInput from '../select-input';
Expand Down
2 changes: 1 addition & 1 deletion src/date-picker/DateRangePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { forwardRef, useEffect, useState } from 'react';
import classNames from 'classnames';
import dayjs from 'dayjs';
import useConfig from '../_util/useConfig';
import useConfig from '../hooks/useConfig';
import { StyledProps } from '../common';
import { TdDateRangePickerProps } from './type';
import { RangeInputPopup } from '../range-input';
Expand Down
2 changes: 1 addition & 1 deletion src/date-picker/base/Cell.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import classNames from 'classnames';
import useConfig from '../../_util/useConfig';
import useConfig from '../../hooks/useConfig';
import { extractTimeObj } from '../../_common/js/date-picker/utils';

export interface DatePickerCellProps {
Expand Down
2 changes: 1 addition & 1 deletion src/date-picker/base/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import classNames from 'classnames';
import { useLocaleReceiver } from '../../locale/LocalReceiver';
import Button from '../../button';
import useConfig from '../../_util/useConfig';
import useConfig from '../../hooks/useConfig';
import { TdDatePickerProps, TdDateRangePickerProps, DateValue } from '../type';

interface DatePickerFooterProps extends Pick<TdDatePickerProps, 'enableTimePicker' | 'presetsPlacement'> {
Expand Down
2 changes: 1 addition & 1 deletion src/date-picker/base/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useMemo } from 'react';
import { useLocaleReceiver } from '../../locale/LocalReceiver';
import useConfig from '../../_util/useConfig';
import useConfig from '../../hooks/useConfig';
import Select from '../../select';
import { TdDatePickerProps } from '../type';
import Jumper, { TdJumperProps } from '../../jumper';
Expand Down
2 changes: 1 addition & 1 deletion src/date-picker/base/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import classNames from 'classnames';
import { useLocaleReceiver } from '../../locale/LocalReceiver';
import useConfig from '../../_util/useConfig';
import useConfig from '../../hooks/useConfig';
import DatePickerCell from './Cell';
import { TdDatePickerProps } from '../type';
import { SinglePanelProps } from '../panel/SinglePanel';
Expand Down
2 changes: 1 addition & 1 deletion src/date-picker/hooks/useRange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState, useEffect, useRef } from 'react';
import { CalendarIcon } from 'tdesign-icons-react';
import dayjs from 'dayjs';
import classNames from 'classnames';
import useConfig from '../../_util/useConfig';
import useConfig from '../../hooks/useConfig';
import { RangeInputRefInterface } from '../../range-input';
import { TdDateRangePickerProps, DateValue } from '../type';
import { isValidDate, formatDate, getDefaultFormat } from './useFormat';
Expand Down
2 changes: 1 addition & 1 deletion src/date-picker/hooks/useSingle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState, useEffect, useRef } from 'react';
import { CalendarIcon } from 'tdesign-icons-react';
import dayjs from 'dayjs';
import classNames from 'classnames';
import useConfig from '../../_util/useConfig';
import useConfig from '../../hooks/useConfig';
import { TdDatePickerProps } from '../type';
import { isValidDate, formatDate, formatTime, getDefaultFormat } from './useFormat';
import useSingleValue from './useSingleValue';
Expand Down
2 changes: 1 addition & 1 deletion src/date-picker/panel/PanelContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import DateTable from '../base/Table';
import { TimePickerPanel } from '../../time-picker';
import type { SinglePanelProps } from './SinglePanel';
import type { RangePanelProps } from './RangePanel';
import useConfig from '../../_util/useConfig';
import useConfig from '../../hooks/useConfig';
import { getDefaultFormat } from '../hooks/useFormat';

export interface PanelContentProps {
Expand Down
2 changes: 1 addition & 1 deletion src/date-picker/panel/RangePanel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { forwardRef } from 'react';
import classNames from 'classnames';
import useConfig from '../../_util/useConfig';
import useConfig from '../../hooks/useConfig';
import { StyledProps } from '../../common';
import PanelContent from './PanelContent';
import ExtraContent from './ExtraContent';
Expand Down
2 changes: 1 addition & 1 deletion src/date-picker/panel/SinglePanel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { forwardRef } from 'react';
import classNames from 'classnames';
import useConfig from '../../_util/useConfig';
import useConfig from '../../hooks/useConfig';
import { StyledProps } from '../../common';
import PanelContent from './PanelContent';
import ExtraContent from './ExtraContent';
Expand Down
Loading

0 comments on commit bf40856

Please sign in to comment.