@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.
- package/dist/index.d.mts +11 -11
- package/dist/index.d.ts +11 -11
- package/dist/index.js +1429 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1405 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
- package/src/color-picker.connect.ts +164 -142
- package/src/color-picker.types.ts +11 -11
|
@@ -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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
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
|
|
552
|
+
const swatchState = getSwatchTriggerState(props)
|
|
535
553
|
return normalize.button({
|
|
536
554
|
...parts.swatchTrigger.attrs,
|
|
537
|
-
disabled:
|
|
555
|
+
disabled: swatchState.disabled,
|
|
538
556
|
dir: state.context.dir,
|
|
539
557
|
type: "button",
|
|
540
|
-
"aria-label": `select ${
|
|
541
|
-
"data-state":
|
|
542
|
-
"data-value":
|
|
543
|
-
"data-disabled": dataAttr(
|
|
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 (
|
|
546
|
-
send({ type: "SWATCH_TRIGGER.CLICK", 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
|
|
573
|
+
const swatchState = getSwatchTriggerState(props)
|
|
556
574
|
return normalize.element({
|
|
557
575
|
...parts.swatchIndicator.attrs,
|
|
558
576
|
dir: state.context.dir,
|
|
559
|
-
hidden: !
|
|
577
|
+
hidden: !swatchState.checked,
|
|
560
578
|
})
|
|
561
579
|
},
|
|
562
580
|
|
|
563
581
|
getSwatchProps(props) {
|
|
564
582
|
const { respectAlpha = true } = props
|
|
565
|
-
const
|
|
583
|
+
const swatchState = getSwatchTriggerState(props)
|
|
566
584
|
return normalize.element({
|
|
567
585
|
...parts.swatch.attrs,
|
|
568
586
|
dir: state.context.dir,
|
|
569
|
-
"data-state":
|
|
570
|
-
"data-value":
|
|
587
|
+
"data-state": swatchState.checked ? "checked" : "unchecked",
|
|
588
|
+
"data-value": swatchState.valueAsString,
|
|
571
589
|
style: {
|
|
572
590
|
position: "relative",
|
|
573
|
-
background:
|
|
591
|
+
background: swatchState.value.toString(respectAlpha ? "css" : "hex"),
|
|
574
592
|
},
|
|
575
593
|
})
|
|
576
594
|
},
|
|
577
595
|
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
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
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
-
|
|
318
|
+
getEyeDropperTriggerProps(): T["button"]
|
|
319
319
|
|
|
320
|
-
|
|
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
|
-
|
|
327
|
-
|
|
326
|
+
getFormatSelectProps(): T["select"]
|
|
327
|
+
getFormatTriggerProps(): T["button"]
|
|
328
328
|
}
|
|
329
329
|
|
|
330
330
|
/* -----------------------------------------------------------------------------
|