api-client/packages/hoppscotch-ui/src/components/smart/Checkbox.vue

78 lines
1.5 KiB
Vue
Raw Normal View History

2021-11-15 14:55:40 +00:00
<template>
<div
2022-11-27 17:49:19 +00:00
class="inline-flex items-center justify-center transition cursor-pointer flex-nowrap group hover:text-secondaryDark"
2022-03-01 06:41:53 +00:00
role="checkbox"
:aria-checked="on"
@click="emit('change')"
2021-11-15 14:55:40 +00:00
>
<input
id="checkbox"
type="checkbox"
name="checkbox"
2022-12-03 07:31:47 +00:00
class="checkbox"
2021-11-15 14:55:40 +00:00
:checked="on"
@change="emit('change')"
2021-11-15 14:55:40 +00:00
/>
<label
for="checkbox"
2022-11-27 17:49:19 +00:00
class="pl-0 font-semibold truncate align-middle cursor-pointer"
:class="{
'before:mr-2': labelSlot.default
}"
2021-11-15 14:55:40 +00:00
>
<slot></slot>
</label>
</div>
</template>
<script setup lang="ts">
import { useSlots } from 'vue';
defineProps({
on: {
type: Boolean,
default: false,
2021-11-15 14:55:40 +00:00
},
})
const emit = defineEmits<{
(e: "change"): void
}>()
// used to check if the default slot is used and add a margin to the label if exists
const labelSlot = useSlots()
2021-11-15 14:55:40 +00:00
</script>
<style lang="scss" scoped>
2022-12-03 07:31:47 +00:00
.checkbox[type="checkbox"] {
2021-11-15 14:55:40 +00:00
@apply appearance-none;
@apply hidden;
& + label {
@apply inline-flex items-center justify-center;
@apply cursor-pointer;
&::before {
2022-12-03 07:31:47 +00:00
@apply border-2 border-divider;
2021-11-15 14:55:40 +00:00
@apply rounded;
@apply group-hover:border-accentDark;
2021-11-15 14:55:40 +00:00
@apply inline-flex;
@apply items-center;
@apply justify-center;
@apply text-transparent;
@apply h-4;
@apply w-4;
@apply font-icon;
@apply transition;
2023-08-24 18:25:22 +00:00
@apply content-["\e5ca"];
2021-11-15 14:55:40 +00:00
}
}
&:checked + label::before {
@apply bg-accent;
@apply border-accent;
@apply text-accentContrast;
}
}
</style>