Skip to content

Commit

Permalink
fix: πŸ› πŸ› replace defaultProps with useDefaultProps
Browse files Browse the repository at this point in the history
πŸ› replace defaultProps with useDefaultProps
  • Loading branch information
li-jia-nan committed Jul 20, 2023
1 parent 405f09e commit af80aaa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/popconfirm/Popconfirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ import { useLocaleReceiver } from '../locale/LocalReceiver';
import { TdPopconfirmProps, PopconfirmVisibleChangeContext } from './type';
import Popcontent from './Popcontent';
import { popconfirmDefaultProps } from './defaultProps';
import useDefaultProps from '../hooks/useDefaultProps';

export type PopconfirmProps = TdPopconfirmProps;

const Popconfirm = forwardRef((props: PopconfirmProps, ref: React.RefObject<PopupRef>) => {
const Popconfirm = forwardRef<PopupRef, TdPopconfirmProps>((originalProps, ref) => {
const { classPrefix } = useConfig();
const [local, t] = useLocaleReceiver('popconfirm');

const cancelContent = typeof local.cancel === 'string' ? local.cancel : local.cancel.content;
const confirmContent = typeof local.confirm === 'string' ? local.confirm : local.confirm.content;

const props = useDefaultProps<TdPopconfirmProps>(originalProps, popconfirmDefaultProps);

const { cancelBtn = t(cancelContent), confirmBtn = t(confirmContent) } = props;
const [visible, setVisible] = useControlled(props, 'visible', props.onVisibleChange);

Expand All @@ -41,6 +45,5 @@ const Popconfirm = forwardRef((props: PopconfirmProps, ref: React.RefObject<Popu
});

Popconfirm.displayName = 'Popconfirm';
Popconfirm.defaultProps = popconfirmDefaultProps;

export default Popconfirm;
6 changes: 5 additions & 1 deletion src/popconfirm/Popcontent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import useGlobalIcon from '../hooks/useGlobalIcon';
import type { PopconfirmProps } from './Popconfirm';
import type { PopconfirmVisibleChangeContext } from './type';

const Popcontent = (props: PopconfirmProps & { onClose?: (context: PopconfirmVisibleChangeContext) => any }) => {
interface PopcontentProps {
onClose?: (context: PopconfirmVisibleChangeContext) => any;
}

const Popcontent: React.FC<PopcontentProps & PopconfirmProps> = (props) => {
const { content, cancelBtn, confirmBtn, icon, theme, onCancel = noop, onConfirm = noop, onClose = noop } = props;

const { classPrefix } = useConfig();
Expand Down

0 comments on commit af80aaa

Please sign in to comment.