@zag-js/color-picker 0.82.2 → 1.0.1

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,11 +1,11 @@
1
1
  import { InteractOutsideHandlers } from '@zag-js/dismissable';
2
2
  export { FocusOutsideEvent, InteractOutsideEvent, PointerDownOutsideEvent } from '@zag-js/dismissable';
3
3
  import * as _zag_js_anatomy from '@zag-js/anatomy';
4
- import { RequiredBy, Orientation, PropTypes, CommonProperties, DirectionProperty, NormalizeProps } from '@zag-js/types';
5
- import { Color, ColorFormat, ColorChannel } from '@zag-js/color-utils';
4
+ import { CommonProperties, DirectionProperty, Orientation, PropTypes, RequiredBy, NormalizeProps } from '@zag-js/types';
5
+ import { Color, ColorFormat, ColorChannel, ColorAxes } from '@zag-js/color-utils';
6
6
  export { Color, ColorAxes, ColorChannel, ColorFormat, ColorType } from '@zag-js/color-utils';
7
7
  import * as _zag_js_core from '@zag-js/core';
8
- import { Machine, StateMachine } from '@zag-js/core';
8
+ import { Service, Machine, EventObject } from '@zag-js/core';
9
9
  import { PositioningOptions } from '@zag-js/popper';
10
10
  export { PositioningOptions } from '@zag-js/popper';
11
11
 
@@ -53,16 +53,21 @@ type ElementIds = Partial<{
53
53
  channelSliderTrack(id: ColorChannel): string;
54
54
  channelSliderThumb(id: ColorChannel): string;
55
55
  }>;
56
- interface PublicContext extends CommonProperties, DirectionProperty, InteractOutsideHandlers {
56
+ interface ColorPickerProps extends CommonProperties, DirectionProperty, InteractOutsideHandlers {
57
57
  /**
58
58
  * The ids of the elements in the color picker. Useful for composition.
59
59
  */
60
60
  ids?: ElementIds | undefined;
61
61
  /**
62
- * The current color value
62
+ * The controlled color value of the color picker
63
+ */
64
+ value?: Color | undefined;
65
+ /**
66
+ * The initial color value when rendered.
67
+ * Use when you don't need to control the color value of the color picker.
63
68
  * @default #000000
64
69
  */
65
- value: Color;
70
+ defaultValue?: Color | undefined;
66
71
  /**
67
72
  * Whether the color picker is disabled
68
73
  */
@@ -98,24 +103,30 @@ interface PublicContext extends CommonProperties, DirectionProperty, InteractOut
98
103
  /**
99
104
  * The positioning options for the color picker
100
105
  */
101
- positioning: PositioningOptions;
106
+ positioning?: PositioningOptions | undefined;
102
107
  /**
103
108
  * The initial focus element when the color picker is opened.
104
109
  */
105
110
  initialFocusEl?: (() => HTMLElement | null) | undefined;
106
111
  /**
107
- * Whether the color picker is open
112
+ * The controlled open state of the color picker
108
113
  */
109
114
  open?: boolean | undefined;
110
115
  /**
111
- * Whether the color picker open state is controlled by the user
116
+ * The initial open state of the color picker when rendered.
117
+ * Use when you don't need to control the open state of the color picker.
112
118
  */
113
- "open.controlled"?: boolean | undefined;
119
+ defaultOpen?: boolean | undefined;
120
+ /**
121
+ * The controlled color format to use
122
+ */
123
+ format?: ColorFormat | undefined;
114
124
  /**
115
- * The color format to use
125
+ * The initial color format when rendered.
126
+ * Use when you don't need to control the color format of the color picker.
116
127
  * @default "rgba"
117
128
  */
118
- format: ColorFormat;
129
+ defaultFormat?: ColorFormat | undefined;
119
130
  /**
120
131
  * Function called when the color format changes
121
132
  */
@@ -131,45 +142,35 @@ interface PublicContext extends CommonProperties, DirectionProperty, InteractOut
131
142
  */
132
143
  openAutoFocus?: boolean | undefined;
133
144
  }
134
- interface PrivateContext {
135
- }
136
- type ComputedContext = Readonly<{
137
- /**
138
- * @computed
139
- * Whether the color picker is in RTL mode
140
- */
141
- isRtl: boolean;
142
- /**
143
- * @computed
144
- * Whether the color picker is interactive
145
- */
146
- isInteractive: boolean;
147
- /**
148
- * @computed
149
- * The color value as a Color object
150
- */
151
- valueAsString: string;
152
- /**
153
- * @computed
154
- * Whether the color picker is disabled
155
- */
156
- isDisabled: boolean;
157
- /**
158
- * @computed
159
- * The area value as a Color object
160
- */
161
- areaValue: Color;
162
- }>;
163
- type UserDefinedContext = RequiredBy<PublicContext, "id">;
164
- interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
165
- }
166
- interface MachineState {
167
- tags: "open" | "closed" | "dragging" | "focused";
168
- value: "idle" | "focused" | "open" | "open:dragging";
169
- }
170
- type State = StateMachine.State<MachineContext, MachineState>;
171
- type Send = StateMachine.Send<StateMachine.AnyEventObject>;
172
- type Service = Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
145
+ type PropsWithDefault = "defaultFormat" | "defaultValue" | "openAutoFocus" | "dir" | "positioning";
146
+ type ColorPickerSchema = {
147
+ tag: "open" | "closed" | "dragging" | "focused";
148
+ state: "idle" | "focused" | "open" | "open:dragging";
149
+ props: RequiredBy<ColorPickerProps, PropsWithDefault>;
150
+ computed: {
151
+ disabled: boolean;
152
+ rtl: boolean;
153
+ interactive: boolean;
154
+ valueAsString: string;
155
+ areaValue: Color;
156
+ };
157
+ context: {
158
+ format: ColorFormat;
159
+ value: Color;
160
+ activeId: string | null;
161
+ activeChannel: Partial<ColorAxes> | null;
162
+ activeOrientation: Orientation | null;
163
+ fieldsetDisabled: boolean;
164
+ currentPlacement: PositioningOptions["placement"] | undefined;
165
+ restoreFocus: boolean;
166
+ };
167
+ event: EventObject;
168
+ action: string;
169
+ effect: string;
170
+ guard: string;
171
+ };
172
+ type ColorPickerService = Service<ColorPickerSchema>;
173
+ type ColorPickerMachine = Machine<ColorPickerSchema>;
173
174
  interface ChannelProps {
174
175
  channel: ColorChannel;
175
176
  orientation?: Orientation | undefined;
@@ -214,7 +215,7 @@ interface SwatchProps {
214
215
  interface TransparencyGridProps {
215
216
  size?: string | undefined;
216
217
  }
217
- interface MachineApi<T extends PropTypes = PropTypes> {
218
+ interface ColorPickerApi<T extends PropTypes = PropTypes> {
218
219
  /**
219
220
  * Whether the color picker is being dragged
220
221
  */
@@ -295,10 +296,23 @@ interface MachineApi<T extends PropTypes = PropTypes> {
295
296
  getFormatTriggerProps(): T["button"];
296
297
  }
297
298
 
298
- declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
299
+ declare function connect<T extends PropTypes>(service: ColorPickerService, normalize: NormalizeProps<T>): ColorPickerApi<T>;
299
300
 
300
- declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
301
+ declare const machine: _zag_js_core.Machine<ColorPickerSchema>;
301
302
 
302
303
  declare const parse: (colorString: string) => Color;
303
304
 
304
- export { type MachineApi as Api, type AreaProps, type ChannelInputProps, type ChannelProps, type ChannelSliderProps, type UserDefinedContext as Context, type ElementIds, type FormatChangeDetails, type OpenChangeDetails, type Service, type SwatchProps, type SwatchTriggerProps, type SwatchTriggerState, type TransparencyGridProps, type ValueChangeDetails, anatomy, connect, machine, parse };
305
+ declare const props: (keyof ColorPickerProps)[];
306
+ declare const splitProps: <Props extends Partial<ColorPickerProps>>(props: Props) => [Partial<ColorPickerProps>, Omit<Props, keyof ColorPickerProps>];
307
+ declare const areaProps: (keyof AreaProps)[];
308
+ declare const splitAreaProps: <Props extends AreaProps>(props: Props) => [AreaProps, Omit<Props, keyof AreaProps>];
309
+ declare const channelProps: (keyof ChannelProps)[];
310
+ declare const splitChannelProps: <Props extends ChannelProps>(props: Props) => [ChannelProps, Omit<Props, keyof ChannelProps>];
311
+ declare const swatchTriggerProps: (keyof SwatchTriggerProps)[];
312
+ declare const splitSwatchTriggerProps: <Props extends SwatchTriggerProps>(props: Props) => [SwatchTriggerProps, Omit<Props, keyof SwatchTriggerProps>];
313
+ declare const swatchProps: (keyof SwatchProps)[];
314
+ declare const splitSwatchProps: <Props extends SwatchProps>(props: Props) => [SwatchProps, Omit<Props, keyof SwatchProps>];
315
+ declare const transparencyGridProps: "size"[];
316
+ declare const splitTransparencyGridProps: <Props extends TransparencyGridProps>(props: Props) => [TransparencyGridProps, Omit<Props, "size">];
317
+
318
+ export { type ColorPickerApi as Api, type AreaProps, type ChannelInputProps, type ChannelProps, type ChannelSliderProps, type ElementIds, type FormatChangeDetails, type ColorPickerMachine as Machine, type OpenChangeDetails, type ColorPickerProps as Props, type ColorPickerService as Service, type SwatchProps, type SwatchTriggerProps, type SwatchTriggerState, type TransparencyGridProps, type ValueChangeDetails, anatomy, areaProps, channelProps, connect, machine, parse, props, splitAreaProps, splitChannelProps, splitProps, splitSwatchProps, splitSwatchTriggerProps, splitTransparencyGridProps, swatchProps, swatchTriggerProps, transparencyGridProps };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { InteractOutsideHandlers } from '@zag-js/dismissable';
2
2
  export { FocusOutsideEvent, InteractOutsideEvent, PointerDownOutsideEvent } from '@zag-js/dismissable';
3
3
  import * as _zag_js_anatomy from '@zag-js/anatomy';
4
- import { RequiredBy, Orientation, PropTypes, CommonProperties, DirectionProperty, NormalizeProps } from '@zag-js/types';
5
- import { Color, ColorFormat, ColorChannel } from '@zag-js/color-utils';
4
+ import { CommonProperties, DirectionProperty, Orientation, PropTypes, RequiredBy, NormalizeProps } from '@zag-js/types';
5
+ import { Color, ColorFormat, ColorChannel, ColorAxes } from '@zag-js/color-utils';
6
6
  export { Color, ColorAxes, ColorChannel, ColorFormat, ColorType } from '@zag-js/color-utils';
7
7
  import * as _zag_js_core from '@zag-js/core';
8
- import { Machine, StateMachine } from '@zag-js/core';
8
+ import { Service, Machine, EventObject } from '@zag-js/core';
9
9
  import { PositioningOptions } from '@zag-js/popper';
10
10
  export { PositioningOptions } from '@zag-js/popper';
11
11
 
@@ -53,16 +53,21 @@ type ElementIds = Partial<{
53
53
  channelSliderTrack(id: ColorChannel): string;
54
54
  channelSliderThumb(id: ColorChannel): string;
55
55
  }>;
56
- interface PublicContext extends CommonProperties, DirectionProperty, InteractOutsideHandlers {
56
+ interface ColorPickerProps extends CommonProperties, DirectionProperty, InteractOutsideHandlers {
57
57
  /**
58
58
  * The ids of the elements in the color picker. Useful for composition.
59
59
  */
60
60
  ids?: ElementIds | undefined;
61
61
  /**
62
- * The current color value
62
+ * The controlled color value of the color picker
63
+ */
64
+ value?: Color | undefined;
65
+ /**
66
+ * The initial color value when rendered.
67
+ * Use when you don't need to control the color value of the color picker.
63
68
  * @default #000000
64
69
  */
65
- value: Color;
70
+ defaultValue?: Color | undefined;
66
71
  /**
67
72
  * Whether the color picker is disabled
68
73
  */
@@ -98,24 +103,30 @@ interface PublicContext extends CommonProperties, DirectionProperty, InteractOut
98
103
  /**
99
104
  * The positioning options for the color picker
100
105
  */
101
- positioning: PositioningOptions;
106
+ positioning?: PositioningOptions | undefined;
102
107
  /**
103
108
  * The initial focus element when the color picker is opened.
104
109
  */
105
110
  initialFocusEl?: (() => HTMLElement | null) | undefined;
106
111
  /**
107
- * Whether the color picker is open
112
+ * The controlled open state of the color picker
108
113
  */
109
114
  open?: boolean | undefined;
110
115
  /**
111
- * Whether the color picker open state is controlled by the user
116
+ * The initial open state of the color picker when rendered.
117
+ * Use when you don't need to control the open state of the color picker.
112
118
  */
113
- "open.controlled"?: boolean | undefined;
119
+ defaultOpen?: boolean | undefined;
120
+ /**
121
+ * The controlled color format to use
122
+ */
123
+ format?: ColorFormat | undefined;
114
124
  /**
115
- * The color format to use
125
+ * The initial color format when rendered.
126
+ * Use when you don't need to control the color format of the color picker.
116
127
  * @default "rgba"
117
128
  */
118
- format: ColorFormat;
129
+ defaultFormat?: ColorFormat | undefined;
119
130
  /**
120
131
  * Function called when the color format changes
121
132
  */
@@ -131,45 +142,35 @@ interface PublicContext extends CommonProperties, DirectionProperty, InteractOut
131
142
  */
132
143
  openAutoFocus?: boolean | undefined;
133
144
  }
134
- interface PrivateContext {
135
- }
136
- type ComputedContext = Readonly<{
137
- /**
138
- * @computed
139
- * Whether the color picker is in RTL mode
140
- */
141
- isRtl: boolean;
142
- /**
143
- * @computed
144
- * Whether the color picker is interactive
145
- */
146
- isInteractive: boolean;
147
- /**
148
- * @computed
149
- * The color value as a Color object
150
- */
151
- valueAsString: string;
152
- /**
153
- * @computed
154
- * Whether the color picker is disabled
155
- */
156
- isDisabled: boolean;
157
- /**
158
- * @computed
159
- * The area value as a Color object
160
- */
161
- areaValue: Color;
162
- }>;
163
- type UserDefinedContext = RequiredBy<PublicContext, "id">;
164
- interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
165
- }
166
- interface MachineState {
167
- tags: "open" | "closed" | "dragging" | "focused";
168
- value: "idle" | "focused" | "open" | "open:dragging";
169
- }
170
- type State = StateMachine.State<MachineContext, MachineState>;
171
- type Send = StateMachine.Send<StateMachine.AnyEventObject>;
172
- type Service = Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
145
+ type PropsWithDefault = "defaultFormat" | "defaultValue" | "openAutoFocus" | "dir" | "positioning";
146
+ type ColorPickerSchema = {
147
+ tag: "open" | "closed" | "dragging" | "focused";
148
+ state: "idle" | "focused" | "open" | "open:dragging";
149
+ props: RequiredBy<ColorPickerProps, PropsWithDefault>;
150
+ computed: {
151
+ disabled: boolean;
152
+ rtl: boolean;
153
+ interactive: boolean;
154
+ valueAsString: string;
155
+ areaValue: Color;
156
+ };
157
+ context: {
158
+ format: ColorFormat;
159
+ value: Color;
160
+ activeId: string | null;
161
+ activeChannel: Partial<ColorAxes> | null;
162
+ activeOrientation: Orientation | null;
163
+ fieldsetDisabled: boolean;
164
+ currentPlacement: PositioningOptions["placement"] | undefined;
165
+ restoreFocus: boolean;
166
+ };
167
+ event: EventObject;
168
+ action: string;
169
+ effect: string;
170
+ guard: string;
171
+ };
172
+ type ColorPickerService = Service<ColorPickerSchema>;
173
+ type ColorPickerMachine = Machine<ColorPickerSchema>;
173
174
  interface ChannelProps {
174
175
  channel: ColorChannel;
175
176
  orientation?: Orientation | undefined;
@@ -214,7 +215,7 @@ interface SwatchProps {
214
215
  interface TransparencyGridProps {
215
216
  size?: string | undefined;
216
217
  }
217
- interface MachineApi<T extends PropTypes = PropTypes> {
218
+ interface ColorPickerApi<T extends PropTypes = PropTypes> {
218
219
  /**
219
220
  * Whether the color picker is being dragged
220
221
  */
@@ -295,10 +296,23 @@ interface MachineApi<T extends PropTypes = PropTypes> {
295
296
  getFormatTriggerProps(): T["button"];
296
297
  }
297
298
 
298
- declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
299
+ declare function connect<T extends PropTypes>(service: ColorPickerService, normalize: NormalizeProps<T>): ColorPickerApi<T>;
299
300
 
300
- declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
301
+ declare const machine: _zag_js_core.Machine<ColorPickerSchema>;
301
302
 
302
303
  declare const parse: (colorString: string) => Color;
303
304
 
304
- export { type MachineApi as Api, type AreaProps, type ChannelInputProps, type ChannelProps, type ChannelSliderProps, type UserDefinedContext as Context, type ElementIds, type FormatChangeDetails, type OpenChangeDetails, type Service, type SwatchProps, type SwatchTriggerProps, type SwatchTriggerState, type TransparencyGridProps, type ValueChangeDetails, anatomy, connect, machine, parse };
305
+ declare const props: (keyof ColorPickerProps)[];
306
+ declare const splitProps: <Props extends Partial<ColorPickerProps>>(props: Props) => [Partial<ColorPickerProps>, Omit<Props, keyof ColorPickerProps>];
307
+ declare const areaProps: (keyof AreaProps)[];
308
+ declare const splitAreaProps: <Props extends AreaProps>(props: Props) => [AreaProps, Omit<Props, keyof AreaProps>];
309
+ declare const channelProps: (keyof ChannelProps)[];
310
+ declare const splitChannelProps: <Props extends ChannelProps>(props: Props) => [ChannelProps, Omit<Props, keyof ChannelProps>];
311
+ declare const swatchTriggerProps: (keyof SwatchTriggerProps)[];
312
+ declare const splitSwatchTriggerProps: <Props extends SwatchTriggerProps>(props: Props) => [SwatchTriggerProps, Omit<Props, keyof SwatchTriggerProps>];
313
+ declare const swatchProps: (keyof SwatchProps)[];
314
+ declare const splitSwatchProps: <Props extends SwatchProps>(props: Props) => [SwatchProps, Omit<Props, keyof SwatchProps>];
315
+ declare const transparencyGridProps: "size"[];
316
+ declare const splitTransparencyGridProps: <Props extends TransparencyGridProps>(props: Props) => [TransparencyGridProps, Omit<Props, "size">];
317
+
318
+ export { type ColorPickerApi as Api, type AreaProps, type ChannelInputProps, type ChannelProps, type ChannelSliderProps, type ElementIds, type FormatChangeDetails, type ColorPickerMachine as Machine, type OpenChangeDetails, type ColorPickerProps as Props, type ColorPickerService as Service, type SwatchProps, type SwatchTriggerProps, type SwatchTriggerState, type TransparencyGridProps, type ValueChangeDetails, anatomy, areaProps, channelProps, connect, machine, parse, props, splitAreaProps, splitChannelProps, splitProps, splitSwatchProps, splitSwatchTriggerProps, splitTransparencyGridProps, swatchProps, swatchTriggerProps, transparencyGridProps };