@pingux/astro 1.10.0-alpha.2 → 1.10.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.
- package/CHANGELOG.md +19 -0
- package/lib/cjs/components/SelectFieldBase/SelectFieldBase.test.js +2 -2
- package/lib/cjs/hooks/useField/useField.js +1 -1
- package/lib/cjs/hooks/useField/useField.test.js +1 -1
- package/lib/cjs/recipes/Slider.stories.js +239 -0
- package/lib/cjs/styles/forms/label.js +1 -1
- package/lib/components/SelectFieldBase/SelectFieldBase.test.js +2 -2
- package/lib/hooks/useField/useField.js +1 -1
- package/lib/hooks/useField/useField.test.js +1 -1
- package/lib/recipes/Slider.stories.js +204 -0
- package/lib/styles/forms/label.js +1 -1
- package/package.json +3 -1
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,25 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
+
# [1.10.0](https://gitlab.corp.pingidentity.com/ux/pingux/compare/@pingux/astro@1.9.0...@pingux/astro@1.10.0) (2022-04-28)
|
7
|
+
|
8
|
+
|
9
|
+
### Bug Fixes
|
10
|
+
|
11
|
+
* [UIP-5300] Multiple inputs not focusable within AccordionGridGroup ([421f210](https://gitlab.corp.pingidentity.com/ux/pingux/commit/421f21046e0638c44ecb34085bd64af681301b3c))
|
12
|
+
* [UIP-5408] float label Tweaks ([eaa79fd](https://gitlab.corp.pingidentity.com/ux/pingux/commit/eaa79fd1da40eed988759a0d0e4c626d1c338dc2))
|
13
|
+
|
14
|
+
|
15
|
+
### Features
|
16
|
+
|
17
|
+
* [UIP-5334] add container widths to box ([5b672d2](https://gitlab.corp.pingidentity.com/ux/pingux/commit/5b672d2b3198e637ee7b0947a221e8ae3cdb60f3))
|
18
|
+
* [UIP-5397] ArrayField Component - Allow a limit on the number of Fields ([61dcdcd](https://gitlab.corp.pingidentity.com/ux/pingux/commit/61dcdcd929c540e8353996755889a320202ad003))
|
19
|
+
* [UIP-5401] Add initial Slider recipe ([1fba9ae](https://gitlab.corp.pingidentity.com/ux/pingux/commit/1fba9ae445f77359bf9db716864b7755e6d0c392))
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
6
25
|
# [1.9.0](https://gitlab.corp.pingidentity.com/ux/pingux/compare/@pingux/astro@1.8.1...@pingux/astro@1.9.0) (2022-04-21)
|
7
26
|
|
8
27
|
|
@@ -175,7 +175,7 @@ test('select field with helper text', function () {
|
|
175
175
|
expect(fieldHelperText).toBeInTheDocument();
|
176
176
|
expect(fieldHelperText).toHaveClass("is-".concat(_statuses["default"].ERROR));
|
177
177
|
});
|
178
|
-
test(
|
178
|
+
test("label floats after user's interacting", function () {
|
179
179
|
getComponent({
|
180
180
|
labelMode: _constants.modes.FLOAT,
|
181
181
|
value: ''
|
@@ -187,7 +187,7 @@ test('label floats after user\'s interacting', function () {
|
|
187
187
|
|
188
188
|
_userEvent["default"].tab();
|
189
189
|
|
190
|
-
expect(textAreaContainer).toHaveClass('is-float-label
|
190
|
+
expect(textAreaContainer).toHaveClass('is-float-label');
|
191
191
|
});
|
192
192
|
test('clicking on the visible button opens the popuplist', function () {
|
193
193
|
getComponent();
|
@@ -190,7 +190,7 @@ var useField = function useField() {
|
|
190
190
|
|
191
191
|
var isFloatLabel = labelMode === _constants.modes.FLOAT || (labelProps === null || labelProps === void 0 ? void 0 : labelProps.labelMode) === _constants.modes.FLOAT;
|
192
192
|
var isLeftLabel = labelMode === _constants.modes.LEFT || (labelProps === null || labelProps === void 0 ? void 0 : labelProps.labelMode) === _constants.modes.LEFT;
|
193
|
-
var isFloatLabelActive = isFloatLabel && (hasValue ||
|
193
|
+
var isFloatLabelActive = isFloatLabel && (hasValue || (containerProps === null || containerProps === void 0 ? void 0 : containerProps.isFloatLabelActive));
|
194
194
|
|
195
195
|
var _useStatusClasses2 = (0, _hooks.useStatusClasses)(containerProps === null || containerProps === void 0 ? void 0 : containerProps.className, {
|
196
196
|
'field-container': true,
|
@@ -165,7 +165,7 @@ test('should return isFloatLabelActive class for container', function () {
|
|
165
165
|
(0, _reactHooks.act)(function () {
|
166
166
|
return result.current.fieldContainerProps.onFocus({});
|
167
167
|
});
|
168
|
-
expect(result.current.fieldContainerProps.className).toContain('is-float-label
|
168
|
+
expect(result.current.fieldContainerProps.className).toContain('is-float-label'); // Does not have the class if the container loses focus within it
|
169
169
|
|
170
170
|
(0, _reactHooks.act)(function () {
|
171
171
|
return result.current.fieldContainerProps.onBlur({
|
@@ -0,0 +1,239 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
6
|
+
|
7
|
+
var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
|
8
|
+
|
9
|
+
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
|
10
|
+
|
11
|
+
var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
|
12
|
+
|
13
|
+
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
14
|
+
|
15
|
+
var _filterInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/filter");
|
16
|
+
|
17
|
+
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols");
|
18
|
+
|
19
|
+
var _Object$keys = require("@babel/runtime-corejs3/core-js-stable/object/keys");
|
20
|
+
|
21
|
+
_Object$defineProperty(exports, "__esModule", {
|
22
|
+
value: true
|
23
|
+
});
|
24
|
+
|
25
|
+
exports["default"] = exports.Default = void 0;
|
26
|
+
|
27
|
+
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
28
|
+
|
29
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
30
|
+
|
31
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
32
|
+
|
33
|
+
var _react = _interopRequireDefault(require("react"));
|
34
|
+
|
35
|
+
var _slider = require("@react-aria/slider");
|
36
|
+
|
37
|
+
var _slider2 = require("@react-stately/slider");
|
38
|
+
|
39
|
+
var _focus = require("@react-aria/focus");
|
40
|
+
|
41
|
+
var _visuallyHidden = require("@react-aria/visually-hidden");
|
42
|
+
|
43
|
+
var _utils = require("@react-aria/utils");
|
44
|
+
|
45
|
+
var _i18n = require("@react-aria/i18n");
|
46
|
+
|
47
|
+
var _index = require("../index");
|
48
|
+
|
49
|
+
var _react2 = require("@emotion/react");
|
50
|
+
|
51
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
52
|
+
|
53
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context6, _context7; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context6 = ownKeys(Object(source), !0)).call(_context6, function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context7 = ownKeys(Object(source))).call(_context7, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
54
|
+
|
55
|
+
var _default = {
|
56
|
+
title: 'Recipes/Slider'
|
57
|
+
};
|
58
|
+
/*
|
59
|
+
* The slider value can be formatted by using the `formatOptions` prop.
|
60
|
+
`* formatOptions` is compatible with the option parameter of
|
61
|
+
* [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
|
62
|
+
* and is applied based on the current locale.
|
63
|
+
* https://react-spectrum.adobe.com/react-aria/useSlider.html
|
64
|
+
*/
|
65
|
+
|
66
|
+
exports["default"] = _default;
|
67
|
+
|
68
|
+
var Default = function Default() {
|
69
|
+
return (0, _react2.jsx)(_react["default"].Fragment, null, (0, _react2.jsx)(_index.Box, {
|
70
|
+
mb: "xl"
|
71
|
+
}, (0, _react2.jsx)(Slider, {
|
72
|
+
label: "Single with solid lower background",
|
73
|
+
maxValue: 100,
|
74
|
+
step: 1
|
75
|
+
})), (0, _react2.jsx)(_index.Box, null, (0, _react2.jsx)(RangeSlider, {
|
76
|
+
label: "Multiple with gradient background and custom point values",
|
77
|
+
maxValue: 100,
|
78
|
+
defaultValue: [0, 1],
|
79
|
+
step: 1
|
80
|
+
})));
|
81
|
+
};
|
82
|
+
|
83
|
+
exports.Default = Default;
|
84
|
+
|
85
|
+
var Slider = function Slider(props) {
|
86
|
+
var _context, _context2, _context3, _context4;
|
87
|
+
|
88
|
+
var trackRef = _react["default"].useRef(null);
|
89
|
+
|
90
|
+
var numberFormatter = (0, _i18n.useNumberFormatter)(props.formatOptions);
|
91
|
+
var state = (0, _slider2.useSliderState)(_objectSpread(_objectSpread({}, props), {}, {
|
92
|
+
numberFormatter: numberFormatter
|
93
|
+
}));
|
94
|
+
|
95
|
+
var _useSlider = (0, _slider.useSlider)(props, state, trackRef),
|
96
|
+
groupProps = _useSlider.groupProps,
|
97
|
+
trackProps = _useSlider.trackProps,
|
98
|
+
labelProps = _useSlider.labelProps,
|
99
|
+
outputProps = _useSlider.outputProps;
|
100
|
+
|
101
|
+
var thumbPosition = state.getThumbPercent(0) * 100;
|
102
|
+
return (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({}, groupProps, {
|
103
|
+
sx: {
|
104
|
+
position: 'relative',
|
105
|
+
alignItems: 'center',
|
106
|
+
width: '100%',
|
107
|
+
touchAction: 'none'
|
108
|
+
}
|
109
|
+
}), (0, _react2.jsx)(_index.Box, {
|
110
|
+
sx: {
|
111
|
+
alignSelf: 'stretch'
|
112
|
+
}
|
113
|
+
}, props.label && (0, _react2.jsx)("label", labelProps, props.label), (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({}, outputProps, {
|
114
|
+
sx: {
|
115
|
+
flex: '1 0 auto',
|
116
|
+
textAlign: 'end'
|
117
|
+
}
|
118
|
+
}), "(", state.getThumbValueLabel(0), ")")), (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({}, trackProps, {
|
119
|
+
ref: trackRef,
|
120
|
+
sx: {
|
121
|
+
position: 'relative',
|
122
|
+
height: 30,
|
123
|
+
width: ' 100%'
|
124
|
+
}
|
125
|
+
}), (0, _react2.jsx)(_index.Box, {
|
126
|
+
sx: {
|
127
|
+
position: 'absolute',
|
128
|
+
backgroundImage: thumbPosition < 25 ? (0, _concat["default"])(_context = "linear-gradient(to right, rgb(169, 215, 50) 0%, rgb(169, 215, 50) ".concat(thumbPosition, "%, rgb(242, 242, 242) ")).call(_context, thumbPosition, "%, rgb(242, 242, 242) 100%)") : thumbPosition >= 25 && thumbPosition <= 49 ? (0, _concat["default"])(_context2 = "linear-gradient(to right, rgb(226, 215, 20) 0%, rgb(226, 215, 20) ".concat(thumbPosition, "%, rgb(242, 242, 242) ")).call(_context2, thumbPosition, "%, rgb(242, 242, 242) 100%)") : thumbPosition >= 50 && thumbPosition <= 74 ? (0, _concat["default"])(_context3 = "linear-gradient(to right, rgb(231, 135, 38) 0%, rgb(231, 135, 38) ".concat(thumbPosition, "%, rgb(242, 242, 242) ")).call(_context3, thumbPosition, "%, rgb(242, 242, 242) 100%)") : (0, _concat["default"])(_context4 = "linear-gradient(to right, rgb(235, 44, 56) 0%, rgb(235, 44, 56) ".concat(thumbPosition, "%, rgb(242, 242, 242) ")).call(_context4, thumbPosition, "%, rgb(242, 242, 242) 100%)"),
|
129
|
+
height: 10,
|
130
|
+
borderRadius: '5px',
|
131
|
+
top: 13,
|
132
|
+
width: '100%'
|
133
|
+
}
|
134
|
+
}), (0, _react2.jsx)(Thumb, {
|
135
|
+
index: 0,
|
136
|
+
state: state,
|
137
|
+
trackRef: trackRef
|
138
|
+
})));
|
139
|
+
};
|
140
|
+
|
141
|
+
var RangeSlider = function RangeSlider(props) {
|
142
|
+
var _context5;
|
143
|
+
|
144
|
+
var trackRef = _react["default"].useRef(null);
|
145
|
+
|
146
|
+
var numberFormatter = (0, _i18n.useNumberFormatter)(props.formatOptions);
|
147
|
+
var state = (0, _slider2.useSliderState)(_objectSpread(_objectSpread({}, props), {}, {
|
148
|
+
numberFormatter: numberFormatter
|
149
|
+
}));
|
150
|
+
|
151
|
+
var _useSlider2 = (0, _slider.useSlider)(props, state, trackRef),
|
152
|
+
groupProps = _useSlider2.groupProps,
|
153
|
+
trackProps = _useSlider2.trackProps,
|
154
|
+
labelProps = _useSlider2.labelProps,
|
155
|
+
outputProps = _useSlider2.outputProps;
|
156
|
+
|
157
|
+
return (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({}, groupProps, {
|
158
|
+
sx: {
|
159
|
+
position: 'relative',
|
160
|
+
alignItems: 'center',
|
161
|
+
width: '100%',
|
162
|
+
touchAction: 'none'
|
163
|
+
}
|
164
|
+
}), (0, _react2.jsx)(_index.Box, {
|
165
|
+
sx: {
|
166
|
+
alignSelf: 'stretch'
|
167
|
+
}
|
168
|
+
}, props.label && (0, _react2.jsx)("label", labelProps, props.label), (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({}, outputProps, {
|
169
|
+
sx: {
|
170
|
+
flex: '1 0 auto',
|
171
|
+
textAlign: 'end'
|
172
|
+
}
|
173
|
+
}), "(", (0, _concat["default"])(_context5 = "".concat(state.getThumbValueLabel(0), ", ")).call(_context5, state.getThumbValueLabel(1)), ")")), (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({}, trackProps, {
|
174
|
+
ref: trackRef,
|
175
|
+
sx: {
|
176
|
+
position: 'relative',
|
177
|
+
height: 30,
|
178
|
+
width: ' 100%'
|
179
|
+
}
|
180
|
+
}), (0, _react2.jsx)(_index.Box, {
|
181
|
+
sx: {
|
182
|
+
position: 'absolute',
|
183
|
+
backgroundImage: 'linear-gradient(to right, rgb(169, 215, 50) 10%, rgb(226, 215, 20) 50%, rgb(235, 44, 56) 90%)',
|
184
|
+
height: 10,
|
185
|
+
borderRadius: '5px',
|
186
|
+
top: 13,
|
187
|
+
width: '100%'
|
188
|
+
}
|
189
|
+
}), (0, _react2.jsx)(Thumb, {
|
190
|
+
index: 0,
|
191
|
+
state: state,
|
192
|
+
trackRef: trackRef
|
193
|
+
}), (0, _react2.jsx)(Thumb, {
|
194
|
+
index: 1,
|
195
|
+
state: state,
|
196
|
+
trackRef: trackRef
|
197
|
+
})));
|
198
|
+
};
|
199
|
+
|
200
|
+
var Thumb = function Thumb(props) {
|
201
|
+
var state = props.state,
|
202
|
+
trackRef = props.trackRef,
|
203
|
+
index = props.index;
|
204
|
+
|
205
|
+
var inputRef = _react["default"].useRef(null);
|
206
|
+
|
207
|
+
var _useSliderThumb = (0, _slider.useSliderThumb)({
|
208
|
+
index: index,
|
209
|
+
trackRef: trackRef,
|
210
|
+
inputRef: inputRef
|
211
|
+
}, state),
|
212
|
+
thumbProps = _useSliderThumb.thumbProps,
|
213
|
+
inputProps = _useSliderThumb.inputProps;
|
214
|
+
|
215
|
+
var _useFocusRing = (0, _focus.useFocusRing)(),
|
216
|
+
focusProps = _useFocusRing.focusProps,
|
217
|
+
isFocusVisible = _useFocusRing.isFocusVisible;
|
218
|
+
|
219
|
+
return (0, _react2.jsx)(_index.Box, {
|
220
|
+
sx: {
|
221
|
+
position: 'absolute',
|
222
|
+
top: 5,
|
223
|
+
transform: 'translateX(-50%)',
|
224
|
+
left: "".concat(state.getThumbPercent(index) * 100, "%")
|
225
|
+
}
|
226
|
+
}, (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({}, thumbProps, {
|
227
|
+
sx: {
|
228
|
+
width: 25,
|
229
|
+
height: 25,
|
230
|
+
borderRadius: '50%',
|
231
|
+
backgroundColor: 'white',
|
232
|
+
border: '1px solid #C1C5C8',
|
233
|
+
boxShadow: '0 2px 2px 0 #CACACA',
|
234
|
+
outline: isFocusVisible ? '5px solid rgba(41,150,204,0.5)' : 'none'
|
235
|
+
}
|
236
|
+
}), (0, _react2.jsx)(_visuallyHidden.VisuallyHidden, null, (0, _react2.jsx)("input", (0, _extends2["default"])({
|
237
|
+
ref: inputRef
|
238
|
+
}, (0, _utils.mergeProps)(inputProps, focusProps))))));
|
239
|
+
};
|
@@ -54,7 +54,7 @@ var label = _objectSpread(_objectSpread({}, _text.text.label), {}, {
|
|
54
54
|
left: 'md',
|
55
55
|
mb: 0,
|
56
56
|
transformOrigin: 'top left',
|
57
|
-
transition: 'all 0.
|
57
|
+
transition: 'all 0.1s ease-out',
|
58
58
|
pointerEvents: 'none',
|
59
59
|
paddingRight: '25px',
|
60
60
|
paddingLeft: '1px' // Otherwise, certain characters get cut off on the left from the overflow
|
@@ -136,7 +136,7 @@ test('select field with helper text', function () {
|
|
136
136
|
expect(fieldHelperText).toBeInTheDocument();
|
137
137
|
expect(fieldHelperText).toHaveClass("is-".concat(statuses.ERROR));
|
138
138
|
});
|
139
|
-
test(
|
139
|
+
test("label floats after user's interacting", function () {
|
140
140
|
getComponent({
|
141
141
|
labelMode: modes.FLOAT,
|
142
142
|
value: ''
|
@@ -144,7 +144,7 @@ test('label floats after user\'s interacting', function () {
|
|
144
144
|
var textAreaContainer = screen.getByTestId(testId);
|
145
145
|
expect(textAreaContainer).not.toHaveClass('is-float-label-active');
|
146
146
|
userEvent.tab();
|
147
|
-
expect(textAreaContainer).toHaveClass('is-float-label
|
147
|
+
expect(textAreaContainer).toHaveClass('is-float-label');
|
148
148
|
});
|
149
149
|
test('clicking on the visible button opens the popuplist', function () {
|
150
150
|
getComponent();
|
@@ -159,7 +159,7 @@ var useField = function useField() {
|
|
159
159
|
|
160
160
|
var isFloatLabel = labelMode === labelModes.FLOAT || (labelProps === null || labelProps === void 0 ? void 0 : labelProps.labelMode) === labelModes.FLOAT;
|
161
161
|
var isLeftLabel = labelMode === labelModes.LEFT || (labelProps === null || labelProps === void 0 ? void 0 : labelProps.labelMode) === labelModes.LEFT;
|
162
|
-
var isFloatLabelActive = isFloatLabel && (hasValue ||
|
162
|
+
var isFloatLabelActive = isFloatLabel && (hasValue || (containerProps === null || containerProps === void 0 ? void 0 : containerProps.isFloatLabelActive));
|
163
163
|
|
164
164
|
var _useStatusClasses2 = useStatusClasses(containerProps === null || containerProps === void 0 ? void 0 : containerProps.className, {
|
165
165
|
'field-container': true,
|
@@ -148,7 +148,7 @@ test('should return isFloatLabelActive class for container', function () {
|
|
148
148
|
act(function () {
|
149
149
|
return result.current.fieldContainerProps.onFocus({});
|
150
150
|
});
|
151
|
-
expect(result.current.fieldContainerProps.className).toContain('is-float-label
|
151
|
+
expect(result.current.fieldContainerProps.className).toContain('is-float-label'); // Does not have the class if the container loses focus within it
|
152
152
|
|
153
153
|
act(function () {
|
154
154
|
return result.current.fieldContainerProps.onBlur({
|
@@ -0,0 +1,204 @@
|
|
1
|
+
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
2
|
+
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
3
|
+
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
4
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
5
|
+
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
6
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
7
|
+
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
8
|
+
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
9
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
10
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
11
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
12
|
+
|
13
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
14
|
+
|
15
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context6, _context7; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context6 = ownKeys(Object(source), !0)).call(_context6, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context7 = ownKeys(Object(source))).call(_context7, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
16
|
+
|
17
|
+
/* eslint-disable no-nested-ternary */
|
18
|
+
import React from 'react';
|
19
|
+
import { useSlider, useSliderThumb } from '@react-aria/slider';
|
20
|
+
import { useSliderState } from '@react-stately/slider';
|
21
|
+
import { useFocusRing } from '@react-aria/focus';
|
22
|
+
import { VisuallyHidden } from '@react-aria/visually-hidden';
|
23
|
+
import { mergeProps } from '@react-aria/utils';
|
24
|
+
import { useNumberFormatter } from '@react-aria/i18n';
|
25
|
+
import { Box } from '../index';
|
26
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
27
|
+
export default {
|
28
|
+
title: 'Recipes/Slider'
|
29
|
+
};
|
30
|
+
/*
|
31
|
+
* The slider value can be formatted by using the `formatOptions` prop.
|
32
|
+
`* formatOptions` is compatible with the option parameter of
|
33
|
+
* [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
|
34
|
+
* and is applied based on the current locale.
|
35
|
+
* https://react-spectrum.adobe.com/react-aria/useSlider.html
|
36
|
+
*/
|
37
|
+
|
38
|
+
export var Default = function Default() {
|
39
|
+
return ___EmotionJSX(React.Fragment, null, ___EmotionJSX(Box, {
|
40
|
+
mb: "xl"
|
41
|
+
}, ___EmotionJSX(Slider, {
|
42
|
+
label: "Single with solid lower background",
|
43
|
+
maxValue: 100,
|
44
|
+
step: 1
|
45
|
+
})), ___EmotionJSX(Box, null, ___EmotionJSX(RangeSlider, {
|
46
|
+
label: "Multiple with gradient background and custom point values",
|
47
|
+
maxValue: 100,
|
48
|
+
defaultValue: [0, 1],
|
49
|
+
step: 1
|
50
|
+
})));
|
51
|
+
};
|
52
|
+
|
53
|
+
var Slider = function Slider(props) {
|
54
|
+
var _context, _context2, _context3, _context4;
|
55
|
+
|
56
|
+
var trackRef = React.useRef(null);
|
57
|
+
var numberFormatter = useNumberFormatter(props.formatOptions);
|
58
|
+
var state = useSliderState(_objectSpread(_objectSpread({}, props), {}, {
|
59
|
+
numberFormatter: numberFormatter
|
60
|
+
}));
|
61
|
+
|
62
|
+
var _useSlider = useSlider(props, state, trackRef),
|
63
|
+
groupProps = _useSlider.groupProps,
|
64
|
+
trackProps = _useSlider.trackProps,
|
65
|
+
labelProps = _useSlider.labelProps,
|
66
|
+
outputProps = _useSlider.outputProps;
|
67
|
+
|
68
|
+
var thumbPosition = state.getThumbPercent(0) * 100;
|
69
|
+
return ___EmotionJSX(Box, _extends({}, groupProps, {
|
70
|
+
sx: {
|
71
|
+
position: 'relative',
|
72
|
+
alignItems: 'center',
|
73
|
+
width: '100%',
|
74
|
+
touchAction: 'none'
|
75
|
+
}
|
76
|
+
}), ___EmotionJSX(Box, {
|
77
|
+
sx: {
|
78
|
+
alignSelf: 'stretch'
|
79
|
+
}
|
80
|
+
}, props.label && ___EmotionJSX("label", labelProps, props.label), ___EmotionJSX(Box, _extends({}, outputProps, {
|
81
|
+
sx: {
|
82
|
+
flex: '1 0 auto',
|
83
|
+
textAlign: 'end'
|
84
|
+
}
|
85
|
+
}), "(", state.getThumbValueLabel(0), ")")), ___EmotionJSX(Box, _extends({}, trackProps, {
|
86
|
+
ref: trackRef,
|
87
|
+
sx: {
|
88
|
+
position: 'relative',
|
89
|
+
height: 30,
|
90
|
+
width: ' 100%'
|
91
|
+
}
|
92
|
+
}), ___EmotionJSX(Box, {
|
93
|
+
sx: {
|
94
|
+
position: 'absolute',
|
95
|
+
backgroundImage: thumbPosition < 25 ? _concatInstanceProperty(_context = "linear-gradient(to right, rgb(169, 215, 50) 0%, rgb(169, 215, 50) ".concat(thumbPosition, "%, rgb(242, 242, 242) ")).call(_context, thumbPosition, "%, rgb(242, 242, 242) 100%)") : thumbPosition >= 25 && thumbPosition <= 49 ? _concatInstanceProperty(_context2 = "linear-gradient(to right, rgb(226, 215, 20) 0%, rgb(226, 215, 20) ".concat(thumbPosition, "%, rgb(242, 242, 242) ")).call(_context2, thumbPosition, "%, rgb(242, 242, 242) 100%)") : thumbPosition >= 50 && thumbPosition <= 74 ? _concatInstanceProperty(_context3 = "linear-gradient(to right, rgb(231, 135, 38) 0%, rgb(231, 135, 38) ".concat(thumbPosition, "%, rgb(242, 242, 242) ")).call(_context3, thumbPosition, "%, rgb(242, 242, 242) 100%)") : _concatInstanceProperty(_context4 = "linear-gradient(to right, rgb(235, 44, 56) 0%, rgb(235, 44, 56) ".concat(thumbPosition, "%, rgb(242, 242, 242) ")).call(_context4, thumbPosition, "%, rgb(242, 242, 242) 100%)"),
|
96
|
+
height: 10,
|
97
|
+
borderRadius: '5px',
|
98
|
+
top: 13,
|
99
|
+
width: '100%'
|
100
|
+
}
|
101
|
+
}), ___EmotionJSX(Thumb, {
|
102
|
+
index: 0,
|
103
|
+
state: state,
|
104
|
+
trackRef: trackRef
|
105
|
+
})));
|
106
|
+
};
|
107
|
+
|
108
|
+
var RangeSlider = function RangeSlider(props) {
|
109
|
+
var _context5;
|
110
|
+
|
111
|
+
var trackRef = React.useRef(null);
|
112
|
+
var numberFormatter = useNumberFormatter(props.formatOptions);
|
113
|
+
var state = useSliderState(_objectSpread(_objectSpread({}, props), {}, {
|
114
|
+
numberFormatter: numberFormatter
|
115
|
+
}));
|
116
|
+
|
117
|
+
var _useSlider2 = useSlider(props, state, trackRef),
|
118
|
+
groupProps = _useSlider2.groupProps,
|
119
|
+
trackProps = _useSlider2.trackProps,
|
120
|
+
labelProps = _useSlider2.labelProps,
|
121
|
+
outputProps = _useSlider2.outputProps;
|
122
|
+
|
123
|
+
return ___EmotionJSX(Box, _extends({}, groupProps, {
|
124
|
+
sx: {
|
125
|
+
position: 'relative',
|
126
|
+
alignItems: 'center',
|
127
|
+
width: '100%',
|
128
|
+
touchAction: 'none'
|
129
|
+
}
|
130
|
+
}), ___EmotionJSX(Box, {
|
131
|
+
sx: {
|
132
|
+
alignSelf: 'stretch'
|
133
|
+
}
|
134
|
+
}, props.label && ___EmotionJSX("label", labelProps, props.label), ___EmotionJSX(Box, _extends({}, outputProps, {
|
135
|
+
sx: {
|
136
|
+
flex: '1 0 auto',
|
137
|
+
textAlign: 'end'
|
138
|
+
}
|
139
|
+
}), "(", _concatInstanceProperty(_context5 = "".concat(state.getThumbValueLabel(0), ", ")).call(_context5, state.getThumbValueLabel(1)), ")")), ___EmotionJSX(Box, _extends({}, trackProps, {
|
140
|
+
ref: trackRef,
|
141
|
+
sx: {
|
142
|
+
position: 'relative',
|
143
|
+
height: 30,
|
144
|
+
width: ' 100%'
|
145
|
+
}
|
146
|
+
}), ___EmotionJSX(Box, {
|
147
|
+
sx: {
|
148
|
+
position: 'absolute',
|
149
|
+
backgroundImage: 'linear-gradient(to right, rgb(169, 215, 50) 10%, rgb(226, 215, 20) 50%, rgb(235, 44, 56) 90%)',
|
150
|
+
height: 10,
|
151
|
+
borderRadius: '5px',
|
152
|
+
top: 13,
|
153
|
+
width: '100%'
|
154
|
+
}
|
155
|
+
}), ___EmotionJSX(Thumb, {
|
156
|
+
index: 0,
|
157
|
+
state: state,
|
158
|
+
trackRef: trackRef
|
159
|
+
}), ___EmotionJSX(Thumb, {
|
160
|
+
index: 1,
|
161
|
+
state: state,
|
162
|
+
trackRef: trackRef
|
163
|
+
})));
|
164
|
+
};
|
165
|
+
|
166
|
+
var Thumb = function Thumb(props) {
|
167
|
+
var state = props.state,
|
168
|
+
trackRef = props.trackRef,
|
169
|
+
index = props.index;
|
170
|
+
var inputRef = React.useRef(null);
|
171
|
+
|
172
|
+
var _useSliderThumb = useSliderThumb({
|
173
|
+
index: index,
|
174
|
+
trackRef: trackRef,
|
175
|
+
inputRef: inputRef
|
176
|
+
}, state),
|
177
|
+
thumbProps = _useSliderThumb.thumbProps,
|
178
|
+
inputProps = _useSliderThumb.inputProps;
|
179
|
+
|
180
|
+
var _useFocusRing = useFocusRing(),
|
181
|
+
focusProps = _useFocusRing.focusProps,
|
182
|
+
isFocusVisible = _useFocusRing.isFocusVisible;
|
183
|
+
|
184
|
+
return ___EmotionJSX(Box, {
|
185
|
+
sx: {
|
186
|
+
position: 'absolute',
|
187
|
+
top: 5,
|
188
|
+
transform: 'translateX(-50%)',
|
189
|
+
left: "".concat(state.getThumbPercent(index) * 100, "%")
|
190
|
+
}
|
191
|
+
}, ___EmotionJSX(Box, _extends({}, thumbProps, {
|
192
|
+
sx: {
|
193
|
+
width: 25,
|
194
|
+
height: 25,
|
195
|
+
borderRadius: '50%',
|
196
|
+
backgroundColor: 'white',
|
197
|
+
border: '1px solid #C1C5C8',
|
198
|
+
boxShadow: '0 2px 2px 0 #CACACA',
|
199
|
+
outline: isFocusVisible ? '5px solid rgba(41,150,204,0.5)' : 'none'
|
200
|
+
}
|
201
|
+
}), ___EmotionJSX(VisuallyHidden, null, ___EmotionJSX("input", _extends({
|
202
|
+
ref: inputRef
|
203
|
+
}, mergeProps(inputProps, focusProps))))));
|
204
|
+
};
|
@@ -36,7 +36,7 @@ export var label = _objectSpread(_objectSpread({}, text.label), {}, {
|
|
36
36
|
left: 'md',
|
37
37
|
mb: 0,
|
38
38
|
transformOrigin: 'top left',
|
39
|
-
transition: 'all 0.
|
39
|
+
transition: 'all 0.1s ease-out',
|
40
40
|
pointerEvents: 'none',
|
41
41
|
paddingRight: '25px',
|
42
42
|
paddingLeft: '1px' // Otherwise, certain characters get cut off on the left from the overflow
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pingux/astro",
|
3
|
-
"version": "1.10.0
|
3
|
+
"version": "1.10.0",
|
4
4
|
"description": "PingUX themeable React component library",
|
5
5
|
"author": "ux-development@pingidentity.com",
|
6
6
|
"license": "Apache-2.0",
|
@@ -98,6 +98,7 @@
|
|
98
98
|
"@react-aria/select": "^3.2.3",
|
99
99
|
"@react-aria/selection": "^3.3.1",
|
100
100
|
"@react-aria/separator": "^3.1.1",
|
101
|
+
"@react-aria/slider": "^3.0.7",
|
101
102
|
"@react-aria/switch": "3.1.1",
|
102
103
|
"@react-aria/tabs": "^3.0.1",
|
103
104
|
"@react-aria/tooltip": "^3.1.2",
|
@@ -119,6 +120,7 @@
|
|
119
120
|
"@react-stately/radio": "^3.2.0",
|
120
121
|
"@react-stately/searchfield": "^3.1.1",
|
121
122
|
"@react-stately/select": "^3.1.1",
|
123
|
+
"@react-stately/slider": "^3.0.7",
|
122
124
|
"@react-stately/tabs": "^3.0.1",
|
123
125
|
"@react-stately/toggle": "^3.2.0",
|
124
126
|
"@react-stately/tooltip": "^3.0.4",
|