@douyinfe/semi-ui 2.27.0-alpha.0 → 2.27.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.
@@ -1,88 +1,78 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import cls from 'classnames';
4
- import { cssClasses, strings } from '@douyinfe/semi-foundation/lib/es/tabs/constants';
5
- import { IconClose } from '@douyinfe/semi-icons';
6
- export default class TabItem extends React.Component {
7
- constructor() {
8
- super(...arguments);
1
+ var __rest = this && this.__rest || function (s, e) {
2
+ var t = {};
9
3
 
10
- this.handleKeyDown = event => {
11
- const {
12
- itemKey,
13
- closable,
14
- handleKeyDown
15
- } = this.props;
16
- handleKeyDown && handleKeyDown(event, itemKey, closable);
17
- };
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
18
5
 
19
- this.handleClick = e => {
20
- const {
21
- itemKey,
22
- onClick,
23
- disabled
24
- } = this.props;
25
- !disabled && onClick && onClick(itemKey, e);
26
- };
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
27
8
  }
9
+ return t;
10
+ };
28
11
 
29
- renderIcon(icon) {
30
- return /*#__PURE__*/React.createElement("span", null, icon);
31
- }
12
+ import React, { forwardRef, useCallback, useMemo } from 'react';
13
+ import cls from 'classnames';
14
+ import { cssClasses } from '@douyinfe/semi-foundation/lib/es/tabs/constants';
15
+ import { IconClose } from '@douyinfe/semi-icons';
32
16
 
33
- render() {
34
- const {
35
- tab,
36
- size,
37
- type,
38
- icon,
39
- selected,
40
- closable,
41
- disabled,
42
- itemKey,
43
- deleteTabItem,
44
- tabPosition
45
- } = this.props;
46
- const panelIcon = icon ? this.renderIcon(icon) : null;
47
- const className = cls(cssClasses.TABS_TAB, "".concat(cssClasses.TABS_TAB, "-").concat(type), "".concat(cssClasses.TABS_TAB, "-").concat(tabPosition), "".concat(cssClasses.TABS_TAB, "-single"), {
48
- [cssClasses.TABS_TAB_ACTIVE]: selected,
49
- [cssClasses.TABS_TAB_DISABLED]: disabled,
50
- ["".concat(cssClasses.TABS_TAB, "-small")]: size === 'small',
51
- ["".concat(cssClasses.TABS_TAB, "-medium")]: size === 'medium'
52
- });
53
- const closableIcon = type === 'card' && closable ? /*#__PURE__*/React.createElement(IconClose, {
17
+ const TabItem = (props, ref) => {
18
+ const {
19
+ tab,
20
+ size,
21
+ type,
22
+ icon,
23
+ selected,
24
+ closable,
25
+ disabled,
26
+ itemKey,
27
+ deleteTabItem,
28
+ tabPosition,
29
+ handleKeyDown,
30
+ onClick
31
+ } = props,
32
+ resetProps = __rest(props, ["tab", "size", "type", "icon", "selected", "closable", "disabled", "itemKey", "deleteTabItem", "tabPosition", "handleKeyDown", "onClick"]);
33
+
34
+ const closableIcon = useMemo(() => {
35
+ return type === 'card' && closable ? /*#__PURE__*/React.createElement(IconClose, {
54
36
  "aria-label": "Close",
55
37
  role: "button",
56
38
  className: "".concat(cssClasses.TABS_TAB, "-icon-close"),
57
39
  onClick: e => deleteTabItem(itemKey, e)
58
40
  }) : null;
59
- return /*#__PURE__*/React.createElement("div", {
60
- role: "tab",
61
- id: "semiTab".concat(itemKey),
62
- "data-tabkey": "semiTab".concat(itemKey),
63
- "aria-controls": "semiTabPanel".concat(itemKey),
64
- "aria-disabled": disabled ? 'true' : 'false',
65
- "aria-selected": selected ? 'true' : 'false',
66
- tabIndex: selected ? 0 : -1,
67
- onKeyDown: this.handleKeyDown,
68
- onClick: this.handleClick,
69
- className: className
70
- }, panelIcon, tab, closableIcon);
71
- }
41
+ }, [type, closable, deleteTabItem, itemKey]);
42
+ const renderIcon = useCallback(icon => /*#__PURE__*/React.createElement("span", null, icon), []);
43
+ const handleKeyDownInItem = useCallback(event => {
44
+ handleKeyDown && handleKeyDown(event, itemKey, closable);
45
+ }, [handleKeyDown, itemKey, closable]);
46
+ const handleItemClick = useCallback(e => {
47
+ !disabled && onClick && onClick(itemKey, e);
48
+ }, [itemKey, disabled, onClick]);
49
+ const panelIcon = icon ? renderIcon(icon) : null;
50
+ const className = cls(cssClasses.TABS_TAB, "".concat(cssClasses.TABS_TAB, "-").concat(type), "".concat(cssClasses.TABS_TAB, "-").concat(tabPosition), "".concat(cssClasses.TABS_TAB, "-single"), {
51
+ [cssClasses.TABS_TAB_ACTIVE]: selected,
52
+ [cssClasses.TABS_TAB_DISABLED]: disabled,
53
+ ["".concat(cssClasses.TABS_TAB, "-small")]: size === 'small',
54
+ ["".concat(cssClasses.TABS_TAB, "-medium")]: size === 'medium'
55
+ });
56
+ return /*#__PURE__*/React.createElement("div", Object.assign({
57
+ role: "tab",
58
+ id: "semiTab".concat(itemKey),
59
+ "data-tabkey": "semiTab".concat(itemKey),
60
+ "aria-controls": "semiTabPanel".concat(itemKey),
61
+ "aria-disabled": disabled ? 'true' : 'false',
62
+ "aria-selected": selected ? 'true' : 'false',
63
+ tabIndex: selected ? 0 : -1,
64
+ onKeyDown: handleKeyDownInItem,
65
+ onClick: handleItemClick,
66
+ className: className
67
+ }, resetProps, {
68
+ ref: ref
69
+ }), panelIcon, tab, closableIcon);
70
+ }; // Why is forwardRef needed here?
71
+ // Because TabItem needs to be used in OverflowList (when tabs' type is collapsible),
72
+ // OverflowList will pass ref to the outermost div DOM node of TabItem
72
73
 
73
- }
74
- TabItem.propsTypes = {
75
- tab: PropTypes.node,
76
- icon: PropTypes.node,
77
- size: PropTypes.oneOf(strings.SIZE),
78
- type: PropTypes.oneOf(strings.TYPE_MAP),
79
- tabPosition: PropTypes.oneOf(strings.POSITION_MAP),
80
- selected: PropTypes.bool,
81
- closable: PropTypes.bool,
82
- disabled: PropTypes.bool,
83
- itemKey: PropTypes.string,
84
- handleKeyDown: PropTypes.func,
85
- deleteTabItem: PropTypes.func,
86
- onClick: PropTypes.func
87
- };
88
- TabItem.elementType = 'TabItem';
74
+
75
+ const ForwardTabItem = /*#__PURE__*/forwardRef(TabItem); // @ts-ignore
76
+
77
+ ForwardTabItem.elementType = 'TabItem';
78
+ export default ForwardTabItem;
@@ -1,10 +1,9 @@
1
- import { MouseEvent, ReactElement, ReactNode, RefCallback, RefObject } from 'react';
1
+ import React, { MouseEvent, ReactElement, ReactNode, RefCallback, RefObject } from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import TabsFoundation, { TabsAdapter } from '@douyinfe/semi-foundation/lib/es/tabs/foundation';
4
4
  import BaseComponent from '../_base/baseComponent';
5
5
  import '@douyinfe/semi-foundation/lib/es/tabs/tabs.css';
6
6
  import TabPane from './TabPane';
7
- import TabItem from './TabItem';
8
7
  import { PlainTab, TabsProps } from './interface';
9
8
  export * from './interface';
10
9
  export interface TabsState {
@@ -15,7 +14,7 @@ export interface TabsState {
15
14
  }
16
15
  declare class Tabs extends BaseComponent<TabsProps, TabsState> {
17
16
  static TabPane: typeof TabPane;
18
- static TabItem: typeof TabItem;
17
+ static TabItem: React.ForwardRefExoticComponent<import("./TabItem").TabItemProps & React.RefAttributes<HTMLDivElement>>;
19
18
  static propTypes: {
20
19
  activeKey: PropTypes.Requireable<string>;
21
20
  className: PropTypes.Requireable<string>;
@@ -90,7 +90,7 @@ export default class Tooltip extends BaseComponent<TooltipProps, TooltipState> {
90
90
  getPopupContainer: PropTypes.Requireable<(...args: any[]) => any>;
91
91
  mouseEnterDelay: PropTypes.Requireable<number>;
92
92
  mouseLeaveDelay: PropTypes.Requireable<number>;
93
- trigger: PropTypes.Validator<NonNullable<"click" | "focus" | "hover" | "custom">>;
93
+ trigger: PropTypes.Validator<NonNullable<"hover" | "focus" | "click" | "custom">>;
94
94
  className: PropTypes.Requireable<string>;
95
95
  wrapperClassName: PropTypes.Requireable<string>;
96
96
  clickToHide: PropTypes.Requireable<boolean>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@douyinfe/semi-ui",
3
- "version": "2.27.0-alpha.0",
3
+ "version": "2.27.0-alpha.1",
4
4
  "description": "",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/es/index.js",
@@ -17,12 +17,12 @@
17
17
  "lib/*"
18
18
  ],
19
19
  "dependencies": {
20
- "@douyinfe/semi-animation": "2.27.0-alpha.0",
21
- "@douyinfe/semi-animation-react": "2.27.0-alpha.0",
22
- "@douyinfe/semi-foundation": "2.27.0-alpha.0",
23
- "@douyinfe/semi-icons": "2.27.0-alpha.0",
24
- "@douyinfe/semi-illustrations": "2.27.0-alpha.0",
25
- "@douyinfe/semi-theme-default": "2.27.0-alpha.0",
20
+ "@douyinfe/semi-animation": "2.27.0-alpha.1",
21
+ "@douyinfe/semi-animation-react": "2.27.0-alpha.1",
22
+ "@douyinfe/semi-foundation": "2.27.0-alpha.1",
23
+ "@douyinfe/semi-icons": "2.27.0-alpha.1",
24
+ "@douyinfe/semi-illustrations": "2.27.0-alpha.1",
25
+ "@douyinfe/semi-theme-default": "2.27.0-alpha.1",
26
26
  "async-validator": "^3.5.0",
27
27
  "classnames": "^2.2.6",
28
28
  "copy-text-to-clipboard": "^2.1.1",
@@ -69,7 +69,7 @@
69
69
  ],
70
70
  "author": "",
71
71
  "license": "MIT",
72
- "gitHead": "3e818e5687041820aab8c5094c3b6fae7c8f2049",
72
+ "gitHead": "45aa538331cc89a4e1e75f9c8ac9e4dcf59eeb3a",
73
73
  "devDependencies": {
74
74
  "@babel/plugin-proposal-decorators": "^7.15.8",
75
75
  "@babel/plugin-transform-runtime": "^7.15.8",