Skip to content

Commit

Permalink
Revert "[LOOM-1278][BpkBarChart] Class 2 Fix Remove unused classname …
Browse files Browse the repository at this point in the history
…prop (#3…" (#3398)

This reverts commit 80098ca.
  • Loading branch information
mungodewar committed Apr 30, 2024
1 parent f60a278 commit 4aab7e3
Show file tree
Hide file tree
Showing 3 changed files with 413 additions and 1 deletion.
16 changes: 16 additions & 0 deletions packages/bpk-component-barchart/src/BpkBarchart-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ describe('BpkBarchart', () => {
expect(asFragment()).toMatchSnapshot();
});

it('should render correctly with "className" prop', () => {
const { asFragment } = render(
<BpkBarchart
xScaleDataKey="month"
yScaleDataKey="price"
xAxisLabel="Month"
yAxisLabel="Average price (£)"
initialWidth={size}
initialHeight={size}
data={prices}
className="my-custom-class-name"
/>,
);
expect(asFragment()).toMatchSnapshot();
});

it('should render correctly with "leadingScrollIndicatorClassName" prop', () => {
const { asFragment } = render(
<BpkBarchart
Expand Down
11 changes: 10 additions & 1 deletion packages/bpk-component-barchart/src/BpkBarchart.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type Props = {
yAxisLabel: string,
initialWidth: number,
initialHeight: number,
className: ?string,
leadingScrollIndicatorClassName: ?string,
trailingScrollIndicatorClassName: ?string,
outlierPercentage: ?number,
Expand Down Expand Up @@ -109,6 +110,7 @@ class BpkBarchart extends Component<Props, State> {
svgEl: ?Element;

static defaultProps = {
className: null,
leadingScrollIndicatorClassName: null,
trailingScrollIndicatorClassName: null,
outlierPercentage: null,
Expand Down Expand Up @@ -168,6 +170,7 @@ class BpkBarchart extends Component<Props, State> {
render() {
const {
BarComponent,
className,
data,
disableDataTable,
getBarLabel,
Expand Down Expand Up @@ -204,6 +207,11 @@ class BpkBarchart extends Component<Props, State> {
bottom: xAxisMargin,
});

const classNames = [getClassName('bpk-barchart')];
if (className) {
classNames.push(className);
}

const width = this.state.width - margin.left - margin.right;
const height = this.state.height - margin.bottom - margin.top;
const maxYValue = getMaxYValue(
Expand Down Expand Up @@ -233,7 +241,7 @@ class BpkBarchart extends Component<Props, State> {
{/* $FlowFixMe[cannot-spread-inexact] - inexact rest. See 'decisions/flowfixme.md'. */}
<svg
xmlns="http://www.w3.org/2000/svg"
className={getClassName('bpk-barchart')}
className={classNames.join(' ')}
width={this.state.width}
height={this.state.height}
ref={(svgEl) => {
Expand Down Expand Up @@ -322,6 +330,7 @@ BpkBarchart.propTypes = {
initialWidth: PropTypes.number.isRequired,
initialHeight: PropTypes.number.isRequired,

className: PropTypes.string,
leadingScrollIndicatorClassName: PropTypes.string,
trailingScrollIndicatorClassName: PropTypes.string,
/**
Expand Down

0 comments on commit 4aab7e3

Please sign in to comment.