Skip to content

Commit 62fd363

Browse files
committed
Create JS euiTitle() mixin and add sizes styling
- and per-theme titles settings - just amsterdam for now, but we can possibly expand this if we add more themes in the future + delete old global_styling title files in favor of component-specific logic
1 parent 922ca52 commit 62fd363

File tree

5 files changed

+100
-141
lines changed

5 files changed

+100
-141
lines changed

src/components/title/_title.scss

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/components/title/title.styles.ts

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,89 @@
66
* Side Public License, v 1.
77
*/
88

9+
import { CSSProperties } from 'react';
910
import { css } from '@emotion/react';
1011
import { UseEuiTheme } from '../../services';
11-
import { euiTextBreakWord } from '../../global_styling';
12+
import {
13+
euiTextBreakWord,
14+
euiFontSizeFromScale,
15+
euiLineHeightFromBaseline,
16+
_EuiThemeFontScale,
17+
_EuiThemeFontSizeMeasurement,
18+
} from '../../global_styling';
19+
import { EuiTitleSize } from './title';
1220

21+
/**
22+
* Theme-specific scale settings
23+
*/
24+
type _EuiThemeTitle = {
25+
fontSize: _EuiThemeFontScale;
26+
lineHeight: _EuiThemeFontScale;
27+
fontWeight?: CSSProperties['fontWeight']; // Defaults to bold
28+
letterSpacing?: string; // Not currently used in Amsterdam, but may be used in future themes
29+
};
30+
31+
const amsterdamThemeTitles: {
32+
[size in EuiTitleSize]: _EuiThemeTitle;
33+
} = {
34+
xxxs: {
35+
fontSize: 'xs',
36+
lineHeight: 'xs',
37+
},
38+
xxs: {
39+
fontSize: 's',
40+
lineHeight: 'm',
41+
},
42+
xs: {
43+
fontSize: 'm',
44+
lineHeight: 'm',
45+
},
46+
s: {
47+
fontSize: 'l',
48+
lineHeight: 'xl',
49+
},
50+
m: {
51+
fontSize: 'xl',
52+
lineHeight: 'xl',
53+
},
54+
l: {
55+
fontSize: 'xxl',
56+
lineHeight: 'xxl',
57+
},
58+
};
59+
60+
/**
61+
* Mixin
62+
*/
63+
export const euiTitle = (
64+
scale: EuiTitleSize = 'm',
65+
euiTheme: UseEuiTheme['euiTheme'],
66+
measurement: _EuiThemeFontSizeMeasurement = 'rem'
67+
): {
68+
fontSize: CSSProperties['fontSize'];
69+
lineHeight: CSSProperties['lineHeight'];
70+
fontWeight: CSSProperties['fontWeight'];
71+
letterSpacing?: CSSProperties['letterSpacing'];
72+
} => {
73+
// NOTE: For future themes, we can conditionally key off `euiTheme.themeName`
74+
// and conditionally switch our title settings.
75+
const title = amsterdamThemeTitles[scale];
76+
77+
return {
78+
fontSize: euiFontSizeFromScale(title.fontSize, euiTheme, measurement),
79+
lineHeight: euiLineHeightFromBaseline(
80+
title.lineHeight,
81+
euiTheme,
82+
measurement
83+
),
84+
fontWeight: title.fontWeight || euiTheme.font.weight.bold,
85+
letterSpacing: title.letterSpacing,
86+
};
87+
};
88+
89+
/**
90+
* Styles
91+
*/
1392
export const euiTitleStyles = ({ euiTheme }: UseEuiTheme) => ({
1493
euiTitle: css`
1594
${euiTextBreakWord}
@@ -22,5 +101,23 @@ export const euiTitleStyles = ({ euiTheme }: UseEuiTheme) => ({
22101
uppercase: css`
23102
text-transform: uppercase;
24103
`,
25-
// TODO: Sizes
104+
// Sizes
105+
xxxs: css`
106+
${euiTitle('xxxs', euiTheme)}
107+
`,
108+
xxs: css`
109+
${euiTitle('xxs', euiTheme)}
110+
`,
111+
xs: css`
112+
${euiTitle('xs', euiTheme)}
113+
`,
114+
s: css`
115+
${euiTitle('s', euiTheme)}
116+
`,
117+
m: css`
118+
${euiTitle('m', euiTheme)}
119+
`,
120+
l: css`
121+
${euiTitle('l', euiTheme)}
122+
`,
26123
});

src/components/title/title.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export const EuiTitle: FunctionComponent<EuiTitleProps> = ({
5454
const cssStyles = [
5555
styles.euiTitle,
5656
textTransform ? styles[textTransform] : undefined,
57+
styles[size],
5758
];
5859
const classes = classNames(
5960
'euiTitle',

src/global_styling/variables/_title.ts

Lines changed: 0 additions & 81 deletions
This file was deleted.

src/themes/amsterdam/global_styling/variables/title.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)