-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use common
Space
type across components (#1433)
## What are you changing? - Use the common `Space` type in components that accept spacing values as props. - Fixes a bug where spacing styles are not applied if `space.0` is used due to `0` being falsy. - Update `Stack` stories to better show how spacing is applied. - Expands `Inline` and `Stack` stories to include examples of _all_ spacing values. <img width="654" alt="Screenshot 2024-05-08 at 15 00 27" src="https://github.com/guardian/csnx/assets/1166188/658fe4a8-ed26-4d8b-a037-84927618290e"> ## Why? - It removes a small amount of duplication and avoids having to update spacing values in multiple places. [New spacing values were added last year](#897), but some components still lack support for these as their types were not updated at the same time.
- Loading branch information
Showing
11 changed files
with
149 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@guardian/source': patch | ||
--- | ||
|
||
Fixes bug where `space.0` was not applied to `Inline` layouts and updates `Column` and `Stack` to support all spacing units |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 2 additions & 24 deletions
26
libs/@guardian/source/src/react-components/stack/styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,16 @@ | ||
import type { SerializedStyles } from '@emotion/react'; | ||
import { css } from '@emotion/react'; | ||
import { space } from '../../foundations'; | ||
import type { StackSpace } from './Stack'; | ||
import type { Space } from '../@types/Space'; | ||
|
||
export const stack = css` | ||
& > * { | ||
width: 100%; | ||
} | ||
`; | ||
|
||
const stackSpaceStyle = (number: StackSpace): SerializedStyles => css` | ||
export const stackSpace = (number: Space): SerializedStyles => css` | ||
& > * + * { | ||
margin-top: ${space[number]}px; | ||
} | ||
`; | ||
|
||
export const stackSpace: { | ||
1: SerializedStyles; | ||
2: SerializedStyles; | ||
3: SerializedStyles; | ||
4: SerializedStyles; | ||
5: SerializedStyles; | ||
6: SerializedStyles; | ||
9: SerializedStyles; | ||
12: SerializedStyles; | ||
24: SerializedStyles; | ||
} = { | ||
1: stackSpaceStyle(1), | ||
2: stackSpaceStyle(2), | ||
3: stackSpaceStyle(3), | ||
4: stackSpaceStyle(4), | ||
5: stackSpaceStyle(5), | ||
6: stackSpaceStyle(6), | ||
9: stackSpaceStyle(9), | ||
12: stackSpaceStyle(12), | ||
24: stackSpaceStyle(24), | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.