@storybook/components 6.3.0-beta.9 → 6.3.0-rc.11
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/dist/cjs/controls/Color.js +14 -2
- package/dist/cjs/controls/Number.js +3 -3
- package/dist/cjs/controls/Object.js +1 -1
- package/dist/cjs/controls/Range.js +58 -25
- package/dist/cjs/controls/Range.stories.js +39 -7
- package/dist/esm/controls/Color.js +15 -3
- package/dist/esm/controls/Number.js +3 -3
- package/dist/esm/controls/Object.js +1 -1
- package/dist/esm/controls/Range.js +33 -24
- package/dist/esm/controls/Range.stories.js +32 -6
- package/dist/modern/controls/Color.js +15 -3
- package/dist/modern/controls/Number.js +3 -3
- package/dist/modern/controls/Object.js +1 -1
- package/dist/modern/controls/Range.js +43 -23
- package/dist/modern/controls/Range.stories.js +28 -6
- package/package.json +4 -4
|
@@ -353,8 +353,15 @@ var useColorInput = function useColorInput(initialValue, onChange) {
|
|
|
353
353
|
var _useState5 = (0, _react.useState)((color === null || color === void 0 ? void 0 : color.colorSpace) || ColorSpace.HEX),
|
|
354
354
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
355
355
|
colorSpace = _useState6[0],
|
|
356
|
-
setColorSpace = _useState6[1];
|
|
356
|
+
setColorSpace = _useState6[1]; // Reset state when initialValue becomes undefined (when resetting controls)
|
|
357
357
|
|
|
358
|
+
|
|
359
|
+
(0, _react.useEffect)(function () {
|
|
360
|
+
if (initialValue !== undefined) return;
|
|
361
|
+
setValue('');
|
|
362
|
+
setColor(undefined);
|
|
363
|
+
setColorSpace(ColorSpace.HEX);
|
|
364
|
+
}, [initialValue]);
|
|
358
365
|
var realValue = (0, _react.useMemo)(function () {
|
|
359
366
|
return getRealValue(value, color, colorSpace).toLowerCase();
|
|
360
367
|
}, [value, color, colorSpace]);
|
|
@@ -392,8 +399,13 @@ var usePresets = function usePresets(presetColors, currentColor, colorSpace) {
|
|
|
392
399
|
var _useState7 = (0, _react.useState)(currentColor !== null && currentColor !== void 0 && currentColor.valid ? [currentColor] : []),
|
|
393
400
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
394
401
|
selectedColors = _useState8[0],
|
|
395
|
-
setSelectedColors = _useState8[1];
|
|
402
|
+
setSelectedColors = _useState8[1]; // Reset state when currentColor becomes undefined (when resetting controls)
|
|
403
|
+
|
|
396
404
|
|
|
405
|
+
(0, _react.useEffect)(function () {
|
|
406
|
+
if (currentColor !== undefined) return;
|
|
407
|
+
setSelectedColors([]);
|
|
408
|
+
}, [currentColor]);
|
|
397
409
|
var presets = (0, _react.useMemo)(function () {
|
|
398
410
|
var initialPresets = (presetColors || []).map(function (preset) {
|
|
399
411
|
if (typeof preset === 'string') return parseValue(preset);
|
|
@@ -96,7 +96,7 @@ var NumberControl = function NumberControl(_ref) {
|
|
|
96
96
|
forceVisible = _useState4[0],
|
|
97
97
|
setForceVisible = _useState4[1];
|
|
98
98
|
|
|
99
|
-
var _useState5 = (0, _react.useState)(
|
|
99
|
+
var _useState5 = (0, _react.useState)(null),
|
|
100
100
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
101
101
|
parseError = _useState6[0],
|
|
102
102
|
setParseError = _useState6[1];
|
|
@@ -106,10 +106,10 @@ var NumberControl = function NumberControl(_ref) {
|
|
|
106
106
|
var result = parseFloat(event.target.value);
|
|
107
107
|
|
|
108
108
|
if (Number.isNaN(result)) {
|
|
109
|
-
setParseError(
|
|
109
|
+
setParseError(new Error("'".concat(event.target.value, "' is not a number")));
|
|
110
110
|
} else {
|
|
111
111
|
onChange(result);
|
|
112
|
-
setParseError(
|
|
112
|
+
setParseError(null);
|
|
113
113
|
}
|
|
114
114
|
}, [onChange, setParseError]);
|
|
115
115
|
var onForceVisible = (0, _react.useCallback)(function () {
|
|
@@ -325,7 +325,7 @@ var ObjectControl = function ObjectControl(_ref7) {
|
|
|
325
325
|
showRaw = _useState2[0],
|
|
326
326
|
setShowRaw = _useState2[1];
|
|
327
327
|
|
|
328
|
-
var _useState3 = (0, _react.useState)(),
|
|
328
|
+
var _useState3 = (0, _react.useState)(null),
|
|
329
329
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
330
330
|
parseError = _useState4[0],
|
|
331
331
|
setParseError = _useState4[1];
|
|
@@ -1,15 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
require("core-js/modules/es.weak-map.js");
|
|
6
|
+
|
|
7
|
+
require("core-js/modules/es.string.iterator.js");
|
|
8
|
+
|
|
9
|
+
require("core-js/modules/es.array.iterator.js");
|
|
10
|
+
|
|
11
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
12
|
+
|
|
13
|
+
require("core-js/modules/es.object.get-own-property-descriptor.js");
|
|
14
|
+
|
|
15
|
+
require("core-js/modules/es.symbol.js");
|
|
16
|
+
|
|
17
|
+
require("core-js/modules/es.symbol.description.js");
|
|
18
|
+
|
|
19
|
+
require("core-js/modules/es.symbol.iterator.js");
|
|
20
|
+
|
|
3
21
|
Object.defineProperty(exports, "__esModule", {
|
|
4
22
|
value: true
|
|
5
23
|
});
|
|
6
24
|
exports.RangeControl = void 0;
|
|
7
25
|
|
|
26
|
+
require("core-js/modules/es.array.concat.js");
|
|
27
|
+
|
|
28
|
+
require("core-js/modules/es.string.match.js");
|
|
29
|
+
|
|
30
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
31
|
+
|
|
32
|
+
require("core-js/modules/es.object.to-string.js");
|
|
33
|
+
|
|
34
|
+
require("core-js/modules/es.regexp.to-string.js");
|
|
35
|
+
|
|
8
36
|
require("core-js/modules/es.function.name.js");
|
|
9
37
|
|
|
10
|
-
require("core-js/modules/es.
|
|
38
|
+
require("core-js/modules/es.number.to-fixed.js");
|
|
11
39
|
|
|
12
|
-
var _react =
|
|
40
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
13
41
|
|
|
14
42
|
var _theming = require("@storybook/theming");
|
|
15
43
|
|
|
@@ -19,10 +47,15 @@ var _helpers = require("./helpers");
|
|
|
19
47
|
|
|
20
48
|
var _Number = require("./Number");
|
|
21
49
|
|
|
22
|
-
function
|
|
50
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
|
51
|
+
|
|
52
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
53
|
|
|
24
54
|
var RangeInput = _theming.styled.input(function (_ref) {
|
|
25
|
-
var theme = _ref.theme
|
|
55
|
+
var theme = _ref.theme,
|
|
56
|
+
min = _ref.min,
|
|
57
|
+
max = _ref.max,
|
|
58
|
+
value = _ref.value;
|
|
26
59
|
return {
|
|
27
60
|
// Resytled using http://danielstern.ca/range.css/#/
|
|
28
61
|
'&': {
|
|
@@ -31,8 +64,8 @@ var RangeInput = _theming.styled.input(function (_ref) {
|
|
|
31
64
|
appearance: 'none'
|
|
32
65
|
},
|
|
33
66
|
'&::-webkit-slider-runnable-track': {
|
|
34
|
-
background: theme.base === 'light' ? (0, _polished.darken)(0.02, theme.input.background) : (0, _polished.lighten)(0.02, theme.input.background),
|
|
35
|
-
|
|
67
|
+
background: theme.base === 'light' ? "linear-gradient(to right, \n ".concat(theme.color.green, " 0%, ").concat(theme.color.green, " ").concat((value - min) / (max - min) * 100, "%, \n ").concat((0, _polished.darken)(0.02, theme.input.background), " ").concat((value - min) / (max - min) * 100, "%, \n ").concat((0, _polished.darken)(0.02, theme.input.background), " 100%)") : "linear-gradient(to right, \n ".concat(theme.color.green, " 0%, ").concat(theme.color.green, " ").concat((value - min) / (max - min) * 100, "%, \n ").concat((0, _polished.lighten)(0.02, theme.input.background), " ").concat((value - min) / (max - min) * 100, "%, \n ").concat((0, _polished.lighten)(0.02, theme.input.background), " 100%)"),
|
|
68
|
+
boxShadow: "".concat(theme.appBorderColor, " 0 0 0 1px inset"),
|
|
36
69
|
borderRadius: 6,
|
|
37
70
|
width: '100%',
|
|
38
71
|
height: 6,
|
|
@@ -63,8 +96,7 @@ var RangeInput = _theming.styled.input(function (_ref) {
|
|
|
63
96
|
'&:focus': {
|
|
64
97
|
outline: 'none',
|
|
65
98
|
'&::-webkit-slider-runnable-track': {
|
|
66
|
-
borderColor: (0, _polished.rgba)(theme.color.secondary, 0.4)
|
|
67
|
-
background: theme.background.hoverable
|
|
99
|
+
borderColor: (0, _polished.rgba)(theme.color.secondary, 0.4)
|
|
68
100
|
},
|
|
69
101
|
'&::-webkit-slider-thumb': {
|
|
70
102
|
borderColor: theme.color.secondary,
|
|
@@ -72,8 +104,8 @@ var RangeInput = _theming.styled.input(function (_ref) {
|
|
|
72
104
|
}
|
|
73
105
|
},
|
|
74
106
|
'&::-moz-range-track': {
|
|
75
|
-
background: theme.base === 'light' ? (0, _polished.darken)(0.02, theme.input.background) : (0, _polished.lighten)(0.02, theme.input.background),
|
|
76
|
-
|
|
107
|
+
background: theme.base === 'light' ? "linear-gradient(to right, \n ".concat(theme.color.green, " 0%, ").concat(theme.color.green, " ").concat((value - min) / (max - min) * 100, "%, \n ").concat((0, _polished.darken)(0.02, theme.input.background), " ").concat((value - min) / (max - min) * 100, "%, \n ").concat((0, _polished.darken)(0.02, theme.input.background), " 100%)") : "linear-gradient(to right, \n ".concat(theme.color.green, " 0%, ").concat(theme.color.green, " ").concat((value - min) / (max - min) * 100, "%, \n ").concat((0, _polished.lighten)(0.02, theme.input.background), " ").concat((value - min) / (max - min) * 100, "%, \n ").concat((0, _polished.lighten)(0.02, theme.input.background), " 100%)"),
|
|
108
|
+
boxShadow: "".concat(theme.appBorderColor, " 0 0 0 1px inset"),
|
|
77
109
|
borderRadius: 6,
|
|
78
110
|
width: '100%',
|
|
79
111
|
height: 6,
|
|
@@ -101,22 +133,17 @@ var RangeInput = _theming.styled.input(function (_ref) {
|
|
|
101
133
|
}
|
|
102
134
|
},
|
|
103
135
|
'&::-ms-track': {
|
|
104
|
-
background: theme.base === 'light' ? (0, _polished.darken)(0.02, theme.input.background) : (0, _polished.lighten)(0.02, theme.input.background),
|
|
105
|
-
|
|
106
|
-
borderWidth: '7.3px 0',
|
|
136
|
+
background: theme.base === 'light' ? "linear-gradient(to right, \n ".concat(theme.color.green, " 0%, ").concat(theme.color.green, " ").concat((value - min) / (max - min) * 100, "%, \n ").concat((0, _polished.darken)(0.02, theme.input.background), " ").concat((value - min) / (max - min) * 100, "%, \n ").concat((0, _polished.darken)(0.02, theme.input.background), " 100%)") : "linear-gradient(to right, \n ".concat(theme.color.green, " 0%, ").concat(theme.color.green, " ").concat((value - min) / (max - min) * 100, "%, \n ").concat((0, _polished.lighten)(0.02, theme.input.background), " ").concat((value - min) / (max - min) * 100, "%, \n ").concat((0, _polished.lighten)(0.02, theme.input.background), " 100%)"),
|
|
137
|
+
boxShadow: "".concat(theme.appBorderColor, " 0 0 0 1px inset"),
|
|
107
138
|
color: 'transparent',
|
|
108
139
|
width: '100%',
|
|
109
140
|
height: '6px',
|
|
110
141
|
cursor: 'pointer'
|
|
111
142
|
},
|
|
112
143
|
'&::-ms-fill-lower': {
|
|
113
|
-
background: '#dadada',
|
|
114
|
-
border: "1px solid ".concat(theme.appBorderColor),
|
|
115
144
|
borderRadius: 6
|
|
116
145
|
},
|
|
117
146
|
'&::-ms-fill-upper': {
|
|
118
|
-
background: '#dddddd',
|
|
119
|
-
border: "1px solid ".concat(theme.appBorderColor),
|
|
120
147
|
borderRadius: 6
|
|
121
148
|
},
|
|
122
149
|
'&::-ms-thumb': {
|
|
@@ -128,12 +155,6 @@ var RangeInput = _theming.styled.input(function (_ref) {
|
|
|
128
155
|
cursor: 'grab',
|
|
129
156
|
marginTop: 0
|
|
130
157
|
},
|
|
131
|
-
'&:focus::-ms-fill-lower': {
|
|
132
|
-
background: '#dddddd'
|
|
133
|
-
},
|
|
134
|
-
'&:focus::-ms-fill-upper': {
|
|
135
|
-
background: '#e0e0e0'
|
|
136
|
-
},
|
|
137
158
|
'@supports (-ms-ime-align:auto)': {
|
|
138
159
|
'input[type=range]': {
|
|
139
160
|
margin: '0'
|
|
@@ -146,7 +167,9 @@ var RangeLabel = _theming.styled.span({
|
|
|
146
167
|
paddingLeft: 5,
|
|
147
168
|
paddingRight: 5,
|
|
148
169
|
fontSize: 12,
|
|
149
|
-
whiteSpace: 'nowrap'
|
|
170
|
+
whiteSpace: 'nowrap',
|
|
171
|
+
fontFeatureSettings: 'tnum',
|
|
172
|
+
fontVariantNumeric: 'tabular-nums'
|
|
150
173
|
});
|
|
151
174
|
|
|
152
175
|
var RangeWrapper = _theming.styled.div({
|
|
@@ -155,6 +178,13 @@ var RangeWrapper = _theming.styled.div({
|
|
|
155
178
|
width: '100%'
|
|
156
179
|
});
|
|
157
180
|
|
|
181
|
+
function getNumberOfDecimalPlaces(number) {
|
|
182
|
+
var match = number.toString().match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
|
|
183
|
+
return !match ? 0 : Math.max(0, // Number of digits right of decimal point.
|
|
184
|
+
(match[1] ? match[1].length : 0) - ( // Adjust for scientific notation.
|
|
185
|
+
match[2] ? +match[2] : 0));
|
|
186
|
+
}
|
|
187
|
+
|
|
158
188
|
var RangeControl = function RangeControl(_ref2) {
|
|
159
189
|
var name = _ref2.name,
|
|
160
190
|
value = _ref2.value,
|
|
@@ -173,6 +203,9 @@ var RangeControl = function RangeControl(_ref2) {
|
|
|
173
203
|
};
|
|
174
204
|
|
|
175
205
|
var hasValue = value !== undefined;
|
|
206
|
+
var numberOFDecimalsPlaces = (0, _react.useMemo)(function () {
|
|
207
|
+
return getNumberOfDecimalPlaces(step);
|
|
208
|
+
}, [step]);
|
|
176
209
|
return /*#__PURE__*/_react.default.createElement(RangeWrapper, null, /*#__PURE__*/_react.default.createElement(RangeLabel, null, min), /*#__PURE__*/_react.default.createElement(RangeInput, {
|
|
177
210
|
id: (0, _helpers.getControlId)(name),
|
|
178
211
|
type: "range",
|
|
@@ -184,7 +217,7 @@ var RangeControl = function RangeControl(_ref2) {
|
|
|
184
217
|
step: step,
|
|
185
218
|
onFocus: onFocus,
|
|
186
219
|
onBlur: onBlur
|
|
187
|
-
}), /*#__PURE__*/_react.default.createElement(RangeLabel, null, "".concat(hasValue ? value : '--', " / "
|
|
220
|
+
}), /*#__PURE__*/_react.default.createElement(RangeLabel, null, "".concat(hasValue ? value.toFixed(numberOFDecimalsPlaces) : '--'), " / ", max));
|
|
188
221
|
};
|
|
189
222
|
|
|
190
223
|
exports.RangeControl = RangeControl;
|
|
@@ -29,7 +29,7 @@ require("core-js/modules/es.object.get-own-property-descriptor.js");
|
|
|
29
29
|
Object.defineProperty(exports, "__esModule", {
|
|
30
30
|
value: true
|
|
31
31
|
});
|
|
32
|
-
exports.Undefined = exports.Zero = exports.Basic = exports.default = void 0;
|
|
32
|
+
exports.Undefined = exports.BigMaxValue = exports.Decimals = exports.Zero = exports.Basic = exports.default = void 0;
|
|
33
33
|
|
|
34
34
|
var _react = _interopRequireWildcard(require("react"));
|
|
35
35
|
|
|
@@ -57,7 +57,11 @@ var _default = {
|
|
|
57
57
|
};
|
|
58
58
|
exports.default = _default;
|
|
59
59
|
|
|
60
|
-
var Template = function Template(
|
|
60
|
+
var Template = function Template(_ref) {
|
|
61
|
+
var initialValue = _ref.initialValue,
|
|
62
|
+
step = _ref.step,
|
|
63
|
+
max = _ref.max;
|
|
64
|
+
|
|
61
65
|
var _useState = (0, _react.useState)(initialValue),
|
|
62
66
|
_useState2 = _slicedToArray(_useState, 2),
|
|
63
67
|
value = _useState2[0],
|
|
@@ -70,25 +74,53 @@ var Template = function Template(initialValue) {
|
|
|
70
74
|
return setValue(newVal);
|
|
71
75
|
},
|
|
72
76
|
min: 0,
|
|
73
|
-
max:
|
|
74
|
-
step:
|
|
77
|
+
max: max,
|
|
78
|
+
step: step
|
|
75
79
|
}), /*#__PURE__*/_react.default.createElement("pre", null, JSON.stringify(value) || 'undefined'));
|
|
76
80
|
};
|
|
77
81
|
|
|
78
82
|
var Basic = function Basic() {
|
|
79
|
-
return Template(
|
|
83
|
+
return Template({
|
|
84
|
+
initialValue: 10,
|
|
85
|
+
max: 20,
|
|
86
|
+
step: 2
|
|
87
|
+
});
|
|
80
88
|
};
|
|
81
89
|
|
|
82
90
|
exports.Basic = Basic;
|
|
83
91
|
|
|
84
92
|
var Zero = function Zero() {
|
|
85
|
-
return Template(
|
|
93
|
+
return Template({
|
|
94
|
+
initialValue: 0,
|
|
95
|
+
max: 20,
|
|
96
|
+
step: 2
|
|
97
|
+
});
|
|
86
98
|
};
|
|
87
99
|
|
|
88
100
|
exports.Zero = Zero;
|
|
89
101
|
|
|
102
|
+
var Decimals = function Decimals() {
|
|
103
|
+
return Template({
|
|
104
|
+
step: 0.000000000002,
|
|
105
|
+
initialValue: 1989.123123123123,
|
|
106
|
+
max: 2000
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
exports.Decimals = Decimals;
|
|
111
|
+
|
|
112
|
+
var BigMaxValue = function BigMaxValue() {
|
|
113
|
+
return Template({
|
|
114
|
+
step: 1000,
|
|
115
|
+
initialValue: 15,
|
|
116
|
+
max: 10000000000
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
exports.BigMaxValue = BigMaxValue;
|
|
121
|
+
|
|
90
122
|
var Undefined = function Undefined() {
|
|
91
|
-
return Template(
|
|
123
|
+
return Template({});
|
|
92
124
|
};
|
|
93
125
|
|
|
94
126
|
exports.Undefined = Undefined;
|
|
@@ -43,7 +43,7 @@ import "core-js/modules/es.string.split.js";
|
|
|
43
43
|
import "core-js/modules/es.array.slice.js";
|
|
44
44
|
import "core-js/modules/es.array.filter.js";
|
|
45
45
|
import "core-js/modules/es.function.name.js";
|
|
46
|
-
import React, { useCallback, useMemo, useState } from 'react';
|
|
46
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
47
47
|
import { HexColorPicker, HslaStringColorPicker, RgbaStringColorPicker } from 'react-colorful';
|
|
48
48
|
import convert from 'color-convert';
|
|
49
49
|
import throttle from 'lodash/throttle';
|
|
@@ -294,8 +294,15 @@ var useColorInput = function useColorInput(initialValue, onChange) {
|
|
|
294
294
|
var _useState5 = useState((color === null || color === void 0 ? void 0 : color.colorSpace) || ColorSpace.HEX),
|
|
295
295
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
296
296
|
colorSpace = _useState6[0],
|
|
297
|
-
setColorSpace = _useState6[1];
|
|
297
|
+
setColorSpace = _useState6[1]; // Reset state when initialValue becomes undefined (when resetting controls)
|
|
298
298
|
|
|
299
|
+
|
|
300
|
+
useEffect(function () {
|
|
301
|
+
if (initialValue !== undefined) return;
|
|
302
|
+
setValue('');
|
|
303
|
+
setColor(undefined);
|
|
304
|
+
setColorSpace(ColorSpace.HEX);
|
|
305
|
+
}, [initialValue]);
|
|
299
306
|
var realValue = useMemo(function () {
|
|
300
307
|
return getRealValue(value, color, colorSpace).toLowerCase();
|
|
301
308
|
}, [value, color, colorSpace]);
|
|
@@ -333,8 +340,13 @@ var usePresets = function usePresets(presetColors, currentColor, colorSpace) {
|
|
|
333
340
|
var _useState7 = useState(currentColor !== null && currentColor !== void 0 && currentColor.valid ? [currentColor] : []),
|
|
334
341
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
335
342
|
selectedColors = _useState8[0],
|
|
336
|
-
setSelectedColors = _useState8[1];
|
|
343
|
+
setSelectedColors = _useState8[1]; // Reset state when currentColor becomes undefined (when resetting controls)
|
|
344
|
+
|
|
337
345
|
|
|
346
|
+
useEffect(function () {
|
|
347
|
+
if (currentColor !== undefined) return;
|
|
348
|
+
setSelectedColors([]);
|
|
349
|
+
}, [currentColor]);
|
|
338
350
|
var presets = useMemo(function () {
|
|
339
351
|
var initialPresets = (presetColors || []).map(function (preset) {
|
|
340
352
|
if (typeof preset === 'string') return parseValue(preset);
|
|
@@ -56,7 +56,7 @@ export var NumberControl = function NumberControl(_ref) {
|
|
|
56
56
|
forceVisible = _useState4[0],
|
|
57
57
|
setForceVisible = _useState4[1];
|
|
58
58
|
|
|
59
|
-
var _useState5 = useState(
|
|
59
|
+
var _useState5 = useState(null),
|
|
60
60
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
61
61
|
parseError = _useState6[0],
|
|
62
62
|
setParseError = _useState6[1];
|
|
@@ -66,10 +66,10 @@ export var NumberControl = function NumberControl(_ref) {
|
|
|
66
66
|
var result = parseFloat(event.target.value);
|
|
67
67
|
|
|
68
68
|
if (Number.isNaN(result)) {
|
|
69
|
-
setParseError(
|
|
69
|
+
setParseError(new Error("'".concat(event.target.value, "' is not a number")));
|
|
70
70
|
} else {
|
|
71
71
|
onChange(result);
|
|
72
|
-
setParseError(
|
|
72
|
+
setParseError(null);
|
|
73
73
|
}
|
|
74
74
|
}, [onChange, setParseError]);
|
|
75
75
|
var onForceVisible = useCallback(function () {
|
|
@@ -282,7 +282,7 @@ export var ObjectControl = function ObjectControl(_ref7) {
|
|
|
282
282
|
showRaw = _useState2[0],
|
|
283
283
|
setShowRaw = _useState2[1];
|
|
284
284
|
|
|
285
|
-
var _useState3 = useState(),
|
|
285
|
+
var _useState3 = useState(null),
|
|
286
286
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
287
287
|
parseError = _useState4[0],
|
|
288
288
|
setParseError = _useState4[1];
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import "core-js/modules/es.function.name.js";
|
|
2
1
|
import "core-js/modules/es.array.concat.js";
|
|
3
|
-
import
|
|
2
|
+
import "core-js/modules/es.string.match.js";
|
|
3
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
4
|
+
import "core-js/modules/es.object.to-string.js";
|
|
5
|
+
import "core-js/modules/es.regexp.to-string.js";
|
|
6
|
+
import "core-js/modules/es.function.name.js";
|
|
7
|
+
import "core-js/modules/es.number.to-fixed.js";
|
|
8
|
+
import React, { useMemo } from 'react';
|
|
4
9
|
import { styled } from '@storybook/theming';
|
|
5
10
|
import { lighten, darken, rgba } from 'polished';
|
|
6
11
|
import { getControlId } from './helpers';
|
|
7
12
|
import { parse } from './Number';
|
|
8
13
|
var RangeInput = styled.input(function (_ref) {
|
|
9
|
-
var theme = _ref.theme
|
|
14
|
+
var theme = _ref.theme,
|
|
15
|
+
min = _ref.min,
|
|
16
|
+
max = _ref.max,
|
|
17
|
+
value = _ref.value;
|
|
10
18
|
return {
|
|
11
19
|
// Resytled using http://danielstern.ca/range.css/#/
|
|
12
20
|
'&': {
|
|
@@ -15,8 +23,8 @@ var RangeInput = styled.input(function (_ref) {
|
|
|
15
23
|
appearance: 'none'
|
|
16
24
|
},
|
|
17
25
|
'&::-webkit-slider-runnable-track': {
|
|
18
|
-
background: theme.base === 'light' ? darken(0.02, theme.input.background) : lighten(0.02, theme.input.background),
|
|
19
|
-
|
|
26
|
+
background: theme.base === 'light' ? "linear-gradient(to right, \n ".concat(theme.color.green, " 0%, ").concat(theme.color.green, " ").concat((value - min) / (max - min) * 100, "%, \n ").concat(darken(0.02, theme.input.background), " ").concat((value - min) / (max - min) * 100, "%, \n ").concat(darken(0.02, theme.input.background), " 100%)") : "linear-gradient(to right, \n ".concat(theme.color.green, " 0%, ").concat(theme.color.green, " ").concat((value - min) / (max - min) * 100, "%, \n ").concat(lighten(0.02, theme.input.background), " ").concat((value - min) / (max - min) * 100, "%, \n ").concat(lighten(0.02, theme.input.background), " 100%)"),
|
|
27
|
+
boxShadow: "".concat(theme.appBorderColor, " 0 0 0 1px inset"),
|
|
20
28
|
borderRadius: 6,
|
|
21
29
|
width: '100%',
|
|
22
30
|
height: 6,
|
|
@@ -47,8 +55,7 @@ var RangeInput = styled.input(function (_ref) {
|
|
|
47
55
|
'&:focus': {
|
|
48
56
|
outline: 'none',
|
|
49
57
|
'&::-webkit-slider-runnable-track': {
|
|
50
|
-
borderColor: rgba(theme.color.secondary, 0.4)
|
|
51
|
-
background: theme.background.hoverable
|
|
58
|
+
borderColor: rgba(theme.color.secondary, 0.4)
|
|
52
59
|
},
|
|
53
60
|
'&::-webkit-slider-thumb': {
|
|
54
61
|
borderColor: theme.color.secondary,
|
|
@@ -56,8 +63,8 @@ var RangeInput = styled.input(function (_ref) {
|
|
|
56
63
|
}
|
|
57
64
|
},
|
|
58
65
|
'&::-moz-range-track': {
|
|
59
|
-
background: theme.base === 'light' ? darken(0.02, theme.input.background) : lighten(0.02, theme.input.background),
|
|
60
|
-
|
|
66
|
+
background: theme.base === 'light' ? "linear-gradient(to right, \n ".concat(theme.color.green, " 0%, ").concat(theme.color.green, " ").concat((value - min) / (max - min) * 100, "%, \n ").concat(darken(0.02, theme.input.background), " ").concat((value - min) / (max - min) * 100, "%, \n ").concat(darken(0.02, theme.input.background), " 100%)") : "linear-gradient(to right, \n ".concat(theme.color.green, " 0%, ").concat(theme.color.green, " ").concat((value - min) / (max - min) * 100, "%, \n ").concat(lighten(0.02, theme.input.background), " ").concat((value - min) / (max - min) * 100, "%, \n ").concat(lighten(0.02, theme.input.background), " 100%)"),
|
|
67
|
+
boxShadow: "".concat(theme.appBorderColor, " 0 0 0 1px inset"),
|
|
61
68
|
borderRadius: 6,
|
|
62
69
|
width: '100%',
|
|
63
70
|
height: 6,
|
|
@@ -85,22 +92,17 @@ var RangeInput = styled.input(function (_ref) {
|
|
|
85
92
|
}
|
|
86
93
|
},
|
|
87
94
|
'&::-ms-track': {
|
|
88
|
-
background: theme.base === 'light' ? darken(0.02, theme.input.background) : lighten(0.02, theme.input.background),
|
|
89
|
-
|
|
90
|
-
borderWidth: '7.3px 0',
|
|
95
|
+
background: theme.base === 'light' ? "linear-gradient(to right, \n ".concat(theme.color.green, " 0%, ").concat(theme.color.green, " ").concat((value - min) / (max - min) * 100, "%, \n ").concat(darken(0.02, theme.input.background), " ").concat((value - min) / (max - min) * 100, "%, \n ").concat(darken(0.02, theme.input.background), " 100%)") : "linear-gradient(to right, \n ".concat(theme.color.green, " 0%, ").concat(theme.color.green, " ").concat((value - min) / (max - min) * 100, "%, \n ").concat(lighten(0.02, theme.input.background), " ").concat((value - min) / (max - min) * 100, "%, \n ").concat(lighten(0.02, theme.input.background), " 100%)"),
|
|
96
|
+
boxShadow: "".concat(theme.appBorderColor, " 0 0 0 1px inset"),
|
|
91
97
|
color: 'transparent',
|
|
92
98
|
width: '100%',
|
|
93
99
|
height: '6px',
|
|
94
100
|
cursor: 'pointer'
|
|
95
101
|
},
|
|
96
102
|
'&::-ms-fill-lower': {
|
|
97
|
-
background: '#dadada',
|
|
98
|
-
border: "1px solid ".concat(theme.appBorderColor),
|
|
99
103
|
borderRadius: 6
|
|
100
104
|
},
|
|
101
105
|
'&::-ms-fill-upper': {
|
|
102
|
-
background: '#dddddd',
|
|
103
|
-
border: "1px solid ".concat(theme.appBorderColor),
|
|
104
106
|
borderRadius: 6
|
|
105
107
|
},
|
|
106
108
|
'&::-ms-thumb': {
|
|
@@ -112,12 +114,6 @@ var RangeInput = styled.input(function (_ref) {
|
|
|
112
114
|
cursor: 'grab',
|
|
113
115
|
marginTop: 0
|
|
114
116
|
},
|
|
115
|
-
'&:focus::-ms-fill-lower': {
|
|
116
|
-
background: '#dddddd'
|
|
117
|
-
},
|
|
118
|
-
'&:focus::-ms-fill-upper': {
|
|
119
|
-
background: '#e0e0e0'
|
|
120
|
-
},
|
|
121
117
|
'@supports (-ms-ime-align:auto)': {
|
|
122
118
|
'input[type=range]': {
|
|
123
119
|
margin: '0'
|
|
@@ -129,13 +125,23 @@ var RangeLabel = styled.span({
|
|
|
129
125
|
paddingLeft: 5,
|
|
130
126
|
paddingRight: 5,
|
|
131
127
|
fontSize: 12,
|
|
132
|
-
whiteSpace: 'nowrap'
|
|
128
|
+
whiteSpace: 'nowrap',
|
|
129
|
+
fontFeatureSettings: 'tnum',
|
|
130
|
+
fontVariantNumeric: 'tabular-nums'
|
|
133
131
|
});
|
|
134
132
|
var RangeWrapper = styled.div({
|
|
135
133
|
display: 'flex',
|
|
136
134
|
alignItems: 'center',
|
|
137
135
|
width: '100%'
|
|
138
136
|
});
|
|
137
|
+
|
|
138
|
+
function getNumberOfDecimalPlaces(number) {
|
|
139
|
+
var match = number.toString().match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
|
|
140
|
+
return !match ? 0 : Math.max(0, // Number of digits right of decimal point.
|
|
141
|
+
(match[1] ? match[1].length : 0) - ( // Adjust for scientific notation.
|
|
142
|
+
match[2] ? +match[2] : 0));
|
|
143
|
+
}
|
|
144
|
+
|
|
139
145
|
export var RangeControl = function RangeControl(_ref2) {
|
|
140
146
|
var name = _ref2.name,
|
|
141
147
|
value = _ref2.value,
|
|
@@ -154,6 +160,9 @@ export var RangeControl = function RangeControl(_ref2) {
|
|
|
154
160
|
};
|
|
155
161
|
|
|
156
162
|
var hasValue = value !== undefined;
|
|
163
|
+
var numberOFDecimalsPlaces = useMemo(function () {
|
|
164
|
+
return getNumberOfDecimalPlaces(step);
|
|
165
|
+
}, [step]);
|
|
157
166
|
return /*#__PURE__*/React.createElement(RangeWrapper, null, /*#__PURE__*/React.createElement(RangeLabel, null, min), /*#__PURE__*/React.createElement(RangeInput, {
|
|
158
167
|
id: getControlId(name),
|
|
159
168
|
type: "range",
|
|
@@ -165,6 +174,6 @@ export var RangeControl = function RangeControl(_ref2) {
|
|
|
165
174
|
step: step,
|
|
166
175
|
onFocus: onFocus,
|
|
167
176
|
onBlur: onBlur
|
|
168
|
-
}), /*#__PURE__*/React.createElement(RangeLabel, null, "".concat(hasValue ? value : '--', " / "
|
|
177
|
+
}), /*#__PURE__*/React.createElement(RangeLabel, null, "".concat(hasValue ? value.toFixed(numberOFDecimalsPlaces) : '--'), " / ", max));
|
|
169
178
|
};
|
|
170
179
|
RangeControl.displayName = "RangeControl";
|
|
@@ -28,7 +28,11 @@ export default {
|
|
|
28
28
|
component: RangeControl
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
var Template = function Template(
|
|
31
|
+
var Template = function Template(_ref) {
|
|
32
|
+
var initialValue = _ref.initialValue,
|
|
33
|
+
step = _ref.step,
|
|
34
|
+
max = _ref.max;
|
|
35
|
+
|
|
32
36
|
var _useState = useState(initialValue),
|
|
33
37
|
_useState2 = _slicedToArray(_useState, 2),
|
|
34
38
|
value = _useState2[0],
|
|
@@ -41,17 +45,39 @@ var Template = function Template(initialValue) {
|
|
|
41
45
|
return setValue(newVal);
|
|
42
46
|
},
|
|
43
47
|
min: 0,
|
|
44
|
-
max:
|
|
45
|
-
step:
|
|
48
|
+
max: max,
|
|
49
|
+
step: step
|
|
46
50
|
}), /*#__PURE__*/React.createElement("pre", null, JSON.stringify(value) || 'undefined'));
|
|
47
51
|
};
|
|
48
52
|
|
|
49
53
|
export var Basic = function Basic() {
|
|
50
|
-
return Template(
|
|
54
|
+
return Template({
|
|
55
|
+
initialValue: 10,
|
|
56
|
+
max: 20,
|
|
57
|
+
step: 2
|
|
58
|
+
});
|
|
51
59
|
};
|
|
52
60
|
export var Zero = function Zero() {
|
|
53
|
-
return Template(
|
|
61
|
+
return Template({
|
|
62
|
+
initialValue: 0,
|
|
63
|
+
max: 20,
|
|
64
|
+
step: 2
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
export var Decimals = function Decimals() {
|
|
68
|
+
return Template({
|
|
69
|
+
step: 0.000000000002,
|
|
70
|
+
initialValue: 1989.123123123123,
|
|
71
|
+
max: 2000
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
export var BigMaxValue = function BigMaxValue() {
|
|
75
|
+
return Template({
|
|
76
|
+
step: 1000,
|
|
77
|
+
initialValue: 15,
|
|
78
|
+
max: 10000000000
|
|
79
|
+
});
|
|
54
80
|
};
|
|
55
81
|
export var Undefined = function Undefined() {
|
|
56
|
-
return Template(
|
|
82
|
+
return Template({});
|
|
57
83
|
};
|
|
@@ -2,7 +2,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
|
|
|
2
2
|
|
|
3
3
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
4
4
|
|
|
5
|
-
import React, { useCallback, useMemo, useState } from 'react';
|
|
5
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
6
6
|
import { HexColorPicker, HslaStringColorPicker, RgbaStringColorPicker } from 'react-colorful';
|
|
7
7
|
import convert from 'color-convert';
|
|
8
8
|
import throttle from 'lodash/throttle';
|
|
@@ -214,7 +214,14 @@ const getRealValue = (value, color, colorSpace) => {
|
|
|
214
214
|
const useColorInput = (initialValue, onChange) => {
|
|
215
215
|
const [value, setValue] = useState(initialValue || '');
|
|
216
216
|
const [color, setColor] = useState(() => parseValue(value));
|
|
217
|
-
const [colorSpace, setColorSpace] = useState((color === null || color === void 0 ? void 0 : color.colorSpace) || ColorSpace.HEX);
|
|
217
|
+
const [colorSpace, setColorSpace] = useState((color === null || color === void 0 ? void 0 : color.colorSpace) || ColorSpace.HEX); // Reset state when initialValue becomes undefined (when resetting controls)
|
|
218
|
+
|
|
219
|
+
useEffect(() => {
|
|
220
|
+
if (initialValue !== undefined) return;
|
|
221
|
+
setValue('');
|
|
222
|
+
setColor(undefined);
|
|
223
|
+
setColorSpace(ColorSpace.HEX);
|
|
224
|
+
}, [initialValue]);
|
|
218
225
|
const realValue = useMemo(() => getRealValue(value, color, colorSpace).toLowerCase(), [value, color, colorSpace]);
|
|
219
226
|
const updateValue = useCallback(update => {
|
|
220
227
|
const parsed = parseValue(update);
|
|
@@ -245,7 +252,12 @@ const useColorInput = (initialValue, onChange) => {
|
|
|
245
252
|
const id = value => value.replace(/\s*/, '').toLowerCase();
|
|
246
253
|
|
|
247
254
|
const usePresets = (presetColors, currentColor, colorSpace) => {
|
|
248
|
-
const [selectedColors, setSelectedColors] = useState(currentColor !== null && currentColor !== void 0 && currentColor.valid ? [currentColor] : []);
|
|
255
|
+
const [selectedColors, setSelectedColors] = useState(currentColor !== null && currentColor !== void 0 && currentColor.valid ? [currentColor] : []); // Reset state when currentColor becomes undefined (when resetting controls)
|
|
256
|
+
|
|
257
|
+
useEffect(() => {
|
|
258
|
+
if (currentColor !== undefined) return;
|
|
259
|
+
setSelectedColors([]);
|
|
260
|
+
}, [currentColor]);
|
|
249
261
|
const presets = useMemo(() => {
|
|
250
262
|
const initialPresets = (presetColors || []).map(preset => {
|
|
251
263
|
if (typeof preset === 'string') return parseValue(preset);
|
|
@@ -22,16 +22,16 @@ export const NumberControl = ({
|
|
|
22
22
|
}) => {
|
|
23
23
|
const [inputValue, setInputValue] = useState(typeof value === 'number' ? value : '');
|
|
24
24
|
const [forceVisible, setForceVisible] = useState(false);
|
|
25
|
-
const [parseError, setParseError] = useState(
|
|
25
|
+
const [parseError, setParseError] = useState(null);
|
|
26
26
|
const handleChange = useCallback(event => {
|
|
27
27
|
setInputValue(event.target.value);
|
|
28
28
|
const result = parseFloat(event.target.value);
|
|
29
29
|
|
|
30
30
|
if (Number.isNaN(result)) {
|
|
31
|
-
setParseError(
|
|
31
|
+
setParseError(new Error(`'${event.target.value}' is not a number`));
|
|
32
32
|
} else {
|
|
33
33
|
onChange(result);
|
|
34
|
-
setParseError(
|
|
34
|
+
setParseError(null);
|
|
35
35
|
}
|
|
36
36
|
}, [onChange, setParseError]);
|
|
37
37
|
const onForceVisible = useCallback(() => {
|
|
@@ -245,7 +245,7 @@ export const ObjectControl = ({
|
|
|
245
245
|
const data = useMemo(() => value && cloneDeep(value), [value]);
|
|
246
246
|
const hasData = data !== null && data !== undefined;
|
|
247
247
|
const [showRaw, setShowRaw] = useState(!hasData);
|
|
248
|
-
const [parseError, setParseError] = useState();
|
|
248
|
+
const [parseError, setParseError] = useState(null);
|
|
249
249
|
const updateRaw = useCallback(raw => {
|
|
250
250
|
try {
|
|
251
251
|
if (raw) onChange(JSON.parse(raw));
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
2
|
import { styled } from '@storybook/theming';
|
|
3
3
|
import { lighten, darken, rgba } from 'polished';
|
|
4
4
|
import { getControlId } from './helpers';
|
|
5
5
|
import { parse } from './Number';
|
|
6
6
|
const RangeInput = styled.input(({
|
|
7
|
-
theme
|
|
7
|
+
theme,
|
|
8
|
+
min,
|
|
9
|
+
max,
|
|
10
|
+
value
|
|
8
11
|
}) => ({
|
|
9
12
|
// Resytled using http://danielstern.ca/range.css/#/
|
|
10
13
|
'&': {
|
|
@@ -13,8 +16,14 @@ const RangeInput = styled.input(({
|
|
|
13
16
|
appearance: 'none'
|
|
14
17
|
},
|
|
15
18
|
'&::-webkit-slider-runnable-track': {
|
|
16
|
-
background: theme.base === 'light' ?
|
|
17
|
-
|
|
19
|
+
background: theme.base === 'light' ? `linear-gradient(to right,
|
|
20
|
+
${theme.color.green} 0%, ${theme.color.green} ${(value - min) / (max - min) * 100}%,
|
|
21
|
+
${darken(0.02, theme.input.background)} ${(value - min) / (max - min) * 100}%,
|
|
22
|
+
${darken(0.02, theme.input.background)} 100%)` : `linear-gradient(to right,
|
|
23
|
+
${theme.color.green} 0%, ${theme.color.green} ${(value - min) / (max - min) * 100}%,
|
|
24
|
+
${lighten(0.02, theme.input.background)} ${(value - min) / (max - min) * 100}%,
|
|
25
|
+
${lighten(0.02, theme.input.background)} 100%)`,
|
|
26
|
+
boxShadow: `${theme.appBorderColor} 0 0 0 1px inset`,
|
|
18
27
|
borderRadius: 6,
|
|
19
28
|
width: '100%',
|
|
20
29
|
height: 6,
|
|
@@ -45,8 +54,7 @@ const RangeInput = styled.input(({
|
|
|
45
54
|
'&:focus': {
|
|
46
55
|
outline: 'none',
|
|
47
56
|
'&::-webkit-slider-runnable-track': {
|
|
48
|
-
borderColor: rgba(theme.color.secondary, 0.4)
|
|
49
|
-
background: theme.background.hoverable
|
|
57
|
+
borderColor: rgba(theme.color.secondary, 0.4)
|
|
50
58
|
},
|
|
51
59
|
'&::-webkit-slider-thumb': {
|
|
52
60
|
borderColor: theme.color.secondary,
|
|
@@ -54,8 +62,14 @@ const RangeInput = styled.input(({
|
|
|
54
62
|
}
|
|
55
63
|
},
|
|
56
64
|
'&::-moz-range-track': {
|
|
57
|
-
background: theme.base === 'light' ?
|
|
58
|
-
|
|
65
|
+
background: theme.base === 'light' ? `linear-gradient(to right,
|
|
66
|
+
${theme.color.green} 0%, ${theme.color.green} ${(value - min) / (max - min) * 100}%,
|
|
67
|
+
${darken(0.02, theme.input.background)} ${(value - min) / (max - min) * 100}%,
|
|
68
|
+
${darken(0.02, theme.input.background)} 100%)` : `linear-gradient(to right,
|
|
69
|
+
${theme.color.green} 0%, ${theme.color.green} ${(value - min) / (max - min) * 100}%,
|
|
70
|
+
${lighten(0.02, theme.input.background)} ${(value - min) / (max - min) * 100}%,
|
|
71
|
+
${lighten(0.02, theme.input.background)} 100%)`,
|
|
72
|
+
boxShadow: `${theme.appBorderColor} 0 0 0 1px inset`,
|
|
59
73
|
borderRadius: 6,
|
|
60
74
|
width: '100%',
|
|
61
75
|
height: 6,
|
|
@@ -83,22 +97,23 @@ const RangeInput = styled.input(({
|
|
|
83
97
|
}
|
|
84
98
|
},
|
|
85
99
|
'&::-ms-track': {
|
|
86
|
-
background: theme.base === 'light' ?
|
|
87
|
-
|
|
88
|
-
|
|
100
|
+
background: theme.base === 'light' ? `linear-gradient(to right,
|
|
101
|
+
${theme.color.green} 0%, ${theme.color.green} ${(value - min) / (max - min) * 100}%,
|
|
102
|
+
${darken(0.02, theme.input.background)} ${(value - min) / (max - min) * 100}%,
|
|
103
|
+
${darken(0.02, theme.input.background)} 100%)` : `linear-gradient(to right,
|
|
104
|
+
${theme.color.green} 0%, ${theme.color.green} ${(value - min) / (max - min) * 100}%,
|
|
105
|
+
${lighten(0.02, theme.input.background)} ${(value - min) / (max - min) * 100}%,
|
|
106
|
+
${lighten(0.02, theme.input.background)} 100%)`,
|
|
107
|
+
boxShadow: `${theme.appBorderColor} 0 0 0 1px inset`,
|
|
89
108
|
color: 'transparent',
|
|
90
109
|
width: '100%',
|
|
91
110
|
height: '6px',
|
|
92
111
|
cursor: 'pointer'
|
|
93
112
|
},
|
|
94
113
|
'&::-ms-fill-lower': {
|
|
95
|
-
background: '#dadada',
|
|
96
|
-
border: `1px solid ${theme.appBorderColor}`,
|
|
97
114
|
borderRadius: 6
|
|
98
115
|
},
|
|
99
116
|
'&::-ms-fill-upper': {
|
|
100
|
-
background: '#dddddd',
|
|
101
|
-
border: `1px solid ${theme.appBorderColor}`,
|
|
102
117
|
borderRadius: 6
|
|
103
118
|
},
|
|
104
119
|
'&::-ms-thumb': {
|
|
@@ -110,12 +125,6 @@ const RangeInput = styled.input(({
|
|
|
110
125
|
cursor: 'grab',
|
|
111
126
|
marginTop: 0
|
|
112
127
|
},
|
|
113
|
-
'&:focus::-ms-fill-lower': {
|
|
114
|
-
background: '#dddddd'
|
|
115
|
-
},
|
|
116
|
-
'&:focus::-ms-fill-upper': {
|
|
117
|
-
background: '#e0e0e0'
|
|
118
|
-
},
|
|
119
128
|
'@supports (-ms-ime-align:auto)': {
|
|
120
129
|
'input[type=range]': {
|
|
121
130
|
margin: '0'
|
|
@@ -126,13 +135,23 @@ const RangeLabel = styled.span({
|
|
|
126
135
|
paddingLeft: 5,
|
|
127
136
|
paddingRight: 5,
|
|
128
137
|
fontSize: 12,
|
|
129
|
-
whiteSpace: 'nowrap'
|
|
138
|
+
whiteSpace: 'nowrap',
|
|
139
|
+
fontFeatureSettings: 'tnum',
|
|
140
|
+
fontVariantNumeric: 'tabular-nums'
|
|
130
141
|
});
|
|
131
142
|
const RangeWrapper = styled.div({
|
|
132
143
|
display: 'flex',
|
|
133
144
|
alignItems: 'center',
|
|
134
145
|
width: '100%'
|
|
135
146
|
});
|
|
147
|
+
|
|
148
|
+
function getNumberOfDecimalPlaces(number) {
|
|
149
|
+
const match = number.toString().match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
|
|
150
|
+
return !match ? 0 : Math.max(0, // Number of digits right of decimal point.
|
|
151
|
+
(match[1] ? match[1].length : 0) - ( // Adjust for scientific notation.
|
|
152
|
+
match[2] ? +match[2] : 0));
|
|
153
|
+
}
|
|
154
|
+
|
|
136
155
|
export const RangeControl = ({
|
|
137
156
|
name,
|
|
138
157
|
value,
|
|
@@ -148,6 +167,7 @@ export const RangeControl = ({
|
|
|
148
167
|
};
|
|
149
168
|
|
|
150
169
|
const hasValue = value !== undefined;
|
|
170
|
+
const numberOFDecimalsPlaces = useMemo(() => getNumberOfDecimalPlaces(step), [step]);
|
|
151
171
|
return /*#__PURE__*/React.createElement(RangeWrapper, null, /*#__PURE__*/React.createElement(RangeLabel, null, min), /*#__PURE__*/React.createElement(RangeInput, {
|
|
152
172
|
id: getControlId(name),
|
|
153
173
|
type: "range",
|
|
@@ -159,6 +179,6 @@ export const RangeControl = ({
|
|
|
159
179
|
step,
|
|
160
180
|
onFocus,
|
|
161
181
|
onBlur
|
|
162
|
-
}), /*#__PURE__*/React.createElement(RangeLabel, null, `${hasValue ? value : '--'} /
|
|
182
|
+
}), /*#__PURE__*/React.createElement(RangeLabel, null, `${hasValue ? value.toFixed(numberOFDecimalsPlaces) : '--'}`, " / ", max));
|
|
163
183
|
};
|
|
164
184
|
RangeControl.displayName = "RangeControl";
|
|
@@ -5,18 +5,40 @@ export default {
|
|
|
5
5
|
component: RangeControl
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
const Template =
|
|
8
|
+
const Template = ({
|
|
9
|
+
initialValue,
|
|
10
|
+
step,
|
|
11
|
+
max
|
|
12
|
+
}) => {
|
|
9
13
|
const [value, setValue] = useState(initialValue);
|
|
10
14
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(RangeControl, {
|
|
11
15
|
name: "range",
|
|
12
16
|
value: value,
|
|
13
17
|
onChange: newVal => setValue(newVal),
|
|
14
18
|
min: 0,
|
|
15
|
-
max:
|
|
16
|
-
step:
|
|
19
|
+
max: max,
|
|
20
|
+
step: step
|
|
17
21
|
}), /*#__PURE__*/React.createElement("pre", null, JSON.stringify(value) || 'undefined'));
|
|
18
22
|
};
|
|
19
23
|
|
|
20
|
-
export const Basic = () => Template(
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
export const Basic = () => Template({
|
|
25
|
+
initialValue: 10,
|
|
26
|
+
max: 20,
|
|
27
|
+
step: 2
|
|
28
|
+
});
|
|
29
|
+
export const Zero = () => Template({
|
|
30
|
+
initialValue: 0,
|
|
31
|
+
max: 20,
|
|
32
|
+
step: 2
|
|
33
|
+
});
|
|
34
|
+
export const Decimals = () => Template({
|
|
35
|
+
step: 0.000000000002,
|
|
36
|
+
initialValue: 1989.123123123123,
|
|
37
|
+
max: 2000
|
|
38
|
+
});
|
|
39
|
+
export const BigMaxValue = () => Template({
|
|
40
|
+
step: 1000,
|
|
41
|
+
initialValue: 15,
|
|
42
|
+
max: 10000000000
|
|
43
|
+
});
|
|
44
|
+
export const Undefined = () => Template({});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/components",
|
|
3
|
-
"version": "6.3.0-
|
|
3
|
+
"version": "6.3.0-rc.11",
|
|
4
4
|
"description": "Core Storybook Components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook"
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@popperjs/core": "^2.6.0",
|
|
44
|
-
"@storybook/client-logger": "6.3.0-
|
|
44
|
+
"@storybook/client-logger": "6.3.0-rc.11",
|
|
45
45
|
"@storybook/csf": "0.0.1",
|
|
46
|
-
"@storybook/theming": "6.3.0-
|
|
46
|
+
"@storybook/theming": "6.3.0-rc.11",
|
|
47
47
|
"@types/color-convert": "^2.0.0",
|
|
48
48
|
"@types/overlayscrollbars": "^1.12.0",
|
|
49
49
|
"@types/react-syntax-highlighter": "11.0.5",
|
|
@@ -76,6 +76,6 @@
|
|
|
76
76
|
"publishConfig": {
|
|
77
77
|
"access": "public"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "db9968a8a241edf423c5780e229eca3f5e5ce773",
|
|
80
80
|
"sbmodern": "dist/modern/index.js"
|
|
81
81
|
}
|