@onesy/ui-react
Version:
UI for React
76 lines • 3.25 kB
JavaScript
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
const _excluded = ["values", "className"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
import { c as _c } from "react/compiler-runtime";
import React from 'react';
import { clamp, is } from '@onesy/utils';
import { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react';
import ChartElement from '../Chart';
import ColumnChartItemElement from '../ColumnChartItem';
import { staticClassName } from '../utils';
import { jsx as _jsx } from "react/jsx-runtime";
const useStyle = styleMethod(theme => ({
root: {}
}), {
name: 'onesy-ColumnChart'
});
const ColumnChart = props_ => {
const $ = _c(8);
const theme = useOnesyTheme();
const props = _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesyColumnChart?.props?.default), props_);
const Chart = theme?.elements?.Chart || ChartElement;
const ColumnChartItem = theme?.elements?.ColumnChartItem || ColumnChartItemElement;
const {
values,
className
} = props,
other = _objectWithoutProperties(props, _excluded);
const {
classes
} = useStyle();
const [rects, setRects] = React.useState();
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = valueNew => {
setRects(valueNew);
};
$[0] = t0;
} else {
t0 = $[0];
}
const onUpdateRects = t0;
const wrapperRect = rects?.wrapper;
const widthItem = wrapperRect ? clamp(wrapperRect?.width / (values.length * 2), undefined, 40) : undefined;
const t1 = "hidden";
const t2 = true;
const t3 = classNames([staticClassName("ColumnChart", theme) && ["onesy-ColumnChart-root"], className, classes.root]);
const t4 = is("array", values) && values.map((item, index) => /*#__PURE__*/_jsx(ColumnChartItem, _objectSpread({
width: widthItem
}, item), index));
let t5;
if ($[1] !== Chart || $[2] !== onUpdateRects || $[3] !== other || $[4] !== t3 || $[5] !== t4 || $[6] !== values) {
t5 = /*#__PURE__*/_jsx(Chart, _objectSpread(_objectSpread({
values: values,
pointsVisibility: t1,
elementTooltip: t2,
onUpdateRects: onUpdateRects,
className: t3
}, other), {}, {
children: t4
}));
$[1] = Chart;
$[2] = onUpdateRects;
$[3] = other;
$[4] = t3;
$[5] = t4;
$[6] = values;
$[7] = t5;
} else {
t5 = $[7];
}
return t5;
};
ColumnChart.displayName = 'onesy-ColumnChart';
export default ColumnChart;