ish-ui 1.4.0 → 1.4.1
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/colorPicker/ColorPicker.js +26 -25
- package/package.json +1 -1
|
@@ -108,54 +108,55 @@ const useStyles = makeAppStyles()(({ spacing, palette, zIndex, transitions }, p,
|
|
|
108
108
|
}));
|
|
109
109
|
// Gap between the anchor and the paper, leaving room for the arrow.
|
|
110
110
|
const popperModifiers = [{ name: 'offset', options: { offset: [0, 12] } }];
|
|
111
|
-
const ColorPickerBase = React.memo(({ color, input: {
|
|
111
|
+
const ColorPickerBase = React.memo(({ color, input: { onChange }, TransitionProps, setAnchorEl }) => {
|
|
112
112
|
const { classes } = useStyles();
|
|
113
|
-
|
|
114
|
-
const [
|
|
113
|
+
// Single source of truth for all pickers; null until HuePicker has parsed the initial color
|
|
114
|
+
const [hsv, setHsv] = useState(null);
|
|
115
115
|
const hueRef = useRef(undefined);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
116
|
+
// Alpha slider is used as a saturation slider, so saturation is passed as alpha
|
|
117
|
+
const hueColor = useMemo(() => (hsv ? Object.assign(Object.assign({}, hsv), { a: 1 }) : color), [hsv, color]);
|
|
118
|
+
const alfaColor = useMemo(() => (hsv ? {
|
|
119
|
+
h: hsv.h, s: 1, v: hsv.v, a: hsv.s
|
|
120
|
+
} : color), [hsv, color]);
|
|
121
|
+
const onHueChange = useCallback(color => {
|
|
122
|
+
setHsv(prev => (Object.assign(Object.assign({}, (prev || color.hsv)), { h: color.hsv.h })));
|
|
121
123
|
}, []);
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
124
|
+
const onAlfaChange = useCallback(color => {
|
|
125
|
+
setHsv(prev => (Object.assign(Object.assign({}, (prev || color.hsv)), { s: color.hsv.a })));
|
|
126
|
+
}, []);
|
|
127
|
+
const onMaterialChange = useCallback(color => {
|
|
128
|
+
setHsv({ h: color.hsv.h, s: color.hsv.s, v: color.hsv.v });
|
|
129
|
+
}, []);
|
|
130
|
+
const commitHex = (hex) => {
|
|
125
131
|
if (hex) {
|
|
126
132
|
onChange(hex.replace('#', ''));
|
|
127
133
|
}
|
|
128
134
|
};
|
|
135
|
+
// Slider pickers report their own (saturation-substituted) color, so take the resulting one from HuePicker
|
|
136
|
+
const onSliderChangeComplete = () => { var _a, _b; return commitHex((_b = (_a = hueRef.current) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.hex); };
|
|
137
|
+
const onMaterialChangeComplete = color => commitHex(color.hex);
|
|
129
138
|
const handleClickAway = useCallback(() => {
|
|
130
139
|
setAnchorEl(null);
|
|
131
140
|
}, []);
|
|
132
|
-
useEffect(() => {
|
|
133
|
-
if (!hueColor && value) {
|
|
134
|
-
setHueColor('#' + value);
|
|
135
|
-
}
|
|
136
|
-
}, [value, hueColor]);
|
|
137
141
|
useEffect(() => {
|
|
138
142
|
var _a, _b;
|
|
139
143
|
const hueHsv = (_b = (_a = hueRef.current) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.hsv;
|
|
140
|
-
if (
|
|
141
|
-
|
|
144
|
+
if (hueHsv) {
|
|
145
|
+
setHsv({ h: hueHsv.h, s: hueHsv.s, v: hueHsv.v });
|
|
142
146
|
}
|
|
143
|
-
|
|
144
|
-
h: hueHsv.h, s: 1, v: hueHsv.v, a: hueHsv.s
|
|
145
|
-
});
|
|
146
|
-
}, [hueRef.current]);
|
|
147
|
+
}, []);
|
|
147
148
|
return (React.createElement(ClickAwayListener, { onClickAway: handleClickAway },
|
|
148
149
|
React.createElement(Grow, Object.assign({}, TransitionProps, { timeout: 200 }),
|
|
149
150
|
React.createElement(Paper, { className: classes.paper },
|
|
150
151
|
React.createElement("span", { className: classes.arrow, "data-popper-arrow": true }),
|
|
151
|
-
React.createElement(HuePicker, { ref: hueRef, color: hueColor, onChange:
|
|
152
|
-
React.createElement(AlphaPicker, { className: classes.customAlfa, color: alfaColor, width: "168", onChange:
|
|
152
|
+
React.createElement(HuePicker, { ref: hueRef, color: hueColor, onChange: onHueChange, onChangeComplete: onSliderChangeComplete, width: "168", className: classes.bottomOffset }),
|
|
153
|
+
React.createElement(AlphaPicker, { className: classes.customAlfa, color: alfaColor, width: "168", onChange: onAlfaChange, onChangeComplete: onSliderChangeComplete }),
|
|
153
154
|
React.createElement("div", { className: classes.material },
|
|
154
155
|
React.createElement(MaterialPicker, { styles: {
|
|
155
156
|
default: {
|
|
156
157
|
material: { width: '100%', height: 'unset', padding: 0, fontFamily: 'inherit' }
|
|
157
158
|
}
|
|
158
|
-
}, color: hueColor, onChange:
|
|
159
|
+
}, color: hueColor, onChange: onMaterialChange, onChangeComplete: onMaterialChangeComplete }))))));
|
|
159
160
|
});
|
|
160
161
|
const ColorPickerWrapper = React.memo(({ input, placement = 'top', width }) => {
|
|
161
162
|
const { classes, cx } = useStyles();
|