File: /var/www/europequiz/src/componenst/Checkbox.svelte
<script>
export let name = 'checkbox';
export let text = '';
export let checked = false;
export let onChange;
</script>
<div class="checkbox {checked ? 'active' : ''}">
<input {name} id={name} type="checkbox" class="checkbox__input" on:change={(e) => onChange(e.target?.checked)} />
<label for={name} class="checkbox__label">
<span class="checkbox__icon" />
<span class="checkbox__text">{@html text}</span>
</label>
</div>
<style lang="scss">
@import 'src/scss/variables';
@import 'src/scss/media';
.checkbox {
position: relative;
user-select: none;
margin-inline: auto;
margin-top: 10px;
&__input {
display: none;
visibility: hidden;
opacity: 0;
appearance: none;
position: absolute;
left: 0;
top: 0;
}
&__label {
display: flex;
align-items: center;
gap: 8px;
}
&__icon {
width: 18px;
height: 18px;
display: block;
border: 2px solid $yellow1;
border-radius: 3px;
}
&__text {
display: block;
font-size: 14px;
line-height: 30px;
@include breakpoint-up('tabS') {
font-size: 14px;
line-height: 30px;
}
:global(a) {
color: $yellow1;
}
}
&.active {
.checkbox__icon {
background-image: url('/src/assets/icons/checkbox.png');
background-size: calc(100% + 4px);
background-repeat: no-repeat;
background-position: -2px -2px;
}
}
}
</style>