laif-ds
Version:
Design System di Laif con componenti React basati su principi di Atomic Design
194 lines (193 loc) • 5.58 kB
JavaScript
"use client";
import * as c from "react";
import { PureComponent as P } from "react";
import { clsx as S } from "../../../clsx/dist/clsx.js";
import { Surface as w } from "../container/Surface.js";
import { Symbols as E } from "../shape/Symbols.js";
import { adaptEventsOfChild as x } 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 k(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 = z(e)) in r ? Object.defineProperty(r, e, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : r[e] = t, r;
}
function z(r) {
var e = I(r, "string");
return typeof e == "symbol" ? e : e + "";
}
function I(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 i = 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 = i / 2, s = i / 6, u = i / 3, m = e.inactive ? n : e.color, l = t ?? e.type;
if (l === "none")
return null;
if (l === "plainline")
return /* @__PURE__ */ c.createElement("line", {
strokeWidth: 4,
fill: "none",
stroke: m,
strokeDasharray: e.payload.strokeDasharray,
x1: 0,
y1: a,
x2: i,
y2: a,
className: "recharts-legend-icon"
});
if (l === "line")
return /* @__PURE__ */ c.createElement("path", {
strokeWidth: 4,
fill: "none",
stroke: m,
d: "M0,".concat(a, "h").concat(u, `
A`).concat(s, ",").concat(s, ",0,1,1,").concat(2 * u, ",").concat(a, `
H`).concat(i, "M").concat(2 * u, ",").concat(a, `
A`).concat(s, ",").concat(s, ",0,1,1,").concat(u, ",").concat(a),
className: "recharts-legend-icon"
});
if (l === "rect")
return /* @__PURE__ */ c.createElement("path", {
stroke: "none",
fill: m,
d: "M0,".concat(i / 8, "h").concat(i, "v").concat(i * 3 / 4, "h").concat(-i, "z"),
className: "recharts-legend-icon"
});
if (/* @__PURE__ */ c.isValidElement(e.legendIcon)) {
var p = k({}, e);
return delete p.legendIcon, /* @__PURE__ */ c.cloneElement(e.legendIcon, p);
}
return /* @__PURE__ */ c.createElement(E, {
fill: m,
cx: a,
cy: a,
size: i,
sizeType: "diameter",
type: l
});
}
/**
* Draw items of legend
* @return Items
*/
renderItems() {
var {
payload: e,
iconSize: t,
layout: n,
formatter: a,
inactiveColor: s,
iconType: u
} = this.props, m = {
x: 0,
y: 0,
width: i,
height: i
}, l = {
display: n === "horizontal" ? "inline-block" : "block",
marginRight: 10
}, p = {
display: "inline-block",
verticalAlign: "middle",
marginRight: 4
};
return e.map((o, f) => {
var g = o.formatter || a, O = S({
"recharts-legend-item": !0,
["legend-item-".concat(f)]: !0,
inactive: o.inactive
});
if (o.type === "none")
return null;
var j = o.inactive ? s : o.color, h = g ? g(o.value, o, f) : o.value;
return /* @__PURE__ */ c.createElement("li", v({
className: O,
style: l,
key: "legend-item-".concat(f)
}, x(this.props, o, f)), /* @__PURE__ */ c.createElement(w, {
width: t,
height: t,
viewBox: m,
style: p,
"aria-label": "".concat(h, " legend icon")
}, this.renderIcon(o, u)), /* @__PURE__ */ c.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__ */ c.createElement("ul", {
className: "recharts-default-legend",
style: a
}, this.renderItems());
}
}
d(b, "displayName", "Legend");
d(b, "defaultProps", {
align: "center",
iconSize: 14,
inactiveColor: "#ccc",
layout: "horizontal",
verticalAlign: "middle"
});
export {
b as DefaultLegendContent
};