diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index b1e6b95..b642668 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -66,6 +66,8 @@ function getFormComponents() { return [ { text: 'Input', link: 'components/input' }, { text: 'Checkbox', link: 'components/checkbox' }, + { text: 'Select', link: 'components/select' }, + { text: 'Toggle', link: 'components/toggle' }, ] } diff --git a/docs/components/toggle.md b/docs/components/toggle.md new file mode 100644 index 0000000..6242cd7 --- /dev/null +++ b/docs/components/toggle.md @@ -0,0 +1,91 @@ + + +# Vue Toggle Component - Flowbite + +#### Use the toggle component to switch between a binary state of true or false using a single click available in multiple sizes, variants, and colors + +--- + +:::tip +Original reference: [https://flowbite.com/docs/forms/toggle/](https://flowbite.com/docs/forms/toggle/) +::: + +The toggle component can be used to receive a simple “yes” or “no” type of answer from the user by choosing a single option from two options available in multiple sizes, styles, and colors coded with the utility classes from Tailwind CSS and with dark mode support. + +## Default toggle +```vue + + +``` + + + +## Checked toggle +```vue + + +``` + + + +## Disabled toggle +```vue + + +``` + + + +## Colors +```vue + +``` + + + +## Size +```vue + +``` + + diff --git a/docs/components/toggle/examples/CheckedToggle.vue b/docs/components/toggle/examples/CheckedToggle.vue new file mode 100644 index 0000000..bc27344 --- /dev/null +++ b/docs/components/toggle/examples/CheckedToggle.vue @@ -0,0 +1,12 @@ + + + diff --git a/docs/components/toggle/examples/ColorsToggle.vue b/docs/components/toggle/examples/ColorsToggle.vue new file mode 100644 index 0000000..dee0e54 --- /dev/null +++ b/docs/components/toggle/examples/ColorsToggle.vue @@ -0,0 +1,22 @@ + + + diff --git a/docs/components/toggle/examples/DefaultToggle.vue b/docs/components/toggle/examples/DefaultToggle.vue new file mode 100644 index 0000000..2cd7773 --- /dev/null +++ b/docs/components/toggle/examples/DefaultToggle.vue @@ -0,0 +1,12 @@ + + + diff --git a/docs/components/toggle/examples/DisabledToggle.vue b/docs/components/toggle/examples/DisabledToggle.vue new file mode 100644 index 0000000..41e9e6f --- /dev/null +++ b/docs/components/toggle/examples/DisabledToggle.vue @@ -0,0 +1,12 @@ + + + diff --git a/docs/components/toggle/examples/SizeToggle.vue b/docs/components/toggle/examples/SizeToggle.vue new file mode 100644 index 0000000..4134404 --- /dev/null +++ b/docs/components/toggle/examples/SizeToggle.vue @@ -0,0 +1,12 @@ + + + diff --git a/src/components/Toggle/Toggle.vue b/src/components/Toggle/Toggle.vue new file mode 100644 index 0000000..280edc5 --- /dev/null +++ b/src/components/Toggle/Toggle.vue @@ -0,0 +1,41 @@ + + + diff --git a/src/components/Toggle/composables/useToggleClasses.ts b/src/components/Toggle/composables/useToggleClasses.ts new file mode 100644 index 0000000..49a3b74 --- /dev/null +++ b/src/components/Toggle/composables/useToggleClasses.ts @@ -0,0 +1,56 @@ +import type { Ref } from 'vue' +import { computed } from 'vue' +import type { InputSize } from '@/components/Input/types' + +// Toggle Background +const defaultLabelClasses = 'w-fit relative inline-flex items-center cursor-pointer' +const defaultToggleBackgroundClasses = 'w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[""] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600' +const defaultToggleBallClasses = 'ml-3 text-sm font-medium text-gray-900 dark:text-gray-300' +const toggleSizeClasses: Record = { + lg: 'w-14 h-7 after:top-0.5 after:left-[4px] after:h-6 after:w-6', + md: 'w-11 h-6 after:top-[2px] after:left-[2px] after:h-5 after:w-5', + sm: 'w-9 h-5 after:top-[2px] after:left-[2px] after:h-4 after:w-4', +} +const toggleColorClasses: Record = { + red: 'peer-focus:ring-red-300 dark:peer-focus:ring-red-800 peer-checked:bg-red-600', + green: 'peer-focus:ring-green-300 dark:peer-focus:ring-green-800 peer-checked:bg-green-600', + purple: 'peer-focus:ring-purple-300 dark:peer-focus:ring-purple-800 peer-checked:bg-purple-600', + yellow: 'peer-focus:ring-yellow-300 dark:peer-focus:ring-yellow-800 peer-checked:bg-yellow-400', + teal: 'peer-focus:ring-teal-300 dark:peer-focus:ring-teal-800 peer-checked:bg-teal-600', + orange: 'peer-focus:ring-orange-300 dark:peer-focus:ring-orange-800 peer-checked:bg-orange-500', +} + +export type UseToggleClassesProps = { + size: Ref + color: Ref +} + +export function useToggleClasses(props: UseToggleClassesProps) { + const labelClasses = computed(() => { + return defaultLabelClasses + }) + + const toggleClasses = computed(() => { + return defaultToggleBackgroundClasses + }) + + const toggleSize = computed(() => { + return toggleSizeClasses[props.size.value] + }) + + const toggleColor = computed(() => { + return toggleColorClasses[props.color.value] + }) + + const toggleBallClasses = computed(() => { + return defaultToggleBallClasses + }) + + return { + labelClasses, + toggleSize, + toggleClasses, + toggleColor, + toggleBallClasses, + } +} diff --git a/src/index.ts b/src/index.ts index a1b73bd..0ccb236 100644 --- a/src/index.ts +++ b/src/index.ts @@ -52,6 +52,10 @@ export { default as Input } from './components/Input/Input.vue' export { default as SlotListener } from './components/utils/SlotListener/SlotListener.vue' +export { default as Checkbox } from './components/Checkbox/Checkbox.vue' + export { default as Select } from './components/Select/Select.vue' +export { default as Toggle } from './components/Toggle/Toggle.vue' + export * from './composables'