Skip to content

Commit

Permalink
LOOM-1221: Add fullWidth prop to BpkButton (#3248)
Browse files Browse the repository at this point in the history
Curently microsites are overriding the BpkButton styles via classname prop.

This adds the functionality to the component removing the need to use the
undesirable classname prop to achieve this
  • Loading branch information
runmoore authored Feb 22, 2024
1 parent 04514c6 commit cecc83b
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 2 deletions.
6 changes: 6 additions & 0 deletions examples/bpk-component-button/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ const LinkOnDarkExample = (props: {}) => (
</BpkDarkExampleWrapper>
);

const FullWidthExample = (props: {}) => (
<BpkButtonV2 fullWidth {...props}>Full Width Button</BpkButtonV2>
);

const MixedExample = () => (
<>
<PrimaryExample />
Expand All @@ -186,6 +190,7 @@ const MixedExample = () => (
<LinkExample />
<LinkOnDarkExample />
<FeaturedExample />
<FullWidthExample />
</>
);

Expand Down Expand Up @@ -215,4 +220,5 @@ export {
LinkOnDarkExample,
MixedExample,
AnchorTagsExample,
FullWidthExample,
};
5 changes: 4 additions & 1 deletion examples/bpk-component-button/stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
LinkOnDarkExample,
MixedExample,
AnchorTagsExample,
FullWidthExample,
} from './examples';

export default {
Expand Down Expand Up @@ -62,4 +63,6 @@ export const VisualTest = () => <MixedExample />;
export const VisualTestWithZoom = VisualTest.bind({});
VisualTestWithZoom.args = {
zoomEnabled: true
};
};

export const FullWidth = () => <FullWidthExample />;
1 change: 1 addition & 0 deletions packages/bpk-component-button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default () => (
<AlignedArrowIcon />
<span className="visually-hidden">Search</span>
</BpkButtonV2>
<BpkButtonV2 fullWidth>Full Width</BpkButtonV2>
</div>
);
```
Expand Down
10 changes: 10 additions & 0 deletions packages/bpk-component-button/src/BpkButtonV2/BpkButton-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,14 @@ describe('BpkButtonV2', () => {
);
expect(asFragment()).toMatchSnapshot();
});

it('should render with a class name if full width is added', () => {
const { container } = render(
<BpkButtonV2 fullWidth>
My button
</BpkButtonV2>,
);

expect(container?.firstElementChild?.classList?.contains('bpk-button--full-width')).toEqual(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@

/// <reference types="react" />
import type { Props } from './common-types';
export declare const BpkButtonV2: ({ blank, children, className, disabled, href, iconOnly, onClick, rel: propRel, size, submit, type, ...rest }: Props) => JSX.Element;
export declare const BpkButtonV2: ({ blank, children, className, disabled, fullWidth, href, iconOnly, onClick, rel: propRel, size, submit, type, ...rest }: Props) => JSX.Element;
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
@include buttons.bpk-button--secondary-on-dark;
}

&--full-width {
@include buttons.bpk-button--full-width;
}

/* stylelint-disable selector-max-compound-selectors */
span > svg {
display: block;
Expand Down
2 changes: 2 additions & 0 deletions packages/bpk-component-button/src/BpkButtonV2/BpkButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const BpkButtonV2 = ({
children,
className = null,
disabled = false,
fullWidth = false,
href = null,
iconOnly = false,
onClick = () => {},
Expand All @@ -44,6 +45,7 @@ export const BpkButtonV2 = ({
iconOnly && 'bpk-button--icon-only',
iconOnly && size === SIZE_TYPES.large && 'bpk-button--large-icon-only',
`bpk-button--${type}`,
fullWidth && 'bpk-button--full-width',
className,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type Props = {
size?: SizeType;
className?: string | null;
disabled?: boolean;
fullWidth?: boolean;
iconOnly?: boolean;
onClick?: (event: MouseEvent<HTMLButtonElement & HTMLAnchorElement>) => void;
rel?: string | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type Props = {
size?: SizeType;
className?: string | null;
disabled?: boolean;
fullWidth?: boolean;
iconOnly?: boolean;
onClick?: (event: MouseEvent<HTMLButtonElement & HTMLAnchorElement>) => void;
rel?: string | undefined;
Expand Down
15 changes: 15 additions & 0 deletions packages/bpk-mixins/_buttons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,18 @@
color: $bpk-text-disabled-day;
}
}

/// Full width button. Modifies the bpk-button to horizontally fill its container
///
/// @require {mixin} bpk-button
///
/// @example scss
/// .selector {
/// @include bpk-button();
/// @include bpk-button--full-width();
/// }

@mixin bpk-button--full-width {
display: block;
width: 100%;
}

0 comments on commit cecc83b

Please sign in to comment.