Skip to content

Commit ca8ce75

Browse files
committed
renamed onGrid to baseline, add monoSpacedNumbers
1 parent db2e697 commit ca8ce75

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

packages/eds-core-react/src/components/Typography/Text/Text.stories.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ export const Demo: StoryFn<TextProps> = () => {
108108
A heading
109109
</Text>
110110
<Text>
111-
<b>Lorem ipsum dolor sit amet</b>, consectetur adipiscing elit, sed do
112-
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
113-
minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
114-
ex ea commodo consequat.
111+
<b>Lorem ipsum dolor sit amet</b>, 0123456789 consectetur adipiscing
112+
elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
113+
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
114+
ut aliquip ex ea commodo consequat.
115115
</Text>
116116
<Text as="a" href="#q">
117117
As a link
@@ -130,6 +130,16 @@ export const Demo: StoryFn<TextProps> = () => {
130130
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
131131
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
132132
</Text>
133+
<Text>
134+
<b>Normal numbers</b>
135+
</Text>
136+
<Text size="3xl">0123456789</Text>
137+
<Text>
138+
<b>Monospaced numbers</b>
139+
</Text>
140+
<Text size="3xl" monoSpacedNumbers>
141+
0123456789
142+
</Text>
133143
</>
134144
)
135145
}

packages/eds-core-react/src/components/Typography/Text/Text.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ export type TextProps = TypographyProps & {
77
/** When true, text is pushed to the bottom of its text-box (making it "on grid" as the total heigth is rounded to a multiple of 4px), when false it is centered within the text-box. Only works when variant is "ui"
88
* @default false
99
*/
10-
onGrid?: boolean
11-
/** header: uses the "equinor" typeface. Please use the "as" prop to assign the correct header level when variant is header. Always "on grid"
12-
* body: uses "inter" typeface. Is always "on grid"
13-
* ui: uses inter typeface. For use in ui components such as buttons, tabs, chips etc. Unlocks "onGrid" prop which is false by default to center text vertically.
10+
baselined?: boolean
11+
/** header: uses the "equinor" typeface. Please use the "as" prop to assign the correct header level when variant is header. Always "baselined"
12+
* body: uses "inter" typeface. Is always "baselined"
13+
* ui: uses inter typeface. For use in ui components such as buttons, tabs, chips etc. Unlocks "baselined" prop which is false by default to center text vertically.
1414
* @default 'body'
1515
*/
1616
variant?: 'ui' | 'body' | 'header'
17+
monoSpacedNumbers?: boolean
1718
as?: ElementType
1819
}
1920
const INTER_VERTICAL_OFFSET = 0.002
2021
const EQUINOR_VERTICAL_OFFSET = 0.06
22+
//prominence/color
2123

2224
export const Text: OverridableComponent<TextProps, HTMLElement> = forwardRef(
2325
function Text(
@@ -27,10 +29,11 @@ export const Text: OverridableComponent<TextProps, HTMLElement> = forwardRef(
2729
fontWeight = 'normal',
2830
letterSpacing = 'normal',
2931
variant = 'body',
32+
monoSpacedNumbers,
3033
lines,
3134
color,
3235
as,
33-
onGrid = false,
36+
baselined = false,
3437
children,
3538
...rest
3639
},
@@ -40,7 +43,7 @@ export const Text: OverridableComponent<TextProps, HTMLElement> = forwardRef(
4043
variant === 'header' ? variant : 'ui-body'
4144
const offset =
4245
variant === 'header' ? EQUINOR_VERTICAL_OFFSET : INTER_VERTICAL_OFFSET
43-
const gridOn = variant === 'ui' ? onGrid : true
46+
const gridOn = variant === 'ui' ? baselined : true
4447
return (
4548
<Typography
4649
ref={ref}
@@ -53,6 +56,7 @@ export const Text: OverridableComponent<TextProps, HTMLElement> = forwardRef(
5356
$lines={lines}
5457
$fontWeight={fontWeight}
5558
$letterSpacing={letterSpacing}
59+
$monoSpacedNumbers={monoSpacedNumbers}
5660
$onGrid={gridOn}
5761
{...rest}
5862
>

packages/eds-core-react/src/components/Typography/_components/Typography.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type StyleHeadingProps = {
1414
$lineHeight: TypographyLineHeight
1515
$fontWeight: TypographyFontWeight
1616
$letterSpacing: TypographyLetterSpacing
17+
$monoSpacedNumbers?: boolean
1718
$offset?: number
1819
$onGrid?: boolean
1920
$color?: string
@@ -28,6 +29,7 @@ export const Typography = styled.p<StyleHeadingProps>`
2829
$lineHeight,
2930
$fontWeight,
3031
$letterSpacing,
32+
$monoSpacedNumbers,
3133
$offset = 0,
3234
$onGrid = true,
3335
$color,
@@ -51,6 +53,7 @@ export const Typography = styled.p<StyleHeadingProps>`
5153
line-height: ${`var(--eds-typography-${$type}-${$size}-lineheight-${$lineHeight})`};
5254
font-weight: ${`var(--eds-typography-${$type}-${$size}-font-weight-${$fontWeight})`};
5355
letter-spacing: ${`var(--eds-typography-${$type}-${$size}-tracking-${$letterSpacing})`};
56+
font-variant-numeric: ${$monoSpacedNumbers ? 'tabular-nums' : 'normal'};
5457
/*TODO: determine if --override-text-color/link-color is needed or if inherit covers all the bases. override overrides all, while inherit only applies when color prop is not set*/
5558
color: var(--override-text-color, var(--_text-preset-color, inherit));
5659
--_offset: calc(${$offset} * 1em);

0 commit comments

Comments
 (0)