mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-26 01:40:34 +01:00
chore(Toggle): handle preset system
This commit is contained in:
@@ -109,6 +109,7 @@ const components = [
|
|||||||
label: 'Toggle',
|
label: 'Toggle',
|
||||||
to: '/components/Toggle',
|
to: '/components/Toggle',
|
||||||
nuxt3: true,
|
nuxt3: true,
|
||||||
|
preset: true,
|
||||||
capi: true
|
capi: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -219,6 +219,24 @@ const container = {
|
|||||||
constrained: 'max-w-7xl'
|
constrained: 'max-w-7xl'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const toggle = {
|
||||||
|
base: 'relative inline-flex flex-shrink-0 h-6 w-11 border-2 border-transparent rounded-full cursor-pointer focus:outline-none focus:ring-2 focus:ring-primary-500',
|
||||||
|
active: 'bg-primary-600',
|
||||||
|
inactive: 'u-bg-gray-200',
|
||||||
|
container: {
|
||||||
|
base: 'pointer-events-none relative inline-block h-5 w-5 rounded-full bg-white shadow transform ring-0 transition ease-in-out duration-200',
|
||||||
|
active: 'translate-x-5',
|
||||||
|
inactive: 'translate-x-0'
|
||||||
|
},
|
||||||
|
icon: {
|
||||||
|
base: 'absolute inset-0 h-full w-full flex items-center justify-center transition-opacity',
|
||||||
|
active: 'opacity-100 ease-in duration-200',
|
||||||
|
inactive: 'opacity-0 ease-out duration-100',
|
||||||
|
on: 'h-3 w-3 text-primary-600',
|
||||||
|
off: 'h-3 w-3 u-text-gray-400'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const verticalNavigation = {
|
const verticalNavigation = {
|
||||||
base: 'flex items-center px-3 py-2 text-sm font-medium rounded-md',
|
base: 'flex items-center px-3 py-2 text-sm font-medium rounded-md',
|
||||||
active: 'u-text-gray-900 u-bg-gray-100',
|
active: 'u-text-gray-900 u-bg-gray-100',
|
||||||
@@ -245,5 +263,6 @@ export default {
|
|||||||
radio,
|
radio,
|
||||||
card,
|
card,
|
||||||
container,
|
container,
|
||||||
|
toggle,
|
||||||
verticalNavigation
|
verticalNavigation
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<Switch
|
<Switch
|
||||||
v-model="enabled"
|
v-model="active"
|
||||||
:class="[enabled ? 'bg-primary-600' : 'u-bg-gray-200', 'relative inline-flex flex-shrink-0 h-6 w-11 border-2 border-transparent rounded-full cursor-pointer focus:outline-none focus:ring-2 focus:ring-primary-500']"
|
:class="[active ? activeClass : inactiveClass, baseClass]"
|
||||||
>
|
>
|
||||||
<span :class="[enabled ? 'translate-x-5' : 'translate-x-0', 'pointer-events-none relative inline-block h-5 w-5 rounded-full bg-white shadow transform ring-0 transition ease-in-out duration-200']">
|
<span :class="[active ? containerActiveClass : containerInactiveClass, containerBaseClass]">
|
||||||
<span :class="[enabled ? 'opacity-0 ease-out duration-100' : 'opacity-100 ease-in duration-200', 'absolute inset-0 h-full w-full flex items-center justify-center transition-opacity']" aria-hidden="true">
|
<span :class="[active ? iconActiveClass : iconInactiveClass, iconBaseClass]" aria-hidden="true">
|
||||||
<Icon :name="iconOff" class="h-3 w-3 u-text-gray-400" />
|
<Icon :name="iconOn" :class="iconOnClass" />
|
||||||
</span>
|
</span>
|
||||||
<span :class="[enabled ? 'opacity-100 ease-in duration-200' : 'opacity-0 ease-out duration-100', 'absolute inset-0 h-full w-full flex items-center justify-center transition-opacity']" aria-hidden="true">
|
<span :class="[active ? iconInactiveClass : iconActiveClass, iconBaseClass]" aria-hidden="true">
|
||||||
<Icon :name="iconOn" class="h-3 w-3 text-primary-600" />
|
<Icon :name="iconOff" :class="iconOffClass" />
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</Switch>
|
</Switch>
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import { Switch } from '@headlessui/vue'
|
import { Switch } from '@headlessui/vue'
|
||||||
import Icon from '../elements/Icon'
|
import Icon from '../elements/Icon'
|
||||||
|
import $ui from '#build/ui'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
modelValue: {
|
modelValue: {
|
||||||
@@ -31,12 +32,56 @@ const props = defineProps({
|
|||||||
iconOff: {
|
iconOff: {
|
||||||
type: String,
|
type: String,
|
||||||
default: ''
|
default: ''
|
||||||
|
},
|
||||||
|
baseClass: {
|
||||||
|
type: String,
|
||||||
|
default: () => $ui.toggle.base
|
||||||
|
},
|
||||||
|
activeClass: {
|
||||||
|
type: String,
|
||||||
|
default: () => $ui.toggle.active
|
||||||
|
},
|
||||||
|
inactiveClass: {
|
||||||
|
type: String,
|
||||||
|
default: () => $ui.toggle.inactive
|
||||||
|
},
|
||||||
|
containerBaseClass: {
|
||||||
|
type: String,
|
||||||
|
default: () => $ui.toggle.container.base
|
||||||
|
},
|
||||||
|
containerActiveClass: {
|
||||||
|
type: String,
|
||||||
|
default: () => $ui.toggle.container.active
|
||||||
|
},
|
||||||
|
containerInactiveClass: {
|
||||||
|
type: String,
|
||||||
|
default: () => $ui.toggle.container.inactive
|
||||||
|
},
|
||||||
|
iconBaseClass: {
|
||||||
|
type: String,
|
||||||
|
default: () => $ui.toggle.icon.base
|
||||||
|
},
|
||||||
|
iconActiveClass: {
|
||||||
|
type: String,
|
||||||
|
default: () => $ui.toggle.icon.active
|
||||||
|
},
|
||||||
|
iconInactiveClass: {
|
||||||
|
type: String,
|
||||||
|
default: () => $ui.toggle.icon.inactive
|
||||||
|
},
|
||||||
|
iconOnClass: {
|
||||||
|
type: String,
|
||||||
|
default: () => $ui.toggle.icon.on
|
||||||
|
},
|
||||||
|
iconOffClass: {
|
||||||
|
type: String,
|
||||||
|
default: () => $ui.toggle.icon.off
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const emit = defineEmits(['update:modelValue'])
|
const emit = defineEmits(['update:modelValue'])
|
||||||
|
|
||||||
const enabled = computed({
|
const active = computed({
|
||||||
get () {
|
get () {
|
||||||
return props.modelValue
|
return props.modelValue
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user