@douyinfe/semi-ui 2.15.2-alpha.0 → 2.17.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/button/buttonGroup.tsx +3 -2
- package/cascader/index.tsx +5 -1
- package/dist/css/semi.css +87 -20
- package/dist/css/semi.min.css +1 -1
- package/dist/umd/semi-ui.js +358 -223
- package/dist/umd/semi-ui.js.map +1 -1
- package/dist/umd/semi-ui.min.js +1 -1
- package/dist/umd/semi-ui.min.js.map +1 -1
- package/iconButton/index.tsx +3 -0
- package/lib/cjs/button/buttonGroup.d.ts +0 -2
- package/lib/cjs/button/buttonGroup.js +4 -3
- package/lib/cjs/cascader/index.d.ts +3 -0
- package/lib/cjs/cascader/index.js +5 -3
- package/lib/cjs/iconButton/index.js +3 -0
- package/lib/cjs/radio/radio.js +3 -5
- package/lib/cjs/slider/index.d.ts +1 -1
- package/lib/cjs/slider/index.js +84 -36
- package/lib/cjs/transfer/index.d.ts +5 -0
- package/lib/cjs/transfer/index.js +7 -17
- package/lib/cjs/typography/base.js +15 -3
- package/lib/cjs/typography/text.js +11 -1
- package/lib/es/button/buttonGroup.d.ts +0 -2
- package/lib/es/button/buttonGroup.js +4 -3
- package/lib/es/cascader/index.d.ts +3 -0
- package/lib/es/cascader/index.js +5 -3
- package/lib/es/iconButton/index.js +3 -0
- package/lib/es/radio/radio.js +3 -5
- package/lib/es/slider/index.d.ts +1 -1
- package/lib/es/slider/index.js +84 -36
- package/lib/es/transfer/index.d.ts +5 -0
- package/lib/es/transfer/index.js +7 -17
- package/lib/es/typography/base.js +15 -3
- package/lib/es/typography/text.js +10 -1
- package/package.json +11 -11
- package/radio/_story/radio.stories.js +5 -5
- package/radio/radio.tsx +5 -3
- package/slider/_story/slider.stories.js +4 -2
- package/slider/index.tsx +63 -33
- package/transfer/_story/transfer.stories.js +29 -0
- package/transfer/index.tsx +10 -10
- package/typography/_story/typography.stories.js +15 -3
- package/typography/base.tsx +9 -4
- package/typography/text.tsx +9 -1
package/slider/index.tsx
CHANGED
|
@@ -51,6 +51,7 @@ export default class Slider extends BaseComponent<SliderProps, SliderState> {
|
|
|
51
51
|
showBoundary: PropTypes.bool,
|
|
52
52
|
railStyle: PropTypes.object,
|
|
53
53
|
verticalReverse: PropTypes.bool,
|
|
54
|
+
getAriaValueText: PropTypes.func,
|
|
54
55
|
} as any;
|
|
55
56
|
|
|
56
57
|
static defaultProps: Partial<SliderProps> = {
|
|
@@ -77,7 +78,6 @@ export default class Slider extends BaseComponent<SliderProps, SliderState> {
|
|
|
77
78
|
private maxHanleEl: React.RefObject<HTMLDivElement>;
|
|
78
79
|
private dragging: boolean[];
|
|
79
80
|
private eventListenerSet: Set<() => void>;
|
|
80
|
-
private chooseMovePos: 'min' | 'max';
|
|
81
81
|
foundation: SliderFoundation;
|
|
82
82
|
|
|
83
83
|
constructor(props: SliderProps) {
|
|
@@ -98,14 +98,14 @@ export default class Slider extends BaseComponent<SliderProps, SliderState> {
|
|
|
98
98
|
isDrag: false,
|
|
99
99
|
clickValue: 0,
|
|
100
100
|
showBoundary: false,
|
|
101
|
-
isInRenderTree: true
|
|
101
|
+
isInRenderTree: true,
|
|
102
|
+
firstDotFocusVisible: false,
|
|
103
|
+
secondDotFocusVisible: false,
|
|
102
104
|
};
|
|
103
105
|
this.sliderEl = React.createRef();
|
|
104
106
|
this.minHanleEl = React.createRef();
|
|
105
107
|
this.maxHanleEl = React.createRef();
|
|
106
108
|
this.dragging = [false, false];
|
|
107
|
-
// this.chooseMovePos = 'min';
|
|
108
|
-
// this.isDrag = false;
|
|
109
109
|
this.foundation = new SliderFoundation(this.adapter);
|
|
110
110
|
this.eventListenerSet = new Set();
|
|
111
111
|
}
|
|
@@ -165,7 +165,6 @@ export default class Slider extends BaseComponent<SliderProps, SliderState> {
|
|
|
165
165
|
},
|
|
166
166
|
getOverallVars: () => ({
|
|
167
167
|
dragging: this.dragging,
|
|
168
|
-
chooseMovePos: this.chooseMovePos,
|
|
169
168
|
}),
|
|
170
169
|
updateDisabled: (disabled: boolean) => {
|
|
171
170
|
this.setState({ disabled });
|
|
@@ -189,8 +188,6 @@ export default class Slider extends BaseComponent<SliderProps, SliderState> {
|
|
|
189
188
|
getMinHandleEl: () => this.minHanleEl,
|
|
190
189
|
getMaxHandleEl: () => this.maxHanleEl,
|
|
191
190
|
onHandleDown: (e: React.MouseEvent) => {
|
|
192
|
-
e.stopPropagation();
|
|
193
|
-
e.preventDefault();
|
|
194
191
|
this._addEventListener(document.body, 'mousemove', this.foundation.onHandleMove, false);
|
|
195
192
|
this._addEventListener(document.body, 'mouseup', this.foundation.onHandleUp, false);
|
|
196
193
|
this._addEventListener(document.body, 'touchmove', this.foundation.onHandleTouchMove, false);
|
|
@@ -287,7 +284,7 @@ export default class Slider extends BaseComponent<SliderProps, SliderState> {
|
|
|
287
284
|
|
|
288
285
|
renderHandle = () => {
|
|
289
286
|
const { vertical, range, tooltipVisible, tipFormatter, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, 'aria-valuetext': ariaValueText, getAriaValueText, disabled } = this.props;
|
|
290
|
-
const { chooseMovePos, isDrag, isInRenderTree } = this.state;
|
|
287
|
+
const { chooseMovePos, isDrag, isInRenderTree, firstDotFocusVisible, secondDotFocusVisible } = this.state;
|
|
291
288
|
const stylePos = vertical ? 'top' : 'left';
|
|
292
289
|
const percentInfo = this.foundation.getMinAndMaxPercent(this.state.currentValue);
|
|
293
290
|
const minPercent = percentInfo.min;
|
|
@@ -307,7 +304,7 @@ export default class Slider extends BaseComponent<SliderProps, SliderState> {
|
|
|
307
304
|
const { min, max, currentValue } = this.state;
|
|
308
305
|
|
|
309
306
|
const commonAria = {
|
|
310
|
-
'aria-label': ariaLabel,
|
|
307
|
+
'aria-label': ariaLabel ?? (disabled ? 'Disabled Slider' : undefined),
|
|
311
308
|
'aria-labelledby': ariaLabelledby,
|
|
312
309
|
'aria-disabled': disabled
|
|
313
310
|
};
|
|
@@ -319,7 +316,7 @@ export default class Slider extends BaseComponent<SliderProps, SliderState> {
|
|
|
319
316
|
position="top"
|
|
320
317
|
trigger="custom"
|
|
321
318
|
rePosKey={minPercent}
|
|
322
|
-
visible={isInRenderTree && tipVisible.min}
|
|
319
|
+
visible={isInRenderTree && (tipVisible.min || firstDotFocusVisible)}
|
|
323
320
|
className={`${cssClasses.HANDLE}-tooltip`}
|
|
324
321
|
>
|
|
325
322
|
<span
|
|
@@ -352,24 +349,32 @@ export default class Slider extends BaseComponent<SliderProps, SliderState> {
|
|
|
352
349
|
onTouchEnd={e => {
|
|
353
350
|
this.foundation.onHandleUp(e);
|
|
354
351
|
}}
|
|
355
|
-
|
|
352
|
+
onKeyDown={(e)=>{
|
|
353
|
+
this.foundation.handleKeyDown(e, 'min');
|
|
354
|
+
}}
|
|
355
|
+
onFocus={e => {
|
|
356
|
+
this.foundation.onFocus(e, 'min');
|
|
357
|
+
}}
|
|
358
|
+
onBlur={(e) => {
|
|
359
|
+
this.foundation.onBlur(e, 'min');
|
|
360
|
+
}}
|
|
356
361
|
role="slider"
|
|
357
|
-
|
|
362
|
+
aria-valuetext={getAriaValueText ? getAriaValueText(currentValue as number, 0) : ariaValueText}
|
|
363
|
+
tabIndex={disabled ? -1 : 0}
|
|
358
364
|
{...commonAria}
|
|
359
365
|
aria-valuenow={currentValue as number}
|
|
360
366
|
aria-valuemax={max}
|
|
361
367
|
aria-valuemin={min}
|
|
362
|
-
aria-valuetext={getAriaValueText ? getAriaValueText(currentValue as number) : ariaValueText}
|
|
363
368
|
/>
|
|
364
369
|
</Tooltip>
|
|
365
370
|
) : (
|
|
366
371
|
<React.Fragment>
|
|
367
|
-
<Tooltip
|
|
372
|
+
<Tooltip
|
|
368
373
|
content={tipChildren.min}
|
|
369
374
|
position="top"
|
|
370
375
|
trigger="custom"
|
|
371
376
|
rePosKey={minPercent}
|
|
372
|
-
visible={isInRenderTree && tipVisible.min}
|
|
377
|
+
visible={isInRenderTree && (tipVisible.min || firstDotFocusVisible)}
|
|
373
378
|
className={`${cssClasses.HANDLE}-tooltip`}
|
|
374
379
|
>
|
|
375
380
|
<span
|
|
@@ -401,12 +406,20 @@ export default class Slider extends BaseComponent<SliderProps, SliderState> {
|
|
|
401
406
|
onTouchEnd={e => {
|
|
402
407
|
this.foundation.onHandleUp(e);
|
|
403
408
|
}}
|
|
404
|
-
|
|
409
|
+
onKeyDown={(e)=>{
|
|
410
|
+
this.foundation.handleKeyDown(e, 'min');
|
|
411
|
+
}}
|
|
412
|
+
onFocus={e => {
|
|
413
|
+
this.foundation.onFocus(e, 'min');
|
|
414
|
+
}}
|
|
415
|
+
onBlur={(e) => {
|
|
416
|
+
this.foundation.onBlur(e, 'min');
|
|
417
|
+
}}
|
|
405
418
|
role="slider"
|
|
406
|
-
tabIndex={0}
|
|
419
|
+
tabIndex={disabled ? -1 : 0}
|
|
407
420
|
{...commonAria}
|
|
421
|
+
aria-valuetext={getAriaValueText ? getAriaValueText(currentValue[0], 0) : ariaValueText}
|
|
408
422
|
aria-valuenow={currentValue[0]}
|
|
409
|
-
aria-valuetext={getAriaValueText ? getAriaValueText(currentValue[0]) : ariaValueText}
|
|
410
423
|
aria-valuemax={currentValue[1]}
|
|
411
424
|
aria-valuemin={min}
|
|
412
425
|
/>
|
|
@@ -416,7 +429,7 @@ export default class Slider extends BaseComponent<SliderProps, SliderState> {
|
|
|
416
429
|
position="top"
|
|
417
430
|
trigger="custom"
|
|
418
431
|
rePosKey={maxPercent}
|
|
419
|
-
visible={isInRenderTree && tipVisible.max}
|
|
432
|
+
visible={isInRenderTree && (tipVisible.max || secondDotFocusVisible)}
|
|
420
433
|
className={`${cssClasses.HANDLE}-tooltip`}
|
|
421
434
|
>
|
|
422
435
|
<span
|
|
@@ -448,12 +461,20 @@ export default class Slider extends BaseComponent<SliderProps, SliderState> {
|
|
|
448
461
|
onTouchEnd={e => {
|
|
449
462
|
this.foundation.onHandleUp(e);
|
|
450
463
|
}}
|
|
451
|
-
|
|
464
|
+
onKeyDown={e =>{
|
|
465
|
+
this.foundation.handleKeyDown(e, 'max');
|
|
466
|
+
}}
|
|
467
|
+
onFocus={e => {
|
|
468
|
+
this.foundation.onFocus(e, 'max');
|
|
469
|
+
}}
|
|
470
|
+
onBlur={(e) => {
|
|
471
|
+
this.foundation.onBlur(e, 'max');
|
|
472
|
+
}}
|
|
452
473
|
role="slider"
|
|
453
|
-
tabIndex={0}
|
|
474
|
+
tabIndex={disabled ? -1 : 0}
|
|
454
475
|
{...commonAria}
|
|
476
|
+
aria-valuetext={getAriaValueText ? getAriaValueText(currentValue[1], 1) : ariaValueText}
|
|
455
477
|
aria-valuenow={currentValue[1]}
|
|
456
|
-
aria-valuetext={getAriaValueText ? getAriaValueText(currentValue[1]) : ariaValueText}
|
|
457
478
|
aria-valuemax={max}
|
|
458
479
|
aria-valuemin={currentValue[0]}
|
|
459
480
|
/>
|
|
@@ -538,29 +559,38 @@ export default class Slider extends BaseComponent<SliderProps, SliderState> {
|
|
|
538
559
|
return labelContent;
|
|
539
560
|
};
|
|
540
561
|
|
|
562
|
+
_getAriaValueText = (value: number, index?: number) => {
|
|
563
|
+
const { getAriaValueText } = this.props;
|
|
564
|
+
return getAriaValueText ? getAriaValueText(value, index) : value;
|
|
565
|
+
}
|
|
566
|
+
|
|
541
567
|
|
|
542
568
|
render() {
|
|
569
|
+
const { disabled, currentValue, min, max } = this.state;
|
|
570
|
+
const { vertical, verticalReverse, style, railStyle, range, className } = this.props;
|
|
543
571
|
const wrapperClass = cls(
|
|
544
572
|
`${prefixCls}-wrapper`,
|
|
545
573
|
{
|
|
546
|
-
[`${prefixCls}-disabled`]:
|
|
547
|
-
[`${cssClasses.VERTICAL}-wrapper`]:
|
|
548
|
-
[`${prefixCls}-reverse`]:
|
|
574
|
+
[`${prefixCls}-disabled`]: disabled,
|
|
575
|
+
[`${cssClasses.VERTICAL}-wrapper`]: vertical,
|
|
576
|
+
[`${prefixCls}-reverse`]: vertical && verticalReverse
|
|
549
577
|
},
|
|
550
|
-
|
|
578
|
+
className
|
|
551
579
|
);
|
|
552
580
|
const boundaryClass = cls(`${prefixCls}-boundary`, {
|
|
553
581
|
[`${prefixCls}-boundary-show`]: this.props.showBoundary && this.state.showBoundary,
|
|
554
582
|
});
|
|
555
583
|
const sliderCls = cls({
|
|
556
|
-
[`${prefixCls}`]: !
|
|
557
|
-
[cssClasses.VERTICAL]:
|
|
584
|
+
[`${prefixCls}`]: !vertical,
|
|
585
|
+
[cssClasses.VERTICAL]: vertical,
|
|
558
586
|
});
|
|
587
|
+
const ariaLabel = range ? `Range: ${this._getAriaValueText(currentValue[0], 0)} to ${this._getAriaValueText(currentValue[1], 1)}` : undefined;
|
|
559
588
|
const slider = (
|
|
560
589
|
<div
|
|
561
590
|
className={wrapperClass}
|
|
562
|
-
style={
|
|
591
|
+
style={style}
|
|
563
592
|
ref={this.sliderEl}
|
|
593
|
+
aria-label={ariaLabel}
|
|
564
594
|
onMouseEnter={() => this.foundation.handleWrapperEnter()}
|
|
565
595
|
onMouseLeave={() => this.foundation.handleWrapperLeave()}
|
|
566
596
|
>
|
|
@@ -568,7 +598,7 @@ export default class Slider extends BaseComponent<SliderProps, SliderState> {
|
|
|
568
598
|
<div
|
|
569
599
|
className={`${prefixCls}-rail`}
|
|
570
600
|
onClick={this.foundation.handleWrapClick}
|
|
571
|
-
style={
|
|
601
|
+
style={railStyle}
|
|
572
602
|
/>
|
|
573
603
|
}
|
|
574
604
|
{this.renderTrack()}
|
|
@@ -576,12 +606,12 @@ export default class Slider extends BaseComponent<SliderProps, SliderState> {
|
|
|
576
606
|
<div>{this.renderHandle()}</div>
|
|
577
607
|
{this.renderLabel()}
|
|
578
608
|
<div className={boundaryClass}>
|
|
579
|
-
<span className={`${prefixCls}-boundary-min`}>{
|
|
580
|
-
<span className={`${prefixCls}-boundary-max`}>{
|
|
609
|
+
<span className={`${prefixCls}-boundary-min`}>{min}</span>
|
|
610
|
+
<span className={`${prefixCls}-boundary-max`}>{max}</span>
|
|
581
611
|
</div>
|
|
582
612
|
</div>
|
|
583
613
|
);
|
|
584
|
-
if (!
|
|
614
|
+
if (!vertical) {
|
|
585
615
|
return <div className={sliderCls}>{slider}</div>;
|
|
586
616
|
}
|
|
587
617
|
return slider;
|
|
@@ -166,6 +166,35 @@ TransferDraggable.story = {
|
|
|
166
166
|
name: 'Transfer draggable',
|
|
167
167
|
};
|
|
168
168
|
|
|
169
|
+
export const TransferDraggableAndDisabled = () => {
|
|
170
|
+
const data = Array.from({ length: 30 }, (v, i) => {
|
|
171
|
+
return {
|
|
172
|
+
label: `选项名称 ${i}`,
|
|
173
|
+
value: i,
|
|
174
|
+
key: i,
|
|
175
|
+
disabled: true,
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
return (
|
|
179
|
+
<>
|
|
180
|
+
<div>Transfer设置draggable, 并且左侧面板中的选项disabled </div>
|
|
181
|
+
<div>符合预期的行为: 右侧面板hover不会出现删除按钮,因此不可以点击删除,但是可以拖拽 </div>
|
|
182
|
+
<Transfer
|
|
183
|
+
style={{ width: 568, height: 416 }}
|
|
184
|
+
dataSource={data}
|
|
185
|
+
defaultValue={[2, 4]}
|
|
186
|
+
draggable
|
|
187
|
+
onChange={(values, items) => console.log(values, items)}
|
|
188
|
+
/>
|
|
189
|
+
</>
|
|
190
|
+
);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
TransferDraggableAndDisabled.story = {
|
|
194
|
+
name: 'transfer draggable and disabled',
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
|
|
169
198
|
const ControledTransfer = () => {
|
|
170
199
|
const [value, setValue] = useState([2, 3]);
|
|
171
200
|
|
package/transfer/index.tsx
CHANGED
|
@@ -102,6 +102,12 @@ export interface ResolvedDataItem extends DataItem {
|
|
|
102
102
|
_optionKey?: string | number;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
export interface DraggableResolvedDataItem {
|
|
106
|
+
key?: string | number;
|
|
107
|
+
index?: number;
|
|
108
|
+
item?: ResolvedDataItem;
|
|
109
|
+
}
|
|
110
|
+
|
|
105
111
|
export type DataSource = Array<DataItem> | Array<GroupItem> | Array<TreeItem>;
|
|
106
112
|
|
|
107
113
|
interface HeaderConfig {
|
|
@@ -511,12 +517,7 @@ class Transfer extends BaseComponent<TransferProps, TransferState> {
|
|
|
511
517
|
|
|
512
518
|
renderRightItem(item: ResolvedDataItem): React.ReactNode {
|
|
513
519
|
const { renderSelectedItem, draggable, type, showPath } = this.props;
|
|
514
|
-
|
|
515
|
-
if (draggable) {
|
|
516
|
-
newItem = { ...item, key: item._optionKey };
|
|
517
|
-
delete newItem._optionKey;
|
|
518
|
-
}
|
|
519
|
-
const onRemove = () => this.foundation.handleSelectOrRemove(newItem);
|
|
520
|
+
const onRemove = () => this.foundation.handleSelectOrRemove(item);
|
|
520
521
|
const rightItemCls = cls({
|
|
521
522
|
[`${prefixcls}-item`]: true,
|
|
522
523
|
[`${prefixcls}-right-item`]: true,
|
|
@@ -536,7 +537,7 @@ class Transfer extends BaseComponent<TransferProps, TransferState> {
|
|
|
536
537
|
|
|
537
538
|
return (
|
|
538
539
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex
|
|
539
|
-
<div role="listitem" className={rightItemCls} key={
|
|
540
|
+
<div role="listitem" className={rightItemCls} key={item.key}>
|
|
540
541
|
{draggable ? <DragHandle /> : null}
|
|
541
542
|
<div className={`${prefixcls}-right-item-text`}>{label}</div>
|
|
542
543
|
<IconClose
|
|
@@ -562,14 +563,13 @@ class Transfer extends BaseComponent<TransferProps, TransferState> {
|
|
|
562
563
|
renderRightSortableList(selectedData: Array<ResolvedDataItem>) {
|
|
563
564
|
// when choose some items && draggable is true
|
|
564
565
|
const SortableItem = SortableElement((
|
|
565
|
-
(
|
|
566
|
+
(props: DraggableResolvedDataItem) => this.renderRightItem(props.item)) as React.FC<DraggableResolvedDataItem>
|
|
566
567
|
);
|
|
567
568
|
const SortableList = SortableContainer(({ items }: { items: Array<ResolvedDataItem> }) => (
|
|
568
569
|
<div className={`${prefixcls}-right-list`} role="list" aria-label="Selected list">
|
|
569
570
|
{items.map((item, index: number) => (
|
|
570
|
-
// sortableElement will take over the property 'key', so use another '_optionKey' to pass
|
|
571
571
|
// @ts-ignore skip SortableItem type check
|
|
572
|
-
<SortableItem key={item.label} index={index}
|
|
572
|
+
<SortableItem key={item.label} index={index} item={item} />
|
|
573
573
|
))}
|
|
574
574
|
</div>
|
|
575
575
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -3,7 +3,7 @@ import withPropsCombinations from 'react-storybook-addon-props-combinations';
|
|
|
3
3
|
|
|
4
4
|
import Icon from '../../icons';
|
|
5
5
|
import Typography from '../index';
|
|
6
|
-
import { IconLink, IconTick } from '@douyinfe/semi-icons';
|
|
6
|
+
import { IconLink, IconTick, IconPlusCircle } from '@douyinfe/semi-icons';
|
|
7
7
|
|
|
8
8
|
export default {
|
|
9
9
|
title: 'Typography'
|
|
@@ -51,10 +51,22 @@ export const _Text = () => (
|
|
|
51
51
|
<br />
|
|
52
52
|
<Text link={{ href: 'https://semi.design/' }}>打开网站</Text>
|
|
53
53
|
<br />
|
|
54
|
+
{/* 用户未通过icon API设置icon,而是通过children传入,则需要手动处理内容的对齐 */}
|
|
54
55
|
<Text link>
|
|
55
|
-
<
|
|
56
|
-
|
|
56
|
+
<span style={ {display: 'inline-flex', alignItems: 'center' }} >
|
|
57
|
+
<IconLink style={{ marginRight: 4 }}/>
|
|
58
|
+
网页链接
|
|
59
|
+
</span>
|
|
57
60
|
</Text>
|
|
61
|
+
<br />
|
|
62
|
+
<Text link icon={<IconLink />} underline>带下划线的网页链接</Text>
|
|
63
|
+
<br />
|
|
64
|
+
<Text icon={<IconLink />} underline>带下划线的内容</Text>
|
|
65
|
+
<br />
|
|
66
|
+
<Text icon={<IconPlusCircle />} style={{ color: 'purple'}}>添加条件</Text>
|
|
67
|
+
<br />
|
|
68
|
+
<Text icon={<IconPlusCircle />} style={{ color: 'purple'}} size={'small'}>添加条件</Text>
|
|
69
|
+
<br />
|
|
58
70
|
</div>
|
|
59
71
|
);
|
|
60
72
|
|
package/typography/base.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { Component } from 'react';
|
|
1
|
+
import React, { Component, ReactElement } from 'react';
|
|
2
2
|
import ReactDOM from 'react-dom';
|
|
3
3
|
import cls from 'classnames';
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
@@ -54,15 +54,15 @@ const prefixCls = cssClasses.PREFIX;
|
|
|
54
54
|
const ELLIPSIS_STR = '...';
|
|
55
55
|
|
|
56
56
|
const wrapperDecorations = (props: BaseTypographyProps, content: React.ReactNode) => {
|
|
57
|
-
const { mark, code, underline, strong, link, disabled } = props;
|
|
57
|
+
const { mark, code, underline, strong, link, disabled, icon, } = props;
|
|
58
58
|
let wrapped = content;
|
|
59
59
|
const wrap = (isNeeded: boolean | LinkType, tag: string) => {
|
|
60
|
-
let wrapProps = {};
|
|
60
|
+
let wrapProps = icon ? { style: { display: 'inline-flex', alignItems: 'center' } } : {};
|
|
61
61
|
if (!isNeeded) {
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
if (typeof isNeeded === 'object') {
|
|
65
|
-
wrapProps = { ...isNeeded };
|
|
65
|
+
wrapProps = { ...isNeeded } as any;
|
|
66
66
|
}
|
|
67
67
|
wrapped = React.createElement(tag, wrapProps, wrapped);
|
|
68
68
|
};
|
|
@@ -72,6 +72,11 @@ const wrapperDecorations = (props: BaseTypographyProps, content: React.ReactNode
|
|
|
72
72
|
wrap(strong, 'strong');
|
|
73
73
|
wrap(props.delete, 'del');
|
|
74
74
|
wrap(link, disabled ? 'span' : 'a');
|
|
75
|
+
// When the content is not wrapped, and there is more than one element in the content (one of which is an icon),
|
|
76
|
+
// use span to wrap the content, so that the content in the span is vertically aligned
|
|
77
|
+
if (wrapped === content && icon) {
|
|
78
|
+
wrap(true, 'span');
|
|
79
|
+
}
|
|
75
80
|
return wrapped;
|
|
76
81
|
};
|
|
77
82
|
|
package/typography/text.tsx
CHANGED
|
@@ -4,9 +4,13 @@ import { strings } from '@douyinfe/semi-foundation/typography/constants';
|
|
|
4
4
|
import Base from './base';
|
|
5
5
|
import { Ellipsis, TypographyBaseSize, TypographyBaseType, OmitTypographyProps } from './interface';
|
|
6
6
|
import { CopyableConfig, LinkType } from './title';
|
|
7
|
+
import cls from 'classnames';
|
|
8
|
+
import { cssClasses } from '@douyinfe/semi-foundation/typography/constants';
|
|
7
9
|
|
|
8
10
|
type OmitTextProps = OmitTypographyProps;
|
|
9
11
|
|
|
12
|
+
const prefixCls = cssClasses.PREFIX;
|
|
13
|
+
|
|
10
14
|
export interface TextProps extends Omit<React.HTMLAttributes<HTMLSpanElement>, OmitTextProps> {
|
|
11
15
|
children?: React.ReactNode;
|
|
12
16
|
className?: string;
|
|
@@ -63,6 +67,10 @@ export default class Text extends PureComponent<TextProps> {
|
|
|
63
67
|
};
|
|
64
68
|
|
|
65
69
|
render() {
|
|
66
|
-
|
|
70
|
+
const className = cls(this.props.className, {
|
|
71
|
+
[`${prefixCls}-text`]: true,
|
|
72
|
+
[`${prefixCls}-text-icon`]: this.props.icon,
|
|
73
|
+
});
|
|
74
|
+
return <Base component={'span'} {...this.props} className={className} />;
|
|
67
75
|
}
|
|
68
76
|
}
|