|
| 1 | +<template> |
| 2 | + <div class="flex flex-col items-start w-screen h-full p-12 bg-gray-50 space-y-12"> |
| 3 | + <SwitchGroup as="div" class="flex items-center space-x-4"> |
| 4 | + <SwitchLabel>Manual keyboard activation</SwitchLabel> |
| 5 | + |
| 6 | + <Switch as="button" v-model="manual" :className="resolveSwitchClass" v-slot="{ checked }"> |
| 7 | + <span |
| 8 | + class="inline-block w-5 h-5 transition duration-200 ease-in-out transform bg-white rounded-full" |
| 9 | + :class="{ 'translate-x-5': checked, 'translate-x-0': !checked }" |
| 10 | + /> |
| 11 | + </Switch> |
| 12 | + </SwitchGroup> |
| 13 | + |
| 14 | + <TabGroup class="flex flex-col max-w-3xl w-full" as="div" :manual="manual"> |
| 15 | + <TabList class="relative z-0 rounded-lg shadow flex divide-x divide-gray-200"> |
| 16 | + <Tab |
| 17 | + v-for="(tab, tabIdx) in tabs" |
| 18 | + key="tab.name" |
| 19 | + :disabled="tab.disabled" |
| 20 | + class="group relative min-w-0 flex-1 overflow-hidden bg-white py-4 px-4 text-sm font-medium text-center hover:bg-gray-50 focus:z-10" |
| 21 | + :class="{ |
| 22 | + 'text-gray-900': selected, |
| 23 | + 'text-gray-500 hover:text-gray-700': !selected, |
| 24 | + 'rounded-l-lg': tabIdx === 0, |
| 25 | + 'rounded-r-lg': tabIdx === tabs.length - 1, |
| 26 | + 'opacity-50': tab.disabled, |
| 27 | + }" |
| 28 | + v-slot="{ selected }" |
| 29 | + > |
| 30 | + <span>{{tab.name}}</span> |
| 31 | + <small v-if="tab.disabled" class="inline-block px-4 text-xs">(disabled)</small> |
| 32 | + <span |
| 33 | + aria-hidden="true" |
| 34 | + class="absolute inset-x-0 bottom-0 h-0.5" |
| 35 | + :class="{'bg-indigo-500': selected, 'bg-transparent':!selected}" |
| 36 | + /> |
| 37 | + </Tab> |
| 38 | + </TabList> |
| 39 | + |
| 40 | + <TabPanels class="mt-4"> |
| 41 | + <TabPanel v-for="tab in tabs" class="bg-white rounded-lg p-4 shadow" key="tab.name"> |
| 42 | + {{tab.content}} |
| 43 | + </TabPanel> |
| 44 | + </TabPanels> |
| 45 | + </TabGroup> |
| 46 | + </div> |
| 47 | +</template> |
| 48 | + |
| 49 | +<script> |
| 50 | +import { defineComponent, h, ref, onMounted, watchEffect, watch } from 'vue' |
| 51 | +import { SwitchGroup, Switch, SwitchLabel, TabGroup, TabList, Tab, TabPanels, TabPanel } from '@headlessui/vue' |
| 52 | +
|
| 53 | +function classNames(...classes) { |
| 54 | + return classes.filter(Boolean).join(' ') |
| 55 | +} |
| 56 | +
|
| 57 | +let tabs = [ |
| 58 | + { name: 'My Account', content: 'Tab content for my account' }, |
| 59 | + { name: 'Company', content: 'Tab content for company', disabled: true }, |
| 60 | + { name: 'Team Members', content: 'Tab content for team members' }, |
| 61 | + { name: 'Billing', content: 'Tab content for billing' }, |
| 62 | +] |
| 63 | +
|
| 64 | +export default { |
| 65 | + components: { SwitchGroup, Switch, SwitchLabel, TabGroup, TabList, Tab, TabPanels, TabPanel }, |
| 66 | + setup(props, context) { |
| 67 | + let manual = ref(false) |
| 68 | +
|
| 69 | + return { |
| 70 | + tabs: ref(tabs), |
| 71 | + manual, |
| 72 | + resolveSwitchClass({ checked }) { |
| 73 | + return classNames( |
| 74 | + 'relative inline-flex flex-shrink-0 h-6 transition-colors duration-200 ease-in-out border-2 border-transparent rounded-full cursor-pointer w-11 focus:outline-none focus:shadow-outline', |
| 75 | + checked ? 'bg-indigo-600' : 'bg-gray-200' |
| 76 | + ) |
| 77 | + }, |
| 78 | + } |
| 79 | + }, |
| 80 | +} |
| 81 | +</script> |
0 commit comments