-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
align values of `rem*` exports from source Brings `remSize`, `remIconSize`, `remHeight` and `remWidth` into line with `remSpace`, by changing their values from numbers (of rems) to strings with `rem` units.
- Loading branch information
Showing
10 changed files
with
113 additions
and
71 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
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,42 @@ | ||
--- | ||
'@guardian/source-development-kitchen': major | ||
'@guardian/source': major | ||
--- | ||
|
||
Brings `remSize`, `remIconSize`, `remHeight` and `remWidth` into line with `remSpace`, by changing their values from numbers (of rems) to strings with `rem` units. | ||
|
||
_The sizes haven't changed, only the way they are exported._ | ||
|
||
### Before | ||
|
||
```js | ||
const style = ` | ||
bottom: ${remHeight.ctaSmall}rem; | ||
`; | ||
``` | ||
|
||
### After | ||
|
||
```js | ||
const style = ` | ||
bottom: ${remHeight.ctaSmall}; | ||
`; | ||
``` | ||
|
||
If you have been performing calculations with the old number values in JS, you can use the [CSS `calc` function](https://developer.mozilla.org/en-US/docs/Web/CSS/calc) instead: | ||
|
||
### Before | ||
|
||
```js | ||
const style = ` | ||
bottom: -${remHeight.ctaSmall / 2}rem; | ||
`; | ||
``` | ||
|
||
### After | ||
|
||
```js | ||
const style = ` | ||
bottom: calc(-${remHeight.ctaSmall} / 2); | ||
`; | ||
``` |
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
13 changes: 10 additions & 3 deletions
13
libs/@guardian/source/src/foundations/utils/convert-value.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,9 +1,16 @@ | ||
export type RemString<N extends number = number> = `${N}rem`; | ||
export type PxString<N extends number = number> = `${N}px`; | ||
|
||
export const rootPixelFontSize = 16; | ||
|
||
export const pxToRem = (px: number): number => px / rootPixelFontSize; | ||
export const pxStringToRem = (px: `${number}px`): number => | ||
export const pxToRem = (px: number): RemString => | ||
`${px / rootPixelFontSize}rem`; | ||
|
||
export const pxStringToRem = (px: PxString): RemString => | ||
pxToRem(pxStringToNumber(px)); | ||
export const pxStringToNumber = <N extends number>(px: `${N}px`): N => | ||
|
||
export const pxStringToNumber = <N extends number>(px: PxString<N>): N => | ||
Number(px.slice(0, -2)) as N; | ||
|
||
export const fontArrayToString = (fonts: readonly string[]): string => | ||
fonts.map((name) => (name.includes(' ') ? `"${name}"` : name)).join(', '); |
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