@semcore/tab-line 16.0.0-prerelease.4 → 16.0.0-prerelease.7

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,201 +1,248 @@
1
- import u from "@babel/runtime/helpers/esm/objectSpread2";
2
- import x from "@babel/runtime/helpers/esm/classCallCheck";
3
- import y from "@babel/runtime/helpers/esm/createClass";
4
- import d from "@babel/runtime/helpers/esm/assertThisInitialized";
5
- import I from "@babel/runtime/helpers/esm/inherits";
6
- import C from "@babel/runtime/helpers/esm/createSuper";
7
- import s from "@babel/runtime/helpers/esm/defineProperty";
8
- import { sstyled as h, createComponent as w, assignProps as b, Component as k } from "@semcore/core";
9
- import c from "react";
10
- import { Box as p } from "@semcore/flex-box";
11
- import P from "@semcore/core/lib/utils/addonTextChildren";
12
- import R from "@semcore/core/lib/utils/enhances/a11yEnhance";
13
- import L from "@semcore/neighbor-location";
14
- var z = (
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
4
+ import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
5
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
6
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
7
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
8
+ import { sstyled, createComponent, assignProps, Component } from "@semcore/core";
9
+ import React from "react";
10
+ import { Box } from "@semcore/flex-box";
11
+ import addonTextChildren from "@semcore/core/lib/utils/addonTextChildren";
12
+ import a11yEnhance from "@semcore/core/lib/utils/enhances/a11yEnhance";
13
+ import NeighborLocation from "@semcore/neighbor-location";
14
+ var style = (
15
15
  /*__reshadow_css_start__*/
16
- (h.insert(
16
+ (sstyled.insert(
17
17
  /*__inner_css_start__*/
18
18
  '.___STabLine_1239i_gg_{position:relative;display:flex;width:100%;max-width:100%}.___STabLine_1239i_gg_.__underlined_1239i_gg_{border-bottom:1px solid var(--intergalactic-border-primary, #c4c7cf)}.___STabLineItem_1239i_gg_{display:inline-flex;align-items:center;justify-content:center;position:relative;touch-action:manipulation;white-space:nowrap;-webkit-user-select:none;-moz-user-select:none;user-select:none;box-sizing:border-box;padding:0;margin:0;box-shadow:none;-webkit-text-decoration:none;text-decoration:none;-webkit-tap-highlight-color:transparent;overflow:visible;text-align:center;vertical-align:middle;font-family:inherit;cursor:pointer;border:0;background:0 0;color:var(--intergalactic-text-primary, #191b23);margin-right:var(--intergalactic-spacing-4x, 16px);font-weight:var(--intergalactic-medium, 500)}.___STabLineItem_1239i_gg_::-moz-focus-inner{border:0;padding:0}.___STabLineItem_1239i_gg_:active{-webkit-text-decoration:none;text-decoration:none}@media (hover:hover){.___STabLineItem_1239i_gg_:hover{-webkit-text-decoration:none;text-decoration:none}}.___STabLineItem_1239i_gg_::after,.___STabLineItem_1239i_gg_::before{content:"";position:absolute;left:0;bottom:-1px;height:3px;width:100%;background-color:transparent}.___STabLineItem_1239i_gg_::before{transition:background-color calc(var(--intergalactic-duration-control, 200)*1ms) ease-in-out}@media (hover:hover){.___STabLineItem_1239i_gg_:hover::before{background-color:var(--intergalactic-border-primary, #c4c7cf)}}.___STabLineItem_1239i_gg_.__selected_1239i_gg_::after{transition-delay:calc(var(--intergalactic-duration-control, 200)*1ms);background-color:var(--intergalactic-border-info-active, #006dca)}.___STabLineItem_1239i_gg_ .___SAddon_1239i_gg_:not(:last-child),.___STabLineItem_1239i_gg_ .___SText_1239i_gg_:not(:last-child){margin-right:var(--intergalactic-spacing-2x, 8px)}.___SCaret_1239i_gg_{position:absolute;bottom:-1px;height:3px;background-color:var(--intergalactic-border-info-active, #006dca);transition:calc(var(--intergalactic-duration-control, 200)*1ms) all ease-in-out}.___STabLineItem_1239i_gg_.__selected_1239i_gg_{flex-shrink:0}.___STabLineItem_1239i_gg_.__disabled_1239i_gg_{opacity:var(--intergalactic-disabled-opacity, 0.3);cursor:default;pointer-events:none}.___SText_1239i_gg_{display:inline-block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.___SAddon_1239i_gg_{display:inline-flex;align-items:center;justify-content:center}.___STabLineItem_1239i_gg_._size_m_1239i_gg_{height:28px;min-width:18px}.___STabLineItem_1239i_gg_._size_m_1239i_gg_ .___SText_1239i_gg_{font-size:var(--intergalactic-fs-200, 14px);line-height:var(--intergalactic-lh-200, 142%)}.___STabLineItem_1239i_gg_._size_l_1239i_gg_{height:40px;min-width:26px}.___STabLineItem_1239i_gg_._size_l_1239i_gg_ .___SText_1239i_gg_{font-size:var(--intergalactic-fs-300, 16px);line-height:var(--intergalactic-lh-300, 150%)}.___STabLineItem_1239i_gg_._neighborLocation_left_1239i_gg_{margin-right:0}@media (prefers-reduced-motion){.___STabLineItem_1239i_gg_.__selected_1239i_gg_::after,.___STabLineItem_1239i_gg_::after,.___STabLineItem_1239i_gg_::before{transition:none}.___SCaret_1239i_gg_{display:none}}',
19
19
  "1239i_gg_"
20
20
  ), {
21
- __STabLine: "___STabLine_1239i_gg_",
22
- _underlined: "__underlined_1239i_gg_",
23
- __SCaret: "___SCaret_1239i_gg_",
24
- __STabLineItem: "___STabLineItem_1239i_gg_",
25
- _selected: "__selected_1239i_gg_",
26
- _disabled: "__disabled_1239i_gg_",
27
- __SText: "___SText_1239i_gg_",
28
- __SAddon: "___SAddon_1239i_gg_",
29
- _neighborLocation_left: "_neighborLocation_left_1239i_gg_",
30
- _size_m: "_size_m_1239i_gg_",
31
- _size_l: "_size_l_1239i_gg_"
21
+ "__STabLine": "___STabLine_1239i_gg_",
22
+ "_underlined": "__underlined_1239i_gg_",
23
+ "__SCaret": "___SCaret_1239i_gg_",
24
+ "__STabLineItem": "___STabLineItem_1239i_gg_",
25
+ "_selected": "__selected_1239i_gg_",
26
+ "_disabled": "__disabled_1239i_gg_",
27
+ "__SText": "___SText_1239i_gg_",
28
+ "__SAddon": "___SAddon_1239i_gg_",
29
+ "_neighborLocation_left": "_neighborLocation_left_1239i_gg_",
30
+ "_size_m": "_size_m_1239i_gg_",
31
+ "_size_l": "_size_l_1239i_gg_"
32
32
  })
33
- ), A = {
34
- onNeighborChange: function(r, i) {
35
- r && (r.focus(), i.behavior === "auto" && r.click());
33
+ );
34
+ var optionsA11yEnhance = {
35
+ onNeighborChange: function onNeighborChange(neighborElement, props) {
36
+ if (neighborElement) {
37
+ neighborElement.focus();
38
+ if (props.behavior === "auto") {
39
+ neighborElement.click();
40
+ }
41
+ }
36
42
  },
37
43
  childSelector: ["role", "tab"]
38
- }, f = /* @__PURE__ */ function(_) {
39
- I(i, _);
40
- var r = C(i);
41
- function i() {
42
- var e;
43
- x(this, i);
44
- for (var t = arguments.length, n = new Array(t), o = 0; o < t; o++)
45
- n[o] = arguments[o];
46
- return e = r.call.apply(r, [this].concat(n)), s(d(e), "state", {
44
+ };
45
+ var TabLineRoot = /* @__PURE__ */ function(_Component) {
46
+ _inherits(TabLineRoot2, _Component);
47
+ var _super = _createSuper(TabLineRoot2);
48
+ function TabLineRoot2() {
49
+ var _this;
50
+ _classCallCheck(this, TabLineRoot2);
51
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
52
+ args[_key] = arguments[_key];
53
+ }
54
+ _this = _super.call.apply(_super, [this].concat(args));
55
+ _defineProperty(_assertThisInitialized(_this), "state", {
47
56
  animation: null
48
- }), s(d(e), "prevValue", void 0), s(d(e), "itemRefs", {}), s(d(e), "containerRef", /* @__PURE__ */ c.createRef()), s(d(e), "animationStartTimeout", -1), s(d(e), "handleAnimationStart", function() {
49
- var a;
50
- ((a = e.state.animation) === null || a === void 0 ? void 0 : a.started) === !1 && e.setState({
51
- animation: u(u({}, e.state.animation), {}, {
52
- started: !0
53
- })
54
- });
55
- }), s(d(e), "handleAnimationEnd", function() {
56
- e.setState({
57
+ });
58
+ _defineProperty(_assertThisInitialized(_this), "prevValue", void 0);
59
+ _defineProperty(_assertThisInitialized(_this), "itemRefs", {});
60
+ _defineProperty(_assertThisInitialized(_this), "containerRef", /* @__PURE__ */ React.createRef());
61
+ _defineProperty(_assertThisInitialized(_this), "animationStartTimeout", -1);
62
+ _defineProperty(_assertThisInitialized(_this), "handleAnimationStart", function() {
63
+ var _this$state$animation;
64
+ if (((_this$state$animation = _this.state.animation) === null || _this$state$animation === void 0 ? void 0 : _this$state$animation.started) === false) {
65
+ _this.setState({
66
+ animation: _objectSpread(_objectSpread({}, _this.state.animation), {}, {
67
+ started: true
68
+ })
69
+ });
70
+ }
71
+ });
72
+ _defineProperty(_assertThisInitialized(_this), "handleAnimationEnd", function() {
73
+ _this.setState({
57
74
  animation: null
58
75
  });
59
- }), s(d(e), "bindHandlerClick", function(a) {
60
- return function(l) {
61
- e.handlers.value(a, l);
76
+ });
77
+ _defineProperty(_assertThisInitialized(_this), "bindHandlerClick", function(value) {
78
+ return function(e) {
79
+ _this.handlers.value(value, e);
62
80
  };
63
- }), e;
81
+ });
82
+ return _this;
64
83
  }
65
- return y(i, [{
84
+ _createClass(TabLineRoot2, [{
66
85
  key: "uncontrolledProps",
67
- value: function() {
86
+ value: function uncontrolledProps() {
68
87
  return {
69
88
  value: null
70
89
  };
71
90
  }
72
91
  }, {
73
92
  key: "componentDidUpdate",
74
- value: function() {
75
- this.prevValue !== null && this.asProps.value !== null && this.prevValue !== this.asProps.value && this.animate(), this.prevValue = this.asProps.value;
93
+ value: function componentDidUpdate() {
94
+ if (this.prevValue !== null && this.asProps.value !== null && this.prevValue !== this.asProps.value) {
95
+ this.animate();
96
+ }
97
+ this.prevValue = this.asProps.value;
76
98
  }
77
99
  }, {
78
100
  key: "componentDidMount",
79
- value: function() {
101
+ value: function componentDidMount() {
80
102
  this.prevValue = this.asProps.value;
81
103
  }
82
104
  }, {
83
105
  key: "componentWillUnmount",
84
- value: function() {
106
+ value: function componentWillUnmount() {
85
107
  clearTimeout(this.animationStartTimeout);
86
108
  }
87
109
  }, {
88
110
  key: "animate",
89
- value: function() {
90
- var t = this.itemRefs[this.prevValue], n = this.itemRefs[this.asProps.value], o = this.containerRef.current;
91
- if (!(!t || !n || !o)) {
92
- var a = o.getBoundingClientRect(), l = t.getBoundingClientRect(), g = n.getBoundingClientRect(), m = {
93
- fromLeft: l.x - a.x,
94
- fromWidth: l.width,
95
- toLeft: g.x - a.x,
96
- toWidth: g.width,
97
- started: !1
98
- };
99
- this.setState({
100
- animation: m
101
- }), clearTimeout(this.animationStartTimeout), this.animationStartTimeout = setTimeout(this.handleAnimationStart, 0);
102
- }
111
+ value: function animate() {
112
+ var fromNode = this.itemRefs[this.prevValue];
113
+ var toNode = this.itemRefs[this.asProps.value];
114
+ var containerNode = this.containerRef.current;
115
+ if (!fromNode || !toNode || !containerNode) return;
116
+ var containerRect = containerNode.getBoundingClientRect();
117
+ var fromRect = fromNode.getBoundingClientRect();
118
+ var toRect = toNode.getBoundingClientRect();
119
+ var animation = {
120
+ fromLeft: fromRect.x - containerRect.x,
121
+ fromWidth: fromRect.width,
122
+ toLeft: toRect.x - containerRect.x,
123
+ toWidth: toRect.width,
124
+ started: false
125
+ };
126
+ this.setState({
127
+ animation
128
+ });
129
+ clearTimeout(this.animationStartTimeout);
130
+ this.animationStartTimeout = setTimeout(this.handleAnimationStart, 0);
103
131
  }
104
132
  }, {
105
133
  key: "getItemProps",
106
- value: function(t, n) {
107
- var o = this, a = this.asProps, l = a.value, g = a.size, m = l === t.value;
134
+ value: function getItemProps(props, index) {
135
+ var _this2 = this;
136
+ var _this$asProps = this.asProps, value = _this$asProps.value, size = _this$asProps.size;
137
+ var isSelected = value === props.value;
108
138
  return {
109
- size: g,
110
- selected: m,
111
- onClick: this.bindHandlerClick(t.value),
112
- tabIndex: m ? 0 : -1,
113
- "aria-selected": m,
114
- ref: function(S) {
115
- o.itemRefs[t.value] = S;
139
+ size,
140
+ selected: isSelected,
141
+ onClick: this.bindHandlerClick(props.value),
142
+ tabIndex: isSelected ? 0 : -1,
143
+ "aria-selected": isSelected,
144
+ ref: function ref(node) {
145
+ _this2.itemRefs[props.value] = node;
116
146
  }
117
147
  };
118
148
  }
119
149
  }, {
120
150
  key: "getCaretProps",
121
- value: function() {
122
- var t = this.state.animation;
123
- return t ? t.started ? {
124
- style: {
125
- left: t.toLeft,
126
- width: t.toWidth
127
- },
128
- onTransitionEnd: this.handleAnimationEnd
129
- } : {
130
- style: {
131
- left: t.fromLeft,
132
- width: t.fromWidth
133
- },
134
- onTransitionEnd: this.handleAnimationEnd
135
- } : {};
151
+ value: function getCaretProps() {
152
+ var animation = this.state.animation;
153
+ if (!animation) return {};
154
+ if (animation.started) {
155
+ return {
156
+ style: {
157
+ left: animation.toLeft,
158
+ width: animation.toWidth
159
+ },
160
+ onTransitionEnd: this.handleAnimationEnd
161
+ };
162
+ } else {
163
+ return {
164
+ style: {
165
+ left: animation.fromLeft,
166
+ width: animation.fromWidth
167
+ },
168
+ onTransitionEnd: this.handleAnimationEnd
169
+ };
170
+ }
136
171
  }
137
172
  }, {
138
173
  key: "render",
139
- value: function() {
140
- var t = this.asProps, n, o = p, a = "div", l = this.asProps, g = l.styles, m = l.Children, T = l.controlsLength, S = this.state.animation;
141
- return n = h(g), /* @__PURE__ */ c.createElement(o, n.cn("STabLine", u({}, b({
142
- role: "tablist",
143
- ref: this.containerRef
144
- }, t))), /* @__PURE__ */ c.createElement(L, n.cn("NeighborLocation", {
145
- controlsLength: T
146
- }), /* @__PURE__ */ c.createElement(m, n.cn("Children", {}))), S && /* @__PURE__ */ c.createElement(a, n.cn("SCaret", u({}, this.getCaretProps()))));
174
+ value: function render() {
175
+ var _ref = this.asProps, _ref5;
176
+ var STabLine = Box;
177
+ var SCaret = "div";
178
+ var _this$asProps2 = this.asProps, styles = _this$asProps2.styles, Children = _this$asProps2.Children, controlsLength = _this$asProps2.controlsLength;
179
+ var animation = this.state.animation;
180
+ return _ref5 = sstyled(styles), /* @__PURE__ */ React.createElement(STabLine, _ref5.cn("STabLine", _objectSpread({}, assignProps({
181
+ "role": "tablist",
182
+ "ref": this.containerRef
183
+ }, _ref))), /* @__PURE__ */ React.createElement(NeighborLocation, _ref5.cn("NeighborLocation", {
184
+ "controlsLength": controlsLength
185
+ }), /* @__PURE__ */ React.createElement(Children, _ref5.cn("Children", {}))), animation && /* @__PURE__ */ React.createElement(SCaret, _ref5.cn("SCaret", _objectSpread({}, this.getCaretProps()))));
147
186
  }
148
- }]), i;
149
- }(k);
150
- s(f, "displayName", "TabLine");
151
- s(f, "style", z);
152
- s(f, "defaultProps", {
187
+ }]);
188
+ return TabLineRoot2;
189
+ }(Component);
190
+ _defineProperty(TabLineRoot, "displayName", "TabLine");
191
+ _defineProperty(TabLineRoot, "style", style);
192
+ _defineProperty(TabLineRoot, "defaultProps", {
153
193
  defaultValue: null,
154
194
  size: "m",
155
- underlined: !0,
195
+ underlined: true,
156
196
  behavior: "auto"
157
197
  });
158
- s(f, "enhance", [R(A)]);
159
- function E(_) {
160
- var r = arguments[0], i = p, e = _.Children, t = _.styles, n = _.addonLeft, o = _.addonRight, a = _.neighborLocation;
161
- return /* @__PURE__ */ c.createElement(L.Detect, {
162
- neighborLocation: a
163
- }, function(l) {
164
- var g;
165
- return g = h(t), /* @__PURE__ */ c.createElement(i, g.cn("STabLineItem", u({}, b({
166
- tag: "button",
167
- tabIndex: 0,
168
- neighborLocation: l,
169
- type: "button",
170
- role: "tab"
171
- }, r))), n ? /* @__PURE__ */ c.createElement(v.Item.Addon, {
172
- tag: n
173
- }) : null, P(e, v.Item.Text, v.Item.Addon), o ? /* @__PURE__ */ c.createElement(v.Item.Addon, {
174
- tag: o
198
+ _defineProperty(TabLineRoot, "enhance", [a11yEnhance(optionsA11yEnhance)]);
199
+ function TabLineItem(props) {
200
+ var _ref2 = arguments[0];
201
+ var STabLineItem = Box;
202
+ var Children = props.Children, styles = props.styles, addonLeft = props.addonLeft, addonRight = props.addonRight, neighborLocation = props.neighborLocation;
203
+ return /* @__PURE__ */ React.createElement(NeighborLocation.Detect, {
204
+ neighborLocation
205
+ }, function(neighborLocation2) {
206
+ var _ref6;
207
+ return _ref6 = sstyled(styles), /* @__PURE__ */ React.createElement(STabLineItem, _ref6.cn("STabLineItem", _objectSpread({}, assignProps({
208
+ "tag": "button",
209
+ "tabIndex": 0,
210
+ "neighborLocation": neighborLocation2,
211
+ "type": "button",
212
+ "role": "tab"
213
+ }, _ref2))), addonLeft ? /* @__PURE__ */ React.createElement(TabLine.Item.Addon, {
214
+ tag: addonLeft
215
+ }) : null, addonTextChildren(Children, TabLine.Item.Text, TabLine.Item.Addon), addonRight ? /* @__PURE__ */ React.createElement(TabLine.Item.Addon, {
216
+ tag: addonRight
175
217
  }) : null);
176
218
  });
177
219
  }
178
- function N(_) {
179
- var r = arguments[0], i, e = _.styles, t = p;
180
- return i = h(e), /* @__PURE__ */ c.createElement(t, i.cn("SText", u({}, b({
181
- tag: "span"
182
- }, r))));
220
+ function Text(props) {
221
+ var _ref3 = arguments[0], _ref7;
222
+ var styles = props.styles;
223
+ var SText = Box;
224
+ return _ref7 = sstyled(styles), /* @__PURE__ */ React.createElement(SText, _ref7.cn("SText", _objectSpread({}, assignProps({
225
+ "tag": "span"
226
+ }, _ref3))));
183
227
  }
184
- function V(_) {
185
- var r = arguments[0], i, e = _.styles, t = p;
186
- return i = h(e), /* @__PURE__ */ c.createElement(t, i.cn("SAddon", u({}, b({
187
- tag: "span"
188
- }, r))));
228
+ function Addon(props) {
229
+ var _ref4 = arguments[0], _ref8;
230
+ var styles = props.styles;
231
+ var SAddon = Box;
232
+ return _ref8 = sstyled(styles), /* @__PURE__ */ React.createElement(SAddon, _ref8.cn("SAddon", _objectSpread({}, assignProps({
233
+ "tag": "span"
234
+ }, _ref4))));
189
235
  }
190
- var v = w(f, {
191
- Item: [E, {
192
- Text: N,
193
- Addon: V
236
+ var TabLine = createComponent(TabLineRoot, {
237
+ Item: [TabLineItem, {
238
+ Text,
239
+ Addon
194
240
  }]
195
- }), O = function(r) {
196
- return r;
241
+ });
242
+ var wrapTabLine = function wrapTabLine2(wrapper) {
243
+ return wrapper;
197
244
  };
198
245
  export {
199
- v as default,
200
- O as wrapTabLine
246
+ TabLine as default,
247
+ wrapTabLine
201
248
  };
package/lib/esm/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { default as r, wrapTabLine as f } from "./TabLine.mjs";
1
+ import { default as default2, wrapTabLine } from "./TabLine.mjs";
2
2
  export {
3
- r as default,
4
- f as wrapTabLine
3
+ default2 as default,
4
+ wrapTabLine
5
5
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@semcore/tab-line",
3
3
  "description": "Semrush TabLine Component",
4
- "version": "16.0.0-prerelease.4",
4
+ "version": "16.0.0-prerelease.7",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/es6/index.js",
7
7
  "typings": "lib/types/index.d.ts",
@@ -14,11 +14,11 @@
14
14
  "types": "./lib/types/index.d.ts"
15
15
  },
16
16
  "dependencies": {
17
- "@semcore/flex-box": "16.0.0-prerelease.4",
18
- "@semcore/neighbor-location": "16.0.0-prerelease.4"
17
+ "@semcore/flex-box": "16.0.0-prerelease.7",
18
+ "@semcore/neighbor-location": "16.0.0-prerelease.7"
19
19
  },
20
20
  "peerDependencies": {
21
- "@semcore/base-components": "^16.0.0-prerelease.4"
21
+ "@semcore/base-components": "^16.0.0-prerelease.7"
22
22
  },
23
23
  "repository": {
24
24
  "type": "git",