orcs-design-system 3.3.60 → 3.3.61
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.
|
@@ -17,8 +17,9 @@ export default {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
|
+
const initialColor = "linear-gradient(90deg,rgb(56, 136, 255) 0%,rgb(148, 81, 255) 100%)";
|
|
20
21
|
export const Default = () => {
|
|
21
|
-
const [color, setColor] = useState(
|
|
22
|
+
const [color, setColor] = useState(initialColor);
|
|
22
23
|
return /*#__PURE__*/_jsx(Box, {
|
|
23
24
|
p: "l",
|
|
24
25
|
position: "relative",
|
|
@@ -63,8 +64,72 @@ export const Default = () => {
|
|
|
63
64
|
})
|
|
64
65
|
});
|
|
65
66
|
};
|
|
67
|
+
export const Controlled = () => {
|
|
68
|
+
const [color, setColor] = useState(initialColor);
|
|
69
|
+
const onSave = color => {
|
|
70
|
+
setColor(color);
|
|
71
|
+
};
|
|
72
|
+
const onClose = () => {
|
|
73
|
+
setColor(initialColor);
|
|
74
|
+
};
|
|
75
|
+
const onReset = () => {
|
|
76
|
+
setColor(initialColor);
|
|
77
|
+
return initialColor;
|
|
78
|
+
};
|
|
79
|
+
return /*#__PURE__*/_jsx(Box, {
|
|
80
|
+
p: "l",
|
|
81
|
+
position: "relative",
|
|
82
|
+
children: /*#__PURE__*/_jsx(Flex, {
|
|
83
|
+
width: "100%",
|
|
84
|
+
height: "150px",
|
|
85
|
+
justifyContent: "flex-end",
|
|
86
|
+
alignItems: "flex-start",
|
|
87
|
+
background: color,
|
|
88
|
+
borderRadius: "2",
|
|
89
|
+
p: "r",
|
|
90
|
+
children: /*#__PURE__*/_jsx(ColorPicker, {
|
|
91
|
+
value: color,
|
|
92
|
+
onChange: setColor,
|
|
93
|
+
position: "bottom-start",
|
|
94
|
+
onSave: onSave,
|
|
95
|
+
onReset: onReset,
|
|
96
|
+
onClose: onClose,
|
|
97
|
+
children: _ref2 => {
|
|
98
|
+
let {
|
|
99
|
+
toggleColorPicker
|
|
100
|
+
} = _ref2;
|
|
101
|
+
return /*#__PURE__*/_jsx(Popover, {
|
|
102
|
+
direction: "left",
|
|
103
|
+
height: "35px",
|
|
104
|
+
width: "fit-content",
|
|
105
|
+
text: "Change background colour",
|
|
106
|
+
ml: "auto",
|
|
107
|
+
children: /*#__PURE__*/_jsx(Button, {
|
|
108
|
+
height: "35px",
|
|
109
|
+
width: "35px",
|
|
110
|
+
borderRadius: "35px",
|
|
111
|
+
borderColor: "white30",
|
|
112
|
+
bg: "white30",
|
|
113
|
+
ariaLabel: "Change background colour",
|
|
114
|
+
onClick: toggleColorPicker,
|
|
115
|
+
children: /*#__PURE__*/_jsx(Icon, {
|
|
116
|
+
icon: ["fas", "palette"],
|
|
117
|
+
color: "white"
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
})
|
|
124
|
+
});
|
|
125
|
+
};
|
|
66
126
|
Default.__docgenInfo = {
|
|
67
127
|
"description": "",
|
|
68
128
|
"methods": [],
|
|
69
129
|
"displayName": "Default"
|
|
130
|
+
};
|
|
131
|
+
Controlled.__docgenInfo = {
|
|
132
|
+
"description": "",
|
|
133
|
+
"methods": [],
|
|
134
|
+
"displayName": "Controlled"
|
|
70
135
|
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import React, { useState, useMemo } from "react";
|
|
1
|
+
import React, { useState, useMemo, useCallback } from "react";
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
3
|
import Box from "../Box";
|
|
4
4
|
import ColorPickerLib from "react-best-gradient-color-picker";
|
|
5
5
|
import { FloatingPortal } from "@floating-ui/react";
|
|
6
6
|
import { getFloatingUiRootElement } from "../../utils/floatingUiHelpers";
|
|
7
7
|
import useActionMenu from "../ActionsMenu/useActionMenu";
|
|
8
|
+
import Flex from "../Flex";
|
|
9
|
+
import Button from "../Button";
|
|
8
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
11
|
const ColorPicker = _ref => {
|
|
10
12
|
let {
|
|
@@ -32,10 +34,16 @@ const ColorPicker = _ref => {
|
|
|
32
34
|
hideGradientAngle = false,
|
|
33
35
|
hideGradientStop = false,
|
|
34
36
|
hideGradientControls = false,
|
|
37
|
+
onSave,
|
|
38
|
+
onReset,
|
|
39
|
+
isSaving,
|
|
40
|
+
isResetting,
|
|
35
41
|
// Spread all other props to the underlying library
|
|
36
42
|
...colorPickerProps
|
|
37
43
|
} = _ref;
|
|
44
|
+
const [initialColor, setInitialColor] = useState(value);
|
|
38
45
|
const [isOpen, setIsOpen] = useState(false);
|
|
46
|
+
const [color, setColor] = useState(value);
|
|
39
47
|
const toggleColorPicker = () => setIsOpen(!isOpen);
|
|
40
48
|
const baseStyles = useMemo(() => ({
|
|
41
49
|
zIndex,
|
|
@@ -48,6 +56,33 @@ const ColorPicker = _ref => {
|
|
|
48
56
|
open: isOpen,
|
|
49
57
|
onOpenChange: setIsOpen
|
|
50
58
|
});
|
|
59
|
+
const handleColorChange = useCallback(color => {
|
|
60
|
+
setColor(color);
|
|
61
|
+
onChange?.(color);
|
|
62
|
+
}, [onChange]);
|
|
63
|
+
const onClose = useCallback(() => {
|
|
64
|
+
setIsOpen(false);
|
|
65
|
+
onChange?.(initialColor);
|
|
66
|
+
setColor(initialColor);
|
|
67
|
+
}, [onChange, initialColor]);
|
|
68
|
+
const handleSave = useCallback(async () => {
|
|
69
|
+
await onSave?.(color);
|
|
70
|
+
setInitialColor(color);
|
|
71
|
+
setIsOpen(false);
|
|
72
|
+
}, [onSave, color]);
|
|
73
|
+
const handleReset = useCallback(async () => {
|
|
74
|
+
const newColor = await onReset?.(initialColor);
|
|
75
|
+
if (!newColor) {
|
|
76
|
+
throw new Error("onReset must return a new color");
|
|
77
|
+
}
|
|
78
|
+
setIsOpen(false);
|
|
79
|
+
setInitialColor(newColor);
|
|
80
|
+
setColor(newColor);
|
|
81
|
+
}, [onReset, initialColor]);
|
|
82
|
+
const isDisabled = useMemo(() => isSaving || isResetting, [isSaving, isResetting]);
|
|
83
|
+
const isChanged = useMemo(() => {
|
|
84
|
+
return color !== initialColor;
|
|
85
|
+
}, [color, initialColor]);
|
|
51
86
|
return /*#__PURE__*/_jsxs(Box, {
|
|
52
87
|
ref: actionMenu.refs.setReference,
|
|
53
88
|
...actionMenu.getReferenceProps(),
|
|
@@ -57,14 +92,14 @@ const ColorPicker = _ref => {
|
|
|
57
92
|
}) : children, isOpen && /*#__PURE__*/_jsx(FloatingPortal, {
|
|
58
93
|
root: getFloatingUiRootElement(actionMenu.refs.reference),
|
|
59
94
|
preserveTabOrder: true,
|
|
60
|
-
children: /*#__PURE__*/
|
|
95
|
+
children: /*#__PURE__*/_jsxs(Box, {
|
|
61
96
|
ref: actionMenu.refs.setFloating,
|
|
62
97
|
style: actionMenu.floatingStyles,
|
|
63
98
|
...baseStyles,
|
|
64
99
|
...actionMenu.getFloatingProps(),
|
|
65
|
-
children: /*#__PURE__*/_jsx(ColorPickerLib, {
|
|
66
|
-
value:
|
|
67
|
-
onChange:
|
|
100
|
+
children: [/*#__PURE__*/_jsx(ColorPickerLib, {
|
|
101
|
+
value: color,
|
|
102
|
+
onChange: handleColorChange,
|
|
68
103
|
width: width,
|
|
69
104
|
height: height,
|
|
70
105
|
hidePresets: hidePresets,
|
|
@@ -81,7 +116,27 @@ const ColorPicker = _ref => {
|
|
|
81
116
|
hideGradientStop: hideGradientStop,
|
|
82
117
|
hideGradientControls: hideGradientControls,
|
|
83
118
|
...colorPickerProps
|
|
84
|
-
})
|
|
119
|
+
}), onSave && /*#__PURE__*/_jsxs(Flex, {
|
|
120
|
+
pt: "r",
|
|
121
|
+
gap: "s",
|
|
122
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
123
|
+
onClick: handleSave,
|
|
124
|
+
disabled: isDisabled || !isChanged,
|
|
125
|
+
variant: "success",
|
|
126
|
+
children: "Save"
|
|
127
|
+
}), onReset && /*#__PURE__*/_jsx(Button, {
|
|
128
|
+
ml: "auto",
|
|
129
|
+
onClick: handleReset,
|
|
130
|
+
disabled: isDisabled,
|
|
131
|
+
variant: "ghost",
|
|
132
|
+
children: "Reset"
|
|
133
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
134
|
+
ml: !onReset && "auto",
|
|
135
|
+
onClick: onClose,
|
|
136
|
+
disabled: isDisabled,
|
|
137
|
+
children: "Close"
|
|
138
|
+
})]
|
|
139
|
+
})]
|
|
85
140
|
})
|
|
86
141
|
})]
|
|
87
142
|
});
|
|
@@ -110,7 +165,11 @@ ColorPicker.propTypes = {
|
|
|
110
165
|
hideGradientType: PropTypes.bool,
|
|
111
166
|
hideGradientAngle: PropTypes.bool,
|
|
112
167
|
hideGradientStop: PropTypes.bool,
|
|
113
|
-
hideGradientControls: PropTypes.bool
|
|
168
|
+
hideGradientControls: PropTypes.bool,
|
|
169
|
+
onSave: PropTypes.func,
|
|
170
|
+
onReset: PropTypes.func,
|
|
171
|
+
isSaving: PropTypes.bool,
|
|
172
|
+
isResetting: PropTypes.bool
|
|
114
173
|
// Note: We don't need to define PropTypes for the spread props
|
|
115
174
|
// as they'll be passed directly to the underlying library
|
|
116
175
|
};
|
|
@@ -389,6 +448,34 @@ ColorPicker.__docgenInfo = {
|
|
|
389
448
|
}]
|
|
390
449
|
},
|
|
391
450
|
"required": true
|
|
451
|
+
},
|
|
452
|
+
"onSave": {
|
|
453
|
+
"description": "",
|
|
454
|
+
"type": {
|
|
455
|
+
"name": "func"
|
|
456
|
+
},
|
|
457
|
+
"required": false
|
|
458
|
+
},
|
|
459
|
+
"onReset": {
|
|
460
|
+
"description": "",
|
|
461
|
+
"type": {
|
|
462
|
+
"name": "func"
|
|
463
|
+
},
|
|
464
|
+
"required": false
|
|
465
|
+
},
|
|
466
|
+
"isSaving": {
|
|
467
|
+
"description": "",
|
|
468
|
+
"type": {
|
|
469
|
+
"name": "bool"
|
|
470
|
+
},
|
|
471
|
+
"required": false
|
|
472
|
+
},
|
|
473
|
+
"isResetting": {
|
|
474
|
+
"description": "",
|
|
475
|
+
"type": {
|
|
476
|
+
"name": "bool"
|
|
477
|
+
},
|
|
478
|
+
"required": false
|
|
392
479
|
}
|
|
393
480
|
}
|
|
394
481
|
};
|