mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-25 09:20:36 +01:00
chore(Dropdown): support preset
This commit is contained in:
@@ -93,7 +93,8 @@ const components = [
|
|||||||
label: 'Dropdown',
|
label: 'Dropdown',
|
||||||
to: '/components/Dropdown',
|
to: '/components/Dropdown',
|
||||||
nuxt3: true,
|
nuxt3: true,
|
||||||
capi: true
|
capi: true,
|
||||||
|
preset: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Icon',
|
label: 'Icon',
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
leave-from-class="transform scale-100 opacity-100"
|
leave-from-class="transform scale-100 opacity-100"
|
||||||
leave-to-class="transform scale-95 opacity-0"
|
leave-to-class="transform scale-95 opacity-0"
|
||||||
>
|
>
|
||||||
<MenuItems :class="itemsClass" static>
|
<MenuItems :class="baseClass" static>
|
||||||
<div v-for="(subItems, index) of items" :key="index" class="py-1">
|
<div v-for="(subItems, index) of items" :key="index" class="py-1">
|
||||||
<MenuItem v-for="(item, subIndex) of subItems" :key="subIndex" v-slot="{ active, disabled }">
|
<MenuItem v-for="(item, subIndex) of subItems" :key="subIndex" v-slot="{ active, disabled }">
|
||||||
<Component v-bind="item" :is="(item.to && 'Link') || 'button'" :class="resolveItemClass({ active, disabled })" @click="onItemClick(item)">
|
<Component v-bind="item" :is="(item.to && 'Link') || 'button'" :class="resolveItemClass({ active, disabled })" @click="onItemClick(item)">
|
||||||
@@ -45,6 +45,7 @@ import {
|
|||||||
import Icon from '../elements/Icon'
|
import Icon from '../elements/Icon'
|
||||||
import Link from '../elements/Link'
|
import Link from '../elements/Link'
|
||||||
import { classNames, usePopper } from '../../utils'
|
import { classNames, usePopper } from '../../utils'
|
||||||
|
import $ui from '#build/ui'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@@ -76,35 +77,35 @@ export default {
|
|||||||
},
|
},
|
||||||
wrapperClass: {
|
wrapperClass: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'relative inline-block text-left'
|
default: () => $ui.dropdown.wrapper
|
||||||
},
|
},
|
||||||
containerClass: {
|
containerClass: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'w-48 z-20'
|
default: () => $ui.dropdown.container
|
||||||
},
|
},
|
||||||
itemsClass: {
|
baseClass: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'u-bg-white divide-y u-divide-gray-100 rounded-md ring-1 ring-black ring-opacity-5'
|
default: () => $ui.dropdown.base
|
||||||
},
|
},
|
||||||
itemClass: {
|
itemBaseClass: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'group flex items-center px-4 py-2 text-sm w-full'
|
default: () => $ui.dropdown.item.base
|
||||||
},
|
},
|
||||||
itemActiveClass: {
|
itemActiveClass: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'u-bg-gray-100 u-text-gray-900'
|
default: () => $ui.dropdown.item.active
|
||||||
},
|
},
|
||||||
itemInactiveClass: {
|
itemInactiveClass: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'u-text-gray-700'
|
default: () => $ui.dropdown.item.inactive
|
||||||
},
|
},
|
||||||
itemDisabledClass: {
|
itemDisabledClass: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'cursor-not-allowed opacity-50'
|
default: () => $ui.dropdown.item.disabled
|
||||||
},
|
},
|
||||||
itemIconClass: {
|
itemIconClass: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'mr-3 h-5 w-5 u-text-gray-400 group-hover:u-text-gray-500'
|
default: () => $ui.dropdown.item.icon
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setup (props) {
|
setup (props) {
|
||||||
@@ -134,7 +135,7 @@ export default {
|
|||||||
|
|
||||||
function resolveItemClass ({ active, disabled }) {
|
function resolveItemClass ({ active, disabled }) {
|
||||||
return classNames(
|
return classNames(
|
||||||
props.itemClass,
|
props.itemBaseClass,
|
||||||
active ? props.itemActiveClass : props.itemInactiveClass,
|
active ? props.itemActiveClass : props.itemInactiveClass,
|
||||||
disabled && props.itemDisabledClass
|
disabled && props.itemDisabledClass
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -278,6 +278,19 @@ const alertDialog = {
|
|||||||
description: 'text-sm text-gray-500'
|
description: 'text-sm text-gray-500'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dropdown = {
|
||||||
|
wrapper: 'relative inline-block text-left',
|
||||||
|
container: 'w-48 z-20',
|
||||||
|
base: 'u-bg-white divide-y u-divide-gray-100 rounded-md ring-1 ring-black ring-opacity-5',
|
||||||
|
item: {
|
||||||
|
base: 'group flex items-center px-4 py-2 text-sm w-full',
|
||||||
|
active: 'u-bg-gray-100 u-text-gray-900',
|
||||||
|
inactive: 'u-text-gray-700',
|
||||||
|
disabled: 'cursor-not-allowed opacity-50',
|
||||||
|
icon: 'mr-3 h-5 w-5 u-text-gray-400 group-hover:u-text-gray-500'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
card,
|
card,
|
||||||
button,
|
button,
|
||||||
@@ -291,5 +304,6 @@ export default {
|
|||||||
container,
|
container,
|
||||||
toggle,
|
toggle,
|
||||||
verticalNavigation,
|
verticalNavigation,
|
||||||
alertDialog
|
alertDialog,
|
||||||
|
dropdown
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user