Checkbox input color (#413)

* stule: checkbox input color

* fix toggle switch input color

* clean up console.log
This commit is contained in:
Favour Olayinka 2024-05-20 12:57:36 +01:00 committed by GitHub
parent 795fcfc973
commit 443f4ef7b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 10 deletions

View File

@ -9,6 +9,7 @@
v-model="compVal" v-model="compVal"
:disabled="disabled ? true : null" :disabled="disabled ? true : null"
:name="name" :name="name"
:color="color"
> >
<slot name="label"> <slot name="label">
{{ label }} {{ label }}

View File

@ -10,6 +10,7 @@
v-model="compVal" v-model="compVal"
class="inline-block mr-2" class="inline-block mr-2"
:disabled="disabled ? true : null" :disabled="disabled ? true : null"
:color="color"
/> />
<slot name="label"> <slot name="label">
<span>{{ label }} <span>{{ label }}

View File

@ -6,7 +6,8 @@
:name="name" :name="name"
type="checkbox" type="checkbox"
:class="sizeClasses" :class="sizeClasses"
class="rounded border-gray-500 cursor-pointer" class="rounded border-gray-500 cursor-pointer checkbox"
:style="{ '--accent-color': color }"
:disabled="disabled ? true : null" :disabled="disabled ? true : null"
> >
<label <label
@ -20,14 +21,7 @@
</template> </template>
<script setup> <script setup>
import { import { defineEmits, defineOptions, defineProps, onMounted, ref, watch, } from "vue"
defineEmits,
defineOptions,
defineProps,
onMounted,
ref,
watch,
} from "vue"
defineOptions({ defineOptions({
name: "VCheckbox", name: "VCheckbox",
@ -39,6 +33,7 @@ const props = defineProps({
modelValue: { type: [Boolean, String], default: false }, modelValue: { type: [Boolean, String], default: false },
disabled: { type: Boolean, default: false }, disabled: { type: Boolean, default: false },
sizeClasses: { type: String, default: "w-4 h-4" }, sizeClasses: { type: String, default: "w-4 h-4" },
color: { type: String, default: null },
}) })
const emit = defineEmits(["update:modelValue", "click"]) const emit = defineEmits(["update:modelValue", "click"])
@ -73,3 +68,8 @@ onMounted(() => {
if (internalValue.value === null) internalValue.value = false if (internalValue.value === null) internalValue.value = false
}) })
</script> </script>
<style>
.checkbox {
accent-color: var(--accent-color);
}
</style>

View File

@ -5,7 +5,9 @@
> >
<div <div
class="inline-flex items-center h-6 w-12 p-1 bg-gray-300 border rounded-full cursor-pointer focus:outline-none transition-all transform ease-in-out duration-100" class="inline-flex items-center h-6 w-12 p-1 bg-gray-300 border rounded-full cursor-pointer focus:outline-none transition-all transform ease-in-out duration-100"
:class="{ 'bg-nt-blue': props.modelValue }" :class="{ 'toggle-switch': props.modelValue }"
:style="{ '--accent-color': props.color }"
> >
<div <div
class="inline-block h-4 w-4 rounded-full bg-white shadow transition-all transform ease-in-out duration-150 rounded-2xl scale-100" class="inline-block h-4 w-4 rounded-full bg-white shadow transition-all transform ease-in-out duration-150 rounded-2xl scale-100"
@ -21,6 +23,7 @@ import { defineEmits, defineProps } from "vue"
const props = defineProps({ const props = defineProps({
modelValue: { type: Boolean, default: false }, modelValue: { type: Boolean, default: false },
disabled: { type: Boolean, default: false }, disabled: { type: Boolean, default: false },
color: { type: String, default: null },
}) })
const emit = defineEmits(["update:modelValue"]) const emit = defineEmits(["update:modelValue"])
@ -29,3 +32,8 @@ function onClick() {
emit("update:modelValue", !props.modelValue) emit("update:modelValue", !props.modelValue)
} }
</script> </script>
<style>
.toggle-switch {
background-color: var(--accent-color);
}
</style>