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