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 (recommended)#
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.
Token | px | rem | Utility function |
---|---|---|---|
major-1 | 8px | 0.5rem | space(1, 'major') |
major-2 | 16px | 1rem | space(2, 'major') |
major-3 | 24px | 1.5rem | space(3, 'major') |
major-4 | 32px | 2rem | space(4, 'major') |
major-5 | 40px | 2.5rem | space(5, 'major') |
major-n | ... | ... | space(n, 'major') |
With style props#
With applyTheme
#
import { Button, applyTheme } from 'bumbag-native';const SaveButton = applyTheme(Button, {styles: {base: {marginTop: 'major-2'}}});<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).
Token | px | rem | Utility |
---|---|---|---|
minor-1 | 4px | 0.25rem | space(1, 'minor') |
minor-2 | 8px | 0.5rem | space(2, 'minor') |
minor-3 | 12px | 0.75rem | space(3, 'minor') |
minor-4 | 16px | 1rem | space(4, 'minor') |
minor-5 | 20px | 1.25rem | space(5, 'minor') |
minor-n | ... | ... | space(n, 'minor') |
With style props#
With applyTheme
#
import { Button, applyTheme } from 'bumbag-native';const SaveButton = applyTheme(Button, {styles: {base: {padding: 'major-2'}}});<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:
Token | Size | Value |
---|---|---|
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') |
With style props#
With applyTheme
#
import { Button, applyTheme } from 'bumbag-native';const SaveButton = applyTheme(Button, {styles: {base: {padding: 'xl'}}});<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')}}