@semcore/pills 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.
- package/lib/esm/Pills.mjs +155 -115
- package/lib/esm/index.mjs +3 -3
- package/package.json +4 -4
package/lib/esm/Pills.mjs
CHANGED
|
@@ -1,155 +1,195 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import { sstyled
|
|
9
|
-
import
|
|
10
|
-
import { Box
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
var
|
|
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
|
-
(
|
|
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
|
-
)
|
|
35
|
-
|
|
36
|
-
|
|
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(
|
|
39
|
-
return
|
|
44
|
+
childSelector: function childSelector(props) {
|
|
45
|
+
return props.behavior === "auto" || props.behavior === "radio" ? ["role", "radio"] : ["role", "tab"];
|
|
40
46
|
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
})
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
})
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
(
|
|
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
|
|
64
|
-
})
|
|
82
|
+
return startIndex >= 0 && startIndex < _this.itemValues.length ? startIndex : void 0;
|
|
83
|
+
});
|
|
84
|
+
return _this;
|
|
65
85
|
}
|
|
66
|
-
|
|
86
|
+
_createClass(RootPills2, [{
|
|
67
87
|
key: "componentDidMount",
|
|
68
|
-
value: function() {
|
|
69
|
-
|
|
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(
|
|
81
|
-
var
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
"
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}), /* @__PURE__ */
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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:
|
|
140
|
+
behavior: behavior !== null && behavior !== void 0 ? behavior : "auto"
|
|
115
141
|
};
|
|
116
142
|
});
|
|
117
|
-
|
|
118
|
-
function
|
|
119
|
-
var
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
"
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
|
133
|
-
var
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
|
139
|
-
var
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
|
145
|
-
Item: [
|
|
146
|
-
Text
|
|
147
|
-
Addon
|
|
183
|
+
var Pills = createComponent(RootPills, {
|
|
184
|
+
Item: [Pill, {
|
|
185
|
+
Text,
|
|
186
|
+
Addon
|
|
148
187
|
}]
|
|
149
|
-
})
|
|
150
|
-
|
|
188
|
+
});
|
|
189
|
+
var wrapPills = function wrapPills2(wrapper) {
|
|
190
|
+
return wrapper;
|
|
151
191
|
};
|
|
152
192
|
export {
|
|
153
|
-
|
|
154
|
-
|
|
193
|
+
Pills as default,
|
|
194
|
+
wrapPills
|
|
155
195
|
};
|
package/lib/esm/index.mjs
CHANGED
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.
|
|
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.
|
|
18
|
-
"@semcore/neighbor-location": "16.0.0-prerelease.
|
|
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.
|
|
21
|
+
"@semcore/base-components": "^16.0.0-prerelease.7"
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|