All files / styles FormControlList.js

100% Statements 14/14
83.33% Branches 5/6
100% Functions 7/7
100% Lines 13/13

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        2x           2x                       2x                                         20x                                                                                                                                       2x   10x                         10x                           10x                 2x   10x                               10x                       10x                       2x                                      
import { css } from 'emotion';
import styled from '@appbaseio/vue-emotion';
import { lighten } from 'polished';
 
const item = {
	width: '15px',
	height: '15px',
	scale: '4px',
};
 
const vh = css`
	border: 0;
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	height: 1px;
	overflow: hidden;
	padding: 0;
	position: absolute;
	width: 1px;
	white-space: nowrap;
`;
 
const hideInputControl = css`
	+ label {
		padding-left: 0;
 
		&::before,
		&::after {
			width: 0;
			height: 0;
			border: 0;
			margin: 0;
			visibility: hidden;
		}
	}
 
	&:checked {
		+ label {
			font-weight: bold;
		}
	}
`;
 
const formItem = ({ theme }) => css`
	${vh};
 
	&:focus {
		+ label {
			&::before {
				box-shadow: 0 0 0 2px ${lighten(0.4, theme.colors.primaryColor)};
			}
		}
	}
 
	&:hover {
		+ label {
			&::before {
				border-color: ${theme.colors.primaryColor};
			}
		}
	}
 
	&:active {
		+ label {
			&::before {
				transition-duration: 0;
			}
		}
	}
 
	+ label {
		position: relative;
		user-select: none;
		display: flex;
		width: 100%;
		height: 100%;
		align-items: center;
		cursor: pointer;
 
		&::before {
			background-color: #fff;
			border: 1px solid ${theme.colors.borderColor || lighten(0.1, theme.colors.textColor)};
			box-sizing: content-box;
			content: '';
			color: ${theme.colors.primaryColor};
			margin-right: calc(${item.width} * 0.5);
			top: 50%;
			left: 0;
			width: ${item.width};
			height: ${item.height};
			display: inline-block;
			vertical-align: middle;
		}
 
		&::after {
			box-sizing: content-box;
			content: '';
			background-color: ${theme.colors.primaryColor};
			position: absolute;
			top: 50%;
			left: calc(1px + ${item.scale} / 2);
			width: calc(${item.width} - ${item.scale});
			height: calc(${item.height} - ${item.scale});
			margin-top: calc(${item.height} / -2 - ${item.scale} / -2);
			transform: scale(0);
			transform-origin: 50%;
			transition: transform 200ms ease-out;
		}
	}
`;
 
const Radio = styled('input')`
	${formItem};
	${props => (props.show ? null : hideInputControl)};
 
	+ label {
		&::before,
		&::after {
			border-radius: 50%;
		}
	}
 
	&:checked {
		&:active,
		&:focus {
			+ label {
				color: ${({ theme }) => theme.colors.primaryColor};
 
				&::before {
					animation: none;
					filter: none;
					transition: none;
				}
			}
		}
 
		+ label {
			&::before {
				animation: none;
				background-color: #fff;
				border-color: ${({ theme }) => theme.colors.primaryColor};
		}
 
		&::after {
			transform: scale(1);
		}
	}
`;
 
const Checkbox = styled('input')`
	${formItem};
	${props => (props.show ? null : hideInputControl)};
 
	+ label {
		&::before,
		&::after {
			border-radius: 0;
		}
 
		&::after {
			background-color: transparent;
			top: 50%;
			left: calc(1px + ${item.width} / 5);
			width: calc(${item.width} / 2);
			height: calc(${item.width} / 5);
			margin-top: calc(${item.height} / -2 / 2 * 0.8);
			border-style: solid;
			border-color: ${({ theme }) => theme.colors.primaryColor};
			border-width: 0 0 2px 2px;
			border-radius: 0;
			border-image: none;
			transform: rotate(-45deg) scale(0);
			transition: none;
		}
	}
 
	&:checked {
		+ label {
			&::before {
				border-color: ${({ theme }) => theme.colors.primaryColor};
			}
 
			&::after {
				content: '';
				transform: rotate(-45deg) scale(1);
				transition: transform 200ms ease-out;
			}
		}
	}
`;
 
const UL = styled('ul')`
	list-style: none;
	padding: 0;
	margin: 0;
	max-height: 240px;
	position: relative;
	overflow-y: auto;
	padding-bottom: 12px;
 
	li {
		height 30px;
		display: flex;
		flex-direction: row;
		align-items: center;
		padding-left: 2px;
	}
`;
 
export { UL, Radio, Checkbox };