@zag-js/color-picker 0.24.0 → 0.26.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 +10 -16
- package/dist/index.d.ts +10 -16
- package/dist/index.js +60 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +14 -14
- package/src/color-picker.anatomy.ts +1 -1
- package/src/color-picker.connect.ts +27 -16
- package/src/color-picker.dom.ts +4 -1
- package/src/color-picker.machine.ts +16 -6
- package/src/color-picker.parse.ts +11 -1
- package/src/color-picker.types.ts +8 -14
- package/src/index.ts +2 -0
- package/src/utils/get-slider-background.ts +11 -9
|
@@ -76,16 +76,6 @@ interface PublicContext extends CommonProperties, InteractOutsideHandlers {
|
|
|
76
76
|
* The name for the form input
|
|
77
77
|
*/
|
|
78
78
|
name?: string
|
|
79
|
-
/**
|
|
80
|
-
* The color format to use (rgb, hsl, hsb)
|
|
81
|
-
* @default "hsl"
|
|
82
|
-
*/
|
|
83
|
-
format?: ColorFormat
|
|
84
|
-
/**
|
|
85
|
-
* The alpha format to use (decimal, percent)
|
|
86
|
-
* @default "decimal"
|
|
87
|
-
*/
|
|
88
|
-
alphaFormat?: "decimal" | "percent"
|
|
89
79
|
/**
|
|
90
80
|
* The positioning options for the color picker
|
|
91
81
|
*/
|
|
@@ -206,8 +196,8 @@ export interface SwatchProps {
|
|
|
206
196
|
respectAlpha?: boolean
|
|
207
197
|
}
|
|
208
198
|
|
|
209
|
-
export interface
|
|
210
|
-
size
|
|
199
|
+
export interface TransparencyGridProps {
|
|
200
|
+
size?: string
|
|
211
201
|
}
|
|
212
202
|
|
|
213
203
|
export interface MachineApi<T extends PropTypes = PropTypes> {
|
|
@@ -243,6 +233,10 @@ export interface MachineApi<T extends PropTypes = PropTypes> {
|
|
|
243
233
|
* Function to set the color value of a specific channel
|
|
244
234
|
*/
|
|
245
235
|
setChannelValue(channel: ColorChannel, value: number): void
|
|
236
|
+
/**
|
|
237
|
+
* The current color format
|
|
238
|
+
*/
|
|
239
|
+
format: ColorFormat
|
|
246
240
|
/**
|
|
247
241
|
* Function to set the color format
|
|
248
242
|
*/
|
|
@@ -250,7 +244,7 @@ export interface MachineApi<T extends PropTypes = PropTypes> {
|
|
|
250
244
|
/**
|
|
251
245
|
* The alpha value of the color
|
|
252
246
|
*/
|
|
253
|
-
|
|
247
|
+
alpha: number
|
|
254
248
|
/**
|
|
255
249
|
* Function to set the color alpha
|
|
256
250
|
*/
|
|
@@ -273,7 +267,7 @@ export interface MachineApi<T extends PropTypes = PropTypes> {
|
|
|
273
267
|
getChannelSliderThumbProps(props: ChannelProps): T["element"]
|
|
274
268
|
getChannelInputProps(props: ChannelInputProps): T["input"]
|
|
275
269
|
|
|
276
|
-
getTransparencyGridProps(props
|
|
270
|
+
getTransparencyGridProps(props?: TransparencyGridProps): T["element"]
|
|
277
271
|
|
|
278
272
|
eyeDropperTriggerProps: T["button"]
|
|
279
273
|
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChannelProps, MachineContext } from "../color-picker.types"
|
|
1
|
+
import type { ChannelProps, Color, MachineContext } from "../color-picker.types"
|
|
2
2
|
|
|
3
3
|
function getSliderBackgroundDirection(orientation: "vertical" | "horizontal", dir: "ltr" | "rtl") {
|
|
4
4
|
if (orientation === "vertical") {
|
|
@@ -10,22 +10,24 @@ function getSliderBackgroundDirection(orientation: "vertical" | "horizontal", di
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const value = ctx.value
|
|
13
|
+
interface SliderBackgroundProps extends Required<ChannelProps> {
|
|
14
|
+
value: Color
|
|
15
|
+
dir: MachineContext["dir"]
|
|
16
|
+
}
|
|
18
17
|
|
|
18
|
+
export const getSliderBackground = (props: SliderBackgroundProps) => {
|
|
19
|
+
const { channel, value, dir } = props
|
|
20
|
+
const bgDirection = getSliderBackgroundDirection(props.orientation, dir!)
|
|
19
21
|
const { minValue, maxValue } = value.getChannelRange(channel)
|
|
20
22
|
|
|
21
23
|
switch (channel) {
|
|
22
24
|
case "hue":
|
|
23
|
-
return `linear-gradient(to ${
|
|
25
|
+
return `linear-gradient(to ${bgDirection}, rgb(255, 0, 0) 0%, rgb(255, 255, 0) 17%, rgb(0, 255, 0) 33%, rgb(0, 255, 255) 50%, rgb(0, 0, 255) 67%, rgb(255, 0, 255) 83%, rgb(255, 0, 0) 100%)`
|
|
24
26
|
case "lightness": {
|
|
25
27
|
let start = value.withChannelValue(channel, minValue).toString("css")
|
|
26
28
|
let middle = value.withChannelValue(channel, (maxValue - minValue) / 2).toString("css")
|
|
27
29
|
let end = value.withChannelValue(channel, maxValue).toString("css")
|
|
28
|
-
return `linear-gradient(to ${
|
|
30
|
+
return `linear-gradient(to ${bgDirection}, ${start}, ${middle}, ${end})`
|
|
29
31
|
}
|
|
30
32
|
case "saturation":
|
|
31
33
|
case "brightness":
|
|
@@ -35,7 +37,7 @@ export const getSliderBackground = (ctx: MachineContext, props: Required<Channel
|
|
|
35
37
|
case "alpha": {
|
|
36
38
|
let start = value.withChannelValue(channel, minValue).toString("css")
|
|
37
39
|
let end = value.withChannelValue(channel, maxValue).toString("css")
|
|
38
|
-
return `linear-gradient(to ${
|
|
40
|
+
return `linear-gradient(to ${bgDirection}, ${start}, ${end})`
|
|
39
41
|
}
|
|
40
42
|
default:
|
|
41
43
|
throw new Error("Unknown color channel: " + channel)
|