@sanity/color-input
Version:
115 lines (114 loc) • 2.79 kB
JavaScript
import { defineType, definePlugin } from "sanity";
import { jsx } from "react/jsx-runtime";
import { lazy } from "react";
const ColorInput = lazy(() => import("./_chunks-es/ColorInput.mjs")), round = (val = 1) => Math.round(val * 100), colorTypeName = "color", color = defineType({
name: colorTypeName,
type: "object",
title: "Color",
components: { input: ColorInput },
fields: [
{
title: "Hex",
name: "hex",
type: "string"
},
{
title: "Alpha",
name: "alpha",
type: "number"
},
{
title: "Hue Saturation Lightness",
name: "hsl",
type: "hslaColor"
},
{
title: "Hue Saturation Value",
name: "hsv",
type: "hsvaColor"
},
{
title: "Red Green Blue (rgb)",
name: "rgb",
type: "rgbaColor"
}
],
preview: {
select: {
title: "hex",
alpha: "alpha",
hex: "hex",
hsl: "hsl"
},
prepare({
title,
hex,
hsl,
alpha
}) {
let subtitle = hex || "No color set";
return hsl && (subtitle = `H:${round(hsl.h)} S:${round(hsl.s)} L:${round(hsl.l)} A:${round(alpha)}`), {
title,
subtitle,
media: () => /* @__PURE__ */ jsx(
"div",
{
style: {
backgroundColor: hex ?? "#000",
opacity: alpha ?? 1,
position: "absolute",
height: "100%",
width: "100%",
top: "0",
left: "0"
}
}
)
};
}
}
}), hslaColor = defineType({
title: "Hue Saturation Lightness",
name: "hslaColor",
type: "object",
fields: [
{ name: "h", type: "number", title: "Hue" },
{ name: "s", type: "number", title: "Saturation" },
{ name: "l", type: "number", title: "Lightness" },
{ name: "a", type: "number", title: "Alpha" }
]
}), hsvaColor = defineType({
title: "Hue Saturation Value",
name: "hsvaColor",
type: "object",
fields: [
{ name: "h", type: "number", title: "Hue" },
{ name: "s", type: "number", title: "Saturation" },
{ name: "v", type: "number", title: "Value" },
{ name: "a", type: "number", title: "Alpha" }
]
}), rgbaColor = defineType({
title: "Red Green Blue (rgb)",
name: "rgbaColor",
type: "object",
fields: [
{ name: "r", type: "number", title: "Red" },
{ name: "g", type: "number", title: "Green" },
{ name: "b", type: "number", title: "Blue" },
{ name: "a", type: "number", title: "Alpha" }
]
}), colorInput = definePlugin({
name: "@sanity/color-input",
schema: {
types: [hslaColor, hsvaColor, rgbaColor, color]
}
});
export {
ColorInput,
color,
colorInput,
hslaColor,
hsvaColor,
rgbaColor
};
//# sourceMappingURL=index.mjs.map