@snack-uikit/color-picker 0.1.2 → 0.1.3-preview-71543426.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/dist/cjs/components/ColorPicker.js +200 -0
- package/dist/cjs/components/index.js +25 -0
- package/dist/cjs/constants.js +34 -0
- package/dist/cjs/helperComponents/FieldAlphaColor/FieldAlphaColor.js +26 -0
- package/dist/cjs/helperComponents/FieldAlphaColor/index.js +25 -0
- package/dist/cjs/helperComponents/FieldPrivate/FieldPrivate.js +74 -0
- package/dist/cjs/helperComponents/FieldPrivate/index.js +25 -0
- package/dist/cjs/helperComponents/index.js +26 -0
- package/dist/cjs/index.js +26 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/utils/convert.js +267 -0
- package/dist/cjs/utils/index.js +25 -0
- package/dist/cjs/utils/round.js +12 -0
- package/dist/cjs/utils/typeGuards.js +48 -0
- package/dist/cjs/utils/validate.js +20 -0
- package/dist/esm/components/ColorPicker.d.ts +20 -0
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/components/styles.module.css +61 -0
- package/dist/esm/constants.d.ts +20 -0
- package/dist/esm/helperComponents/FieldAlphaColor/FieldAlphaColor.d.ts +16 -0
- package/dist/esm/helperComponents/FieldAlphaColor/index.js +1 -0
- package/dist/esm/helperComponents/FieldPrivate/FieldPrivate.d.ts +14 -0
- package/dist/esm/helperComponents/FieldPrivate/index.js +1 -0
- package/dist/esm/helperComponents/FieldPrivate/styles.module.css +186 -0
- package/dist/esm/helperComponents/index.js +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/types.d.ts +12 -0
- package/dist/esm/utils/convert.d.ts +12 -0
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/round.d.ts +1 -0
- package/dist/esm/utils/typeGuards.d.ts +10 -0
- package/dist/esm/utils/validate.d.ts +1 -0
- package/package.json +12 -10
- /package/dist/{components → cjs/components}/ColorPicker.d.ts +0 -0
- /package/dist/{components → cjs/components}/index.d.ts +0 -0
- /package/dist/{components → cjs/components}/styles.module.css +0 -0
- /package/dist/{constants.d.ts → cjs/constants.d.ts} +0 -0
- /package/dist/{helperComponents → cjs/helperComponents}/FieldAlphaColor/FieldAlphaColor.d.ts +0 -0
- /package/dist/{helperComponents → cjs/helperComponents}/FieldAlphaColor/index.d.ts +0 -0
- /package/dist/{helperComponents → cjs/helperComponents}/FieldPrivate/FieldPrivate.d.ts +0 -0
- /package/dist/{helperComponents → cjs/helperComponents}/FieldPrivate/index.d.ts +0 -0
- /package/dist/{helperComponents → cjs/helperComponents}/FieldPrivate/styles.module.css +0 -0
- /package/dist/{helperComponents → cjs/helperComponents}/index.d.ts +0 -0
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{types.d.ts → cjs/types.d.ts} +0 -0
- /package/dist/{utils → cjs/utils}/convert.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/index.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/round.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/typeGuards.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/validate.d.ts +0 -0
- /package/dist/{components → esm/components}/ColorPicker.js +0 -0
- /package/dist/{components/index.js → esm/components/index.d.ts} +0 -0
- /package/dist/{constants.js → esm/constants.js} +0 -0
- /package/dist/{helperComponents → esm/helperComponents}/FieldAlphaColor/FieldAlphaColor.js +0 -0
- /package/dist/{helperComponents/FieldAlphaColor/index.js → esm/helperComponents/FieldAlphaColor/index.d.ts} +0 -0
- /package/dist/{helperComponents → esm/helperComponents}/FieldPrivate/FieldPrivate.js +0 -0
- /package/dist/{helperComponents/FieldPrivate/index.js → esm/helperComponents/FieldPrivate/index.d.ts} +0 -0
- /package/dist/{helperComponents/index.js → esm/helperComponents/index.d.ts} +0 -0
- /package/dist/{index.js → esm/index.d.ts} +0 -0
- /package/dist/{types.js → esm/types.js} +0 -0
- /package/dist/{utils → esm/utils}/convert.js +0 -0
- /package/dist/{utils/index.js → esm/utils/index.d.ts} +0 -0
- /package/dist/{utils → esm/utils}/round.js +0 -0
- /package/dist/{utils → esm/utils}/typeGuards.js +0 -0
- /package/dist/{utils → esm/utils}/validate.js +0 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __rest = void 0 && (void 0).__rest || function (s, e) {
|
|
4
|
+
var t = {};
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
12
|
+
return mod && mod.__esModule ? mod : {
|
|
13
|
+
"default": mod
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
19
|
+
exports.ColorPicker = ColorPicker;
|
|
20
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
21
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
22
|
+
const react_1 = require("react");
|
|
23
|
+
const react_colorful_1 = require("react-colorful");
|
|
24
|
+
const button_1 = require("@snack-uikit/button");
|
|
25
|
+
const icons_1 = require("@snack-uikit/icons");
|
|
26
|
+
const locale_1 = require("@snack-uikit/locale");
|
|
27
|
+
const segmented_control_1 = require("@snack-uikit/segmented-control");
|
|
28
|
+
const utils_1 = require("@snack-uikit/utils");
|
|
29
|
+
const constants_1 = require("../constants");
|
|
30
|
+
const helperComponents_1 = require("../helperComponents");
|
|
31
|
+
const FieldAlphaColor_1 = require("../helperComponents/FieldAlphaColor/FieldAlphaColor");
|
|
32
|
+
const convert_1 = require("../utils/convert");
|
|
33
|
+
const validate_1 = require("../utils/validate");
|
|
34
|
+
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
35
|
+
function ColorPicker(_a) {
|
|
36
|
+
var {
|
|
37
|
+
value,
|
|
38
|
+
onChange,
|
|
39
|
+
withAlpha = true,
|
|
40
|
+
autoApply,
|
|
41
|
+
className,
|
|
42
|
+
colorMode: colorModeProp = constants_1.DEFAULT_COLOR_MODE_CONFIG
|
|
43
|
+
} = _a,
|
|
44
|
+
rest = __rest(_a, ["value", "onChange", "withAlpha", "autoApply", "className", "colorMode"]);
|
|
45
|
+
const colorModeOptions = (0, react_1.useMemo)(() => {
|
|
46
|
+
const colorModeConfig = Object.assign(Object.assign({}, constants_1.DEFAULT_COLOR_MODE_CONFIG), colorModeProp);
|
|
47
|
+
return Object.keys(colorModeConfig).reduce((res, colorMode) => {
|
|
48
|
+
if (Boolean(colorModeConfig[colorMode])) {
|
|
49
|
+
res.push({
|
|
50
|
+
value: colorMode,
|
|
51
|
+
label: constants_1.COLOR_MODE_LABEL[colorMode]
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return res;
|
|
55
|
+
}, []);
|
|
56
|
+
}, [colorModeProp]);
|
|
57
|
+
const [rawValue, setRawValue] = (0, react_1.useState)((0, convert_1.colorToRawValue)(value || '#000'));
|
|
58
|
+
const [colorMode, setColorMode] = (0, react_1.useState)(colorModeOptions[0].value);
|
|
59
|
+
const [tempHex, setTempHex] = (0, react_1.useState)(rawValue.hex);
|
|
60
|
+
(0, react_1.useEffect)(() => {
|
|
61
|
+
if (value) {
|
|
62
|
+
const raw = (0, convert_1.colorToRawValue)(value);
|
|
63
|
+
setRawValue(raw);
|
|
64
|
+
setTempHex(raw.hex);
|
|
65
|
+
}
|
|
66
|
+
}, [value]);
|
|
67
|
+
const handleChange = color => {
|
|
68
|
+
const rawValue = (0, convert_1.colorToRawValue)(color);
|
|
69
|
+
setRawValue(rawValue);
|
|
70
|
+
autoApply && (onChange === null || onChange === void 0 ? void 0 : onChange(rawValue));
|
|
71
|
+
};
|
|
72
|
+
const applyChange = () => {
|
|
73
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(rawValue);
|
|
74
|
+
};
|
|
75
|
+
const reset = () => {
|
|
76
|
+
value && setRawValue((0, convert_1.colorToRawValue)(value));
|
|
77
|
+
};
|
|
78
|
+
const {
|
|
79
|
+
t
|
|
80
|
+
} = (0, locale_1.useLocale)('ColorPicker');
|
|
81
|
+
return (0, jsx_runtime_1.jsxs)("div", Object.assign({
|
|
82
|
+
className: (0, classnames_1.default)(styles_module_scss_1.default.container, 'osThemeSnack', className)
|
|
83
|
+
}, (0, utils_1.extractSupportProps)(rest), {
|
|
84
|
+
children: [colorMode === constants_1.COLOR_MODE.Hex && (withAlpha ? (0, jsx_runtime_1.jsx)(react_colorful_1.HexAlphaColorPicker, {
|
|
85
|
+
onChange: handleChange,
|
|
86
|
+
color: rawValue.hex
|
|
87
|
+
}) : (0, jsx_runtime_1.jsx)(react_colorful_1.HexColorPicker, {
|
|
88
|
+
onChange: handleChange,
|
|
89
|
+
color: rawValue.hex
|
|
90
|
+
})), colorMode === constants_1.COLOR_MODE.Rbg && (withAlpha ? (0, jsx_runtime_1.jsx)(react_colorful_1.RgbaColorPicker, {
|
|
91
|
+
onChange: handleChange,
|
|
92
|
+
color: rawValue.rgba
|
|
93
|
+
}) : (0, jsx_runtime_1.jsx)(react_colorful_1.RgbColorPicker, {
|
|
94
|
+
onChange: handleChange,
|
|
95
|
+
color: rawValue.rgb
|
|
96
|
+
})), colorMode === constants_1.COLOR_MODE.Hsv && (withAlpha ? (0, jsx_runtime_1.jsx)(react_colorful_1.HsvaColorPicker, {
|
|
97
|
+
onChange: handleChange,
|
|
98
|
+
color: rawValue.hsva
|
|
99
|
+
}) : (0, jsx_runtime_1.jsx)(react_colorful_1.HsvColorPicker, {
|
|
100
|
+
onChange: handleChange,
|
|
101
|
+
color: rawValue.hsv
|
|
102
|
+
})), (0, jsx_runtime_1.jsxs)("div", {
|
|
103
|
+
className: styles_module_scss_1.default.colorModel,
|
|
104
|
+
children: [(0, jsx_runtime_1.jsx)(segmented_control_1.SegmentedControl, {
|
|
105
|
+
outline: true,
|
|
106
|
+
value: colorMode,
|
|
107
|
+
size: 's',
|
|
108
|
+
onChange: setColorMode,
|
|
109
|
+
items: colorModeOptions
|
|
110
|
+
}), (0, jsx_runtime_1.jsxs)("div", {
|
|
111
|
+
className: styles_module_scss_1.default.colorFields,
|
|
112
|
+
"data-mode": colorMode,
|
|
113
|
+
"data-with-alpha": withAlpha || undefined,
|
|
114
|
+
children: [(0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, {
|
|
115
|
+
children: [colorMode === constants_1.COLOR_MODE.Hex && (0, jsx_runtime_1.jsx)(helperComponents_1.FieldPrivate, {
|
|
116
|
+
value: rawValue.hex.replace('#', '').substring(0, 6),
|
|
117
|
+
error: !(0, validate_1.validHex)(tempHex, withAlpha),
|
|
118
|
+
inputType: 'text',
|
|
119
|
+
onChange: function () {
|
|
120
|
+
let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
121
|
+
setTempHex(value);
|
|
122
|
+
if ((0, validate_1.validHex)(value)) {
|
|
123
|
+
handleChange(Object.assign(Object.assign({}, (0, convert_1.hexToRgba)(value)), {
|
|
124
|
+
a: rawValue.rgba.a
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}), colorMode === constants_1.COLOR_MODE.Rbg && (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, {
|
|
129
|
+
children: [(0, jsx_runtime_1.jsx)(helperComponents_1.FieldPrivate, {
|
|
130
|
+
value: rawValue.rgb.r,
|
|
131
|
+
max: 255,
|
|
132
|
+
onChange: value => {
|
|
133
|
+
handleChange(Object.assign(Object.assign({}, rawValue.rgba), {
|
|
134
|
+
r: Number(value)
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
}), (0, jsx_runtime_1.jsx)(helperComponents_1.FieldPrivate, {
|
|
138
|
+
value: rawValue.rgb.g,
|
|
139
|
+
max: 255,
|
|
140
|
+
onChange: value => {
|
|
141
|
+
handleChange(Object.assign(Object.assign({}, rawValue.rgba), {
|
|
142
|
+
g: Number(value)
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
}), (0, jsx_runtime_1.jsx)(helperComponents_1.FieldPrivate, {
|
|
146
|
+
value: rawValue.rgb.b,
|
|
147
|
+
max: 255,
|
|
148
|
+
onChange: value => {
|
|
149
|
+
handleChange(Object.assign(Object.assign({}, rawValue.rgba), {
|
|
150
|
+
b: Number(value)
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
})]
|
|
154
|
+
}), colorMode === constants_1.COLOR_MODE.Hsv && (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, {
|
|
155
|
+
children: [(0, jsx_runtime_1.jsx)(helperComponents_1.FieldPrivate, {
|
|
156
|
+
value: rawValue.hsv.h,
|
|
157
|
+
max: 360,
|
|
158
|
+
onChange: value => {
|
|
159
|
+
handleChange(Object.assign(Object.assign({}, rawValue.hsva), {
|
|
160
|
+
h: Number(value)
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
}), (0, jsx_runtime_1.jsx)(helperComponents_1.FieldPrivate, {
|
|
164
|
+
value: rawValue.hsv.s,
|
|
165
|
+
max: 100,
|
|
166
|
+
onChange: value => {
|
|
167
|
+
handleChange(Object.assign(Object.assign({}, rawValue.hsva), {
|
|
168
|
+
s: Number(value)
|
|
169
|
+
}));
|
|
170
|
+
}
|
|
171
|
+
}), (0, jsx_runtime_1.jsx)(helperComponents_1.FieldPrivate, {
|
|
172
|
+
value: rawValue.hsv.v,
|
|
173
|
+
max: 100,
|
|
174
|
+
onChange: value => {
|
|
175
|
+
handleChange(Object.assign(Object.assign({}, rawValue.hsva), {
|
|
176
|
+
v: Number(value)
|
|
177
|
+
}));
|
|
178
|
+
}
|
|
179
|
+
})]
|
|
180
|
+
})]
|
|
181
|
+
}), withAlpha && (0, jsx_runtime_1.jsx)(FieldAlphaColor_1.FieldAlphaColor, {
|
|
182
|
+
rgba: rawValue.rgba,
|
|
183
|
+
onChange: handleChange
|
|
184
|
+
})]
|
|
185
|
+
})]
|
|
186
|
+
}), !autoApply && (0, jsx_runtime_1.jsxs)("div", {
|
|
187
|
+
className: styles_module_scss_1.default.footer,
|
|
188
|
+
children: [(0, jsx_runtime_1.jsx)(button_1.ButtonFunction, {
|
|
189
|
+
label: t('cancel'),
|
|
190
|
+
size: 'xs',
|
|
191
|
+
onClick: reset
|
|
192
|
+
}), (0, jsx_runtime_1.jsx)(button_1.ButtonFilled, {
|
|
193
|
+
label: t('apply'),
|
|
194
|
+
icon: (0, jsx_runtime_1.jsx)(icons_1.CheckSVG, {}),
|
|
195
|
+
onClick: applyChange,
|
|
196
|
+
size: 'xs'
|
|
197
|
+
})]
|
|
198
|
+
})]
|
|
199
|
+
}));
|
|
200
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return m[k];
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
} : function (o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
});
|
|
19
|
+
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
});
|
|
25
|
+
__exportStar(require("./ColorPicker"), exports);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.HSLA_REGEX = exports.HSVA_REGEX = exports.RGBA_REGEX = exports.DEFAULT_COLOR_MODE_CONFIG = exports.COLOR_MODE_LABEL = exports.COLOR_MODE_OPTIONS = exports.COLOR_MODE = void 0;
|
|
7
|
+
exports.COLOR_MODE = {
|
|
8
|
+
Hex: 'hex',
|
|
9
|
+
Rbg: 'rbg',
|
|
10
|
+
Hsv: 'hsv'
|
|
11
|
+
};
|
|
12
|
+
exports.COLOR_MODE_OPTIONS = [{
|
|
13
|
+
value: exports.COLOR_MODE.Hex,
|
|
14
|
+
label: 'HEX'
|
|
15
|
+
}, {
|
|
16
|
+
value: exports.COLOR_MODE.Hsv,
|
|
17
|
+
label: 'HSV'
|
|
18
|
+
}, {
|
|
19
|
+
value: exports.COLOR_MODE.Rbg,
|
|
20
|
+
label: 'RGB'
|
|
21
|
+
}];
|
|
22
|
+
exports.COLOR_MODE_LABEL = {
|
|
23
|
+
[exports.COLOR_MODE.Hex]: 'HEX',
|
|
24
|
+
[exports.COLOR_MODE.Rbg]: 'RGB',
|
|
25
|
+
[exports.COLOR_MODE.Hsv]: 'HSV'
|
|
26
|
+
};
|
|
27
|
+
exports.DEFAULT_COLOR_MODE_CONFIG = {
|
|
28
|
+
[exports.COLOR_MODE.Hex]: true,
|
|
29
|
+
[exports.COLOR_MODE.Rbg]: true,
|
|
30
|
+
[exports.COLOR_MODE.Hsv]: true
|
|
31
|
+
};
|
|
32
|
+
exports.RGBA_REGEX = /rgba?\(?\s*(-?\d*\.?\d+)(%)?[,\s]+(-?\d*\.?\d+)(%)?[,\s]+(-?\d*\.?\d+)(%)?,?\s*[/\s]*(-?\d*\.?\d+)?(%)?\s*\)?/i;
|
|
33
|
+
exports.HSVA_REGEX = /hsva?\(?\s*(-?\d*\.?\d+)(deg|rad|grad|turn)?[,\s]+(-?\d*\.?\d+)%?[,\s]+(-?\d*\.?\d+)%?,?\s*[/\s]*(-?\d*\.?\d+)?(%)?\s*\)?/i;
|
|
34
|
+
exports.HSLA_REGEX = /hsla?\(?\s*(-?\d*\.?\d+)(deg|rad|grad|turn)?[,\s]+(-?\d*\.?\d+)%?[,\s]+(-?\d*\.?\d+)%?,?\s*[/\s]*(-?\d*\.?\d+)?(%)?\s*\)?/i;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FieldAlphaColor = FieldAlphaColor;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const FieldPrivate_1 = require("../FieldPrivate");
|
|
9
|
+
function FieldAlphaColor(_ref) {
|
|
10
|
+
let {
|
|
11
|
+
onChange,
|
|
12
|
+
rgba
|
|
13
|
+
} = _ref;
|
|
14
|
+
const handleChange = a => {
|
|
15
|
+
onChange(Object.assign(Object.assign({}, rgba), {
|
|
16
|
+
a: Number(a) % 100 / 100
|
|
17
|
+
}));
|
|
18
|
+
};
|
|
19
|
+
return (0, jsx_runtime_1.jsx)(FieldPrivate_1.FieldPrivate, {
|
|
20
|
+
value: rgba.a * 100,
|
|
21
|
+
onChange: handleChange,
|
|
22
|
+
inputType: 'number',
|
|
23
|
+
min: 0,
|
|
24
|
+
max: 100
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return m[k];
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
} : function (o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
});
|
|
19
|
+
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
});
|
|
25
|
+
__exportStar(require("./FieldAlphaColor"), exports);
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
4
|
+
return mod && mod.__esModule ? mod : {
|
|
5
|
+
"default": mod
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
exports.FieldPrivate = FieldPrivate;
|
|
12
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
13
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
14
|
+
const react_1 = require("react");
|
|
15
|
+
const input_private_1 = require("@snack-uikit/input-private");
|
|
16
|
+
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
17
|
+
function FieldPrivate(_ref) {
|
|
18
|
+
let {
|
|
19
|
+
className,
|
|
20
|
+
disabled,
|
|
21
|
+
focused,
|
|
22
|
+
style,
|
|
23
|
+
value = '',
|
|
24
|
+
onChange,
|
|
25
|
+
min = 0,
|
|
26
|
+
max = 255,
|
|
27
|
+
inputType = 'number',
|
|
28
|
+
error
|
|
29
|
+
} = _ref;
|
|
30
|
+
const inputRef = (0, react_1.useRef)(null);
|
|
31
|
+
const handleContainerClick = () => {
|
|
32
|
+
var _a;
|
|
33
|
+
if (disabled) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
(_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
37
|
+
};
|
|
38
|
+
const [rawValue, setRawValue] = (0, react_1.useState)('');
|
|
39
|
+
const handleBlur = () => {
|
|
40
|
+
if (inputType === 'number') {
|
|
41
|
+
const rawNumberValue = Number(rawValue) || 0;
|
|
42
|
+
const newValue = String(Math.min(Math.max(min, rawNumberValue), Math.min(max, rawNumberValue)));
|
|
43
|
+
setRawValue(newValue);
|
|
44
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(rawValue);
|
|
48
|
+
};
|
|
49
|
+
(0, react_1.useEffect)(() => {
|
|
50
|
+
setRawValue(String(value));
|
|
51
|
+
}, [value]);
|
|
52
|
+
return (0, jsx_runtime_1.jsx)("div", {
|
|
53
|
+
className: (0, classnames_1.default)(className, styles_module_scss_1.default.container),
|
|
54
|
+
style: style,
|
|
55
|
+
"data-focused": focused || undefined,
|
|
56
|
+
"data-validation": error ? 'error' : undefined,
|
|
57
|
+
"data-test-id": 'field-container-private',
|
|
58
|
+
onClick: handleContainerClick,
|
|
59
|
+
"data-size": 's',
|
|
60
|
+
"data-variant": 'single-line-container',
|
|
61
|
+
role: 'textbox',
|
|
62
|
+
tabIndex: -1,
|
|
63
|
+
children: (0, jsx_runtime_1.jsx)(input_private_1.InputPrivate, Object.assign({
|
|
64
|
+
value: String(rawValue),
|
|
65
|
+
onChange: setRawValue,
|
|
66
|
+
onBlur: handleBlur,
|
|
67
|
+
type: inputType,
|
|
68
|
+
ref: inputRef
|
|
69
|
+
}, inputType === 'number' ? {
|
|
70
|
+
min,
|
|
71
|
+
max
|
|
72
|
+
} : {}))
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return m[k];
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
} : function (o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
});
|
|
19
|
+
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
});
|
|
25
|
+
__exportStar(require("./FieldPrivate"), exports);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return m[k];
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
} : function (o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
});
|
|
19
|
+
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
});
|
|
25
|
+
__exportStar(require("./FieldPrivate"), exports);
|
|
26
|
+
__exportStar(require("./FieldAlphaColor"), exports);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return m[k];
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
} : function (o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
});
|
|
19
|
+
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
});
|
|
25
|
+
__exportStar(require("./components"), exports);
|
|
26
|
+
__exportStar(require("./types"), exports);
|