Skip to content

Commit

Permalink
style(Typography): added css variables needed for heading theming (#2348
Browse files Browse the repository at this point in the history
)

## Summary

Theming the typography requires us to add some more css variables. In
particular, headings need some more granularity. Since there's no common
css class for headings we have to generate a class/tag namespace that covers alle of typography.

---------

Co-authored-by: Tobias Høegh <[email protected]>
  • Loading branch information
snorrekim and tujoworker authored Jun 23, 2023
1 parent 5f5ff8e commit 224d8b2
Show file tree
Hide file tree
Showing 38 changed files with 510 additions and 287 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe('Typography for Sbanken', () => {
cy.get('.typography-box > .dnb-h--xx-large').should(
'have.css',
'font-size',
'48px'
'50px'
)
})

Expand All @@ -150,7 +150,7 @@ describe('Typography for Sbanken', () => {
cy.get('.typography-box > .dnb-h--x-large').should(
'have.css',
'font-size',
'34px'
'42px'
)
})

Expand All @@ -159,7 +159,7 @@ describe('Typography for Sbanken', () => {
cy.get('.typography-box > .dnb-h--large').should(
'have.css',
'font-size',
'26px'
'34px'
)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Example = styled.div`
margin: 0 !important;
}
`
const Contrast = styled(Example)`
const ContrastExample = styled(Example)`
display: inline-block;
padding: 0.5rem;
Expand Down Expand Up @@ -87,15 +87,15 @@ export const AnchorExampleStates = () => (

export const AnchorExampleHelperClasses = () => (
<Wrapper>
<ComponentBox hideCode scope={{ Example, Contrast }}>
<Contrast data-visual-test="anchor-contrast">
<ComponentBox hideCode scope={{ Example, ContrastExample }}>
<ContrastExample data-visual-test="anchor-contrast">
<Anchor
href="/uilib/components/anchor"
className="dnb-anchor--contrast"
>
Contrast Style
</Anchor>
</Contrast>
</ContrastExample>
<Example>
<Anchor
href="/uilib/components/anchor"
Expand Down Expand Up @@ -185,19 +185,21 @@ export const AnchorExampleIcons = () => (
href="/uilib/components/anchor"
icon={<IconPrimary icon="question" />}
>
Anchor with Icon left using a react element
Anchor with Icon left using a html/react element
</Anchor>
</Example>
<Example data-visual-test="anchor-paragraph">
<P>
text{' '}
text
{' '}
<Anchor
href="/uilib/components/anchor"
icon="bell"
iconPosition="right"
>
Inside a Paragraph
</Anchor>{' '}
</Anchor>
{' '}
text
</P>
</Example>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ To force a specific state of style, use the following classes to do so:

### Anchor with icons

Icons can be adde with the `icon` and `iconPosition` props. Normally by sending in the name if an icon, but it is also possible to send in html/react code (normally for custom svg).

<AnchorExampleIcons />

### Anchor with `target="_blank"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import { Heading } from '@dnb/eufemia/components'
```jsx
import { H1, H2, ... } from '@dnb/eufemia'
```

### The most basic use of headings

Just using the `H1, H2, etc.` components will give you the basic headings.
Expand All @@ -67,7 +68,7 @@ Just using the `H1, H2, etc.` components will give you the basic headings.

### Heading typography using React JSX

The visual size of a heading can be customized using the `size` prop with values: `xx-large | x-large | large | medium | basis | small | x-small`
The visual size of a heading can be customized using the `size` prop with values: `xx-large | x-large | large | medium | basis | small | x-small`

<HeadingTypographyExample />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ export const HeadingModifiersExample = () => (
<h2 className="dnb-h--large">
Normal dnb-h--large <small>dnb-h--medium</small>
</h2>
<h3 className="dnb-lead">
<h3 className="dnb-h--medium">
Normal dnb-h--medium <small>dnb-h--basis</small>
</h3>
<h3 className="dnb-lead">
Normal dnb-lead <small>small</small>
</h3>
</article>
</ComponentBox>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,9 @@ describe('style build', () => {
}`)
expect(content).toContain(`
.dnb-h--basis {
font-size: var(--font-size-basis);
line-height: var(--line-height-basis);
font-size: var(--typography-h-basis-font-size);
line-height: var(--typography-h-basis-line-height);
font-weight: var(--typography-h-basis-weight);
}`)
}

Expand All @@ -434,19 +435,15 @@ describe('style build', () => {
)
expect(content).toContain(`font-family: MaisonNeueHeadings;`)
expect(content).toContain(`
.dnb-h--basis {
font-size: var(--font-size-basis);
line-height: var(--line-height-basis);
}`)
expect(content).toContain(`
.dnb-p {
font-size: var(--font-size-basis);
padding: 0;
}`)
expect(content).toContain(`
.dnb-h--basis {
font-size: var(--font-size-basis);
line-height: var(--line-height-basis);
font-size: var(--typography-h-basis-font-size);
line-height: var(--typography-h-basis-line-height);
font-weight: var(--typography-h-basis-weight);
}`)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ export default {
'--sb-font-size-basis': '1rem',
'--sb-font-size-basis--em': '1em',
'--sb-font-size-lead': '1.25rem',
'--sb-font-size-large': '1.625rem',
'--sb-font-size-x-large': '2.125rem',
'--sb-font-size-xx-large': '3rem',
'--sb-font-size-medium': '1.625rem',
'--sb-font-size-large': '2.125rem',
'--sb-font-size-x-large': '2.625rem',
'--sb-font-size-xx-large': '3.125rem',
'--sb-line-height-x-small': '1.125rem',
'--sb-line-height-small': '1.25rem',
'--sb-line-height-basis': '1.5rem',
'--sb-line-height-basis--em': '1.5em',
'--sb-line-height-lead': '1.75rem',
'--sb-line-height-medium': '2rem',
'--sb-line-height-large': '2.5rem',
'--sb-line-height-x-large': '3.5rem',
'--sb-line-height-x-large': '3rem',
'--sb-line-height-xx-large': '3.5rem',
'--sb-color-black': '#000',
'--sb-color-text': '#18172a',
'--sb-color-gray-dark-3': '#3a3970',
Expand Down Expand Up @@ -109,6 +111,7 @@ export default {
'--font-size-small': '1rem',
'--font-size-basis': '1.125rem',
'--font-size-basis--em': '1em',
'--font-size-lead': 'var(--font-size-medium)',
'--font-size-medium': '1.25rem',
'--font-size-large': '1.625rem',
'--font-size-x-large': '2.125rem',
Expand All @@ -122,6 +125,7 @@ export default {
'--line-height-medium': '2rem',
'--line-height-large': '2.5rem',
'--line-height-x-large': '3.5rem',
'--line-height-xx-large': 'var(--line-height-x-large)',
'--color-mint-green-50': '#d2f0e9',
'--color-mint-green-25': '#e9f8f4',
'--color-mint-green-12': '#f4fbf9',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ describe.each(['ui', 'sbanken'])('Anchor for %s', (themeName) => {
it('have to match anchor in heading', async () => {
const screenshot = await makeScreenshot({
selector: '[data-visual-test="anchor-heading"]',
matchConfig: {
failureThreshold: 0.0016,
},
})
expect(screenshot).toMatchImageSnapshot()
})
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ describe.each(['ui', 'sbanken'])('Logo for %s', (themeName) => {
it('have to match the default "Logo"', async () => {
const screenshot = await makeScreenshot({
selector: '[data-visual-test="logo-default"]',
matchConfig: {
failureThreshold: 0.19,
},
})
expect(screenshot).toMatchImageSnapshot()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ describe.each(['ui', 'sbanken', 'eiendom'])(
}
)


describe.each(['ui', 'sbanken'])(
describe.each(['ui', 'sbanken', 'eiendom'])(
'Heading for %s',
(themeName) => {
setupPageScreenshot({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@ describe.each(['ui', 'sbanken'])('Paragraph for %s', (themeName) => {
it('have to match the paragraph with additional elements', async () => {
const screenshot = await makeScreenshot({
selector: '[data-visual-test="paragraph-additional"]',
matchConfig: {
failureThreshold: 0.0099, // the underlines gets blurry in the build version
},
})
expect(screenshot).toMatchImageSnapshot()
})
})

describe.each(['ui', 'sbanken'])(
'Paragraph for %s',
(themeName) => {
setupPageScreenshot({
themeName,
url: '/uilib/elements/paragraph',
})
describe.each(['ui', 'sbanken'])('Paragraph for %s', (themeName) => {
setupPageScreenshot({
themeName,
url: '/uilib/elements/paragraph',
})

it('matches all sizes and weights', async () => {
const screenshot = await makeScreenshot({
selector: '[data-visual-test="paragraph-sizes"]',
})
expect(screenshot).toMatchImageSnapshot()
it('matches all sizes and weights', async () => {
const screenshot = await makeScreenshot({
selector: '[data-visual-test="paragraph-sizes"]',
})
}
)
expect(screenshot).toMatchImageSnapshot()
})
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,69 @@
@use '../../../style/elements/ui-spacing.scss';
@import './typography-mixins.scss';

@include typographySelectors() {
--typography-h-default-font-family: var(--font-family-default);
--typography-h-default-font-weight: var(--font-weight-medium);

// Heading xx-large
--typography-h-xx-large-font-size: var(--font-size-xx-large);
--typography-h-xx-large-line-height: var(--line-height-xx-large);
--typography-h-xx-large-small-font-size: var(--font-size-x-large);
--typography-h-xx-large-small-line-height: var(--line-height-x-large);
--typography-h-xx-large-weight: var(--font-weight-medium);

// Heading x-large
--typography-h-x-large-font-size: var(--font-size-x-large);
--typography-h-x-large-line-height: var(--line-height-x-large);
--typography-h-x-large-small-font-size: var(--font-size-large);
--typography-h-x-large-small-line-height: var(--line-height-large);
--typography-h-x-large-weight: var(--font-weight-medium);

// Heading large
--typography-h-large-font-size: var(--font-size-large);
--typography-h-large-line-height: var(--line-height-large);
--typography-h-large-small-font-size: var(--font-size-medium);
--typography-h-large-small-line-height: var(--line-height-medium);
--typography-h-large-weight: var(--font-weight-medium);

// Lead
--typography-lead-font-size: var(--font-size-lead);
--typography-lead-line-height: var(--line-height-lead);
--typography-lead-small-font-size: var(--font-size-lead);
--typography-lead-small-line-height: var(--line-height-lead);
--typography-lead-weight: var(--font-weight-medium);

// Heading medium
--typography-h-medium-font-size: var(--font-size-medium);
--typography-h-medium-line-height: var(--line-height-medium);
--typography-h-medium-small-font-size: var(--font-size-basis);
--typography-h-medium-small-line-height: var(--line-height-basis);
--typography-h-medium-weight: var(--font-weight-medium);

// Heading basis
--typography-h-basis-font-size: var(--font-size-basis);
--typography-h-basis-line-height: var(--line-height-basis);
--typography-h-basis-small-font-size: var(--font-size-small);
--typography-h-basis-small-line-height: var(--line-height-small);
--typography-h-basis-weight: var(--font-weight-medium);

// Heading small
--typography-h-small-font-size: var(--font-size-small);
--typography-h-small-line-height: var(--line-height-small);
--typography-h-small-small-font-size: var(--font-size-x-small);
--typography-h-small-small-line-height: var(--line-height-x-small);
--typography-h-small-weight: var(--font-weight-medium);

// Heading x-small
--typography-h-x-small-font-size: var(--font-size-x-small);
--typography-h-x-small-line-height: var(--line-height-x-small);
--typography-h-x-small-weight: var(--font-weight-medium);
}

@include headingClasses() {
@include headingDefaults();
}

.dnb-small {
font-size: var(--font-size-small);
}
Expand Down Expand Up @@ -48,11 +111,12 @@ sub {
@include headingSize_large();
}

/* dnb-h--medium looks the same as .dnb-lead */
.dnb-lead,
.dnb-lead {
@include typography_lead();
}

.dnb-h--medium {
@include headingSize_medium();
font-weight: var(--font-weight-medium);
}

// The rest of the Headings are nod defned by the Eufemia Typography
Expand All @@ -68,27 +132,6 @@ sub {
@include headingSize_x-small();
}

// Headings
.dnb-lead,
.dnb-h--xx-large,
.dnb-h--x-large,
.dnb-h--large,
.dnb-h--medium,
.dnb-h--basis,
.dnb-h--small,
.dnb-h--x-small,
// make exception on headings which are inside of dnb-core-style
.dnb-core-style .dnb-lead,
.dnb-core-style .dnb-h--xx-large,
.dnb-core-style .dnb-h--x-large,
.dnb-core-style .dnb-h--large,
.dnb-core-style .dnb-h--medium,
.dnb-core-style .dnb-h--basis,
.dnb-core-style .dnb-h--small,
.dnb-core-style .dnb-h--x-small {
@include headingDefaults();
}

// Spacing
.dnb-spacing {
.dnb-h--xx-large,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@use '../typography-mixins.scss' as typography;

@include typography.typographySelectors() {
--typography-h-xx-large-weight: var(--font-weight-regular);
--typography-h-x-large-weight: var(--font-weight-regular);
--typography-h-large-weight: var(--font-weight-regular);
--typography-h-medium-weight: var(--font-weight-regular);
--typography-h-basis-weight: var(--font-weight-regular);
--typography-h-small-weight: var(--font-weight-regular);
--typography-h-x-small-weight: var(--font-weight-regular);
}
Loading

1 comment on commit 224d8b2

@vercel
Copy link

@vercel vercel bot commented on 224d8b2 Jun 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.