@xsolla/xui-color-picker 0.148.0 → 0.148.2

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.
Files changed (2) hide show
  1. package/README.md +204 -0
  2. package/package.json +6 -6
package/README.md ADDED
@@ -0,0 +1,204 @@
1
+ # Color Picker
2
+
3
+ A cross-platform React color picker component with a visual selection area, format switching, and color value controls.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @xsolla/xui-color-picker
9
+ # or
10
+ yarn add @xsolla/xui-color-picker
11
+ ```
12
+
13
+ ## Demo
14
+
15
+ ### Basic Color Picker
16
+
17
+ ```tsx
18
+ import * as React from 'react';
19
+ import { ColorPicker } from '@xsolla/xui-color-picker';
20
+
21
+ export default function BasicColorPicker() {
22
+ const [color, setColor] = React.useState('#66E6FFFF');
23
+
24
+ return (
25
+ <ColorPicker
26
+ value={color}
27
+ onChange={({ valueInInitialFormat }) => setColor(valueInInitialFormat)}
28
+ />
29
+ );
30
+ }
31
+ ```
32
+
33
+ ### Without Alpha Channel
34
+
35
+ ```tsx
36
+ import * as React from 'react';
37
+ import { ColorPicker } from '@xsolla/xui-color-picker';
38
+
39
+ export default function NoAlpha() {
40
+ return (
41
+ <ColorPicker
42
+ value="#FF5733"
43
+ alpha={false}
44
+ onChange={console.log}
45
+ />
46
+ );
47
+ }
48
+ ```
49
+
50
+ ### With Eyedropper
51
+
52
+ ```tsx
53
+ import * as React from 'react';
54
+ import { ColorPicker } from '@xsolla/xui-color-picker';
55
+
56
+ export default function WithEyedropper() {
57
+ return (
58
+ <ColorPicker
59
+ value="#3498DB"
60
+ eyedropper
61
+ onChange={console.log}
62
+ />
63
+ );
64
+ }
65
+ ```
66
+
67
+ ## Anatomy
68
+
69
+ ```jsx
70
+ import { ColorPicker } from '@xsolla/xui-color-picker';
71
+
72
+ <ColorPicker
73
+ value="#66E6FFFF" // Initial color value
74
+ colorFormat="hex" // Default format (hex, rgb, hsl, hsb)
75
+ alpha={true} // Show alpha slider
76
+ eyedropper={false} // Show eyedropper button
77
+ selectableFormats={['hex', 'hsl', 'rgb', 'hsb']} // Available formats
78
+ onChange={handleChange} // Change callback
79
+ bottomContent={<Custom />} // Custom content below controls
80
+ />
81
+ ```
82
+
83
+ ## Examples
84
+
85
+ ### Custom Format Selection
86
+
87
+ ```tsx
88
+ import * as React from 'react';
89
+ import { ColorPicker } from '@xsolla/xui-color-picker';
90
+
91
+ export default function CustomFormats() {
92
+ return (
93
+ <ColorPicker
94
+ value="#FF0000"
95
+ colorFormat="rgb"
96
+ selectableFormats={['rgb', 'hex']}
97
+ onChange={({ valueInCurrentFormat, currentColorFormat }) => {
98
+ console.log(`${currentColorFormat}: ${valueInCurrentFormat}`);
99
+ }}
100
+ />
101
+ );
102
+ }
103
+ ```
104
+
105
+ ### With Bottom Content
106
+
107
+ ```tsx
108
+ import * as React from 'react';
109
+ import { ColorPicker } from '@xsolla/xui-color-picker';
110
+ import { Button } from '@xsolla/xui-button';
111
+
112
+ export default function WithBottomContent() {
113
+ const [color, setColor] = React.useState('#66E6FFFF');
114
+
115
+ return (
116
+ <ColorPicker
117
+ value={color}
118
+ onChange={({ valueInInitialFormat }) => setColor(valueInInitialFormat)}
119
+ bottomContent={
120
+ <Button size="sm" onPress={() => console.log('Applied:', color)}>
121
+ Apply Color
122
+ </Button>
123
+ }
124
+ />
125
+ );
126
+ }
127
+ ```
128
+
129
+ ### Controlled Color Picker
130
+
131
+ ```tsx
132
+ import * as React from 'react';
133
+ import { ColorPicker } from '@xsolla/xui-color-picker';
134
+
135
+ export default function ControlledPicker() {
136
+ const [color, setColor] = React.useState('#9B59B6FF');
137
+
138
+ const handleChange = ({ valueInInitialFormat, valueInCurrentFormat, currentColorFormat }) => {
139
+ console.log('Format:', currentColorFormat);
140
+ console.log('Current format value:', valueInCurrentFormat);
141
+ console.log('Initial format value:', valueInInitialFormat);
142
+ setColor(valueInInitialFormat);
143
+ };
144
+
145
+ return (
146
+ <div>
147
+ <p>Selected: {color}</p>
148
+ <ColorPicker value={color} onChange={handleChange} />
149
+ </div>
150
+ );
151
+ }
152
+ ```
153
+
154
+ ## API Reference
155
+
156
+ ### ColorPicker
157
+
158
+ **ColorPickerProps:**
159
+
160
+ | Prop | Type | Default | Description |
161
+ | :--- | :--- | :------ | :---------- |
162
+ | value | `string` | `"#66E6FFFF"` | Color value in any supported format. |
163
+ | colorFormat | `"hex" \| "rgb" \| "hsl" \| "hsb"` | `"hex"` | Default color format for output. |
164
+ | alpha | `boolean` | `true` | Show alpha channel slider. |
165
+ | eyedropper | `boolean` | `false` | Show eyedropper tool (web only). |
166
+ | selectableFormats | `Array<"hex" \| "rgb" \| "hsl" \| "hsb">` | All formats | Available formats in dropdown. |
167
+ | copiedIcon | `ReactNode` | - | Custom icon for copied state. |
168
+ | bottomContent | `ReactNode` | - | Custom content below color controls. |
169
+ | onChange | `(result: ColorChangeResult) => void` | - | Callback when color changes. |
170
+ | testID | `string` | - | Test identifier. |
171
+
172
+ **ColorChangeResult:**
173
+
174
+ ```typescript
175
+ interface ColorChangeResult {
176
+ valueInInitialFormat: string; // Color in original format
177
+ valueInCurrentFormat: string; // Color in selected format
178
+ currentColorFormat: "hex" | "rgb" | "hsl" | "hsb";
179
+ }
180
+ ```
181
+
182
+ ## Supported Formats
183
+
184
+ | Format | Example | With Alpha |
185
+ | :----- | :------ | :--------- |
186
+ | hex | `#FF5733` | `#FF5733FF` |
187
+ | rgb | `rgb(255, 87, 51)` | `rgba(255, 87, 51, 1)` |
188
+ | hsl | `hsl(11, 100%, 60%)` | `hsla(11, 100%, 60%, 1)` |
189
+ | hsb | `hsb(11, 80%, 100%)` | `hsba(11, 80%, 100%, 1)` |
190
+
191
+ ## Features
192
+
193
+ - **Visual picker**: Click and drag on the color area to select hue/saturation
194
+ - **Sliders**: Hue and alpha channel sliders
195
+ - **Format switching**: Toggle between hex, RGB, HSL, HSB via dropdown
196
+ - **Copy button**: Copy current color value to clipboard
197
+ - **Reset button**: Reset to initial color value
198
+ - **Eyedropper**: Pick colors from anywhere on screen (web only, requires browser support)
199
+
200
+ ## Accessibility
201
+
202
+ - Copy and reset buttons have accessible labels
203
+ - Keyboard navigation supported for all controls
204
+ - Color values are displayed in text inputs for manual entry
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xsolla/xui-color-picker",
3
- "version": "0.148.0",
3
+ "version": "0.148.2",
4
4
  "main": "./web/index.js",
5
5
  "module": "./web/index.mjs",
6
6
  "types": "./web/index.d.ts",
@@ -13,11 +13,11 @@
13
13
  "test:coverage": "vitest run --coverage"
14
14
  },
15
15
  "dependencies": {
16
- "@xsolla/xui-button": "0.148.0",
17
- "@xsolla/xui-core": "0.148.0",
18
- "@xsolla/xui-input": "0.148.0",
19
- "@xsolla/xui-primitives-core": "0.148.0",
20
- "@xsolla/xui-select": "0.148.0"
16
+ "@xsolla/xui-button": "0.148.2",
17
+ "@xsolla/xui-core": "0.148.2",
18
+ "@xsolla/xui-input": "0.148.2",
19
+ "@xsolla/xui-primitives-core": "0.148.2",
20
+ "@xsolla/xui-select": "0.148.2"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "react": ">=16.8.0"