Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update global EUI font size to use configurable theme units #7182

Merged
merged 9 commits into from
Oct 4, 2023
5 changes: 4 additions & 1 deletion .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ import { hideStorybookControls } from './utils';
const preview: Preview = {
decorators: [
(Story, context) => (
<EuiProvider colorMode={context.globals.colorMode}>
<EuiProvider
colorMode={context.globals.colorMode}
{...(context.componentId === 'euiprovider' && context.args)}
>
<div
css={[
writingModeStyles.writingMode,
Expand Down
25 changes: 25 additions & 0 deletions src-docs/src/views/theme/typography/_typography_js.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
EuiPanel,
EuiSpacer,
EuiText,
EuiCallOut,
EuiLink,
} from '../../../../../src/components';

import {
Expand Down Expand Up @@ -285,6 +287,29 @@ export const FontScaleValuesJS = () => {
/>
</EuiDescribedFormGroup>
</EuiPanel>
<EuiSpacer size="m" />
<EuiCallOut
iconType="accessibility"
title={
<>
We strongly recommend using relative (<EuiCode>rem</EuiCode> or{' '}
<EuiCode>em</EuiCode>) units instead of <EuiCode>px</EuiCode> when
possible{' '}
</>
}
>
<p>
Relative font units respect configured browser default font sizes,
which some users may set to larger than than the 16px default due to,
e.g. visual impairment, monitor size, or personal preference.{' '}
<EuiLink
href="https://usability.yale.edu/web-accessibility/articles/zoom-resizing-text"
target="_blank"
>
Read more on accessible text resizing.
</EuiLink>
</p>
</EuiCallOut>
<EuiSpacer />
<EuiBasicTable<FontScaleDetails>
tableLayout="auto"
Expand Down
43 changes: 43 additions & 0 deletions src/components/provider/provider.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';

import { EuiProvider, EuiProviderProps } from './provider';

const meta: Meta<EuiProviderProps<{}>> = {
title: 'EuiProvider',
component: EuiProvider,
argTypes: {
colorMode: {
control: 'select',
options: ['light', 'dark', 'inverse', 'LIGHT', 'DARK', 'INVERSE'],
},
modify: { control: 'object' },
componentDefaults: { control: 'object' },
globalStyles: { control: 'boolean' },
utilityClasses: { control: 'boolean' },
},
};

export default meta;
type Story = StoryObj<EuiProviderProps<{}>>;

export const FontDefaultUnits: Story = {
render: () => (
<>
Change <strong>`modify.font.defaultUnits`</strong> to{' '}
<strong>`rem`, `em`, or `px`</strong> and then inspect this demo's `html`
CSS
</>
),
args: {
modify: { font: { defaultUnits: 'rem' } },
},
};
20 changes: 13 additions & 7 deletions src/global_styling/reset/global_styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ export const EuiGlobalStyles = ({}: EuiGlobalStylesProps) => {
* This font reset sets all our base font/typography related properties
* that are needed to override browser-specific element settings.
*/
const fontReset = `
font-family: ${font.family};
font-size: ${`${font.scale[font.body.scale] * base}px`};
line-height: ${base / (font.scale[font.body.scale] * base)};
font-weight: ${font.weight[font.body.weight]};
`;
const fontBodyScale = font.scale[font.body.scale];
const fontReset = {
fontFamily: font.family,
fontSize: `${
font.defaultUnits === 'px' ? fontBodyScale * base : fontBodyScale
}${font.defaultUnits}`,
lineHeight: base / (fontBodyScale * base),
fontWeight: font.weight[font.body.weight],
};

/**
* Final styles
Expand Down Expand Up @@ -70,7 +73,10 @@ export const EuiGlobalStyles = ({}: EuiGlobalStylesProps) => {
input,
textarea,
select {
${fontReset}
${{
...fontReset,
fontSize: '1rem', // Inherit from html root
}}
}

// Chrome has opinionated select:disabled opacity styles that need to be overridden
Expand Down
7 changes: 7 additions & 0 deletions upcoming_changelogs/7182.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**Breaking changes**

- EUI's global body font-size now respects the `font.defaultUnits` token. This means that the global font size will use the `rem` unit by default, instead of `px`.

**Accessibility**

- When using `rem` or `em` font units, EUI now respects, instead of ignoring, browser default font sizes set by end users.
Loading