| 1 |
<template> |
| 2 |
<ElCheckbox |
| 3 |
v-if="$slots.default" |
| 4 |
v-model="localModelValue" |
| 5 |
class="ivyforms-checkbox" |
| 6 |
:class="[ |
| 7 |
`size-${props.size}`, |
| 8 |
`priority-${props.priority}`, |
| 9 |
`type-${props.type}`, |
| 10 |
props.labelPosition === 'left' ? 'label-left' : 'label-right', |
| 11 |
{ 'with-description': props.description }, |
| 12 |
{ |
| 13 |
'is-checked': localModelValue, |
| 14 |
'is-indeterminate': props.indeterminate, |
| 15 |
'is-disabled': props.disabled, |
| 16 |
'with-marker': props.type === 'withMarker', |
| 17 |
}, |
| 18 |
]" |
| 19 |
:disabled="props.disabled" |
| 20 |
@change="(eventValue) => $emit('change', eventValue)" |
| 21 |
> |
| 22 |
<slot /> |
| 23 |
<span v-if="props.description" class="ivyforms-checkbox__description"> |
| 24 |
{{ props.description }} |
| 25 |
</span> |
| 26 |
</ElCheckbox> |
| 27 |
</template> |
| 28 |
|
| 29 |
<script setup lang="ts"> |
| 30 |
import { computed } from 'vue' |
| 31 |
|
| 32 |
interface Props { |
| 33 |
modelValue?: boolean |
| 34 |
indeterminate?: boolean |
| 35 |
labelPosition?: 'right' | 'left' |
| 36 |
description?: string |
| 37 |
priority?: 'primary' | 'secondary' | 'amber' |
| 38 |
size?: 's' | 'd' | 'l' | 'xl' |
| 39 |
type?: 'checkmark' | 'withMarker' |
| 40 |
disabled?: boolean |
| 41 |
} |
| 42 |
|
| 43 |
const props = withDefaults(defineProps<Props>(), { |
| 44 |
labelPosition: 'right', |
| 45 |
priority: 'primary', |
| 46 |
size: 'd', |
| 47 |
type: 'withMarker', |
| 48 |
disabled: false, |
| 49 |
indeterminate: false, |
| 50 |
description: '', |
| 51 |
}) |
| 52 |
|
| 53 |
const emit = defineEmits(['update:modelValue', 'change']) |
| 54 |
|
| 55 |
const localModelValue = computed({ |
| 56 |
get() { |
| 57 |
return props.modelValue |
| 58 |
}, |
| 59 |
set(value) { |
| 60 |
emit('update:modelValue', value) |
| 61 |
}, |
| 62 |
}) |
| 63 |
</script> |
| 64 |
|
| 65 |
<style lang="scss"> |
| 66 |
@use 'sass:list' as *; |
| 67 |
@use 'sass:meta' as *; |
| 68 |
$el: '.el-checkbox'; |
| 69 |
|
| 70 |
// Checkbox |
| 71 |
.ivyforms-checkbox { |
| 72 |
display: flex; |
| 73 |
flex-direction: row; |
| 74 |
gap: 12px; |
| 75 |
margin-right: 0; |
| 76 |
height: unset; |
| 77 |
min-height: 24px; |
| 78 |
white-space: normal; |
| 79 |
|
| 80 |
&.el-checkbox { |
| 81 |
white-space: normal; |
| 82 |
display: flex; |
| 83 |
align-items: center; |
| 84 |
gap: 12px; |
| 85 |
-webkit-tap-highlight-color: transparent; |
| 86 |
min-height: 24px; |
| 87 |
height: unset; |
| 88 |
color: var(--map-base-text-0); |
| 89 |
&.is-checked { |
| 90 |
color: var(--map-base-text-0); |
| 91 |
.el-checkbox__label { |
| 92 |
color: var(--map-base-text-0); |
| 93 |
} |
| 94 |
&.is-indeterminate { |
| 95 |
.el-checkbox__inner { |
| 96 |
background-color: var(--map-base-dusk-o05); |
| 97 |
border-color: var(--map-base-dusk-stroke--2); |
| 98 |
&::after { |
| 99 |
content: ''; |
| 100 |
width: 10px; |
| 101 |
height: 2px; |
| 102 |
background-color: white; |
| 103 |
position: absolute; |
| 104 |
top: 50%; |
| 105 |
left: 50%; |
| 106 |
transform: translate(-50%, -50%); |
| 107 |
border-radius: 2px; |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
.el-checkbox__input { |
| 114 |
margin-right: 0; |
| 115 |
padding: 0; |
| 116 |
|
| 117 |
.el-checkbox__inner { |
| 118 |
background-color: var(--map-base-dusk-o05); |
| 119 |
border-color: var(--map-base-dusk-stroke--2); |
| 120 |
} |
| 121 |
|
| 122 |
&:disabled { |
| 123 |
opacity: 0.5; |
| 124 |
} |
| 125 |
|
| 126 |
&.is-checked { |
| 127 |
color: var(--map-base-text-0); |
| 128 |
.el-checkbox__inner { |
| 129 |
background-color: var(--map-base-dusk-o05); |
| 130 |
border-color: var(--map-base-dusk-stroke--2); |
| 131 |
&::after { |
| 132 |
content: ''; |
| 133 |
display: inline-block; |
| 134 |
position: absolute; |
| 135 |
left: 50%; |
| 136 |
top: 50%; |
| 137 |
transform: translate(-50%, -50%); |
| 138 |
} |
| 139 |
} |
| 140 |
.el-checkbox__label { |
| 141 |
color: var(--map-base-text-0); |
| 142 |
} |
| 143 |
} |
| 144 |
&.is-checked { |
| 145 |
&:disabled { |
| 146 |
opacity: 0.5; |
| 147 |
} |
| 148 |
} |
| 149 |
} |
| 150 |
.el-checkbox__label { |
| 151 |
padding: 0; |
| 152 |
font-size: 16px; |
| 153 |
font-weight: 400; |
| 154 |
display: flex; |
| 155 |
line-height: 22px; |
| 156 |
flex-direction: column; |
| 157 |
color: var(--map-base-text--1); |
| 158 |
} |
| 159 |
|
| 160 |
&.label-left { |
| 161 |
.el-checkbox__input { |
| 162 |
order: 2; |
| 163 |
} |
| 164 |
.el-checkbox__label { |
| 165 |
order: 1; |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
&.with-description { |
| 170 |
align-items: flex-start; |
| 171 |
} |
| 172 |
|
| 173 |
&__description { |
| 174 |
font-size: 14px; |
| 175 |
font-weight: 400; |
| 176 |
line-height: 20px; |
| 177 |
} |
| 178 |
|
| 179 |
// Sizes |
| 180 |
$sizes: ( |
| 181 |
'xl': ( |
| 182 |
32px, |
| 183 |
24px, |
| 184 |
16px, |
| 185 |
), |
| 186 |
'l': ( |
| 187 |
24px, |
| 188 |
16px, |
| 189 |
12px, |
| 190 |
), |
| 191 |
'd': ( |
| 192 |
20px, |
| 193 |
16px, |
| 194 |
12px, |
| 195 |
), |
| 196 |
's': ( |
| 197 |
16px, |
| 198 |
12px, |
| 199 |
8px, |
| 200 |
), |
| 201 |
); |
| 202 |
|
| 203 |
@each $size, $values in $sizes { |
| 204 |
&.size-#{$size} { |
| 205 |
.el-checkbox__inner { |
| 206 |
height: nth($values, 1); |
| 207 |
width: nth($values, 1); |
| 208 |
&::after { |
| 209 |
height: nth($values, 2); |
| 210 |
width: nth($values, 2); |
| 211 |
} |
| 212 |
} |
| 213 |
&.type-withMarker { |
| 214 |
.el-checkbox__inner { |
| 215 |
&::after { |
| 216 |
height: nth($values, 3); |
| 217 |
width: nth($values, 3); |
| 218 |
} |
| 219 |
} |
| 220 |
} |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
// Priorities |
| 225 |
$priorities: ( |
| 226 |
'primary': ( |
| 227 |
var(--map-base-brand-fill-0), |
| 228 |
var(--map-base-brand-fill-1), |
| 229 |
var(--map-base-brand-o05), |
| 230 |
var(--map-base-brand-stroke-0), |
| 231 |
), |
| 232 |
'secondary': ( |
| 233 |
var(--map-base-purple-fill-0), |
| 234 |
var(--map-base-purple-fill-1), |
| 235 |
var(--map-base-purple-o05), |
| 236 |
var(--map-base-purple-stroke-0), |
| 237 |
), |
| 238 |
'amber': ( |
| 239 |
var(--map-accent-amber-fill-0), |
| 240 |
var(--map-accent-amber-fill-1), |
| 241 |
var(--map-accent-amber-o05), |
| 242 |
var(--map-accent-amber-stroke-0), |
| 243 |
), |
| 244 |
); |
| 245 |
|
| 246 |
@each $priority, $values in $priorities { |
| 247 |
&.priority-#{$priority} { |
| 248 |
&.is-checked { |
| 249 |
&.type-checkmark { |
| 250 |
.el-checkbox__inner { |
| 251 |
background-color: nth($values, 1); |
| 252 |
border-color: nth($values, 1); |
| 253 |
} |
| 254 |
&:hover { |
| 255 |
.el-checkbox__inner { |
| 256 |
background-color: nth($values, 2); |
| 257 |
border-color: nth($values, 2); |
| 258 |
} |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
.el-checkbox__inner { |
| 263 |
&::after { |
| 264 |
background-color: nth($values, 1); |
| 265 |
border-color: nth($values, 1); |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
&:hover { |
| 270 |
.el-checkbox__inner { |
| 271 |
&::after { |
| 272 |
background-color: nth($values, 2); |
| 273 |
border-color: nth($values, 2); |
| 274 |
} |
| 275 |
} |
| 276 |
} |
| 277 |
&.is-indeterminate { |
| 278 |
.el-checkbox__inner { |
| 279 |
background-color: nth($values, 1); |
| 280 |
border-color: nth($values, 1); |
| 281 |
} |
| 282 |
&:hover { |
| 283 |
.el-checkbox__inner { |
| 284 |
background-color: nth($values, 2); |
| 285 |
border-color: nth($values, 2); |
| 286 |
&::after { |
| 287 |
background-color: white; |
| 288 |
} |
| 289 |
} |
| 290 |
} |
| 291 |
} |
| 292 |
} |
| 293 |
|
| 294 |
&:not(.is-checked) { |
| 295 |
&:hover { |
| 296 |
.el-checkbox__inner { |
| 297 |
background-color: nth($values, 3); |
| 298 |
border-color: nth($values, 4); |
| 299 |
} |
| 300 |
} |
| 301 |
} |
| 302 |
} |
| 303 |
} |
| 304 |
|
| 305 |
&.type-checkmark { |
| 306 |
&.is-checked { |
| 307 |
.el-checkbox__inner { |
| 308 |
&::after { |
| 309 |
content: ''; |
| 310 |
display: inline-block; |
| 311 |
background-image: url('@/assets/images/radioButton/radio-button-checkmark.svg'); |
| 312 |
background-size: contain; |
| 313 |
background-repeat: no-repeat; |
| 314 |
position: absolute; |
| 315 |
left: 50%; |
| 316 |
top: 50%; |
| 317 |
transform: translate(-50%, -50%); |
| 318 |
} |
| 319 |
} |
| 320 |
} |
| 321 |
} |
| 322 |
} |
| 323 |
</style> |
| 324 |
|