@festo-ui/react 4.0.3-pre-20221213.1 → 5.0.0-dev.102

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.
Files changed (228) hide show
  1. package/index.css +3 -3202
  2. package/index.d.ts +50 -48
  3. package/index.js +50 -4797
  4. package/lib/components/accordion/Accordion.d.ts +9 -9
  5. package/lib/components/accordion/Accordion.js +38 -0
  6. package/lib/components/accordion/AccordionContext.d.ts +11 -11
  7. package/lib/components/accordion/AccordionContext.js +3 -0
  8. package/lib/components/accordion/accordion-header/AccordionHeader.d.ts +4 -4
  9. package/lib/components/accordion/accordion-header/AccordionHeader.js +17 -0
  10. package/lib/components/accordion/accordion-item/AccordionItem.d.ts +9 -9
  11. package/lib/components/accordion/accordion-item/AccordionItem.js +64 -0
  12. package/lib/components/accordion/accordion-item/AccordionItemContext.d.ts +8 -8
  13. package/lib/components/accordion/accordion-item/AccordionItemContext.js +3 -0
  14. package/lib/components/accordion/accordion-item/accordion-item-body/AccordionItemBody.d.ts +4 -4
  15. package/lib/components/accordion/accordion-item/accordion-item-body/AccordionItemBody.js +71 -0
  16. package/lib/components/accordion/accordion-item/accordion-item-header/AccordionItemHeader.d.ts +4 -4
  17. package/lib/components/accordion/accordion-item/accordion-item-header/AccordionItemHeader.js +41 -0
  18. package/lib/components/breadcrumb/Breadcrumb.d.ts +14 -14
  19. package/lib/components/breadcrumb/Breadcrumb.js +45 -0
  20. package/lib/components/buttons/button/Button.d.ts +12 -12
  21. package/lib/components/buttons/button/Button.js +37 -0
  22. package/lib/components/card/Card.d.ts +4 -4
  23. package/lib/components/card/Card.js +13 -0
  24. package/lib/components/card/CardBody.d.ts +7 -7
  25. package/lib/components/card/CardBody.js +18 -0
  26. package/lib/components/card/CardHeader.d.ts +9 -9
  27. package/lib/components/card/CardHeader.js +23 -0
  28. package/lib/components/card/CardNotification.d.ts +9 -9
  29. package/lib/components/card/CardNotification.js +26 -0
  30. package/lib/components/chips/chip/Chip.d.ts +19 -19
  31. package/lib/components/chips/chip/Chip.js +46 -0
  32. package/lib/components/chips/chip/DeleteIcon.d.ts +2 -0
  33. package/lib/components/chips/chip/DeleteIcon.js +7 -0
  34. package/lib/components/chips/chip-container/ChipContainer.d.ts +8 -8
  35. package/lib/components/chips/chip-container/ChipContainer.js +17 -0
  36. package/lib/components/link-button/LinkButton.d.ts +10 -10
  37. package/lib/components/link-button/LinkButton.js +26 -0
  38. package/lib/components/loading-indicator/LoadingIndicator.d.ts +7 -7
  39. package/lib/components/loading-indicator/LoadingIndicator.js +40 -0
  40. package/lib/components/modals/AlertModal.d.ts +14 -14
  41. package/lib/components/modals/AlertModal.js +76 -0
  42. package/lib/components/modals/ConfirmModal.d.ts +13 -13
  43. package/lib/components/modals/ConfirmModal.js +56 -0
  44. package/lib/components/modals/Modal.d.ts +11 -11
  45. package/lib/components/modals/Modal.js +76 -0
  46. package/lib/components/modals/ModalFooter.d.ts +4 -4
  47. package/lib/components/modals/ModalFooter.js +18 -0
  48. package/lib/components/modals/Prompt.d.ts +16 -16
  49. package/lib/components/modals/Prompt.js +65 -0
  50. package/lib/components/pagination/Pagination.d.ts +17 -17
  51. package/lib/components/pagination/Pagination.js +107 -0
  52. package/lib/components/popovers/legend/Legend.d.ts +12 -12
  53. package/lib/components/popovers/legend/Legend.js +25 -0
  54. package/lib/components/popovers/popover/Popover.d.ts +18 -18
  55. package/lib/components/popovers/popover/Popover.js +109 -0
  56. package/lib/components/popovers/popover-menu/PopoverMenu.d.ts +15 -15
  57. package/lib/components/popovers/popover-menu/PopoverMenu.js +54 -0
  58. package/lib/components/popovers/tooltip/Tooltip.d.ts +10 -10
  59. package/lib/components/popovers/tooltip/Tooltip.js +64 -0
  60. package/lib/components/progress/Progress.d.ts +9 -9
  61. package/lib/components/progress/Progress.js +32 -0
  62. package/lib/components/search-input/ClearButton.d.ts +2 -0
  63. package/lib/components/search-input/ClearButton.js +10 -0
  64. package/lib/components/search-input/SearchInput.d.ts +15 -0
  65. package/lib/components/search-input/SearchInput.js +75 -0
  66. package/lib/components/search-input/SearchSuggestion.d.ts +17 -0
  67. package/lib/components/search-input/SearchSuggestion.js +32 -0
  68. package/lib/components/search-input/useSearchInput.d.ts +13 -0
  69. package/lib/components/search-input/useSearchInput.js +94 -0
  70. package/lib/components/snackbar/Snackbar.d.ts +23 -23
  71. package/lib/components/snackbar/Snackbar.js +87 -0
  72. package/lib/components/snackbar/SnackbarContext.d.ts +8 -8
  73. package/lib/components/snackbar/SnackbarContext.js +2 -0
  74. package/lib/components/snackbar/SnackbarProvider.d.ts +8 -8
  75. package/lib/components/snackbar/SnackbarProvider.js +58 -0
  76. package/lib/components/snackbar/useSnackbar.d.ts +3 -3
  77. package/lib/components/snackbar/useSnackbar.js +3 -0
  78. package/lib/components/stepper-horizontal/StepperHorizontal.d.ts +7 -7
  79. package/lib/components/stepper-horizontal/StepperHorizontal.js +62 -0
  80. package/lib/components/stepper-horizontal/step-horizontal/StepHorizontal.d.ts +7 -7
  81. package/lib/components/stepper-horizontal/step-horizontal/StepHorizontal.js +23 -0
  82. package/lib/components/stepper-vertical/StepperVertical.d.ts +7 -7
  83. package/lib/components/stepper-vertical/StepperVertical.js +37 -0
  84. package/lib/components/stepper-vertical/step-vertical/StepVertical.d.ts +12 -12
  85. package/lib/components/stepper-vertical/step-vertical/StepVertical.js +77 -0
  86. package/lib/components/tab/Tabs.d.ts +23 -23
  87. package/lib/components/tab/Tabs.js +229 -0
  88. package/lib/components/tab/interfaces.d.ts +5 -0
  89. package/lib/components/tab/interfaces.js +1 -0
  90. package/lib/components/tab/tab-pane/TabPane.d.ts +11 -13
  91. package/lib/components/tab/tab-pane/TabPane.js +23 -0
  92. package/lib/components/tab/useTabScroll.d.ts +24 -24
  93. package/lib/components/tab/useTabScroll.js +233 -0
  94. package/lib/components/table-header-cell/TableHeaderCell.d.ts +7 -7
  95. package/lib/components/table-header-cell/TableHeaderCell.js +21 -0
  96. package/lib/forms/checkbox/Checkbox.d.ts +16 -16
  97. package/lib/forms/checkbox/Checkbox.js +88 -0
  98. package/lib/forms/color-indicator/ColorIndicator.d.ts +12 -12
  99. package/lib/forms/color-indicator/ColorIndicator.js +122 -0
  100. package/lib/forms/color-picker/ColorHelper.d.ts +9 -9
  101. package/lib/forms/color-picker/ColorHelper.js +142 -0
  102. package/lib/forms/color-picker/ColorPicker.d.ts +15 -15
  103. package/lib/forms/color-picker/ColorPicker.js +539 -0
  104. package/lib/forms/date-picker/DatePicker.d.ts +22 -21
  105. package/lib/forms/date-picker/DatePicker.js +124 -0
  106. package/lib/forms/date-range-picker/DateRangePicker.d.ts +20 -20
  107. package/lib/forms/date-range-picker/DateRangePicker.js +135 -0
  108. package/lib/forms/radio/RadioButton.d.ts +15 -15
  109. package/lib/forms/radio/RadioButton.js +56 -0
  110. package/lib/forms/radio/RadioGroup.d.ts +13 -13
  111. package/lib/forms/radio/RadioGroup.js +35 -0
  112. package/lib/forms/radio/RadioGroupContext.d.ts +12 -12
  113. package/lib/forms/radio/RadioGroupContext.js +3 -0
  114. package/lib/forms/segment/Segment.d.ts +14 -14
  115. package/lib/forms/segment/Segment.js +77 -0
  116. package/lib/forms/segment/segment-control/SegmentControl.d.ts +15 -15
  117. package/lib/forms/segment/segment-control/SegmentControl.js +64 -0
  118. package/lib/forms/select/Select.d.ts +26 -26
  119. package/lib/forms/select/Select.js +281 -0
  120. package/lib/forms/select/select-option/SelectOption.d.ts +10 -10
  121. package/lib/forms/select/select-option/SelectOption.js +16 -0
  122. package/lib/forms/slider/Slider.d.ts +18 -17
  123. package/lib/forms/slider/Slider.js +92 -0
  124. package/lib/forms/switch/Switch.d.ts +13 -12
  125. package/lib/forms/switch/Switch.js +51 -0
  126. package/lib/forms/text-area/TextArea.d.ts +22 -21
  127. package/lib/forms/text-area/TextArea.js +108 -0
  128. package/lib/forms/text-editor/TextEditor.d.ts +29 -29
  129. package/lib/forms/text-editor/TextEditor.js +255 -0
  130. package/lib/forms/text-editor/TextEditorButton.d.ts +14 -14
  131. package/lib/forms/text-editor/TextEditorButton.js +82 -0
  132. package/lib/forms/text-input/TextInput.d.ts +21 -21
  133. package/lib/forms/text-input/TextInput.js +75 -0
  134. package/lib/forms/time-picker/TimePicker.d.ts +18 -18
  135. package/lib/forms/time-picker/TimePicker.js +161 -0
  136. package/lib/forms/time-picker/time-picker-dropdown/TimePickerDropdown.d.ts +12 -12
  137. package/lib/forms/time-picker/time-picker-dropdown/TimePickerDropdown.js +213 -0
  138. package/lib/helper/index.d.ts +2 -2
  139. package/lib/helper/index.js +7 -0
  140. package/lib/helper/setRef.d.ts +2 -2
  141. package/lib/helper/setRef.js +7 -0
  142. package/lib/helper/types.d.ts +7 -7
  143. package/lib/helper/types.js +1 -0
  144. package/lib/helper/useControlled.d.ts +6 -6
  145. package/lib/helper/useControlled.js +18 -0
  146. package/lib/helper/useForkRef.d.ts +2 -2
  147. package/lib/helper/useForkRef.js +20 -0
  148. package/lib/helper/useId.d.ts +1 -0
  149. package/lib/helper/useId.js +21 -0
  150. package/lib/helper/useOnClickOutside.d.ts +2 -2
  151. package/lib/helper/useOnClickOutside.js +18 -0
  152. package/node/index.js +370 -0
  153. package/node/lib/components/accordion/Accordion.js +46 -0
  154. package/node/lib/components/accordion/AccordionContext.js +10 -0
  155. package/node/lib/components/accordion/accordion-header/AccordionHeader.js +25 -0
  156. package/node/lib/components/accordion/accordion-item/AccordionItem.js +71 -0
  157. package/node/lib/components/accordion/accordion-item/AccordionItemContext.js +10 -0
  158. package/node/lib/components/accordion/accordion-item/accordion-item-body/AccordionItemBody.js +78 -0
  159. package/node/lib/components/accordion/accordion-item/accordion-item-header/AccordionItemHeader.js +49 -0
  160. package/node/lib/components/breadcrumb/Breadcrumb.js +52 -0
  161. package/node/lib/components/buttons/button/Button.js +44 -0
  162. package/node/lib/components/card/Card.js +21 -0
  163. package/node/lib/components/card/CardBody.js +25 -0
  164. package/node/lib/components/card/CardHeader.js +30 -0
  165. package/node/lib/components/card/CardNotification.js +33 -0
  166. package/node/lib/components/chips/chip/Chip.js +54 -0
  167. package/node/lib/components/chips/chip/DeleteIcon.js +13 -0
  168. package/node/lib/components/chips/chip-container/ChipContainer.js +25 -0
  169. package/node/lib/components/link-button/LinkButton.js +33 -0
  170. package/node/lib/components/loading-indicator/LoadingIndicator.js +48 -0
  171. package/node/lib/components/modals/AlertModal.js +82 -0
  172. package/node/lib/components/modals/ConfirmModal.js +62 -0
  173. package/node/lib/components/modals/Modal.js +84 -0
  174. package/node/lib/components/modals/ModalFooter.js +26 -0
  175. package/node/lib/components/modals/Prompt.js +72 -0
  176. package/node/lib/components/pagination/Pagination.js +116 -0
  177. package/node/lib/components/popovers/legend/Legend.js +32 -0
  178. package/node/lib/components/popovers/popover/Popover.js +117 -0
  179. package/node/lib/components/popovers/popover-menu/PopoverMenu.js +61 -0
  180. package/node/lib/components/popovers/tooltip/Tooltip.js +70 -0
  181. package/node/lib/components/progress/Progress.js +40 -0
  182. package/node/lib/components/search-input/ClearButton.js +16 -0
  183. package/node/lib/components/search-input/SearchInput.js +82 -0
  184. package/node/lib/components/search-input/SearchSuggestion.js +39 -0
  185. package/node/lib/components/search-input/useSearchInput.js +101 -0
  186. package/node/lib/components/snackbar/Snackbar.js +94 -0
  187. package/node/lib/components/snackbar/SnackbarContext.js +10 -0
  188. package/node/lib/components/snackbar/SnackbarProvider.js +65 -0
  189. package/node/lib/components/snackbar/useSnackbar.js +11 -0
  190. package/node/lib/components/stepper-horizontal/StepperHorizontal.js +70 -0
  191. package/node/lib/components/stepper-horizontal/step-horizontal/StepHorizontal.js +31 -0
  192. package/node/lib/components/stepper-vertical/StepperVertical.js +47 -0
  193. package/node/lib/components/stepper-vertical/step-vertical/StepVertical.js +84 -0
  194. package/node/lib/components/tab/Tabs.js +237 -0
  195. package/node/lib/components/tab/interfaces.js +5 -0
  196. package/node/lib/components/tab/tab-pane/TabPane.js +31 -0
  197. package/node/lib/components/tab/useTabScroll.js +236 -0
  198. package/node/lib/components/table-header-cell/TableHeaderCell.js +29 -0
  199. package/node/lib/forms/checkbox/Checkbox.js +97 -0
  200. package/node/lib/forms/color-indicator/ColorIndicator.js +130 -0
  201. package/node/lib/forms/color-picker/ColorHelper.js +149 -0
  202. package/node/lib/forms/color-picker/ColorPicker.js +549 -0
  203. package/node/lib/forms/date-picker/DatePicker.js +131 -0
  204. package/node/lib/forms/date-range-picker/DateRangePicker.js +142 -0
  205. package/node/lib/forms/radio/RadioButton.js +63 -0
  206. package/node/lib/forms/radio/RadioGroup.js +43 -0
  207. package/node/lib/forms/radio/RadioGroupContext.js +10 -0
  208. package/node/lib/forms/segment/Segment.js +84 -0
  209. package/node/lib/forms/segment/segment-control/SegmentControl.js +72 -0
  210. package/node/lib/forms/select/Select.js +289 -0
  211. package/node/lib/forms/select/select-option/SelectOption.js +26 -0
  212. package/node/lib/forms/slider/Slider.js +101 -0
  213. package/node/lib/forms/switch/Switch.js +58 -0
  214. package/node/lib/forms/text-area/TextArea.js +117 -0
  215. package/node/lib/forms/text-editor/TextEditor.js +261 -0
  216. package/node/lib/forms/text-editor/TextEditorButton.js +88 -0
  217. package/node/lib/forms/text-input/TextInput.js +84 -0
  218. package/node/lib/forms/time-picker/TimePicker.js +169 -0
  219. package/node/lib/forms/time-picker/time-picker-dropdown/TimePickerDropdown.js +222 -0
  220. package/node/lib/helper/index.js +15 -0
  221. package/node/lib/helper/setRef.js +13 -0
  222. package/node/lib/helper/types.js +5 -0
  223. package/node/lib/helper/useControlled.js +24 -0
  224. package/node/lib/helper/useForkRef.js +26 -0
  225. package/node/lib/helper/useId.js +27 -0
  226. package/node/lib/helper/useOnClickOutside.js +24 -0
  227. package/package.json +20 -10
  228. package/README.md +0 -17
@@ -0,0 +1,142 @@
1
+ export default class ColorHelper {
2
+ // based on: https://gist.github.com/mjackson/5311256
3
+ static rgbToHsv(rgb) {
4
+ if (!rgb) {
5
+ return undefined;
6
+ }
7
+ const r = this.limitToByte(rgb.r) / 255;
8
+ const g = this.limitToByte(rgb.g) / 255;
9
+ const b = this.limitToByte(rgb.b) / 255;
10
+ const max = Math.max(r, g, b);
11
+ const min = Math.min(r, g, b);
12
+ let h = max;
13
+ let s = max;
14
+ const v = max;
15
+ const d = max - min;
16
+ s = max === 0 ? 0 : d / max;
17
+ if (max === min) {
18
+ h = 0; // achromatic
19
+ } else {
20
+ switch (max) {
21
+ case r:
22
+ h = (g - b) / d + (g < b ? 6 : 0);
23
+ break;
24
+ case g:
25
+ h = (b - r) / d + 2;
26
+ break;
27
+ case b:
28
+ h = (r - g) / d + 4;
29
+ break;
30
+ default:
31
+ // no other option
32
+ }
33
+
34
+ h /= 6;
35
+ }
36
+ return {
37
+ h,
38
+ s,
39
+ v
40
+ };
41
+ }
42
+
43
+ // based on: https://gist.github.com/mjackson/5311256
44
+ static hsvToRgb(_hsv) {
45
+ const hsv = _hsv;
46
+ hsv.h = this.limitToOne(_hsv.h);
47
+ hsv.s = this.limitToOne(_hsv.s);
48
+ hsv.v = this.limitToOne(_hsv.v);
49
+ let r = 0;
50
+ let g = 0;
51
+ let b = 0;
52
+ const i = Math.floor(hsv.h * 6);
53
+ const f = hsv.h * 6 - i;
54
+ const p = hsv.v * (1 - hsv.s);
55
+ const q = hsv.v * (1 - f * hsv.s);
56
+ const t = hsv.v * (1 - (1 - f) * hsv.s);
57
+ switch (i % 6) {
58
+ case 0:
59
+ r = hsv.v;
60
+ g = t;
61
+ b = p;
62
+ break;
63
+ case 1:
64
+ r = q;
65
+ g = hsv.v;
66
+ b = p;
67
+ break;
68
+ case 2:
69
+ r = p;
70
+ g = hsv.v;
71
+ b = t;
72
+ break;
73
+ case 3:
74
+ r = p;
75
+ g = q;
76
+ b = hsv.v;
77
+ break;
78
+ case 4:
79
+ r = t;
80
+ g = p;
81
+ b = hsv.v;
82
+ break;
83
+ case 5:
84
+ r = hsv.v;
85
+ g = p;
86
+ b = q;
87
+ break;
88
+ default:
89
+ // no other option
90
+ }
91
+
92
+ return {
93
+ r: this.limitToByte(r * 255),
94
+ g: this.limitToByte(g * 255),
95
+ b: this.limitToByte(b * 255)
96
+ };
97
+ }
98
+ static limitToByte(num) {
99
+ if (num <= 0) {
100
+ return 0;
101
+ }
102
+ if (num >= 255) {
103
+ return 255;
104
+ }
105
+ return num;
106
+ }
107
+ static limitToOne(num) {
108
+ if (num <= 0) {
109
+ return 0;
110
+ }
111
+ if (num >= 1) {
112
+ return 1;
113
+ }
114
+ return num;
115
+ }
116
+ static numberToHex(rgb) {
117
+ let hex = Math.round(rgb).toString(16);
118
+ if (hex.length < 2) {
119
+ hex = `0${hex}`;
120
+ }
121
+ return hex.toUpperCase();
122
+ }
123
+ static rgbToHex(_rgb) {
124
+ const rgb = _rgb;
125
+ rgb.r = this.limitToByte(rgb.r);
126
+ rgb.g = this.limitToByte(rgb.g);
127
+ rgb.b = this.limitToByte(rgb.b);
128
+ const red = this.numberToHex(rgb.r);
129
+ const green = this.numberToHex(rgb.g);
130
+ const blue = this.numberToHex(rgb.b);
131
+ return `#${red}${green}${blue}`;
132
+ }
133
+ static hexToRgb(hexString) {
134
+ const numbersOnly = hexString.substring(1);
135
+ const aRgbHex = numbersOnly.match(/.{1,2}/g);
136
+ return aRgbHex ? {
137
+ r: parseInt(aRgbHex[0], 16),
138
+ g: parseInt(aRgbHex[1], 16),
139
+ b: parseInt(aRgbHex[2], 16)
140
+ } : undefined;
141
+ }
142
+ }
@@ -1,15 +1,15 @@
1
- /// <reference types="react" />
2
- import './ColorPicker.scss';
3
- import { ClassNameProps } from '../../helper/types';
4
- export declare const PREDEFINED_COLORS: string[];
5
- interface ColorPickerProps extends ClassNameProps {
6
- palette?: string[];
7
- useAlpha?: boolean;
8
- alpha?: number;
9
- paletteOnly?: boolean;
10
- color?: string;
11
- onChange?: (color?: string | null) => void;
12
- onAlphaChange?: (alpha?: number) => void;
13
- }
14
- declare function ColorPicker({ palette, useAlpha, alpha, paletteOnly, color, onChange, onAlphaChange, className }: ColorPickerProps): JSX.Element;
15
- export default ColorPicker;
1
+ /// <reference types="react" />
2
+ import './ColorPicker.scss';
3
+ import { ClassNameProps } from '../../helper/types';
4
+ export declare const PREDEFINED_COLORS: string[];
5
+ interface ColorPickerProps extends ClassNameProps {
6
+ palette?: string[];
7
+ useAlpha?: boolean;
8
+ alpha?: number;
9
+ paletteOnly?: boolean;
10
+ color?: string;
11
+ onChange?: (color?: string | null) => void;
12
+ onAlphaChange?: (alpha?: number) => void;
13
+ }
14
+ declare function ColorPicker({ palette, useAlpha, alpha, paletteOnly, color, onChange, onAlphaChange, className, }: ColorPickerProps): JSX.Element;
15
+ export default ColorPicker;
@@ -0,0 +1,539 @@
1
+ /* eslint-disable jsx-a11y/no-static-element-interactions */
2
+ /* eslint-disable jsx-a11y/click-events-have-key-events */
3
+ import React, { useCallback, useEffect, useState } from 'react';
4
+ import Draggable from 'react-draggable';
5
+ import classNames from 'classnames';
6
+ import ColorHelper from './ColorHelper';
7
+ import useId from '../../helper/useId';
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ import { jsxs as _jsxs } from "react/jsx-runtime";
10
+ import { Fragment as _Fragment } from "react/jsx-runtime";
11
+ export const PREDEFINED_COLORS = ['#0091dc', '#333333', '#ffffff', '#f2f3f5', '#e5e8eb', '#d8dce1', '#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
+ function limitAlpha() {
47
+ if (innerAlpha > 100) {
48
+ return 100;
49
+ }
50
+ if (innerAlpha < 0) {
51
+ return 0;
52
+ }
53
+ return innerAlpha;
54
+ }
55
+ const hueKnobOffset = hsv.h * baseSize - 14 - baseSize;
56
+ const saturationKnobOffset = hsv.s * baseSize;
57
+ const valueKnobOffset = (1 - hsv.v) * baseSize;
58
+ const alphaKnobOffset = (100 - limitAlpha()) / 100 * baseSize;
59
+ function getSaturationGradient() {
60
+ return `linear-gradient(to right, white, hsl(${hsv.h * 360}, 100%, 50%) )`;
61
+ }
62
+ function updateInputs(hexColor) {
63
+ setHexInputColor(hexColor);
64
+ const rgb = ColorHelper.hexToRgb(hexColor);
65
+ if (rgb) {
66
+ setRedInput(rgb.r);
67
+ setGreenInput(rgb.g);
68
+ setBlueInput(rgb.b);
69
+ }
70
+ }
71
+ useEffect(() => {
72
+ if (onChange) {
73
+ onChange(innerColor);
74
+ }
75
+ }, [onChange, innerColor]);
76
+ useEffect(() => {
77
+ if (onAlphaChange && innerAlpha) {
78
+ onAlphaChange(innerAlpha);
79
+ }
80
+ }, [onAlphaChange, innerAlpha]);
81
+ const updateColorHsv = useCallback((_hsv, _changeColor) => {
82
+ const rgb = ColorHelper.hsvToRgb(_hsv);
83
+ const hex = ColorHelper.rgbToHex(rgb);
84
+ if (_changeColor) {
85
+ setInnerColor(hex);
86
+ }
87
+ updateInputs(hex);
88
+ }, []);
89
+ useEffect(() => {
90
+ updateColorHsv(hsv, changeColor);
91
+ }, [updateColorHsv, hsv, changeColor]);
92
+ function updateGradient(x, y) {
93
+ setChangeColor(true);
94
+ setHsv(prevHsv => ({
95
+ ...prevHsv,
96
+ s: Math.floor(x) / baseSize,
97
+ v: (baseSize - y) / baseSize
98
+ }));
99
+ }
100
+ function onGradientDrag(e, data) {
101
+ e.preventDefault();
102
+ updateGradient(data.x, data.y);
103
+ }
104
+ function updateHue(y) {
105
+ const newHue = y / baseSize;
106
+ setChangeColor(true);
107
+ setHsv(prevHsv => ({
108
+ ...prevHsv,
109
+ h: newHue
110
+ }));
111
+ }
112
+ function onHueDrag(e, data) {
113
+ e.preventDefault();
114
+ updateHue(data.y + 14 + baseSize);
115
+ }
116
+ function updateAlpha(y) {
117
+ setInnerAlpha(100 - Math.round(y / baseSize * 100));
118
+ }
119
+ function onAlphaDrag(e, data) {
120
+ e.preventDefault();
121
+ updateAlpha(data.y);
122
+ }
123
+ const updateColorRgb = newColor => {
124
+ const currentColor = newColor || '#FFFFFF';
125
+ updateInputs(currentColor);
126
+ const rgb = ColorHelper.hexToRgb(currentColor);
127
+ setChangeColor(false);
128
+ if (rgb) {
129
+ const newHsv = ColorHelper.rgbToHsv(rgb);
130
+ if (newHsv) {
131
+ setHsv(newHsv);
132
+ }
133
+ }
134
+ setInnerColor(newColor);
135
+ };
136
+ const isHexColor = _color => /^#[0-9A-F]{6}$/i.test(_color);
137
+ function onHexInput(event) {
138
+ const newHexInputColor = event.target.value;
139
+ setHexInputColor(newHexInputColor.toUpperCase());
140
+ if (isHexColor(newHexInputColor)) {
141
+ updateColorRgb(newHexInputColor.toUpperCase());
142
+ }
143
+ }
144
+ function onHexBlur() {
145
+ if (!isHexColor(hexInputColor) && innerColor) {
146
+ setHexInputColor(innerColor);
147
+ updateColorRgb(innerColor);
148
+ }
149
+ }
150
+ function onRgbBlur(channel) {
151
+ let currentInput = '';
152
+ switch (channel) {
153
+ case 'r':
154
+ currentInput = redInput;
155
+ break;
156
+ case 'g':
157
+ currentInput = greenInput;
158
+ break;
159
+ case 'b':
160
+ currentInput = blueInput;
161
+ break;
162
+ default:
163
+ // no other value possible
164
+ }
165
+
166
+ if (typeof currentInput !== 'number' || typeof currentInput === 'number' && currentInput > 255 && currentInput < 0) {
167
+ const rgb = ColorHelper.hexToRgb(innerColor || '#FFFFFF');
168
+ if (rgb) {
169
+ const newHexColor = ColorHelper.rgbToHex(rgb);
170
+ updateInputs(newHexColor);
171
+ }
172
+ }
173
+ }
174
+ function onRgbInput(_value, channel) {
175
+ const numberValue = Number.parseInt(_value, 10);
176
+ switch (channel) {
177
+ case 'r':
178
+ setRedInput(_value);
179
+ break;
180
+ case 'g':
181
+ setGreenInput(_value);
182
+ break;
183
+ case 'b':
184
+ setBlueInput(_value);
185
+ break;
186
+ default:
187
+ // no other value possible
188
+ }
189
+
190
+ if (numberValue <= 255 && numberValue >= 0) {
191
+ const rgb = ColorHelper.hexToRgb(innerColor || '#FFFFFF');
192
+ if (rgb) {
193
+ rgb[channel] = numberValue;
194
+ const newHexColor = ColorHelper.rgbToHex(rgb);
195
+ setInnerColor(newHexColor);
196
+ updateColorRgb(newHexColor);
197
+ }
198
+ }
199
+ }
200
+ function onAlphaInput(_alpha) {
201
+ const numberValue = Number.parseInt(_alpha, 10);
202
+ setInnerAlpha(numberValue);
203
+ }
204
+ function onAlphaBlur() {
205
+ setInnerAlpha(limitAlpha());
206
+ }
207
+ const onChangeType = type => {
208
+ setInputType(type);
209
+ setSelectOpen(false);
210
+ };
211
+ function onRemoveColor() {
212
+ if (useAlpha) {
213
+ setInnerAlpha(0);
214
+ } else {
215
+ updateColorRgb();
216
+ }
217
+ }
218
+ return /*#__PURE__*/_jsxs("div", {
219
+ className: classNames('fwe-color-picker', {
220
+ 'fwe-alpha-active': useAlpha
221
+ }, className),
222
+ children: [!paletteOnly && /*#__PURE__*/_jsxs("div", {
223
+ className: "fwe-d-flex",
224
+ children: [/*#__PURE__*/_jsxs("div", {
225
+ className: "fwe-gradient-picker",
226
+ children: [/*#__PURE__*/_jsx("div", {
227
+ className: "fwe-saturation-gradient",
228
+ style: {
229
+ backgroundImage: getSaturationGradient()
230
+ }
231
+ }), /*#__PURE__*/_jsx("div", {
232
+ "aria-label": "brightness-gradient",
233
+ onClick: _ref2 => {
234
+ let {
235
+ nativeEvent: {
236
+ offsetX,
237
+ offsetY
238
+ }
239
+ } = _ref2;
240
+ return updateGradient(offsetX, offsetY);
241
+ },
242
+ className: "fwe-brightness-gradient"
243
+ }), /*#__PURE__*/_jsx(Draggable, {
244
+ position: {
245
+ x: saturationKnobOffset,
246
+ y: valueKnobOffset
247
+ },
248
+ onDrag: (e, data) => onGradientDrag(e, data),
249
+ bounds: "parent",
250
+ children: /*#__PURE__*/_jsx("div", {
251
+ className: "fwe-knob"
252
+ })
253
+ })]
254
+ }), /*#__PURE__*/_jsxs("div", {
255
+ className: "fwe-hue-picker",
256
+ children: [/*#__PURE__*/_jsx("div", {
257
+ className: "fwe-picker-background",
258
+ onClick: _ref3 => {
259
+ let {
260
+ nativeEvent: {
261
+ offsetY
262
+ }
263
+ } = _ref3;
264
+ return updateHue(offsetY);
265
+ }
266
+ }), /*#__PURE__*/_jsx(Draggable, {
267
+ position: {
268
+ x: 3,
269
+ y: hueKnobOffset
270
+ },
271
+ onDrag: (e, data) => onHueDrag(e, data),
272
+ bounds: "parent",
273
+ children: /*#__PURE__*/_jsx("div", {
274
+ className: "fwe-knob",
275
+ style: {
276
+ background: `hsl(${hsv.h * 360}, 100%, 50%)`
277
+ }
278
+ })
279
+ })]
280
+ }), useAlpha && /*#__PURE__*/_jsxs("div", {
281
+ className: "fwe-alpha-picker",
282
+ children: [/*#__PURE__*/_jsxs("svg", {
283
+ className: "fwe-no-color-pattern",
284
+ version: "1.1",
285
+ xmlns: "http://www.w3.org/2000/svg",
286
+ xmlnsXlink: "http://www.w3.org/1999/xlink",
287
+ id: "canvas1",
288
+ width: "8",
289
+ height: "184",
290
+ children: [/*#__PURE__*/_jsx("defs", {
291
+ children: /*#__PURE__*/_jsxs("pattern", {
292
+ id: "bwsquare2px",
293
+ width: "4",
294
+ height: "4",
295
+ patternUnits: "userSpaceOnUse",
296
+ children: [/*#__PURE__*/_jsx("rect", {
297
+ x: "0",
298
+ y: "0",
299
+ width: "2",
300
+ height: "2",
301
+ stroke: "none",
302
+ fill: "#ffffff"
303
+ }), /*#__PURE__*/_jsx("rect", {
304
+ x: "2",
305
+ y: "0",
306
+ width: "2",
307
+ height: "2",
308
+ stroke: "none",
309
+ fill: "#e5e8eb"
310
+ }), /*#__PURE__*/_jsx("rect", {
311
+ x: "0",
312
+ y: "2",
313
+ width: "2",
314
+ height: "2",
315
+ stroke: "none",
316
+ fill: "#e5e8eb"
317
+ }), /*#__PURE__*/_jsx("rect", {
318
+ x: "2",
319
+ y: "2",
320
+ width: "2",
321
+ height: "2",
322
+ stroke: "none",
323
+ fill: "#ffffff"
324
+ })]
325
+ })
326
+ }), /*#__PURE__*/_jsx("rect", {
327
+ x: "0",
328
+ y: "0",
329
+ rx: "4",
330
+ ry: "4",
331
+ width: "8",
332
+ height: "184",
333
+ fill: "url(#bwsquare2px)",
334
+ strokeWidth: "0"
335
+ })]
336
+ }), /*#__PURE__*/_jsx("div", {
337
+ onClick: _ref4 => {
338
+ let {
339
+ nativeEvent: {
340
+ offsetY
341
+ }
342
+ } = _ref4;
343
+ return updateAlpha(offsetY);
344
+ },
345
+ className: "fwe-picker-background",
346
+ style: {
347
+ backgroundImage: `linear-gradient( ${innerColor}, transparent)`
348
+ }
349
+ }), /*#__PURE__*/_jsx(Draggable, {
350
+ position: {
351
+ x: 3,
352
+ y: alphaKnobOffset
353
+ },
354
+ onDrag: (e, data) => onAlphaDrag(e, data),
355
+ bounds: "parent",
356
+ children: /*#__PURE__*/_jsx("div", {
357
+ className: "fwe-knob"
358
+ })
359
+ })]
360
+ })]
361
+ }), !paletteOnly && /*#__PURE__*/_jsxs("div", {
362
+ className: "fwe-mt-s",
363
+ children: [/*#__PURE__*/_jsxs("div", {
364
+ className: "fwe-type-select",
365
+ children: [/*#__PURE__*/_jsxs("div", {
366
+ className: "fwe-type-indicator",
367
+ onClick: () => setSelectOpen(prevOpen => !prevOpen),
368
+ children: [/*#__PURE__*/_jsx("span", {
369
+ className: "fwe-input-type",
370
+ children: inputType
371
+ }), /*#__PURE__*/_jsx("i", {
372
+ className: "fwe-icon fwe-icon-arrows-collapse"
373
+ })]
374
+ }), selectOpen && /*#__PURE__*/_jsxs("div", {
375
+ className: "fwe-popover",
376
+ children: [/*#__PURE__*/_jsxs("div", {
377
+ className: classNames('fwe-type-item', {
378
+ 'fwe-selected': inputType === 'HEX'
379
+ }),
380
+ onClick: () => onChangeType('HEX'),
381
+ children: [/*#__PURE__*/_jsx("i", {
382
+ className: "fwe-icon fwe-icon-menu-check"
383
+ }), " HEX"]
384
+ }), /*#__PURE__*/_jsxs("div", {
385
+ className: classNames('fwe-type-item', {
386
+ 'fwe-selected': inputType === 'RGB'
387
+ }),
388
+ onClick: () => onChangeType('RGB'),
389
+ children: [/*#__PURE__*/_jsx("i", {
390
+ className: "fwe-icon fwe-icon-menu-check"
391
+ }), " RGB"]
392
+ })]
393
+ })]
394
+ }), /*#__PURE__*/_jsxs("div", {
395
+ className: "fwe-d-flex",
396
+ children: [inputType === 'HEX' && /*#__PURE__*/_jsx("label", {
397
+ className: "fwe-input-text fwe-hex-input",
398
+ htmlFor: hexId,
399
+ children: /*#__PURE__*/_jsx("input", {
400
+ type: "text",
401
+ value: hexInputColor,
402
+ onBlur: onHexBlur,
403
+ onChange: onHexInput,
404
+ id: hexId
405
+ })
406
+ }), inputType === 'RGB' && /*#__PURE__*/_jsxs(_Fragment, {
407
+ children: [/*#__PURE__*/_jsx("label", {
408
+ className: "fwe-input-text fwe-red-input",
409
+ htmlFor: redId,
410
+ children: /*#__PURE__*/_jsx("input", {
411
+ type: "text",
412
+ value: redInput,
413
+ onBlur: () => onRgbBlur('r'),
414
+ onChange: e => onRgbInput(e.target.value, 'r'),
415
+ id: redId
416
+ })
417
+ }), /*#__PURE__*/_jsx("label", {
418
+ className: "fwe-input-text fwe-green-input",
419
+ htmlFor: greenId,
420
+ children: /*#__PURE__*/_jsx("input", {
421
+ type: "text",
422
+ value: greenInput,
423
+ onBlur: () => onRgbBlur('g'),
424
+ onChange: e => onRgbInput(e.target.value, 'g'),
425
+ id: greenId
426
+ })
427
+ }), /*#__PURE__*/_jsx("label", {
428
+ className: "fwe-input-text fwe-blue-input",
429
+ htmlFor: blueId,
430
+ children: /*#__PURE__*/_jsx("input", {
431
+ type: "text",
432
+ value: blueInput,
433
+ onBlur: () => onRgbBlur('b'),
434
+ onChange: e => onRgbInput(e.target.value, 'b'),
435
+ id: blueId
436
+ })
437
+ })]
438
+ }), useAlpha && /*#__PURE__*/_jsx("label", {
439
+ className: "fwe-input-text fwe-alpha-input fwe-ml-auto",
440
+ htmlFor: alphaId,
441
+ children: /*#__PURE__*/_jsxs("span", {
442
+ children: [/*#__PURE__*/_jsx("input", {
443
+ type: "number",
444
+ min: "0",
445
+ max: "100",
446
+ value: innerAlpha,
447
+ onBlur: () => onAlphaBlur(),
448
+ onChange: e => onAlphaInput(e.target.value),
449
+ id: alphaId
450
+ }), /*#__PURE__*/_jsx("span", {
451
+ className: "fwe-percent-char",
452
+ children: "%"
453
+ })]
454
+ })
455
+ })]
456
+ })]
457
+ }), /*#__PURE__*/_jsxs("div", {
458
+ className: "fwe-mt-xs fwe-color-grid",
459
+ children: [/*#__PURE__*/_jsxs("div", {
460
+ className: "fwe-remove-color-button",
461
+ onClick: onRemoveColor,
462
+ children: [/*#__PURE__*/_jsxs("svg", {
463
+ className: "fwe-no-color-pattern",
464
+ version: "1.1",
465
+ xmlns: "http://www.w3.org/2000/svg",
466
+ xmlnsXlink: "http://www.w3.org/1999/xlink",
467
+ id: "canvas1",
468
+ width: "18",
469
+ height: "18",
470
+ children: [/*#__PURE__*/_jsx("defs", {
471
+ children: /*#__PURE__*/_jsxs("pattern", {
472
+ id: "bwsquare2px",
473
+ width: "4",
474
+ height: "4",
475
+ patternUnits: "userSpaceOnUse",
476
+ children: [/*#__PURE__*/_jsx("rect", {
477
+ x: "0",
478
+ y: "0",
479
+ width: "2",
480
+ height: "2",
481
+ stroke: "none",
482
+ fill: "#ffffff"
483
+ }), /*#__PURE__*/_jsx("rect", {
484
+ x: "2",
485
+ y: "0",
486
+ width: "2",
487
+ height: "2",
488
+ stroke: "none",
489
+ fill: "#e5e8eb"
490
+ }), /*#__PURE__*/_jsx("rect", {
491
+ x: "0",
492
+ y: "2",
493
+ width: "2",
494
+ height: "2",
495
+ stroke: "none",
496
+ fill: "#e5e8eb"
497
+ }), /*#__PURE__*/_jsx("rect", {
498
+ x: "2",
499
+ y: "2",
500
+ width: "2",
501
+ height: "2",
502
+ stroke: "none",
503
+ fill: "#ffffff"
504
+ })]
505
+ })
506
+ }), /*#__PURE__*/_jsx("rect", {
507
+ x: "0",
508
+ y: "0",
509
+ rx: "0",
510
+ ry: "0",
511
+ width: "18",
512
+ height: "18",
513
+ fill: "url(#bwsquare2px)",
514
+ strokeWidth: "0"
515
+ })]
516
+ }), /*#__PURE__*/_jsx("i", {
517
+ className: classNames('fwe-icon fwe-icon-menu-check', {
518
+ 'fwe-color-text': !innerColor
519
+ })
520
+ })]
521
+ }), palette.map(colorItem => {
522
+ const itemClasses = classNames('fwe-color-item', {
523
+ 'fwe-white-item': colorItem.toUpperCase() === '#FFFFFF'
524
+ });
525
+ return /*#__PURE__*/_jsx("div", {
526
+ className: itemClasses,
527
+ style: {
528
+ background: colorItem
529
+ },
530
+ onClick: () => updateColorRgb(colorItem.toUpperCase()),
531
+ children: innerColor === colorItem.toUpperCase() && /*#__PURE__*/_jsx("i", {
532
+ className: "fwe-icon fwe-icon-menu-check"
533
+ })
534
+ }, colorItem);
535
+ })]
536
+ })]
537
+ });
538
+ }
539
+ export default ColorPicker;