@festo-ui/react 9.0.0-dev.681 → 9.0.0-dev.684

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.
@@ -1,545 +0,0 @@
1
- /* eslint-disable jsx-a11y/no-static-element-interactions */
2
- /* eslint-disable jsx-a11y/click-events-have-key-events */
3
-
4
- import { useRef, useCallback, useEffect, useState } from "react";
5
- import Draggable from "react-draggable";
6
- import classNames from "classnames";
7
- import { IconCheckSmall, IconCollapse } from "@festo-ui/react-icons";
8
- import ColorHelper from "./ColorHelper.js";
9
- import useId from "../../helper/useId.js";
10
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
- export const PREDEFINED_COLORS = ["#0091dc", "#333333", "#ffffff", "#f0f2f3", "#e2e5e8", "#d3d8dd", "#b6bec6", "#80ca3d", "#ffd600", "#ff9600", "#d50000"];
12
- function ColorPicker(_ref) {
13
- let {
14
- palette = PREDEFINED_COLORS,
15
- useAlpha = false,
16
- alpha = 100,
17
- paletteOnly,
18
- color = "#FFFFFF",
19
- onChange,
20
- onAlphaChange,
21
- className
22
- } = _ref;
23
- const baseSize = 184;
24
- const initialRgb = ColorHelper.hexToRgb(color);
25
- const defaultHsv = {
26
- h: 0,
27
- s: 0,
28
- v: 1
29
- };
30
- const initialHsv = initialRgb ? ColorHelper.rgbToHsv(initialRgb) || defaultHsv : defaultHsv;
31
- const [hsv, setHsv] = useState(initialHsv);
32
- const [innerColor, setInnerColor] = useState(color);
33
- const [redInput, setRedInput] = useState(initialRgb?.r || 255);
34
- const [greenInput, setGreenInput] = useState(initialRgb?.g || 255);
35
- const [blueInput, setBlueInput] = useState(initialRgb?.b || 255);
36
- const [hexInputColor, setHexInputColor] = useState(color);
37
- const [inputType, setInputType] = useState("RGB");
38
- const [selectOpen, setSelectOpen] = useState(false);
39
- const [innerAlpha, setInnerAlpha] = useState(alpha);
40
- const [changeColor, setChangeColor] = useState(true);
41
- const redId = useId();
42
- const greenId = useId();
43
- const blueId = useId();
44
- const hexId = useId();
45
- const alphaId = useId();
46
- const gradientKnobRef = useRef(null);
47
- const hueKnobRef = useRef(null);
48
- const alphaKnobRef = useRef(null);
49
- function limitAlpha() {
50
- if (innerAlpha > 100) {
51
- return 100;
52
- }
53
- if (innerAlpha < 0) {
54
- return 0;
55
- }
56
- return innerAlpha;
57
- }
58
- const hueKnobOffset = hsv.h * baseSize - 14 - baseSize;
59
- const saturationKnobOffset = hsv.s * baseSize;
60
- const valueKnobOffset = (1 - hsv.v) * baseSize;
61
- const alphaKnobOffset = (100 - limitAlpha()) / 100 * baseSize;
62
- function getSaturationGradient() {
63
- return `linear-gradient(to right, white, hsl(${hsv.h * 360}, 100%, 50%) )`;
64
- }
65
- function updateInputs(hexColor) {
66
- setHexInputColor(hexColor);
67
- const rgb = ColorHelper.hexToRgb(hexColor);
68
- if (rgb) {
69
- setRedInput(rgb.r);
70
- setGreenInput(rgb.g);
71
- setBlueInput(rgb.b);
72
- }
73
- }
74
- useEffect(() => {
75
- if (onChange) {
76
- onChange(innerColor);
77
- }
78
- }, [onChange, innerColor]);
79
- useEffect(() => {
80
- if (onAlphaChange && innerAlpha) {
81
- onAlphaChange(innerAlpha);
82
- }
83
- }, [onAlphaChange, innerAlpha]);
84
- const updateColorHsv = useCallback((_hsv, _changeColor) => {
85
- const rgb = ColorHelper.hsvToRgb(_hsv);
86
- const hex = ColorHelper.rgbToHex(rgb);
87
- if (_changeColor) {
88
- setInnerColor(hex);
89
- }
90
- updateInputs(hex);
91
- }, []);
92
- useEffect(() => {
93
- updateColorHsv(hsv, changeColor);
94
- }, [updateColorHsv, hsv, changeColor]);
95
- function updateGradient(x, y) {
96
- setChangeColor(true);
97
- setHsv(prevHsv => ({
98
- ...prevHsv,
99
- s: Math.floor(x) / baseSize,
100
- v: (baseSize - y) / baseSize
101
- }));
102
- }
103
- function onGradientDrag(e, data) {
104
- e.preventDefault();
105
- updateGradient(data.x, data.y);
106
- }
107
- function updateHue(y) {
108
- const newHue = y / baseSize;
109
- setChangeColor(true);
110
- setHsv(prevHsv => ({
111
- ...prevHsv,
112
- h: newHue
113
- }));
114
- }
115
- function onHueDrag(e, data) {
116
- e.preventDefault();
117
- updateHue(data.y + 14 + baseSize);
118
- }
119
- function updateAlpha(y) {
120
- setInnerAlpha(100 - Math.round(y / baseSize * 100));
121
- }
122
- function onAlphaDrag(e, data) {
123
- e.preventDefault();
124
- updateAlpha(data.y);
125
- }
126
- const updateColorRgb = newColor => {
127
- const currentColor = newColor || "#FFFFFF";
128
- updateInputs(currentColor);
129
- const rgb = ColorHelper.hexToRgb(currentColor);
130
- setChangeColor(false);
131
- if (rgb) {
132
- const newHsv = ColorHelper.rgbToHsv(rgb);
133
- if (newHsv) {
134
- setHsv(newHsv);
135
- }
136
- }
137
- setInnerColor(newColor);
138
- };
139
- const isHexColor = _color => /^#[0-9A-F]{6}$/i.test(_color);
140
- function onHexInput(event) {
141
- const newHexInputColor = event.target.value;
142
- setHexInputColor(newHexInputColor.toUpperCase());
143
- if (isHexColor(newHexInputColor)) {
144
- updateColorRgb(newHexInputColor.toUpperCase());
145
- }
146
- }
147
- function onHexBlur() {
148
- if (!isHexColor(hexInputColor) && innerColor) {
149
- setHexInputColor(innerColor);
150
- updateColorRgb(innerColor);
151
- }
152
- }
153
- function onRgbBlur(channel) {
154
- let currentInput = "";
155
- switch (channel) {
156
- case "r":
157
- currentInput = redInput;
158
- break;
159
- case "g":
160
- currentInput = greenInput;
161
- break;
162
- case "b":
163
- currentInput = blueInput;
164
- break;
165
- default:
166
- // no other value possible
167
- }
168
- if (typeof currentInput !== "number" || typeof currentInput === "number" && currentInput > 255 && currentInput < 0) {
169
- const rgb = ColorHelper.hexToRgb(innerColor || "#FFFFFF");
170
- if (rgb) {
171
- const newHexColor = ColorHelper.rgbToHex(rgb);
172
- updateInputs(newHexColor);
173
- }
174
- }
175
- }
176
- function onRgbInput(_value, channel) {
177
- const numberValue = Number.parseInt(_value, 10);
178
- switch (channel) {
179
- case "r":
180
- setRedInput(_value);
181
- break;
182
- case "g":
183
- setGreenInput(_value);
184
- break;
185
- case "b":
186
- setBlueInput(_value);
187
- break;
188
- default:
189
- // no other value possible
190
- }
191
- if (numberValue <= 255 && numberValue >= 0) {
192
- const rgb = ColorHelper.hexToRgb(innerColor || "#FFFFFF");
193
- if (rgb) {
194
- rgb[channel] = numberValue;
195
- const newHexColor = ColorHelper.rgbToHex(rgb);
196
- setInnerColor(newHexColor);
197
- updateColorRgb(newHexColor);
198
- }
199
- }
200
- }
201
- function onAlphaInput(_alpha) {
202
- const numberValue = Number.parseInt(_alpha, 10);
203
- setInnerAlpha(numberValue);
204
- }
205
- function onAlphaBlur() {
206
- setInnerAlpha(limitAlpha());
207
- }
208
- const onChangeType = type => {
209
- setInputType(type);
210
- setSelectOpen(false);
211
- };
212
- function onRemoveColor() {
213
- if (useAlpha) {
214
- setInnerAlpha(0);
215
- } else {
216
- updateColorRgb();
217
- }
218
- }
219
- return /*#__PURE__*/_jsxs("div", {
220
- className: classNames("fwe-color-picker", {
221
- "fwe-alpha-active": useAlpha
222
- }, className),
223
- children: [!paletteOnly && /*#__PURE__*/_jsxs("div", {
224
- className: "fwe-d-flex",
225
- children: [/*#__PURE__*/_jsxs("div", {
226
- className: "fwe-gradient-picker",
227
- children: [/*#__PURE__*/_jsx("div", {
228
- className: "fwe-saturation-gradient",
229
- style: {
230
- backgroundImage: getSaturationGradient()
231
- }
232
- }), /*#__PURE__*/_jsx("div", {
233
- "aria-label": "brightness-gradient",
234
- onClick: _ref2 => {
235
- let {
236
- nativeEvent: {
237
- offsetX,
238
- offsetY
239
- }
240
- } = _ref2;
241
- return updateGradient(offsetX, offsetY);
242
- },
243
- className: "fwe-brightness-gradient"
244
- }), /*#__PURE__*/_jsx(Draggable, {
245
- position: {
246
- x: saturationKnobOffset,
247
- y: valueKnobOffset
248
- },
249
- onDrag: (e, data) => onGradientDrag(e, data),
250
- bounds: "parent",
251
- nodeRef: gradientKnobRef,
252
- children: /*#__PURE__*/_jsx("div", {
253
- className: "fwe-knob",
254
- ref: gradientKnobRef
255
- })
256
- })]
257
- }), /*#__PURE__*/_jsxs("div", {
258
- className: "fwe-hue-picker",
259
- children: [/*#__PURE__*/_jsx("div", {
260
- className: "fwe-picker-background",
261
- onClick: _ref3 => {
262
- let {
263
- nativeEvent: {
264
- offsetY
265
- }
266
- } = _ref3;
267
- return updateHue(offsetY);
268
- }
269
- }), /*#__PURE__*/_jsx(Draggable, {
270
- position: {
271
- x: 3,
272
- y: hueKnobOffset
273
- },
274
- onDrag: (e, data) => onHueDrag(e, data),
275
- bounds: "parent",
276
- nodeRef: hueKnobRef,
277
- children: /*#__PURE__*/_jsx("div", {
278
- className: "fwe-knob",
279
- style: {
280
- background: `hsl(${hsv.h * 360}, 100%, 50%)`
281
- },
282
- ref: hueKnobRef
283
- })
284
- })]
285
- }), useAlpha && /*#__PURE__*/_jsxs("div", {
286
- className: "fwe-alpha-picker",
287
- children: [/*#__PURE__*/_jsxs("svg", {
288
- className: "fwe-no-color-pattern",
289
- version: "1.1",
290
- xmlns: "http://www.w3.org/2000/svg",
291
- xmlnsXlink: "http://www.w3.org/1999/xlink",
292
- id: "canvas1",
293
- width: "8",
294
- height: "184",
295
- children: [/*#__PURE__*/_jsx("defs", {
296
- children: /*#__PURE__*/_jsxs("pattern", {
297
- id: "bwsquare2px",
298
- width: "4",
299
- height: "4",
300
- patternUnits: "userSpaceOnUse",
301
- children: [/*#__PURE__*/_jsx("rect", {
302
- x: "0",
303
- y: "0",
304
- width: "2",
305
- height: "2",
306
- stroke: "none",
307
- fill: "#ffffff"
308
- }), /*#__PURE__*/_jsx("rect", {
309
- x: "2",
310
- y: "0",
311
- width: "2",
312
- height: "2",
313
- stroke: "none",
314
- fill: "#e2e5e8"
315
- }), /*#__PURE__*/_jsx("rect", {
316
- x: "0",
317
- y: "2",
318
- width: "2",
319
- height: "2",
320
- stroke: "none",
321
- fill: "#e2e5e8"
322
- }), /*#__PURE__*/_jsx("rect", {
323
- x: "2",
324
- y: "2",
325
- width: "2",
326
- height: "2",
327
- stroke: "none",
328
- fill: "#ffffff"
329
- })]
330
- })
331
- }), /*#__PURE__*/_jsx("rect", {
332
- x: "0",
333
- y: "0",
334
- rx: "4",
335
- ry: "4",
336
- width: "8",
337
- height: "184",
338
- fill: "url(#bwsquare2px)",
339
- strokeWidth: "0"
340
- })]
341
- }), /*#__PURE__*/_jsx("div", {
342
- onClick: _ref4 => {
343
- let {
344
- nativeEvent: {
345
- offsetY
346
- }
347
- } = _ref4;
348
- return updateAlpha(offsetY);
349
- },
350
- className: "fwe-picker-background",
351
- style: {
352
- backgroundImage: `linear-gradient( ${innerColor}, transparent)`
353
- }
354
- }), /*#__PURE__*/_jsx(Draggable, {
355
- position: {
356
- x: 3,
357
- y: alphaKnobOffset
358
- },
359
- onDrag: (e, data) => onAlphaDrag(e, data),
360
- bounds: "parent",
361
- nodeRef: alphaKnobRef,
362
- children: /*#__PURE__*/_jsx("div", {
363
- className: "fwe-knob",
364
- ref: alphaKnobRef
365
- })
366
- })]
367
- })]
368
- }), !paletteOnly && /*#__PURE__*/_jsxs("div", {
369
- className: "fwe-mt-s",
370
- children: [/*#__PURE__*/_jsxs("div", {
371
- className: "fwe-type-select",
372
- children: [/*#__PURE__*/_jsxs("div", {
373
- className: "fwe-type-indicator",
374
- onClick: () => setSelectOpen(prevOpen => !prevOpen),
375
- children: [/*#__PURE__*/_jsx("span", {
376
- className: "fwe-input-type",
377
- children: inputType
378
- }), /*#__PURE__*/_jsx(IconCollapse, {
379
- className: "fwe-ml-s"
380
- })]
381
- }), selectOpen && /*#__PURE__*/_jsxs("div", {
382
- className: "fwe-popover",
383
- children: [/*#__PURE__*/_jsxs("div", {
384
- className: classNames("fwe-type-item", {
385
- "fwe-selected": inputType === "HEX"
386
- }),
387
- onClick: () => onChangeType("HEX"),
388
- children: [/*#__PURE__*/_jsx(IconCheckSmall, {}), " HEX"]
389
- }), /*#__PURE__*/_jsxs("div", {
390
- className: classNames("fwe-type-item", {
391
- "fwe-selected": inputType === "RGB"
392
- }),
393
- onClick: () => onChangeType("RGB"),
394
- children: [/*#__PURE__*/_jsx(IconCheckSmall, {}), " RGB"]
395
- })]
396
- })]
397
- }), /*#__PURE__*/_jsxs("div", {
398
- className: "fwe-d-flex",
399
- children: [inputType === "HEX" && /*#__PURE__*/_jsx("label", {
400
- "aria-label": "Hexadecimal Color",
401
- className: "fwe-input-text fwe-hex-input",
402
- htmlFor: hexId,
403
- children: /*#__PURE__*/_jsx("input", {
404
- type: "text",
405
- value: hexInputColor,
406
- onBlur: onHexBlur,
407
- onChange: onHexInput,
408
- id: hexId
409
- })
410
- }), inputType === "RGB" && /*#__PURE__*/_jsxs(_Fragment, {
411
- children: [/*#__PURE__*/_jsx("label", {
412
- "aria-label": "RGB Color Red",
413
- className: "fwe-input-text fwe-red-input",
414
- htmlFor: redId,
415
- children: /*#__PURE__*/_jsx("input", {
416
- type: "text",
417
- value: redInput,
418
- onBlur: () => onRgbBlur("r"),
419
- onChange: e => onRgbInput(e.target.value, "r"),
420
- id: redId
421
- })
422
- }), /*#__PURE__*/_jsx("label", {
423
- "aria-label": "RGB Color Green",
424
- className: "fwe-input-text fwe-green-input",
425
- htmlFor: greenId,
426
- children: /*#__PURE__*/_jsx("input", {
427
- type: "text",
428
- value: greenInput,
429
- onBlur: () => onRgbBlur("g"),
430
- onChange: e => onRgbInput(e.target.value, "g"),
431
- id: greenId
432
- })
433
- }), /*#__PURE__*/_jsx("label", {
434
- "aria-label": "RGB Color Blue",
435
- className: "fwe-input-text fwe-blue-input",
436
- htmlFor: blueId,
437
- children: /*#__PURE__*/_jsx("input", {
438
- type: "text",
439
- value: blueInput,
440
- onBlur: () => onRgbBlur("b"),
441
- onChange: e => onRgbInput(e.target.value, "b"),
442
- id: blueId
443
- })
444
- })]
445
- }), useAlpha && /*#__PURE__*/_jsx("label", {
446
- "aria-label": "Alpha Channel",
447
- className: "fwe-input-text fwe-alpha-input fwe-ml-auto",
448
- htmlFor: alphaId,
449
- children: /*#__PURE__*/_jsxs("span", {
450
- children: [/*#__PURE__*/_jsx("input", {
451
- type: "number",
452
- min: "0",
453
- max: "100",
454
- value: innerAlpha,
455
- onBlur: () => onAlphaBlur(),
456
- onChange: e => onAlphaInput(e.target.value),
457
- id: alphaId
458
- }), /*#__PURE__*/_jsx("span", {
459
- className: "fwe-percent-char",
460
- children: "%"
461
- })]
462
- })
463
- })]
464
- })]
465
- }), /*#__PURE__*/_jsxs("div", {
466
- className: "fwe-mt-xs fwe-color-grid",
467
- children: [/*#__PURE__*/_jsxs("div", {
468
- className: "fwe-remove-color-button",
469
- onClick: onRemoveColor,
470
- children: [/*#__PURE__*/_jsxs("svg", {
471
- className: "fwe-no-color-pattern",
472
- version: "1.1",
473
- xmlns: "http://www.w3.org/2000/svg",
474
- xmlnsXlink: "http://www.w3.org/1999/xlink",
475
- id: "canvas1",
476
- width: "18",
477
- height: "18",
478
- children: [/*#__PURE__*/_jsx("defs", {
479
- children: /*#__PURE__*/_jsxs("pattern", {
480
- id: "bwsquare2px",
481
- width: "4",
482
- height: "4",
483
- patternUnits: "userSpaceOnUse",
484
- children: [/*#__PURE__*/_jsx("rect", {
485
- x: "0",
486
- y: "0",
487
- width: "2",
488
- height: "2",
489
- stroke: "none",
490
- fill: "#ffffff"
491
- }), /*#__PURE__*/_jsx("rect", {
492
- x: "2",
493
- y: "0",
494
- width: "2",
495
- height: "2",
496
- stroke: "none",
497
- fill: "#e2e5e8"
498
- }), /*#__PURE__*/_jsx("rect", {
499
- x: "0",
500
- y: "2",
501
- width: "2",
502
- height: "2",
503
- stroke: "none",
504
- fill: "#e2e5e8"
505
- }), /*#__PURE__*/_jsx("rect", {
506
- x: "2",
507
- y: "2",
508
- width: "2",
509
- height: "2",
510
- stroke: "none",
511
- fill: "#ffffff"
512
- })]
513
- })
514
- }), /*#__PURE__*/_jsx("rect", {
515
- x: "0",
516
- y: "0",
517
- rx: "0",
518
- ry: "0",
519
- width: "18",
520
- height: "18",
521
- fill: "url(#bwsquare2px)",
522
- strokeWidth: "0"
523
- })]
524
- }), /*#__PURE__*/_jsx(IconCheckSmall, {
525
- className: classNames({
526
- "fwe-color-text": !innerColor
527
- })
528
- })]
529
- }), palette.map(colorItem => {
530
- const itemClasses = classNames("fwe-color-item", {
531
- "fwe-white-item": colorItem.toUpperCase() === "#FFFFFF"
532
- });
533
- return /*#__PURE__*/_jsx("div", {
534
- className: itemClasses,
535
- style: {
536
- background: colorItem
537
- },
538
- onClick: () => updateColorRgb(colorItem.toUpperCase()),
539
- children: innerColor === colorItem.toUpperCase() && /*#__PURE__*/_jsx(IconCheckSmall, {})
540
- }, colorItem);
541
- })]
542
- })]
543
- });
544
- }
545
- export default ColorPicker;
@@ -1,25 +0,0 @@
1
- import type { ClassNamePropsWithChildren } from "../../helper/types";
2
- import "./DatePicker.scss";
3
- export interface DatePickerOptions {
4
- maxDate?: Date;
5
- minDate?: Date;
6
- keepOpenOnDateChange?: boolean;
7
- position?: "auto" | "above" | "below" | "auto left" | "auto center" | "auto right" | "above left" | "above center" | "above right" | "below left" | "below center" | "below right";
8
- }
9
- export interface DatePickerProps extends ClassNamePropsWithChildren {
10
- disabled?: boolean;
11
- required?: boolean;
12
- hint?: string;
13
- error?: string;
14
- value?: Date;
15
- defaultValue?: Date;
16
- formatDate?: (date: Date) => string;
17
- options?: DatePickerOptions;
18
- onChange?: (date: Date) => void;
19
- id?: string;
20
- allowManualInput?: boolean;
21
- dateFormat?: string;
22
- openOnInputClick?: boolean;
23
- }
24
- declare function DatePicker({ children, className, disabled, required, error, hint, value, defaultValue, formatDate, options, onChange, id: idProps, allowManualInput, dateFormat, openOnInputClick, }: DatePickerProps): import("react/jsx-runtime").JSX.Element;
25
- export default DatePicker;