Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | 49x 131x 23x 32x 32x 4x 4x 4x 4x 4x 4x 23x 4x 4x 46x 1x 45x 6x 39x 3x 36x 36x 23x 46x 46x 23x 49x 1x 48x 23x 49x 49x 23x | /*
Copyright (c) 2018-2019 Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
// @flow
import {styled} from '../styles/index.js';
import type {ThemeT} from '../styles/types.js';
import {SIZE} from './constants.js';
import type {SharedPropsT} from './types.js';
function getInputPadding(size, sizing) {
return {
[SIZE.compact]: {
paddingTop: sizing.scale200,
paddingBottom: sizing.scale200,
paddingLeft: sizing.scale400,
paddingRight: sizing.scale400,
},
[SIZE.default]: {
paddingTop: sizing.scale400,
paddingBottom: sizing.scale400,
paddingLeft: sizing.scale550,
paddingRight: sizing.scale550,
},
[SIZE.large]: {
paddingTop: sizing.scale550,
paddingBottom: sizing.scale550,
paddingLeft: sizing.scale650,
paddingRight: sizing.scale650,
},
}[size];
}
function getFont(size, typography) {
return {
[SIZE.compact]: typography.font300,
[SIZE.default]: typography.font400,
[SIZE.large]: typography.font460,
}[size];
}
export const Root = styled<SharedPropsT>('div', props => {
const {
$size,
$theme: {colors, typography},
} = props;
return {
...getFont($size, typography),
color: colors.foreground,
display: 'flex',
width: '100%',
};
});
// InputEnhancer
function getInputEnhancerPadding($size, sizing) {
return {
[SIZE.compact]: {
paddingRight: sizing.scale400,
paddingLeft: sizing.scale400,
},
[SIZE.default]: {
paddingRight: sizing.scale600,
paddingLeft: sizing.scale600,
},
[SIZE.large]: {
paddingRight: sizing.scale650,
paddingLeft: sizing.scale650,
},
}[$size];
}
function getInputEnhancerColors(
$disabled,
$isFocused,
$error,
$positive,
colors,
) {
Iif ($disabled) {
return {
color: colors.inputEnhancerTextDisabled,
backgroundColor: colors.inputEnhancerFillDisabled,
};
}
Iif ($isFocused) {
return {
color: colors.foregroundInv,
backgroundColor: colors.primary400,
};
}
Iif ($error) {
return {
color: colors.foreground,
backgroundColor: colors.inputBorderError,
};
}
Iif ($positive) {
return {
color: colors.foreground,
backgroundColor: colors.inputBorderPositive,
};
}
return {
color: colors.foreground,
backgroundColor: colors.inputEnhancerFill,
};
}
export const InputEnhancer = styled<SharedPropsT>('div', props => {
const {
$size,
$disabled,
$isFocused,
$error,
$positive,
$theme: {colors, sizing, typography, animation},
} = props;
return {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
transitionProperty: 'color, background-color',
transitionDuration: animation.timing100,
transitionTimingFunction: animation.easeOutCurve,
...getFont($size, typography),
...getInputEnhancerPadding($size, sizing),
...getInputEnhancerColors($disabled, $isFocused, $error, $positive, colors),
};
});
// InputContainer
function getInputContainerColors(
$disabled,
$isFocused,
$error,
$positive,
colors,
) {
if ($disabled) {
return {
color: colors.inputTextDisabled,
borderColor: colors.inputFillDisabled,
backgroundColor: colors.inputFillDisabled,
};
}
if ($isFocused) {
return {
color: colors.foreground,
borderColor: colors.primary400,
backgroundColor: colors.inputFillActive,
};
}
if ($error) {
return {
color: colors.foreground,
borderColor: colors.inputBorderError,
backgroundColor: colors.inputFillError,
};
}
Iif ($positive) {
return {
color: colors.foreground,
borderColor: colors.inputBorderPositive,
backgroundColor: colors.inputFillPositive,
};
}
return {
color: colors.foreground,
borderColor: colors.inputFill,
backgroundColor: colors.inputFill,
};
}
export const getInputContainerStyles = (
props: SharedPropsT & {$theme: ThemeT},
) => {
const {
$isFocused,
$error,
$disabled,
$positive,
$size,
$theme: {colors, typography, animation},
} = props;
return {
boxSizing: 'border-box',
display: 'flex',
width: '100%',
borderWidth: '2px',
borderStyle: 'solid',
transitionProperty: 'border, background-color',
transitionDuration: animation.timing100,
transitionTimingFunction: animation.easeOutCurve,
...getFont($size, typography),
...getInputContainerColors(
$disabled,
$isFocused,
$error,
$positive,
colors,
),
};
};
export const InputContainer = styled<SharedPropsT>(
'div',
getInputContainerStyles,
);
function getInputColors($disabled, $isFocused, $error, colors) {
if ($disabled) {
return {
color: colors.foregroundAlt,
caretColor: colors.foreground,
'::placeholder': {
color: colors.inputTextDisabled,
},
};
}
return {
color: colors.foreground,
caretColor: colors.foreground,
'::placeholder': {
color: colors.foregroundAlt,
},
};
}
export const getInputStyles = (props: SharedPropsT & {$theme: ThemeT}) => {
const {
$disabled,
$isFocused,
$error,
$size,
$theme: {colors, sizing, typography},
} = props;
return {
boxSizing: 'border-box',
backgroundColor: 'transparent',
borderWidth: 0,
borderStyle: 'none',
outline: 'none',
width: '100%',
maxWidth: '100%',
cursor: $disabled ? 'not-allowed' : 'text',
paddingTop: '0',
paddingBottom: '0',
paddingLeft: '0',
paddingRight: '0',
...getFont($size, typography),
...getInputPadding($size, sizing),
...getInputColors($disabled, $isFocused, $error, colors),
};
};
export const Input = styled<SharedPropsT>('input', getInputStyles);
|