Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new units to spacing scale #897

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-turtles-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@guardian/source-foundations': minor
---

Add new spacing units to maintain parity with Figma
12 changes: 12 additions & 0 deletions libs/@guardian/source-foundations/src/space/space.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,36 @@ const container = css`
The following units can be applied to margin or padding properties, vertically
or horizontally.

- `space[0]` -> 2px
- `space[1]` -> 4px
- `space[2]` -> 8px
- `space[3]` -> 12px
- `space[4]` -> 16px
- `space[5]` -> 20px
- `space[6]` -> 24px
- `space[8]` -> 32px
- `space[9]` -> 36px
- `space[10]` -> 40px
- `space[12]` -> 48px
- `space[14]` -> 56px
- `space[16]` -> 64px
- `space[18]` -> 72px
- `space[24]` -> 96px

The same scale is also available as rems:

- `remSpace[0]` -> 0.125rem
- `remSpace[1]` -> 0.25rem
- `remSpace[2]` -> 0.5rem
- `remSpace[3]` -> 0.75rem
- `remSpace[4]` -> 1rem
- `remSpace[5]` -> 1.25rem
- `remSpace[6]` -> 1.5rem
- `remSpace[8]` -> 2rem
- `remSpace[9]` -> 2.25rem
- `remSpace[10]` -> 2.5rem
- `remSpace[12]` -> 3rem
- `remSpace[14]` -> 3.5rem
- `remSpace[16]` -> 4rem
- `remSpace[18]` -> 4.5rem
- `remSpace[24]` -> 6rem
24 changes: 24 additions & 0 deletions libs/@guardian/source-foundations/src/space/space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,37 @@ import { pxToRem } from '../utils/px-to-rem';
*
* Can be applied to margin or padding properties, vertically or horizontally.
*
** `space[0]` -> 2px
** `space[1]` -> 4px
** `space[2]` -> 8px
** `space[3]` -> 12px
** `space[4]` -> 16px
** `space[5]` -> 20px
** `space[6]` -> 24px
** `space[8]` -> 32px
** `space[9]` -> 36px
** `space[10]` -> 40px
** `space[12]` -> 48px
** `space[14]` -> 56px
** `space[16]` -> 64px
** `space[18]` -> 72px
** `space[24]` -> 96px
*/
export const space = {
0: 2,
1: 4,
2: 8,
3: 12,
4: 16,
5: 20,
6: 24,
8: 32,
9: 36,
10: 40,
12: 48,
14: 56,
16: 64,
18: 72,
24: 96,
} as const;

Expand All @@ -34,25 +46,37 @@ export const space = {
*
* Can be applied to margin or padding properties, vertically or horizontally.
*
** `remSpace[0]` -> 0.125rem
** `remSpace[1]` -> 0.25rem
** `remSpace[2]` -> 0.5rem
** `remSpace[3]` -> 0.75rem
** `remSpace[4]` -> 1rem
** `remSpace[5]` -> 1.25rem
** `remSpace[6]` -> 1.5rem
** `remSpace[8]` -> 2rem
** `remSpace[9]` -> 2.25rem
** `remSpace[10]` -> 2.5rem
** `remSpace[12]` -> 3rem
** `remSpace[14]` -> 3.5rem
** `remSpace[16]` -> 4rem
** `remSpace[18]` -> 4.5rem
** `remSpace[24]` -> 6rem
*/
export const remSpace: { [K in keyof typeof space]: string } = {
0: `${pxToRem(space[0])}rem`,
1: `${pxToRem(space[1])}rem`,
2: `${pxToRem(space[2])}rem`,
3: `${pxToRem(space[3])}rem`,
4: `${pxToRem(space[4])}rem`,
5: `${pxToRem(space[5])}rem`,
6: `${pxToRem(space[6])}rem`,
8: `${pxToRem(space[8])}rem`,
9: `${pxToRem(space[9])}rem`,
10: `${pxToRem(space[10])}rem`,
12: `${pxToRem(space[12])}rem`,
14: `${pxToRem(space[14])}rem`,
16: `${pxToRem(space[16])}rem`,
18: `${pxToRem(space[18])}rem`,
24: `${pxToRem(space[24])}rem`,
};

Expand Down