@progress/kendo-react-inputs 13.4.0-develop.4 → 14.0.0-develop.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.
@@ -5,200 +5,226 @@
5
5
  * Licensed under commercial license. See LICENSE.md in the package root for more information
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
- import * as i from "react";
9
- import s from "prop-types";
10
- import { ColorPaletteService as w } from "./utils/color-palette.service.mjs";
11
- import { withIdHOC as y, createPropsContext as E, withPropsContext as k, KEYS as l, getTabIndex as R, classNames as f, kendoThemeMaps as F, dispatchEvent as N } from "@progress/kendo-react-common";
12
- import { PALETTEPRESETS as z } from "./models/palette-presets.mjs";
13
- import { isPresent as T } from "./utils/misc.mjs";
14
- import { parseColor as P } from "./utils/color-parser.mjs";
15
- const I = 24, C = 10, D = "office", a = class a extends i.Component {
16
- constructor(t) {
17
- super(t), this.wrapperRef = i.createRef(), this.paletteService = null, this.focus = () => {
18
- this.wrapperRef && this.wrapperRef.current && this.wrapperRef.current.focus();
19
- }, this.onKeyDown = (e) => {
20
- switch (e.key) {
21
- case l.down:
22
- this.handleCellNavigation(0, 1);
8
+ import * as R from "react";
9
+ import { useRef as z, useMemo as O, useState as U, useEffect as re, useCallback as p, useImperativeHandle as V } from "react";
10
+ import l from "prop-types";
11
+ import { ColorPaletteService as se } from "./utils/color-palette.service.mjs";
12
+ import { withIdHOC as le, createPropsContext as ne, usePropsContext as ae, dispatchEvent as M, classNames as H, getTabIndex as ce } from "@progress/kendo-react-common";
13
+ import { PALETTEPRESETS as ie } from "./models/palette-presets.mjs";
14
+ import { parseColor as $ } from "./utils/color-parser.mjs";
15
+ const ue = 24, de = 10, fe = "office", F = {
16
+ palette: fe,
17
+ columns: de,
18
+ tileSize: ue
19
+ }, Ce = ne(), we = (m) => {
20
+ if (Array.isArray(m))
21
+ return m;
22
+ if (typeof m == "string") {
23
+ const P = ie[m];
24
+ if (P)
25
+ return P.colors;
26
+ }
27
+ return [];
28
+ }, v = R.forwardRef((m, P) => {
29
+ const K = ae(Ce, m), {
30
+ palette: I = F.palette,
31
+ columns: S = F.columns,
32
+ tileSize: c = F.tileSize,
33
+ value: y,
34
+ defaultValue: j,
35
+ disabled: i = !1,
36
+ tabIndex: q,
37
+ onChange: g,
38
+ onFocus: D,
39
+ className: W,
40
+ size: L,
41
+ id: Z,
42
+ ariaLabelledBy: G,
43
+ ariaDescribedBy: J
44
+ } = K, k = z(null), Q = z({
45
+ focus: () => {
46
+ var o;
47
+ (o = k.current) == null || o.focus();
48
+ },
49
+ wrapperRef: k
50
+ }), A = S != null ? S : F.columns, f = O(() => we(I), [I]), t = O(() => {
51
+ const o = new se();
52
+ return o.setColorMatrix(f, A), o;
53
+ }, [f, A]), [C, T] = U(() => y !== void 0 ? y : j || ""), [x, b] = U(""), h = y !== void 0;
54
+ re(() => {
55
+ h && T(y);
56
+ }, [y, h]);
57
+ const X = p(
58
+ (o) => {
59
+ if (i || f.length === 0)
60
+ return;
61
+ const u = C || f[0];
62
+ b(u), D && D(o);
63
+ },
64
+ [i, f, C, D]
65
+ ), Y = p(() => {
66
+ b("");
67
+ }, []), ee = p(
68
+ (o) => {
69
+ if (i)
70
+ return;
71
+ const { key: u } = o, r = () => x || C || f[0], w = (s, e) => s < 0 ? e : s > e ? 0 : s;
72
+ switch (u) {
73
+ case "ArrowRight":
74
+ o.preventDefault();
75
+ {
76
+ const s = r(), e = t.getCellCoordsFor(s);
77
+ if (e && t.colorRows[e.row]) {
78
+ const d = t.colorRows[e.row].length - 1, n = w(e.col + 1, d), a = t.colorRows[e.row][n];
79
+ a && b(a);
80
+ }
81
+ }
23
82
  break;
24
- case l.up:
25
- this.handleCellNavigation(0, -1);
83
+ case "ArrowLeft":
84
+ o.preventDefault();
85
+ {
86
+ const s = r(), e = t.getCellCoordsFor(s);
87
+ if (e && t.colorRows[e.row]) {
88
+ const d = t.colorRows[e.row].length - 1, n = w(e.col - 1, d), a = t.colorRows[e.row][n];
89
+ a && b(a);
90
+ }
91
+ }
26
92
  break;
27
- case l.right:
28
- this.handleCellNavigation(1, 0);
93
+ case "ArrowDown":
94
+ o.preventDefault();
95
+ {
96
+ const s = r(), e = t.getCellCoordsFor(s);
97
+ if (e) {
98
+ const d = t.colorRows.length - 1, n = w(e.row + 1, d), a = Math.min(e.col, t.colorRows[n].length - 1), E = t.colorRows[n][a];
99
+ E && b(E);
100
+ }
101
+ }
29
102
  break;
30
- case l.left:
31
- this.handleCellNavigation(-1, 0);
103
+ case "ArrowUp":
104
+ o.preventDefault();
105
+ {
106
+ const s = r(), e = t.getCellCoordsFor(s);
107
+ if (e) {
108
+ const d = t.colorRows.length - 1, n = w(e.row - 1, d), a = Math.min(e.col, t.colorRows[n].length - 1), E = t.colorRows[n][a];
109
+ E && b(E);
110
+ }
111
+ }
32
112
  break;
33
- case l.enter:
34
- this.handleEnter(e);
113
+ case "Enter":
114
+ o.preventDefault();
115
+ {
116
+ const s = r();
117
+ if (s && (h || T(s), g)) {
118
+ const e = $(s, "rgba");
119
+ M(g, o, null, {
120
+ value: s,
121
+ rgbaValue: e || ""
122
+ });
123
+ }
124
+ }
35
125
  break;
36
- default:
37
- return;
38
126
  }
39
- e.preventDefault();
40
- }, this.onColorClick = (e, o) => {
41
- this.isUncontrolled ? this.setState({ selectedColor: e, focusedColor: e }) : this.setState({ focusedColor: e }), this.dispatchChangeEvent(e, o);
42
- }, this.onFocus = (e) => {
43
- this.paletteService && (this.setState({ focusedColor: this.state.selectedColor || this.paletteService.colorRows[0][0] }), this.props.onFocus && this.props.onFocus.call(void 0, e));
44
- }, this.onBlur = () => {
45
- this.setState({ focusedColor: void 0 });
46
- }, this.state = {
47
- selectedColor: this.props.value !== void 0 ? this.props.value : this.props.defaultValue ? this.props.defaultValue : void 0,
48
- isFirstRender: !0
49
- };
50
- }
51
- get guid() {
52
- return this.props.id;
53
- }
54
- /**
55
- * @hidden
56
- */
57
- render() {
58
- const t = this.getPaletteInfo(), e = this.paletteService = new w();
59
- e.setColorMatrix(t.colors, t.columns);
60
- const o = e.getCellCoordsFor(this.state.selectedColor), r = e.getCellCoordsFor(this.state.focusedColor);
61
- return t.colors.length ? /* @__PURE__ */ i.createElement(
62
- "div",
63
- {
64
- id: this.props.id,
65
- role: "grid",
66
- className: f(
67
- "k-colorpalette",
68
- {
69
- [`k-colorpalette-${F.sizeMap[this.props.size] || this.props.size}`]: this.props.size,
70
- "k-disabled": this.props.disabled
71
- },
72
- this.props.className
73
- ),
74
- onFocus: this.onFocus,
75
- onBlur: this.onBlur,
76
- onKeyDown: this.onKeyDown,
77
- "aria-disabled": this.props.ariaDisabled || (this.props.disabled ? "true" : void 0),
78
- "aria-labelledby": this.props.ariaLabelledBy,
79
- "aria-describedby": this.props.ariaDescribedBy,
80
- tabIndex: R(this.props.tabIndex, this.props.disabled),
81
- ref: this.wrapperRef
82
- },
83
- /* @__PURE__ */ i.createElement("table", { className: "k-colorpalette-table", role: "presentation" }, /* @__PURE__ */ i.createElement("tbody", { role: "rowgroup" }, this.renderRows(e.colorRows, o, r)))
84
- ) : "";
85
- }
86
- /**
87
- * @hidden
88
- */
89
- static getDerivedStateFromProps(t, e) {
90
- if (!e.isFirstRender && t.value !== void 0) {
91
- if (t.value === "" && e.selectedColor !== void 0)
92
- return { selectedColor: void 0 };
93
- if (t.value !== "" && t.value !== e.selectedColor)
94
- return { selectedColor: t.value };
95
- } else if (e.isFirstRender)
96
- return { isFirstRender: !1 };
97
- return null;
98
- }
99
- handleCellNavigation(t, e) {
100
- if (this.paletteService)
101
- if (this.focusedColorCooridanates) {
102
- const o = this.paletteService.getNextCell(
103
- this.focusedColorCooridanates,
104
- t,
105
- e
106
- );
107
- this.setState({ focusedColor: this.paletteService.getColorAt(o) });
108
- } else
109
- this.setState({ focusedColor: this.paletteService.colorRows[0][0] });
110
- }
111
- handleEnter(t) {
112
- this.isUncontrolled && this.setState({ selectedColor: this.state.focusedColor }), this.dispatchChangeEvent(this.state.focusedColor, t);
113
- }
114
- dispatchChangeEvent(t, e) {
115
- N(this.props.onChange, e, this, { value: t, rgbaValue: P(t, "rgba") });
116
- }
117
- get focusedColorCooridanates() {
118
- return this.state.focusedColor && this.paletteService ? this.paletteService.getCellCoordsFor(this.state.focusedColor) : void 0;
119
- }
120
- get isUncontrolled() {
121
- return this.props.value === void 0;
122
- }
123
- getPaletteInfo() {
124
- if (typeof this.props.palette == "string") {
125
- const t = z[this.props.palette];
126
- return T(t) ? {
127
- colors: t.colors,
128
- columns: this.props.columns || t.columns || C
129
- } : { colors: [], columns: 0 };
130
- }
131
- return { colors: this.props.palette || [], columns: this.props.columns || C };
132
- }
133
- renderRows(t, e, o) {
134
- return t.map((r, n) => /* @__PURE__ */ i.createElement("tr", { role: "row", key: n }, this.renderColumns(r, n, e, o)));
135
- }
136
- renderColumns(t, e, o, r) {
137
- const n = o !== void 0 && o.row === e, m = o && o.col, g = r !== void 0 && r.row === e, v = r && r.col;
138
- return t.map((p, c) => {
139
- const h = n && m === c, b = f("k-colorpalette-tile", {
140
- "k-selected": h,
141
- "k-focus": g && v === c
142
- });
143
- let u = {
144
- width: this.props.tileSize,
145
- height: this.props.tileSize
127
+ },
128
+ [i, x, C, f, t, h, g]
129
+ ), N = p(
130
+ (o, u) => {
131
+ if (i)
132
+ return;
133
+ const r = o;
134
+ if (h || T(r), g) {
135
+ const w = $(r, "rgba");
136
+ M(g, u, null, {
137
+ value: r,
138
+ rgbaValue: w || ""
139
+ });
140
+ }
141
+ },
142
+ [i, g, h]
143
+ ), B = p(
144
+ (o, u) => o.map((r, w) => {
145
+ const s = C && r.toLowerCase() === C.toLowerCase(), e = x && r.toLowerCase() === x.toLowerCase(), d = H("k-colorpalette-tile", {
146
+ "k-selected": s,
147
+ "k-focus": e
148
+ }), n = {
149
+ backgroundColor: r
146
150
  };
147
- return typeof this.props.tileSize == "object" && (u = {
148
- width: this.props.tileSize.width,
149
- height: this.props.tileSize.height
150
- }), /* @__PURE__ */ i.createElement(
151
+ return typeof c == "number" ? (n.width = `${c}px`, n.height = `${c}px`) : c && typeof c == "object" && ("width" in c && (n.width = `${c.width}px`), "height" in c && (n.height = `${c.height}px`)), /* @__PURE__ */ R.createElement(
151
152
  "td",
152
153
  {
154
+ key: r,
153
155
  role: "gridcell",
154
- className: b,
155
- "aria-label": p,
156
- "aria-selected": h ? !0 : this.props.disabled ? void 0 : !1,
157
- style: { backgroundColor: p, ...u },
158
- onClick: (S) => this.onColorClick(p, S),
159
- id: this.createCellId({ row: e, col: c }),
160
- key: c
156
+ className: d,
157
+ style: n,
158
+ "aria-label": r,
159
+ "aria-selected": s ? "true" : "false",
160
+ onClick: (a) => N(r, a)
161
161
  }
162
162
  );
163
- });
164
- }
165
- createCellId(t) {
166
- return `${this.guid}_${t.row}_${t.col}`;
167
- }
168
- };
169
- a.displayName = "ColorPalette", a.propTypes = {
170
- palette: s.oneOfType([s.arrayOf(s.string.isRequired), s.string]),
171
- columns: s.number,
172
- tileSize: s.any,
173
- defaultValue: s.string,
174
- value: s.string,
175
- disabled: s.bool,
176
- tabIndex: s.number,
177
- onChange: s.func,
178
- onFocus: s.func,
179
- id: s.string,
180
- ariaLabelledBy: s.string,
181
- ariaDescribedBy: s.string,
182
- className: s.string,
183
- size: s.oneOf(["small", "medium", "large", null])
184
- }, a.defaultProps = {
185
- palette: D,
186
- tileSize: I,
187
- size: void 0
163
+ }),
164
+ [C, x, c, N]
165
+ ), oe = p(() => t.colorRows.map((u, r) => /* @__PURE__ */ R.createElement("tr", { key: u[0] || r, role: "row" }, B(u, r))), [t, B]), _ = p(
166
+ () => ({
167
+ focus: () => {
168
+ var o;
169
+ (o = k.current) == null || o.focus();
170
+ },
171
+ wrapperRef: k
172
+ }),
173
+ []
174
+ );
175
+ V(Q, _), V(P, _);
176
+ const te = H("k-colorpalette", W, {
177
+ "k-disabled": i,
178
+ "k-colorpalette-sm": L === "small",
179
+ "k-colorpalette-md": L === "medium",
180
+ "k-colorpalette-lg": L === "large"
181
+ });
182
+ return /* @__PURE__ */ R.createElement(
183
+ "div",
184
+ {
185
+ ref: k,
186
+ role: "grid",
187
+ className: te,
188
+ tabIndex: ce(q, i),
189
+ id: Z,
190
+ "aria-labelledby": G,
191
+ "aria-describedby": J,
192
+ "aria-disabled": i ? "true" : void 0,
193
+ onFocus: X,
194
+ onBlur: Y,
195
+ onKeyDown: ee
196
+ },
197
+ /* @__PURE__ */ R.createElement("table", { className: "k-colorpalette-table", role: "presentation" }, /* @__PURE__ */ R.createElement("tbody", null, oe()))
198
+ );
199
+ });
200
+ v.displayName = "ColorPalette";
201
+ v.propTypes = {
202
+ palette: l.oneOfType([l.arrayOf(l.string.isRequired), l.string]),
203
+ columns: l.number,
204
+ tileSize: l.any,
205
+ defaultValue: l.string,
206
+ value: l.string,
207
+ disabled: l.bool,
208
+ tabIndex: l.number,
209
+ onChange: l.func,
210
+ onFocus: l.func,
211
+ id: l.string,
212
+ ariaLabelledBy: l.string,
213
+ ariaDescribedBy: l.string,
214
+ className: l.string,
215
+ size: l.oneOf(["small", "medium", "large"])
188
216
  };
189
- let d = a;
190
- const L = E(), U = y(
191
- k(
192
- L,
193
- d
194
- )
217
+ const pe = le(
218
+ v
195
219
  );
196
- U.displayName = "KendoReactColorPalette";
220
+ pe.displayName = "KendoReactColorPalette";
221
+ const ke = v;
197
222
  export {
198
- U as ColorPalette,
199
- L as ColorPalettePropsContext,
200
- d as ColorPaletteWithoutContext,
201
- C as DEFAULT_COLUMNS_COUNT,
202
- D as DEFAULT_PRESET,
203
- I as DEFAULT_TILE_SIZE
223
+ pe as ColorPalette,
224
+ Ce as ColorPalettePropsContext,
225
+ ke as ColorPaletteWithoutContext,
226
+ de as DEFAULT_COLUMNS_COUNT,
227
+ fe as DEFAULT_PRESET,
228
+ ue as DEFAULT_TILE_SIZE,
229
+ F as defaultColorPaletteProps
204
230
  };
@@ -6,11 +6,11 @@
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
8
  import { BaseEvent } from '@progress/kendo-react-common';
9
- import { ColorPalette } from '../ColorPalette.js';
9
+ import { ColorPaletteHandle } from './ColorPaletteHandle.js';
10
10
  /**
11
11
  * The arguments for the `onChange` ColorPalette event.
12
12
  */
13
- export interface ColorPaletteChangeEvent extends BaseEvent<ColorPalette> {
13
+ export interface ColorPaletteChangeEvent extends BaseEvent<ColorPaletteHandle> {
14
14
  /**
15
15
  * The current value of the ColorPalette.
16
16
  */
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @license
3
+ *-------------------------------------------------------------------------------------------
4
+ * Copyright © 2026 Progress Software Corporation. All rights reserved.
5
+ * Licensed under commercial license. See LICENSE.md in the package root for more information
6
+ *-------------------------------------------------------------------------------------------
7
+ */
8
+ import * as React from 'react';
9
+ /**
10
+ * Represents the imperative handle exposed by the ColorPalette component through ref.
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * const paletteRef = useRef<ColorPaletteHandle>(null);
15
+ *
16
+ * // Focus the palette programmatically
17
+ * paletteRef.current?.focus();
18
+ *
19
+ * // Access the wrapper element
20
+ * const width = paletteRef.current?.wrapperRef.current?.offsetWidth;
21
+ *
22
+ * <ColorPalette ref={paletteRef} palette="basic" />
23
+ * ```
24
+ */
25
+ export interface ColorPaletteHandle {
26
+ /**
27
+ * Programmatically focuses the ColorPalette component.
28
+ *
29
+ * When called:
30
+ * - The root div element receives DOM focus
31
+ * - The first color tile (or previously selected tile) is focused for keyboard navigation
32
+ * - The component's `onFocus` callback is triggered
33
+ */
34
+ focus: () => void;
35
+ /**
36
+ * A React ref to the root wrapper element of the ColorPalette.
37
+ *
38
+ * This ref can be used to access the underlying DOM element for scenarios such as:
39
+ * - Measuring the component dimensions
40
+ * - Integrating with non-React libraries
41
+ * - Programmatic scrolling or focus management
42
+ *
43
+ * The ref is populated after the component mounts and will be `null` before that.
44
+ */
45
+ wrapperRef: React.RefObject<HTMLDivElement | null>;
46
+ }