@zag-js/color-picker 0.22.0 → 0.24.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/dist/index.d.mts CHANGED
@@ -1,18 +1,29 @@
1
1
  import * as _zag_js_anatomy from '@zag-js/anatomy';
2
- import { RequiredBy, Orientation, PropTypes, CommonProperties, Context, NormalizeProps } from '@zag-js/types';
2
+ import { RequiredBy, Orientation, PropTypes, CommonProperties, MaybeElement, Context, NormalizeProps } from '@zag-js/types';
3
3
  import { ColorChannel, Color, ColorFormat } from '@zag-js/color-utils';
4
4
  export { Color, ColorAxes, ColorChannel, ColorFormat, ColorType } from '@zag-js/color-utils';
5
5
  import * as _zag_js_core from '@zag-js/core';
6
6
  import { StateMachine } from '@zag-js/core';
7
+ import { InteractOutsideHandlers } from '@zag-js/dismissable';
8
+ import { PositioningOptions } from '@zag-js/popper';
9
+ import { MaybeFunction } from '@zag-js/utils';
7
10
 
8
- declare const anatomy: _zag_js_anatomy.Anatomy<"area" | "areaThumb" | "areaGradient" | "channelSliderTrack" | "channelSliderTrackBackground" | "channelSliderThumb" | "channelInput" | "swatch" | "swatchBackground" | "content" | "label" | "eyeDropperTrigger">;
11
+ declare const anatomy: _zag_js_anatomy.Anatomy<"root" | "label" | "control" | "trigger" | "positioner" | "content" | "area" | "areaThumb" | "areaBackground" | "channelSlider" | "channelSliderTrack" | "channelSliderThumb" | "channelInput" | "transparancyGrid" | "swatchGroup" | "swatchTrigger" | "swatch" | "eyeDropperTrigger">;
9
12
 
10
13
  interface ValueChangeDetails {
11
- value: string;
12
- valueAsColor: Color;
14
+ value: Color;
15
+ valueAsString: string;
16
+ }
17
+ interface OpenChangeDetails {
18
+ open: boolean;
13
19
  }
14
20
  type ExtendedColorChannel = ColorChannel | "hex" | "css";
15
21
  type ElementIds = Partial<{
22
+ root: string;
23
+ control: string;
24
+ trigger: string;
25
+ label: string;
26
+ input: string;
16
27
  content: string;
17
28
  area: string;
18
29
  areaGradient: string;
@@ -21,7 +32,7 @@ type ElementIds = Partial<{
21
32
  channelSliderTrack(id: ColorChannel): string;
22
33
  channelSliderThumb(id: ColorChannel): string;
23
34
  }>;
24
- interface PublicContext extends CommonProperties {
35
+ interface PublicContext extends CommonProperties, InteractOutsideHandlers {
25
36
  /**
26
37
  * The ids of the elements in the color picker. Useful for composition.
27
38
  */
@@ -33,7 +44,7 @@ interface PublicContext extends CommonProperties {
33
44
  /**
34
45
  * The current color value
35
46
  */
36
- value: string;
47
+ value: Color;
37
48
  /**
38
49
  * Whether the color picker is disabled
39
50
  */
@@ -51,9 +62,40 @@ interface PublicContext extends CommonProperties {
51
62
  */
52
63
  onValueChangeEnd?: (details: ValueChangeDetails) => void;
53
64
  /**
54
- * The name for the form input
65
+ * Handler that is called when the user opens or closes the color picker.
66
+ */
67
+ onOpenChange?: (details: OpenChangeDetails) => void;
68
+ /**
69
+ * The name for the form input
55
70
  */
56
71
  name?: string;
72
+ /**
73
+ * The color format to use (rgb, hsl, hsb)
74
+ * @default "hsl"
75
+ */
76
+ format?: ColorFormat;
77
+ /**
78
+ * The alpha format to use (decimal, percent)
79
+ * @default "decimal"
80
+ */
81
+ alphaFormat?: "decimal" | "percent";
82
+ /**
83
+ * The positioning options for the color picker
84
+ */
85
+ positioning: PositioningOptions;
86
+ /**
87
+ * Whether to automatically set focus on the first focusable
88
+ * content within the color picker when opened.
89
+ */
90
+ autoFocus?: boolean;
91
+ /**
92
+ * The initial focus element when the color picker is opened.
93
+ */
94
+ initialFocusEl?: MaybeFunction<MaybeElement>;
95
+ /**
96
+ * Whether the color picker is open
97
+ */
98
+ open?: boolean;
57
99
  }
58
100
  type PrivateContext = Context<{}>;
59
101
  type ComputedContext = Readonly<{
@@ -71,7 +113,7 @@ type ComputedContext = Readonly<{
71
113
  * @computed
72
114
  * The color value as a Color object
73
115
  */
74
- valueAsColor: Color;
116
+ valueAsString: string;
75
117
  /**
76
118
  * @computed
77
119
  * Whether the color picker is disabled
@@ -82,43 +124,59 @@ type UserDefinedContext = RequiredBy<PublicContext, "id">;
82
124
  interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
83
125
  }
84
126
  interface MachineState {
85
- value: "idle" | "focused" | "dragging";
127
+ tags: "open" | "closed" | "dragging" | "focused";
128
+ value: "idle" | "focused" | "open" | "open:dragging";
86
129
  }
87
130
  type State = StateMachine.State<MachineContext, MachineState>;
88
131
  type Send = StateMachine.Send<StateMachine.AnyEventObject>;
89
- interface ColorChannelProps {
132
+ interface ChannelProps {
90
133
  channel: ColorChannel;
91
134
  orientation?: Orientation;
92
135
  }
93
- interface ColorChannelInputProps {
136
+ interface ChannelInputProps {
94
137
  channel: ExtendedColorChannel;
95
138
  orientation?: Orientation;
96
139
  }
97
- interface ColorAreaProps {
98
- xChannel: ColorChannel;
99
- yChannel: ColorChannel;
140
+ interface AreaProps {
141
+ xChannel?: ColorChannel;
142
+ yChannel?: ColorChannel;
100
143
  }
101
- interface ColorSwatchProps {
102
- readOnly?: boolean;
144
+ interface SwatchTriggerProps {
145
+ /**
146
+ * The color value
147
+ */
103
148
  value: string | Color;
104
149
  }
150
+ interface SwatchProps {
151
+ /**
152
+ * The color value
153
+ */
154
+ value: string | Color;
155
+ /**
156
+ * Whether to include the alpha channel in the color
157
+ */
158
+ respectAlpha?: boolean;
159
+ }
160
+ interface TransparancyGridProps {
161
+ size: string;
162
+ }
105
163
  interface MachineApi<T extends PropTypes = PropTypes> {
106
164
  /**
107
165
  * Whether the color picker is being dragged
108
166
  */
109
167
  isDragging: boolean;
110
168
  /**
111
- * The current color value (as a string)
169
+ * Whether the color picker is open
112
170
  */
113
- value: string;
171
+ isOpen: boolean;
114
172
  /**
115
- * The current color value (as a Color object)
173
+ * The current color value (as a string)
116
174
  */
117
- valueAsColor: Color;
175
+ value: Color;
118
176
  /**
119
- * The alpha value of the color
177
+ * The current color value (as a Color object)
120
178
  */
121
- alpha: number;
179
+ valueAsString: string;
122
180
  /**
123
181
  * The current color channels of the color
124
182
  */
@@ -127,6 +185,10 @@ interface MachineApi<T extends PropTypes = PropTypes> {
127
185
  * Function to set the color value
128
186
  */
129
187
  setColor(value: string | Color): void;
188
+ /**
189
+ * Function to set the color value
190
+ */
191
+ getChannelValue(channel: ColorChannel): string;
130
192
  /**
131
193
  * Function to set the color value of a specific channel
132
194
  */
@@ -135,26 +197,39 @@ interface MachineApi<T extends PropTypes = PropTypes> {
135
197
  * Function to set the color format
136
198
  */
137
199
  setFormat(format: ColorFormat): void;
200
+ /**
201
+ * The alpha value of the color
202
+ */
203
+ getAlpha(): number;
138
204
  /**
139
205
  * Function to set the color alpha
140
206
  */
141
207
  setAlpha(value: number): void;
208
+ rootProps: T["element"];
209
+ labelProps: T["element"];
210
+ controlProps: T["element"];
211
+ triggerProps: T["button"];
212
+ positionerProps: T["element"];
142
213
  contentProps: T["element"];
143
214
  hiddenInputProps: T["input"];
144
- getAreaProps(props: ColorAreaProps): T["element"];
145
- getAreaGradientProps(props: ColorAreaProps): T["element"];
146
- getAreaThumbProps(props: ColorAreaProps): T["element"];
147
- getChannelSliderTrackProps(props: ColorChannelProps): T["element"];
148
- getChannelSliderBackgroundProps(props: ColorChannelProps): T["element"];
149
- getChannelSliderThumbProps(props: ColorChannelProps): T["element"];
150
- getChannelInputProps(props: ColorChannelInputProps): T["input"];
215
+ getAreaProps(props?: AreaProps): T["element"];
216
+ getAreaBackgroundProps(props?: AreaProps): T["element"];
217
+ getAreaThumbProps(props?: AreaProps): T["element"];
218
+ getChannelSliderProps(props: ChannelProps): T["element"];
219
+ getChannelSliderTrackProps(props: ChannelProps): T["element"];
220
+ getChannelSliderThumbProps(props: ChannelProps): T["element"];
221
+ getChannelInputProps(props: ChannelInputProps): T["input"];
222
+ getTransparencyGridProps(props: TransparancyGridProps): T["element"];
151
223
  eyeDropperTriggerProps: T["button"];
152
- getSwatchBackgroundProps(props: ColorSwatchProps): T["element"];
153
- getSwatchProps(props: ColorSwatchProps): T["element"];
224
+ swatchGroupProps: T["element"];
225
+ getSwatchTriggerProps(props: SwatchTriggerProps): T["button"];
226
+ getSwatchProps(props: SwatchProps): T["element"];
154
227
  }
155
228
 
156
229
  declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
157
230
 
158
231
  declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
159
232
 
160
- export { MachineApi as Api, ColorAreaProps, ColorChannelInputProps, ColorChannelProps, ColorSwatchProps, UserDefinedContext as Context, anatomy, connect, machine };
233
+ declare const parse: (color: string) => Color;
234
+
235
+ export { MachineApi as Api, AreaProps, ChannelInputProps, ChannelProps, UserDefinedContext as Context, SwatchProps, anatomy, connect, machine, parse };
package/dist/index.d.ts CHANGED
@@ -1,18 +1,29 @@
1
1
  import * as _zag_js_anatomy from '@zag-js/anatomy';
2
- import { RequiredBy, Orientation, PropTypes, CommonProperties, Context, NormalizeProps } from '@zag-js/types';
2
+ import { RequiredBy, Orientation, PropTypes, CommonProperties, MaybeElement, Context, NormalizeProps } from '@zag-js/types';
3
3
  import { ColorChannel, Color, ColorFormat } from '@zag-js/color-utils';
4
4
  export { Color, ColorAxes, ColorChannel, ColorFormat, ColorType } from '@zag-js/color-utils';
5
5
  import * as _zag_js_core from '@zag-js/core';
6
6
  import { StateMachine } from '@zag-js/core';
7
+ import { InteractOutsideHandlers } from '@zag-js/dismissable';
8
+ import { PositioningOptions } from '@zag-js/popper';
9
+ import { MaybeFunction } from '@zag-js/utils';
7
10
 
8
- declare const anatomy: _zag_js_anatomy.Anatomy<"area" | "areaThumb" | "areaGradient" | "channelSliderTrack" | "channelSliderTrackBackground" | "channelSliderThumb" | "channelInput" | "swatch" | "swatchBackground" | "content" | "label" | "eyeDropperTrigger">;
11
+ declare const anatomy: _zag_js_anatomy.Anatomy<"root" | "label" | "control" | "trigger" | "positioner" | "content" | "area" | "areaThumb" | "areaBackground" | "channelSlider" | "channelSliderTrack" | "channelSliderThumb" | "channelInput" | "transparancyGrid" | "swatchGroup" | "swatchTrigger" | "swatch" | "eyeDropperTrigger">;
9
12
 
10
13
  interface ValueChangeDetails {
11
- value: string;
12
- valueAsColor: Color;
14
+ value: Color;
15
+ valueAsString: string;
16
+ }
17
+ interface OpenChangeDetails {
18
+ open: boolean;
13
19
  }
14
20
  type ExtendedColorChannel = ColorChannel | "hex" | "css";
15
21
  type ElementIds = Partial<{
22
+ root: string;
23
+ control: string;
24
+ trigger: string;
25
+ label: string;
26
+ input: string;
16
27
  content: string;
17
28
  area: string;
18
29
  areaGradient: string;
@@ -21,7 +32,7 @@ type ElementIds = Partial<{
21
32
  channelSliderTrack(id: ColorChannel): string;
22
33
  channelSliderThumb(id: ColorChannel): string;
23
34
  }>;
24
- interface PublicContext extends CommonProperties {
35
+ interface PublicContext extends CommonProperties, InteractOutsideHandlers {
25
36
  /**
26
37
  * The ids of the elements in the color picker. Useful for composition.
27
38
  */
@@ -33,7 +44,7 @@ interface PublicContext extends CommonProperties {
33
44
  /**
34
45
  * The current color value
35
46
  */
36
- value: string;
47
+ value: Color;
37
48
  /**
38
49
  * Whether the color picker is disabled
39
50
  */
@@ -51,9 +62,40 @@ interface PublicContext extends CommonProperties {
51
62
  */
52
63
  onValueChangeEnd?: (details: ValueChangeDetails) => void;
53
64
  /**
54
- * The name for the form input
65
+ * Handler that is called when the user opens or closes the color picker.
66
+ */
67
+ onOpenChange?: (details: OpenChangeDetails) => void;
68
+ /**
69
+ * The name for the form input
55
70
  */
56
71
  name?: string;
72
+ /**
73
+ * The color format to use (rgb, hsl, hsb)
74
+ * @default "hsl"
75
+ */
76
+ format?: ColorFormat;
77
+ /**
78
+ * The alpha format to use (decimal, percent)
79
+ * @default "decimal"
80
+ */
81
+ alphaFormat?: "decimal" | "percent";
82
+ /**
83
+ * The positioning options for the color picker
84
+ */
85
+ positioning: PositioningOptions;
86
+ /**
87
+ * Whether to automatically set focus on the first focusable
88
+ * content within the color picker when opened.
89
+ */
90
+ autoFocus?: boolean;
91
+ /**
92
+ * The initial focus element when the color picker is opened.
93
+ */
94
+ initialFocusEl?: MaybeFunction<MaybeElement>;
95
+ /**
96
+ * Whether the color picker is open
97
+ */
98
+ open?: boolean;
57
99
  }
58
100
  type PrivateContext = Context<{}>;
59
101
  type ComputedContext = Readonly<{
@@ -71,7 +113,7 @@ type ComputedContext = Readonly<{
71
113
  * @computed
72
114
  * The color value as a Color object
73
115
  */
74
- valueAsColor: Color;
116
+ valueAsString: string;
75
117
  /**
76
118
  * @computed
77
119
  * Whether the color picker is disabled
@@ -82,43 +124,59 @@ type UserDefinedContext = RequiredBy<PublicContext, "id">;
82
124
  interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
83
125
  }
84
126
  interface MachineState {
85
- value: "idle" | "focused" | "dragging";
127
+ tags: "open" | "closed" | "dragging" | "focused";
128
+ value: "idle" | "focused" | "open" | "open:dragging";
86
129
  }
87
130
  type State = StateMachine.State<MachineContext, MachineState>;
88
131
  type Send = StateMachine.Send<StateMachine.AnyEventObject>;
89
- interface ColorChannelProps {
132
+ interface ChannelProps {
90
133
  channel: ColorChannel;
91
134
  orientation?: Orientation;
92
135
  }
93
- interface ColorChannelInputProps {
136
+ interface ChannelInputProps {
94
137
  channel: ExtendedColorChannel;
95
138
  orientation?: Orientation;
96
139
  }
97
- interface ColorAreaProps {
98
- xChannel: ColorChannel;
99
- yChannel: ColorChannel;
140
+ interface AreaProps {
141
+ xChannel?: ColorChannel;
142
+ yChannel?: ColorChannel;
100
143
  }
101
- interface ColorSwatchProps {
102
- readOnly?: boolean;
144
+ interface SwatchTriggerProps {
145
+ /**
146
+ * The color value
147
+ */
103
148
  value: string | Color;
104
149
  }
150
+ interface SwatchProps {
151
+ /**
152
+ * The color value
153
+ */
154
+ value: string | Color;
155
+ /**
156
+ * Whether to include the alpha channel in the color
157
+ */
158
+ respectAlpha?: boolean;
159
+ }
160
+ interface TransparancyGridProps {
161
+ size: string;
162
+ }
105
163
  interface MachineApi<T extends PropTypes = PropTypes> {
106
164
  /**
107
165
  * Whether the color picker is being dragged
108
166
  */
109
167
  isDragging: boolean;
110
168
  /**
111
- * The current color value (as a string)
169
+ * Whether the color picker is open
112
170
  */
113
- value: string;
171
+ isOpen: boolean;
114
172
  /**
115
- * The current color value (as a Color object)
173
+ * The current color value (as a string)
116
174
  */
117
- valueAsColor: Color;
175
+ value: Color;
118
176
  /**
119
- * The alpha value of the color
177
+ * The current color value (as a Color object)
120
178
  */
121
- alpha: number;
179
+ valueAsString: string;
122
180
  /**
123
181
  * The current color channels of the color
124
182
  */
@@ -127,6 +185,10 @@ interface MachineApi<T extends PropTypes = PropTypes> {
127
185
  * Function to set the color value
128
186
  */
129
187
  setColor(value: string | Color): void;
188
+ /**
189
+ * Function to set the color value
190
+ */
191
+ getChannelValue(channel: ColorChannel): string;
130
192
  /**
131
193
  * Function to set the color value of a specific channel
132
194
  */
@@ -135,26 +197,39 @@ interface MachineApi<T extends PropTypes = PropTypes> {
135
197
  * Function to set the color format
136
198
  */
137
199
  setFormat(format: ColorFormat): void;
200
+ /**
201
+ * The alpha value of the color
202
+ */
203
+ getAlpha(): number;
138
204
  /**
139
205
  * Function to set the color alpha
140
206
  */
141
207
  setAlpha(value: number): void;
208
+ rootProps: T["element"];
209
+ labelProps: T["element"];
210
+ controlProps: T["element"];
211
+ triggerProps: T["button"];
212
+ positionerProps: T["element"];
142
213
  contentProps: T["element"];
143
214
  hiddenInputProps: T["input"];
144
- getAreaProps(props: ColorAreaProps): T["element"];
145
- getAreaGradientProps(props: ColorAreaProps): T["element"];
146
- getAreaThumbProps(props: ColorAreaProps): T["element"];
147
- getChannelSliderTrackProps(props: ColorChannelProps): T["element"];
148
- getChannelSliderBackgroundProps(props: ColorChannelProps): T["element"];
149
- getChannelSliderThumbProps(props: ColorChannelProps): T["element"];
150
- getChannelInputProps(props: ColorChannelInputProps): T["input"];
215
+ getAreaProps(props?: AreaProps): T["element"];
216
+ getAreaBackgroundProps(props?: AreaProps): T["element"];
217
+ getAreaThumbProps(props?: AreaProps): T["element"];
218
+ getChannelSliderProps(props: ChannelProps): T["element"];
219
+ getChannelSliderTrackProps(props: ChannelProps): T["element"];
220
+ getChannelSliderThumbProps(props: ChannelProps): T["element"];
221
+ getChannelInputProps(props: ChannelInputProps): T["input"];
222
+ getTransparencyGridProps(props: TransparancyGridProps): T["element"];
151
223
  eyeDropperTriggerProps: T["button"];
152
- getSwatchBackgroundProps(props: ColorSwatchProps): T["element"];
153
- getSwatchProps(props: ColorSwatchProps): T["element"];
224
+ swatchGroupProps: T["element"];
225
+ getSwatchTriggerProps(props: SwatchTriggerProps): T["button"];
226
+ getSwatchProps(props: SwatchProps): T["element"];
154
227
  }
155
228
 
156
229
  declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
157
230
 
158
231
  declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
159
232
 
160
- export { MachineApi as Api, ColorAreaProps, ColorChannelInputProps, ColorChannelProps, ColorSwatchProps, UserDefinedContext as Context, anatomy, connect, machine };
233
+ declare const parse: (color: string) => Color;
234
+
235
+ export { MachineApi as Api, AreaProps, ChannelInputProps, ChannelProps, UserDefinedContext as Context, SwatchProps, anatomy, connect, machine, parse };