All files / styles Input.js

82.61% Statements 19/23
30.56% Branches 11/36
73.33% Functions 11/15
100% Lines 18/18

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      5x       5x                               5x       5x                   5x   22x     22x             22x               22x           22x             22x                 22x               22x             22x               22x     10x                                                                                               5x             5x                                                                                        
import { css } from 'emotion';
import styled from '@appbaseio/vue-emotion';
 
const alertBorder = ({ theme }) => css`
	border: 1px solid ${theme.colors.alertColor};
`;
 
const input = css`
	width: 100%;
	line-height: 1.5;
	min-height: 42px;
	padding: 8px 12px;
	border: 1px solid #ccc;
	background-color: #fafafa;
	font-size: 0.9rem;
	outline: none;
	height: 100%;
 
	&:focus {
		background-color: #fff;
	}
`;
 
const dark = theme => css`
	border-color: ${theme.colors.borderColor};
`;
 
const darkInput = ({ theme }) => css`
	background-color: ${theme.colors.backgroundColor};
	color: ${theme.colors.textColor};
	${dark(theme)};
 
	&:focus {
		background-color: ${theme.colors.backgroundColor};
	}
`;
 
const Input = styled('input')`
	${input};
	${({ themePreset, theme }) => themePreset === 'dark' && darkInput({ theme })};
 
	${props =>
		props.showIcon
		&& props.iconPosition === 'left'
		&& css`
			padding-left: 36px;
		`};
 
	${props =>
		props.showIcon
		&& props.iconPosition === 'right'
		&& css`
			padding-right: 36px;
		`};
 
	${props =>
		// for clear icon
		props.showClear
		&& css`
			padding-right: 36px;
		`};
	${props =>
		// for voice search icon
		props.showVoiceSearch
		&& css`
			padding-right: 36px;
		`};
 
	${props =>
		// for clear icon with search icon
		props.showClear
		&& props.showIcon
		&& props.iconPosition === 'right'
		&& css`
			padding-right: 66px;
		`};
 
	${props =>
		// for voice search icon with search icon
		props.showVoiceSearch
		&& props.showIcon
		&& props.iconPosition === 'right'
		&& css`
			padding-right: 66px;
		`};
	${props =>
		// for voice search icon with clear icon
		props.showVoiceSearch
		&& props.showIcon
		&& css`
			padding-right: 66px;
		`};
	${props =>
		// for clear icon with search icon and voice search
		props.showClear
		&& props.showIcon
		&& props.showVoiceSearch
		&& props.iconPosition === 'right'
		&& css`
			padding-right: 90px;
		`};
 
	${props => props.alert && alertBorder};
`;
 
const suggestions = (themePreset, theme) => css`
	display: block;
	width: 100%;
	border: 1px solid #ccc;
	border-top: none;
	background-color: #fff;
	font-size: 0.9rem;
	z-index: 3;
	position: absolute;
	margin: 0;
	padding: 0;
	list-style: none;
	max-height: 395px;
	overflow-y: auto;
 
	&.small {
		top: 30px;
	}
 
	li {
		display: flex;
		justify-content: space-between;
		cursor: pointer;
		padding: 10px;
		user-select: none;
 
		& > .trim {
			display: -webkit-box;
			display: block;
			width: 100%;
			max-height: 2.3rem;
			line-height: 1.2rem;
			-webkit-line-clamp: 2;
			-webkit-box-orient: vertical;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}
 
		&:hover,
		&:focus {
			background-color: #eee;
		}
	}
 
	${themePreset === 'dark' && theme && dark(theme)};
`;
 
const suggestionsContainer = css`
	position: relative;
	.cancel-icon {
		cursor: pointer;
	}
`;
 
const noSuggestions = (themePreset, theme) => css`
	display: block;
	width: 100%;
	border: 1px solid #ccc;
	border-top: none;
	background-color: #fff;
	font-size: 0.9rem;
	z-index: 3;
	position: absolute;
	margin: 0;
	padding: 0;
	list-style: none;
	max-height: 260px;
	overflow-y: auto;
 
	&.small {
		top: 30px;
	}
 
	li {
		display: flex;
		justify-content: space-between;
		padding: 10px;
		user-select: none;
 
		& > .trim {
			display: -webkit-box;
			display: block;
			width: 100%;
			max-height: 2.3rem;
			line-height: 1.2rem;
			-webkit-line-clamp: 2;
			-webkit-box-orient: vertical;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}
	}
 
	${themePreset === 'dark' && theme && dark(theme)}
`;
 
export default Input;
export { suggestionsContainer, suggestions, input, noSuggestions };