|
1 | 1 | import { css } from '@emotion/core';
|
2 | 2 | import vars from '../../../../materials/custom-properties';
|
| 3 | +import designTokens from '../../../../materials/design-tokens'; |
| 4 | + |
3 | 5 | import { getInputStyles } from '../styles';
|
4 | 6 |
|
5 | 7 | // NOTE: order is important here
|
6 | 8 | // * a disabled-field currently does not display warning/error-states so it takes precedence
|
7 | 9 | // * a readonly-field cannot be changed, but it might be relevant for validation, so error and warning are checked first
|
8 | 10 | // how you can interact with the field is controlled separately by the props, this only influences visuals
|
9 |
| -const getClearSectionStyles = props => { |
| 11 | +const getClearSectionStyles = (props, theme) => { |
| 12 | + const overwrittenVars = { |
| 13 | + ...vars, |
| 14 | + ...theme, |
| 15 | + }; |
| 16 | + |
10 | 17 | const baseIconStyles = css`
|
11 | 18 | align-items: center;
|
12 | 19 | box-sizing: border-box;
|
13 |
| - background-color: ${vars.backgroundColorInputPristine}; |
14 |
| - border-bottom: 1px solid ${vars.borderColorInputPristine}; |
15 |
| - border-right: 1px solid ${vars.borderColorInputPristine}; |
16 |
| - border-top: 1px solid ${vars.borderColorInputPristine}; |
| 20 | + background-color: ${overwrittenVars[designTokens.backgroundColorForInput]}; |
| 21 | + border-bottom: 1px solid |
| 22 | + ${overwrittenVars[designTokens.borderColorForInput]}; |
| 23 | + border-right: 1px solid ${overwrittenVars[designTokens.borderColorForInput]}; |
| 24 | + border-top: 1px solid ${overwrittenVars[designTokens.borderColorForInput]}; |
17 | 25 | border-left: none;
|
18 |
| - height: ${vars.sizeHeightInput}; |
| 26 | + height: ${overwrittenVars.sizeHeightInput}; |
19 | 27 | display: flex;
|
20 |
| - padding: ${vars.spacingXs}; |
| 28 | + padding: ${overwrittenVars.spacingXs}; |
| 29 | + transition: ${overwrittenVars.transitionStandard}; |
21 | 30 | cursor: pointer;
|
22 | 31 | `;
|
23 | 32 | if (props.isDisabled) {
|
24 | 33 | return [
|
25 | 34 | baseIconStyles,
|
26 | 35 | css`
|
27 | 36 | cursor: not-allowed;
|
28 |
| - background-color: ${vars.backgroundColorInputDisabled}; |
29 |
| - color: ${vars.fontColorDisabled}; |
30 |
| - border-color: ${vars.borderColorInputDisabled}; |
| 37 | + background-color: ${overwrittenVars[ |
| 38 | + designTokens.backgroundColorForInputWhenDisabled |
| 39 | + ]}; |
| 40 | + color: ${overwrittenVars[designTokens.fontColorForInputWhenDisabled]}; |
| 41 | + border-color: ${overwrittenVars[ |
| 42 | + designTokens.borderColorForInputWhenDisabled |
| 43 | + ]}; |
| 44 | + `, |
| 45 | + ]; |
| 46 | + } |
| 47 | + if (props.isReadOnly) { |
| 48 | + return [ |
| 49 | + baseIconStyles, |
| 50 | + css` |
| 51 | + cursor: default; |
| 52 | + color: ${overwrittenVars[designTokens.fontColorForInputWhenReadonly]}; |
| 53 | + border-color: ${overwrittenVars[ |
| 54 | + designTokens.borderColorForInputWhenReadonly |
| 55 | + ]}; |
| 56 | +
|
| 57 | + svg path { |
| 58 | + fill: ${overwrittenVars[designTokens.fontColorForInputWhenReadonly]}; |
| 59 | + } |
31 | 60 | `,
|
32 | 61 | ];
|
33 | 62 | }
|
34 | 63 | if (props.hasError) {
|
35 | 64 | return [
|
36 | 65 | baseIconStyles,
|
37 | 66 | css`
|
38 |
| - color: ${vars.fontColorError}; |
39 |
| - border-color: ${vars.borderColorInputError}; |
| 67 | + color: ${overwrittenVars[designTokens.fontColorForInputWhenError]}; |
| 68 | + border-color: ${overwrittenVars[ |
| 69 | + designTokens.borderColorForInputWhenError |
| 70 | + ]}; |
40 | 71 | `,
|
41 | 72 | ];
|
42 | 73 | }
|
43 | 74 | return baseIconStyles;
|
44 | 75 | };
|
45 | 76 |
|
46 |
| -const getClockIconContainerStyles = props => { |
| 77 | +const getClockIconContainerStyles = (props, theme) => { |
| 78 | + const overwrittenVars = { |
| 79 | + ...vars, |
| 80 | + ...theme, |
| 81 | + }; |
| 82 | + |
47 | 83 | const baseIconStyles = css`
|
48 | 84 | align-items: center;
|
49 | 85 | box-sizing: border-box;
|
50 |
| - background-color: ${vars.backgroundColorInputPristine}; |
51 |
| - border-bottom: 1px solid ${vars.borderColorInputPristine}; |
52 |
| - border-right: 1px solid ${vars.borderColorInputPristine}; |
53 |
| - border-top: 1px solid ${vars.borderColorInputPristine}; |
| 86 | + background-color: ${overwrittenVars[designTokens.backgroundColorForInput]}; |
| 87 | + border-bottom: 1px solid |
| 88 | + ${overwrittenVars[designTokens.borderColorForInput]}; |
| 89 | + border-right: 1px solid ${overwrittenVars[designTokens.borderColorForInput]}; |
| 90 | + border-top: 1px solid ${overwrittenVars[designTokens.borderColorForInput]}; |
54 | 91 | border-left: none;
|
55 |
| - height: ${vars.sizeHeightInput}; |
| 92 | + height: ${overwrittenVars.sizeHeightInput}; |
56 | 93 | display: flex;
|
57 |
| - padding: ${vars.spacingXs}; |
58 |
| - border-top-right-radius: ${vars.borderRadiusInput}; |
59 |
| - border-bottom-right-radius: ${vars.borderRadiusInput}; |
| 94 | + padding: ${overwrittenVars.spacingXs}; |
| 95 | + border-top-right-radius: ${overwrittenVars[ |
| 96 | + designTokens.borderRadiusForInput |
| 97 | + ]}; |
| 98 | + border-bottom-right-radius: ${overwrittenVars[ |
| 99 | + designTokens.borderRadiusForInput |
| 100 | + ]}; |
60 | 101 | `;
|
61 | 102 | if (props.isDisabled) {
|
62 | 103 | return [
|
63 | 104 | baseIconStyles,
|
64 | 105 | css`
|
65 | 106 | cursor: not-allowed;
|
66 |
| - background-color: ${vars.backgroundColorInputDisabled}; |
67 |
| - color: ${vars.fontColorDisabled}; |
68 |
| - border-color: ${vars.borderColorInputDisabled}; |
| 107 | + background-color: ${overwrittenVars[ |
| 108 | + designTokens.backgroundColorForInputWhenDisabled |
| 109 | + ]}; |
| 110 | + color: ${overwrittenVars[designTokens.fontColorForInputWhenDisabled]}; |
| 111 | + border-color: ${overwrittenVars[ |
| 112 | + designTokens.borderColorForInputWhenDisabled |
| 113 | + ]}; |
| 114 | + `, |
| 115 | + ]; |
| 116 | + } |
| 117 | + if (props.isReadOnly) { |
| 118 | + return [ |
| 119 | + baseIconStyles, |
| 120 | + css` |
| 121 | + cursor: default; |
| 122 | + color: ${overwrittenVars[designTokens.fontColorForInputWhenReadonly]}; |
| 123 | + border-color: ${overwrittenVars[ |
| 124 | + designTokens.borderColorForInputWhenReadonly |
| 125 | + ]}; |
| 126 | +
|
| 127 | + svg path { |
| 128 | + fill: ${overwrittenVars[designTokens.fontColorForInputWhenReadonly]}; |
| 129 | + } |
69 | 130 | `,
|
70 | 131 | ];
|
71 | 132 | }
|
72 | 133 | if (props.hasError) {
|
73 | 134 | return [
|
74 | 135 | baseIconStyles,
|
75 | 136 | css`
|
76 |
| - color: ${vars.fontColorError}; |
77 |
| - border-color: ${vars.borderColorInputError}; |
| 137 | + color: ${overwrittenVars[designTokens.fontColorFolorInputWhenError]}; |
| 138 | + border-color: ${overwrittenVars[ |
| 139 | + designTokens.borderColorForInputWhenError |
| 140 | + ]}; |
78 | 141 | `,
|
79 | 142 | ];
|
80 | 143 | }
|
81 | 144 | return baseIconStyles;
|
82 | 145 | };
|
83 | 146 |
|
84 |
| -const getInputContainerStyles = () => css` |
85 |
| - width: 100%; |
86 |
| - align-items: center; |
87 |
| - display: flex; |
88 |
| - font-size: ${vars.fontSizeDefault}; |
89 |
| - font-family: ${vars.fontFamilyDefault}; |
90 |
| -`; |
| 147 | +const getInputContainerStyles = (props, theme) => { |
| 148 | + const overwrittenVars = { |
| 149 | + ...props, |
| 150 | + ...theme, |
| 151 | + }; |
| 152 | + |
| 153 | + return css` |
| 154 | + width: 100%; |
| 155 | + align-items: center; |
| 156 | + display: flex; |
| 157 | + font-size: ${overwrittenVars[designTokens.fontSizeForInput]}; |
| 158 | + font-family: ${overwrittenVars[designTokens.fontSizeForInput]}; |
| 159 | + `; |
| 160 | +}; |
| 161 | + |
| 162 | +const getTimeInputStyles = (props, theme) => { |
| 163 | + const overwrittenVars = { |
| 164 | + ...props, |
| 165 | + ...theme, |
| 166 | + }; |
91 | 167 |
|
92 |
| -const getTimeInputStyles = props => [ |
93 |
| - getInputStyles(props), |
94 |
| - css` |
95 |
| - border-radius: ${vars.borderRadiusInput} 0 0 ${vars.borderRadiusInput}; |
96 |
| - border-right: none; |
| 168 | + return [ |
| 169 | + getInputStyles(props, theme), |
| 170 | + css` |
| 171 | + border-radius: ${overwrittenVars[designTokens.borderRadiusInput]} 0 0 |
| 172 | + ${overwrittenVars[designTokens.borderRadiusInput]}; |
| 173 | + border-right: none; |
97 | 174 |
|
98 |
| - &:focus, |
99 |
| - &:active, |
100 |
| - &:focus + *, |
101 |
| - &:active + * { |
102 |
| - border-color: ${vars.borderColorInputFocus}; |
103 |
| - color: ${vars.fontColorDefault}; |
104 |
| - transition: ${vars.transitionStandard}; |
105 |
| - } |
| 175 | + &:focus, |
| 176 | + &:active, |
| 177 | + &:focus + *, |
| 178 | + &:active + * { |
| 179 | + border-color: ${overwrittenVars[ |
| 180 | + designTokens.borderColorForInputWhenFocused |
| 181 | + ]}; |
| 182 | + color: ${overwrittenVars[designTokens.fontColorForInput]}; |
| 183 | + transition: ${overwrittenVars.transitionStandard}; |
| 184 | + } |
106 | 185 |
|
107 |
| - &:disabled { |
108 |
| - cursor: not-allowed; |
109 |
| - } |
| 186 | + &:disabled { |
| 187 | + cursor: not-allowed; |
| 188 | + } |
110 | 189 |
|
111 |
| - &:disabled, |
112 |
| - &:read-only { |
113 |
| - background-color: ${vars.backgroundColorInputDisabled}; |
114 |
| - color: ${vars.fontColorDisabled}; |
115 |
| - border-color: ${vars.borderColorInputDisabled}; |
116 |
| - opacity: 1; /* fix for mobile safari */ |
117 |
| - } |
118 |
| - `, |
119 |
| -]; |
| 190 | + &:disabled { |
| 191 | + background-color: ${overwrittenVars[ |
| 192 | + designTokens.backgroundColorForInputWhenDisabled |
| 193 | + ]}; |
| 194 | + color: ${overwrittenVars[designTokens.fontColorForInputWhenDisabled]}; |
| 195 | + border-color: ${overwrittenVars[ |
| 196 | + designTokens.borderColorForInputWhenDisabled |
| 197 | + ]}; |
| 198 | + opacity: 1; /* fix for mobile safari */ |
| 199 | + } |
| 200 | + `, |
| 201 | + ]; |
| 202 | +}; |
120 | 203 |
|
121 | 204 | export {
|
122 | 205 | getClearSectionStyles,
|
|
0 commit comments