@xsolla/xui-gradient-picker 0.204.0

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/web/index.d.ts ADDED
@@ -0,0 +1,243 @@
1
+ import React from 'react';
2
+ import { ThemeOverrideProps } from '@xsolla/xui-core';
3
+
4
+ /**
5
+ * Supported gradient geometries.
6
+ *
7
+ * `angular` maps to the CSS `conic-gradient()` function. Some products call
8
+ * this "Conic" — use `typeLabels` to relabel it without changing the value.
9
+ */
10
+ type GradientType = "linear" | "radial" | "angular";
11
+ /**
12
+ * A single colour stop on the gradient track.
13
+ */
14
+ interface GradientStop {
15
+ /**
16
+ * Stable identity for the stop. Used as the React key and as the handle for
17
+ * update / remove operations, so it must survive reordering.
18
+ */
19
+ id: string;
20
+ /**
21
+ * Stop colour as a `#RRGGBB` hex string. Opacity is tracked separately in
22
+ * `opacity` so the hex field stays human-editable.
23
+ */
24
+ color: string;
25
+ /**
26
+ * Position along the track, `0`–`100` (percent).
27
+ */
28
+ position: number;
29
+ /**
30
+ * Stop opacity, `0`–`100` (percent).
31
+ */
32
+ opacity: number;
33
+ }
34
+ /**
35
+ * The full gradient definition rendered by the picker.
36
+ */
37
+ interface GradientValue {
38
+ /**
39
+ * Gradient geometry.
40
+ */
41
+ type: GradientType;
42
+ /**
43
+ * Rotation in degrees. Only meaningful for `linear` and `angular` — a radial
44
+ * gradient has no angle, so the angle field is hidden for it.
45
+ */
46
+ angle: number;
47
+ /**
48
+ * Colour stops. Order is not significant: the component sorts by `position`
49
+ * when serialising, so stops may swap as the user drags them past each other.
50
+ */
51
+ stops: GradientStop[];
52
+ }
53
+ /**
54
+ * Payload emitted on every gradient change.
55
+ */
56
+ interface GradientPickerChangeEvent {
57
+ /**
58
+ * The new gradient definition.
59
+ */
60
+ value: GradientValue;
61
+ /**
62
+ * The same gradient serialised as a CSS-compatible string, ready to drop into
63
+ * a `background` / `background-image` declaration.
64
+ */
65
+ css: string;
66
+ }
67
+ interface GradientPickerProps extends ThemeOverrideProps {
68
+ /**
69
+ * Controlled gradient value. Pair with `onChange`.
70
+ */
71
+ value?: GradientValue;
72
+ /**
73
+ * Initial gradient value for uncontrolled usage.
74
+ */
75
+ defaultValue?: GradientValue;
76
+ /**
77
+ * Called on every interaction — stop drag, colour edit, opacity edit,
78
+ * gradient-type switch, angle change, add / remove stop.
79
+ */
80
+ onChange?: (event: GradientPickerChangeEvent) => void;
81
+ /**
82
+ * Gradient types offered in the type selector, in display order.
83
+ * @default ["linear", "radial", "angular"]
84
+ */
85
+ gradientTypes?: GradientType[];
86
+ /**
87
+ * Overrides for the gradient-type option labels — e.g. `{ angular: "Conic gradient" }`
88
+ * when the product uses the CSS term.
89
+ */
90
+ typeLabels?: Partial<Record<GradientType, string>>;
91
+ /**
92
+ * Smallest number of stops the user may reduce the gradient to. The remove
93
+ * control is disabled once this floor is reached.
94
+ * @default 1
95
+ */
96
+ minStops?: number;
97
+ /**
98
+ * Largest number of stops the user may add. The add control is disabled once
99
+ * this ceiling is reached.
100
+ * @default 5
101
+ */
102
+ maxStops?: number;
103
+ /**
104
+ * Disables every control and blocks track interaction.
105
+ */
106
+ disabled?: boolean;
107
+ /**
108
+ * Accessible label for the gradient-type selector.
109
+ * @default "Gradient type"
110
+ */
111
+ typeAriaLabel?: string;
112
+ /**
113
+ * Accessible label for the angle field.
114
+ * @default "Gradient angle"
115
+ */
116
+ angleAriaLabel?: string;
117
+ /**
118
+ * Heading rendered above the stop list.
119
+ * @default "Stops"
120
+ */
121
+ stopsLabel?: string;
122
+ testID?: string;
123
+ }
124
+
125
+ /**
126
+ * A compound control for defining a CSS gradient.
127
+ *
128
+ * Combines a live preview track carrying draggable stop markers with a per-stop
129
+ * row editor (position, colour, opacity) and an integrated `ColorPicker` for
130
+ * the active stop. Supports linear, radial and angular (CSS `conic`) gradients
131
+ * and 1–5 colour stops.
132
+ *
133
+ * Every interaction updates the preview immediately — there is no confirm step —
134
+ * and the gradient is emitted both as structured data and as a ready-to-apply
135
+ * CSS string.
136
+ *
137
+ * @example
138
+ * ```tsx
139
+ * const [gradient, setGradient] = useState<GradientValue>();
140
+ *
141
+ * <GradientPicker
142
+ * value={gradient}
143
+ * onChange={({ value, css }) => {
144
+ * setGradient(value);
145
+ * setBackground(css); // e.g. "linear-gradient(0deg, #D9D9D9 0%, #22A8C3 100%)"
146
+ * }}
147
+ * />
148
+ * ```
149
+ */
150
+ declare const GradientPicker: React.FC<GradientPickerProps>;
151
+
152
+ interface GradientStopMarkerProps extends ThemeOverrideProps {
153
+ /**
154
+ * The stop this marker represents.
155
+ */
156
+ stop: GradientStop;
157
+ /**
158
+ * 1-based index used to build the accessible name (`"Stop 2 position"`).
159
+ */
160
+ index: number;
161
+ /**
162
+ * Whether this stop is the one currently being edited in the ColorPicker.
163
+ */
164
+ active?: boolean;
165
+ /**
166
+ * Whether the whole picker is disabled.
167
+ */
168
+ disabled?: boolean;
169
+ /**
170
+ * Pointer-down on the marker — the parent owns the drag because it owns the
171
+ * track geometry.
172
+ */
173
+ onDragStart?: (event: React.MouseEvent) => void;
174
+ /**
175
+ * Keyboard interaction on the marker. Handled by the parent so that arrow
176
+ * keys, Home/End, Enter/Space and Delete/Backspace share one implementation.
177
+ */
178
+ onKeyDown?: (event: React.KeyboardEvent) => void;
179
+ }
180
+ /**
181
+ * A single draggable handle on the gradient preview track.
182
+ *
183
+ * Exposed as `role="slider"` over the `0`–`100` position range so the stop can
184
+ * be moved with the keyboard alone, and so its numeric position is announced —
185
+ * the visual gradient must never be the only carrier of that information.
186
+ */
187
+ declare const GradientStopMarker: React.FC<GradientStopMarkerProps>;
188
+
189
+ /**
190
+ * Returns the stops ordered by position without mutating the input array.
191
+ * Ties keep their original relative order, so two stops parked on the same
192
+ * percent do not flicker while one of them is being dragged.
193
+ */
194
+ declare const sortStops: (stops: GradientStop[]) => GradientStop[];
195
+ /**
196
+ * Serialises the gradient to a CSS-compatible string usable as a `background`
197
+ * or `background-image` value.
198
+ */
199
+ declare const toCssGradient: (value: GradientValue) => string;
200
+ /**
201
+ * The gradient rendered inside the horizontal preview track. The track always
202
+ * reads left-to-right regardless of gradient type, so the user can see stop
203
+ * ordering while dragging — the type-specific rendering is what `toCssGradient`
204
+ * produces for the consuming surface.
205
+ */
206
+ declare const toPreviewCssGradient: (value: GradientValue) => string;
207
+ /**
208
+ * Whether the given gradient type exposes an angle control. Radial gradients
209
+ * have no rotation, so the angle field is hidden for them.
210
+ */
211
+ declare const supportsAngle: (value: GradientValue["type"]) => boolean;
212
+ /**
213
+ * Samples the gradient at `position` (`0`–`100`) and returns the interpolated
214
+ * colour + opacity. Used to give a newly added stop the colour the gradient
215
+ * already had at that point, so adding a stop never visibly changes the ramp.
216
+ */
217
+ declare const interpolateColorAt: (stops: GradientStop[], position: number) => {
218
+ color: string;
219
+ opacity: number;
220
+ };
221
+ /**
222
+ * Adds a stop at `position`, taking its colour from the gradient at that point.
223
+ * Returns the original array untouched when `maxStops` is already reached, so
224
+ * callers can compare by reference to detect a no-op.
225
+ */
226
+ declare const addStopAt: (stops: GradientStop[], position: number, maxStops: number) => GradientStop[];
227
+ /**
228
+ * Removes a stop by id. Returns the original array when the removal would drop
229
+ * below `minStops`, or when the id is unknown.
230
+ */
231
+ declare const removeStop: (stops: GradientStop[], id: string, minStops: number) => GradientStop[];
232
+ /**
233
+ * Applies a partial update to a single stop, clamping position and opacity and
234
+ * normalising the hex colour.
235
+ */
236
+ declare const updateStop: (stops: GradientStop[], id: string, patch: Partial<Omit<GradientStop, "id">>) => GradientStop[];
237
+ /**
238
+ * The default gradient — the two-stop `#D9D9D9 → #22A8C3` linear ramp from the
239
+ * Figma component.
240
+ */
241
+ declare const DEFAULT_GRADIENT: GradientValue;
242
+
243
+ export { DEFAULT_GRADIENT, GradientPicker, type GradientPickerChangeEvent, type GradientPickerProps, type GradientStop, GradientStopMarker, type GradientStopMarkerProps, type GradientType, type GradientValue, addStopAt, interpolateColorAt, removeStop, sortStops, supportsAngle, toCssGradient, toPreviewCssGradient, updateStop };