Skip to content

Commit da1c30e

Browse files
author
WB01676250
committed
fix: typography
1 parent 0363e41 commit da1c30e

File tree

4 files changed

+95
-43
lines changed

4 files changed

+95
-43
lines changed

components/typography/Base/CopyBtn.tsx

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface CopyBtnProps extends Omit<CopyConfig, 'onCopy'> {
1616
onCopy: React.MouseEventHandler<HTMLButtonElement>;
1717
iconOnly: boolean;
1818
loading: boolean;
19+
disabled?: boolean;
1920
}
2021

2122
const CopyBtn: React.FC<CopyBtnProps> = ({
@@ -28,6 +29,7 @@ const CopyBtn: React.FC<CopyBtnProps> = ({
2829
tabIndex,
2930
onCopy,
3031
loading: btnLoading,
32+
disabled,
3133
}) => {
3234
const tooltipNodes = toList(tooltips);
3335
const iconNodes = toList(icon);
@@ -36,24 +38,30 @@ const CopyBtn: React.FC<CopyBtnProps> = ({
3638
const copyTitle = getNode(tooltipNodes[copied ? 1 : 0], systemStr);
3739
const ariaLabel = typeof copyTitle === 'string' ? copyTitle : systemStr;
3840

39-
return (
40-
<Tooltip title={copyTitle}>
41-
<button
42-
type="button"
43-
className={classNames(`${prefixCls}-copy`, {
44-
[`${prefixCls}-copy-success`]: copied,
45-
[`${prefixCls}-copy-icon-only`]: iconOnly,
46-
})}
47-
onClick={onCopy}
48-
aria-label={ariaLabel}
49-
tabIndex={tabIndex}
50-
>
51-
{copied
52-
? getNode(iconNodes[1], <CheckOutlined />, true)
53-
: getNode(iconNodes[0], btnLoading ? <LoadingOutlined /> : <CopyOutlined />, true)}
54-
</button>
55-
</Tooltip>
41+
const copyBtn = (
42+
<button
43+
type="button"
44+
className={classNames(`${prefixCls}-copy`, {
45+
[`${prefixCls}-copy-success`]: copied,
46+
[`${prefixCls}-copy-icon-only`]: iconOnly,
47+
[`${prefixCls}-copy-disabled`]: disabled,
48+
})}
49+
onClick={onCopy}
50+
aria-label={ariaLabel}
51+
tabIndex={tabIndex}
52+
disabled={disabled}
53+
>
54+
{copied
55+
? getNode(iconNodes[1], <CheckOutlined />, true)
56+
: getNode(iconNodes[0], btnLoading ? <LoadingOutlined /> : <CopyOutlined />, true)}
57+
</button>
5658
);
59+
60+
if (disabled) {
61+
return copyBtn;
62+
}
63+
64+
return <Tooltip title={copyTitle}>{copyBtn}</Tooltip>;
5765
};
5866

5967
export default CopyBtn;

components/typography/Base/EllipsisTooltip.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,24 @@ export interface EllipsisTooltipProps {
88
enableEllipsis: boolean;
99
isEllipsis?: boolean;
1010
children: React.ReactElement;
11+
disabled?: boolean;
1112
}
1213

1314
const EllipsisTooltip: React.FC<EllipsisTooltipProps> = ({
1415
enableEllipsis,
1516
isEllipsis,
1617
children,
1718
tooltipProps,
19+
disabled,
1820
}) => {
1921
if (!tooltipProps?.title || !enableEllipsis) {
2022
return children;
2123
}
2224

25+
if (disabled) {
26+
return children;
27+
}
28+
2329
return (
2430
<Tooltip open={isEllipsis ? undefined : false} {...tooltipProps}>
2531
{children}

components/typography/Base/index.tsx

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ interface EditConfig {
5252
triggerType?: ('icon' | 'text')[];
5353
enterIcon?: React.ReactNode;
5454
tabIndex?: number;
55+
disabled?: boolean;
5556
}
5657

5758
export interface EllipsisConfig {
@@ -112,13 +113,13 @@ function wrapperDecorations(
112113
const ELLIPSIS_STR = '...';
113114

114115
const DECORATION_PROPS = [
115-
'delete',
116-
'mark',
117-
'code',
118-
'underline',
119-
'strong',
120-
'keyboard',
121-
'italic'
116+
'delete',
117+
'mark',
118+
'code',
119+
'underline',
120+
'strong',
121+
'keyboard',
122+
'italic',
122123
] as const;
123124

124125
const Base = React.forwardRef<HTMLElement, BlockProps>((props, ref) => {
@@ -374,19 +375,30 @@ const Base = React.forwardRef<HTMLElement, BlockProps>((props, ref) => {
374375
const editTitle = toArray(tooltip)[0] || textLocale?.edit;
375376
const ariaLabel = typeof editTitle === 'string' ? editTitle : '';
376377

378+
const editBtn = (
379+
<button
380+
type="button"
381+
ref={editIconRef}
382+
className={classNames(`${prefixCls}-edit`, {
383+
[`${prefixCls}-edit-disabled`]: disabled,
384+
})}
385+
onClick={onEditClick}
386+
aria-label={ariaLabel}
387+
tabIndex={tabIndex}
388+
disabled={disabled}
389+
>
390+
{icon || <EditOutlined role="button" />}
391+
</button>
392+
);
393+
377394
return triggerType.includes('icon') ? (
378-
<Tooltip key="edit" title={tooltip === false ? '' : editTitle}>
379-
<button
380-
type="button"
381-
ref={editIconRef}
382-
className={`${prefixCls}-edit`}
383-
onClick={onEditClick}
384-
aria-label={ariaLabel}
385-
tabIndex={tabIndex}
386-
>
387-
{icon || <EditOutlined role="button" />}
388-
</button>
389-
</Tooltip>
395+
disabled ? (
396+
editBtn
397+
) : (
398+
<Tooltip key="edit" title={tooltip === false ? '' : editTitle}>
399+
{editBtn}
400+
</Tooltip>
401+
)
390402
) : null;
391403
};
392404

@@ -406,6 +418,7 @@ const Base = React.forwardRef<HTMLElement, BlockProps>((props, ref) => {
406418
onCopy={onCopyClick}
407419
loading={copyLoading}
408420
iconOnly={children === null || children === undefined}
421+
disabled={disabled}
409422
/>
410423
);
411424
};
@@ -433,6 +446,7 @@ const Base = React.forwardRef<HTMLElement, BlockProps>((props, ref) => {
433446
tooltipProps={tooltipProps}
434447
enableEllipsis={mergedEnableEllipsis}
435448
isEllipsis={isMergedEllipsis}
449+
disabled={disabled}
436450
>
437451
<Typography
438452
className={classNames(
@@ -466,13 +480,13 @@ const Base = React.forwardRef<HTMLElement, BlockProps>((props, ref) => {
466480
onEllipsis={onJsEllipsis}
467481
expanded={expanded}
468482
miscDeps={[
469-
copied,
470-
expanded,
471-
copyLoading,
472-
enableEdit,
473-
enableCopy,
474-
textLocale,
475-
...DECORATION_PROPS.map(key => props[key as keyof BlockProps])
483+
copied,
484+
expanded,
485+
copyLoading,
486+
enableEdit,
487+
enableCopy,
488+
textLocale,
489+
...DECORATION_PROPS.map((key) => props[key as keyof BlockProps]),
476490
]}
477491
>
478492
{(node, canEllipsis) =>

components/typography/style/mixins.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,30 @@ export const getCopyableStyles: GenerateStyle<TypographyToken, CSSObject> = (tok
229229
[`${token.componentCls}-copy-icon-only`]: {
230230
marginInlineStart: 0,
231231
},
232+
[`${token.componentCls}-copy-disabled`]: {
233+
color: token.colorTextDisabled,
234+
cursor: 'not-allowed',
235+
236+
'&:active, &:hover': {
237+
color: token.colorTextDisabled,
238+
},
239+
240+
'&:active': {
241+
pointerEvents: 'none',
242+
},
243+
},
244+
[`${token.componentCls}-edit-disabled`]: {
245+
color: token.colorTextDisabled,
246+
cursor: 'not-allowed',
247+
248+
'&:active, &:hover': {
249+
color: token.colorTextDisabled,
250+
},
251+
252+
'&:active': {
253+
pointerEvents: 'none',
254+
},
255+
},
232256
});
233257

234258
export const getEllipsisStyles = (): CSSObject => ({

0 commit comments

Comments
 (0)