Skip to content

Commit

Permalink
Adding backgroundColor prop to Box (#12524)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanml authored Oct 29, 2021
1 parent 7e7d0c1 commit 487080b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ui/components/ui/box/box.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export default function Box({
height,
children,
className,
backgroundColor,
}) {
const boxClassName = classnames('box', className, {
// ---Borders---
Expand Down Expand Up @@ -128,6 +129,8 @@ export default function Box({
// width & height
[`box--width-${width}`]: Boolean(width),
[`box--height-${height}`]: Boolean(height),
// background
[`box--background-color-${backgroundColor}`]: Boolean(backgroundColor),
});
// Apply Box styles to any other component using function pattern
if (typeof children === 'function') {
Expand Down Expand Up @@ -159,5 +162,6 @@ Box.propTypes = {
display: PropTypes.oneOf(Object.values(DISPLAY)),
width: PropTypes.oneOf(Object.values(BLOCK_SIZES)),
height: PropTypes.oneOf(Object.values(BLOCK_SIZES)),
backgroundColor: PropTypes.oneOf(Object.values(COLORS)),
className: PropTypes.string,
};
7 changes: 7 additions & 0 deletions ui/components/ui/box/box.scss
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,11 @@ $attributes: padding, margin;
text-align: $alignment;
}
}

// background
@each $variant, $color in design-system.$color-map {
&--background-color-#{$variant} {
background-color: $color;
}
}
}
6 changes: 6 additions & 0 deletions ui/components/ui/box/box.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ export const box = () => {
)}
borderWidth={number('borderWidth', 1, sizeKnobOptions, 'border')}
borderColor={select('borderColor', COLORS, COLORS.BLACK, 'border')}
backgroundColor={select(
'backgroundColor',
COLORS,
COLORS.WHITE,
'background',
)}
>
{items}
</Box>
Expand Down

0 comments on commit 487080b

Please sign in to comment.