@progress/kendo-react-inputs 5.13.0-dev.202304201410 → 5.13.0-dev.202304251043

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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FlatColorPicker = void 0;
4
+ /* eslint-disable max-len */
4
5
  var React = require("react");
5
6
  var PropTypes = require("prop-types");
6
7
  var kendo_react_common_1 = require("@progress/kendo-react-common");
@@ -10,19 +11,33 @@ var main_1 = require("../main");
10
11
  var package_metadata_1 = require("../package-metadata");
11
12
  var kendo_react_intl_1 = require("@progress/kendo-react-intl");
12
13
  var messages_1 = require("../messages");
14
+ var defaultColor = 'rgba(255, 255, 255, 1)';
13
15
  ;
14
16
  ;
15
17
  /**
16
- * Represents the FlatColorPicker component.
18
+ * Represents the [KendoReact FlatColorPicker component]({% slug overview_flatcolorpicker %}).
19
+ * Accepts properties of type [FlatColorPickerProps]({% slug api_inputs_flatcolorpickerprops %}). Obtaining the [FlatColorPickerHandle]({% slug api_inputs_flatcolorpickerhandle %}).
20
+ *
21
+ * @example
22
+ * ```jsx
23
+ * class App extends React.Component {
24
+ * render() {
25
+ * return <FlatColorPicker />;
26
+ * }
27
+ * }
28
+ * ReactDOM.render(<App />, document.querySelector('my-app'));
29
+ * ```
17
30
  */
18
31
  exports.FlatColorPicker = React.forwardRef(function (props, ref) {
19
32
  (0, kendo_react_common_1.validatePackage)(package_metadata_1.packageMetadata);
20
33
  var target = React.useRef(null);
21
34
  var flatColorPickerRef = React.useRef(null);
22
35
  var colorGradientRef = React.useRef(null);
23
- var _a = React.useState((props.view || 'ColorGradient') === 'ColorGradient'), colorGradientView = _a[0], setColorGradientView = _a[1];
24
- var _b = React.useState('rgba(255, 255, 255, 1)'), colorValue = _b[0], setColorValue = _b[1];
25
- var _c = React.useState('rgba(255, 255, 255, 1)'), prevColor = _c[0], setPrevColor = _c[1];
36
+ var _a = props.defaultValue, defaultValue = _a === void 0 ? defaultColor : _a, _b = props.showButtons, showButtons = _b === void 0 ? true : _b, _c = props.showPreview, showPreview = _c === void 0 ? true : _c, _d = props.showClearButton, showClearButton = _d === void 0 ? true : _d;
37
+ var _e = React.useState((props.view || 'ColorGradient') === 'ColorGradient'), colorGradientView = _e[0], setColorGradientView = _e[1];
38
+ var _f = React.useState(props.value || defaultValue), colorValue = _f[0], setColorValue = _f[1];
39
+ var _g = React.useState(props.value || defaultValue), prevColor = _g[0], setPrevColor = _g[1];
40
+ var value = props.value !== undefined ? props.value : prevColor;
26
41
  var localizationService = (0, kendo_react_intl_1.useLocalization)();
27
42
  var focus = React.useCallback(function () {
28
43
  if (target.current) {
@@ -32,8 +47,9 @@ exports.FlatColorPicker = React.forwardRef(function (props, ref) {
32
47
  React.useImperativeHandle(target, function () { return ({
33
48
  element: flatColorPickerRef.current,
34
49
  focus: focus,
35
- props: props
36
- }); });
50
+ props: props,
51
+ value: value
52
+ }); }, [value, focus, props]);
37
53
  React.useImperativeHandle(ref, function () { return target.current; });
38
54
  var handleViewChange = React.useCallback(function (viewType) {
39
55
  if ((viewType === 'ColorGradient' && !colorGradientView) || (viewType === 'ColorPalette' && colorGradientView)) {
@@ -41,28 +57,51 @@ exports.FlatColorPicker = React.forwardRef(function (props, ref) {
41
57
  }
42
58
  }, [colorGradientView]);
43
59
  var handleResetColor = React.useCallback(function () {
44
- setColorValue('rgba(255, 255, 255, 1)');
45
- }, []);
60
+ setColorValue(defaultValue);
61
+ }, [defaultValue]);
46
62
  var handleColorChange = React.useCallback(function (event) {
47
63
  setColorValue(event.value);
48
64
  }, []);
49
- var handleApplyBtnClick = React.useCallback(function () {
65
+ var handleApplyBtnClick = React.useCallback(function (event) {
50
66
  setPrevColor(colorValue);
51
- }, [colorValue]);
67
+ if (props.onChange) {
68
+ var ev = {
69
+ value: colorValue,
70
+ nativeEvent: event.nativeEvent,
71
+ syntheticEvent: event
72
+ };
73
+ props.onChange.call(undefined, ev);
74
+ }
75
+ }, [colorValue, props.onChange]);
52
76
  var handleCancelBtnClick = React.useCallback(function () {
53
- setPrevColor('rgba(255, 255, 255, 1)');
77
+ setPrevColor(defaultColor);
54
78
  }, []);
55
79
  var handlePrevColorClick = React.useCallback(function () {
56
80
  setColorValue(prevColor);
57
81
  }, [prevColor]);
58
- var handleFocus = React.useCallback(function () {
59
- if (flatColorPickerRef.current) {
82
+ var handleFocus = React.useCallback(function (event) {
83
+ if (flatColorPickerRef.current && event.nativeEvent.target instanceof HTMLInputElement === false) {
60
84
  flatColorPickerRef.current.focus();
61
85
  }
62
86
  }, [flatColorPickerRef]);
63
- var handleFlatColorPickerBlur = React.useCallback(function () {
64
- setPrevColor(colorValue);
65
- }, [colorValue]);
87
+ var handleFlatColorPickerBlur = React.useCallback(function (event) {
88
+ var _a;
89
+ var blurred = (!event.relatedTarget || !((_a = flatColorPickerRef.current) === null || _a === void 0 ? void 0 : _a.contains(event.relatedTarget)));
90
+ if (!blurred) {
91
+ return;
92
+ }
93
+ if (!showButtons) {
94
+ setPrevColor(colorValue);
95
+ }
96
+ if (!showButtons && props.onChange) {
97
+ var ev = {
98
+ value: colorValue,
99
+ nativeEvent: event.nativeEvent,
100
+ syntheticEvent: event
101
+ };
102
+ props.onChange.call(undefined, ev);
103
+ }
104
+ }, [colorValue, showButtons, props.onChange]);
66
105
  return (React.createElement("div", { id: props.id, role: 'textbox', "aria-label": props.ariaLabel, "aria-labelledby": props.ariaLabelledBy, "aria-disabled": props.disabled ? 'true' : undefined, style: props.style, ref: flatColorPickerRef, tabIndex: (0, kendo_react_common_1.getTabIndex)(props.tabIndex, props.disabled), className: (0, kendo_react_common_1.classNames)('k-flatcolorpicker k-coloreditor', {
67
106
  'k-disabled': props.disabled
68
107
  }, props.className), onBlur: handleFlatColorPickerBlur },
@@ -75,35 +114,38 @@ exports.FlatColorPicker = React.forwardRef(function (props, ref) {
75
114
  React.createElement(kendo_react_buttons_1.Button, { type: "button", "aria-label": localizationService.toLanguageString(messages_1.flatColorPickerColorPaletteBtn, messages_1.messages[messages_1.flatColorPickerColorPaletteBtn]), togglable: true, fillMode: 'flat', selected: !colorGradientView, onClick: function () { return handleViewChange('ColorPalette'); }, icon: "palette", svgIcon: kendo_svg_icons_1.paletteIcon }))),
76
115
  React.createElement("div", { className: "k-spacer" }),
77
116
  React.createElement("div", { className: "k-coloreditor-header-actions k-hstack" },
78
- (props.showClearButton && defaultProps.showClearButton) &&
117
+ showClearButton &&
79
118
  React.createElement(kendo_react_buttons_1.Button, { type: "button", fillMode: 'flat', onClick: handleResetColor, "aria-label": localizationService.toLanguageString(messages_1.flatColorPickerClearBtn, messages_1.messages[messages_1.flatColorPickerClearBtn]), icon: "droplet-slash", svgIcon: kendo_svg_icons_1.dropletSlashIcon }),
80
- (props.showPreview && defaultProps.showPreview) &&
119
+ showPreview &&
81
120
  React.createElement("div", { className: "k-coloreditor-preview k-vstack" },
82
121
  React.createElement("span", { className: "k-coloreditor-preview-color k-color-preview", style: { background: colorValue } }),
83
122
  React.createElement("span", { className: "k-coloreditor-current-color k-color-preview", style: { background: prevColor }, onClick: handlePrevColorClick })))),
84
123
  React.createElement("div", { className: "k-coloreditor-views k-vstack" }, colorGradientView
85
- ? React.createElement(main_1.ColorGradient, { ref: colorGradientRef, role: "none", tabIndex: -1, ariaLabel: undefined, value: colorValue, onChange: handleColorChange, onFocus: handleFocus })
124
+ ? React.createElement(main_1.ColorGradient, { ref: colorGradientRef, role: "none", tabIndex: -1, ariaLabel: undefined, value: colorValue, onChange: handleColorChange, onFocus: handleFocus, opacity: props.opacity, format: props.format })
86
125
  : React.createElement(main_1.ColorPalette, { ariaDisabled: true, ariaLabelledBy: 'required_label', value: colorValue, onChange: handleColorChange, onFocus: handleFocus })),
87
- (props.showButtons && defaultProps.showButtons) &&
126
+ showButtons &&
88
127
  React.createElement("div", { className: "k-coloreditor-footer k-actions k-actions-end" },
89
128
  React.createElement(kendo_react_buttons_1.Button, { type: "button", className: "k-coloreditor-cancel", onClick: handleCancelBtnClick }, messages_1.messages[messages_1.flatColorPickerCancelBtn]),
90
129
  React.createElement(kendo_react_buttons_1.Button, { type: "button", className: "k-coloreditor-apply k-primary", onClick: handleApplyBtnClick }, messages_1.messages[messages_1.flatColorPickerApplyBtn])))));
91
130
  });
92
131
  var propTypes = {
93
132
  id: PropTypes.string,
133
+ style: PropTypes.any,
134
+ className: PropTypes.string,
94
135
  value: PropTypes.string,
95
- view: PropTypes.string,
96
- header: PropTypes.elementType,
136
+ defaultValue: PropTypes.string,
137
+ onChange: PropTypes.func,
138
+ opacity: PropTypes.bool,
139
+ format: PropTypes.any,
140
+ tabIndex: PropTypes.number,
141
+ ariaLabel: PropTypes.string,
142
+ ariaLabelledBy: PropTypes.string,
143
+ disabled: PropTypes.bool,
144
+ view: PropTypes.any,
145
+ header: PropTypes.any,
97
146
  showClearButton: PropTypes.bool,
98
147
  showPreview: PropTypes.bool,
99
148
  showButtons: PropTypes.bool
100
149
  };
101
- var defaultProps = {
102
- showClearButton: true,
103
- showPreview: true,
104
- showButtons: true
105
- };
106
150
  exports.FlatColorPicker.displayName = 'KendoFlatColorPicker';
107
- // TODO: delete casting when @types/react is updated!
108
151
  exports.FlatColorPicker.propTypes = propTypes;
109
- exports.FlatColorPicker.defaultProps = defaultProps;
@@ -85,4 +85,10 @@ export interface ColorGradientProps {
85
85
  * Represents the text rendered inside the `hsv` drag handle.
86
86
  */
87
87
  ariaValueText?: string;
88
+ /**
89
+ * Sets the default input format in the gradient input editor.
90
+ *
91
+ * @default 'rgb'
92
+ */
93
+ format?: 'rgba' | 'rgb' | 'hex';
88
94
  }
@@ -8,7 +8,7 @@ exports.packageMetadata = {
8
8
  name: '@progress/kendo-react-inputs',
9
9
  productName: 'KendoReact',
10
10
  productCodes: ['KENDOUIREACT', 'KENDOUICOMPLETE'],
11
- publishDate: 1681998620,
11
+ publishDate: 1682418230,
12
12
  version: '',
13
13
  licensingDocsUrl: 'https://www.telerik.com/kendo-react-ui/my-license/?utm_medium=product&utm_source=kendoreact&utm_campaign=kendo-ui-react-purchase-license-keys-warning'
14
14
  };