@zag-js/color-picker 0.77.0 → 0.78.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 +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +29 -2
- package/dist/index.mjs +29 -2
- package/package.json +12 -12
package/dist/index.d.mts
CHANGED
|
@@ -75,6 +75,10 @@ interface PublicContext extends CommonProperties, DirectionProperty, InteractOut
|
|
|
75
75
|
* Whether the color picker is required
|
|
76
76
|
*/
|
|
77
77
|
required?: boolean | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* Whether the color picker is invalid
|
|
80
|
+
*/
|
|
81
|
+
invalid?: boolean | undefined;
|
|
78
82
|
/**
|
|
79
83
|
* Handler that is called when the value changes, as the user drags.
|
|
80
84
|
*/
|
|
@@ -121,6 +125,11 @@ interface PublicContext extends CommonProperties, DirectionProperty, InteractOut
|
|
|
121
125
|
* @default false
|
|
122
126
|
*/
|
|
123
127
|
closeOnSelect?: boolean | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* Whether to auto focus the color picker when it is opened
|
|
130
|
+
* @default true
|
|
131
|
+
*/
|
|
132
|
+
openAutoFocus?: boolean | undefined;
|
|
124
133
|
}
|
|
125
134
|
interface PrivateContext {
|
|
126
135
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -75,6 +75,10 @@ interface PublicContext extends CommonProperties, DirectionProperty, InteractOut
|
|
|
75
75
|
* Whether the color picker is required
|
|
76
76
|
*/
|
|
77
77
|
required?: boolean | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* Whether the color picker is invalid
|
|
80
|
+
*/
|
|
81
|
+
invalid?: boolean | undefined;
|
|
78
82
|
/**
|
|
79
83
|
* Handler that is called when the value changes, as the user drags.
|
|
80
84
|
*/
|
|
@@ -121,6 +125,11 @@ interface PublicContext extends CommonProperties, DirectionProperty, InteractOut
|
|
|
121
125
|
* @default false
|
|
122
126
|
*/
|
|
123
127
|
closeOnSelect?: boolean | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* Whether to auto focus the color picker when it is opened
|
|
130
|
+
* @default true
|
|
131
|
+
*/
|
|
132
|
+
openAutoFocus?: boolean | undefined;
|
|
124
133
|
}
|
|
125
134
|
interface PrivateContext {
|
|
126
135
|
}
|
package/dist/index.js
CHANGED
|
@@ -274,6 +274,7 @@ function connect(state, send, normalize) {
|
|
|
274
274
|
id: dom.getRootId(state.context),
|
|
275
275
|
"data-disabled": domQuery.dataAttr(disabled),
|
|
276
276
|
"data-readonly": domQuery.dataAttr(state.context.readOnly),
|
|
277
|
+
"data-invalid": domQuery.dataAttr(state.context.invalid),
|
|
277
278
|
style: {
|
|
278
279
|
"--value": value.toString("css")
|
|
279
280
|
}
|
|
@@ -287,6 +288,7 @@ function connect(state, send, normalize) {
|
|
|
287
288
|
htmlFor: dom.getHiddenInputId(state.context),
|
|
288
289
|
"data-disabled": domQuery.dataAttr(disabled),
|
|
289
290
|
"data-readonly": domQuery.dataAttr(state.context.readOnly),
|
|
291
|
+
"data-invalid": domQuery.dataAttr(state.context.invalid),
|
|
290
292
|
"data-focus": domQuery.dataAttr(focused),
|
|
291
293
|
onClick(event) {
|
|
292
294
|
event.preventDefault();
|
|
@@ -302,6 +304,7 @@ function connect(state, send, normalize) {
|
|
|
302
304
|
dir: state.context.dir,
|
|
303
305
|
"data-disabled": domQuery.dataAttr(disabled),
|
|
304
306
|
"data-readonly": domQuery.dataAttr(state.context.readOnly),
|
|
307
|
+
"data-invalid": domQuery.dataAttr(state.context.invalid),
|
|
305
308
|
"data-state": open ? "open" : "closed",
|
|
306
309
|
"data-focus": domQuery.dataAttr(focused)
|
|
307
310
|
});
|
|
@@ -317,6 +320,7 @@ function connect(state, send, normalize) {
|
|
|
317
320
|
"aria-labelledby": dom.getLabelId(state.context),
|
|
318
321
|
"data-disabled": domQuery.dataAttr(disabled),
|
|
319
322
|
"data-readonly": domQuery.dataAttr(state.context.readOnly),
|
|
323
|
+
"data-invalid": domQuery.dataAttr(state.context.invalid),
|
|
320
324
|
"data-placement": currentPlacement,
|
|
321
325
|
"aria-expanded": domQuery.dataAttr(open),
|
|
322
326
|
"data-state": open ? "open" : "closed",
|
|
@@ -372,6 +376,9 @@ function connect(state, send, normalize) {
|
|
|
372
376
|
...parts.area.attrs,
|
|
373
377
|
id: dom.getAreaId(state.context),
|
|
374
378
|
role: "group",
|
|
379
|
+
"data-invalid": domQuery.dataAttr(state.context.invalid),
|
|
380
|
+
"data-disabled": domQuery.dataAttr(disabled),
|
|
381
|
+
"data-readonly": domQuery.dataAttr(state.context.readOnly),
|
|
375
382
|
onPointerDown(event) {
|
|
376
383
|
if (!interactive) return;
|
|
377
384
|
if (!domEvent.isLeftClick(event)) return;
|
|
@@ -399,6 +406,9 @@ function connect(state, send, normalize) {
|
|
|
399
406
|
return normalize.element({
|
|
400
407
|
...parts.areaBackground.attrs,
|
|
401
408
|
id: dom.getAreaGradientId(state.context),
|
|
409
|
+
"data-invalid": domQuery.dataAttr(state.context.invalid),
|
|
410
|
+
"data-disabled": domQuery.dataAttr(disabled),
|
|
411
|
+
"data-readonly": domQuery.dataAttr(state.context.readOnly),
|
|
402
412
|
style: {
|
|
403
413
|
position: "relative",
|
|
404
414
|
touchAction: "none",
|
|
@@ -414,12 +424,15 @@ function connect(state, send, normalize) {
|
|
|
414
424
|
const yPercent = 1 - areaValue.getChannelValuePercent(yChannel);
|
|
415
425
|
const xValue = areaValue.getChannelValue(xChannel);
|
|
416
426
|
const yValue = areaValue.getChannelValue(yChannel);
|
|
427
|
+
const color = areaValue.withChannelValue("alpha", 1).toString("css");
|
|
417
428
|
return normalize.element({
|
|
418
429
|
...parts.areaThumb.attrs,
|
|
419
430
|
id: dom.getAreaThumbId(state.context),
|
|
420
431
|
dir: state.context.dir,
|
|
421
432
|
tabIndex: disabled ? void 0 : 0,
|
|
422
433
|
"data-disabled": domQuery.dataAttr(disabled),
|
|
434
|
+
"data-invalid": domQuery.dataAttr(state.context.invalid),
|
|
435
|
+
"data-readonly": domQuery.dataAttr(state.context.readOnly),
|
|
423
436
|
role: "slider",
|
|
424
437
|
"aria-valuemin": 0,
|
|
425
438
|
"aria-valuemax": 100,
|
|
@@ -434,7 +447,8 @@ function connect(state, send, normalize) {
|
|
|
434
447
|
transform: "translate(-50%, -50%)",
|
|
435
448
|
touchAction: "none",
|
|
436
449
|
forcedColorAdjust: "none",
|
|
437
|
-
|
|
450
|
+
"--color": color,
|
|
451
|
+
background: color
|
|
438
452
|
},
|
|
439
453
|
onFocus() {
|
|
440
454
|
if (!interactive) return;
|
|
@@ -645,6 +659,8 @@ function connect(state, send, normalize) {
|
|
|
645
659
|
autoComplete: "off",
|
|
646
660
|
disabled,
|
|
647
661
|
"data-disabled": domQuery.dataAttr(disabled),
|
|
662
|
+
"data-invalid": domQuery.dataAttr(state.context.invalid),
|
|
663
|
+
"data-readonly": domQuery.dataAttr(state.context.readOnly),
|
|
648
664
|
readOnly: state.context.readOnly,
|
|
649
665
|
defaultValue: getChannelValue(value, channel),
|
|
650
666
|
min: channelRange?.minValue,
|
|
@@ -688,6 +704,7 @@ function connect(state, send, normalize) {
|
|
|
688
704
|
type: "text",
|
|
689
705
|
disabled,
|
|
690
706
|
name: state.context.name,
|
|
707
|
+
tabIndex: -1,
|
|
691
708
|
readOnly: state.context.readOnly,
|
|
692
709
|
required: state.context.required,
|
|
693
710
|
id: dom.getHiddenInputId(state.context),
|
|
@@ -702,6 +719,8 @@ function connect(state, send, normalize) {
|
|
|
702
719
|
dir: state.context.dir,
|
|
703
720
|
disabled,
|
|
704
721
|
"data-disabled": domQuery.dataAttr(disabled),
|
|
722
|
+
"data-invalid": domQuery.dataAttr(state.context.invalid),
|
|
723
|
+
"data-readonly": domQuery.dataAttr(state.context.readOnly),
|
|
705
724
|
"aria-label": "Pick a color from the screen",
|
|
706
725
|
onClick() {
|
|
707
726
|
if (!interactive) return;
|
|
@@ -732,6 +751,7 @@ function connect(state, send, normalize) {
|
|
|
732
751
|
send({ type: "SWATCH_TRIGGER.CLICK", value: swatchState.value });
|
|
733
752
|
},
|
|
734
753
|
style: {
|
|
754
|
+
"--color": swatchState.valueAsString,
|
|
735
755
|
position: "relative"
|
|
736
756
|
}
|
|
737
757
|
});
|
|
@@ -747,14 +767,16 @@ function connect(state, send, normalize) {
|
|
|
747
767
|
getSwatchProps(props) {
|
|
748
768
|
const { respectAlpha = true } = props;
|
|
749
769
|
const swatchState = getSwatchTriggerState(props);
|
|
770
|
+
const color = swatchState.value.toString(respectAlpha ? "css" : "hex");
|
|
750
771
|
return normalize.element({
|
|
751
772
|
...parts.swatch.attrs,
|
|
752
773
|
dir: state.context.dir,
|
|
753
774
|
"data-state": swatchState.checked ? "checked" : "unchecked",
|
|
754
775
|
"data-value": swatchState.valueAsString,
|
|
755
776
|
style: {
|
|
777
|
+
"--color": color,
|
|
756
778
|
position: "relative",
|
|
757
|
-
background:
|
|
779
|
+
background: color
|
|
758
780
|
}
|
|
759
781
|
});
|
|
760
782
|
},
|
|
@@ -814,6 +836,7 @@ function machine(userContext) {
|
|
|
814
836
|
format: "rgba",
|
|
815
837
|
disabled: false,
|
|
816
838
|
closeOnSelect: false,
|
|
839
|
+
openAutoFocus: true,
|
|
817
840
|
...ctx,
|
|
818
841
|
activeId: null,
|
|
819
842
|
activeChannel: null,
|
|
@@ -853,6 +876,9 @@ function machine(userContext) {
|
|
|
853
876
|
},
|
|
854
877
|
"EYEDROPPER.CLICK": {
|
|
855
878
|
actions: ["openEyeDropper"]
|
|
879
|
+
},
|
|
880
|
+
"SWATCH_TRIGGER.CLICK": {
|
|
881
|
+
actions: ["setValue"]
|
|
856
882
|
}
|
|
857
883
|
},
|
|
858
884
|
states: {
|
|
@@ -1299,6 +1325,7 @@ function machine(userContext) {
|
|
|
1299
1325
|
});
|
|
1300
1326
|
},
|
|
1301
1327
|
setInitialFocus(ctx2) {
|
|
1328
|
+
if (!ctx2.openAutoFocus) return;
|
|
1302
1329
|
domQuery.raf(() => {
|
|
1303
1330
|
const element = domQuery.getInitialFocus({
|
|
1304
1331
|
root: dom.getContentEl(ctx2),
|
package/dist/index.mjs
CHANGED
|
@@ -272,6 +272,7 @@ function connect(state, send, normalize) {
|
|
|
272
272
|
id: dom.getRootId(state.context),
|
|
273
273
|
"data-disabled": dataAttr(disabled),
|
|
274
274
|
"data-readonly": dataAttr(state.context.readOnly),
|
|
275
|
+
"data-invalid": dataAttr(state.context.invalid),
|
|
275
276
|
style: {
|
|
276
277
|
"--value": value.toString("css")
|
|
277
278
|
}
|
|
@@ -285,6 +286,7 @@ function connect(state, send, normalize) {
|
|
|
285
286
|
htmlFor: dom.getHiddenInputId(state.context),
|
|
286
287
|
"data-disabled": dataAttr(disabled),
|
|
287
288
|
"data-readonly": dataAttr(state.context.readOnly),
|
|
289
|
+
"data-invalid": dataAttr(state.context.invalid),
|
|
288
290
|
"data-focus": dataAttr(focused),
|
|
289
291
|
onClick(event) {
|
|
290
292
|
event.preventDefault();
|
|
@@ -300,6 +302,7 @@ function connect(state, send, normalize) {
|
|
|
300
302
|
dir: state.context.dir,
|
|
301
303
|
"data-disabled": dataAttr(disabled),
|
|
302
304
|
"data-readonly": dataAttr(state.context.readOnly),
|
|
305
|
+
"data-invalid": dataAttr(state.context.invalid),
|
|
303
306
|
"data-state": open ? "open" : "closed",
|
|
304
307
|
"data-focus": dataAttr(focused)
|
|
305
308
|
});
|
|
@@ -315,6 +318,7 @@ function connect(state, send, normalize) {
|
|
|
315
318
|
"aria-labelledby": dom.getLabelId(state.context),
|
|
316
319
|
"data-disabled": dataAttr(disabled),
|
|
317
320
|
"data-readonly": dataAttr(state.context.readOnly),
|
|
321
|
+
"data-invalid": dataAttr(state.context.invalid),
|
|
318
322
|
"data-placement": currentPlacement,
|
|
319
323
|
"aria-expanded": dataAttr(open),
|
|
320
324
|
"data-state": open ? "open" : "closed",
|
|
@@ -370,6 +374,9 @@ function connect(state, send, normalize) {
|
|
|
370
374
|
...parts.area.attrs,
|
|
371
375
|
id: dom.getAreaId(state.context),
|
|
372
376
|
role: "group",
|
|
377
|
+
"data-invalid": dataAttr(state.context.invalid),
|
|
378
|
+
"data-disabled": dataAttr(disabled),
|
|
379
|
+
"data-readonly": dataAttr(state.context.readOnly),
|
|
373
380
|
onPointerDown(event) {
|
|
374
381
|
if (!interactive) return;
|
|
375
382
|
if (!isLeftClick(event)) return;
|
|
@@ -397,6 +404,9 @@ function connect(state, send, normalize) {
|
|
|
397
404
|
return normalize.element({
|
|
398
405
|
...parts.areaBackground.attrs,
|
|
399
406
|
id: dom.getAreaGradientId(state.context),
|
|
407
|
+
"data-invalid": dataAttr(state.context.invalid),
|
|
408
|
+
"data-disabled": dataAttr(disabled),
|
|
409
|
+
"data-readonly": dataAttr(state.context.readOnly),
|
|
400
410
|
style: {
|
|
401
411
|
position: "relative",
|
|
402
412
|
touchAction: "none",
|
|
@@ -412,12 +422,15 @@ function connect(state, send, normalize) {
|
|
|
412
422
|
const yPercent = 1 - areaValue.getChannelValuePercent(yChannel);
|
|
413
423
|
const xValue = areaValue.getChannelValue(xChannel);
|
|
414
424
|
const yValue = areaValue.getChannelValue(yChannel);
|
|
425
|
+
const color = areaValue.withChannelValue("alpha", 1).toString("css");
|
|
415
426
|
return normalize.element({
|
|
416
427
|
...parts.areaThumb.attrs,
|
|
417
428
|
id: dom.getAreaThumbId(state.context),
|
|
418
429
|
dir: state.context.dir,
|
|
419
430
|
tabIndex: disabled ? void 0 : 0,
|
|
420
431
|
"data-disabled": dataAttr(disabled),
|
|
432
|
+
"data-invalid": dataAttr(state.context.invalid),
|
|
433
|
+
"data-readonly": dataAttr(state.context.readOnly),
|
|
421
434
|
role: "slider",
|
|
422
435
|
"aria-valuemin": 0,
|
|
423
436
|
"aria-valuemax": 100,
|
|
@@ -432,7 +445,8 @@ function connect(state, send, normalize) {
|
|
|
432
445
|
transform: "translate(-50%, -50%)",
|
|
433
446
|
touchAction: "none",
|
|
434
447
|
forcedColorAdjust: "none",
|
|
435
|
-
|
|
448
|
+
"--color": color,
|
|
449
|
+
background: color
|
|
436
450
|
},
|
|
437
451
|
onFocus() {
|
|
438
452
|
if (!interactive) return;
|
|
@@ -643,6 +657,8 @@ function connect(state, send, normalize) {
|
|
|
643
657
|
autoComplete: "off",
|
|
644
658
|
disabled,
|
|
645
659
|
"data-disabled": dataAttr(disabled),
|
|
660
|
+
"data-invalid": dataAttr(state.context.invalid),
|
|
661
|
+
"data-readonly": dataAttr(state.context.readOnly),
|
|
646
662
|
readOnly: state.context.readOnly,
|
|
647
663
|
defaultValue: getChannelValue(value, channel),
|
|
648
664
|
min: channelRange?.minValue,
|
|
@@ -686,6 +702,7 @@ function connect(state, send, normalize) {
|
|
|
686
702
|
type: "text",
|
|
687
703
|
disabled,
|
|
688
704
|
name: state.context.name,
|
|
705
|
+
tabIndex: -1,
|
|
689
706
|
readOnly: state.context.readOnly,
|
|
690
707
|
required: state.context.required,
|
|
691
708
|
id: dom.getHiddenInputId(state.context),
|
|
@@ -700,6 +717,8 @@ function connect(state, send, normalize) {
|
|
|
700
717
|
dir: state.context.dir,
|
|
701
718
|
disabled,
|
|
702
719
|
"data-disabled": dataAttr(disabled),
|
|
720
|
+
"data-invalid": dataAttr(state.context.invalid),
|
|
721
|
+
"data-readonly": dataAttr(state.context.readOnly),
|
|
703
722
|
"aria-label": "Pick a color from the screen",
|
|
704
723
|
onClick() {
|
|
705
724
|
if (!interactive) return;
|
|
@@ -730,6 +749,7 @@ function connect(state, send, normalize) {
|
|
|
730
749
|
send({ type: "SWATCH_TRIGGER.CLICK", value: swatchState.value });
|
|
731
750
|
},
|
|
732
751
|
style: {
|
|
752
|
+
"--color": swatchState.valueAsString,
|
|
733
753
|
position: "relative"
|
|
734
754
|
}
|
|
735
755
|
});
|
|
@@ -745,14 +765,16 @@ function connect(state, send, normalize) {
|
|
|
745
765
|
getSwatchProps(props) {
|
|
746
766
|
const { respectAlpha = true } = props;
|
|
747
767
|
const swatchState = getSwatchTriggerState(props);
|
|
768
|
+
const color = swatchState.value.toString(respectAlpha ? "css" : "hex");
|
|
748
769
|
return normalize.element({
|
|
749
770
|
...parts.swatch.attrs,
|
|
750
771
|
dir: state.context.dir,
|
|
751
772
|
"data-state": swatchState.checked ? "checked" : "unchecked",
|
|
752
773
|
"data-value": swatchState.valueAsString,
|
|
753
774
|
style: {
|
|
775
|
+
"--color": color,
|
|
754
776
|
position: "relative",
|
|
755
|
-
background:
|
|
777
|
+
background: color
|
|
756
778
|
}
|
|
757
779
|
});
|
|
758
780
|
},
|
|
@@ -812,6 +834,7 @@ function machine(userContext) {
|
|
|
812
834
|
format: "rgba",
|
|
813
835
|
disabled: false,
|
|
814
836
|
closeOnSelect: false,
|
|
837
|
+
openAutoFocus: true,
|
|
815
838
|
...ctx,
|
|
816
839
|
activeId: null,
|
|
817
840
|
activeChannel: null,
|
|
@@ -851,6 +874,9 @@ function machine(userContext) {
|
|
|
851
874
|
},
|
|
852
875
|
"EYEDROPPER.CLICK": {
|
|
853
876
|
actions: ["openEyeDropper"]
|
|
877
|
+
},
|
|
878
|
+
"SWATCH_TRIGGER.CLICK": {
|
|
879
|
+
actions: ["setValue"]
|
|
854
880
|
}
|
|
855
881
|
},
|
|
856
882
|
states: {
|
|
@@ -1297,6 +1323,7 @@ function machine(userContext) {
|
|
|
1297
1323
|
});
|
|
1298
1324
|
},
|
|
1299
1325
|
setInitialFocus(ctx2) {
|
|
1326
|
+
if (!ctx2.openAutoFocus) return;
|
|
1300
1327
|
raf(() => {
|
|
1301
1328
|
const element = getInitialFocus({
|
|
1302
1329
|
root: dom.getContentEl(ctx2),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/color-picker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.78.0",
|
|
4
4
|
"description": "Core logic for the color-picker widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -27,17 +27,17 @@
|
|
|
27
27
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@zag-js/core": "0.
|
|
31
|
-
"@zag-js/anatomy": "0.
|
|
32
|
-
"@zag-js/dom-query": "0.
|
|
33
|
-
"@zag-js/dismissable": "0.
|
|
34
|
-
"@zag-js/dom-event": "0.
|
|
35
|
-
"@zag-js/utils": "0.
|
|
36
|
-
"@zag-js/form-utils": "0.
|
|
37
|
-
"@zag-js/color-utils": "0.
|
|
38
|
-
"@zag-js/popper": "0.
|
|
39
|
-
"@zag-js/text-selection": "0.
|
|
40
|
-
"@zag-js/types": "0.
|
|
30
|
+
"@zag-js/core": "0.78.0",
|
|
31
|
+
"@zag-js/anatomy": "0.78.0",
|
|
32
|
+
"@zag-js/dom-query": "0.78.0",
|
|
33
|
+
"@zag-js/dismissable": "0.78.0",
|
|
34
|
+
"@zag-js/dom-event": "0.78.0",
|
|
35
|
+
"@zag-js/utils": "0.78.0",
|
|
36
|
+
"@zag-js/form-utils": "0.78.0",
|
|
37
|
+
"@zag-js/color-utils": "0.78.0",
|
|
38
|
+
"@zag-js/popper": "0.78.0",
|
|
39
|
+
"@zag-js/text-selection": "0.78.0",
|
|
40
|
+
"@zag-js/types": "0.78.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"clean-package": "2.2.0"
|