@pixpilot/shadcn 1.2.5 → 1.2.7

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.
@@ -78,7 +78,10 @@ declare function ColorPickerContent(props: React.ComponentProps<typeof PopoverCo
78
78
  declare function ColorPickerArea(props: DivProps): react_jsx_runtime41.JSX.Element;
79
79
  declare function ColorPickerHueSlider(props: React.ComponentProps<typeof SliderPrimitive.Root>): react_jsx_runtime41.JSX.Element;
80
80
  declare function ColorPickerAlphaSlider(props: React.ComponentProps<typeof SliderPrimitive.Root>): react_jsx_runtime41.JSX.Element;
81
- declare function ColorPickerSwatch(props: DivProps): react_jsx_runtime41.JSX.Element;
81
+ interface ColorPickerSwatchProps extends Omit<DivProps, 'color'> {
82
+ color?: string;
83
+ }
84
+ declare function ColorPickerSwatch(props: ColorPickerSwatchProps): react_jsx_runtime41.JSX.Element;
82
85
  declare function ColorPickerEyeDropper(props: React.ComponentProps<typeof Button>): react_jsx_runtime41.JSX.Element | null;
83
86
  interface ColorPickerFormatSelectProps extends Omit<React.ComponentProps<typeof Select>, 'value' | 'onValueChange'>, Pick<React.ComponentProps<typeof SelectTrigger>, 'size' | 'className'> {}
84
87
  declare function ColorPickerFormatSelect(props: ColorPickerFormatSelectProps): react_jsx_runtime41.JSX.Element;
@@ -231,8 +231,17 @@ function hslToRgb(hsl, alpha = 1) {
231
231
  a: alpha
232
232
  };
233
233
  }
234
+ function isTransparent(color) {
235
+ return color.trim().toLowerCase() === "transparent";
236
+ }
234
237
  function parseColorString(value) {
235
238
  const trimmed = value.trim();
239
+ if (isTransparent(trimmed)) return {
240
+ r: 0,
241
+ g: 0,
242
+ b: 0,
243
+ a: 0
244
+ };
236
245
  if (trimmed.startsWith("#")) {
237
246
  const hexMatch = trimmed.match(/^#([a-f0-9]{3}|[a-f0-9]{4}|[a-f0-9]{6}|[a-f0-9]{8})$/i);
238
247
  if (hexMatch) {
@@ -701,17 +710,21 @@ function ColorPickerAlphaSlider(props) {
701
710
  });
702
711
  }
703
712
  function ColorPickerSwatch(props) {
704
- const { asChild, className,...swatchProps } = props;
713
+ const { asChild, className, color: colorProp, style: styleProp,...swatchProps } = props;
705
714
  const context = useColorPickerContext(SWATCH_NAME);
706
- const color = useStore((state) => state.color);
715
+ const storeColor = useStore((state) => state.color);
707
716
  const format = useStore((state) => state.format);
717
+ const color = React.useMemo(() => {
718
+ if (colorProp === void 0) return storeColor;
719
+ return parseColorString(colorProp);
720
+ }, [colorProp, storeColor]);
708
721
  const backgroundStyle = React.useMemo(() => {
709
- if (!color) return { background: "linear-gradient(to bottom right, transparent calc(50% - 1px), hsl(var(--destructive)) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)) no-repeat" };
722
+ if (!color) return { backgroundColor: colorProp };
710
723
  const colorString = `rgba(${color.r}, ${color.g}, ${color.b}, ${color.a})`;
711
724
  if (color.a < 1) return { background: `linear-gradient(${colorString}, ${colorString}), repeating-conic-gradient(#ccc 0% 25%, #fff 0% 50%) 0% 50% / 8px 8px` };
712
725
  return { backgroundColor: colorString };
713
- }, [color]);
714
- const ariaLabel = !color ? "No color selected" : `Current color: ${colorToString(color, format)}`;
726
+ }, [color, colorProp]);
727
+ const ariaLabel = color ? `Current color: ${colorToString(color, format)}` : colorProp ? `Current color: ${colorProp}` : "No color selected";
715
728
  return /* @__PURE__ */ jsx(asChild ? Slot : "div", {
716
729
  role: "img",
717
730
  "aria-label": ariaLabel,
@@ -720,7 +733,8 @@ function ColorPickerSwatch(props) {
720
733
  className: cn("box-border size-8 rounded-sm border shadow-sm", context.disabled && "opacity-50", className),
721
734
  style: {
722
735
  ...backgroundStyle,
723
- forcedColorAdjust: "none"
736
+ forcedColorAdjust: "none",
737
+ ...styleProp
724
738
  }
725
739
  });
726
740
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pixpilot/shadcn",
3
3
  "type": "module",
4
- "version": "1.2.5",
4
+ "version": "1.2.7",
5
5
  "description": "A collection of reusable UI components built with shadcn/ui and Radix UI primitives.",
6
6
  "author": "m.doaie <m.doaie@hotmail.com>",
7
7
  "license": "MIT",