@zendeskgarden/react-colorpickers 9.0.0-next.2 → 9.0.0-next.21
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/README.md +72 -2
- package/dist/esm/elements/ColorPicker/ColorWell.js +110 -0
- package/dist/esm/elements/ColorPicker/index.js +237 -0
- package/dist/esm/elements/ColorPicker/reducer.js +275 -0
- package/dist/esm/elements/ColorPickerDialog/index.js +153 -0
- package/dist/esm/elements/ColorSwatch/index.js +149 -0
- package/dist/esm/elements/ColorSwatchDialog/index.js +179 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/12/check-sm-fill.svg.js +29 -0
- package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/chevron-down-stroke.svg.js +25 -0
- package/dist/esm/styled/ColorPicker/StyledAlphaRange.js +42 -0
- package/dist/esm/styled/ColorPicker/StyledColorPicker.js +25 -0
- package/dist/esm/styled/ColorPicker/StyledColorWell.js +36 -0
- package/dist/esm/styled/ColorPicker/StyledColorWellThumb.js +51 -0
- package/dist/esm/styled/ColorPicker/StyledHexField.js +24 -0
- package/dist/esm/styled/ColorPicker/StyledHueRange.js +23 -0
- package/dist/esm/styled/ColorPicker/StyledInput.js +24 -0
- package/dist/esm/styled/ColorPicker/StyledInputGroup.js +22 -0
- package/dist/esm/styled/ColorPicker/StyledLabel.js +23 -0
- package/dist/esm/styled/ColorPicker/StyledPreview.js +39 -0
- package/dist/esm/styled/ColorPicker/StyledRGBAField.js +32 -0
- package/dist/esm/styled/ColorPicker/StyledSliderGroup.js +22 -0
- package/dist/esm/styled/ColorPicker/StyledSliders.js +45 -0
- package/dist/esm/styled/ColorPickerDialog/StyledButton.js +22 -0
- package/dist/esm/styled/ColorPickerDialog/StyledButtonPreview.js +52 -0
- package/dist/esm/styled/ColorPickerDialog/StyledTooltipBody.js +23 -0
- package/dist/esm/styled/ColorPickerDialog/StyledTooltipModal.js +23 -0
- package/dist/esm/styled/ColorSwatch/StyledCell.js +22 -0
- package/dist/esm/styled/ColorSwatch/StyledColorSwatch.js +22 -0
- package/dist/esm/styled/ColorSwatch/StyledColorSwatchInput.js +22 -0
- package/dist/esm/styled/ColorSwatch/StyledColorSwatchLabel.js +53 -0
- package/dist/esm/styled/ColorSwatch/StyledIcon.js +24 -0
- package/dist/esm/styled/common/StyledRange.js +160 -0
- package/dist/esm/utils/conversion.js +34 -0
- package/dist/esm/utils/saturation.js +64 -0
- package/dist/esm/utils/validation.js +12 -0
- package/dist/index.cjs.js +267 -243
- package/dist/typings/elements/{Colorpicker → ColorPicker}/index.d.ts +2 -2
- package/dist/typings/elements/{ColorpickerDialog → ColorPickerDialog}/index.d.ts +2 -2
- package/dist/typings/index.d.ts +3 -3
- package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledAlphaRange.d.ts +2 -2
- package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledColorPicker.d.ts +1 -1
- package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledColorWell.d.ts +1 -1
- package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledPreview.d.ts +3 -3
- package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledSliders.d.ts +3 -2
- package/dist/typings/styled/{ColorpickerDialog → ColorPickerDialog}/StyledButton.d.ts +0 -1
- package/dist/typings/styled/{ColorpickerDialog → ColorPickerDialog}/StyledButtonPreview.d.ts +2 -2
- package/dist/typings/styled/ColorSwatch/StyledColorSwatchLabel.d.ts +3 -3
- package/dist/typings/styled/common/StyledRange.d.ts +2 -2
- package/dist/typings/styled/index.d.ts +17 -17
- package/dist/typings/styled/types.d.ts +12 -0
- package/dist/typings/types/index.d.ts +2 -2
- package/package.json +12 -12
- package/dist/index.esm.js +0 -1612
- package/dist/typings/styled/common/checkeredBackground.d.ts +0 -8
- /package/dist/typings/elements/{Colorpicker → ColorPicker}/ColorWell.d.ts +0 -0
- /package/dist/typings/elements/{Colorpicker → ColorPicker}/reducer.d.ts +0 -0
- /package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledColorWellThumb.d.ts +0 -0
- /package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledHexField.d.ts +0 -0
- /package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledHueRange.d.ts +0 -0
- /package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledInput.d.ts +0 -0
- /package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledInputGroup.d.ts +0 -0
- /package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledLabel.d.ts +0 -0
- /package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledRGBAField.d.ts +0 -0
- /package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledSliderGroup.d.ts +0 -0
- /package/dist/typings/styled/{ColorpickerDialog → ColorPickerDialog}/StyledTooltipBody.d.ts +0 -0
- /package/dist/typings/styled/{ColorpickerDialog → ColorPickerDialog}/StyledTooltipModal.d.ts +0 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import React__default, { forwardRef, useRef, useState, useEffect, cloneElement, Children } from 'react';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import { Button } from '@zendeskgarden/react-buttons';
|
|
10
|
+
import { PLACEMENT } from '@zendeskgarden/react-modals';
|
|
11
|
+
import { composeEventHandlers } from '@zendeskgarden/container-utilities';
|
|
12
|
+
import SvgChevronDownStroke from '../../node_modules/@zendeskgarden/svg-icons/src/16/chevron-down-stroke.svg.js';
|
|
13
|
+
import { ColorPicker } from '../ColorPicker/index.js';
|
|
14
|
+
import '../../styled/ColorPicker/StyledColorPicker.js';
|
|
15
|
+
import '../../styled/ColorPicker/StyledHueRange.js';
|
|
16
|
+
import '../../styled/ColorPicker/StyledAlphaRange.js';
|
|
17
|
+
import '../../styled/ColorPicker/StyledPreview.js';
|
|
18
|
+
import '../../styled/ColorPicker/StyledColorWell.js';
|
|
19
|
+
import '../../styled/ColorPicker/StyledColorWellThumb.js';
|
|
20
|
+
import '../../styled/ColorPicker/StyledSliderGroup.js';
|
|
21
|
+
import '../../styled/ColorPicker/StyledHexField.js';
|
|
22
|
+
import '../../styled/ColorPicker/StyledLabel.js';
|
|
23
|
+
import '../../styled/ColorPicker/StyledInput.js';
|
|
24
|
+
import '../../styled/ColorPicker/StyledInputGroup.js';
|
|
25
|
+
import '../../styled/ColorPicker/StyledRGBAField.js';
|
|
26
|
+
import '../../styled/ColorPicker/StyledSliders.js';
|
|
27
|
+
import { StyledButton } from '../../styled/ColorPickerDialog/StyledButton.js';
|
|
28
|
+
import { StyledButtonPreview } from '../../styled/ColorPickerDialog/StyledButtonPreview.js';
|
|
29
|
+
import { StyledTooltipModal } from '../../styled/ColorPickerDialog/StyledTooltipModal.js';
|
|
30
|
+
import { StyledTooltipBody } from '../../styled/ColorPickerDialog/StyledTooltipBody.js';
|
|
31
|
+
import '../../styled/ColorSwatch/StyledColorSwatch.js';
|
|
32
|
+
import '../../styled/ColorSwatch/StyledColorSwatchInput.js';
|
|
33
|
+
import '../../styled/ColorSwatch/StyledColorSwatchLabel.js';
|
|
34
|
+
import '../../styled/ColorSwatch/StyledIcon.js';
|
|
35
|
+
import '../../styled/ColorSwatch/StyledCell.js';
|
|
36
|
+
import { useText } from '@zendeskgarden/react-theming';
|
|
37
|
+
|
|
38
|
+
const ColorPickerDialog = forwardRef((_ref, ref) => {
|
|
39
|
+
let {
|
|
40
|
+
color,
|
|
41
|
+
defaultColor,
|
|
42
|
+
placement,
|
|
43
|
+
onChange,
|
|
44
|
+
onClose,
|
|
45
|
+
labels,
|
|
46
|
+
hasArrow,
|
|
47
|
+
isAnimated,
|
|
48
|
+
isOpaque,
|
|
49
|
+
isOpen,
|
|
50
|
+
zIndex,
|
|
51
|
+
focusInset,
|
|
52
|
+
disabled,
|
|
53
|
+
buttonProps,
|
|
54
|
+
onDialogChange,
|
|
55
|
+
'aria-label': ariaLabel,
|
|
56
|
+
children,
|
|
57
|
+
...props
|
|
58
|
+
} = _ref;
|
|
59
|
+
const isControlled = color !== null && color !== undefined;
|
|
60
|
+
const isDialogControlled = isOpen !== undefined && isOpen !== null;
|
|
61
|
+
const buttonRef = useRef(null);
|
|
62
|
+
const colorPickerRef = useRef(null);
|
|
63
|
+
const [referenceElement, setReferenceElement] = useState();
|
|
64
|
+
const [uncontrolledColor, setUncontrolledColor] = useState(defaultColor);
|
|
65
|
+
const ariaLabelText = useText(ColorPickerDialog, {
|
|
66
|
+
'aria-label': ariaLabel
|
|
67
|
+
}, 'aria-label', 'Color picker');
|
|
68
|
+
const openDialog = () => {
|
|
69
|
+
setReferenceElement(buttonRef.current);
|
|
70
|
+
onDialogChange && onDialogChange({
|
|
71
|
+
isOpen: true
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
const closeDialog = () => {
|
|
75
|
+
setReferenceElement(null);
|
|
76
|
+
onDialogChange && onDialogChange({
|
|
77
|
+
isOpen: false
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
const onClick = composeEventHandlers(props.onClick, () => {
|
|
81
|
+
if (referenceElement) {
|
|
82
|
+
closeDialog();
|
|
83
|
+
} else {
|
|
84
|
+
openDialog();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (isDialogControlled) {
|
|
89
|
+
if (isOpen) {
|
|
90
|
+
setReferenceElement(buttonRef.current);
|
|
91
|
+
} else {
|
|
92
|
+
setReferenceElement(null);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}, [isOpen, isDialogControlled]);
|
|
96
|
+
return React__default.createElement(React__default.Fragment, null, children ? ( cloneElement(Children.only(children), {
|
|
97
|
+
onClick,
|
|
98
|
+
ref: buttonRef
|
|
99
|
+
})) : React__default.createElement(StyledButton, Object.assign({
|
|
100
|
+
disabled: disabled,
|
|
101
|
+
focusInset: focusInset,
|
|
102
|
+
ref: buttonRef,
|
|
103
|
+
onClick: onClick
|
|
104
|
+
}, buttonProps), React__default.createElement(StyledButtonPreview, {
|
|
105
|
+
$backgroundColor: isControlled ? color : uncontrolledColor
|
|
106
|
+
}), React__default.createElement(Button.EndIcon, {
|
|
107
|
+
isRotated: referenceElement != null
|
|
108
|
+
}, React__default.createElement(SvgChevronDownStroke, null))), React__default.createElement(StyledTooltipModal, Object.assign({
|
|
109
|
+
ref: ref,
|
|
110
|
+
hasArrow: hasArrow,
|
|
111
|
+
zIndex: zIndex,
|
|
112
|
+
isAnimated: isAnimated,
|
|
113
|
+
focusOnMount: false,
|
|
114
|
+
placement: placement,
|
|
115
|
+
referenceElement: referenceElement,
|
|
116
|
+
onClose: () => {
|
|
117
|
+
closeDialog();
|
|
118
|
+
onClose && onClose(isControlled ? color : uncontrolledColor);
|
|
119
|
+
},
|
|
120
|
+
"aria-label": ariaLabelText
|
|
121
|
+
}, props), React__default.createElement(StyledTooltipBody, null, React__default.createElement(ColorPicker, {
|
|
122
|
+
autofocus: true,
|
|
123
|
+
color: color,
|
|
124
|
+
isOpaque: isOpaque,
|
|
125
|
+
labels: labels,
|
|
126
|
+
ref: colorPickerRef,
|
|
127
|
+
defaultColor: uncontrolledColor,
|
|
128
|
+
onChange: isControlled ? onChange : setUncontrolledColor
|
|
129
|
+
}))));
|
|
130
|
+
});
|
|
131
|
+
ColorPickerDialog.propTypes = {
|
|
132
|
+
...ColorPicker.propTypes,
|
|
133
|
+
placement: PropTypes.oneOf(PLACEMENT),
|
|
134
|
+
onClose: PropTypes.func,
|
|
135
|
+
onDialogChange: PropTypes.func,
|
|
136
|
+
disabled: PropTypes.bool,
|
|
137
|
+
labels: PropTypes.object,
|
|
138
|
+
buttonProps: PropTypes.object,
|
|
139
|
+
zIndex: PropTypes.number,
|
|
140
|
+
hasArrow: PropTypes.bool,
|
|
141
|
+
isAnimated: PropTypes.bool,
|
|
142
|
+
isOpen: PropTypes.bool,
|
|
143
|
+
focusInset: PropTypes.bool
|
|
144
|
+
};
|
|
145
|
+
ColorPickerDialog.defaultProps = {
|
|
146
|
+
placement: 'bottom-start',
|
|
147
|
+
isAnimated: true,
|
|
148
|
+
zIndex: 1000,
|
|
149
|
+
hasArrow: false
|
|
150
|
+
};
|
|
151
|
+
ColorPickerDialog.displayName = 'ColorPickerDialog';
|
|
152
|
+
|
|
153
|
+
export { ColorPickerDialog };
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import React__default, { forwardRef, useContext, useRef, useState } from 'react';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import { mergeRefs } from 'react-merge-refs';
|
|
10
|
+
import { ThemeContext } from 'styled-components';
|
|
11
|
+
import { useGrid } from '@zendeskgarden/container-grid';
|
|
12
|
+
import { useId } from '@zendeskgarden/container-utilities';
|
|
13
|
+
import { DEFAULT_THEME, useDocument } from '@zendeskgarden/react-theming';
|
|
14
|
+
import { Tooltip } from '@zendeskgarden/react-tooltips';
|
|
15
|
+
import '../../styled/ColorPicker/StyledColorPicker.js';
|
|
16
|
+
import '../../styled/ColorPicker/StyledHueRange.js';
|
|
17
|
+
import '../../styled/ColorPicker/StyledAlphaRange.js';
|
|
18
|
+
import '../../styled/ColorPicker/StyledPreview.js';
|
|
19
|
+
import '../../styled/ColorPicker/StyledColorWell.js';
|
|
20
|
+
import '../../styled/ColorPicker/StyledColorWellThumb.js';
|
|
21
|
+
import '../../styled/ColorPicker/StyledSliderGroup.js';
|
|
22
|
+
import '../../styled/ColorPicker/StyledHexField.js';
|
|
23
|
+
import '../../styled/ColorPicker/StyledLabel.js';
|
|
24
|
+
import '../../styled/ColorPicker/StyledInput.js';
|
|
25
|
+
import '../../styled/ColorPicker/StyledInputGroup.js';
|
|
26
|
+
import '../../styled/ColorPicker/StyledRGBAField.js';
|
|
27
|
+
import '../../styled/ColorPicker/StyledSliders.js';
|
|
28
|
+
import '../../styled/ColorPickerDialog/StyledButton.js';
|
|
29
|
+
import '../../styled/ColorPickerDialog/StyledButtonPreview.js';
|
|
30
|
+
import '../../styled/ColorPickerDialog/StyledTooltipModal.js';
|
|
31
|
+
import '../../styled/ColorPickerDialog/StyledTooltipBody.js';
|
|
32
|
+
import { StyledColorSwatch } from '../../styled/ColorSwatch/StyledColorSwatch.js';
|
|
33
|
+
import { StyledColorSwatchInput } from '../../styled/ColorSwatch/StyledColorSwatchInput.js';
|
|
34
|
+
import { StyledColorSwatchLabel } from '../../styled/ColorSwatch/StyledColorSwatchLabel.js';
|
|
35
|
+
import { StyledIcon } from '../../styled/ColorSwatch/StyledIcon.js';
|
|
36
|
+
import { StyledCell } from '../../styled/ColorSwatch/StyledCell.js';
|
|
37
|
+
|
|
38
|
+
const ColorSwatch = forwardRef((_ref, ref) => {
|
|
39
|
+
let {
|
|
40
|
+
name,
|
|
41
|
+
colors,
|
|
42
|
+
isCheckboxGroup,
|
|
43
|
+
defaultSelectedColIndex,
|
|
44
|
+
defaultSelectedRowIndex,
|
|
45
|
+
selectedColIndex,
|
|
46
|
+
selectedRowIndex,
|
|
47
|
+
onSelect,
|
|
48
|
+
...props
|
|
49
|
+
} = _ref;
|
|
50
|
+
const theme = useContext(ThemeContext) || DEFAULT_THEME;
|
|
51
|
+
const environment = useDocument(theme);
|
|
52
|
+
const gridRef = useRef();
|
|
53
|
+
const [rowIndex, setRowIndex] = useState(selectedRowIndex === null ? undefined : selectedRowIndex);
|
|
54
|
+
const [colIndex, setColIndex] = useState(selectedColIndex === null ? undefined : selectedColIndex);
|
|
55
|
+
const isControlled = selectedColIndex !== undefined && selectedRowIndex !== undefined;
|
|
56
|
+
const {
|
|
57
|
+
getGridCellProps
|
|
58
|
+
} = useGrid({
|
|
59
|
+
environment,
|
|
60
|
+
rtl: theme.rtl,
|
|
61
|
+
matrix: colors,
|
|
62
|
+
wrap: true,
|
|
63
|
+
idPrefix: useId(undefined),
|
|
64
|
+
defaultRowIndex: defaultSelectedRowIndex,
|
|
65
|
+
defaultColIndex: defaultSelectedColIndex,
|
|
66
|
+
rowIndex,
|
|
67
|
+
colIndex,
|
|
68
|
+
onChange: (row, col) => {
|
|
69
|
+
setRowIndex(row);
|
|
70
|
+
setColIndex(col);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return React__default.createElement(StyledColorSwatch, Object.assign({
|
|
74
|
+
role: "grid",
|
|
75
|
+
ref: mergeRefs([gridRef, ref])
|
|
76
|
+
}, props), React__default.createElement("tbody", null, colors.map((row, _rowIndex) => React__default.createElement("tr", {
|
|
77
|
+
key: row[0].value
|
|
78
|
+
}, row.map((color, _colIndex) => {
|
|
79
|
+
const {
|
|
80
|
+
label,
|
|
81
|
+
value
|
|
82
|
+
} = color;
|
|
83
|
+
const {
|
|
84
|
+
role,
|
|
85
|
+
...gridCellProps
|
|
86
|
+
} = getGridCellProps({
|
|
87
|
+
colIndex: _colIndex,
|
|
88
|
+
rowIndex: _rowIndex
|
|
89
|
+
});
|
|
90
|
+
const checked = isControlled ? selectedRowIndex === _rowIndex && selectedColIndex === _colIndex : undefined;
|
|
91
|
+
const defaultChecked = isControlled ? undefined : defaultSelectedRowIndex === _rowIndex && defaultSelectedColIndex === _colIndex;
|
|
92
|
+
const handleChange = event => {
|
|
93
|
+
if (onSelect) {
|
|
94
|
+
if (event.target.checked) {
|
|
95
|
+
onSelect(_rowIndex, _colIndex);
|
|
96
|
+
} else {
|
|
97
|
+
onSelect(null, null);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (isCheckboxGroup && event.target.checked) {
|
|
101
|
+
const inputs = gridRef.current?.querySelectorAll('input');
|
|
102
|
+
inputs?.forEach(input => {
|
|
103
|
+
if (input !== event.target) {
|
|
104
|
+
input.checked = false;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const handleBlur = event => {
|
|
110
|
+
if (!(isCheckboxGroup || gridRef.current?.contains(event.relatedTarget))) {
|
|
111
|
+
const selectedInput = gridRef.current?.querySelector(`input[name='${event.target.name}']:checked`);
|
|
112
|
+
if (selectedInput !== null) {
|
|
113
|
+
const inputs = gridRef.current?.querySelectorAll('input');
|
|
114
|
+
inputs?.forEach(input => input.setAttribute('tabIndex', input.checked ? '0' : '-1'));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
return React__default.createElement(StyledCell, {
|
|
119
|
+
key: value,
|
|
120
|
+
role: role
|
|
121
|
+
}, React__default.createElement(StyledColorSwatchLabel, {
|
|
122
|
+
$backgroundColor: value
|
|
123
|
+
}, React__default.createElement(Tooltip, {
|
|
124
|
+
content: label
|
|
125
|
+
}, React__default.createElement(StyledColorSwatchInput, Object.assign({
|
|
126
|
+
"aria-label": label,
|
|
127
|
+
name: name,
|
|
128
|
+
type: isCheckboxGroup ? 'checkbox' : 'radio',
|
|
129
|
+
value: value,
|
|
130
|
+
defaultChecked: defaultChecked,
|
|
131
|
+
checked: checked,
|
|
132
|
+
onBlur: handleBlur,
|
|
133
|
+
onChange: handleChange
|
|
134
|
+
}, gridCellProps))), React__default.createElement(StyledIcon, null)));
|
|
135
|
+
})))));
|
|
136
|
+
});
|
|
137
|
+
ColorSwatch.displayName = 'ColorSwatch';
|
|
138
|
+
ColorSwatch.propTypes = {
|
|
139
|
+
name: PropTypes.string.isRequired,
|
|
140
|
+
colors: PropTypes.arrayOf(PropTypes.any).isRequired,
|
|
141
|
+
isCheckboxGroup: PropTypes.bool,
|
|
142
|
+
selectedRowIndex: PropTypes.number,
|
|
143
|
+
selectedColIndex: PropTypes.number,
|
|
144
|
+
defaultSelectedRowIndex: PropTypes.number,
|
|
145
|
+
defaultSelectedColIndex: PropTypes.number,
|
|
146
|
+
onSelect: PropTypes.func
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export { ColorSwatch };
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import React__default, { forwardRef, useRef, useState, useEffect, cloneElement, Children } from 'react';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import { Button } from '@zendeskgarden/react-buttons';
|
|
10
|
+
import { PLACEMENT } from '@zendeskgarden/react-modals';
|
|
11
|
+
import { useText } from '@zendeskgarden/react-theming';
|
|
12
|
+
import { composeEventHandlers } from '@zendeskgarden/container-utilities';
|
|
13
|
+
import SvgChevronDownStroke from '../../node_modules/@zendeskgarden/svg-icons/src/16/chevron-down-stroke.svg.js';
|
|
14
|
+
import { ColorSwatch } from '../ColorSwatch/index.js';
|
|
15
|
+
import '../../styled/ColorPicker/StyledColorPicker.js';
|
|
16
|
+
import '../../styled/ColorPicker/StyledHueRange.js';
|
|
17
|
+
import '../../styled/ColorPicker/StyledAlphaRange.js';
|
|
18
|
+
import '../../styled/ColorPicker/StyledPreview.js';
|
|
19
|
+
import '../../styled/ColorPicker/StyledColorWell.js';
|
|
20
|
+
import '../../styled/ColorPicker/StyledColorWellThumb.js';
|
|
21
|
+
import '../../styled/ColorPicker/StyledSliderGroup.js';
|
|
22
|
+
import '../../styled/ColorPicker/StyledHexField.js';
|
|
23
|
+
import '../../styled/ColorPicker/StyledLabel.js';
|
|
24
|
+
import '../../styled/ColorPicker/StyledInput.js';
|
|
25
|
+
import '../../styled/ColorPicker/StyledInputGroup.js';
|
|
26
|
+
import '../../styled/ColorPicker/StyledRGBAField.js';
|
|
27
|
+
import '../../styled/ColorPicker/StyledSliders.js';
|
|
28
|
+
import { StyledButton } from '../../styled/ColorPickerDialog/StyledButton.js';
|
|
29
|
+
import { StyledButtonPreview } from '../../styled/ColorPickerDialog/StyledButtonPreview.js';
|
|
30
|
+
import { StyledTooltipModal } from '../../styled/ColorPickerDialog/StyledTooltipModal.js';
|
|
31
|
+
import { StyledTooltipBody } from '../../styled/ColorPickerDialog/StyledTooltipBody.js';
|
|
32
|
+
import '../../styled/ColorSwatch/StyledColorSwatch.js';
|
|
33
|
+
import '../../styled/ColorSwatch/StyledColorSwatchInput.js';
|
|
34
|
+
import '../../styled/ColorSwatch/StyledColorSwatchLabel.js';
|
|
35
|
+
import '../../styled/ColorSwatch/StyledIcon.js';
|
|
36
|
+
import '../../styled/ColorSwatch/StyledCell.js';
|
|
37
|
+
|
|
38
|
+
const ColorSwatchDialog = forwardRef((_ref, ref) => {
|
|
39
|
+
let {
|
|
40
|
+
name,
|
|
41
|
+
colors,
|
|
42
|
+
isCheckboxGroup,
|
|
43
|
+
selectedRowIndex,
|
|
44
|
+
selectedColIndex,
|
|
45
|
+
defaultSelectedRowIndex,
|
|
46
|
+
defaultSelectedColIndex,
|
|
47
|
+
placement,
|
|
48
|
+
onSelect,
|
|
49
|
+
hasArrow,
|
|
50
|
+
isAnimated,
|
|
51
|
+
zIndex,
|
|
52
|
+
isOpen,
|
|
53
|
+
focusInset,
|
|
54
|
+
disabled,
|
|
55
|
+
buttonProps,
|
|
56
|
+
onDialogChange,
|
|
57
|
+
children,
|
|
58
|
+
'aria-label': ariaLabel,
|
|
59
|
+
...props
|
|
60
|
+
} = _ref;
|
|
61
|
+
const isControlled = selectedRowIndex !== undefined && selectedColIndex !== undefined;
|
|
62
|
+
const isDialogControlled = isOpen !== undefined && isOpen !== null;
|
|
63
|
+
const buttonRef = useRef(null);
|
|
64
|
+
const colorSwatchRef = useRef(null);
|
|
65
|
+
const [referenceElement, setReferenceElement] = useState(null);
|
|
66
|
+
const [rowIndex, setRowIndex] = useState(defaultSelectedRowIndex);
|
|
67
|
+
const [colIndex, setColIndex] = useState(defaultSelectedColIndex);
|
|
68
|
+
let backgroundColor;
|
|
69
|
+
if (isControlled) {
|
|
70
|
+
if (selectedRowIndex !== null && selectedColIndex !== null) {
|
|
71
|
+
backgroundColor = colors[selectedRowIndex][selectedColIndex].value;
|
|
72
|
+
}
|
|
73
|
+
} else if (rowIndex !== undefined && colIndex !== undefined) {
|
|
74
|
+
backgroundColor = colors[rowIndex][colIndex].value;
|
|
75
|
+
}
|
|
76
|
+
const ariaLabelText = useText(ColorSwatchDialog, {
|
|
77
|
+
'aria-label': ariaLabel
|
|
78
|
+
}, 'aria-label', 'Color swatch');
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (isDialogControlled) {
|
|
81
|
+
if (isOpen) {
|
|
82
|
+
setReferenceElement(buttonRef.current);
|
|
83
|
+
} else {
|
|
84
|
+
setReferenceElement(null);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}, [isOpen, isDialogControlled]);
|
|
88
|
+
const openDialog = () => {
|
|
89
|
+
setReferenceElement(buttonRef.current);
|
|
90
|
+
onDialogChange && onDialogChange({
|
|
91
|
+
isOpen: true
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
const closeDialog = () => {
|
|
95
|
+
setReferenceElement(null);
|
|
96
|
+
onDialogChange && onDialogChange({
|
|
97
|
+
isOpen: false
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
const onClick = composeEventHandlers(props.onClick, () => {
|
|
101
|
+
if (referenceElement) {
|
|
102
|
+
closeDialog();
|
|
103
|
+
} else {
|
|
104
|
+
openDialog();
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
if (referenceElement && colorSwatchRef.current) {
|
|
109
|
+
const input = colorSwatchRef.current.querySelector('[tabindex="0"]');
|
|
110
|
+
input?.focus();
|
|
111
|
+
}
|
|
112
|
+
}, [referenceElement]);
|
|
113
|
+
const handleSelect = (row, col) => {
|
|
114
|
+
if (isControlled === false) {
|
|
115
|
+
if (row === null || col === null) {
|
|
116
|
+
setRowIndex(undefined);
|
|
117
|
+
setColIndex(undefined);
|
|
118
|
+
} else {
|
|
119
|
+
setRowIndex(row);
|
|
120
|
+
setColIndex(col);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
onSelect && onSelect(row, col);
|
|
124
|
+
};
|
|
125
|
+
return React__default.createElement(React__default.Fragment, null, children ? ( cloneElement(Children.only(children), {
|
|
126
|
+
onClick,
|
|
127
|
+
ref: buttonRef
|
|
128
|
+
})) : React__default.createElement(StyledButton, Object.assign({
|
|
129
|
+
disabled: disabled,
|
|
130
|
+
focusInset: focusInset,
|
|
131
|
+
ref: buttonRef,
|
|
132
|
+
onClick: onClick
|
|
133
|
+
}, buttonProps), React__default.createElement(StyledButtonPreview, {
|
|
134
|
+
$backgroundColor: backgroundColor
|
|
135
|
+
}), React__default.createElement(Button.EndIcon, {
|
|
136
|
+
isRotated: referenceElement !== null
|
|
137
|
+
}, React__default.createElement(SvgChevronDownStroke, null))), React__default.createElement(StyledTooltipModal, Object.assign({
|
|
138
|
+
ref: ref,
|
|
139
|
+
zIndex: zIndex,
|
|
140
|
+
hasArrow: hasArrow,
|
|
141
|
+
focusOnMount: false,
|
|
142
|
+
placement: placement,
|
|
143
|
+
isAnimated: isAnimated,
|
|
144
|
+
referenceElement: referenceElement,
|
|
145
|
+
onClose: closeDialog,
|
|
146
|
+
"aria-label": ariaLabelText
|
|
147
|
+
}, props), React__default.createElement(StyledTooltipBody, null, React__default.createElement(ColorSwatch, {
|
|
148
|
+
name: name,
|
|
149
|
+
colors: colors,
|
|
150
|
+
ref: colorSwatchRef,
|
|
151
|
+
isCheckboxGroup: isCheckboxGroup,
|
|
152
|
+
selectedRowIndex: selectedRowIndex,
|
|
153
|
+
selectedColIndex: selectedColIndex,
|
|
154
|
+
defaultSelectedRowIndex: rowIndex,
|
|
155
|
+
defaultSelectedColIndex: colIndex,
|
|
156
|
+
onSelect: handleSelect
|
|
157
|
+
}))));
|
|
158
|
+
});
|
|
159
|
+
ColorSwatchDialog.propTypes = {
|
|
160
|
+
...ColorSwatch.propTypes,
|
|
161
|
+
placement: PropTypes.oneOf(PLACEMENT),
|
|
162
|
+
onDialogChange: PropTypes.func,
|
|
163
|
+
disabled: PropTypes.bool,
|
|
164
|
+
buttonProps: PropTypes.object,
|
|
165
|
+
zIndex: PropTypes.number,
|
|
166
|
+
hasArrow: PropTypes.bool,
|
|
167
|
+
isAnimated: PropTypes.bool,
|
|
168
|
+
focusInset: PropTypes.bool,
|
|
169
|
+
isOpen: PropTypes.bool
|
|
170
|
+
};
|
|
171
|
+
ColorSwatchDialog.defaultProps = {
|
|
172
|
+
placement: 'bottom-start',
|
|
173
|
+
isAnimated: true,
|
|
174
|
+
zIndex: 1000,
|
|
175
|
+
hasArrow: false
|
|
176
|
+
};
|
|
177
|
+
ColorSwatchDialog.displayName = 'ColorSwatchDialog';
|
|
178
|
+
|
|
179
|
+
export { ColorSwatchDialog };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
export { ColorPicker } from './elements/ColorPicker/index.js';
|
|
8
|
+
export { ColorPickerDialog } from './elements/ColorPickerDialog/index.js';
|
|
9
|
+
export { ColorSwatch } from './elements/ColorSwatch/index.js';
|
|
10
|
+
export { ColorSwatchDialog } from './elements/ColorSwatchDialog/index.js';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
|
|
9
|
+
var _path;
|
|
10
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
11
|
+
var SvgCheckSmFill = function SvgCheckSmFill(props) {
|
|
12
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
13
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
14
|
+
width: 12,
|
|
15
|
+
height: 12,
|
|
16
|
+
focusable: "false",
|
|
17
|
+
viewBox: "0 0 12 12",
|
|
18
|
+
"aria-hidden": "true"
|
|
19
|
+
}, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
|
|
20
|
+
fill: "none",
|
|
21
|
+
stroke: "currentColor",
|
|
22
|
+
strokeLinecap: "round",
|
|
23
|
+
strokeLinejoin: "round",
|
|
24
|
+
strokeWidth: 2,
|
|
25
|
+
d: "M3 6l2 2 4-4"
|
|
26
|
+
})));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { SvgCheckSmFill as default };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
|
|
9
|
+
var _path;
|
|
10
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
11
|
+
var SvgChevronDownStroke = function SvgChevronDownStroke(props) {
|
|
12
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
13
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
14
|
+
width: 16,
|
|
15
|
+
height: 16,
|
|
16
|
+
focusable: "false",
|
|
17
|
+
viewBox: "0 0 16 16",
|
|
18
|
+
"aria-hidden": "true"
|
|
19
|
+
}, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
|
|
20
|
+
fill: "currentColor",
|
|
21
|
+
d: "M12.688 5.61a.5.5 0 01.69.718l-.066.062-5 4a.5.5 0 01-.542.054l-.082-.054-5-4a.5.5 0 01.55-.83l.074.05L8 9.359l4.688-3.75z"
|
|
22
|
+
})));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { SvgChevronDownStroke as default };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import styled from 'styled-components';
|
|
8
|
+
import { DEFAULT_THEME, getCheckeredBackground } from '@zendeskgarden/react-theming';
|
|
9
|
+
import { StyledRange, getTrackMargin, getTrackHeight } from '../common/StyledRange.js';
|
|
10
|
+
|
|
11
|
+
const COMPONENT_ID = 'colorpickers.colorpicker_alpha';
|
|
12
|
+
const background = props => {
|
|
13
|
+
const direction = `to ${props.theme.rtl ? 'left' : 'right'}`;
|
|
14
|
+
const fromColor = `rgba(${props.$red}, ${props.$green}, ${props.$blue}, 0)`;
|
|
15
|
+
const toColor = `rgb(${props.$red}, ${props.$green}, ${props.$blue})`;
|
|
16
|
+
const positionY = getTrackMargin(props);
|
|
17
|
+
const height = getTrackHeight(props);
|
|
18
|
+
const overlay = `linear-gradient(${direction}, ${fromColor}, ${toColor}) 0 ${positionY}px / 100% ${height}px no-repeat`;
|
|
19
|
+
return getCheckeredBackground({
|
|
20
|
+
theme: props.theme,
|
|
21
|
+
size: height,
|
|
22
|
+
positionY,
|
|
23
|
+
repeat: 'repeat-x',
|
|
24
|
+
overlay
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const StyledAlphaRange = styled(StyledRange).attrs(props => ({
|
|
28
|
+
style: {
|
|
29
|
+
backgroundSize: 'auto',
|
|
30
|
+
background: background(props)
|
|
31
|
+
},
|
|
32
|
+
'data-garden-id': COMPONENT_ID,
|
|
33
|
+
'data-garden-version': '9.0.0-next.21'
|
|
34
|
+
})).withConfig({
|
|
35
|
+
displayName: "StyledAlphaRange",
|
|
36
|
+
componentId: "sc-1f6hp2j-0"
|
|
37
|
+
})([""]);
|
|
38
|
+
StyledAlphaRange.defaultProps = {
|
|
39
|
+
theme: DEFAULT_THEME
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export { StyledAlphaRange };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import styled from 'styled-components';
|
|
8
|
+
import { retrieveComponentStyles, DEFAULT_THEME } from '@zendeskgarden/react-theming';
|
|
9
|
+
|
|
10
|
+
const COMPONENT_ID = 'colorpickers.colorpicker';
|
|
11
|
+
const getColorPickerWidth = props => {
|
|
12
|
+
return props.$isOpaque ? 268 : 312;
|
|
13
|
+
};
|
|
14
|
+
const StyledColorPicker = styled.div.attrs({
|
|
15
|
+
'data-garden-id': COMPONENT_ID,
|
|
16
|
+
'data-garden-version': '9.0.0-next.21'
|
|
17
|
+
}).withConfig({
|
|
18
|
+
displayName: "StyledColorPicker",
|
|
19
|
+
componentId: "sc-gspq4q-0"
|
|
20
|
+
})(["width:", "px;min-width:", "px;", ";"], getColorPickerWidth, getColorPickerWidth, props => retrieveComponentStyles(COMPONENT_ID, props));
|
|
21
|
+
StyledColorPicker.defaultProps = {
|
|
22
|
+
theme: DEFAULT_THEME
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { StyledColorPicker, getColorPickerWidth };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import styled from 'styled-components';
|
|
8
|
+
import { rgba, hsl } from 'polished';
|
|
9
|
+
import { retrieveComponentStyles, DEFAULT_THEME } from '@zendeskgarden/react-theming';
|
|
10
|
+
|
|
11
|
+
const COMPONENT_ID = 'colorpickers.colorpicker_colorwell';
|
|
12
|
+
const background = props => {
|
|
13
|
+
const blackAlpha = rgba(props.theme.palette.black, 0.9);
|
|
14
|
+
const black = `linear-gradient(0deg, ${props.theme.palette.black}, ${blackAlpha} 1%, transparent 99%)`;
|
|
15
|
+
const whiteAngle = `${props.theme.rtl ? -90 : 90}deg`;
|
|
16
|
+
const white = `linear-gradient(${whiteAngle}, ${props.theme.palette.white} 1%, transparent)`;
|
|
17
|
+
const colorValue = hsl(props.$hue, 1, 0.5);
|
|
18
|
+
const color = `linear-gradient(${colorValue}, ${colorValue})`;
|
|
19
|
+
return `${black}, ${white}, ${color}`;
|
|
20
|
+
};
|
|
21
|
+
const StyledColorWell = styled.div.attrs(props => ({
|
|
22
|
+
'data-garden-id': COMPONENT_ID,
|
|
23
|
+
'data-garden-version': '9.0.0-next.21',
|
|
24
|
+
'data-test-id': 'colorwell',
|
|
25
|
+
style: {
|
|
26
|
+
background: background(props)
|
|
27
|
+
}
|
|
28
|
+
})).withConfig({
|
|
29
|
+
displayName: "StyledColorWell",
|
|
30
|
+
componentId: "sc-1gg9z8m-0"
|
|
31
|
+
})(["position:relative;margin-bottom:", "px;cursor:pointer;height:208px;overflow:hidden;", ";"], props => props.theme.space.base * 2, props => retrieveComponentStyles(COMPONENT_ID, props));
|
|
32
|
+
StyledColorWell.defaultProps = {
|
|
33
|
+
theme: DEFAULT_THEME
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { StyledColorWell };
|