Skip to content

Commit 007102f

Browse files
committed
Add hook version + unit tests for euiTitle() mixin
1 parent 62fd363 commit 007102f

File tree

3 files changed

+97
-7
lines changed

3 files changed

+97
-7
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`euiTitle mixin returns a static object of title font properties for each title size l 1`] = `
4+
Object {
5+
"fontSize": "2.4286rem",
6+
"fontWeight": 700,
7+
"letterSpacing": undefined,
8+
"lineHeight": "2.8571rem",
9+
}
10+
`;
11+
12+
exports[`euiTitle mixin returns a static object of title font properties for each title size m 1`] = `
13+
Object {
14+
"fontSize": "1.9286rem",
15+
"fontWeight": 700,
16+
"letterSpacing": undefined,
17+
"lineHeight": "2.2857rem",
18+
}
19+
`;
20+
21+
exports[`euiTitle mixin returns a static object of title font properties for each title size s 1`] = `
22+
Object {
23+
"fontSize": "1.5714rem",
24+
"fontWeight": 700,
25+
"letterSpacing": undefined,
26+
"lineHeight": "2.2857rem",
27+
}
28+
`;
29+
30+
exports[`euiTitle mixin returns a static object of title font properties for each title size xs 1`] = `
31+
Object {
32+
"fontSize": "1.1429rem",
33+
"fontWeight": 700,
34+
"letterSpacing": undefined,
35+
"lineHeight": "1.7143rem",
36+
}
37+
`;
38+
39+
exports[`euiTitle mixin returns a static object of title font properties for each title size xxs 1`] = `
40+
Object {
41+
"fontSize": "1.0000rem",
42+
"fontWeight": 700,
43+
"letterSpacing": undefined,
44+
"lineHeight": "1.7143rem",
45+
}
46+
`;
47+
48+
exports[`euiTitle mixin returns a static object of title font properties for each title size xxxs 1`] = `
49+
Object {
50+
"fontSize": "0.8571rem",
51+
"fontWeight": 700,
52+
"letterSpacing": undefined,
53+
"lineHeight": "1.1429rem",
54+
}
55+
`;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import { testCustomHook } from '../../test/internal';
10+
11+
import { TITLE_SIZES } from './title';
12+
import { useEuiTitle } from './title.styles';
13+
14+
describe('euiTitle mixin', () => {
15+
describe('returns a static object of title font properties for each title size', () => {
16+
TITLE_SIZES.forEach((size) => {
17+
it(size, () => {
18+
expect(
19+
testCustomHook(() => useEuiTitle(size)).return
20+
).toMatchSnapshot();
21+
});
22+
});
23+
});
24+
});

src/components/title/title.styles.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import { CSSProperties } from 'react';
1010
import { css } from '@emotion/react';
11-
import { UseEuiTheme } from '../../services';
11+
import { UseEuiTheme, useEuiTheme } from '../../services';
1212
import {
1313
euiTextBreakWord,
1414
euiFontSizeFromScale,
@@ -60,16 +60,18 @@ const amsterdamThemeTitles: {
6060
/**
6161
* Mixin
6262
*/
63-
export const euiTitle = (
64-
scale: EuiTitleSize = 'm',
65-
euiTheme: UseEuiTheme['euiTheme'],
66-
measurement: _EuiThemeFontSizeMeasurement = 'rem'
67-
): {
63+
type EuiThemeTitle = {
6864
fontSize: CSSProperties['fontSize'];
6965
lineHeight: CSSProperties['lineHeight'];
7066
fontWeight: CSSProperties['fontWeight'];
7167
letterSpacing?: CSSProperties['letterSpacing'];
72-
} => {
68+
};
69+
70+
export const euiTitle = (
71+
scale: EuiTitleSize = 'm',
72+
euiTheme: UseEuiTheme['euiTheme'],
73+
measurement: _EuiThemeFontSizeMeasurement = 'rem'
74+
): EuiThemeTitle => {
7375
// NOTE: For future themes, we can conditionally key off `euiTheme.themeName`
7476
// and conditionally switch our title settings.
7577
const title = amsterdamThemeTitles[scale];
@@ -86,6 +88,15 @@ export const euiTitle = (
8688
};
8789
};
8890

91+
// Hook version
92+
export const useEuiTitle = (
93+
scale: EuiTitleSize = 'm',
94+
measurement: _EuiThemeFontSizeMeasurement = 'rem'
95+
): EuiThemeTitle => {
96+
const { euiTheme } = useEuiTheme();
97+
return euiTitle(scale, euiTheme, measurement);
98+
};
99+
89100
/**
90101
* Styles
91102
*/

0 commit comments

Comments
 (0)