UNPKG

laif-ds

Version:

Design System di Laif con componenti React basati su principi di Atomic Design

197 lines (196 loc) 5.68 kB
"use client"; import * as l from "react"; import { PureComponent as P } from "react"; import { clsx as w } from "../../../clsx/dist/clsx.js"; import E from "../../../../_virtual/sortBy.js"; import { Surface as x } from "../container/Surface.js"; import { Symbols as k } from "../shape/Symbols.js"; import { adaptEventsOfChild as z } from "../util/types.js"; function v() { return v = Object.assign ? Object.assign.bind() : function(r) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var n in t) ({}).hasOwnProperty.call(t, n) && (r[n] = t[n]); } return r; }, v.apply(null, arguments); } function y(r, e) { var t = Object.keys(r); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(r); e && (n = n.filter(function(a) { return Object.getOwnPropertyDescriptor(r, a).enumerable; })), t.push.apply(t, n); } return t; } function I(r) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e] != null ? arguments[e] : {}; e % 2 ? y(Object(t), !0).forEach(function(n) { d(r, n, t[n]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(r, Object.getOwnPropertyDescriptors(t)) : y(Object(t)).forEach(function(n) { Object.defineProperty(r, n, Object.getOwnPropertyDescriptor(t, n)); }); } return r; } function d(r, e, t) { return (e = N(e)) in r ? Object.defineProperty(r, e, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : r[e] = t, r; } function N(r) { var e = D(r, "string"); return typeof e == "symbol" ? e : e + ""; } function D(r, e) { if (typeof r != "object" || !r) return r; var t = r[Symbol.toPrimitive]; if (t !== void 0) { var n = t.call(r, e); if (typeof n != "object") return n; throw new TypeError("@@toPrimitive must return a primitive value."); } return (e === "string" ? String : Number)(r); } var o = 32; class b extends P { /** * Render the path of icon * @param data Data of each legend item * @param iconType if defined, it will always render this icon. If undefined then it uses icon from data.type * @return Path element */ renderIcon(e, t) { var { inactiveColor: n } = this.props, a = o / 2, u = o / 6, m = o / 3, c = e.inactive ? n : e.color, s = t ?? e.type; if (s === "none") return null; if (s === "plainline") return /* @__PURE__ */ l.createElement("line", { strokeWidth: 4, fill: "none", stroke: c, strokeDasharray: e.payload.strokeDasharray, x1: 0, y1: a, x2: o, y2: a, className: "recharts-legend-icon" }); if (s === "line") return /* @__PURE__ */ l.createElement("path", { strokeWidth: 4, fill: "none", stroke: c, d: "M0,".concat(a, "h").concat(m, ` A`).concat(u, ",").concat(u, ",0,1,1,").concat(2 * m, ",").concat(a, ` H`).concat(o, "M").concat(2 * m, ",").concat(a, ` A`).concat(u, ",").concat(u, ",0,1,1,").concat(m, ",").concat(a), className: "recharts-legend-icon" }); if (s === "rect") return /* @__PURE__ */ l.createElement("path", { stroke: "none", fill: c, d: "M0,".concat(o / 8, "h").concat(o, "v").concat(o * 3 / 4, "h").concat(-o, "z"), className: "recharts-legend-icon" }); if (/* @__PURE__ */ l.isValidElement(e.legendIcon)) { var p = I({}, e); return delete p.legendIcon, /* @__PURE__ */ l.cloneElement(e.legendIcon, p); } return /* @__PURE__ */ l.createElement(k, { fill: c, cx: a, cy: a, size: o, sizeType: "diameter", type: s }); } /** * Draw items of legend * @return Items */ renderItems() { var { payload: e, iconSize: t, layout: n, formatter: a, inactiveColor: u, iconType: m, itemSorter: c } = this.props, s = { x: 0, y: 0, width: o, height: o }, p = { display: n === "horizontal" ? "inline-block" : "block", marginRight: 10 }, O = { display: "inline-block", verticalAlign: "middle", marginRight: 4 }; return (c ? E(e, c) : e).map((i, f) => { var g = i.formatter || a, S = w({ "recharts-legend-item": !0, ["legend-item-".concat(f)]: !0, inactive: i.inactive }); if (i.type === "none") return null; var j = i.inactive ? u : i.color, h = g ? g(i.value, i, f) : i.value; return /* @__PURE__ */ l.createElement("li", v({ className: S, style: p, key: "legend-item-".concat(f) }, z(this.props, i, f)), /* @__PURE__ */ l.createElement(x, { width: t, height: t, viewBox: s, style: O, "aria-label": "".concat(h, " legend icon") }, this.renderIcon(i, m)), /* @__PURE__ */ l.createElement("span", { className: "recharts-legend-item-text", style: { color: j } }, h)); }); } render() { var { payload: e, layout: t, align: n } = this.props; if (!e || !e.length) return null; var a = { padding: 0, margin: 0, textAlign: t === "horizontal" ? n : "left" }; return /* @__PURE__ */ l.createElement("ul", { className: "recharts-default-legend", style: a }, this.renderItems()); } } d(b, "displayName", "Legend"); d(b, "defaultProps", { align: "center", iconSize: 14, inactiveColor: "#ccc", itemSorter: "value", layout: "horizontal", verticalAlign: "middle" }); export { b as DefaultLegendContent };