-
Notifications
You must be signed in to change notification settings - Fork 842
/
Copy pathform.styles.ts
158 lines (138 loc) Β· 4.68 KB
/
form.styles.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* 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 {
UseEuiTheme,
shade,
tint,
darken,
transparentize,
makeHighContrastColor,
} from '../../services';
import { mathWithUnits, euiCanAnimate } from '../../global_styling';
export const euiFormVariables = (euiThemeContext: UseEuiTheme) => {
const { euiTheme, colorMode } = euiThemeContext;
const isColorDark = colorMode === 'DARK';
const backgroundColor = isColorDark
? shade(euiTheme.colors.lightestShade, 0.4)
: tint(euiTheme.colors.lightestShade, 0.6);
const controlHeight = euiTheme.size.xxl;
const controlCompressedHeight = euiTheme.size.xl;
const sizes = {
maxWidth: mathWithUnits(euiTheme.size.base, (x) => x * 25),
controlHeight: controlHeight,
controlCompressedHeight: controlCompressedHeight,
controlPadding: euiTheme.size.m,
controlCompressedPadding: euiTheme.size.s,
controlBorderRadius: euiTheme.border.radius.medium,
controlCompressedBorderRadius: euiTheme.border.radius.small,
};
const colors = {
backgroundColor: backgroundColor,
backgroundDisabledColor: darken(euiTheme.colors.lightestShade, 0.1),
backgroundReadOnlyColor: euiTheme.colors.emptyShade,
borderColor: transparentize(euiTheme.border.color, 0.9),
borderDisabledColor: transparentize(euiTheme.border.color, 0.9),
controlDisabledColor: euiTheme.colors.mediumShade,
controlBoxShadow: '0 0 transparent',
controlPlaceholderText: makeHighContrastColor(euiTheme.colors.subduedText)(
backgroundColor
),
inputGroupLabelBackground: isColorDark
? shade(euiTheme.colors.lightShade, 0.15)
: tint(euiTheme.colors.lightShade, 0.5),
inputGroupBorder: 'none',
};
// Colors - specific to checkboxes, radios, switches, and range thumbs
const customControlColors = {
customControlDisabledIconColor: isColorDark
? shade(euiTheme.colors.mediumShade, 0.38)
: tint(euiTheme.colors.mediumShade, 0.485),
customControlBorderColor: isColorDark
? shade(euiTheme.colors.lightestShade, 0.4)
: tint(euiTheme.colors.lightestShade, 0.31),
};
const controlLayout = {
controlLayoutGroupInputHeight: mathWithUnits(controlHeight, (x) => x - 2),
controlLayoutGroupInputCompressedHeight: mathWithUnits(
controlCompressedHeight,
(x) => x - 2
),
controlLayoutGroupInputCompressedBorderRadius: euiTheme.border.radius.small,
};
const iconSizes = {
controlIconSize: {
s: euiTheme.size.m,
m: euiTheme.size.base,
l: euiTheme.size.l,
xl: euiTheme.size.xl,
xxl: euiTheme.size.xxl,
},
};
return {
...sizes,
...colors,
...customControlColors,
...iconSizes,
...controlLayout,
};
};
export const euiFormControlSize = (
euiThemeContext: UseEuiTheme,
options: {
height?: string;
fullWidth?: boolean;
compressed?: boolean;
inGroup?: boolean;
} = {}
) => {
const form = euiFormVariables(euiThemeContext);
const width = '100%';
let maxWidth = form.maxWidth;
if (options.fullWidth) maxWidth = '100%';
let height = options.height || form.controlHeight;
if (options.compressed) height = form.controlCompressedHeight;
if (options.inGroup) height = '100%';
return `
max-inline-size: ${maxWidth};
inline-size: ${width};
block-size: ${height};
`;
};
export const euiCustomControl = (
euiThemeContext: UseEuiTheme,
options: {
type?: 'round' | 'square';
size?: string;
} = {}
) => {
const euiTheme = euiThemeContext.euiTheme;
const form = euiFormVariables(euiThemeContext);
const { type, size = euiTheme.size.base } = options;
let padddingStyle = '';
let borderRadiusStyle = '';
if (size) {
const borderSize = parseFloat(String(euiTheme.border.width.thin));
const paddingSize = mathWithUnits(size, (x) => (x - borderSize * 2) / 2);
padddingStyle = `padding: ${paddingSize};`;
}
if (type === 'round') {
borderRadiusStyle = `border-radius: ${size};`;
} else if (type === 'square') {
borderRadiusStyle = `border-radius: ${form.controlCompressedBorderRadius};`;
}
return `
${padddingStyle}
${borderRadiusStyle}
border: ${euiTheme.border.width.thin} solid ${form.customControlBorderColor};
background: ${euiTheme.colors.emptyShade} no-repeat center;
${euiCanAnimate} {
transition: background-color ${euiTheme.animation.fast} ease-in,
border-color ${euiTheme.animation.fast} ease-in;
}
`;
};