Skip to content

Commit

Permalink
feat(component): add clearfix prop for Box component (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
chanceaclark authored Apr 23, 2020
1 parent 77ea579 commit 29b073b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/big-design/src/components/Box/Box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface BoxProps extends React.HTMLAttributes<HTMLDivElement>, DisplayP
borderRight?: keyof Border;
borderTop?: keyof Border;
borderRadius?: keyof BorderRadius;
clearfix?: boolean;
}

interface PrivateProps {
Expand Down
16 changes: 16 additions & 0 deletions packages/big-design/src/components/Box/__snapshots__/spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ exports[`has border props 1`] = `
/>
`;

exports[`has clearfix prop 1`] = `
.c0 {
box-sizing: border-box;
}
.c0::after {
clear: both;
content: "";
display: table;
}
<div
class="c0"
/>
`;

exports[`has individual border props 1`] = `
.c0 {
box-sizing: border-box;
Expand Down
6 changes: 6 additions & 0 deletions packages/big-design/src/components/Box/spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ test('has shadow props', () => {
expect(container.firstChild).toMatchSnapshot();
});

test('has clearfix prop', () => {
const { container } = render(<Box clearfix />);

expect(container.firstChild).toMatchSnapshot();
});

test('renders as a different tag', () => {
const { getByTestId } = render(<Box data-testid="box" as="section" />);
const tag = getByTestId('box').tagName;
Expand Down
3 changes: 3 additions & 0 deletions packages/big-design/src/components/Box/styled.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { theme as defaultTheme } from '@bigcommerce/big-design-theme';
import { clearFix } from 'polished';
import styled, { css } from 'styled-components';

import { withDisplay, withMargins, withPaddings } from '../../mixins';
Expand All @@ -11,6 +12,8 @@ export const StyledBox = styled.div<BoxProps>`
${withPaddings()}
box-sizing: border-box;
${({ clearfix }) => clearfix && clearFix()};
${({ backgroundColor, theme }) =>
backgroundColor &&
css`
Expand Down
5 changes: 5 additions & 0 deletions packages/docs/PropTables/BoxPropTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ const boxProps: Prop[] = [
types: ['normal', 'circle', 'none'],
description: 'Determines type of border radius to be applied.',
},
{
name: 'clearfix',
types: ['boolean'],
description: 'Adds a clearfix for floating internal elements.',
},
];

export const BoxPropTable: React.FC<PropTableWrapper> = props => (
Expand Down

0 comments on commit 29b073b

Please sign in to comment.