@patternfly/react-charts
Version:
This library provides a set of React chart components for use with the PatternFly reference implementation.
30 lines • 2.31 kB
JavaScript
import { __rest } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import { cloneElement } from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';
import { VictoryAxis } from 'victory-axis';
import { ChartContainer } from '../ChartContainer/ChartContainer';
import { ChartLabel } from '../ChartLabel/ChartLabel';
import { getComponentTheme, getTheme } from '../ChartUtils/chart-theme';
import { getAxisTheme } from '../ChartUtils/chart-theme-types';
export const ChartAxis = (_a) => {
var { axisLabelComponent = _jsx(ChartLabel, {}), containerComponent = _jsx(ChartContainer, {}), name, showGrid = false, themeColor, tickLabelComponent = _jsx(ChartLabel, {}),
// destructure last
theme = getTheme(themeColor) } = _a, rest = __rest(_a, ["axisLabelComponent", "containerComponent", "name", "showGrid", "themeColor", "tickLabelComponent", "theme"]);
const componentTheme = getComponentTheme(themeColor);
// Clone so users can override container props
const container = cloneElement(containerComponent, Object.assign({ theme }, containerComponent.props));
const getAxisLabelComponent = () => cloneElement(axisLabelComponent, Object.assign(Object.assign(Object.assign({}, (name && {
id: () => `${name}-${axisLabelComponent.type.displayName}`
})), axisLabelComponent.props), ((componentTheme === null || componentTheme === void 0 ? void 0 : componentTheme.label) && componentTheme.label) // override backgroundStyle
));
const getTickLabelComponent = () => cloneElement(tickLabelComponent, Object.assign(Object.assign(Object.assign({}, (name && {
id: (props) => `${name}-${tickLabelComponent.type.displayName}-${props.index}`
})), tickLabelComponent.props), ((componentTheme === null || componentTheme === void 0 ? void 0 : componentTheme.label) && componentTheme.label) // override backgroundStyle
));
// Note: containerComponent is required for theme
return (_jsx(VictoryAxis, Object.assign({ axisLabelComponent: getAxisLabelComponent(), containerComponent: container, name: name, theme: showGrid ? getAxisTheme(themeColor) : theme, tickLabelComponent: getTickLabelComponent() }, rest)));
};
ChartAxis.displayName = 'ChartAxis';
hoistNonReactStatics(ChartAxis, VictoryAxis);
//# sourceMappingURL=ChartAxis.js.map