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