Skip to content

Commit

Permalink
feat(box): Add between prop to add bottom margin to all children exce…
Browse files Browse the repository at this point in the history
…pt for last
  • Loading branch information
lzcabrera committed Nov 2, 2017
1 parent 68bda42 commit 170d67e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/components/Box/Box.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ const getXClasses = xSize => {
return styles[`horizontalPadding-${xSize}`]
}

const getYClasses = ySize => {
if (!ySize) {
return undefined
}

return styles[`verticalPadding-${ySize}`]
}

const getBelowClasses = belowSize => {
if (!belowSize) {
return undefined
Expand All @@ -23,12 +31,12 @@ const getBelowClasses = belowSize => {
return styles[`bottomMargin-${belowSize}`]
}

const getYClasses = ySize => {
if (!ySize) {
const getBetweenClasses = (betweenSize, inline) => {
if (!betweenSize) {
return undefined
}

return styles[`verticalPadding-${ySize}`]
return styles[`betweenBottomMargin-${betweenSize}`]
}

const Box = ({
Expand All @@ -46,6 +54,7 @@ const Box = ({
x,
y,
below,
between,
dangerouslyAddClassName,
children,
...rest
Expand All @@ -66,6 +75,7 @@ const Box = ({
getXClasses(xSize),
getYClasses(ySize),
getBelowClasses(below),
getBetweenClasses(between, inline),
dangerouslyAddClassName
)

Expand All @@ -91,6 +101,7 @@ Box.propTypes = {
x: PropTypes.oneOf([1, 2, 3, 4, 6]),
y: PropTypes.oneOf([1, 2, 3, 4, 6]),
below: PropTypes.oneOf([1, 2, 3, 4, 5, 6, 7, 8]),
between: PropTypes.oneOf([1, 2, 3, 4, 5, 6, 7, 8]),
dangerouslyAddClassName: PropTypes.string,
children: PropTypes.node.isRequired,
}
Expand All @@ -110,6 +121,7 @@ Box.defaultProps = {
x: undefined,
y: undefined,
below: undefined,
between: undefined,
dangerouslyAddClassName: undefined,
}

Expand Down
5 changes: 5 additions & 0 deletions src/components/Box/Box.modules.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ $boxProps: ('margin': 'Margin', 'padding': 'Padding');
#{$p}-bottom: $value;
}

// TODO: refactor to not generate unnecessary .betweenBottomPadding-*
.betweenBottom#{$v}-#{$level} > *:not(:last-child) {
#{$p}-bottom: $value;
}

.left#{$v}-#{$level} {
#{$p}-left: $value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ exports[`ExpandCollapse renders 1`] = `
<Box
all={undefined}
below={undefined}
between={undefined}
bottom={undefined}
dangerouslyAddClassName={undefined}
horizontal={undefined}
Expand Down Expand Up @@ -75,6 +76,7 @@ exports[`ExpandCollapse renders 1`] = `
<Box
all={undefined}
below={undefined}
between={undefined}
bottom={undefined}
dangerouslyAddClassName={undefined}
horizontal={undefined}
Expand Down Expand Up @@ -167,6 +169,7 @@ exports[`ExpandCollapse renders 1`] = `
<Box
all={undefined}
below={undefined}
between={undefined}
bottom={undefined}
dangerouslyAddClassName={undefined}
horizontal={undefined}
Expand Down Expand Up @@ -243,6 +246,7 @@ exports[`ExpandCollapse renders 1`] = `
<Box
all={undefined}
below={undefined}
between={undefined}
bottom={undefined}
dangerouslyAddClassName={undefined}
horizontal={undefined}
Expand Down Expand Up @@ -270,6 +274,7 @@ exports[`ExpandCollapse renders 1`] = `
<Box
all={undefined}
below={undefined}
between={undefined}
bottom={undefined}
dangerouslyAddClassName={undefined}
horizontal={undefined}
Expand Down Expand Up @@ -362,6 +367,7 @@ exports[`ExpandCollapse renders 1`] = `
<Box
all={undefined}
below={undefined}
between={undefined}
bottom={undefined}
dangerouslyAddClassName={undefined}
horizontal={undefined}
Expand Down

0 comments on commit 170d67e

Please sign in to comment.