Skip to content

Commit 6cbc34d

Browse files
authored
refactor: migrate Field off TypographyNext (#4843)
1 parent e519ff2 commit 6cbc34d

8 files changed

Lines changed: 44 additions & 79 deletions

File tree

packages/eds-core-react/src/components/next/Checkbox/__snapshots__/Checkbox.test.tsx.snap

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ exports[`Checkbox (next) matches snapshot 1`] = `
6767
<label
6868
class="eds-field__label"
6969
data-baseline="center"
70-
data-font-family="ui"
71-
data-font-size="md"
72-
data-font-weight="normal"
73-
data-line-height="default"
74-
data-tracking="normal"
7570
for="test-id"
7671
>
7772
checkbox

packages/eds-core-react/src/components/next/Field/Field.Description.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
import { forwardRef } from 'react'
2-
import { TypographyNext } from '../../Typography'
32
import type { FieldDescriptionProps } from './Field.types'
43

54
export const FieldDescription = forwardRef<
65
HTMLParagraphElement,
76
FieldDescriptionProps
87
>(function FieldDescription({ children, className, ...rest }, ref) {
98
return (
10-
<TypographyNext
9+
<p
1110
ref={ref}
12-
as="p"
13-
family="ui"
14-
size="sm"
15-
baseline="center"
16-
lineHeight="default"
17-
tracking="normal"
11+
data-baseline="center"
1812
className={['eds-field__description', className]
1913
.filter(Boolean)
2014
.join(' ')}
2115
{...rest}
2216
>
2317
{children}
24-
</TypographyNext>
18+
</p>
2519
)
2620
})
2721

packages/eds-core-react/src/components/next/Field/Field.HelperMessage.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { forwardRef } from 'react'
2-
import { TypographyNext } from '../../Typography'
32
import type { HelperMessageProps } from './Field.HelperMessage.types'
43

54
/**
@@ -23,23 +22,18 @@ export const HelperMessage = forwardRef<
2322
HelperMessageProps
2423
>(function HelperMessage({ children, className, role, id, ...rest }, ref) {
2524
return (
26-
<TypographyNext
25+
<p
2726
ref={ref}
28-
as="p"
27+
data-baseline="grid"
2928
id={id}
30-
family="ui"
31-
size="sm"
32-
baseline="grid"
33-
lineHeight="default"
34-
tracking="normal"
3529
role={role}
3630
className={['eds-field__helper-message', className]
3731
.filter(Boolean)
3832
.join(' ')}
3933
{...rest}
4034
>
4135
{children}
42-
</TypographyNext>
36+
</p>
4337
)
4438
})
4539

packages/eds-core-react/src/components/next/Field/Field.Label.tsx

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,18 @@
11
import { forwardRef } from 'react'
2-
import { TypographyNext } from '../../Typography'
32
import type { FieldLabelProps } from './Field.types'
43

54
export const FieldLabel = forwardRef<HTMLLabelElement, FieldLabelProps>(
65
function FieldLabel({ children, className, indicator, ...rest }, ref) {
76
return (
8-
<TypographyNext
7+
<label
98
ref={ref}
10-
as="label"
11-
family="ui"
12-
size="md"
13-
baseline="center"
14-
lineHeight="default"
15-
weight="normal"
16-
tracking="normal"
9+
data-baseline="center"
1710
className={['eds-field__label', className].filter(Boolean).join(' ')}
1811
{...rest}
1912
>
2013
{children}
21-
{indicator && (
22-
<span className="eds-field__indicator" data-font-size="sm">
23-
{indicator}
24-
</span>
25-
)}
26-
</TypographyNext>
14+
{indicator && <span className="eds-field__indicator">{indicator}</span>}
15+
</label>
2716
)
2817
},
2918
)

packages/eds-core-react/src/components/next/Field/field.css

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
@layer eds-components {
22
.eds-field {
3-
/* Layout - use CSS variable for configurable width */
4-
display: flex;
5-
flex-direction: column;
6-
align-items: flex-start;
7-
gap: var(--eds-generic-gap-vertical);
8-
width: var(--eds-field-width, 100%);
93
/* Private color variables */
104
--_eds-field-label-color: var(--eds-color-text-strong);
115
--_eds-field-description-color: var(--eds-color-text-subtle);
126
--_eds-field-indicator-color: var(--eds-color-text-neutral-subtle);
137
--_eds-field-helper-color: var(--eds-color-text-subtle);
8+
9+
/* Layout - use CSS variable for configurable width */
10+
display: flex;
11+
flex-direction: column;
12+
gap: var(--eds-generic-gap-vertical);
13+
align-items: flex-start;
14+
15+
width: var(--eds-field-width, 100%);
16+
17+
/* Shared font-family — inherits to all text children */
18+
font-family: var(--eds-typography-ui-body-font-family);
1419
}
1520

1621
/* Horizontal layout for toggle inputs (checkbox, radio, switch) */
1722
.eds-field:is([data-position='start'], [data-position='end']) {
18-
flex-direction: row;
19-
flex-wrap: wrap;
20-
align-items: center;
23+
flex-flow: row wrap;
2124
gap: var(--eds-generic-gap-horizontal);
25+
align-items: center;
2226
}
2327

2428
.eds-field[data-position='end'] {
@@ -31,17 +35,23 @@
3135
flex-basis: 100%;
3236
}
3337

38+
/* Label uses data-baseline="center" for text-box trim + grid-snap padding —
39+
see [data-baseline='center'] rule in eds-tokens/src/css/typography.css */
3440
.eds-field__label {
35-
display: inline-flex;
36-
flex-wrap: wrap;
37-
align-items: center;
41+
display: block;
42+
43+
font-size: var(--eds-typography-ui-body-md-font-size);
44+
line-height: var(--eds-typography-ui-body-md-line-height-default);
45+
font-weight: var(--eds-typography-ui-body-md-font-weight-normal);
3846
color: var(--_eds-field-label-color);
3947
}
4048

4149
.eds-field__indicator {
4250
margin-inline-start: var(--eds-selectable-space-horizontal);
51+
52+
font-size: var(--eds-typography-ui-body-sm-font-size);
53+
line-height: var(--eds-typography-ui-body-sm-line-height-default);
4354
color: var(--_eds-field-indicator-color);
44-
font-size: var(--eds-typography-font-size);
4555
vertical-align: middle;
4656
}
4757

@@ -50,16 +60,22 @@
5060
color: var(--_eds-field-description-color);
5161
}
5262

53-
/* HelperMessage styling */
5463
.eds-field__helper-message {
5564
margin: 0;
65+
/* Tighten spacing above helper-message to 3xs (overrides parent gap).
66+
Longhand follows shorthand to win the cascade. */
67+
margin-block-start: calc(
68+
var(--eds-spacing-vertical-3xs) - var(--eds-generic-gap-vertical)
69+
);
5670
color: var(--_eds-field-helper-color);
5771
}
5872

59-
/* Reduce gap before helper message to 3xs spacing.
60-
Applied to the preceding sibling (not helper message) to avoid [data-font-family] margin: 0 override. */
61-
.eds-field > :has(+ .eds-field__helper-message) {
62-
margin-block-end: calc(var(--eds-spacing-vertical-3xs) - var(--eds-generic-gap-vertical));
73+
/* data-baseline="grid" on these elements handles text-box trim via
74+
[data-baseline='grid'] in eds-tokens/src/css/typography.css */
75+
.eds-field__description,
76+
.eds-field__helper-message {
77+
font-size: var(--eds-typography-ui-body-sm-font-size);
78+
line-height: var(--eds-typography-ui-body-sm-line-height-default);
6379
}
6480

6581
/* Only helper message changes color when disabled */

packages/eds-core-react/src/components/next/Radio/__snapshots__/Radio.test.tsx.snap

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ exports[`Radio (next) matches snapshot 1`] = `
5252
<label
5353
class="eds-field__label"
5454
data-baseline="center"
55-
data-font-family="ui"
56-
data-font-size="md"
57-
data-font-weight="normal"
58-
data-line-height="default"
59-
data-tracking="normal"
6055
for="test-id"
6156
>
6257
radio

packages/eds-core-react/src/components/next/Switch/__snapshots__/Switch.test.tsx.snap

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ exports[`Switch (next) matches snapshot 1`] = `
3131
<label
3232
class="eds-field__label"
3333
data-baseline="center"
34-
data-font-family="ui"
35-
data-font-size="md"
36-
data-font-weight="normal"
37-
data-line-height="default"
38-
data-tracking="normal"
3934
for="test-id"
4035
>
4136
switch

packages/eds-core-react/src/components/next/TextField/__snapshots__/TextField.test.tsx.snap

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ exports[`TextField (Next EDS 2.0) Matches snapshot 1`] = `
1111
<label
1212
class="eds-field__label"
1313
data-baseline="center"
14-
data-font-family="ui"
15-
data-font-size="md"
16-
data-font-weight="normal"
17-
data-line-height="default"
18-
data-tracking="normal"
1914
for="test-id-input"
2015
>
2116
Label
@@ -24,10 +19,6 @@ exports[`TextField (Next EDS 2.0) Matches snapshot 1`] = `
2419
<p
2520
class="eds-field__description"
2621
data-baseline="center"
27-
data-font-family="ui"
28-
data-font-size="sm"
29-
data-line-height="default"
30-
data-tracking="normal"
3122
id="test-id-description"
3223
>
3324
Description text
@@ -54,10 +45,6 @@ exports[`TextField (Next EDS 2.0) Matches snapshot 1`] = `
5445
<p
5546
class="eds-field__helper-message"
5647
data-baseline="grid"
57-
data-font-family="ui"
58-
data-font-size="sm"
59-
data-line-height="default"
60-
data-tracking="normal"
6148
id="test-id-helper-message"
6249
>
6350
Helper message

0 commit comments

Comments
 (0)