-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Selemondev
authored and
Selemondev
committed
Jul 31, 2023
1 parent
670995c
commit 28778dd
Showing
7 changed files
with
195 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<script setup lang='ts'> | ||
import { computed, defineComponent } from 'vue' | ||
import classNames from 'classnames' | ||
import { getVariantPropsWithClassesList } from '../../utils/getVariantProps' | ||
import type { VariantJSWithClassesListProps } from '../../utils/getVariantProps' | ||
import type { WCheckbox } from '../../Types/componentsTypes/components' | ||
import { Components } from '../../Types/enums/Components' | ||
import { useVariants } from '../../composables/useVariants' | ||
const props = defineProps({ | ||
...getVariantPropsWithClassesList<WCheckbox>(), | ||
value: { | ||
type: [String, Number, Boolean, Object], | ||
default: null, | ||
}, | ||
modelValue: { | ||
type: [Boolean, Array], | ||
default: null, | ||
}, | ||
name: { | ||
type: String, | ||
default: null, | ||
}, | ||
disabled: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
checked: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
indeterminate: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
help: { | ||
type: String, | ||
default: null, | ||
}, | ||
label: { | ||
type: String, | ||
default: null, | ||
}, | ||
required: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
}) | ||
const emit = defineEmits<{ | ||
(event: 'update:modelValue', e): void | ||
}>() | ||
const variant = computed(() => { | ||
const customProps = { | ||
...props, | ||
variant: props.variant, | ||
} | ||
return useVariants<WCheckbox>( | ||
Components.WCheckbox, | ||
customProps as VariantJSWithClassesListProps<WCheckbox>, | ||
) | ||
}) | ||
const toggle = computed({ | ||
get() { | ||
return props.modelValue | ||
}, | ||
set(value) { | ||
emit('update:modelValue', value) | ||
}, | ||
}) | ||
const checkboxWrapperClass = computed(() => { | ||
return classNames( | ||
variant.value.checkboxWrapper, | ||
variant.value.checkIcon, | ||
variant.value.checkIconActive, | ||
) | ||
}) | ||
</script> | ||
|
||
<script lang="ts"> | ||
export default defineComponent({ | ||
name: Components.WCheckbox, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div :class="variant.root"> | ||
<div class="flex items-center h-5"> | ||
<input | ||
:id="props.name" v-model="toggle" :name="props.name" :required="props.required" :value="props.value" :disabled="props.disabled" | ||
:checked="props.checked" type="checkbox" class="form-checkbox" :class="checkboxWrapperClass" | ||
v-bind="$attrs" | ||
> | ||
</div> | ||
<div v-if="label || $slots.label" class="ms-2 text-sm"> | ||
<label :for="name" :class="variant.checkboxLabel"> | ||
<slot name="label">{{ label }}</slot> | ||
<span v-if="required" :class="variant.checkboxRequired">*</span> | ||
</label> | ||
<p v-if="help" :class="variant.checkboxHelp"> | ||
{{ help }} | ||
</p> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Checkbox from './WCheckbox.vue' | ||
|
||
export default { | ||
Checkbox, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters