-
Notifications
You must be signed in to change notification settings - Fork 842
/
_typography.ts
77 lines (71 loc) · 2.35 KB
/
_typography.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* 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 { CSSProperties } from 'react';
import {
euiLineHeightFromBaseline,
euiFontSizeFromScale,
_FontScaleOptions,
} from '../functions/typography';
import { useEuiTheme, UseEuiTheme } from '../../services/theme/hooks';
import { _EuiThemeFontScale } from '../variables/typography';
import { logicalCSS } from '../functions';
export type EuiThemeFontSize = {
fontSize: CSSProperties['fontSize'];
lineHeight: CSSProperties['lineHeight'];
};
/**
* Returns font-size and line-height
*/
export const euiFontSize = (
{ euiTheme }: UseEuiTheme,
scale: _EuiThemeFontScale,
options?: _FontScaleOptions
): EuiThemeFontSize => {
return {
fontSize: euiFontSizeFromScale(scale, euiTheme, options),
lineHeight: euiLineHeightFromBaseline(scale, euiTheme, options),
};
};
export const useEuiFontSize = (
scale: _EuiThemeFontScale,
options?: _FontScaleOptions
): EuiThemeFontSize => {
const euiTheme = useEuiTheme();
return euiFontSize(euiTheme, scale, options);
};
/**
* Force text to wrap on natural word breaks (e.g. spaces & hyphens)
* https://css-tricks.com/snippets/css/prevent-long-urls-from-breaking-out-of-container/
*/
export const euiTextBreakWord = () => `
overflow-wrap: break-word !important; // makes sure the long string will wrap and not bust out of the container
word-break: break-word;
`;
/**
* Prevent text from wrapping onto multiple lines, and truncate with an ellipsis.
*/
export const euiTextTruncate = (
maxWidth: CSSProperties['maxWidth'] = '100%'
) => `
${
logicalCSS('max-width', maxWidth) // Ensure that the node has a maximum width after which truncation can occur
}
overflow: hidden !important;
text-overflow: ellipsis !important;
white-space: nowrap !important;
`;
/**
* Fixed-width numbers for tabular data
*/
export const euiNumberFormat = ({ euiTheme }: UseEuiTheme) => `
font-feature-settings: ${euiTheme.font.featureSettings}, 'tnum' 1;
`;
export const useEuiNumberFormat = (): string => {
const euiTheme = useEuiTheme();
return euiNumberFormat(euiTheme);
};