@zag-js/color-picker 0.28.1 → 0.30.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,6 +1,6 @@
1
1
  import * as _zag_js_anatomy from '@zag-js/anatomy';
2
2
  import { RequiredBy, Orientation, PropTypes, CommonProperties, MaybeElement, Context, NormalizeProps } from '@zag-js/types';
3
- import { ColorChannel, Color, ColorFormat } from '@zag-js/color-utils';
3
+ import { Color, ColorChannel, 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';
@@ -8,8 +8,9 @@ import { InteractOutsideHandlers } from '@zag-js/dismissable';
8
8
  import { PositioningOptions } from '@zag-js/popper';
9
9
  import { MaybeFunction } from '@zag-js/utils';
10
10
 
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">;
11
+ declare const anatomy: _zag_js_anatomy.Anatomy<"root" | "label" | "control" | "trigger" | "positioner" | "content" | "area" | "areaThumb" | "areaBackground" | "channelSlider" | "channelSliderTrack" | "channelSliderThumb" | "channelInput" | "transparencyGrid" | "swatchGroup" | "swatchTrigger" | "swatchIndicator" | "swatch" | "eyeDropperTrigger" | "formatTrigger" | "formatSelect">;
12
12
 
13
+ type ExtendedColorChannel = ColorChannel | "hex" | "css";
13
14
  interface ValueChangeDetails {
14
15
  value: Color;
15
16
  valueAsString: string;
@@ -17,7 +18,9 @@ interface ValueChangeDetails {
17
18
  interface OpenChangeDetails {
18
19
  open: boolean;
19
20
  }
20
- type ExtendedColorChannel = ColorChannel | "hex" | "css";
21
+ interface FormatChangeDetails {
22
+ format: ColorFormat;
23
+ }
21
24
  type ElementIds = Partial<{
22
25
  root: string;
23
26
  control: string;
@@ -73,11 +76,6 @@ interface PublicContext extends CommonProperties, InteractOutsideHandlers {
73
76
  * The positioning options for the color picker
74
77
  */
75
78
  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
79
  /**
82
80
  * The initial focus element when the color picker is opened.
83
81
  */
@@ -86,6 +84,18 @@ interface PublicContext extends CommonProperties, InteractOutsideHandlers {
86
84
  * Whether the color picker is open
87
85
  */
88
86
  open?: boolean;
87
+ /**
88
+ * The color format to use
89
+ */
90
+ format: ColorFormat;
91
+ /**
92
+ * Function called when the color format changes
93
+ */
94
+ onFormatChange?: (details: FormatChangeDetails) => void;
95
+ /**
96
+ * Whether to close the color picker when a swatch is selected
97
+ */
98
+ closeOnSelect?: boolean;
89
99
  }
90
100
  type PrivateContext = Context<{}>;
91
101
  type ComputedContext = Readonly<{
@@ -109,6 +119,11 @@ type ComputedContext = Readonly<{
109
119
  * Whether the color picker is disabled
110
120
  */
111
121
  isDisabled: boolean;
122
+ /**
123
+ * @computed
124
+ * The area value as a Color object
125
+ */
126
+ areaValue: Color;
112
127
  }>;
113
128
  type UserDefinedContext = RequiredBy<PublicContext, "id">;
114
129
  interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
@@ -136,6 +151,16 @@ interface SwatchTriggerProps {
136
151
  * The color value
137
152
  */
138
153
  value: string | Color;
154
+ /**
155
+ * Whether the swatch trigger is disabled
156
+ */
157
+ disabled?: boolean;
158
+ }
159
+ interface SwatchTriggerState {
160
+ value: Color;
161
+ valueAsString: string;
162
+ isChecked: boolean;
163
+ isDisabled: boolean;
139
164
  }
140
165
  interface SwatchProps {
141
166
  /**
@@ -195,6 +220,14 @@ interface MachineApi<T extends PropTypes = PropTypes> {
195
220
  * Function to set the color alpha
196
221
  */
197
222
  setAlpha(value: number): void;
223
+ /**
224
+ * Function to open the color picker
225
+ */
226
+ open(): void;
227
+ /**
228
+ * Function to close the color picker
229
+ */
230
+ close(): void;
198
231
  rootProps: T["element"];
199
232
  labelProps: T["element"];
200
233
  controlProps: T["element"];
@@ -213,13 +246,17 @@ interface MachineApi<T extends PropTypes = PropTypes> {
213
246
  eyeDropperTriggerProps: T["button"];
214
247
  swatchGroupProps: T["element"];
215
248
  getSwatchTriggerProps(props: SwatchTriggerProps): T["button"];
249
+ getSwatchTriggerState(props: SwatchTriggerProps): SwatchTriggerState;
216
250
  getSwatchProps(props: SwatchProps): T["element"];
251
+ getSwatchIndicatorProps(props: SwatchProps): T["element"];
252
+ formatSelectProps: T["select"];
253
+ formatTriggerProps: T["button"];
217
254
  }
218
255
 
219
256
  declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
220
257
 
221
258
  declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
222
259
 
223
- declare const parse: (color: string) => Color;
260
+ declare const parse: (colorString: string) => Color;
224
261
 
225
- export { MachineApi as Api, AreaProps, ChannelInputProps, ChannelProps, UserDefinedContext as Context, SwatchProps, SwatchTriggerProps, TransparencyGridProps, anatomy, connect, machine, parse };
262
+ export { MachineApi as Api, AreaProps, ChannelInputProps, ChannelProps, UserDefinedContext as Context, ElementIds, OpenChangeDetails, SwatchProps, SwatchTriggerProps, SwatchTriggerState, TransparencyGridProps, ValueChangeDetails, anatomy, connect, machine, parse };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _zag_js_anatomy from '@zag-js/anatomy';
2
2
  import { RequiredBy, Orientation, PropTypes, CommonProperties, MaybeElement, Context, NormalizeProps } from '@zag-js/types';
3
- import { ColorChannel, Color, ColorFormat } from '@zag-js/color-utils';
3
+ import { Color, ColorChannel, 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';
@@ -8,8 +8,9 @@ import { InteractOutsideHandlers } from '@zag-js/dismissable';
8
8
  import { PositioningOptions } from '@zag-js/popper';
9
9
  import { MaybeFunction } from '@zag-js/utils';
10
10
 
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">;
11
+ declare const anatomy: _zag_js_anatomy.Anatomy<"root" | "label" | "control" | "trigger" | "positioner" | "content" | "area" | "areaThumb" | "areaBackground" | "channelSlider" | "channelSliderTrack" | "channelSliderThumb" | "channelInput" | "transparencyGrid" | "swatchGroup" | "swatchTrigger" | "swatchIndicator" | "swatch" | "eyeDropperTrigger" | "formatTrigger" | "formatSelect">;
12
12
 
13
+ type ExtendedColorChannel = ColorChannel | "hex" | "css";
13
14
  interface ValueChangeDetails {
14
15
  value: Color;
15
16
  valueAsString: string;
@@ -17,7 +18,9 @@ interface ValueChangeDetails {
17
18
  interface OpenChangeDetails {
18
19
  open: boolean;
19
20
  }
20
- type ExtendedColorChannel = ColorChannel | "hex" | "css";
21
+ interface FormatChangeDetails {
22
+ format: ColorFormat;
23
+ }
21
24
  type ElementIds = Partial<{
22
25
  root: string;
23
26
  control: string;
@@ -73,11 +76,6 @@ interface PublicContext extends CommonProperties, InteractOutsideHandlers {
73
76
  * The positioning options for the color picker
74
77
  */
75
78
  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
79
  /**
82
80
  * The initial focus element when the color picker is opened.
83
81
  */
@@ -86,6 +84,18 @@ interface PublicContext extends CommonProperties, InteractOutsideHandlers {
86
84
  * Whether the color picker is open
87
85
  */
88
86
  open?: boolean;
87
+ /**
88
+ * The color format to use
89
+ */
90
+ format: ColorFormat;
91
+ /**
92
+ * Function called when the color format changes
93
+ */
94
+ onFormatChange?: (details: FormatChangeDetails) => void;
95
+ /**
96
+ * Whether to close the color picker when a swatch is selected
97
+ */
98
+ closeOnSelect?: boolean;
89
99
  }
90
100
  type PrivateContext = Context<{}>;
91
101
  type ComputedContext = Readonly<{
@@ -109,6 +119,11 @@ type ComputedContext = Readonly<{
109
119
  * Whether the color picker is disabled
110
120
  */
111
121
  isDisabled: boolean;
122
+ /**
123
+ * @computed
124
+ * The area value as a Color object
125
+ */
126
+ areaValue: Color;
112
127
  }>;
113
128
  type UserDefinedContext = RequiredBy<PublicContext, "id">;
114
129
  interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
@@ -136,6 +151,16 @@ interface SwatchTriggerProps {
136
151
  * The color value
137
152
  */
138
153
  value: string | Color;
154
+ /**
155
+ * Whether the swatch trigger is disabled
156
+ */
157
+ disabled?: boolean;
158
+ }
159
+ interface SwatchTriggerState {
160
+ value: Color;
161
+ valueAsString: string;
162
+ isChecked: boolean;
163
+ isDisabled: boolean;
139
164
  }
140
165
  interface SwatchProps {
141
166
  /**
@@ -195,6 +220,14 @@ interface MachineApi<T extends PropTypes = PropTypes> {
195
220
  * Function to set the color alpha
196
221
  */
197
222
  setAlpha(value: number): void;
223
+ /**
224
+ * Function to open the color picker
225
+ */
226
+ open(): void;
227
+ /**
228
+ * Function to close the color picker
229
+ */
230
+ close(): void;
198
231
  rootProps: T["element"];
199
232
  labelProps: T["element"];
200
233
  controlProps: T["element"];
@@ -213,13 +246,17 @@ interface MachineApi<T extends PropTypes = PropTypes> {
213
246
  eyeDropperTriggerProps: T["button"];
214
247
  swatchGroupProps: T["element"];
215
248
  getSwatchTriggerProps(props: SwatchTriggerProps): T["button"];
249
+ getSwatchTriggerState(props: SwatchTriggerProps): SwatchTriggerState;
216
250
  getSwatchProps(props: SwatchProps): T["element"];
251
+ getSwatchIndicatorProps(props: SwatchProps): T["element"];
252
+ formatSelectProps: T["select"];
253
+ formatTriggerProps: T["button"];
217
254
  }
218
255
 
219
256
  declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
220
257
 
221
258
  declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
222
259
 
223
- declare const parse: (color: string) => Color;
260
+ declare const parse: (colorString: string) => Color;
224
261
 
225
- export { MachineApi as Api, AreaProps, ChannelInputProps, ChannelProps, UserDefinedContext as Context, SwatchProps, SwatchTriggerProps, TransparencyGridProps, anatomy, connect, machine, parse };
262
+ export { MachineApi as Api, AreaProps, ChannelInputProps, ChannelProps, UserDefinedContext as Context, ElementIds, OpenChangeDetails, SwatchProps, SwatchTriggerProps, SwatchTriggerState, TransparencyGridProps, ValueChangeDetails, anatomy, connect, machine, parse };