pleroma-fe/src/components/checkbox/checkbox.vue

130 lines
2.4 KiB
Vue
Raw Normal View History

<template>
<label
class="checkbox"
2023-05-23 18:52:10 +03:00
:class="{ disabled, indeterminate, 'indeterminate-fix': indeterminateTransitionFix }"
2019-10-29 09:35:42 +02:00
>
2019-07-05 10:17:44 +03:00
<input
type="checkbox"
class="visible-for-screenreader-only"
:disabled="disabled"
2022-03-24 13:41:52 +02:00
:checked="modelValue"
2022-03-17 08:35:19 +02:00
:indeterminate="indeterminate"
@change="$emit('update:modelValue', $event.target.checked)"
2019-07-05 10:17:44 +03:00
>
2023-01-28 22:10:06 -05:00
<i
2024-02-07 15:53:49 +02:00
class="input checkbox-indicator"
2023-01-28 22:10:06 -05:00
:aria-hidden="true"
2023-05-23 18:52:10 +03:00
@transitionend.capture="onTransitionEnd"
2023-01-28 22:10:06 -05:00
/>
<span
v-if="!!$slots.default"
2019-11-08 11:14:01 -05:00
class="label"
2019-10-29 09:35:42 +02:00
>
<slot />
</span>
</label>
</template>
2019-04-03 21:13:25 -04:00
<script>
export default {
props: [
'modelValue',
'indeterminate',
'disabled'
2022-07-31 12:35:48 +03:00
],
2023-05-23 18:52:10 +03:00
emits: ['update:modelValue'],
data: (vm) => ({
indeterminateTransitionFix: vm.indeterminate
2023-05-23 18:52:10 +03:00
}),
watch: {
indeterminate (e) {
if (e) {
this.indeterminateTransitionFix = true
}
}
},
methods: {
onTransitionEnd (e) {
if (!this.indeterminate) {
this.indeterminateTransitionFix = false
}
2023-05-23 18:52:10 +03:00
}
}
}
</script>
<style lang="scss">
2023-01-09 13:02:16 -05:00
@import "../../variables";
2023-01-28 22:10:06 -05:00
@import "../../mixins";
2019-04-06 13:21:41 -04:00
2019-04-03 21:13:25 -04:00
.checkbox {
position: relative;
display: inline-block;
min-height: 1.2em;
2019-04-03 21:13:25 -04:00
2024-02-07 15:53:49 +02:00
& > &-indicator {
/* Reset .input stuff */
padding: 0;
margin: 0;
position: relative;
2024-02-07 15:53:49 +02:00
line-height: inherit;
display: inline;
padding-left: 1.2em;
2024-02-07 15:53:49 +02:00
box-shadow: none;
}
2019-04-03 21:13:25 -04:00
&-indicator::before {
position: absolute;
right: 0;
2019-04-03 21:13:25 -04:00
top: 0;
display: block;
2023-01-09 13:02:16 -05:00
content: "✓";
2019-04-03 21:13:25 -04:00
transition: color 200ms;
width: 1.1em;
height: 1.1em;
border-radius: $fallback--checkboxRadius;
border-radius: var(--checkboxRadius, $fallback--checkboxRadius);
2024-02-07 15:53:49 +02:00
box-shadow: var(--shadow);
background-color: var(--background);
2019-04-03 21:13:25 -04:00
vertical-align: top;
text-align: center;
line-height: 1.1em;
font-size: 1.1em;
color: transparent;
overflow: hidden;
box-sizing: border-box;
}
&.disabled {
.checkbox-indicator::before,
.label {
2023-01-09 13:02:16 -05:00
opacity: 0.5;
}
2023-01-09 13:02:16 -05:00
.label {
2024-02-07 15:53:49 +02:00
color: var(--text);
}
}
2023-01-09 13:02:16 -05:00
input[type="checkbox"] {
2019-04-03 21:13:25 -04:00
&:checked + .checkbox-indicator::before {
2024-02-07 15:53:49 +02:00
color: var(--text);
2019-04-03 21:13:25 -04:00
}
2019-04-06 13:45:28 -04:00
&:indeterminate + .checkbox-indicator::before {
2023-01-09 13:02:16 -05:00
content: "";
2024-02-07 15:53:49 +02:00
color: var(--text);
2019-04-06 13:45:28 -04:00
}
2019-04-03 21:13:25 -04:00
}
2023-05-23 18:52:10 +03:00
&.indeterminate-fix {
input[type="checkbox"] + .checkbox-indicator::before {
content: "";
}
}
2019-04-03 21:13:25 -04:00
& > span {
2023-01-09 13:02:16 -05:00
margin-left: 0.5em;
2019-04-03 21:13:25 -04:00
}
}
</style>