@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.
- package/index.css +3 -3202
- package/index.d.ts +50 -48
- package/index.js +50 -4797
- package/lib/components/accordion/Accordion.d.ts +9 -9
- package/lib/components/accordion/Accordion.js +38 -0
- package/lib/components/accordion/AccordionContext.d.ts +11 -11
- package/lib/components/accordion/AccordionContext.js +3 -0
- package/lib/components/accordion/accordion-header/AccordionHeader.d.ts +4 -4
- package/lib/components/accordion/accordion-header/AccordionHeader.js +17 -0
- package/lib/components/accordion/accordion-item/AccordionItem.d.ts +9 -9
- package/lib/components/accordion/accordion-item/AccordionItem.js +64 -0
- package/lib/components/accordion/accordion-item/AccordionItemContext.d.ts +8 -8
- package/lib/components/accordion/accordion-item/AccordionItemContext.js +3 -0
- package/lib/components/accordion/accordion-item/accordion-item-body/AccordionItemBody.d.ts +4 -4
- package/lib/components/accordion/accordion-item/accordion-item-body/AccordionItemBody.js +71 -0
- package/lib/components/accordion/accordion-item/accordion-item-header/AccordionItemHeader.d.ts +4 -4
- package/lib/components/accordion/accordion-item/accordion-item-header/AccordionItemHeader.js +41 -0
- package/lib/components/breadcrumb/Breadcrumb.d.ts +14 -14
- package/lib/components/breadcrumb/Breadcrumb.js +45 -0
- package/lib/components/buttons/button/Button.d.ts +12 -12
- package/lib/components/buttons/button/Button.js +37 -0
- package/lib/components/card/Card.d.ts +4 -4
- package/lib/components/card/Card.js +13 -0
- package/lib/components/card/CardBody.d.ts +7 -7
- package/lib/components/card/CardBody.js +18 -0
- package/lib/components/card/CardHeader.d.ts +9 -9
- package/lib/components/card/CardHeader.js +23 -0
- package/lib/components/card/CardNotification.d.ts +9 -9
- package/lib/components/card/CardNotification.js +26 -0
- package/lib/components/chips/chip/Chip.d.ts +19 -19
- package/lib/components/chips/chip/Chip.js +46 -0
- package/lib/components/chips/chip/DeleteIcon.d.ts +2 -0
- package/lib/components/chips/chip/DeleteIcon.js +7 -0
- package/lib/components/chips/chip-container/ChipContainer.d.ts +8 -8
- package/lib/components/chips/chip-container/ChipContainer.js +17 -0
- package/lib/components/link-button/LinkButton.d.ts +10 -10
- package/lib/components/link-button/LinkButton.js +26 -0
- package/lib/components/loading-indicator/LoadingIndicator.d.ts +7 -7
- package/lib/components/loading-indicator/LoadingIndicator.js +40 -0
- package/lib/components/modals/AlertModal.d.ts +14 -14
- package/lib/components/modals/AlertModal.js +76 -0
- package/lib/components/modals/ConfirmModal.d.ts +13 -13
- package/lib/components/modals/ConfirmModal.js +56 -0
- package/lib/components/modals/Modal.d.ts +11 -11
- package/lib/components/modals/Modal.js +76 -0
- package/lib/components/modals/ModalFooter.d.ts +4 -4
- package/lib/components/modals/ModalFooter.js +18 -0
- package/lib/components/modals/Prompt.d.ts +16 -16
- package/lib/components/modals/Prompt.js +65 -0
- package/lib/components/pagination/Pagination.d.ts +17 -17
- package/lib/components/pagination/Pagination.js +107 -0
- package/lib/components/popovers/legend/Legend.d.ts +12 -12
- package/lib/components/popovers/legend/Legend.js +25 -0
- package/lib/components/popovers/popover/Popover.d.ts +18 -18
- package/lib/components/popovers/popover/Popover.js +109 -0
- package/lib/components/popovers/popover-menu/PopoverMenu.d.ts +15 -15
- package/lib/components/popovers/popover-menu/PopoverMenu.js +54 -0
- package/lib/components/popovers/tooltip/Tooltip.d.ts +10 -10
- package/lib/components/popovers/tooltip/Tooltip.js +64 -0
- package/lib/components/progress/Progress.d.ts +9 -9
- package/lib/components/progress/Progress.js +32 -0
- package/lib/components/search-input/ClearButton.d.ts +2 -0
- package/lib/components/search-input/ClearButton.js +10 -0
- package/lib/components/search-input/SearchInput.d.ts +15 -0
- package/lib/components/search-input/SearchInput.js +75 -0
- package/lib/components/search-input/SearchSuggestion.d.ts +17 -0
- package/lib/components/search-input/SearchSuggestion.js +32 -0
- package/lib/components/search-input/useSearchInput.d.ts +13 -0
- package/lib/components/search-input/useSearchInput.js +94 -0
- package/lib/components/snackbar/Snackbar.d.ts +23 -23
- package/lib/components/snackbar/Snackbar.js +87 -0
- package/lib/components/snackbar/SnackbarContext.d.ts +8 -8
- package/lib/components/snackbar/SnackbarContext.js +2 -0
- package/lib/components/snackbar/SnackbarProvider.d.ts +8 -8
- package/lib/components/snackbar/SnackbarProvider.js +58 -0
- package/lib/components/snackbar/useSnackbar.d.ts +3 -3
- package/lib/components/snackbar/useSnackbar.js +3 -0
- package/lib/components/stepper-horizontal/StepperHorizontal.d.ts +7 -7
- package/lib/components/stepper-horizontal/StepperHorizontal.js +62 -0
- package/lib/components/stepper-horizontal/step-horizontal/StepHorizontal.d.ts +7 -7
- package/lib/components/stepper-horizontal/step-horizontal/StepHorizontal.js +23 -0
- package/lib/components/stepper-vertical/StepperVertical.d.ts +7 -7
- package/lib/components/stepper-vertical/StepperVertical.js +37 -0
- package/lib/components/stepper-vertical/step-vertical/StepVertical.d.ts +12 -12
- package/lib/components/stepper-vertical/step-vertical/StepVertical.js +77 -0
- package/lib/components/tab/Tabs.d.ts +23 -23
- package/lib/components/tab/Tabs.js +229 -0
- package/lib/components/tab/interfaces.d.ts +5 -0
- package/lib/components/tab/interfaces.js +1 -0
- package/lib/components/tab/tab-pane/TabPane.d.ts +11 -13
- package/lib/components/tab/tab-pane/TabPane.js +23 -0
- package/lib/components/tab/useTabScroll.d.ts +24 -24
- package/lib/components/tab/useTabScroll.js +233 -0
- package/lib/components/table-header-cell/TableHeaderCell.d.ts +7 -7
- package/lib/components/table-header-cell/TableHeaderCell.js +21 -0
- package/lib/forms/checkbox/Checkbox.d.ts +16 -16
- package/lib/forms/checkbox/Checkbox.js +88 -0
- package/lib/forms/color-indicator/ColorIndicator.d.ts +12 -12
- package/lib/forms/color-indicator/ColorIndicator.js +122 -0
- package/lib/forms/color-picker/ColorHelper.d.ts +9 -9
- package/lib/forms/color-picker/ColorHelper.js +142 -0
- package/lib/forms/color-picker/ColorPicker.d.ts +15 -15
- package/lib/forms/color-picker/ColorPicker.js +539 -0
- package/lib/forms/date-picker/DatePicker.d.ts +22 -21
- package/lib/forms/date-picker/DatePicker.js +124 -0
- package/lib/forms/date-range-picker/DateRangePicker.d.ts +20 -20
- package/lib/forms/date-range-picker/DateRangePicker.js +135 -0
- package/lib/forms/radio/RadioButton.d.ts +15 -15
- package/lib/forms/radio/RadioButton.js +56 -0
- package/lib/forms/radio/RadioGroup.d.ts +13 -13
- package/lib/forms/radio/RadioGroup.js +35 -0
- package/lib/forms/radio/RadioGroupContext.d.ts +12 -12
- package/lib/forms/radio/RadioGroupContext.js +3 -0
- package/lib/forms/segment/Segment.d.ts +14 -14
- package/lib/forms/segment/Segment.js +77 -0
- package/lib/forms/segment/segment-control/SegmentControl.d.ts +15 -15
- package/lib/forms/segment/segment-control/SegmentControl.js +64 -0
- package/lib/forms/select/Select.d.ts +26 -26
- package/lib/forms/select/Select.js +281 -0
- package/lib/forms/select/select-option/SelectOption.d.ts +10 -10
- package/lib/forms/select/select-option/SelectOption.js +16 -0
- package/lib/forms/slider/Slider.d.ts +18 -17
- package/lib/forms/slider/Slider.js +92 -0
- package/lib/forms/switch/Switch.d.ts +13 -12
- package/lib/forms/switch/Switch.js +51 -0
- package/lib/forms/text-area/TextArea.d.ts +22 -21
- package/lib/forms/text-area/TextArea.js +108 -0
- package/lib/forms/text-editor/TextEditor.d.ts +29 -29
- package/lib/forms/text-editor/TextEditor.js +255 -0
- package/lib/forms/text-editor/TextEditorButton.d.ts +14 -14
- package/lib/forms/text-editor/TextEditorButton.js +82 -0
- package/lib/forms/text-input/TextInput.d.ts +21 -21
- package/lib/forms/text-input/TextInput.js +75 -0
- package/lib/forms/time-picker/TimePicker.d.ts +18 -18
- package/lib/forms/time-picker/TimePicker.js +161 -0
- package/lib/forms/time-picker/time-picker-dropdown/TimePickerDropdown.d.ts +12 -12
- package/lib/forms/time-picker/time-picker-dropdown/TimePickerDropdown.js +213 -0
- package/lib/helper/index.d.ts +2 -2
- package/lib/helper/index.js +7 -0
- package/lib/helper/setRef.d.ts +2 -2
- package/lib/helper/setRef.js +7 -0
- package/lib/helper/types.d.ts +7 -7
- package/lib/helper/types.js +1 -0
- package/lib/helper/useControlled.d.ts +6 -6
- package/lib/helper/useControlled.js +18 -0
- package/lib/helper/useForkRef.d.ts +2 -2
- package/lib/helper/useForkRef.js +20 -0
- package/lib/helper/useId.d.ts +1 -0
- package/lib/helper/useId.js +21 -0
- package/lib/helper/useOnClickOutside.d.ts +2 -2
- package/lib/helper/useOnClickOutside.js +18 -0
- package/node/index.js +370 -0
- package/node/lib/components/accordion/Accordion.js +46 -0
- package/node/lib/components/accordion/AccordionContext.js +10 -0
- package/node/lib/components/accordion/accordion-header/AccordionHeader.js +25 -0
- package/node/lib/components/accordion/accordion-item/AccordionItem.js +71 -0
- package/node/lib/components/accordion/accordion-item/AccordionItemContext.js +10 -0
- package/node/lib/components/accordion/accordion-item/accordion-item-body/AccordionItemBody.js +78 -0
- package/node/lib/components/accordion/accordion-item/accordion-item-header/AccordionItemHeader.js +49 -0
- package/node/lib/components/breadcrumb/Breadcrumb.js +52 -0
- package/node/lib/components/buttons/button/Button.js +44 -0
- package/node/lib/components/card/Card.js +21 -0
- package/node/lib/components/card/CardBody.js +25 -0
- package/node/lib/components/card/CardHeader.js +30 -0
- package/node/lib/components/card/CardNotification.js +33 -0
- package/node/lib/components/chips/chip/Chip.js +54 -0
- package/node/lib/components/chips/chip/DeleteIcon.js +13 -0
- package/node/lib/components/chips/chip-container/ChipContainer.js +25 -0
- package/node/lib/components/link-button/LinkButton.js +33 -0
- package/node/lib/components/loading-indicator/LoadingIndicator.js +48 -0
- package/node/lib/components/modals/AlertModal.js +82 -0
- package/node/lib/components/modals/ConfirmModal.js +62 -0
- package/node/lib/components/modals/Modal.js +84 -0
- package/node/lib/components/modals/ModalFooter.js +26 -0
- package/node/lib/components/modals/Prompt.js +72 -0
- package/node/lib/components/pagination/Pagination.js +116 -0
- package/node/lib/components/popovers/legend/Legend.js +32 -0
- package/node/lib/components/popovers/popover/Popover.js +117 -0
- package/node/lib/components/popovers/popover-menu/PopoverMenu.js +61 -0
- package/node/lib/components/popovers/tooltip/Tooltip.js +70 -0
- package/node/lib/components/progress/Progress.js +40 -0
- package/node/lib/components/search-input/ClearButton.js +16 -0
- package/node/lib/components/search-input/SearchInput.js +82 -0
- package/node/lib/components/search-input/SearchSuggestion.js +39 -0
- package/node/lib/components/search-input/useSearchInput.js +101 -0
- package/node/lib/components/snackbar/Snackbar.js +94 -0
- package/node/lib/components/snackbar/SnackbarContext.js +10 -0
- package/node/lib/components/snackbar/SnackbarProvider.js +65 -0
- package/node/lib/components/snackbar/useSnackbar.js +11 -0
- package/node/lib/components/stepper-horizontal/StepperHorizontal.js +70 -0
- package/node/lib/components/stepper-horizontal/step-horizontal/StepHorizontal.js +31 -0
- package/node/lib/components/stepper-vertical/StepperVertical.js +47 -0
- package/node/lib/components/stepper-vertical/step-vertical/StepVertical.js +84 -0
- package/node/lib/components/tab/Tabs.js +237 -0
- package/node/lib/components/tab/interfaces.js +5 -0
- package/node/lib/components/tab/tab-pane/TabPane.js +31 -0
- package/node/lib/components/tab/useTabScroll.js +236 -0
- package/node/lib/components/table-header-cell/TableHeaderCell.js +29 -0
- package/node/lib/forms/checkbox/Checkbox.js +97 -0
- package/node/lib/forms/color-indicator/ColorIndicator.js +130 -0
- package/node/lib/forms/color-picker/ColorHelper.js +149 -0
- package/node/lib/forms/color-picker/ColorPicker.js +549 -0
- package/node/lib/forms/date-picker/DatePicker.js +131 -0
- package/node/lib/forms/date-range-picker/DateRangePicker.js +142 -0
- package/node/lib/forms/radio/RadioButton.js +63 -0
- package/node/lib/forms/radio/RadioGroup.js +43 -0
- package/node/lib/forms/radio/RadioGroupContext.js +10 -0
- package/node/lib/forms/segment/Segment.js +84 -0
- package/node/lib/forms/segment/segment-control/SegmentControl.js +72 -0
- package/node/lib/forms/select/Select.js +289 -0
- package/node/lib/forms/select/select-option/SelectOption.js +26 -0
- package/node/lib/forms/slider/Slider.js +101 -0
- package/node/lib/forms/switch/Switch.js +58 -0
- package/node/lib/forms/text-area/TextArea.js +117 -0
- package/node/lib/forms/text-editor/TextEditor.js +261 -0
- package/node/lib/forms/text-editor/TextEditorButton.js +88 -0
- package/node/lib/forms/text-input/TextInput.js +84 -0
- package/node/lib/forms/time-picker/TimePicker.js +169 -0
- package/node/lib/forms/time-picker/time-picker-dropdown/TimePickerDropdown.js +222 -0
- package/node/lib/helper/index.js +15 -0
- package/node/lib/helper/setRef.js +13 -0
- package/node/lib/helper/types.js +5 -0
- package/node/lib/helper/useControlled.js +24 -0
- package/node/lib/helper/useForkRef.js +26 -0
- package/node/lib/helper/useId.js +27 -0
- package/node/lib/helper/useOnClickOutside.js +24 -0
- package/package.json +20 -10
- package/README.md +0 -17
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
9
|
+
var _Popover = _interopRequireDefault(require("../../components/popovers/popover/Popover"));
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
|
|
14
|
+
function ColorIndicator(_ref) {
|
|
15
|
+
let {
|
|
16
|
+
text,
|
|
17
|
+
label,
|
|
18
|
+
color,
|
|
19
|
+
className,
|
|
20
|
+
showPopOver = false,
|
|
21
|
+
children,
|
|
22
|
+
disabled
|
|
23
|
+
} = _ref;
|
|
24
|
+
const classes = (0, _classnames.default)('fwe-color-indicator', className, disabled);
|
|
25
|
+
const [isEditorOpen, setEditorOpen] = (0, _react.useState)(false);
|
|
26
|
+
function getBorderColor() {
|
|
27
|
+
if (!color || color.toUpperCase() === '#FFFFFF' || color.toUpperCase() === '#F2F3F5') {
|
|
28
|
+
return '#b6bec6'; // = $control-border
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return color;
|
|
32
|
+
}
|
|
33
|
+
const colorBox = /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
34
|
+
className: "fwe-color-box",
|
|
35
|
+
style: {
|
|
36
|
+
background: color,
|
|
37
|
+
borderColor: getBorderColor()
|
|
38
|
+
},
|
|
39
|
+
children: !color && /*#__PURE__*/(0, _jsxRuntime.jsxs)("svg", {
|
|
40
|
+
className: "fwe-no-color-pattern",
|
|
41
|
+
version: "1.1",
|
|
42
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
43
|
+
xmlnsXlink: "http://www.w3.org/1999/xlink",
|
|
44
|
+
id: "canvas1",
|
|
45
|
+
width: "18",
|
|
46
|
+
height: "18",
|
|
47
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("defs", {
|
|
48
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("pattern", {
|
|
49
|
+
id: "bwsquare2px",
|
|
50
|
+
width: "4",
|
|
51
|
+
height: "4",
|
|
52
|
+
patternUnits: "userSpaceOnUse",
|
|
53
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("rect", {
|
|
54
|
+
x: "0",
|
|
55
|
+
y: "0",
|
|
56
|
+
width: "2",
|
|
57
|
+
height: "2",
|
|
58
|
+
stroke: "none",
|
|
59
|
+
fill: "#ffffff"
|
|
60
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("rect", {
|
|
61
|
+
x: "2",
|
|
62
|
+
y: "0",
|
|
63
|
+
width: "2",
|
|
64
|
+
height: "2",
|
|
65
|
+
stroke: "none",
|
|
66
|
+
fill: "#e5e8eb"
|
|
67
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("rect", {
|
|
68
|
+
x: "0",
|
|
69
|
+
y: "2",
|
|
70
|
+
width: "2",
|
|
71
|
+
height: "2",
|
|
72
|
+
stroke: "none",
|
|
73
|
+
fill: "#e5e8eb"
|
|
74
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("rect", {
|
|
75
|
+
x: "2",
|
|
76
|
+
y: "2",
|
|
77
|
+
width: "2",
|
|
78
|
+
height: "2",
|
|
79
|
+
stroke: "none",
|
|
80
|
+
fill: "#ffffff"
|
|
81
|
+
})]
|
|
82
|
+
})
|
|
83
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("rect", {
|
|
84
|
+
x: "0",
|
|
85
|
+
y: "0",
|
|
86
|
+
rx: "0",
|
|
87
|
+
ry: "0",
|
|
88
|
+
width: "18",
|
|
89
|
+
height: "18",
|
|
90
|
+
fill: "url(#bwsquare2px)",
|
|
91
|
+
strokeWidth: "0"
|
|
92
|
+
})]
|
|
93
|
+
})
|
|
94
|
+
});
|
|
95
|
+
const wrapperProperties = showPopOver ? {
|
|
96
|
+
onClick: () => setEditorOpen(prevOpen => !prevOpen)
|
|
97
|
+
} : {};
|
|
98
|
+
const wrapper = wrapperChildren => /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
99
|
+
className: classes,
|
|
100
|
+
...wrapperProperties,
|
|
101
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
102
|
+
style: {
|
|
103
|
+
opacity: isEditorOpen ? 0 : 1
|
|
104
|
+
},
|
|
105
|
+
className: "fwe-color-label",
|
|
106
|
+
children: label
|
|
107
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
108
|
+
className: "fwe-color-container",
|
|
109
|
+
children: [wrapperChildren, " ", text && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
110
|
+
className: "fwe-color-indicator-text",
|
|
111
|
+
children: text
|
|
112
|
+
}), ' ']
|
|
113
|
+
})]
|
|
114
|
+
});
|
|
115
|
+
return showPopOver ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Popover.default, {
|
|
116
|
+
containerClassName: "fwe-popover-container--color-indicator",
|
|
117
|
+
position: "top",
|
|
118
|
+
flip: false,
|
|
119
|
+
wrapper: wrapper,
|
|
120
|
+
popoverContent: children,
|
|
121
|
+
open: isEditorOpen,
|
|
122
|
+
onStatusChange: setEditorOpen,
|
|
123
|
+
stopPropagation: true,
|
|
124
|
+
children: colorBox
|
|
125
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
126
|
+
children: wrapper(colorBox)
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
var _default = ColorIndicator;
|
|
130
|
+
exports.default = _default;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
class ColorHelper {
|
|
8
|
+
// based on: https://gist.github.com/mjackson/5311256
|
|
9
|
+
static rgbToHsv(rgb) {
|
|
10
|
+
if (!rgb) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
const r = this.limitToByte(rgb.r) / 255;
|
|
14
|
+
const g = this.limitToByte(rgb.g) / 255;
|
|
15
|
+
const b = this.limitToByte(rgb.b) / 255;
|
|
16
|
+
const max = Math.max(r, g, b);
|
|
17
|
+
const min = Math.min(r, g, b);
|
|
18
|
+
let h = max;
|
|
19
|
+
let s = max;
|
|
20
|
+
const v = max;
|
|
21
|
+
const d = max - min;
|
|
22
|
+
s = max === 0 ? 0 : d / max;
|
|
23
|
+
if (max === min) {
|
|
24
|
+
h = 0; // achromatic
|
|
25
|
+
} else {
|
|
26
|
+
switch (max) {
|
|
27
|
+
case r:
|
|
28
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
29
|
+
break;
|
|
30
|
+
case g:
|
|
31
|
+
h = (b - r) / d + 2;
|
|
32
|
+
break;
|
|
33
|
+
case b:
|
|
34
|
+
h = (r - g) / d + 4;
|
|
35
|
+
break;
|
|
36
|
+
default:
|
|
37
|
+
// no other option
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
h /= 6;
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
h,
|
|
44
|
+
s,
|
|
45
|
+
v
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// based on: https://gist.github.com/mjackson/5311256
|
|
50
|
+
static hsvToRgb(_hsv) {
|
|
51
|
+
const hsv = _hsv;
|
|
52
|
+
hsv.h = this.limitToOne(_hsv.h);
|
|
53
|
+
hsv.s = this.limitToOne(_hsv.s);
|
|
54
|
+
hsv.v = this.limitToOne(_hsv.v);
|
|
55
|
+
let r = 0;
|
|
56
|
+
let g = 0;
|
|
57
|
+
let b = 0;
|
|
58
|
+
const i = Math.floor(hsv.h * 6);
|
|
59
|
+
const f = hsv.h * 6 - i;
|
|
60
|
+
const p = hsv.v * (1 - hsv.s);
|
|
61
|
+
const q = hsv.v * (1 - f * hsv.s);
|
|
62
|
+
const t = hsv.v * (1 - (1 - f) * hsv.s);
|
|
63
|
+
switch (i % 6) {
|
|
64
|
+
case 0:
|
|
65
|
+
r = hsv.v;
|
|
66
|
+
g = t;
|
|
67
|
+
b = p;
|
|
68
|
+
break;
|
|
69
|
+
case 1:
|
|
70
|
+
r = q;
|
|
71
|
+
g = hsv.v;
|
|
72
|
+
b = p;
|
|
73
|
+
break;
|
|
74
|
+
case 2:
|
|
75
|
+
r = p;
|
|
76
|
+
g = hsv.v;
|
|
77
|
+
b = t;
|
|
78
|
+
break;
|
|
79
|
+
case 3:
|
|
80
|
+
r = p;
|
|
81
|
+
g = q;
|
|
82
|
+
b = hsv.v;
|
|
83
|
+
break;
|
|
84
|
+
case 4:
|
|
85
|
+
r = t;
|
|
86
|
+
g = p;
|
|
87
|
+
b = hsv.v;
|
|
88
|
+
break;
|
|
89
|
+
case 5:
|
|
90
|
+
r = hsv.v;
|
|
91
|
+
g = p;
|
|
92
|
+
b = q;
|
|
93
|
+
break;
|
|
94
|
+
default:
|
|
95
|
+
// no other option
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
r: this.limitToByte(r * 255),
|
|
100
|
+
g: this.limitToByte(g * 255),
|
|
101
|
+
b: this.limitToByte(b * 255)
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
static limitToByte(num) {
|
|
105
|
+
if (num <= 0) {
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
if (num >= 255) {
|
|
109
|
+
return 255;
|
|
110
|
+
}
|
|
111
|
+
return num;
|
|
112
|
+
}
|
|
113
|
+
static limitToOne(num) {
|
|
114
|
+
if (num <= 0) {
|
|
115
|
+
return 0;
|
|
116
|
+
}
|
|
117
|
+
if (num >= 1) {
|
|
118
|
+
return 1;
|
|
119
|
+
}
|
|
120
|
+
return num;
|
|
121
|
+
}
|
|
122
|
+
static numberToHex(rgb) {
|
|
123
|
+
let hex = Math.round(rgb).toString(16);
|
|
124
|
+
if (hex.length < 2) {
|
|
125
|
+
hex = `0${hex}`;
|
|
126
|
+
}
|
|
127
|
+
return hex.toUpperCase();
|
|
128
|
+
}
|
|
129
|
+
static rgbToHex(_rgb) {
|
|
130
|
+
const rgb = _rgb;
|
|
131
|
+
rgb.r = this.limitToByte(rgb.r);
|
|
132
|
+
rgb.g = this.limitToByte(rgb.g);
|
|
133
|
+
rgb.b = this.limitToByte(rgb.b);
|
|
134
|
+
const red = this.numberToHex(rgb.r);
|
|
135
|
+
const green = this.numberToHex(rgb.g);
|
|
136
|
+
const blue = this.numberToHex(rgb.b);
|
|
137
|
+
return `#${red}${green}${blue}`;
|
|
138
|
+
}
|
|
139
|
+
static hexToRgb(hexString) {
|
|
140
|
+
const numbersOnly = hexString.substring(1);
|
|
141
|
+
const aRgbHex = numbersOnly.match(/.{1,2}/g);
|
|
142
|
+
return aRgbHex ? {
|
|
143
|
+
r: parseInt(aRgbHex[0], 16),
|
|
144
|
+
g: parseInt(aRgbHex[1], 16),
|
|
145
|
+
b: parseInt(aRgbHex[2], 16)
|
|
146
|
+
} : undefined;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.default = ColorHelper;
|