@zag-js/color-picker 0.23.0 → 0.25.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" | "transparencyGrid" | "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,30 @@ 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 positioning options for the color picker
74
+ */
75
+ positioning: PositioningOptions;
76
+ /**
77
+ * Whether to automatically set focus on the first focusable
78
+ * content within the color picker when opened.
79
+ */
80
+ autoFocus?: boolean;
81
+ /**
82
+ * The initial focus element when the color picker is opened.
83
+ */
84
+ initialFocusEl?: MaybeFunction<MaybeElement>;
85
+ /**
86
+ * Whether the color picker is open
87
+ */
88
+ open?: boolean;
57
89
  }
58
90
  type PrivateContext = Context<{}>;
59
91
  type ComputedContext = Readonly<{
@@ -71,7 +103,7 @@ type ComputedContext = Readonly<{
71
103
  * @computed
72
104
  * The color value as a Color object
73
105
  */
74
- valueAsColor: Color;
106
+ valueAsString: string;
75
107
  /**
76
108
  * @computed
77
109
  * Whether the color picker is disabled
@@ -82,43 +114,59 @@ type UserDefinedContext = RequiredBy<PublicContext, "id">;
82
114
  interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
83
115
  }
84
116
  interface MachineState {
85
- value: "idle" | "focused" | "dragging";
117
+ tags: "open" | "closed" | "dragging" | "focused";
118
+ value: "idle" | "focused" | "open" | "open:dragging";
86
119
  }
87
120
  type State = StateMachine.State<MachineContext, MachineState>;
88
121
  type Send = StateMachine.Send<StateMachine.AnyEventObject>;
89
- interface ColorChannelProps {
122
+ interface ChannelProps {
90
123
  channel: ColorChannel;
91
124
  orientation?: Orientation;
92
125
  }
93
- interface ColorChannelInputProps {
126
+ interface ChannelInputProps {
94
127
  channel: ExtendedColorChannel;
95
128
  orientation?: Orientation;
96
129
  }
97
- interface ColorAreaProps {
98
- xChannel: ColorChannel;
99
- yChannel: ColorChannel;
130
+ interface AreaProps {
131
+ xChannel?: ColorChannel;
132
+ yChannel?: ColorChannel;
100
133
  }
101
- interface ColorSwatchProps {
102
- readOnly?: boolean;
134
+ interface SwatchTriggerProps {
135
+ /**
136
+ * The color value
137
+ */
103
138
  value: string | Color;
104
139
  }
140
+ interface SwatchProps {
141
+ /**
142
+ * The color value
143
+ */
144
+ value: string | Color;
145
+ /**
146
+ * Whether to include the alpha channel in the color
147
+ */
148
+ respectAlpha?: boolean;
149
+ }
150
+ interface TransparencyGridProps {
151
+ size?: string;
152
+ }
105
153
  interface MachineApi<T extends PropTypes = PropTypes> {
106
154
  /**
107
155
  * Whether the color picker is being dragged
108
156
  */
109
157
  isDragging: boolean;
110
158
  /**
111
- * The current color value (as a string)
159
+ * Whether the color picker is open
112
160
  */
113
- value: string;
161
+ isOpen: boolean;
114
162
  /**
115
- * The current color value (as a Color object)
163
+ * The current color value (as a string)
116
164
  */
117
- valueAsColor: Color;
165
+ value: Color;
118
166
  /**
119
- * The alpha value of the color
167
+ * The current color value (as a Color object)
120
168
  */
121
- alpha: number;
169
+ valueAsString: string;
122
170
  /**
123
171
  * The current color channels of the color
124
172
  */
@@ -127,34 +175,55 @@ interface MachineApi<T extends PropTypes = PropTypes> {
127
175
  * Function to set the color value
128
176
  */
129
177
  setColor(value: string | Color): void;
178
+ /**
179
+ * Function to set the color value
180
+ */
181
+ getChannelValue(channel: ColorChannel): string;
130
182
  /**
131
183
  * Function to set the color value of a specific channel
132
184
  */
133
185
  setChannelValue(channel: ColorChannel, value: number): void;
186
+ /**
187
+ * The current color format
188
+ */
189
+ format: ColorFormat;
134
190
  /**
135
191
  * Function to set the color format
136
192
  */
137
193
  setFormat(format: ColorFormat): void;
194
+ /**
195
+ * The alpha value of the color
196
+ */
197
+ alpha: number;
138
198
  /**
139
199
  * Function to set the color alpha
140
200
  */
141
201
  setAlpha(value: number): void;
202
+ rootProps: T["element"];
203
+ labelProps: T["element"];
204
+ controlProps: T["element"];
205
+ triggerProps: T["button"];
206
+ positionerProps: T["element"];
142
207
  contentProps: T["element"];
143
208
  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"];
209
+ getAreaProps(props?: AreaProps): T["element"];
210
+ getAreaBackgroundProps(props?: AreaProps): T["element"];
211
+ getAreaThumbProps(props?: AreaProps): T["element"];
212
+ getChannelSliderProps(props: ChannelProps): T["element"];
213
+ getChannelSliderTrackProps(props: ChannelProps): T["element"];
214
+ getChannelSliderThumbProps(props: ChannelProps): T["element"];
215
+ getChannelInputProps(props: ChannelInputProps): T["input"];
216
+ getTransparencyGridProps(props?: TransparencyGridProps): T["element"];
151
217
  eyeDropperTriggerProps: T["button"];
152
- getSwatchBackgroundProps(props: ColorSwatchProps): T["element"];
153
- getSwatchProps(props: ColorSwatchProps): T["element"];
218
+ swatchGroupProps: T["element"];
219
+ getSwatchTriggerProps(props: SwatchTriggerProps): T["button"];
220
+ getSwatchProps(props: SwatchProps): T["element"];
154
221
  }
155
222
 
156
223
  declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
157
224
 
158
225
  declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
159
226
 
160
- export { MachineApi as Api, ColorAreaProps, ColorChannelInputProps, ColorChannelProps, ColorSwatchProps, UserDefinedContext as Context, anatomy, connect, machine };
227
+ declare const parse: (color: string) => Color;
228
+
229
+ export { MachineApi as Api, AreaProps, ChannelInputProps, ChannelProps, UserDefinedContext as Context, SwatchProps, SwatchTriggerProps, TransparencyGridProps, 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" | "transparencyGrid" | "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,30 @@ 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 positioning options for the color picker
74
+ */
75
+ positioning: PositioningOptions;
76
+ /**
77
+ * Whether to automatically set focus on the first focusable
78
+ * content within the color picker when opened.
79
+ */
80
+ autoFocus?: boolean;
81
+ /**
82
+ * The initial focus element when the color picker is opened.
83
+ */
84
+ initialFocusEl?: MaybeFunction<MaybeElement>;
85
+ /**
86
+ * Whether the color picker is open
87
+ */
88
+ open?: boolean;
57
89
  }
58
90
  type PrivateContext = Context<{}>;
59
91
  type ComputedContext = Readonly<{
@@ -71,7 +103,7 @@ type ComputedContext = Readonly<{
71
103
  * @computed
72
104
  * The color value as a Color object
73
105
  */
74
- valueAsColor: Color;
106
+ valueAsString: string;
75
107
  /**
76
108
  * @computed
77
109
  * Whether the color picker is disabled
@@ -82,43 +114,59 @@ type UserDefinedContext = RequiredBy<PublicContext, "id">;
82
114
  interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
83
115
  }
84
116
  interface MachineState {
85
- value: "idle" | "focused" | "dragging";
117
+ tags: "open" | "closed" | "dragging" | "focused";
118
+ value: "idle" | "focused" | "open" | "open:dragging";
86
119
  }
87
120
  type State = StateMachine.State<MachineContext, MachineState>;
88
121
  type Send = StateMachine.Send<StateMachine.AnyEventObject>;
89
- interface ColorChannelProps {
122
+ interface ChannelProps {
90
123
  channel: ColorChannel;
91
124
  orientation?: Orientation;
92
125
  }
93
- interface ColorChannelInputProps {
126
+ interface ChannelInputProps {
94
127
  channel: ExtendedColorChannel;
95
128
  orientation?: Orientation;
96
129
  }
97
- interface ColorAreaProps {
98
- xChannel: ColorChannel;
99
- yChannel: ColorChannel;
130
+ interface AreaProps {
131
+ xChannel?: ColorChannel;
132
+ yChannel?: ColorChannel;
100
133
  }
101
- interface ColorSwatchProps {
102
- readOnly?: boolean;
134
+ interface SwatchTriggerProps {
135
+ /**
136
+ * The color value
137
+ */
103
138
  value: string | Color;
104
139
  }
140
+ interface SwatchProps {
141
+ /**
142
+ * The color value
143
+ */
144
+ value: string | Color;
145
+ /**
146
+ * Whether to include the alpha channel in the color
147
+ */
148
+ respectAlpha?: boolean;
149
+ }
150
+ interface TransparencyGridProps {
151
+ size?: string;
152
+ }
105
153
  interface MachineApi<T extends PropTypes = PropTypes> {
106
154
  /**
107
155
  * Whether the color picker is being dragged
108
156
  */
109
157
  isDragging: boolean;
110
158
  /**
111
- * The current color value (as a string)
159
+ * Whether the color picker is open
112
160
  */
113
- value: string;
161
+ isOpen: boolean;
114
162
  /**
115
- * The current color value (as a Color object)
163
+ * The current color value (as a string)
116
164
  */
117
- valueAsColor: Color;
165
+ value: Color;
118
166
  /**
119
- * The alpha value of the color
167
+ * The current color value (as a Color object)
120
168
  */
121
- alpha: number;
169
+ valueAsString: string;
122
170
  /**
123
171
  * The current color channels of the color
124
172
  */
@@ -127,34 +175,55 @@ interface MachineApi<T extends PropTypes = PropTypes> {
127
175
  * Function to set the color value
128
176
  */
129
177
  setColor(value: string | Color): void;
178
+ /**
179
+ * Function to set the color value
180
+ */
181
+ getChannelValue(channel: ColorChannel): string;
130
182
  /**
131
183
  * Function to set the color value of a specific channel
132
184
  */
133
185
  setChannelValue(channel: ColorChannel, value: number): void;
186
+ /**
187
+ * The current color format
188
+ */
189
+ format: ColorFormat;
134
190
  /**
135
191
  * Function to set the color format
136
192
  */
137
193
  setFormat(format: ColorFormat): void;
194
+ /**
195
+ * The alpha value of the color
196
+ */
197
+ alpha: number;
138
198
  /**
139
199
  * Function to set the color alpha
140
200
  */
141
201
  setAlpha(value: number): void;
202
+ rootProps: T["element"];
203
+ labelProps: T["element"];
204
+ controlProps: T["element"];
205
+ triggerProps: T["button"];
206
+ positionerProps: T["element"];
142
207
  contentProps: T["element"];
143
208
  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"];
209
+ getAreaProps(props?: AreaProps): T["element"];
210
+ getAreaBackgroundProps(props?: AreaProps): T["element"];
211
+ getAreaThumbProps(props?: AreaProps): T["element"];
212
+ getChannelSliderProps(props: ChannelProps): T["element"];
213
+ getChannelSliderTrackProps(props: ChannelProps): T["element"];
214
+ getChannelSliderThumbProps(props: ChannelProps): T["element"];
215
+ getChannelInputProps(props: ChannelInputProps): T["input"];
216
+ getTransparencyGridProps(props?: TransparencyGridProps): T["element"];
151
217
  eyeDropperTriggerProps: T["button"];
152
- getSwatchBackgroundProps(props: ColorSwatchProps): T["element"];
153
- getSwatchProps(props: ColorSwatchProps): T["element"];
218
+ swatchGroupProps: T["element"];
219
+ getSwatchTriggerProps(props: SwatchTriggerProps): T["button"];
220
+ getSwatchProps(props: SwatchProps): T["element"];
154
221
  }
155
222
 
156
223
  declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
157
224
 
158
225
  declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
159
226
 
160
- export { MachineApi as Api, ColorAreaProps, ColorChannelInputProps, ColorChannelProps, ColorSwatchProps, UserDefinedContext as Context, anatomy, connect, machine };
227
+ declare const parse: (color: string) => Color;
228
+
229
+ export { MachineApi as Api, AreaProps, ChannelInputProps, ChannelProps, UserDefinedContext as Context, SwatchProps, SwatchTriggerProps, TransparencyGridProps, anatomy, connect, machine, parse };