@xsolla/xui-input-color 0.184.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/README.md ADDED
@@ -0,0 +1,130 @@
1
+ # Input Color
2
+
3
+ A compact inline control for previewing and editing a colour value — a colour swatch alongside an editable hex or RGB field, with optional transparency (alpha). Use it on its own, or as the inline trigger that opens a `ColorPicker`. Works on web and React Native via `XUIProvider` themed contexts.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @xsolla/xui-input-color
9
+ ```
10
+
11
+ ## Imports
12
+
13
+ ```tsx
14
+ import { InputColor } from '@xsolla/xui-input-color';
15
+ import type {
16
+ InputColorProps,
17
+ InputColorType,
18
+ InputColorSize,
19
+ } from '@xsolla/xui-input-color';
20
+ ```
21
+
22
+ ## Quick start
23
+
24
+ ```tsx
25
+ const [color, setColor] = useState('#22A8C3');
26
+
27
+ <InputColor value={color} onChange={setColor} />;
28
+ ```
29
+
30
+ ## API Reference
31
+
32
+ ### `<InputColor>`
33
+
34
+ | Prop | Type | Default | Description |
35
+ | --- | --- | --- | --- |
36
+ | `value` | `string` | — | Controlled colour as a hex string (e.g. `#22A8C3`; `#RRGGBBAA` when `transparency` is on). |
37
+ | `defaultValue` | `string` | `'#000000'` | Initial value for uncontrolled usage. |
38
+ | `onChange` | `(value: string) => void` | — | Change handler; always receives a hex string (8-digit when `transparency` is on). |
39
+ | `onSwatchClick` | `() => void` | — | Fired when the swatch is activated. The swatch is interactive **only** when `type="color"` — use it to open a parent `ColorPicker`. Never called for other types. |
40
+ | `type` | `'color' \| 'color-hex' \| 'color-rgb' \| 'hex' \| 'rgb'` | `'color-hex'` | Which controls render (see [Types](#types)). |
41
+ | `transparency` | `boolean` | `false` | Add an alpha (`%`) field and a transparency-aware swatch. |
42
+ | `size` | `'xl' \| 'lg' \| 'md' \| 'sm' \| 'xs'` | `'md'` | Control size. |
43
+ | `label` | `string` | — | Visible label shown above the control. |
44
+ | `id` | `string` | `auto` | HTML id used for accessibility linking. |
45
+ | `aria-label` | `string` | — | Accessible name when no visible label is present. |
46
+ | `testID` | `string` | — | Test identifier. |
47
+
48
+ Inherits `ThemeOverrideProps` (`themeMode`, `themeProductContext`).
49
+
50
+ The canonical value is always a hex string, regardless of `type`. The hex and RGB fields are alternate editable representations of the same colour; editing either emits an updated hex through `onChange`.
51
+
52
+ ## Types
53
+
54
+ | `type` | Shows |
55
+ | --- | --- |
56
+ | `color` | Swatch only — acts as a trigger (`onSwatchClick`). |
57
+ | `color-hex` | Swatch + hex field. |
58
+ | `color-rgb` | Swatch + R / G / B fields. |
59
+ | `hex` | Hex field only. |
60
+ | `rgb` | R / G / B fields only. |
61
+
62
+ When `transparency` is on, an alpha (`%`) field is appended to every type and `color` gains it too.
63
+
64
+ ## Examples
65
+
66
+ ### Hex field (default)
67
+
68
+ ```tsx
69
+ const [color, setColor] = useState('#22A8C3');
70
+
71
+ <InputColor value={color} onChange={setColor} />;
72
+ ```
73
+
74
+ ### RGB channels
75
+
76
+ ```tsx
77
+ const [color, setColor] = useState('#22A8C3');
78
+
79
+ <InputColor type="color-rgb" value={color} onChange={setColor} />;
80
+ ```
81
+
82
+ ### Transparency (alpha)
83
+
84
+ ```tsx
85
+ const [color, setColor] = useState('#22A8C380');
86
+
87
+ <InputColor type="color-rgb" transparency value={color} onChange={setColor} />;
88
+ ```
89
+
90
+ ### Sizes
91
+
92
+ ```tsx
93
+ <InputColor size="xl" defaultValue="#22A8C3" />
94
+ <InputColor size="md" defaultValue="#22A8C3" />
95
+ <InputColor size="xs" defaultValue="#22A8C3" />
96
+ ```
97
+
98
+ ### Swatch as a ColorPicker trigger
99
+
100
+ `type="color"` renders the swatch alone; wire `onSwatchClick` to open a parent `ColorPicker`.
101
+
102
+ ```tsx
103
+ const [color, setColor] = useState('#22A8C3');
104
+ const [open, setOpen] = useState(false);
105
+
106
+ <InputColor
107
+ type="color"
108
+ value={color}
109
+ onChange={setColor}
110
+ onSwatchClick={() => setOpen(true)}
111
+ />;
112
+ ```
113
+
114
+ ### With a label
115
+
116
+ ```tsx
117
+ const [color, setColor] = useState('#22A8C3');
118
+
119
+ <InputColor value={color} onChange={setColor} label="Brand color" />;
120
+ ```
121
+
122
+ ## Accessibility
123
+
124
+ - The control is a `role="group"`; label it with `label`, `aria-label`, or an external `aria-labelledby` target.
125
+ - Each editable field has an `aria-label` — `"Hex color value"`, `"Red channel"`, `"Green channel"`, `"Blue channel"`, `"Opacity percentage"`.
126
+ - For `type="color"` the swatch is a `<button aria-label="Open color picker">`; for every other type it is a decorative preview marked `aria-hidden` (not focusable, not clickable).
127
+ - Numeric fields (R / G / B, alpha) step by ±1 with the `ArrowUp` / `ArrowDown` keys, clamped to their range (0–255, or 0–100 for alpha).
128
+ - A visually hidden `role="status"` / `aria-live="polite"` region announces colour changes to screen readers (e.g. "Color updated to #FF0000").
129
+ - Editing updates the swatch live as you type; the value commits (and normalizes — shorthand expand, uppercase, clamp) on blur, `Enter`, or `Tab`.
130
+ - The transparency checkerboard behind a translucent colour is rendered with CSS and is web only; the solid swatch and alpha split render on native.
@@ -0,0 +1,66 @@
1
+ import React from 'react';
2
+ import { ThemeOverrideProps } from '@xsolla/xui-core';
3
+
4
+ /**
5
+ * Display variant of the InputColor control. Maps 1:1 to the Figma `Type` prop:
6
+ * - `color` → "Color only" (swatch preview only, no editable field)
7
+ * - `color-hex` → "Color + HEX" (swatch + editable hex field)
8
+ * - `color-rgb` → "Color + HSL/HSB/RGB" (swatch + editable R/G/B channels)
9
+ * - `hex` → "HEX" (editable hex field only)
10
+ * - `rgb` → "HSL/HSB/RGB" (editable R/G/B channels only)
11
+ */
12
+ type InputColorType = "color" | "color-hex" | "color-rgb" | "hex" | "rgb";
13
+ type InputColorSize = "xl" | "lg" | "md" | "sm" | "xs";
14
+ interface InputColorProps extends ThemeOverrideProps {
15
+ /**
16
+ * The current color value as a hex string (controlled mode), e.g. `#22A8C3`.
17
+ * When `transparency` is enabled an 8-digit hex (`#RRGGBBAA`) is accepted.
18
+ */
19
+ value?: string;
20
+ /**
21
+ * The initial color value for uncontrolled usage. Defaults to `#000000`.
22
+ */
23
+ defaultValue?: string;
24
+ /**
25
+ * Event handler fired when the color changes. Always receives a hex string.
26
+ */
27
+ onChange?: (value: string) => void;
28
+ /**
29
+ * Fired when the swatch is activated. The swatch is only interactive when
30
+ * `type="color"` — its role is to open the parent ColorPicker panel. For all
31
+ * other types the swatch is a decorative preview and this is never called.
32
+ */
33
+ onSwatchClick?: () => void;
34
+ /**
35
+ * Display variant of the control. Defaults to `color-hex`.
36
+ */
37
+ type?: InputColorType;
38
+ /**
39
+ * Enables the alpha channel. Adds an alpha field and splits the swatch to
40
+ * preview the transparency against a checkerboard.
41
+ */
42
+ transparency?: boolean;
43
+ /**
44
+ * Property for changing the size of the control.
45
+ */
46
+ size?: InputColorSize;
47
+ /**
48
+ * Property for displaying a label above the control.
49
+ */
50
+ label?: string;
51
+ /**
52
+ * Unique identifier for the control. Used for accessibility linking.
53
+ */
54
+ id?: string;
55
+ /**
56
+ * Accessible label for screen readers when no visible label is present.
57
+ */
58
+ "aria-label"?: string;
59
+ /**
60
+ * Test identifier for the component.
61
+ */
62
+ testID?: string;
63
+ }
64
+ declare const InputColor: React.ForwardRefExoticComponent<InputColorProps & React.RefAttributes<HTMLDivElement>>;
65
+
66
+ export { InputColor, type InputColorProps, type InputColorSize, type InputColorType };
@@ -0,0 +1,66 @@
1
+ import React from 'react';
2
+ import { ThemeOverrideProps } from '@xsolla/xui-core';
3
+
4
+ /**
5
+ * Display variant of the InputColor control. Maps 1:1 to the Figma `Type` prop:
6
+ * - `color` → "Color only" (swatch preview only, no editable field)
7
+ * - `color-hex` → "Color + HEX" (swatch + editable hex field)
8
+ * - `color-rgb` → "Color + HSL/HSB/RGB" (swatch + editable R/G/B channels)
9
+ * - `hex` → "HEX" (editable hex field only)
10
+ * - `rgb` → "HSL/HSB/RGB" (editable R/G/B channels only)
11
+ */
12
+ type InputColorType = "color" | "color-hex" | "color-rgb" | "hex" | "rgb";
13
+ type InputColorSize = "xl" | "lg" | "md" | "sm" | "xs";
14
+ interface InputColorProps extends ThemeOverrideProps {
15
+ /**
16
+ * The current color value as a hex string (controlled mode), e.g. `#22A8C3`.
17
+ * When `transparency` is enabled an 8-digit hex (`#RRGGBBAA`) is accepted.
18
+ */
19
+ value?: string;
20
+ /**
21
+ * The initial color value for uncontrolled usage. Defaults to `#000000`.
22
+ */
23
+ defaultValue?: string;
24
+ /**
25
+ * Event handler fired when the color changes. Always receives a hex string.
26
+ */
27
+ onChange?: (value: string) => void;
28
+ /**
29
+ * Fired when the swatch is activated. The swatch is only interactive when
30
+ * `type="color"` — its role is to open the parent ColorPicker panel. For all
31
+ * other types the swatch is a decorative preview and this is never called.
32
+ */
33
+ onSwatchClick?: () => void;
34
+ /**
35
+ * Display variant of the control. Defaults to `color-hex`.
36
+ */
37
+ type?: InputColorType;
38
+ /**
39
+ * Enables the alpha channel. Adds an alpha field and splits the swatch to
40
+ * preview the transparency against a checkerboard.
41
+ */
42
+ transparency?: boolean;
43
+ /**
44
+ * Property for changing the size of the control.
45
+ */
46
+ size?: InputColorSize;
47
+ /**
48
+ * Property for displaying a label above the control.
49
+ */
50
+ label?: string;
51
+ /**
52
+ * Unique identifier for the control. Used for accessibility linking.
53
+ */
54
+ id?: string;
55
+ /**
56
+ * Accessible label for screen readers when no visible label is present.
57
+ */
58
+ "aria-label"?: string;
59
+ /**
60
+ * Test identifier for the component.
61
+ */
62
+ testID?: string;
63
+ }
64
+ declare const InputColor: React.ForwardRefExoticComponent<InputColorProps & React.RefAttributes<HTMLDivElement>>;
65
+
66
+ export { InputColor, type InputColorProps, type InputColorSize, type InputColorType };