antd-color-editor
Version:
An open-source color editor for designing color system
143 lines (136 loc) • 4.89 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/ScaleBlock/index.tsx
var ScaleBlock_exports = {};
__export(ScaleBlock_exports, {
default: () => ScaleBlock_default
});
module.exports = __toCommonJS(ScaleBlock_exports);
var import_antd = require("antd");
var import_react = require("react");
var import_styled_components = __toESM(require("styled-components"));
var import__ = require("../index");
var ScaleBox = import_styled_components.default.div`
cursor: pointer;
position: relative;
width: 48px;
height: 32px;
background-position:
0 0,
0 8px,
8px -8px,
-8px 0;
background-size: 16px 16px;
&:active {
transform: scale(0.95);
}
`;
var ScaleItem = import_styled_components.default.div`
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
`;
var ScaleRowTitle = import_styled_components.default.div`
display: flex;
align-items: center;
width: 64px;
height: 32px;
`;
var Text = import_styled_components.default.div`
opacity: 0.5;
`;
var ColorView = import_styled_components.default.div`
padding: 8px 16px 32px 0;
`;
var View = import_styled_components.default.div`
display: flex;
flex: 1;
align-items: center;
justify-content: center;
`;
var ScaleBlock = (0, import_react.memo)(
({ scale, colorType = "hex", showDetail, highLights, midHighLight, isFliterStep }) => {
return /* @__PURE__ */ React.createElement(View, null, /* @__PURE__ */ React.createElement(ColorView, null, /* @__PURE__ */ React.createElement(import_antd.Space, { direction: showDetail ? "horizontal" : "vertical", size: 2 }, /* @__PURE__ */ React.createElement(import_antd.Space, { direction: showDetail ? "vertical" : "horizontal", key: "scale-title", size: 2 }, /* @__PURE__ */ React.createElement(ScaleRowTitle, { key: "scale-num", style: showDetail ? { width: 32 } : {} }), Array.from({ length: scale.light.length }).fill("").map((_, index) => {
const isHighlight = highLights == null ? void 0 : highLights.includes(index);
const isMidHighlight = midHighLight === index;
return /* @__PURE__ */ React.createElement(ScaleBox, { key: "num" + index, style: showDetail ? { width: 32 } : {} }, /* @__PURE__ */ React.createElement(ScaleItem, null, /* @__PURE__ */ React.createElement(
Text,
{
style: {
fontWeight: isMidHighlight ? 700 : 400,
opacity: isFliterStep ? isHighlight ? 1 : 0.1 : 0.5
}
},
index + 1
)));
})), /* @__PURE__ */ React.createElement(
import__.ScaleRow,
{
colorType,
key: "light",
scale: scale.light,
showDetail,
title: "light"
}
), /* @__PURE__ */ React.createElement(
import__.ScaleRow,
{
alpha: true,
colorType,
key: "lightA",
scale: scale.light.map((c) => (0, import__.getAlphaColor)(c, "#fff")),
showDetail,
solidScale: scale.light,
title: "lightA"
}
), /* @__PURE__ */ React.createElement(
import__.ScaleRow,
{
colorType,
key: "dark",
scale: scale.dark,
showDetail,
title: "dark"
}
), /* @__PURE__ */ React.createElement(
import__.ScaleRow,
{
alpha: true,
colorType,
key: "darkA",
scale: scale.dark.map((c) => (0, import__.getAlphaColor)(c, "#000")),
showDetail,
solidScale: scale.dark,
title: "darkA"
}
))));
}
);
var ScaleBlock_default = ScaleBlock;