@zag-js/color-picker 0.53.0 → 0.55.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.
@@ -91,85 +91,97 @@ export function connect<T extends PropTypes>(state: State, send: Send, normalize
91
91
  send({ type: "VALUE.SET", value: color, src: "set-alpha" })
92
92
  },
93
93
 
94
- rootProps: normalize.element({
95
- ...parts.root.attrs,
96
- dir: state.context.dir,
97
- id: dom.getRootId(state.context),
98
- "data-disabled": dataAttr(disabled),
99
- "data-readonly": dataAttr(state.context.readOnly),
100
- style: {
101
- "--value": value.toString("css"),
102
- },
103
- }),
104
-
105
- labelProps: normalize.element({
106
- ...parts.label.attrs,
107
- dir: state.context.dir,
108
- id: dom.getLabelId(state.context),
109
- htmlFor: dom.getHiddenInputId(state.context),
110
- "data-disabled": dataAttr(disabled),
111
- "data-readonly": dataAttr(state.context.readOnly),
112
- "data-focus": dataAttr(focused),
113
- onClick(event) {
114
- event.preventDefault()
115
- const inputEl = query(dom.getControlEl(state.context), "[data-channel=hex]")
116
- inputEl?.focus({ preventScroll: true })
117
- },
118
- }),
119
-
120
- controlProps: normalize.element({
121
- ...parts.control.attrs,
122
- id: dom.getControlId(state.context),
123
- dir: state.context.dir,
124
- "data-disabled": dataAttr(disabled),
125
- "data-readonly": dataAttr(state.context.readOnly),
126
- "data-state": open ? "open" : "closed",
127
- "data-focus": dataAttr(focused),
128
- }),
129
-
130
- triggerProps: normalize.button({
131
- ...parts.trigger.attrs,
132
- id: dom.getTriggerId(state.context),
133
- dir: state.context.dir,
134
- disabled: disabled,
135
- "aria-label": `select color. current color is ${valueAsString}`,
136
- "aria-controls": dom.getContentId(state.context),
137
- "aria-labelledby": dom.getLabelId(state.context),
138
- "data-disabled": dataAttr(disabled),
139
- "data-readonly": dataAttr(state.context.readOnly),
140
- "data-placement": currentPlacement,
141
- "aria-expanded": dataAttr(open),
142
- "data-state": open ? "open" : "closed",
143
- "data-focus": dataAttr(focused),
144
- type: "button",
145
- onClick() {
146
- if (!interactive) return
147
- send({ type: "TRIGGER.CLICK" })
148
- },
149
- onBlur() {
150
- if (!interactive) return
151
- send({ type: "TRIGGER.BLUR" })
152
- },
153
- style: {
154
- position: "relative",
155
- },
156
- }),
157
-
158
- positionerProps: normalize.element({
159
- ...parts.positioner.attrs,
160
- id: dom.getPositionerId(state.context),
161
- dir: state.context.dir,
162
- style: popperStyles.floating,
163
- }),
164
-
165
- contentProps: normalize.element({
166
- ...parts.content.attrs,
167
- id: dom.getContentId(state.context),
168
- dir: state.context.dir,
169
- "data-placement": currentPlacement,
170
- "data-state": open ? "open" : "closed",
171
- hidden: !open,
172
- }),
94
+ getRootProps() {
95
+ return normalize.element({
96
+ ...parts.root.attrs,
97
+ dir: state.context.dir,
98
+ id: dom.getRootId(state.context),
99
+ "data-disabled": dataAttr(disabled),
100
+ "data-readonly": dataAttr(state.context.readOnly),
101
+ style: {
102
+ "--value": value.toString("css"),
103
+ },
104
+ })
105
+ },
106
+
107
+ getLabelProps() {
108
+ return normalize.element({
109
+ ...parts.label.attrs,
110
+ dir: state.context.dir,
111
+ id: dom.getLabelId(state.context),
112
+ htmlFor: dom.getHiddenInputId(state.context),
113
+ "data-disabled": dataAttr(disabled),
114
+ "data-readonly": dataAttr(state.context.readOnly),
115
+ "data-focus": dataAttr(focused),
116
+ onClick(event) {
117
+ event.preventDefault()
118
+ const inputEl = query(dom.getControlEl(state.context), "[data-channel=hex]")
119
+ inputEl?.focus({ preventScroll: true })
120
+ },
121
+ })
122
+ },
123
+
124
+ getControlProps() {
125
+ return normalize.element({
126
+ ...parts.control.attrs,
127
+ id: dom.getControlId(state.context),
128
+ dir: state.context.dir,
129
+ "data-disabled": dataAttr(disabled),
130
+ "data-readonly": dataAttr(state.context.readOnly),
131
+ "data-state": open ? "open" : "closed",
132
+ "data-focus": dataAttr(focused),
133
+ })
134
+ },
135
+
136
+ getTriggerProps() {
137
+ return normalize.button({
138
+ ...parts.trigger.attrs,
139
+ id: dom.getTriggerId(state.context),
140
+ dir: state.context.dir,
141
+ disabled: disabled,
142
+ "aria-label": `select color. current color is ${valueAsString}`,
143
+ "aria-controls": dom.getContentId(state.context),
144
+ "aria-labelledby": dom.getLabelId(state.context),
145
+ "data-disabled": dataAttr(disabled),
146
+ "data-readonly": dataAttr(state.context.readOnly),
147
+ "data-placement": currentPlacement,
148
+ "aria-expanded": dataAttr(open),
149
+ "data-state": open ? "open" : "closed",
150
+ "data-focus": dataAttr(focused),
151
+ type: "button",
152
+ onClick() {
153
+ if (!interactive) return
154
+ send({ type: "TRIGGER.CLICK" })
155
+ },
156
+ onBlur() {
157
+ if (!interactive) return
158
+ send({ type: "TRIGGER.BLUR" })
159
+ },
160
+ style: {
161
+ position: "relative",
162
+ },
163
+ })
164
+ },
165
+
166
+ getPositionerProps() {
167
+ return normalize.element({
168
+ ...parts.positioner.attrs,
169
+ id: dom.getPositionerId(state.context),
170
+ dir: state.context.dir,
171
+ style: popperStyles.floating,
172
+ })
173
+ },
174
+
175
+ getContentProps() {
176
+ return normalize.element({
177
+ ...parts.content.attrs,
178
+ id: dom.getContentId(state.context),
179
+ dir: state.context.dir,
180
+ "data-placement": currentPlacement,
181
+ "data-state": open ? "open" : "closed",
182
+ hidden: !open,
183
+ })
184
+ },
173
185
 
174
186
  getAreaProps(props = {}) {
175
187
  const { xChannel, yChannel } = getAreaChannels(props)
@@ -501,49 +513,55 @@ export function connect<T extends PropTypes>(state: State, send: Send, normalize
501
513
  })
502
514
  },
503
515
 
504
- hiddenInputProps: normalize.input({
505
- type: "text",
506
- disabled: disabled,
507
- name: state.context.name,
508
- id: dom.getHiddenInputId(state.context),
509
- style: visuallyHiddenStyle,
510
- defaultValue: valueAsString,
511
- }),
512
-
513
- eyeDropperTriggerProps: normalize.button({
514
- ...parts.eyeDropperTrigger.attrs,
515
- type: "button",
516
- dir: state.context.dir,
517
- disabled: disabled,
518
- "data-disabled": dataAttr(disabled),
519
- "aria-label": "Pick a color from the screen",
520
- onClick() {
521
- if (!interactive) return
522
- send("EYEDROPPER.CLICK")
523
- },
524
- }),
525
-
526
- swatchGroupProps: normalize.element({
527
- ...parts.swatchGroup.attrs,
528
- role: "group",
529
- }),
516
+ getHiddenInputProps() {
517
+ return normalize.input({
518
+ type: "text",
519
+ disabled: disabled,
520
+ name: state.context.name,
521
+ id: dom.getHiddenInputId(state.context),
522
+ style: visuallyHiddenStyle,
523
+ defaultValue: valueAsString,
524
+ })
525
+ },
526
+
527
+ getEyeDropperTriggerProps() {
528
+ return normalize.button({
529
+ ...parts.eyeDropperTrigger.attrs,
530
+ type: "button",
531
+ dir: state.context.dir,
532
+ disabled: disabled,
533
+ "data-disabled": dataAttr(disabled),
534
+ "aria-label": "Pick a color from the screen",
535
+ onClick() {
536
+ if (!interactive) return
537
+ send("EYEDROPPER.CLICK")
538
+ },
539
+ })
540
+ },
541
+
542
+ getSwatchGroupProps() {
543
+ return normalize.element({
544
+ ...parts.swatchGroup.attrs,
545
+ role: "group",
546
+ })
547
+ },
530
548
 
531
549
  getSwatchTriggerState,
532
550
 
533
551
  getSwatchTriggerProps(props) {
534
- const triggerState = getSwatchTriggerState(props)
552
+ const swatchState = getSwatchTriggerState(props)
535
553
  return normalize.button({
536
554
  ...parts.swatchTrigger.attrs,
537
- disabled: triggerState.disabled,
555
+ disabled: swatchState.disabled,
538
556
  dir: state.context.dir,
539
557
  type: "button",
540
- "aria-label": `select ${triggerState.valueAsString} as the color`,
541
- "data-state": triggerState.checked ? "checked" : "unchecked",
542
- "data-value": triggerState.valueAsString,
543
- "data-disabled": dataAttr(triggerState.disabled),
558
+ "aria-label": `select ${swatchState.valueAsString} as the color`,
559
+ "data-state": swatchState.checked ? "checked" : "unchecked",
560
+ "data-value": swatchState.valueAsString,
561
+ "data-disabled": dataAttr(swatchState.disabled),
544
562
  onClick() {
545
- if (triggerState.disabled) return
546
- send({ type: "SWATCH_TRIGGER.CLICK", value: triggerState.value })
563
+ if (swatchState.disabled) return
564
+ send({ type: "SWATCH_TRIGGER.CLICK", value: swatchState.value })
547
565
  },
548
566
  style: {
549
567
  position: "relative",
@@ -552,52 +570,56 @@ export function connect<T extends PropTypes>(state: State, send: Send, normalize
552
570
  },
553
571
 
554
572
  getSwatchIndicatorProps(props) {
555
- const triggerState = getSwatchTriggerState(props)
573
+ const swatchState = getSwatchTriggerState(props)
556
574
  return normalize.element({
557
575
  ...parts.swatchIndicator.attrs,
558
576
  dir: state.context.dir,
559
- hidden: !triggerState.checked,
577
+ hidden: !swatchState.checked,
560
578
  })
561
579
  },
562
580
 
563
581
  getSwatchProps(props) {
564
582
  const { respectAlpha = true } = props
565
- const triggerState = getSwatchTriggerState(props)
583
+ const swatchState = getSwatchTriggerState(props)
566
584
  return normalize.element({
567
585
  ...parts.swatch.attrs,
568
586
  dir: state.context.dir,
569
- "data-state": triggerState.checked ? "checked" : "unchecked",
570
- "data-value": triggerState.valueAsString,
587
+ "data-state": swatchState.checked ? "checked" : "unchecked",
588
+ "data-value": swatchState.valueAsString,
571
589
  style: {
572
590
  position: "relative",
573
- background: triggerState.value.toString(respectAlpha ? "css" : "hex"),
591
+ background: swatchState.value.toString(respectAlpha ? "css" : "hex"),
574
592
  },
575
593
  })
576
594
  },
577
595
 
578
- formatTriggerProps: normalize.button({
579
- ...parts.formatTrigger.attrs,
580
- dir: state.context.dir,
581
- type: "button",
582
- "aria-label": `change color format to ${getNextFormat(state.context.format)}`,
583
- onClick(event) {
584
- if (event.currentTarget.disabled) return
585
- const nextFormat = getNextFormat(state.context.format)
586
- send({ type: "FORMAT.SET", format: nextFormat, src: "format-trigger" })
587
- },
588
- }),
589
-
590
- formatSelectProps: normalize.select({
591
- ...parts.formatSelect.attrs,
592
- "aria-label": "change color format",
593
- dir: state.context.dir,
594
- defaultValue: state.context.format,
595
- disabled: disabled,
596
- onChange(event) {
597
- const format = assertFormat(event.currentTarget.value)
598
- send({ type: "FORMAT.SET", format, src: "format-select" })
599
- },
600
- }),
596
+ getFormatTriggerProps() {
597
+ return normalize.button({
598
+ ...parts.formatTrigger.attrs,
599
+ dir: state.context.dir,
600
+ type: "button",
601
+ "aria-label": `change color format to ${getNextFormat(state.context.format)}`,
602
+ onClick(event) {
603
+ if (event.currentTarget.disabled) return
604
+ const nextFormat = getNextFormat(state.context.format)
605
+ send({ type: "FORMAT.SET", format: nextFormat, src: "format-trigger" })
606
+ },
607
+ })
608
+ },
609
+
610
+ getFormatSelectProps() {
611
+ return normalize.select({
612
+ ...parts.formatSelect.attrs,
613
+ "aria-label": "change color format",
614
+ dir: state.context.dir,
615
+ defaultValue: state.context.format,
616
+ disabled: disabled,
617
+ onChange(event) {
618
+ const format = assertFormat(event.currentTarget.value)
619
+ send({ type: "FORMAT.SET", format, src: "format-select" })
620
+ },
621
+ })
622
+ },
601
623
  }
602
624
  }
603
625
 
@@ -296,13 +296,13 @@ export interface MachineApi<T extends PropTypes = PropTypes> {
296
296
  */
297
297
  setOpen(open: boolean): void
298
298
 
299
- rootProps: T["element"]
300
- labelProps: T["element"]
301
- controlProps: T["element"]
302
- triggerProps: T["button"]
303
- positionerProps: T["element"]
304
- contentProps: T["element"]
305
- hiddenInputProps: T["input"]
299
+ getRootProps(): T["element"]
300
+ getLabelProps(): T["element"]
301
+ getControlProps(): T["element"]
302
+ getTriggerProps(): T["button"]
303
+ getPositionerProps(): T["element"]
304
+ getContentProps(): T["element"]
305
+ getHiddenInputProps(): T["input"]
306
306
 
307
307
  getAreaProps(props?: AreaProps): T["element"]
308
308
  getAreaBackgroundProps(props?: AreaProps): T["element"]
@@ -315,16 +315,16 @@ export interface MachineApi<T extends PropTypes = PropTypes> {
315
315
 
316
316
  getTransparencyGridProps(props?: TransparencyGridProps): T["element"]
317
317
 
318
- eyeDropperTriggerProps: T["button"]
318
+ getEyeDropperTriggerProps(): T["button"]
319
319
 
320
- swatchGroupProps: T["element"]
320
+ getSwatchGroupProps(): T["element"]
321
321
  getSwatchTriggerProps(props: SwatchTriggerProps): T["button"]
322
322
  getSwatchTriggerState(props: SwatchTriggerProps): SwatchTriggerState
323
323
  getSwatchProps(props: SwatchProps): T["element"]
324
324
  getSwatchIndicatorProps(props: SwatchProps): T["element"]
325
325
 
326
- formatSelectProps: T["select"]
327
- formatTriggerProps: T["button"]
326
+ getFormatSelectProps(): T["select"]
327
+ getFormatTriggerProps(): T["button"]
328
328
  }
329
329
 
330
330
  /* -----------------------------------------------------------------------------