cornet-ui 0.1.0-beta.5 → 0.1.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Actions/du-button/du-button.types.ts +14 -0
- package/components/Actions/du-button/du-button.vue +149 -0
- package/components/Actions/du-dropdown/du-dropdown.types.ts +15 -0
- package/components/Actions/du-dropdown/du-dropdown.vue +75 -0
- package/components/Actions/du-fab/du-fab.types.ts +28 -0
- package/components/Actions/du-fab/du-fab.vue +270 -0
- package/components/Actions/du-modal/du-modal.types.ts +10 -0
- package/components/Actions/du-modal/du-modal.vue +123 -0
- package/components/Actions/du-swap/du-swap.types.ts +3 -0
- package/components/Actions/du-swap/du-swap.vue +68 -0
- package/components/DataDisplay/du-accordion/du-accordion-item.vue +37 -0
- package/components/DataDisplay/du-accordion/du-accordion.types.ts +15 -0
- package/components/DataDisplay/du-accordion/du-accordion.vue +73 -0
- package/components/DataDisplay/du-avatar/du-avatar.types.ts +59 -0
- package/components/DataDisplay/du-avatar/du-avatar.vue +139 -0
- package/components/DataDisplay/du-badge/du-badge.types.ts +21 -0
- package/components/DataDisplay/du-badge/du-badge.vue +81 -0
- package/components/DataDisplay/du-card/du-card.types.ts +18 -0
- package/components/DataDisplay/du-card/du-card.vue +86 -0
- package/components/DataDisplay/du-carousel/du-carousel-item.vue +11 -0
- package/components/DataDisplay/du-carousel/du-carousel.types.ts +15 -0
- package/components/DataDisplay/du-carousel/du-carousel.vue +46 -0
- package/components/DataDisplay/du-chat/du-chat-item.vue +56 -0
- package/components/DataDisplay/du-chat/du-chat.types.ts +31 -0
- package/components/DataDisplay/du-chat/du-chat.vue +71 -0
- package/components/DataDisplay/du-collapse/du-collapse.types.ts +15 -0
- package/components/DataDisplay/du-collapse/du-collapse.vue +59 -0
- package/components/DataDisplay/du-countdown/du-countdown-group.vue +88 -0
- package/components/DataDisplay/du-countdown/du-countdown.types.ts +15 -0
- package/components/DataDisplay/du-countdown/du-countdown.vue +180 -0
- package/components/DataDisplay/du-diff/du-diff.types.ts +9 -0
- package/components/DataDisplay/du-diff/du-diff.vue +44 -0
- package/components/DataDisplay/du-kbd/du-kbd.types.ts +9 -0
- package/components/DataDisplay/du-kbd/du-kbd.vue +21 -0
- package/components/DataDisplay/du-list/du-list-row.vue +12 -0
- package/components/DataDisplay/du-list/du-list.types.ts +3 -0
- package/components/DataDisplay/du-list/du-list.vue +11 -0
- package/components/DataDisplay/du-stat/du-stat.types.ts +12 -0
- package/components/DataDisplay/du-stat/du-stat.vue +28 -0
- package/components/DataDisplay/du-stats/du-stats.types.ts +3 -0
- package/components/DataDisplay/du-stats/du-stats.vue +91 -0
- package/components/DataDisplay/du-status/du-status.types.ts +21 -0
- package/components/DataDisplay/du-status/du-status.vue +51 -0
- package/components/DataDisplay/du-table/du-table-item.types.ts +6 -0
- package/components/DataDisplay/du-table/du-table-item.vue +24 -0
- package/components/DataDisplay/du-table/du-table.types.ts +26 -0
- package/components/DataDisplay/du-table/du-table.vue +125 -0
- package/components/DataDisplay/du-timeline/du-timeline-item.vue +85 -0
- package/components/DataDisplay/du-timeline/du-timeline.types.ts +22 -0
- package/components/DataDisplay/du-timeline/du-timeline.vue +138 -0
- package/components/DataInput/du-checkbox/du-checkbox.types.ts +17 -0
- package/components/DataInput/du-checkbox/du-checkbox.vue +40 -0
- package/components/DataInput/du-fieldset/du-fieldset.types.ts +4 -0
- package/components/DataInput/du-fieldset/du-fieldset.vue +16 -0
- package/components/DataInput/du-file-input/du-file-input.types.ts +29 -0
- package/components/DataInput/du-file-input/du-file-input.vue +31 -0
- package/components/DataInput/du-filter/du-filter.types.ts +30 -0
- package/components/DataInput/du-filter/du-filter.vue +47 -0
- package/components/DataInput/du-input-field/du-input-field.types.ts +43 -0
- package/components/DataInput/du-input-field/du-input-field.vue +47 -0
- package/components/DataInput/du-label/du-label.types.ts +3 -0
- package/components/DataInput/du-label/du-label.vue +28 -0
- package/components/DataInput/du-label-input-validator/du-label-input-validator.types.ts +7 -0
- package/components/DataInput/du-label-input-validator/du-label-input-validator.vue +51 -0
- package/components/DataInput/du-radio/du-radio.types.ts +15 -0
- package/components/DataInput/du-radio/du-radio.vue +27 -0
- package/components/DataInput/du-range/du-range.types.ts +18 -0
- package/components/DataInput/du-range/du-range.vue +60 -0
- package/components/DataInput/du-rating/du-rating-item.vue +65 -0
- package/components/DataInput/du-rating/du-rating.types.ts +46 -0
- package/components/DataInput/du-rating/du-rating.vue +127 -0
- package/components/DataInput/du-search/du-search.types.ts +44 -0
- package/components/DataInput/du-search/du-search.vue +425 -0
- package/components/DataInput/du-select/du-select.types.ts +31 -0
- package/components/DataInput/du-select/du-select.vue +384 -0
- package/components/DataInput/du-text-area/du-text-area.types.ts +11 -0
- package/components/DataInput/du-text-area/du-text-area.vue +41 -0
- package/components/Feedback/du-alert/du-alert.types.ts +16 -0
- package/components/Feedback/du-alert/du-alert.vue +113 -0
- package/components/Feedback/du-loading/du-loading.types.ts +11 -0
- package/components/Feedback/du-loading/du-loading.vue +33 -0
- package/components/Feedback/du-progress/du-progress.types.ts +8 -0
- package/components/Feedback/du-progress/du-progress.vue +23 -0
- package/components/Feedback/du-radial-progress/du-radial-progress.types.ts +9 -0
- package/components/Feedback/du-radial-progress/du-radial-progress.vue +64 -0
- package/components/Feedback/du-skeleton/du-skeleton.types.ts +3 -0
- package/components/Feedback/du-skeleton/du-skeleton.vue +11 -0
- package/components/Feedback/du-toast/du-toast.types.ts +11 -0
- package/components/Feedback/du-toast/du-toast.vue +54 -0
- package/components/Feedback/du-tooltip/du-tooltip.types.ts +12 -0
- package/components/Feedback/du-tooltip/du-tooltip.vue +55 -0
- package/components/Layout/du-drawer/du-drawer.types.ts +27 -0
- package/components/Layout/du-drawer/du-drawer.vue +224 -0
- package/components/Layout/du-join/du-join.types.ts +7 -0
- package/components/Layout/du-join/du-join.vue +31 -0
- package/components/Navigation/du-breadcrumbs/du-breadcrumbs.types.ts +13 -0
- package/components/Navigation/du-breadcrumbs/du-breadcrumbs.vue +79 -0
- package/components/Navigation/du-button-link/du-button-link.types.ts +17 -0
- package/components/Navigation/du-button-link/du-button-link.vue +77 -0
- package/components/Navigation/du-dock/du-dock.types.ts +19 -0
- package/components/Navigation/du-dock/du-dock.vue +73 -0
- package/components/Navigation/du-link/du-link.types.ts +7 -0
- package/components/Navigation/du-link/du-link.vue +25 -0
- package/components/Navigation/du-menu/du-menu-item.vue +160 -0
- package/components/Navigation/du-menu/du-menu.types.ts +33 -0
- package/components/Navigation/du-menu/du-menu.vue +87 -0
- package/components/Navigation/du-navbar/du-navbar.types.ts +3 -0
- package/components/Navigation/du-navbar/du-navbar.vue +21 -0
- package/components/Navigation/du-pagination/du-pagination.types.ts +30 -0
- package/components/Navigation/du-pagination/du-pagination.vue +186 -0
- package/components/Navigation/du-step-item/du-step-item.types.ts +9 -0
- package/components/Navigation/du-step-item/du-step-item.vue +46 -0
- package/components/Navigation/du-steps/du-steps.types.ts +20 -0
- package/components/Navigation/du-steps/du-steps.vue +85 -0
- package/components/Navigation/du-tabs/du-tabs.types.ts +25 -0
- package/components/Navigation/du-tabs/du-tabs.vue +96 -0
- package/composables/useSizeProps.ts +26 -0
- package/composables/useVariantProps.ts +18 -0
- package/dist/plugin-vite.d.ts +1 -1
- package/dist/plugin-vite.js +20 -19
- package/index.css +7 -0
- package/index.ts +69 -0
- package/package.json +10 -1
- package/plugin-vite.ts +301 -0
- package/types/index.ts +59 -0
- package/types/types.sh +80 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const BUTTON_SIZES = ['btn-xs', 'btn-sm', 'btn-md', 'btn-lg', 'btn-xl'] as const
|
|
2
|
+
export const BUTTON_COLORS = [
|
|
3
|
+
'btn-primary',
|
|
4
|
+
'btn-secondary',
|
|
5
|
+
'btn-accent',
|
|
6
|
+
'btn-neutral',
|
|
7
|
+
'btn-info',
|
|
8
|
+
'btn-success',
|
|
9
|
+
'btn-warning',
|
|
10
|
+
'btn-error',
|
|
11
|
+
] as const
|
|
12
|
+
|
|
13
|
+
export type BUTTONSize = (typeof BUTTON_SIZES)[number]
|
|
14
|
+
export type BUTTONColor = (typeof BUTTON_COLORS)[number]
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { type Size, useSizeMapping } from '../../../composables/useSizeProps'
|
|
3
|
+
import { useVariantMapping, type Variant } from '../../../composables/useVariantProps'
|
|
4
|
+
import { computed, inject } from 'vue'
|
|
5
|
+
|
|
6
|
+
type ElementType = 'button' | 'a' | 'input' | 'div' | 'RouterLink' | 'NuxtLink' | string
|
|
7
|
+
|
|
8
|
+
const props = withDefaults(
|
|
9
|
+
defineProps<{
|
|
10
|
+
customClass?: string
|
|
11
|
+
size?: Size
|
|
12
|
+
variant?: Variant
|
|
13
|
+
outline?: boolean
|
|
14
|
+
soft?: boolean
|
|
15
|
+
dash?: boolean
|
|
16
|
+
active?: boolean
|
|
17
|
+
ghost?: boolean
|
|
18
|
+
link?: boolean
|
|
19
|
+
wide?: boolean
|
|
20
|
+
disabled?: boolean
|
|
21
|
+
square?: boolean
|
|
22
|
+
circle?: boolean
|
|
23
|
+
block?: boolean
|
|
24
|
+
as?: ElementType
|
|
25
|
+
type?: string
|
|
26
|
+
href?: string
|
|
27
|
+
value?: string
|
|
28
|
+
inputType?: 'button' | 'submit' | 'reset' | 'radio' | 'checkbox'
|
|
29
|
+
label?: string
|
|
30
|
+
}>(),
|
|
31
|
+
{
|
|
32
|
+
customClass: undefined,
|
|
33
|
+
size: 'default',
|
|
34
|
+
variant: 'default',
|
|
35
|
+
outline: false,
|
|
36
|
+
soft: false,
|
|
37
|
+
dash: false,
|
|
38
|
+
active: false,
|
|
39
|
+
ghost: false,
|
|
40
|
+
link: false,
|
|
41
|
+
wide: false,
|
|
42
|
+
disabled: undefined,
|
|
43
|
+
square: false,
|
|
44
|
+
circle: false,
|
|
45
|
+
block: false,
|
|
46
|
+
type: undefined,
|
|
47
|
+
href: undefined,
|
|
48
|
+
value: undefined,
|
|
49
|
+
inputType: undefined,
|
|
50
|
+
label: undefined,
|
|
51
|
+
},
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
const isInDropdownTrigger = inject('isDropdownTrigger', false)
|
|
55
|
+
const inJoin = inject("isInJoin", false)
|
|
56
|
+
const filterName = inject('filterName', undefined)
|
|
57
|
+
|
|
58
|
+
const { sizeClass } = useSizeMapping(props, 'btn')
|
|
59
|
+
const { colorClass } = useVariantMapping(props, 'btn')
|
|
60
|
+
const softClass = computed(() => {
|
|
61
|
+
return props.soft ? 'btn-soft' : ''
|
|
62
|
+
})
|
|
63
|
+
const outlineClass = computed(() => {
|
|
64
|
+
return props.outline ? 'btn-outline' : ''
|
|
65
|
+
})
|
|
66
|
+
const dashClass = computed(() => {
|
|
67
|
+
return props.dash ? 'btn-dash' : ''
|
|
68
|
+
})
|
|
69
|
+
const activeClass = computed(() => {
|
|
70
|
+
return props.active ? 'btn-active' : ''
|
|
71
|
+
})
|
|
72
|
+
const ghostClass = computed(() => {
|
|
73
|
+
return props.ghost ? 'btn-ghost' : ''
|
|
74
|
+
})
|
|
75
|
+
const linkClass = computed(() => {
|
|
76
|
+
return props.link ? 'btn-link' : ''
|
|
77
|
+
})
|
|
78
|
+
const wideClass = computed(() => {
|
|
79
|
+
return props.wide ? 'btn-wide' : ''
|
|
80
|
+
})
|
|
81
|
+
const squareClass = computed(() => {
|
|
82
|
+
return props.square ? 'btn-square' : ''
|
|
83
|
+
})
|
|
84
|
+
const circleClass = computed(() => {
|
|
85
|
+
return props.circle ? 'btn-circle' : ''
|
|
86
|
+
})
|
|
87
|
+
const blockClass = computed(() => {
|
|
88
|
+
return props.block ? 'btn-block' : ''
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
const elementTag = computed((): ElementType => {
|
|
92
|
+
if (props.as) return props.as
|
|
93
|
+
if (isInDropdownTrigger) return 'div'
|
|
94
|
+
if (filterName) return 'input'
|
|
95
|
+
|
|
96
|
+
return 'button'
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
const isInputElement = computed(() => elementTag.value === 'input')
|
|
100
|
+
const isAnchorElement = computed(() => elementTag.value === 'a')
|
|
101
|
+
|
|
102
|
+
const buttonAttributes = computed(() => {
|
|
103
|
+
const attrs: Record<string, any> = {}
|
|
104
|
+
|
|
105
|
+
if (filterName) {
|
|
106
|
+
attrs.name = filterName
|
|
107
|
+
attrs.type = 'radio'
|
|
108
|
+
} else if (isInputElement.value) {
|
|
109
|
+
attrs.type = props.inputType || 'button'
|
|
110
|
+
attrs.value = props.value || ''
|
|
111
|
+
} else if (isAnchorElement.value) {
|
|
112
|
+
attrs.href = props.href || '#'
|
|
113
|
+
attrs.role = 'button'
|
|
114
|
+
} else if (isInDropdownTrigger) {
|
|
115
|
+
attrs.tabindex = '0'
|
|
116
|
+
attrs.role = 'button'
|
|
117
|
+
} else {
|
|
118
|
+
attrs.type = props.type || 'button'
|
|
119
|
+
}
|
|
120
|
+
return attrs
|
|
121
|
+
})
|
|
122
|
+
</script>
|
|
123
|
+
<template>
|
|
124
|
+
<component
|
|
125
|
+
:is="elementTag"
|
|
126
|
+
v-bind="buttonAttributes"
|
|
127
|
+
:class="[
|
|
128
|
+
'btn',
|
|
129
|
+
customClass,
|
|
130
|
+
sizeClass,
|
|
131
|
+
colorClass,
|
|
132
|
+
softClass,
|
|
133
|
+
outlineClass,
|
|
134
|
+
dashClass,
|
|
135
|
+
activeClass,
|
|
136
|
+
ghostClass,
|
|
137
|
+
linkClass,
|
|
138
|
+
wideClass,
|
|
139
|
+
squareClass,
|
|
140
|
+
circleClass,
|
|
141
|
+
blockClass,
|
|
142
|
+
inJoin && 'join-item',
|
|
143
|
+
]"
|
|
144
|
+
:aria-label="props.label"
|
|
145
|
+
:disabled="props.disabled"
|
|
146
|
+
>
|
|
147
|
+
<slot v-if="!isInputElement"></slot>
|
|
148
|
+
</component>
|
|
149
|
+
</template>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const DROPDOWN_PLACEMENTS = [
|
|
2
|
+
'dropdown-start',
|
|
3
|
+
'dropdown-center',
|
|
4
|
+
'dropdown-end',
|
|
5
|
+
'dropdown-top',
|
|
6
|
+
'dropdown-bottom',
|
|
7
|
+
'dropdown-left',
|
|
8
|
+
'dropdown-right',
|
|
9
|
+
] as const
|
|
10
|
+
|
|
11
|
+
export type DROPDOWNPlacement = (typeof DROPDOWN_PLACEMENTS)[number]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export type PlacementValue = 'start' | 'center' | 'end' | 'top' | 'bottom' | 'left' | 'right'
|
|
15
|
+
export type PlacementInput = PlacementValue | string | PlacementValue[] | Partial<Record<PlacementValue, boolean>>
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, provide } from 'vue'
|
|
3
|
+
import { type PlacementInput, type PlacementValue } from './du-dropdown.types'
|
|
4
|
+
|
|
5
|
+
const props = withDefaults(
|
|
6
|
+
defineProps<{
|
|
7
|
+
hover?: boolean
|
|
8
|
+
open?: boolean
|
|
9
|
+
placement?: PlacementInput
|
|
10
|
+
}>(),
|
|
11
|
+
{
|
|
12
|
+
hover: false,
|
|
13
|
+
open: false,
|
|
14
|
+
placement: 'bottom',
|
|
15
|
+
},
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
provide('isDropdownTrigger', true)
|
|
19
|
+
|
|
20
|
+
const placementToClass = (value: PlacementValue): string => {
|
|
21
|
+
return `dropdown-${value}`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const getPlacementClasses = (input: PlacementInput): string[] => {
|
|
25
|
+
if (!input) return []
|
|
26
|
+
|
|
27
|
+
if (typeof input === 'string') {
|
|
28
|
+
if (input.includes(',')) {
|
|
29
|
+
return input.split(',').map(s => s.trim()).filter(Boolean).map(s => placementToClass(s as PlacementValue))
|
|
30
|
+
}
|
|
31
|
+
return [placementToClass(input as PlacementValue)]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (Array.isArray(input)) {
|
|
35
|
+
return input.map(placementToClass)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (typeof input === 'object') {
|
|
39
|
+
const keys = Object.keys(input)
|
|
40
|
+
if (keys.every(key => key in { start: 1, center: 1, end: 1, top: 1, bottom: 1, left: 1, right: 1 })) {
|
|
41
|
+
return keys.map(key => placementToClass(key as PlacementValue))
|
|
42
|
+
}
|
|
43
|
+
return Object.entries(input)
|
|
44
|
+
.filter(([, enabled]) => enabled)
|
|
45
|
+
.map(([key]) => placementToClass(key as PlacementValue))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return []
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const placementClass = computed(() => {
|
|
52
|
+
const classes = getPlacementClasses(props.placement)
|
|
53
|
+
return classes.join(' ')
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
const hoverClass = computed(() => {
|
|
57
|
+
return props.hover ? 'dropdown-hover' : ''
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
const openClass = computed(() => {
|
|
61
|
+
return props.open ? 'dropdown-open' : ''
|
|
62
|
+
})
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
<template>
|
|
66
|
+
<div :class="['dropdown', placementClass, hoverClass, openClass]">
|
|
67
|
+
<!-- Bind triggerProps on your trigger element (v-bind="triggerProps")
|
|
68
|
+
to get the expected role/tabindex/aria attributes for free. -->
|
|
69
|
+
<slot name="trigger" :trigger-props="{ role: 'button', tabindex: 0, 'aria-haspopup': 'true' }"></slot>
|
|
70
|
+
<div class="dropdown-content" tabindex="0">
|
|
71
|
+
<slot name="content"></slot>
|
|
72
|
+
<slot></slot>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
</template>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const FAB_MODIFIERS = ['fab-flower'] as const
|
|
2
|
+
|
|
3
|
+
export type FABModifier = (typeof FAB_MODIFIERS)[number]
|
|
4
|
+
|
|
5
|
+
export interface FABItem {
|
|
6
|
+
label?: string
|
|
7
|
+
icon?: any
|
|
8
|
+
customClass?: string
|
|
9
|
+
onClick?: () => void
|
|
10
|
+
tooltip?: string
|
|
11
|
+
tooltipPosition?: 'left' | 'top' | 'right' | 'bottom'
|
|
12
|
+
[key: string]: any
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface FABMainAction {
|
|
16
|
+
label?: string
|
|
17
|
+
icon?: any
|
|
18
|
+
customClass?: string
|
|
19
|
+
variant?: string
|
|
20
|
+
onClick?: () => void
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface FABCloseButton {
|
|
24
|
+
label?: string
|
|
25
|
+
icon?: string
|
|
26
|
+
customClass?: string
|
|
27
|
+
variant?: string
|
|
28
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
import { type Size, useSizeMapping } from '../../../composables/useSizeProps'
|
|
4
|
+
import { type Variant, useVariantMapping } from '../../../composables/useVariantProps'
|
|
5
|
+
import { type FABItem, type FABMainAction, type FABCloseButton } from './du-fab.types'
|
|
6
|
+
import DuButton from '../du-button/du-button.vue'
|
|
7
|
+
import DuTooltip from '../../Feedback/du-tooltip/du-tooltip.vue'
|
|
8
|
+
|
|
9
|
+
const props = withDefaults(
|
|
10
|
+
defineProps<{
|
|
11
|
+
items?: FABItem[]
|
|
12
|
+
modifier?: 'fab-flower'
|
|
13
|
+
customClass?: string
|
|
14
|
+
size?: Size
|
|
15
|
+
variant?: Variant
|
|
16
|
+
circle?: boolean
|
|
17
|
+
mainAction?: FABMainAction
|
|
18
|
+
closeButton?: FABCloseButton
|
|
19
|
+
absolute?: boolean
|
|
20
|
+
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'
|
|
21
|
+
}>(),
|
|
22
|
+
{
|
|
23
|
+
items: undefined,
|
|
24
|
+
modifier: undefined,
|
|
25
|
+
customClass: '',
|
|
26
|
+
size: 'lg',
|
|
27
|
+
variant: 'primary',
|
|
28
|
+
circle: true,
|
|
29
|
+
mainAction: undefined,
|
|
30
|
+
closeButton: undefined,
|
|
31
|
+
absolute: true,
|
|
32
|
+
position: 'bottom-right',
|
|
33
|
+
},
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
const { sizeClass } = useSizeMapping(props, 'btn')
|
|
37
|
+
const { colorClass } = useVariantMapping(props, 'btn')
|
|
38
|
+
|
|
39
|
+
const modifierClass = computed(() => {
|
|
40
|
+
return props.modifier ? props.modifier : ''
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const positionClass = computed(() => {
|
|
44
|
+
if (!props.absolute) return ''
|
|
45
|
+
|
|
46
|
+
switch (props.position) {
|
|
47
|
+
case 'bottom-right':
|
|
48
|
+
return 'absolute bottom-4 right-4'
|
|
49
|
+
case 'bottom-left':
|
|
50
|
+
return 'absolute bottom-4 left-4'
|
|
51
|
+
case 'top-right':
|
|
52
|
+
return 'absolute top-4 right-4'
|
|
53
|
+
case 'top-left':
|
|
54
|
+
return 'absolute top-4 left-4'
|
|
55
|
+
default:
|
|
56
|
+
return 'absolute bottom-4 right-4'
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
const fabClasses = computed(() => {
|
|
61
|
+
return [
|
|
62
|
+
'fab',
|
|
63
|
+
modifierClass.value,
|
|
64
|
+
positionClass.value,
|
|
65
|
+
'z-50',
|
|
66
|
+
props.customClass,
|
|
67
|
+
]
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
const getTooltipPosition = (position?: 'left' | 'top' | 'right' | 'bottom') => {
|
|
71
|
+
return position || 'left'
|
|
72
|
+
}
|
|
73
|
+
</script>
|
|
74
|
+
|
|
75
|
+
<template>
|
|
76
|
+
<!-- Dynamic items mode -->
|
|
77
|
+
<template v-if="items || mainAction">
|
|
78
|
+
<div :class="fabClasses">
|
|
79
|
+
<!-- Main trigger button -->
|
|
80
|
+
<div
|
|
81
|
+
tabindex="0"
|
|
82
|
+
role="button"
|
|
83
|
+
:class="[
|
|
84
|
+
'btn',
|
|
85
|
+
sizeClass,
|
|
86
|
+
colorClass,
|
|
87
|
+
props.circle ? 'btn-circle' : '',
|
|
88
|
+
]"
|
|
89
|
+
>
|
|
90
|
+
<slot name="trigger">
|
|
91
|
+
<slot name="trigger-icon">F</slot>
|
|
92
|
+
</slot>
|
|
93
|
+
</div>
|
|
94
|
+
|
|
95
|
+
<!-- Close button (optional) -->
|
|
96
|
+
<div
|
|
97
|
+
v-if="closeButton"
|
|
98
|
+
class="fab-close"
|
|
99
|
+
>
|
|
100
|
+
<slot name="close-button" :closeButton="closeButton">
|
|
101
|
+
{{ closeButton.label || 'Close' }}
|
|
102
|
+
<span
|
|
103
|
+
:class="[
|
|
104
|
+
'btn',
|
|
105
|
+
sizeClass,
|
|
106
|
+
'btn-circle',
|
|
107
|
+
closeButton.variant ? `btn-${closeButton.variant}` : 'btn-error',
|
|
108
|
+
closeButton.customClass,
|
|
109
|
+
]"
|
|
110
|
+
>
|
|
111
|
+
<slot name="close-icon">{{ closeButton.icon || '✕' }}</slot>
|
|
112
|
+
</span>
|
|
113
|
+
</slot>
|
|
114
|
+
</div>
|
|
115
|
+
|
|
116
|
+
<!-- Main action button (optional) -->
|
|
117
|
+
<DuButton
|
|
118
|
+
v-if="mainAction"
|
|
119
|
+
as="button"
|
|
120
|
+
customClass="fab-main-action"
|
|
121
|
+
:size="props.size"
|
|
122
|
+
:variant="(mainAction.variant as Variant) || 'default'"
|
|
123
|
+
circle
|
|
124
|
+
@click="mainAction.onClick"
|
|
125
|
+
>
|
|
126
|
+
<slot name="main-action" :mainAction="mainAction">
|
|
127
|
+
<slot name="main-action-icon" :mainAction="mainAction">
|
|
128
|
+
<component
|
|
129
|
+
class="w-6 h-6"
|
|
130
|
+
:is="mainAction.icon"
|
|
131
|
+
v-if="typeof mainAction.icon === 'object' || typeof mainAction.icon === 'function'"
|
|
132
|
+
/>
|
|
133
|
+
<img
|
|
134
|
+
v-else-if="typeof mainAction.icon === 'string' && mainAction.icon.startsWith('http')"
|
|
135
|
+
:src="mainAction.icon"
|
|
136
|
+
:alt="mainAction.label"
|
|
137
|
+
class="w-6 h-6"
|
|
138
|
+
/>
|
|
139
|
+
<div
|
|
140
|
+
v-else-if="typeof mainAction.icon === 'string'"
|
|
141
|
+
v-html="mainAction.icon"
|
|
142
|
+
></div>
|
|
143
|
+
<template v-else>
|
|
144
|
+
{{ mainAction.label || 'M' }}
|
|
145
|
+
</template>
|
|
146
|
+
</slot>
|
|
147
|
+
</slot>
|
|
148
|
+
</DuButton>
|
|
149
|
+
|
|
150
|
+
<!-- Speed dial buttons -->
|
|
151
|
+
<template v-for="(item, index) in items" :key="index">
|
|
152
|
+
<!-- With tooltip wrapper -->
|
|
153
|
+
<DuTooltip
|
|
154
|
+
v-if="item.tooltip"
|
|
155
|
+
:dataTip="item.tooltip"
|
|
156
|
+
:position="getTooltipPosition(item.tooltipPosition)"
|
|
157
|
+
>
|
|
158
|
+
<DuButton
|
|
159
|
+
as="button"
|
|
160
|
+
:size="props.size"
|
|
161
|
+
:circle="props.circle"
|
|
162
|
+
:customClass="item.customClass"
|
|
163
|
+
@click="item.onClick"
|
|
164
|
+
>
|
|
165
|
+
<slot name="item" :item="item" :index="index">
|
|
166
|
+
<slot :name="`item-${index}`" :item="item" :index="index">
|
|
167
|
+
<component
|
|
168
|
+
class="w-6 h-6"
|
|
169
|
+
:is="item.icon"
|
|
170
|
+
v-if="typeof item.icon === 'object' || typeof item.icon === 'function'"
|
|
171
|
+
/>
|
|
172
|
+
<img
|
|
173
|
+
v-else-if="typeof item.icon === 'string' && item.icon.startsWith('http')"
|
|
174
|
+
:src="item.icon"
|
|
175
|
+
:alt="item.label"
|
|
176
|
+
class="w-6 h-6"
|
|
177
|
+
/>
|
|
178
|
+
<div
|
|
179
|
+
v-else-if="typeof item.icon === 'string'"
|
|
180
|
+
v-html="item.icon"
|
|
181
|
+
></div>
|
|
182
|
+
<template v-else>
|
|
183
|
+
{{ item.label || index + 1 }}
|
|
184
|
+
</template>
|
|
185
|
+
</slot>
|
|
186
|
+
</slot>
|
|
187
|
+
</DuButton>
|
|
188
|
+
</DuTooltip>
|
|
189
|
+
|
|
190
|
+
<!-- Without tooltip wrapper -->
|
|
191
|
+
<template v-else>
|
|
192
|
+
<!-- With label wrapper -->
|
|
193
|
+
<div v-if="item.label && !props.modifier">
|
|
194
|
+
{{ item.label }}
|
|
195
|
+
<DuButton
|
|
196
|
+
as="button"
|
|
197
|
+
:size="props.size"
|
|
198
|
+
:circle="props.circle"
|
|
199
|
+
:customClass="item.customClass"
|
|
200
|
+
@click="item.onClick"
|
|
201
|
+
>
|
|
202
|
+
<slot name="item" :item="item" :index="index">
|
|
203
|
+
<slot :name="`item-${index}`" :item="item" :index="index">
|
|
204
|
+
<component
|
|
205
|
+
class="w-6 h-6"
|
|
206
|
+
:is="item.icon"
|
|
207
|
+
v-if="typeof item.icon === 'object' || typeof item.icon === 'function'"
|
|
208
|
+
/>
|
|
209
|
+
<img
|
|
210
|
+
v-else-if="typeof item.icon === 'string' && item.icon.startsWith('http')"
|
|
211
|
+
:src="item.icon"
|
|
212
|
+
:alt="item.label"
|
|
213
|
+
class="w-6 h-6"
|
|
214
|
+
/>
|
|
215
|
+
<div
|
|
216
|
+
v-else-if="typeof item.icon === 'string'"
|
|
217
|
+
v-html="item.icon"
|
|
218
|
+
></div>
|
|
219
|
+
<template v-else>
|
|
220
|
+
{{ index + 1 }}
|
|
221
|
+
</template>
|
|
222
|
+
</slot>
|
|
223
|
+
</slot>
|
|
224
|
+
</DuButton>
|
|
225
|
+
</div>
|
|
226
|
+
|
|
227
|
+
<!-- Without label wrapper -->
|
|
228
|
+
<DuButton
|
|
229
|
+
v-else
|
|
230
|
+
as="button"
|
|
231
|
+
:size="props.size"
|
|
232
|
+
:circle="props.circle"
|
|
233
|
+
:customClass="item.customClass"
|
|
234
|
+
@click="item.onClick"
|
|
235
|
+
>
|
|
236
|
+
<slot name="item" :item="item" :index="index">
|
|
237
|
+
<slot :name="`item-${index}`" :item="item" :index="index">
|
|
238
|
+
<component
|
|
239
|
+
class="w-6 h-6"
|
|
240
|
+
:is="item.icon"
|
|
241
|
+
v-if="typeof item.icon === 'object' || typeof item.icon === 'function'"
|
|
242
|
+
/>
|
|
243
|
+
<img
|
|
244
|
+
v-else-if="typeof item.icon === 'string' && item.icon.startsWith('http')"
|
|
245
|
+
:src="item.icon"
|
|
246
|
+
:alt="item.label"
|
|
247
|
+
class="w-6 h-6"
|
|
248
|
+
/>
|
|
249
|
+
<div
|
|
250
|
+
v-else-if="typeof item.icon === 'string'"
|
|
251
|
+
v-html="item.icon"
|
|
252
|
+
></div>
|
|
253
|
+
<template v-else>
|
|
254
|
+
{{ item.label || index + 1 }}
|
|
255
|
+
</template>
|
|
256
|
+
</slot>
|
|
257
|
+
</slot>
|
|
258
|
+
</DuButton>
|
|
259
|
+
</template>
|
|
260
|
+
</template>
|
|
261
|
+
</div>
|
|
262
|
+
</template>
|
|
263
|
+
|
|
264
|
+
<!-- Manual mode -->
|
|
265
|
+
<template v-else>
|
|
266
|
+
<div :class="fabClasses">
|
|
267
|
+
<slot></slot>
|
|
268
|
+
</div>
|
|
269
|
+
</template>
|
|
270
|
+
</template>
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, onMounted, watch } from 'vue'
|
|
3
|
+
|
|
4
|
+
const props = withDefaults(
|
|
5
|
+
defineProps<{
|
|
6
|
+
id?: string
|
|
7
|
+
open?: boolean
|
|
8
|
+
closeButton?: boolean
|
|
9
|
+
closeOnEscape?: boolean
|
|
10
|
+
closeBackdrop?: boolean
|
|
11
|
+
placement?: 'top' | 'middle' | 'bottom' | 'start' | 'end' | 'responsive'
|
|
12
|
+
classBox?: string
|
|
13
|
+
/** Accessible name of the dialog (use when there is no visible title). */
|
|
14
|
+
ariaLabel?: string
|
|
15
|
+
/** id of the element naming the dialog (e.g. your title element). */
|
|
16
|
+
ariaLabelledby?: string
|
|
17
|
+
/** Accessible label of the close button and backdrop. */
|
|
18
|
+
closeLabel?: string
|
|
19
|
+
}>(),
|
|
20
|
+
{
|
|
21
|
+
id: undefined,
|
|
22
|
+
open: false,
|
|
23
|
+
closeButton: false,
|
|
24
|
+
closeOnEscape: true,
|
|
25
|
+
closeBackdrop: true,
|
|
26
|
+
placement: 'middle',
|
|
27
|
+
classBox: '',
|
|
28
|
+
ariaLabel: undefined,
|
|
29
|
+
ariaLabelledby: undefined,
|
|
30
|
+
closeLabel: 'Close',
|
|
31
|
+
},
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
const dialogRef = ref<HTMLDialogElement | null>(null)
|
|
35
|
+
|
|
36
|
+
const placementClass = computed(() => {
|
|
37
|
+
switch (props.placement) {
|
|
38
|
+
case 'top':
|
|
39
|
+
return 'modal-top'
|
|
40
|
+
case 'middle':
|
|
41
|
+
return 'modal-middle'
|
|
42
|
+
case 'bottom':
|
|
43
|
+
return 'modal-bottom'
|
|
44
|
+
case 'start':
|
|
45
|
+
return 'modal-start'
|
|
46
|
+
case 'end':
|
|
47
|
+
return 'modal-end'
|
|
48
|
+
case 'responsive':
|
|
49
|
+
return 'modal-bottom sm:modal-middle'
|
|
50
|
+
default:
|
|
51
|
+
return ''
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const showModal = () => {
|
|
56
|
+
if (dialogRef.value) {
|
|
57
|
+
dialogRef.value.showModal()
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const closeModal = () => {
|
|
62
|
+
if (dialogRef.value) {
|
|
63
|
+
dialogRef.value.close()
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const emit = defineEmits<{
|
|
68
|
+
'update:open': [value: boolean]
|
|
69
|
+
}>()
|
|
70
|
+
|
|
71
|
+
defineExpose({
|
|
72
|
+
showModal,
|
|
73
|
+
closeModal,
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
onMounted(() => {
|
|
77
|
+
if (props.open && dialogRef.value) {
|
|
78
|
+
showModal()
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
watch(
|
|
83
|
+
() => props.open,
|
|
84
|
+
(newValue: boolean) => {
|
|
85
|
+
if (newValue && dialogRef.value) {
|
|
86
|
+
showModal()
|
|
87
|
+
} else if (!newValue && dialogRef.value) {
|
|
88
|
+
closeModal()
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
function handleEscapeKey(_event: KeyboardEvent) {
|
|
94
|
+
if (props.closeOnEscape) {
|
|
95
|
+
closeModal()
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
</script>
|
|
99
|
+
|
|
100
|
+
<template>
|
|
101
|
+
<dialog
|
|
102
|
+
ref="dialogRef"
|
|
103
|
+
:id="id"
|
|
104
|
+
:class="['modal', placementClass]"
|
|
105
|
+
:aria-label="ariaLabel"
|
|
106
|
+
:aria-labelledby="ariaLabelledby"
|
|
107
|
+
@keydown.esc.prevent="handleEscapeKey"
|
|
108
|
+
@close="emit('update:open', false)"
|
|
109
|
+
>
|
|
110
|
+
<div :class="['modal-box', classBox]">
|
|
111
|
+
<form v-if="closeButton" method="dialog">
|
|
112
|
+
<button class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2" :aria-label="closeLabel">
|
|
113
|
+
✕
|
|
114
|
+
</button>
|
|
115
|
+
</form>
|
|
116
|
+
<slot></slot>
|
|
117
|
+
<div class="modal-action" v-if="$slots.actions"><slot name="actions"> </slot></div>
|
|
118
|
+
</div>
|
|
119
|
+
<form v-if="closeBackdrop" method="dialog" class="modal-backdrop">
|
|
120
|
+
<button>{{ closeLabel }}</button>
|
|
121
|
+
</form>
|
|
122
|
+
</dialog>
|
|
123
|
+
</template>
|