@douyinfe/semi-ui 2.15.0 → 2.16.0-beta.0

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.
Files changed (42) hide show
  1. package/button/buttonGroup.tsx +3 -2
  2. package/cascader/index.tsx +5 -1
  3. package/dist/css/semi.css +12 -0
  4. package/dist/css/semi.min.css +1 -1
  5. package/dist/umd/semi-ui.js +325 -73
  6. package/dist/umd/semi-ui.js.map +1 -1
  7. package/dist/umd/semi-ui.min.js +1 -1
  8. package/dist/umd/semi-ui.min.js.map +1 -1
  9. package/iconButton/index.tsx +3 -0
  10. package/lib/cjs/button/buttonGroup.d.ts +0 -2
  11. package/lib/cjs/button/buttonGroup.js +4 -3
  12. package/lib/cjs/cascader/index.d.ts +3 -0
  13. package/lib/cjs/cascader/index.js +5 -3
  14. package/lib/cjs/iconButton/index.js +3 -0
  15. package/lib/cjs/slider/index.d.ts +1 -1
  16. package/lib/cjs/slider/index.js +84 -36
  17. package/lib/cjs/tooltip/index.js +1 -1
  18. package/lib/cjs/transfer/index.d.ts +5 -0
  19. package/lib/cjs/transfer/index.js +7 -17
  20. package/lib/cjs/typography/base.js +15 -3
  21. package/lib/cjs/typography/text.js +11 -1
  22. package/lib/es/button/buttonGroup.d.ts +0 -2
  23. package/lib/es/button/buttonGroup.js +4 -3
  24. package/lib/es/cascader/index.d.ts +3 -0
  25. package/lib/es/cascader/index.js +5 -3
  26. package/lib/es/iconButton/index.js +3 -0
  27. package/lib/es/slider/index.d.ts +1 -1
  28. package/lib/es/slider/index.js +84 -36
  29. package/lib/es/tooltip/index.js +1 -1
  30. package/lib/es/transfer/index.d.ts +5 -0
  31. package/lib/es/transfer/index.js +7 -17
  32. package/lib/es/typography/base.js +15 -3
  33. package/lib/es/typography/text.js +10 -1
  34. package/package.json +7 -7
  35. package/slider/_story/slider.stories.js +4 -2
  36. package/slider/index.tsx +63 -33
  37. package/tooltip/index.tsx +1 -1
  38. package/transfer/_story/transfer.stories.js +29 -0
  39. package/transfer/index.tsx +10 -10
  40. package/typography/_story/typography.stories.js +15 -3
  41. package/typography/base.tsx +9 -4
  42. package/typography/text.tsx +9 -1
@@ -50,7 +50,9 @@ export default class Slider extends BaseComponent {
50
50
  const {
51
51
  chooseMovePos,
52
52
  isDrag,
53
- isInRenderTree
53
+ isInRenderTree,
54
+ firstDotFocusVisible,
55
+ secondDotFocusVisible
54
56
  } = this.state;
55
57
  const stylePos = vertical ? 'top' : 'left';
56
58
  const percentInfo = this.foundation.getMinAndMaxPercent(this.state.currentValue);
@@ -76,7 +78,7 @@ export default class Slider extends BaseComponent {
76
78
  currentValue
77
79
  } = this.state;
78
80
  const commonAria = {
79
- 'aria-label': ariaLabel,
81
+ 'aria-label': ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : disabled ? 'Disabled Slider' : undefined,
80
82
  'aria-labelledby': ariaLabelledby,
81
83
  'aria-disabled': disabled
82
84
  };
@@ -88,7 +90,7 @@ export default class Slider extends BaseComponent {
88
90
  position: "top",
89
91
  trigger: "custom",
90
92
  rePosKey: minPercent,
91
- visible: isInRenderTree && tipVisible.min,
93
+ visible: isInRenderTree && (tipVisible.min || firstDotFocusVisible),
92
94
  className: "".concat(cssClasses.HANDLE, "-tooltip")
93
95
  }, /*#__PURE__*/React.createElement("span", _Object$assign({
94
96
  onMouseOver: this.foundation.checkAndUpdateIsInRenderTreeState,
@@ -120,20 +122,28 @@ export default class Slider extends BaseComponent {
120
122
  onTouchEnd: e => {
121
123
  this.foundation.onHandleUp(e);
122
124
  },
123
- onFocus: e => this.foundation.onFocus(e, 'min'),
125
+ onKeyDown: e => {
126
+ this.foundation.handleKeyDown(e, 'min');
127
+ },
128
+ onFocus: e => {
129
+ this.foundation.onFocus(e, 'min');
130
+ },
131
+ onBlur: e => {
132
+ this.foundation.onBlur(e, 'min');
133
+ },
124
134
  role: "slider",
125
- tabIndex: 0
135
+ "aria-valuetext": getAriaValueText ? getAriaValueText(currentValue, 0) : ariaValueText,
136
+ tabIndex: disabled ? -1 : 0
126
137
  }, commonAria, {
127
138
  "aria-valuenow": currentValue,
128
139
  "aria-valuemax": max,
129
- "aria-valuemin": min,
130
- "aria-valuetext": getAriaValueText ? getAriaValueText(currentValue) : ariaValueText
140
+ "aria-valuemin": min
131
141
  }))) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Tooltip, {
132
142
  content: tipChildren.min,
133
143
  position: "top",
134
144
  trigger: "custom",
135
145
  rePosKey: minPercent,
136
- visible: isInRenderTree && tipVisible.min,
146
+ visible: isInRenderTree && (tipVisible.min || firstDotFocusVisible),
137
147
  className: "".concat(cssClasses.HANDLE, "-tooltip")
138
148
  }, /*#__PURE__*/React.createElement("span", _Object$assign({
139
149
  ref: this.minHanleEl,
@@ -164,12 +174,20 @@ export default class Slider extends BaseComponent {
164
174
  onTouchEnd: e => {
165
175
  this.foundation.onHandleUp(e);
166
176
  },
167
- onFocus: e => this.foundation.onFocus(e, 'min'),
177
+ onKeyDown: e => {
178
+ this.foundation.handleKeyDown(e, 'min');
179
+ },
180
+ onFocus: e => {
181
+ this.foundation.onFocus(e, 'min');
182
+ },
183
+ onBlur: e => {
184
+ this.foundation.onBlur(e, 'min');
185
+ },
168
186
  role: "slider",
169
- tabIndex: 0
187
+ tabIndex: disabled ? -1 : 0
170
188
  }, commonAria, {
189
+ "aria-valuetext": getAriaValueText ? getAriaValueText(currentValue[0], 0) : ariaValueText,
171
190
  "aria-valuenow": currentValue[0],
172
- "aria-valuetext": getAriaValueText ? getAriaValueText(currentValue[0]) : ariaValueText,
173
191
  "aria-valuemax": currentValue[1],
174
192
  "aria-valuemin": min
175
193
  }))), /*#__PURE__*/React.createElement(Tooltip, {
@@ -177,7 +195,7 @@ export default class Slider extends BaseComponent {
177
195
  position: "top",
178
196
  trigger: "custom",
179
197
  rePosKey: maxPercent,
180
- visible: isInRenderTree && tipVisible.max,
198
+ visible: isInRenderTree && (tipVisible.max || secondDotFocusVisible),
181
199
  className: "".concat(cssClasses.HANDLE, "-tooltip")
182
200
  }, /*#__PURE__*/React.createElement("span", _Object$assign({
183
201
  ref: this.maxHanleEl,
@@ -208,12 +226,20 @@ export default class Slider extends BaseComponent {
208
226
  onTouchEnd: e => {
209
227
  this.foundation.onHandleUp(e);
210
228
  },
211
- onFocus: e => this.foundation.onFocus(e, 'min'),
229
+ onKeyDown: e => {
230
+ this.foundation.handleKeyDown(e, 'max');
231
+ },
232
+ onFocus: e => {
233
+ this.foundation.onFocus(e, 'max');
234
+ },
235
+ onBlur: e => {
236
+ this.foundation.onBlur(e, 'max');
237
+ },
212
238
  role: "slider",
213
- tabIndex: 0
239
+ tabIndex: disabled ? -1 : 0
214
240
  }, commonAria, {
241
+ "aria-valuetext": getAriaValueText ? getAriaValueText(currentValue[1], 1) : ariaValueText,
215
242
  "aria-valuenow": currentValue[1],
216
- "aria-valuetext": getAriaValueText ? getAriaValueText(currentValue[1]) : ariaValueText,
217
243
  "aria-valuemax": max,
218
244
  "aria-valuemin": currentValue[0]
219
245
  }))));
@@ -314,6 +340,13 @@ export default class Slider extends BaseComponent {
314
340
  return labelContent;
315
341
  };
316
342
 
343
+ this._getAriaValueText = (value, index) => {
344
+ const {
345
+ getAriaValueText
346
+ } = this.props;
347
+ return getAriaValueText ? getAriaValueText(value, index) : value;
348
+ };
349
+
317
350
  let {
318
351
  value
319
352
  } = this.props;
@@ -334,14 +367,14 @@ export default class Slider extends BaseComponent {
334
367
  isDrag: false,
335
368
  clickValue: 0,
336
369
  showBoundary: false,
337
- isInRenderTree: true
370
+ isInRenderTree: true,
371
+ firstDotFocusVisible: false,
372
+ secondDotFocusVisible: false
338
373
  };
339
374
  this.sliderEl = /*#__PURE__*/React.createRef();
340
375
  this.minHanleEl = /*#__PURE__*/React.createRef();
341
376
  this.maxHanleEl = /*#__PURE__*/React.createRef();
342
- this.dragging = [false, false]; // this.chooseMovePos = 'min';
343
- // this.isDrag = false;
344
-
377
+ this.dragging = [false, false];
345
378
  this.foundation = new SliderFoundation(this.adapter);
346
379
  this.eventListenerSet = new _Set();
347
380
  }
@@ -408,8 +441,7 @@ export default class Slider extends BaseComponent {
408
441
  return flag;
409
442
  },
410
443
  getOverallVars: () => ({
411
- dragging: this.dragging,
412
- chooseMovePos: this.chooseMovePos
444
+ dragging: this.dragging
413
445
  }),
414
446
  updateDisabled: disabled => {
415
447
  this.setState({
@@ -443,9 +475,6 @@ export default class Slider extends BaseComponent {
443
475
  getMinHandleEl: () => this.minHanleEl,
444
476
  getMaxHandleEl: () => this.maxHanleEl,
445
477
  onHandleDown: e => {
446
- e.stopPropagation();
447
- e.preventDefault();
448
-
449
478
  this._addEventListener(document.body, 'mousemove', this.foundation.onHandleMove, false);
450
479
 
451
480
  this._addEventListener(document.body, 'mouseup', this.foundation.onHandleUp, false);
@@ -568,37 +597,55 @@ export default class Slider extends BaseComponent {
568
597
  }
569
598
 
570
599
  render() {
600
+ var _context5;
601
+
602
+ const {
603
+ disabled,
604
+ currentValue,
605
+ min,
606
+ max
607
+ } = this.state;
608
+ const {
609
+ vertical,
610
+ verticalReverse,
611
+ style,
612
+ railStyle,
613
+ range,
614
+ className
615
+ } = this.props;
571
616
  const wrapperClass = cls("".concat(prefixCls, "-wrapper"), {
572
- ["".concat(prefixCls, "-disabled")]: this.state.disabled,
573
- ["".concat(cssClasses.VERTICAL, "-wrapper")]: this.props.vertical,
574
- ["".concat(prefixCls, "-reverse")]: this.props.vertical && this.props.verticalReverse
575
- }, this.props.className);
617
+ ["".concat(prefixCls, "-disabled")]: disabled,
618
+ ["".concat(cssClasses.VERTICAL, "-wrapper")]: vertical,
619
+ ["".concat(prefixCls, "-reverse")]: vertical && verticalReverse
620
+ }, className);
576
621
  const boundaryClass = cls("".concat(prefixCls, "-boundary"), {
577
622
  ["".concat(prefixCls, "-boundary-show")]: this.props.showBoundary && this.state.showBoundary
578
623
  });
579
624
  const sliderCls = cls({
580
- ["".concat(prefixCls)]: !this.props.vertical,
581
- [cssClasses.VERTICAL]: this.props.vertical
625
+ ["".concat(prefixCls)]: !vertical,
626
+ [cssClasses.VERTICAL]: vertical
582
627
  });
628
+ const ariaLabel = range ? _concatInstanceProperty(_context5 = "Range: ".concat(this._getAriaValueText(currentValue[0], 0), " to ")).call(_context5, this._getAriaValueText(currentValue[1], 1)) : undefined;
583
629
  const slider = /*#__PURE__*/React.createElement("div", {
584
630
  className: wrapperClass,
585
- style: this.props.style,
631
+ style: style,
586
632
  ref: this.sliderEl,
633
+ "aria-label": ariaLabel,
587
634
  onMouseEnter: () => this.foundation.handleWrapperEnter(),
588
635
  onMouseLeave: () => this.foundation.handleWrapperLeave()
589
636
  }, /*#__PURE__*/React.createElement("div", {
590
637
  className: "".concat(prefixCls, "-rail"),
591
638
  onClick: this.foundation.handleWrapClick,
592
- style: this.props.railStyle
639
+ style: railStyle
593
640
  }), this.renderTrack(), this.renderStepDot(), /*#__PURE__*/React.createElement("div", null, this.renderHandle()), this.renderLabel(), /*#__PURE__*/React.createElement("div", {
594
641
  className: boundaryClass
595
642
  }, /*#__PURE__*/React.createElement("span", {
596
643
  className: "".concat(prefixCls, "-boundary-min")
597
- }, this.state.min), /*#__PURE__*/React.createElement("span", {
644
+ }, min), /*#__PURE__*/React.createElement("span", {
598
645
  className: "".concat(prefixCls, "-boundary-max")
599
- }, this.state.max)));
646
+ }, max)));
600
647
 
601
- if (!this.props.vertical) {
648
+ if (!vertical) {
602
649
  return /*#__PURE__*/React.createElement("div", {
603
650
  className: sliderCls
604
651
  }, slider);
@@ -651,7 +698,8 @@ Slider.propTypes = {
651
698
  className: PropTypes.string,
652
699
  showBoundary: PropTypes.bool,
653
700
  railStyle: PropTypes.object,
654
- verticalReverse: PropTypes.bool
701
+ verticalReverse: PropTypes.bool,
702
+ getAriaValueText: PropTypes.func
655
703
  };
656
704
  Slider.defaultProps = {
657
705
  // allowClear: false,
@@ -684,7 +684,7 @@ export default class Tooltip extends BaseComponent {
684
684
  }
685
685
  },
686
686
  tabIndex: 0,
687
- 'data-popupId': id
687
+ 'data-popupid': id
688
688
  })); // If you do not add a layer of div, in order to bind the events and className in the tooltip, you need to cloneElement children, but this time it may overwrite the children's original ref reference
689
689
  // So if the user adds ref to the content, you need to use callback ref: https://github.com/facebook/react/issues/8873
690
690
 
@@ -63,6 +63,11 @@ export interface ResolvedDataItem extends DataItem {
63
63
  };
64
64
  _optionKey?: string | number;
65
65
  }
66
+ export interface DraggableResolvedDataItem {
67
+ key?: string | number;
68
+ index?: number;
69
+ item?: ResolvedDataItem;
70
+ }
66
71
  export declare type DataSource = Array<DataItem> | Array<GroupItem> | Array<TreeItem>;
67
72
  interface HeaderConfig {
68
73
  totalContent: string;
@@ -419,16 +419,8 @@ class Transfer extends BaseComponent {
419
419
  type,
420
420
  showPath
421
421
  } = this.props;
422
- let newItem = item;
423
422
 
424
- if (draggable) {
425
- newItem = _Object$assign(_Object$assign({}, item), {
426
- key: item._optionKey
427
- });
428
- delete newItem._optionKey;
429
- }
430
-
431
- const onRemove = () => this.foundation.handleSelectOrRemove(newItem);
423
+ const onRemove = () => this.foundation.handleSelectOrRemove(item);
432
424
 
433
425
  const rightItemCls = cls({
434
426
  ["".concat(prefixcls, "-item")]: true,
@@ -456,7 +448,7 @@ class Transfer extends BaseComponent {
456
448
  React.createElement("div", {
457
449
  role: "listitem",
458
450
  className: rightItemCls,
459
- key: newItem.key
451
+ key: item.key
460
452
  }, draggable ? /*#__PURE__*/React.createElement(DragHandle, null) : null, /*#__PURE__*/React.createElement("div", {
461
453
  className: "".concat(prefixcls, "-right-item-text")
462
454
  }, label), /*#__PURE__*/React.createElement(IconClose, {
@@ -483,7 +475,7 @@ class Transfer extends BaseComponent {
483
475
 
484
476
  renderRightSortableList(selectedData) {
485
477
  // when choose some items && draggable is true
486
- const SortableItem = SortableElement(item => this.renderRightItem(item));
478
+ const SortableItem = SortableElement(props => this.renderRightItem(props.item));
487
479
  const SortableList = SortableContainer(_ref => {
488
480
  let {
489
481
  items
@@ -494,14 +486,12 @@ class Transfer extends BaseComponent {
494
486
  "aria-label": "Selected list"
495
487
  }, _mapInstanceProperty(items).call(items, (item, index) =>
496
488
  /*#__PURE__*/
497
- // sortableElement will take over the property 'key', so use another '_optionKey' to pass
498
489
  // @ts-ignore skip SortableItem type check
499
- React.createElement(SortableItem, _Object$assign({
490
+ React.createElement(SortableItem, {
500
491
  key: item.label,
501
- index: index
502
- }, item, {
503
- _optionKey: item.key
504
- })))) // eslint-disable-next-line @typescript-eslint/ban-ts-comment
492
+ index: index,
493
+ item: item
494
+ }))) // eslint-disable-next-line @typescript-eslint/ban-ts-comment
505
495
  // @ts-ignore see reasons: https://github.com/clauderic/react-sortable-hoc/issues/206
506
496
  ;
507
497
  }, {
@@ -45,12 +45,18 @@ const wrapperDecorations = (props, content) => {
45
45
  underline,
46
46
  strong,
47
47
  link,
48
- disabled
48
+ disabled,
49
+ icon
49
50
  } = props;
50
51
  let wrapped = content;
51
52
 
52
53
  const wrap = (isNeeded, tag) => {
53
- let wrapProps = {};
54
+ let wrapProps = icon ? {
55
+ style: {
56
+ display: 'inline-flex',
57
+ alignItems: 'center'
58
+ }
59
+ } : {};
54
60
 
55
61
  if (!isNeeded) {
56
62
  return;
@@ -68,7 +74,13 @@ const wrapperDecorations = (props, content) => {
68
74
  wrap(underline && !link, 'u');
69
75
  wrap(strong, 'strong');
70
76
  wrap(props.delete, 'del');
71
- wrap(link, disabled ? 'span' : 'a');
77
+ wrap(link, disabled ? 'span' : 'a'); // When the content is not wrapped, and there is more than one element in the content (one of which is an icon),
78
+ // use span to wrap the content, so that the content in the span is vertically aligned
79
+
80
+ if (wrapped === content && icon) {
81
+ wrap(true, 'span');
82
+ }
83
+
72
84
  return wrapped;
73
85
  };
74
86
 
@@ -3,11 +3,20 @@ import React, { PureComponent } from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import { strings } from '@douyinfe/semi-foundation/lib/es/typography/constants';
5
5
  import Base from './base';
6
+ import cls from 'classnames';
7
+ import { cssClasses } from '@douyinfe/semi-foundation/lib/es/typography/constants';
8
+ const prefixCls = cssClasses.PREFIX;
6
9
  export default class Text extends PureComponent {
7
10
  render() {
11
+ const className = cls(this.props.className, {
12
+ ["".concat(prefixCls, "-text")]: true,
13
+ ["".concat(prefixCls, "-text-icon")]: this.props.icon
14
+ });
8
15
  return /*#__PURE__*/React.createElement(Base, _Object$assign({
9
16
  component: 'span'
10
- }, this.props));
17
+ }, this.props, {
18
+ className: className
19
+ }));
11
20
  }
12
21
 
13
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@douyinfe/semi-ui",
3
- "version": "2.15.0",
3
+ "version": "2.16.0-beta.0",
4
4
  "description": "",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/es/index.js",
@@ -15,11 +15,11 @@
15
15
  "dependencies": {
16
16
  "@babel/runtime-corejs3": "^7.15.4",
17
17
  "@douyinfe/semi-animation": "2.12.0",
18
- "@douyinfe/semi-animation-react": "2.15.0",
19
- "@douyinfe/semi-foundation": "2.15.0",
20
- "@douyinfe/semi-icons": "2.15.0",
18
+ "@douyinfe/semi-animation-react": "2.16.0-beta.0",
19
+ "@douyinfe/semi-foundation": "2.16.0-beta.0",
20
+ "@douyinfe/semi-icons": "2.16.0-beta.0",
21
21
  "@douyinfe/semi-illustrations": "2.15.0",
22
- "@douyinfe/semi-theme-default": "2.15.0",
22
+ "@douyinfe/semi-theme-default": "2.16.0-beta.0",
23
23
  "@types/react-window": "^1.8.2",
24
24
  "async-validator": "^3.5.0",
25
25
  "classnames": "^2.2.6",
@@ -69,13 +69,13 @@
69
69
  ],
70
70
  "author": "",
71
71
  "license": "MIT",
72
- "gitHead": "236be8e52864297171e3b08da20475139dadd633",
72
+ "gitHead": "e2cb837fd9d77bd14f32f8bee74c16bcdf0d9196",
73
73
  "devDependencies": {
74
74
  "@babel/plugin-proposal-decorators": "^7.15.8",
75
75
  "@babel/plugin-transform-runtime": "^7.15.8",
76
76
  "@babel/preset-env": "^7.15.8",
77
77
  "@babel/preset-react": "^7.14.5",
78
- "@douyinfe/semi-scss-compile": "2.15.0",
78
+ "@douyinfe/semi-scss-compile": "2.16.0-beta.0",
79
79
  "@storybook/addon-knobs": "^6.3.1",
80
80
  "@types/lodash": "^4.14.176",
81
81
  "babel-loader": "^8.2.2",
@@ -113,7 +113,8 @@ export const HorizontalSlider = () => (
113
113
  <div style={divStyle}>
114
114
  <div>marks</div>
115
115
  <Slider
116
- marks={{ 20: '20c', 40: '40c' }}
116
+ marks={{ 20: '20°C', 40: '40°C' }}
117
+ getAriaValueText={(value) => `${value}°C`}
117
118
  defaultValue={[0, 100]}
118
119
  range={true}
119
120
  onChange={value => {
@@ -124,7 +125,8 @@ export const HorizontalSlider = () => (
124
125
  <div style={divStyle}>
125
126
  <div>inclued</div>
126
127
  <Slider
127
- marks={{ 20: '20c', 40: '40c' }}
128
+ marks={{ 20: '20°C', 40: '40°C' }}
129
+ getAriaValueText={(value) => `${value}°C`}
128
130
  included={false}
129
131
  defaultValue={[0, 100]}
130
132
  range={true}