@semcore/pills 16.0.0-prerelease.6 → 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.
package/lib/esm/Pills.mjs CHANGED
@@ -1,155 +1,195 @@
1
- import u from "@babel/runtime/helpers/esm/objectSpread2";
2
- import z from "@babel/runtime/helpers/esm/classCallCheck";
3
- import w from "@babel/runtime/helpers/esm/createClass";
4
- import p from "@babel/runtime/helpers/esm/assertThisInitialized";
5
- import L from "@babel/runtime/helpers/esm/inherits";
6
- import A from "@babel/runtime/helpers/esm/createSuper";
7
- import d from "@babel/runtime/helpers/esm/defineProperty";
8
- import { sstyled as f, createComponent as k, assignProps as P, Component as C } from "@semcore/core";
9
- import s from "react";
10
- import { Box as S } from "@semcore/flex-box";
11
- import T, { useNeighborLocationDetect as E } from "@semcore/neighbor-location";
12
- import D from "@semcore/core/lib/utils/addonTextChildren";
13
- import N from "@semcore/core/lib/utils/enhances/a11yEnhance";
14
- import y from "@semcore/core/lib/utils/logger";
15
- var R = (
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 NeighborLocation, { useNeighborLocationDetect } from "@semcore/neighbor-location";
12
+ import addonTextChildren from "@semcore/core/lib/utils/addonTextChildren";
13
+ import a11yEnhance from "@semcore/core/lib/utils/enhances/a11yEnhance";
14
+ import log from "@semcore/core/lib/utils/logger";
15
+ var style = (
16
16
  /*__reshadow_css_start__*/
17
- (f.insert(
17
+ (sstyled.insert(
18
18
  /*__inner_css_start__*/
19
19
  ".___SPill_1m0ra_gg_,.___SPills_1m0ra_gg_{display:inline-flex;align-items:center;justify-content:center;border-radius:var(--intergalactic-control-rounded, 6px)}.___SPills_1m0ra_gg_{isolation:isolate}.___SPill_1m0ra_gg_{line-height:normal;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;background:var(--intergalactic-bg-primary-neutral, #ffffff);border:1px solid var(--intergalactic-border-primary, #c4c7cf)}.___SPill_1m0ra_gg_::-moz-focus-inner{border:0;padding:0}.___SPill_1m0ra_gg_:active{outline:0;-webkit-text-decoration:none;text-decoration:none}@media (hover:hover){.___SPill_1m0ra_gg_:hover{outline:0;-webkit-text-decoration:none;text-decoration:none;background:var(--intergalactic-bg-primary-neutral-hover, #f4f5f9)}}.___SPill_1m0ra_gg_.__selected_1m0ra_gg_{background:var(--intergalactic-control-secondary-info, rgba(0, 143, 248, 0.1));border-color:var(--intergalactic-border-info-active, #006dca)}.___SPill_1m0ra_gg_:active,.___SPill_1m0ra_gg_:focus-visible{z-index:1}@media (hover:hover){.___SPill_1m0ra_gg_:hover{z-index:1}}.___SPill_1m0ra_gg_.__disabled_1m0ra_gg_{cursor:default;pointer-events:none}.___SPill_1m0ra_gg_.__disabled_1m0ra_gg_>*{opacity:var(--intergalactic-disabled-opacity, 0.3)}.___SText_1m0ra_gg_{color:var(--intergalactic-text-primary, #191b23);display:inline-flex}.___SAddon_1m0ra_gg_{color:var(--intergalactic-text-secondary, #6c6e79);display:inline-flex;align-items:center;justify-content:center}.___SPill_1m0ra_gg_._size_m_1m0ra_gg_{height:var(--intergalactic-form-control-m, 28px);min-width:var(--intergalactic-form-control-m, 28px);font-size:var(--intergalactic-fs-200, 14px)}.___SPill_1m0ra_gg_._size_l_1m0ra_gg_ .___SText_1m0ra_gg_,.___SPill_1m0ra_gg_._size_m_1m0ra_gg_ .___SText_1m0ra_gg_{margin-left:var(--intergalactic-spacing-2x, 8px);margin-right:var(--intergalactic-spacing-2x, 8px)}.___SPill_1m0ra_gg_._size_m_1m0ra_gg_ .___SAddon_1m0ra_gg_:not(:only-child):first-child{margin-left:var(--intergalactic-spacing-2x, 8px)}.___SPill_1m0ra_gg_._size_m_1m0ra_gg_ .___SAddon_1m0ra_gg_:not(:only-child):last-child{margin-right:var(--intergalactic-spacing-2x, 8px)}.___SPill_1m0ra_gg_._size_m_1m0ra_gg_ .___SAddon_1m0ra_gg_:only-child{margin-left:var(--intergalactic-spacing-2x, 8px);margin-right:var(--intergalactic-spacing-2x, 8px)}.___SPill_1m0ra_gg_._size_l_1m0ra_gg_{height:var(--intergalactic-form-control-l, 40px);min-width:var(--intergalactic-form-control-l, 40px);font-size:var(--intergalactic-fs-300, 16px)}.___SPill_1m0ra_gg_._size_l_1m0ra_gg_ .___SAddon_1m0ra_gg_:only-child,.___SPill_1m0ra_gg_._size_l_1m0ra_gg_ .___SText_1m0ra_gg_:only-child{margin-left:var(--intergalactic-spacing-3x, 12px);margin-right:var(--intergalactic-spacing-3x, 12px)}.___SPill_1m0ra_gg_._size_l_1m0ra_gg_ .___SAddon_1m0ra_gg_:not(:only-child):first-child{margin-left:var(--intergalactic-spacing-3x, 12px)}.___SPill_1m0ra_gg_._size_l_1m0ra_gg_ .___SAddon_1m0ra_gg_:not(:only-child):last-child{margin-right:var(--intergalactic-spacing-3x, 12px)}.___SPill_1m0ra_gg_._neighborLocation_right_1m0ra_gg_{border-top-right-radius:0;border-bottom-right-radius:0}.___SPill_1m0ra_gg_._neighborLocation_both_1m0ra_gg_{border-radius:0;margin-left:-1px}.___SPill_1m0ra_gg_._neighborLocation_left_1m0ra_gg_{border-top-left-radius:0;border-bottom-left-radius:0;margin-left:-1px}",
20
20
  "1m0ra_gg_"
21
21
  ), {
22
- __SPills: "___SPills_1m0ra_gg_",
23
- __SPill: "___SPill_1m0ra_gg_",
24
- _selected: "__selected_1m0ra_gg_",
25
- __SText: "___SText_1m0ra_gg_",
26
- __SAddon: "___SAddon_1m0ra_gg_",
27
- _neighborLocation_right: "_neighborLocation_right_1m0ra_gg_",
28
- _neighborLocation_both: "_neighborLocation_both_1m0ra_gg_",
29
- _neighborLocation_left: "_neighborLocation_left_1m0ra_gg_",
30
- _disabled: "__disabled_1m0ra_gg_",
31
- _size_m: "_size_m_1m0ra_gg_",
32
- _size_l: "_size_l_1m0ra_gg_"
22
+ "__SPills": "___SPills_1m0ra_gg_",
23
+ "__SPill": "___SPill_1m0ra_gg_",
24
+ "_selected": "__selected_1m0ra_gg_",
25
+ "__SText": "___SText_1m0ra_gg_",
26
+ "__SAddon": "___SAddon_1m0ra_gg_",
27
+ "_neighborLocation_right": "_neighborLocation_right_1m0ra_gg_",
28
+ "_neighborLocation_both": "_neighborLocation_both_1m0ra_gg_",
29
+ "_neighborLocation_left": "_neighborLocation_left_1m0ra_gg_",
30
+ "_disabled": "__disabled_1m0ra_gg_",
31
+ "_size_m": "_size_m_1m0ra_gg_",
32
+ "_size_l": "_size_l_1m0ra_gg_"
33
33
  })
34
- ), j = {
35
- onNeighborChange: function(r, _) {
36
- r && (r.focus(), (_.behavior === "auto" || _.behavior === "radio") && r.click());
34
+ );
35
+ var optionsA11yEnhance = {
36
+ onNeighborChange: function onNeighborChange(neighborElement, props) {
37
+ if (neighborElement) {
38
+ neighborElement.focus();
39
+ if (props.behavior === "auto" || props.behavior === "radio") {
40
+ neighborElement.click();
41
+ }
42
+ }
37
43
  },
38
- childSelector: function(r) {
39
- return r.behavior === "auto" || r.behavior === "radio" ? ["role", "radio"] : ["role", "tab"];
44
+ childSelector: function childSelector(props) {
45
+ return props.behavior === "auto" || props.behavior === "radio" ? ["role", "radio"] : ["role", "tab"];
40
46
  }
41
- }, v = /* @__PURE__ */ function(a) {
42
- L(_, a);
43
- var r = A(_);
44
- function _() {
45
- var i;
46
- z(this, _);
47
- for (var l = arguments.length, o = new Array(l), n = 0; n < l; n++)
48
- o[n] = arguments[n];
49
- return i = r.call.apply(r, [this].concat(o)), d(p(i), "itemValues", []), d(p(i), "bindHandlerClick", function(e) {
50
- return function(t) {
51
- i.handlers.value(e, t);
47
+ };
48
+ var RootPills = /* @__PURE__ */ function(_Component) {
49
+ _inherits(RootPills2, _Component);
50
+ var _super = _createSuper(RootPills2);
51
+ function RootPills2() {
52
+ var _this;
53
+ _classCallCheck(this, RootPills2);
54
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
55
+ args[_key] = arguments[_key];
56
+ }
57
+ _this = _super.call.apply(_super, [this].concat(args));
58
+ _defineProperty(_assertThisInitialized(_this), "itemValues", []);
59
+ _defineProperty(_assertThisInitialized(_this), "bindHandlerClick", function(value) {
60
+ return function(e) {
61
+ _this.handlers.value(value, e);
52
62
  };
53
- }), d(p(i), "bindHandleKeyDown", function(e) {
54
- return function(t) {
55
- (t.key === "Enter" || t.key === " ") && (t.preventDefault(), i.handlers.value(e, t));
63
+ });
64
+ _defineProperty(_assertThisInitialized(_this), "bindHandleKeyDown", function(value) {
65
+ return function(event) {
66
+ if (event.key === "Enter" || event.key === " ") {
67
+ event.preventDefault();
68
+ _this.handlers.value(value, event);
69
+ }
56
70
  };
57
- }), d(p(i), "changeIndex", function(e, t) {
58
- for (var c = !1; !c && e >= 0 && e < i.itemValues.length; ) {
59
- t === "increment" && e++, t === "decrement" && e--;
60
- var g = i.itemRefs[e];
61
- (g == null ? void 0 : g.disabled) === !1 && (c = !0);
71
+ });
72
+ _defineProperty(_assertThisInitialized(_this), "changeIndex", function(startIndex, type) {
73
+ var selectable = false;
74
+ while (!selectable && startIndex >= 0 && startIndex < _this.itemValues.length) {
75
+ if (type === "increment") startIndex++;
76
+ if (type === "decrement") startIndex--;
77
+ var element = _this.itemRefs[startIndex];
78
+ if ((element === null || element === void 0 ? void 0 : element.disabled) === false) {
79
+ selectable = true;
80
+ }
62
81
  }
63
- return e >= 0 && e < i.itemValues.length ? e : void 0;
64
- }), i;
82
+ return startIndex >= 0 && startIndex < _this.itemValues.length ? startIndex : void 0;
83
+ });
84
+ return _this;
65
85
  }
66
- return w(_, [{
86
+ _createClass(RootPills2, [{
67
87
  key: "componentDidMount",
68
- value: function() {
69
- y.warn(this.asProps.behavior === "tabs", "Use behavior `manual` instead of `tabs`. \n`tabs` is deprecated and will be removed in the next major release.", "Pills"), y.warn(this.asProps.behavior === "radio", "Use behavior `auto` (or nothing, it is default value) instead of `radio`. \n`radio` is deprecated and will be removed in the next major release.", "Pills");
88
+ value: function componentDidMount() {
89
+ log.warn(this.asProps.behavior === "tabs", "Use behavior `manual` instead of `tabs`. \n`tabs` is deprecated and will be removed in the next major release.", "Pills");
90
+ log.warn(this.asProps.behavior === "radio", "Use behavior `auto` (or nothing, it is default value) instead of `radio`. \n`radio` is deprecated and will be removed in the next major release.", "Pills");
70
91
  }
71
92
  }, {
72
93
  key: "uncontrolledProps",
73
- value: function() {
94
+ value: function uncontrolledProps() {
74
95
  return {
75
96
  value: null
76
97
  };
77
98
  }
78
99
  }, {
79
100
  key: "getItemProps",
80
- value: function(l, o) {
81
- var n = this.asProps, e = n.value, t = n.size, c = n.disabled, g = n.behavior, m = e === l.value;
82
- return this.itemValues[o] = l.value, {
83
- index: o,
84
- size: t,
85
- disabled: c,
86
- selected: m,
87
- behavior: g,
88
- tabIndex: m ? 0 : -1,
89
- onClick: this.bindHandlerClick(l.value),
90
- onKeyDown: this.bindHandleKeyDown(l.value)
101
+ value: function getItemProps(props, index) {
102
+ var _this$asProps = this.asProps, value = _this$asProps.value, size = _this$asProps.size, disabled = _this$asProps.disabled, behavior = _this$asProps.behavior;
103
+ var isSelected = value === props.value;
104
+ this.itemValues[index] = props.value;
105
+ return {
106
+ index,
107
+ size,
108
+ disabled,
109
+ selected: isSelected,
110
+ behavior,
111
+ tabIndex: isSelected ? 0 : -1,
112
+ onClick: this.bindHandlerClick(props.value),
113
+ onKeyDown: this.bindHandleKeyDown(props.value)
91
114
  };
92
115
  }
93
116
  }, {
94
117
  key: "render",
95
- value: function() {
96
- var l = this.asProps, o, n = S, e = this.asProps, t = e.Children, c = e.styles, g = e.controlsLength, m = e.disabled, b = e.behavior, h = e.value;
97
- return o = f(c), /* @__PURE__ */ s.createElement(n, o.cn("SPills", u({}, P({
98
- role: b === "radio" || b === "auto" ? "radiogroup" : "tablist",
99
- "aria-disabled": m,
100
- "use:tabIndex": h !== null ? -1 : 0
101
- }, l))), /* @__PURE__ */ s.createElement(T, o.cn("NeighborLocation", {
102
- controlsLength: g
103
- }), /* @__PURE__ */ s.createElement(t, o.cn("Children", {}))));
118
+ value: function render() {
119
+ var _ref = this.asProps, _ref5;
120
+ var SPills = Box;
121
+ var _this$asProps2 = this.asProps, Children = _this$asProps2.Children, styles = _this$asProps2.styles, controlsLength = _this$asProps2.controlsLength, disabled = _this$asProps2.disabled, behavior = _this$asProps2.behavior, value = _this$asProps2.value;
122
+ return _ref5 = sstyled(styles), /* @__PURE__ */ React.createElement(SPills, _ref5.cn("SPills", _objectSpread({}, assignProps({
123
+ "role": behavior === "radio" || behavior === "auto" ? "radiogroup" : "tablist",
124
+ "aria-disabled": disabled,
125
+ "use:tabIndex": value !== null ? -1 : 0
126
+ }, _ref))), /* @__PURE__ */ React.createElement(NeighborLocation, _ref5.cn("NeighborLocation", {
127
+ "controlsLength": controlsLength
128
+ }), /* @__PURE__ */ React.createElement(Children, _ref5.cn("Children", {}))));
104
129
  }
105
- }]), _;
106
- }(C);
107
- d(v, "displayName", "Pills");
108
- d(v, "style", R);
109
- d(v, "defaultProps", function(a) {
110
- var r = a.behavior;
130
+ }]);
131
+ return RootPills2;
132
+ }(Component);
133
+ _defineProperty(RootPills, "displayName", "Pills");
134
+ _defineProperty(RootPills, "style", style);
135
+ _defineProperty(RootPills, "defaultProps", function(_ref9) {
136
+ var behavior = _ref9.behavior;
111
137
  return {
112
138
  size: "m",
113
139
  defaultValue: null,
114
- behavior: r ?? "auto"
140
+ behavior: behavior !== null && behavior !== void 0 ? behavior : "auto"
115
141
  };
116
142
  });
117
- d(v, "enhance", [N(j)]);
118
- function I(a) {
119
- var r = arguments[0], _, i = S, l = a.Children, o = a.styles, n = a.addonLeft, e = a.addonRight, t = a.selected, c = a.disabled, g = a.index, m = a.behavior, b = E(g), h = {};
120
- return m === "radio" || m === "auto" ? (h.role = "radio", h["aria-checked"] = t) : (h.role = "tab", h["aria-selected"] = t), _ = f(o), /* @__PURE__ */ s.createElement(i, _.cn("SPill", u({}, P(u({
121
- tag: "button",
122
- type: "button",
123
- tabIndex: 0,
124
- neighborLocation: b,
125
- "aria-disabled": c
126
- }, h), r))), n ? /* @__PURE__ */ s.createElement(x.Item.Addon, {
127
- tag: n
128
- }) : null, D(l, x.Item.Text, x.Item.Addon), e ? /* @__PURE__ */ s.createElement(x.Item.Addon, {
129
- tag: e
143
+ _defineProperty(RootPills, "enhance", [a11yEnhance(optionsA11yEnhance)]);
144
+ function Pill(props) {
145
+ var _ref2 = arguments[0], _ref6;
146
+ var SPill = Box;
147
+ var Children = props.Children, styles = props.styles, addonLeft = props.addonLeft, addonRight = props.addonRight, selected = props.selected, disabled = props.disabled, index = props.index, behavior = props.behavior;
148
+ var neighborLocation = useNeighborLocationDetect(index);
149
+ var roleAreaProps = {};
150
+ if (behavior === "radio" || behavior === "auto") {
151
+ roleAreaProps.role = "radio";
152
+ roleAreaProps["aria-checked"] = selected;
153
+ } else {
154
+ roleAreaProps.role = "tab";
155
+ roleAreaProps["aria-selected"] = selected;
156
+ }
157
+ return _ref6 = sstyled(styles), /* @__PURE__ */ React.createElement(SPill, _ref6.cn("SPill", _objectSpread({}, assignProps(_objectSpread({
158
+ "tag": "button",
159
+ "type": "button",
160
+ "tabIndex": 0,
161
+ "neighborLocation": neighborLocation,
162
+ "aria-disabled": disabled
163
+ }, roleAreaProps), _ref2))), addonLeft ? /* @__PURE__ */ React.createElement(Pills.Item.Addon, {
164
+ tag: addonLeft
165
+ }) : null, addonTextChildren(Children, Pills.Item.Text, Pills.Item.Addon), addonRight ? /* @__PURE__ */ React.createElement(Pills.Item.Addon, {
166
+ tag: addonRight
130
167
  }) : null);
131
168
  }
132
- function V(a) {
133
- var r = arguments[0], _, i = S;
134
- return _ = f(a.styles), /* @__PURE__ */ s.createElement(i, _.cn("SText", u({}, P({
135
- tag: "span"
136
- }, r))));
169
+ function Text(props) {
170
+ var _ref3 = arguments[0], _ref7;
171
+ var SText = Box;
172
+ return _ref7 = sstyled(props.styles), /* @__PURE__ */ React.createElement(SText, _ref7.cn("SText", _objectSpread({}, assignProps({
173
+ "tag": "span"
174
+ }, _ref3))));
137
175
  }
138
- function H(a) {
139
- var r = arguments[0], _, i = S;
140
- return _ = f(a.styles), /* @__PURE__ */ s.createElement(i, _.cn("SAddon", u({}, P({
141
- tag: "span"
142
- }, r))));
176
+ function Addon(props) {
177
+ var _ref4 = arguments[0], _ref8;
178
+ var SAddon = Box;
179
+ return _ref8 = sstyled(props.styles), /* @__PURE__ */ React.createElement(SAddon, _ref8.cn("SAddon", _objectSpread({}, assignProps({
180
+ "tag": "span"
181
+ }, _ref4))));
143
182
  }
144
- var x = k(v, {
145
- Item: [I, {
146
- Text: V,
147
- Addon: H
183
+ var Pills = createComponent(RootPills, {
184
+ Item: [Pill, {
185
+ Text,
186
+ Addon
148
187
  }]
149
- }), Z = function(r) {
150
- return r;
188
+ });
189
+ var wrapPills = function wrapPills2(wrapper) {
190
+ return wrapper;
151
191
  };
152
192
  export {
153
- x as default,
154
- Z as wrapPills
193
+ Pills as default,
194
+ wrapPills
155
195
  };
package/lib/esm/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { default as a, wrapPills as e } from "./Pills.mjs";
1
+ import { default as default2, wrapPills } from "./Pills.mjs";
2
2
  export {
3
- a as default,
4
- e as wrapPills
3
+ default2 as default,
4
+ wrapPills
5
5
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@semcore/pills",
3
3
  "description": "Semrush Pills Component",
4
- "version": "16.0.0-prerelease.6",
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.6",
18
- "@semcore/neighbor-location": "16.0.0-prerelease.6"
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.6"
21
+ "@semcore/base-components": "^16.0.0-prerelease.7"
22
22
  },
23
23
  "repository": {
24
24
  "type": "git",