-
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.
Merge pull request #48 from selemondev/feat/Switch
feat(app): #39 Switch
- Loading branch information
Showing
9 changed files
with
160 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
<script setup lang='ts'> | ||
import { ref } from 'vue' | ||
const selected = ref('') | ||
</script> | ||
|
||
<template> | ||
<div class="grid place-items-center w-full min-h-screen"> | ||
<WButton variant="default-light" disabled label="Button" /> | ||
<WSwitch v-model="selected" on-icon="ph:sun" off-icon="ph:moon" class="text-xl" /> | ||
</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
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 |
---|---|---|
|
@@ -13,4 +13,5 @@ export enum Components { | |
WCheckbox = 'WCheckbox', | ||
WKbd = 'WKbd', | ||
WDivider = 'WDivider', | ||
WSwitch = 'WSwitch', | ||
} |
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,93 @@ | ||
<script setup lang='ts'> | ||
import { computed, defineComponent } from 'vue' | ||
import classNames from 'classnames' | ||
import { Switch } from '@headlessui/vue' | ||
import { Icon } from '@iconify/vue' | ||
import { getVariantPropsWithClassesList } from '../../utils/getVariantProps' | ||
import type { VariantJSWithClassesListProps } from '../../utils/getVariantProps' | ||
import type { WSwitch } from '../../Types/componentsTypes/components' | ||
import { useVariants } from '../../composables/useVariants' | ||
import { Components } from '../../Types/enums/Components' | ||
const props = defineProps({ | ||
...getVariantPropsWithClassesList<WSwitch>(), | ||
name: { | ||
type: String, | ||
default: null, | ||
}, | ||
modelValue: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
disabled: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
onIcon: { | ||
type: String, | ||
default: null, | ||
}, | ||
offIcon: { | ||
type: String, | ||
default: null, | ||
}, | ||
}) | ||
const emit = defineEmits<{ | ||
(event: 'update:modelValue', value: boolean): void | ||
}>() | ||
const toggle = computed({ | ||
get() { | ||
return props.modelValue | ||
}, | ||
set(value) { | ||
return emit('update:modelValue', value) | ||
}, | ||
}) | ||
const variant = computed(() => { | ||
const customProps = { | ||
...props, | ||
variant: props.variant, | ||
} | ||
return useVariants<WSwitch>( | ||
Components.WSwitch, | ||
customProps as VariantJSWithClassesListProps<WSwitch>, | ||
) | ||
}) | ||
const switchClassWrapper = computed(() => { | ||
return classNames( | ||
variant.value.root, | ||
variant.value.switchRounded, | ||
toggle.value ? variant.value.switchActive : variant.value.switchInActive, | ||
) | ||
}) | ||
</script> | ||
|
||
<script lang='ts'> | ||
export default defineComponent({ | ||
name: Components.WSwitch, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<Switch | ||
v-model="toggle" | ||
:name="name" | ||
:disabled="disabled" | ||
:class="switchClassWrapper" | ||
> | ||
<span :class="[toggle ? variant.switchContainerActive : variant.switchContainerInActive, variant.switchContainer]"> | ||
<span v-if="props.onIcon" :class="[toggle ? variant.switchIconActive : variant.switchIconInActive, variant.switchIcon]" aria-hidden="true"> | ||
<Icon :icon="onIcon" :class="variant.switchIconOn" /> | ||
</span> | ||
<span v-if="props.offIcon" :class="[toggle ? variant.switchIconInActive : variant.switchIconActive, variant.switchIcon]" aria-hidden="true"> | ||
<Icon :icon="offIcon" :class="variant.switchIconOff" /> | ||
</span> | ||
</span> | ||
</Switch> | ||
</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 Switch from './WSwitch.vue' | ||
|
||
export default { | ||
Switch, | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.