geostyler
Version:
Framework for styling geodata
79 lines (78 loc) • 1.93 kB
JavaScript
import { jsx as t, jsxs as y } from "react/jsx-runtime";
import { useCallback as x } from "react";
import S from "color";
import { ColorPicker as a, Button as n } from "antd";
/* empty css */
import { useGeoStylerLocale as g } from "../../../../context/GeoStylerContext/GeoStylerContext.js";
import { isGeoStylerFunction as m } from "geostyler-style";
import { FunctionUI as k } from "../../../FunctionUI/FunctionUI.js";
import { FunctionOutlined as b } from "@ant-design/icons";
const B = ({
onChange: o = () => {
},
value: r,
defaultValue: i = "#FFFFFF",
...F
}) => {
const p = g("ColorField"), e = x((s) => {
if (!s) {
o(void 0);
return;
}
const f = s.toHexString();
o(f);
}, [o]);
function d() {
o(i);
}
if (m(r))
return /* @__PURE__ */ t("span", { className: "editor-field gs-color-field", children: /* @__PURE__ */ t(
k,
{
type: "string",
value: r,
onChange: o,
onCancel: d
}
) });
let c;
try {
c = S(r || i).isLight() ? "#000000" : "#FFFFFF";
} catch {
c = "#000000";
}
const l = r || (m(i) ? "#FFFFF" : i);
return /* @__PURE__ */ y("span", { className: "editor-field gs-color-field", children: [
/* @__PURE__ */ t(
a,
{
allowClear: !0,
...F,
disabledAlpha: !0,
onChange: e,
onClear: () => e(),
value: l,
children: /* @__PURE__ */ t(n, { style: {
backgroundColor: l,
color: c
}, className: "color-picker-trigger", children: r ? r.toString() : p.chooseText })
}
),
/* @__PURE__ */ t(
n,
{
className: "function-ui-trigger",
icon: /* @__PURE__ */ t(b, {}),
onClick: () => {
o == null || o({
name: "property",
args: [""]
});
}
}
)
] });
};
export {
B as ColorField
};