Skip to content

Commit

Permalink
feat(responsiveBox): Apply new responsive skill to box component
Browse files Browse the repository at this point in the history
  • Loading branch information
codedavinci committed Nov 22, 2017
1 parent b76b13f commit 18924b1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 31 deletions.
24 changes: 15 additions & 9 deletions src/components/Box/Box.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import PropTypes from 'prop-types'
import Responsive from '../Responsive/Responsive'

import safeRest from '../../utils/safeRest'
import joinClassNames from '../../utils/joinClassNames'
Expand All @@ -11,7 +12,6 @@ const getClassName = (spacing, location, scale) => {
if (!scale) {
return undefined
}

return styles[`${location}${capitalize(spacing)}-${scale}`]
}

Expand Down Expand Up @@ -47,15 +47,21 @@ const Box = ({
const xSize = inset || horizontal
const ySize = inset || vertical

const classes = joinClassNames(
getClassName('padding', 'horizontal', xSize),
getClassName('padding', 'vertical', ySize),
getClassName('margin', 'bottom', below),
getBetweenClasses(between, inline),
dangerouslyAddClassName
return (
<Responsive minWidth="md">
{isDesktop => {
const classes = joinClassNames(
styles[isDesktop ? 'desktop' : 'mobile'],
getClassName('padding', 'horizontal', xSize),
getClassName('padding', 'vertical', ySize),
getClassName('margin', 'bottom', below),
getBetweenClasses(between, inline),
dangerouslyAddClassName
)
return React.createElement(tag, { ...safeRest(rest), className: classes }, children)
}}
</Responsive>
)

return React.createElement(tag, { ...safeRest(rest), className: classes }, children)
}

Box.propTypes = {
Expand Down
38 changes: 17 additions & 21 deletions src/components/Box/Box.modules.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

$spacing-base: 1rem; // 16px

$spacings: (
$mobile: (
1: $spacing-base * 0.25,
2: $spacing-base * 0.5,
3: $spacing-base,
Expand All @@ -14,15 +14,15 @@ $spacings: (
8: $spacing-base * 4
);

$responsive-spacings: (
medium:
(
4: $spacing-base * 2,
5: $spacing-base * 3,
6: $spacing-base * 4,
7: $spacing-base * 4.5,
8: $spacing-base * 6
)
$desktop: (
1: $spacing-base * 0.25,
2: $spacing-base * 0.5,
3: $spacing-base,
4: $spacing-base * 2,
5: $spacing-base * 3,
6: $spacing-base * 4,
7: $spacing-base * 4.5,
8: $spacing-base * 6
);

.betweenRight {
Expand Down Expand Up @@ -59,18 +59,14 @@ $responsive-spacings: (
}
}

@mixin responsiveSpacingClasses ($bp, $map) {
@include from-breakpoint($bp) {
@each $level, $value in $map {
@include spacingClasses($level, $value);
}
.desktop {
@each $level, $value in $desktop {
@include spacingClasses($level, $value);
}
}

@each $level, $value in $spacings {
@include spacingClasses($level, $value);
}

@each $bp, $map in $responsive-spacings {
@include responsiveSpacingClasses($bp, $map);
.mobile {
@each $level, $value in $mobile {
@include spacingClasses($level, $value);
}
}
2 changes: 2 additions & 0 deletions src/components/Box/__tests__/Box.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ describe('Box', () => {
Some content
</Box>
)
.dive()
.dive()

it('renders', () => {
const box = doShallow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`Box renders 1`] = `
<div
className="betweenBottomMargin-3 betweenBottom"
className="mobile betweenBottomMargin-3 betweenBottom"
>
Some content
</div>
Expand Down

0 comments on commit 18924b1

Please sign in to comment.