@zag-js/color-picker 1.17.3 → 1.18.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 +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +24 -3
- package/dist/index.mjs +24 -3
- package/package.json +9 -9
package/dist/index.d.mts
CHANGED
|
@@ -141,6 +141,10 @@ interface ColorPickerProps extends CommonProperties, DirectionProperty, Interact
|
|
|
141
141
|
* @default true
|
|
142
142
|
*/
|
|
143
143
|
openAutoFocus?: boolean | undefined;
|
|
144
|
+
/**
|
|
145
|
+
* Whether to render the color picker inline
|
|
146
|
+
*/
|
|
147
|
+
inline?: boolean | undefined;
|
|
144
148
|
}
|
|
145
149
|
type PropsWithDefault = "defaultFormat" | "defaultValue" | "openAutoFocus" | "dir" | "positioning";
|
|
146
150
|
type ColorPickerSchema = {
|
|
@@ -224,6 +228,10 @@ interface ColorPickerApi<T extends PropTypes = PropTypes> {
|
|
|
224
228
|
* Whether the color picker is open
|
|
225
229
|
*/
|
|
226
230
|
open: boolean;
|
|
231
|
+
/**
|
|
232
|
+
* Whether the color picker is rendered inline
|
|
233
|
+
*/
|
|
234
|
+
inline: boolean;
|
|
227
235
|
/**
|
|
228
236
|
* The current color value (as a string)
|
|
229
237
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -141,6 +141,10 @@ interface ColorPickerProps extends CommonProperties, DirectionProperty, Interact
|
|
|
141
141
|
* @default true
|
|
142
142
|
*/
|
|
143
143
|
openAutoFocus?: boolean | undefined;
|
|
144
|
+
/**
|
|
145
|
+
* Whether to render the color picker inline
|
|
146
|
+
*/
|
|
147
|
+
inline?: boolean | undefined;
|
|
144
148
|
}
|
|
145
149
|
type PropsWithDefault = "defaultFormat" | "defaultValue" | "openAutoFocus" | "dir" | "positioning";
|
|
146
150
|
type ColorPickerSchema = {
|
|
@@ -224,6 +228,10 @@ interface ColorPickerApi<T extends PropTypes = PropTypes> {
|
|
|
224
228
|
* Whether the color picker is open
|
|
225
229
|
*/
|
|
226
230
|
open: boolean;
|
|
231
|
+
/**
|
|
232
|
+
* Whether the color picker is rendered inline
|
|
233
|
+
*/
|
|
234
|
+
inline: boolean;
|
|
227
235
|
/**
|
|
228
236
|
* The current color value (as a string)
|
|
229
237
|
*/
|
package/dist/index.js
CHANGED
|
@@ -229,7 +229,9 @@ function connect(service, normalize) {
|
|
|
229
229
|
open,
|
|
230
230
|
valueAsString,
|
|
231
231
|
value,
|
|
232
|
+
inline: !!prop("inline"),
|
|
232
233
|
setOpen(nextOpen) {
|
|
234
|
+
if (prop("inline")) return;
|
|
233
235
|
const open2 = state.hasTag("open");
|
|
234
236
|
if (open2 === nextOpen) return;
|
|
235
237
|
send({ type: nextOpen ? "OPEN" : "CLOSE" });
|
|
@@ -817,6 +819,17 @@ var parse = (colorString) => {
|
|
|
817
819
|
return colorUtils.parseColor(colorString);
|
|
818
820
|
};
|
|
819
821
|
|
|
822
|
+
// src/utils/is-valid-hex.ts
|
|
823
|
+
var HEX_REGEX = /^[0-9a-fA-F]{3,8}$/;
|
|
824
|
+
function isValidHex(value) {
|
|
825
|
+
return HEX_REGEX.test(value);
|
|
826
|
+
}
|
|
827
|
+
function prefixHex(value) {
|
|
828
|
+
if (value.startsWith("#")) return value;
|
|
829
|
+
if (isValidHex(value)) return `#${value}`;
|
|
830
|
+
return value;
|
|
831
|
+
}
|
|
832
|
+
|
|
820
833
|
// src/color-picker.machine.ts
|
|
821
834
|
var { and } = core.createGuards();
|
|
822
835
|
var machine = core.createMachine({
|
|
@@ -834,7 +847,7 @@ var machine = core.createMachine({
|
|
|
834
847
|
};
|
|
835
848
|
},
|
|
836
849
|
initialState({ prop }) {
|
|
837
|
-
const open = prop("open") || prop("defaultOpen");
|
|
850
|
+
const open = prop("open") || prop("defaultOpen") || prop("inline");
|
|
838
851
|
return open ? "open" : "idle";
|
|
839
852
|
},
|
|
840
853
|
context({ prop, bindable, getContext }) {
|
|
@@ -1167,11 +1180,12 @@ var machine = core.createMachine({
|
|
|
1167
1180
|
implementations: {
|
|
1168
1181
|
guards: {
|
|
1169
1182
|
closeOnSelect: ({ prop }) => !!prop("closeOnSelect"),
|
|
1170
|
-
isOpenControlled: ({ prop }) => prop("open") != null,
|
|
1183
|
+
isOpenControlled: ({ prop }) => prop("open") != null || !!prop("inline"),
|
|
1171
1184
|
shouldRestoreFocus: ({ context }) => !!context.get("restoreFocus")
|
|
1172
1185
|
},
|
|
1173
1186
|
effects: {
|
|
1174
1187
|
trackPositioning({ context, prop, scope }) {
|
|
1188
|
+
if (prop("inline")) return;
|
|
1175
1189
|
if (!context.get("currentPlacement")) {
|
|
1176
1190
|
context.set("currentPlacement", prop("positioning")?.placement);
|
|
1177
1191
|
}
|
|
@@ -1186,6 +1200,7 @@ var machine = core.createMachine({
|
|
|
1186
1200
|
});
|
|
1187
1201
|
},
|
|
1188
1202
|
trackDismissableElement({ context, scope, prop, send }) {
|
|
1203
|
+
if (prop("inline")) return;
|
|
1189
1204
|
const getContentEl2 = () => getContentEl(scope);
|
|
1190
1205
|
return dismissable.trackDismissableElement(getContentEl2, {
|
|
1191
1206
|
exclude: getTriggerEl(scope),
|
|
@@ -1303,7 +1318,10 @@ var machine = core.createMachine({
|
|
|
1303
1318
|
color = context.get("value").withChannelValue("alpha", valueAsNumber);
|
|
1304
1319
|
} else if (isTextField) {
|
|
1305
1320
|
color = utils.tryCatch(
|
|
1306
|
-
() =>
|
|
1321
|
+
() => {
|
|
1322
|
+
const parseValue = channel === "hex" ? prefixHex(value) : value;
|
|
1323
|
+
return parse(parseValue).withChannelValue("alpha", currentAlpha);
|
|
1324
|
+
},
|
|
1307
1325
|
() => context.get("value")
|
|
1308
1326
|
);
|
|
1309
1327
|
} else {
|
|
@@ -1387,9 +1405,11 @@ var machine = core.createMachine({
|
|
|
1387
1405
|
syncFormatSelect(scope, context.get("format"));
|
|
1388
1406
|
},
|
|
1389
1407
|
invokeOnOpen({ prop }) {
|
|
1408
|
+
if (prop("inline")) return;
|
|
1390
1409
|
prop("onOpenChange")?.({ open: true });
|
|
1391
1410
|
},
|
|
1392
1411
|
invokeOnClose({ prop }) {
|
|
1412
|
+
if (prop("inline")) return;
|
|
1393
1413
|
prop("onOpenChange")?.({ open: false });
|
|
1394
1414
|
},
|
|
1395
1415
|
toggleVisibility({ prop, event, send }) {
|
|
@@ -1422,6 +1442,7 @@ var props = types.createProps()([
|
|
|
1422
1442
|
"id",
|
|
1423
1443
|
"ids",
|
|
1424
1444
|
"initialFocusEl",
|
|
1445
|
+
"inline",
|
|
1425
1446
|
"name",
|
|
1426
1447
|
"positioning",
|
|
1427
1448
|
"onFocusOutside",
|
package/dist/index.mjs
CHANGED
|
@@ -227,7 +227,9 @@ function connect(service, normalize) {
|
|
|
227
227
|
open,
|
|
228
228
|
valueAsString,
|
|
229
229
|
value,
|
|
230
|
+
inline: !!prop("inline"),
|
|
230
231
|
setOpen(nextOpen) {
|
|
232
|
+
if (prop("inline")) return;
|
|
231
233
|
const open2 = state.hasTag("open");
|
|
232
234
|
if (open2 === nextOpen) return;
|
|
233
235
|
send({ type: nextOpen ? "OPEN" : "CLOSE" });
|
|
@@ -815,6 +817,17 @@ var parse = (colorString) => {
|
|
|
815
817
|
return parseColor(colorString);
|
|
816
818
|
};
|
|
817
819
|
|
|
820
|
+
// src/utils/is-valid-hex.ts
|
|
821
|
+
var HEX_REGEX = /^[0-9a-fA-F]{3,8}$/;
|
|
822
|
+
function isValidHex(value) {
|
|
823
|
+
return HEX_REGEX.test(value);
|
|
824
|
+
}
|
|
825
|
+
function prefixHex(value) {
|
|
826
|
+
if (value.startsWith("#")) return value;
|
|
827
|
+
if (isValidHex(value)) return `#${value}`;
|
|
828
|
+
return value;
|
|
829
|
+
}
|
|
830
|
+
|
|
818
831
|
// src/color-picker.machine.ts
|
|
819
832
|
var { and } = createGuards();
|
|
820
833
|
var machine = createMachine({
|
|
@@ -832,7 +845,7 @@ var machine = createMachine({
|
|
|
832
845
|
};
|
|
833
846
|
},
|
|
834
847
|
initialState({ prop }) {
|
|
835
|
-
const open = prop("open") || prop("defaultOpen");
|
|
848
|
+
const open = prop("open") || prop("defaultOpen") || prop("inline");
|
|
836
849
|
return open ? "open" : "idle";
|
|
837
850
|
},
|
|
838
851
|
context({ prop, bindable, getContext }) {
|
|
@@ -1165,11 +1178,12 @@ var machine = createMachine({
|
|
|
1165
1178
|
implementations: {
|
|
1166
1179
|
guards: {
|
|
1167
1180
|
closeOnSelect: ({ prop }) => !!prop("closeOnSelect"),
|
|
1168
|
-
isOpenControlled: ({ prop }) => prop("open") != null,
|
|
1181
|
+
isOpenControlled: ({ prop }) => prop("open") != null || !!prop("inline"),
|
|
1169
1182
|
shouldRestoreFocus: ({ context }) => !!context.get("restoreFocus")
|
|
1170
1183
|
},
|
|
1171
1184
|
effects: {
|
|
1172
1185
|
trackPositioning({ context, prop, scope }) {
|
|
1186
|
+
if (prop("inline")) return;
|
|
1173
1187
|
if (!context.get("currentPlacement")) {
|
|
1174
1188
|
context.set("currentPlacement", prop("positioning")?.placement);
|
|
1175
1189
|
}
|
|
@@ -1184,6 +1198,7 @@ var machine = createMachine({
|
|
|
1184
1198
|
});
|
|
1185
1199
|
},
|
|
1186
1200
|
trackDismissableElement({ context, scope, prop, send }) {
|
|
1201
|
+
if (prop("inline")) return;
|
|
1187
1202
|
const getContentEl2 = () => getContentEl(scope);
|
|
1188
1203
|
return trackDismissableElement(getContentEl2, {
|
|
1189
1204
|
exclude: getTriggerEl(scope),
|
|
@@ -1301,7 +1316,10 @@ var machine = createMachine({
|
|
|
1301
1316
|
color = context.get("value").withChannelValue("alpha", valueAsNumber);
|
|
1302
1317
|
} else if (isTextField) {
|
|
1303
1318
|
color = tryCatch(
|
|
1304
|
-
() =>
|
|
1319
|
+
() => {
|
|
1320
|
+
const parseValue = channel === "hex" ? prefixHex(value) : value;
|
|
1321
|
+
return parse(parseValue).withChannelValue("alpha", currentAlpha);
|
|
1322
|
+
},
|
|
1305
1323
|
() => context.get("value")
|
|
1306
1324
|
);
|
|
1307
1325
|
} else {
|
|
@@ -1385,9 +1403,11 @@ var machine = createMachine({
|
|
|
1385
1403
|
syncFormatSelect(scope, context.get("format"));
|
|
1386
1404
|
},
|
|
1387
1405
|
invokeOnOpen({ prop }) {
|
|
1406
|
+
if (prop("inline")) return;
|
|
1388
1407
|
prop("onOpenChange")?.({ open: true });
|
|
1389
1408
|
},
|
|
1390
1409
|
invokeOnClose({ prop }) {
|
|
1410
|
+
if (prop("inline")) return;
|
|
1391
1411
|
prop("onOpenChange")?.({ open: false });
|
|
1392
1412
|
},
|
|
1393
1413
|
toggleVisibility({ prop, event, send }) {
|
|
@@ -1420,6 +1440,7 @@ var props = createProps()([
|
|
|
1420
1440
|
"id",
|
|
1421
1441
|
"ids",
|
|
1422
1442
|
"initialFocusEl",
|
|
1443
|
+
"inline",
|
|
1423
1444
|
"name",
|
|
1424
1445
|
"positioning",
|
|
1425
1446
|
"onFocusOutside",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/color-picker",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.0",
|
|
4
4
|
"description": "Core logic for the color-picker widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@zag-js/core": "1.
|
|
31
|
-
"@zag-js/anatomy": "1.
|
|
32
|
-
"@zag-js/dom-query": "1.
|
|
33
|
-
"@zag-js/dismissable": "1.
|
|
34
|
-
"@zag-js/utils": "1.
|
|
35
|
-
"@zag-js/color-utils": "1.
|
|
36
|
-
"@zag-js/popper": "1.
|
|
37
|
-
"@zag-js/types": "1.
|
|
30
|
+
"@zag-js/core": "1.18.0",
|
|
31
|
+
"@zag-js/anatomy": "1.18.0",
|
|
32
|
+
"@zag-js/dom-query": "1.18.0",
|
|
33
|
+
"@zag-js/dismissable": "1.18.0",
|
|
34
|
+
"@zag-js/utils": "1.18.0",
|
|
35
|
+
"@zag-js/color-utils": "1.18.0",
|
|
36
|
+
"@zag-js/popper": "1.18.0",
|
|
37
|
+
"@zag-js/types": "1.18.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"clean-package": "2.2.0"
|