#Spacing

Bumbag uses two types of scales for its spacing system: the 8px major scale and the 4px minor scale.

You can either use the scales directly, or use a pre-defined set of scales (e.g. sm, md, lg).

#Using the scales directly

The 8px major scale is most commonly used for positional spacing. Like margins & paddings between components on a layout.

Bumbag also exports a utility function called space to help you with calculating the scale values.

Note: It is recommended to try stick to the 8px scale unless you need more precision. In that case, use the 4px minor scale.

TokenpxremUtility function
major-18px0.5remspace(1, 'major')
major-216px1remspace(2, 'major')
major-324px1.5remspace(3, 'major')
major-432px2remspace(4, 'major')
major-540px2.5remspace(5, 'major')
major-n......space(n, 'major')

#Usage via CSS props

#Usage via themeable components

With applyTheme
import { Button, applyTheme } from 'bumbag';
const SaveButton = applyTheme(Button, {
styles: {
base: {
marginTop: 'major-2'
}
}
});
<SaveButton>Save</SaveButton>
With styled
import { Button, styled, space } from 'bumbag';
const SaveButton = styled(Button)`
margin-top: ${space(2, 'major')}rem;
`;
<SaveButton>Save</SaveButton>

#The 4px minor scale

The 4px minor scale is most commonly used for precise spacing (margins & paddings) of atomic components (e.g. the inner padding of a checkbox).

TokenpxremUtility
minor-14px0.25remspace(1, 'minor')
minor-28px0.5remspace(2, 'minor')
minor-312px0.75remspace(3, 'minor')
minor-416px1remspace(4, 'minor')
minor-520px1.25remspace(5, 'minor')
minor-n......space(n, 'minor')

#Usage via CSS props

#Usage via themeable components

With applyTheme
import { Button, applyTheme } from 'bumbag';
const SaveButton = applyTheme(Button, {
styles: {
base: {
padding: 'major-2'
}
}
});
<SaveButton>Save</SaveButton>
With styled
import { Button, styled, space } from 'bumbag';
const SaveButton = styled(Button)`
padding: ${space(2, 'major')}rem;
`;
<SaveButton>Save</SaveButton>

#Using a pre-defined set

Bumbag has the ability for you to specify your own pre-defined set of spacings. Pre-defined spacings can be used when you want to restrict the user to a set of sizes.

Bumbag has the following pre-defined attributes set by default:

TokenSizeValue
xs
8px - 0.5rem
space(1, 'major')
sm
16px - 1rem
space(2, 'major')
md
32px - 2rem
space(4, 'major')
lg
48px - 3rem
space(6, 'major')
xl
64px - 4rem
space(8, 'major')
2xl
96px - 6rem
space(12, 'major')
3xl
128px - 8rem
space(16, 'major')
4xl
160px - 10rem
space(20, 'major')
5xl
192px - 12rem
space(24, 'major')
6xl
224px - 14rem
space(28, 'major')

#Usage via CSS props

#Usage via themeable components

With applyTheme
import { Button, applyTheme } from 'bumbag';
const SaveButton = applyTheme(Button, {
styles: {
base: {
padding: 'xl'
}
}
});
<SaveButton>Save</SaveButton>
With styled
import { Button, styled, space } from 'bumbag';
const SaveButton = styled(Button)`
padding: ${space('xl')}rem;
`;
<SaveButton>Save</SaveButton>

#Theming

#Schema

{
spacing: {
minorUnit: number // default = 4,
majorUnit: number // default = 8,
// Plus your own pre-defined set...
[key: string]: number
// e.g. sm: space(2, 'major')
}
}
Copyright © 2020 Jake Moxey