@zag-js/color-picker 0.56.0 → 0.57.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.
@@ -193,22 +193,22 @@ export function machine(userContext: UserDefinedContext) {
193
193
  actions: ["setActiveChannel"],
194
194
  },
195
195
  "AREA.ARROW_LEFT": {
196
- actions: ["decrementXChannel"],
196
+ actions: ["decrementAreaXChannel"],
197
197
  },
198
198
  "AREA.ARROW_RIGHT": {
199
- actions: ["incrementXChannel"],
199
+ actions: ["incrementAreaXChannel"],
200
200
  },
201
201
  "AREA.ARROW_UP": {
202
- actions: ["incrementYChannel"],
202
+ actions: ["incrementAreaYChannel"],
203
203
  },
204
204
  "AREA.ARROW_DOWN": {
205
- actions: ["decrementYChannel"],
205
+ actions: ["decrementAreaYChannel"],
206
206
  },
207
207
  "AREA.PAGE_UP": {
208
- actions: ["incrementXChannel"],
208
+ actions: ["incrementAreaXChannel"],
209
209
  },
210
210
  "AREA.PAGE_DOWN": {
211
- actions: ["decrementXChannel"],
211
+ actions: ["decrementAreaXChannel"],
212
212
  },
213
213
  "CHANNEL_SLIDER.ARROW_LEFT": {
214
214
  actions: ["decrementChannel"],
@@ -384,11 +384,11 @@ export function machine(userContext: UserDefinedContext) {
384
384
  },
385
385
  })
386
386
  },
387
- trackPointerMove(ctx, _evt, { send }) {
387
+ trackPointerMove(ctx, evt, { send }) {
388
388
  return trackPointerMove(dom.getDoc(ctx), {
389
389
  onPointerMove({ point }) {
390
390
  const type = ctx.activeId === "area" ? "AREA.POINTER_MOVE" : "CHANNEL_SLIDER.POINTER_MOVE"
391
- send({ type, point })
391
+ send({ type, point, format: evt.format })
392
392
  },
393
393
  onPointerUp() {
394
394
  const type = ctx.activeId === "area" ? "AREA.POINTER_UP" : "CHANNEL_SLIDER.POINTER_UP"
@@ -427,19 +427,21 @@ export function machine(userContext: UserDefinedContext) {
427
427
  ctx.activeOrientation = null
428
428
  },
429
429
  setAreaColorFromPoint(ctx, evt) {
430
+ const normalizedValue = evt.format ? ctx.value.toFormat(evt.format) : ctx.areaValue
430
431
  const { xChannel, yChannel } = evt.channel || ctx.activeChannel
431
432
 
432
433
  const percent = dom.getAreaValueFromPoint(ctx, evt.point)
433
434
  if (!percent) return
434
435
 
435
- const xValue = ctx.areaValue.getChannelPercentValue(xChannel, percent.x)
436
- const yValue = ctx.areaValue.getChannelPercentValue(yChannel, 1 - percent.y)
436
+ const xValue = normalizedValue.getChannelPercentValue(xChannel, percent.x)
437
+ const yValue = normalizedValue.getChannelPercentValue(yChannel, 1 - percent.y)
437
438
 
438
- const color = ctx.areaValue.withChannelValue(xChannel, xValue).withChannelValue(yChannel, yValue)
439
+ const color = normalizedValue.withChannelValue(xChannel, xValue).withChannelValue(yChannel, yValue)
439
440
  set.value(ctx, color)
440
441
  },
441
442
  setChannelColorFromPoint(ctx, evt) {
442
443
  const channel = evt.channel || ctx.activeId
444
+ const normalizedValue = evt.format ? ctx.value.toFormat(evt.format) : ctx.areaValue
443
445
 
444
446
  const percent = dom.getChannelSliderValueFromPoint(ctx, evt.point, channel)
445
447
  if (!percent) return
@@ -447,8 +449,8 @@ export function machine(userContext: UserDefinedContext) {
447
449
  const orientation = ctx.activeOrientation || "horizontal"
448
450
  const channelPercent = orientation === "horizontal" ? percent.x : percent.y
449
451
 
450
- const value = ctx.areaValue.getChannelPercentValue(channel, channelPercent)
451
- const color = ctx.areaValue.withChannelValue(channel, value)
452
+ const value = normalizedValue.getChannelPercentValue(channel, channelPercent)
453
+ const color = normalizedValue.withChannelValue(channel, value)
452
454
  set.value(ctx, color)
453
455
  },
454
456
  setValue(ctx, evt) {
@@ -506,22 +508,22 @@ export function machine(userContext: UserDefinedContext) {
506
508
  const color = ctx.value.decrementChannel(evt.channel, evt.step)
507
509
  set.value(ctx, color)
508
510
  },
509
- incrementXChannel(ctx, evt) {
511
+ incrementAreaXChannel(ctx, evt) {
510
512
  const { xChannel } = evt.channel
511
513
  const color = ctx.areaValue.incrementChannel(xChannel, evt.step)
512
514
  set.value(ctx, color)
513
515
  },
514
- decrementXChannel(ctx, evt) {
516
+ decrementAreaXChannel(ctx, evt) {
515
517
  const { xChannel } = evt.channel
516
518
  const color = ctx.areaValue.decrementChannel(xChannel, evt.step)
517
519
  set.value(ctx, color)
518
520
  },
519
- incrementYChannel(ctx, evt) {
521
+ incrementAreaYChannel(ctx, evt) {
520
522
  const { yChannel } = evt.channel
521
523
  const color = ctx.areaValue.incrementChannel(yChannel, evt.step)
522
524
  set.value(ctx, color)
523
525
  },
524
- decrementYChannel(ctx, evt) {
526
+ decrementAreaYChannel(ctx, evt) {
525
527
  const { yChannel } = evt.channel
526
528
  const color = ctx.areaValue.decrementChannel(yChannel, evt.step)
527
529
  set.value(ctx, color)
@@ -203,6 +203,10 @@ export interface ChannelProps {
203
203
  orientation?: Orientation
204
204
  }
205
205
 
206
+ export interface ChannelSliderProps extends ChannelProps {
207
+ format?: ColorFormat
208
+ }
209
+
206
210
  export interface ChannelInputProps {
207
211
  channel: ExtendedColorChannel
208
212
  orientation?: Orientation
@@ -271,6 +275,10 @@ export interface MachineApi<T extends PropTypes = PropTypes> {
271
275
  * Function to set the color value
272
276
  */
273
277
  getChannelValue(channel: ColorChannel): string
278
+ /**
279
+ * Function to get the formatted and localized value of a specific channel
280
+ */
281
+ getChannelValueText(channel: ColorChannel, locale: string): string
274
282
  /**
275
283
  * Function to set the color value of a specific channel
276
284
  */
@@ -308,11 +316,14 @@ export interface MachineApi<T extends PropTypes = PropTypes> {
308
316
  getAreaBackgroundProps(props?: AreaProps): T["element"]
309
317
  getAreaThumbProps(props?: AreaProps): T["element"]
310
318
 
311
- getChannelSliderProps(props: ChannelProps): T["element"]
312
- getChannelSliderTrackProps(props: ChannelProps): T["element"]
313
- getChannelSliderThumbProps(props: ChannelProps): T["element"]
314
319
  getChannelInputProps(props: ChannelInputProps): T["input"]
315
320
 
321
+ getChannelSliderProps(props: ChannelSliderProps): T["element"]
322
+ getChannelSliderTrackProps(props: ChannelSliderProps): T["element"]
323
+ getChannelSliderThumbProps(props: ChannelSliderProps): T["element"]
324
+ getChannelSliderLabelProps(props: ChannelProps): T["element"]
325
+ getChannelSliderValueTextProps(props: ChannelProps): T["element"]
326
+
316
327
  getTransparencyGridProps(props?: TransparencyGridProps): T["element"]
317
328
 
318
329
  getEyeDropperTriggerProps(): T["button"]
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ export { parse } from "./color-picker.parse"
6
6
  export type {
7
7
  MachineApi as Api,
8
8
  AreaProps,
9
+ ChannelSliderProps,
9
10
  ChannelInputProps,
10
11
  ChannelProps,
11
12
  Color,