@altafusion/fugue-ui 0.0.0-stage → 0.2.0
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/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/README.md +46 -2
- package/components/AccentSectionCard.vue +243 -0
- package/components/CopyToClipboard.vue +105 -0
- package/components/FileDropzone.vue +223 -0
- package/components/FugueAppHeader.vue +66 -0
- package/components/FugueAppHeaderDefault.vue +74 -0
- package/components/FugueAppHeaderLanding.vue +85 -0
- package/components/PresenceOrb.vue +55 -0
- package/components/TileGroupSection.vue +65 -0
- package/components/TileHintTooltip.vue +37 -0
- package/components/TileSelector.vue +174 -0
- package/components/TileSelectorLabel.vue +110 -0
- package/components/TileSelectorMultiple.vue +114 -0
- package/components/accentSectionCard.shared.ts +293 -0
- package/components/fileDropzone.shared.ts +140 -0
- package/components/fugue-app-header-types.ts +6 -0
- package/components/tileGroupSection.shared.ts +60 -0
- package/components/tileSelector.shared.ts +491 -0
- package/composables/useFugueAppHeaderChrome.ts +33 -0
- package/eslint.config.mjs +4 -0
- package/lib/fugue-header-visual-style.ts +8 -0
- package/nuxt.config.ts +17 -0
- package/package.json +46 -3
- package/utils/brandTheme.ts +42 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @altafusion/fugue-ui
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 7767e60: Rebrand for the public release. In `@altafusion/shell`, `CODERMAR_BRANDS`, `CODERMAR_BRAND_THEME` and `utils/codermarBrandTheme` become `ALTAFUSION_*` and `utils/altafusionBrandTheme`, and the brand cookie key is now `altafusion:brand`. In `@altafusion/msw`, the `codermarMsw*` exports become `altafusionMsw*`. The site settings schema `$id` is now `https://altafusion.com/schemas/site-settings.json`. Package descriptions and docs no longer reference private sites.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [7767e60]
|
|
12
|
+
- @altafusion/fugue-nuxt-ui@0.2.0
|
|
13
|
+
|
|
14
|
+
## 0.1.1
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- @altafusion/fugue-nuxt-ui@0.1.1
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Altafusion
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,47 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @altafusion/fugue-ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Nuxt layer for **generic** Vue UI primitives on Nuxt UI — part of the **Fugue** family (`@altafusion/fugue-storage`, `@altafusion/fugue-devtools`, …). Reusable across Nuxt apps; product-specific layout stays in app layers until promotion here is warranted.
|
|
4
|
+
|
|
5
|
+
## Stack
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
@altafusion/fugue-ui
|
|
9
|
+
extends → @altafusion/fugue-nuxt-ui unbranded Tailwind + @nuxt/ui + @nuxt/eslint
|
|
10
|
+
extends → @altafusion/nuxt-base
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Extend **`@altafusion/fugue-theme`** as a **sibling** when optional Fugue tokens are needed. **`@nuxt/eslint`** requires a direct extend of **`fugue-nuxt-ui`**, **`@altafusion/fugue-theme`**, or another layer that registers the module (see **`packages-platform/nuxt-base/modules.ts`**).
|
|
14
|
+
|
|
15
|
+
Portable brand helpers: **`@altafusion/fugue-ui/utils/brandTheme`**.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
export default defineNuxtConfig({
|
|
21
|
+
extends: ['@altafusion/fugue-theme', '@altafusion/fugue-ui'],
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Components under **`components/`** auto-import: **`AccentSectionCard`**, **`CopyToClipboard`**, **`TileSelector`** (+ **`TileSelectorMultiple`**), **`FileDropzone`**.
|
|
26
|
+
|
|
27
|
+
**`AccentSectionCard`** composes **`UCard`** (`title`, `description`, `variant`, `as`, `class`) with a left stripe: semantic **`color`** (`primary`); optional **`palette`** (composer hex — **`ACCENT_SECTION_CARD_VISUAL_STYLE_COLORS`**); optional **`accentColor`** (CSS color). Optional **`tooltip`** (TileHintTooltip). Modal-style **`close`** + **`closeIcon`**; **`@close`** when dismissed.
|
|
28
|
+
|
|
29
|
+
## Component naming
|
|
30
|
+
|
|
31
|
+
- **Generic primitives** — **`components/<Widget>.vue`** at layer root → **`<CopyToClipboard />`**. No `F*` prefix.
|
|
32
|
+
- **Widget families** — subfolder namespace: **`components/Forms/DateRange.vue`** → **`FormsDateRange`**.
|
|
33
|
+
- **Do not** use single-letter prefixes (**`U*`** is Nuxt UI only).
|
|
34
|
+
|
|
35
|
+
When promoting from an app, keep the same path under **`components/`** so auto-import names stay stable.
|
|
36
|
+
|
|
37
|
+
## VueUse
|
|
38
|
+
|
|
39
|
+
Direct **`@vueuse/core`** imports in this package. Do **not** add **`@vueuse/nuxt`** — prefer explicit imports for tree-shaking.
|
|
40
|
+
|
|
41
|
+
## Consumers
|
|
42
|
+
|
|
43
|
+
> **Local — do not copy-sync.** Repo wiring, ports, catalog keys, consuming apps, and docs-site links.
|
|
44
|
+
|
|
45
|
+
- **`@altafusion/shell`** extends fugue-ui transitively; **`ShellSiteHeader`** + **`useShellSiteHeader()`** wire **`FugueAppHeader`** (**`visualStyle`**: `default`, `landing-fixed`, `landing-static`). Override **`ShellSiteHeader`** only for extra slots (e.g. Studio edit).
|
|
46
|
+
- **`packages-consumer/fugue-content`**, **`templates/fugue-content-site`**.
|
|
47
|
+
- Docs: **[Fugue overview](../../apps/developer-docs/content/3.fugue/1.overview.md)** · **[Fugue UI](../../apps/developer-docs/content/3.fugue/2.fugue-ui.md)** · wizard: **[`@altafusion/fugue-workflow`](../fugue-workflow/README.md)**.
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { CardProps, IconProps } from '@nuxt/ui'
|
|
3
|
+
import type {
|
|
4
|
+
AccentSectionCardCloseConfig,
|
|
5
|
+
AccentSectionCardColor,
|
|
6
|
+
AccentSectionCardUi,
|
|
7
|
+
AccentSectionCardVisualStyle,
|
|
8
|
+
} from './accentSectionCard.shared'
|
|
9
|
+
import { nextTick } from 'vue'
|
|
10
|
+
import {
|
|
11
|
+
buildAccentSectionCardUCardUi,
|
|
12
|
+
mergeAccentSectionCardUi,
|
|
13
|
+
resolveAccentSectionCardAccent,
|
|
14
|
+
resolveAccentSectionCardClose,
|
|
15
|
+
} from './accentSectionCard.shared'
|
|
16
|
+
import TileHintTooltip from './TileHintTooltip.vue'
|
|
17
|
+
|
|
18
|
+
defineOptions({ inheritAttrs: false })
|
|
19
|
+
|
|
20
|
+
const props = withDefaults(defineProps<{
|
|
21
|
+
title: string
|
|
22
|
+
description?: string
|
|
23
|
+
/** @defaultValue 'outline' */
|
|
24
|
+
variant?: CardProps['variant']
|
|
25
|
+
/** Root element for {@link UCard}. */
|
|
26
|
+
as?: CardProps['as']
|
|
27
|
+
/** Leading icon (`UIcon` name). */
|
|
28
|
+
icon?: IconProps['name']
|
|
29
|
+
/** Hint copy — shows {@link TileHintTooltip} beside the title. */
|
|
30
|
+
tooltip?: string
|
|
31
|
+
/** Heading element for the title (defaults to `h2`). */
|
|
32
|
+
titleAs?: AccentSectionCardHeading
|
|
33
|
+
/**
|
|
34
|
+
* Left accent stripe semantic role (Nuxt UI color scale).
|
|
35
|
+
* Not {@link UCard} `variant`.
|
|
36
|
+
*/
|
|
37
|
+
color?: AccentSectionCardColor
|
|
38
|
+
/** Named composer palette key (hex stripe; see {@link ACCENT_SECTION_CARD_VISUAL_STYLE_COLORS}). */
|
|
39
|
+
palette?: AccentSectionCardVisualStyle
|
|
40
|
+
/** Any CSS color for the left stripe (overrides `palette` and `color`). */
|
|
41
|
+
accentColor?: string
|
|
42
|
+
disabled?: boolean
|
|
43
|
+
/**
|
|
44
|
+
* Header close control (Modal pattern). Hidden when falsy.
|
|
45
|
+
* @defaultValue false
|
|
46
|
+
*/
|
|
47
|
+
close?: boolean | Omit<AccentSectionCardCloseConfig, LinkPropsKeys>
|
|
48
|
+
/** Close button icon. @defaultValue `i-lucide-x` */
|
|
49
|
+
closeIcon?: IconProps['name']
|
|
50
|
+
ui?: AccentSectionCardUi
|
|
51
|
+
}>(), {
|
|
52
|
+
variant: 'outline',
|
|
53
|
+
titleAs: 'h2',
|
|
54
|
+
color: 'primary',
|
|
55
|
+
disabled: false,
|
|
56
|
+
closeIcon: 'i-lucide-x',
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
const emit = defineEmits<{
|
|
60
|
+
close: []
|
|
61
|
+
}>()
|
|
62
|
+
|
|
63
|
+
export type {
|
|
64
|
+
AccentSectionCardCloseConfig,
|
|
65
|
+
AccentSectionCardColor,
|
|
66
|
+
AccentSectionCardUi,
|
|
67
|
+
AccentSectionCardVisualStyle,
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
type LinkPropsKeys = 'to' | 'href' | 'target' | 'rel' | 'noRel' | 'external' | 'prefetch' | 'prefetchOn' | 'prefetchedClass' | 'noPrefetch' | 'trailingSlash' | 'replace' | 'ariaCurrentValue' | 'active' | 'activeClass' | 'exact' | 'exactQuery' | 'exactHash' | 'inactiveClass' | 'locale' | 'download' | 'ping' | 'referrerpolicy' | 'hreflang' | 'media'
|
|
71
|
+
|
|
72
|
+
type AccentSectionCardHeading = 'h2' | 'h3'
|
|
73
|
+
|
|
74
|
+
const attrs = useAttrs()
|
|
75
|
+
|
|
76
|
+
const shellRef = ref<HTMLElement | null>(null)
|
|
77
|
+
const closeButtonRef = ref<{ $el?: HTMLElement, focus?: () => void } | HTMLElement | null>(null)
|
|
78
|
+
|
|
79
|
+
function focusRefTarget(target: typeof closeButtonRef.value) {
|
|
80
|
+
if (!target)
|
|
81
|
+
return
|
|
82
|
+
if (target instanceof HTMLElement) {
|
|
83
|
+
target.focus()
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
if (typeof target.focus === 'function') {
|
|
87
|
+
target.focus()
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
if ('$el' in target && target.$el instanceof HTMLElement)
|
|
91
|
+
target.$el.focus()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const mergedUi = computed(() => mergeAccentSectionCardUi(props.ui))
|
|
95
|
+
|
|
96
|
+
const resolvedAccent = computed(() =>
|
|
97
|
+
resolveAccentSectionCardAccent({
|
|
98
|
+
accentColor: props.accentColor,
|
|
99
|
+
palette: props.palette,
|
|
100
|
+
color: props.color,
|
|
101
|
+
disabled: props.disabled,
|
|
102
|
+
}),
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
const cardUi = computed(() =>
|
|
106
|
+
buildAccentSectionCardUCardUi(mergedUi.value, resolvedAccent.value.borderClass, props.disabled),
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
const cardStyle = computed(() =>
|
|
110
|
+
resolvedAccent.value.mode === 'custom'
|
|
111
|
+
? resolvedAccent.value.style
|
|
112
|
+
: undefined,
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
const resolvedClose = computed(() => resolveAccentSectionCardClose(props.close))
|
|
116
|
+
|
|
117
|
+
watch(() => props.disabled, (disabled, wasDisabled) => {
|
|
118
|
+
if (disabled && !wasDisabled) {
|
|
119
|
+
const root = shellRef.value
|
|
120
|
+
const active = document.activeElement
|
|
121
|
+
if (root && active instanceof HTMLElement && root.contains(active)) {
|
|
122
|
+
nextTick(() => {
|
|
123
|
+
if (resolvedClose.value.show)
|
|
124
|
+
focusRefTarget(closeButtonRef.value)
|
|
125
|
+
else
|
|
126
|
+
root.focus()
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
const inertValue = computed(() => (props.disabled ? true : undefined))
|
|
133
|
+
|
|
134
|
+
function handleClose() {
|
|
135
|
+
emit('close')
|
|
136
|
+
}
|
|
137
|
+
</script>
|
|
138
|
+
|
|
139
|
+
<template>
|
|
140
|
+
<div
|
|
141
|
+
ref="shellRef"
|
|
142
|
+
v-bind="attrs"
|
|
143
|
+
tabindex="-1"
|
|
144
|
+
:class="[mergedUi.root, disabled && 'select-none']"
|
|
145
|
+
:aria-disabled="disabled || undefined"
|
|
146
|
+
>
|
|
147
|
+
<UCard
|
|
148
|
+
:as="as"
|
|
149
|
+
:variant="variant"
|
|
150
|
+
:description="resolvedClose.show || icon || tooltip || $slots.header ? undefined : description"
|
|
151
|
+
:ui="cardUi"
|
|
152
|
+
:style="cardStyle"
|
|
153
|
+
>
|
|
154
|
+
<template
|
|
155
|
+
v-if="!(resolvedClose.show || icon || tooltip || $slots.header)"
|
|
156
|
+
#title
|
|
157
|
+
>
|
|
158
|
+
<component
|
|
159
|
+
:is="titleAs"
|
|
160
|
+
:class="mergedUi.title"
|
|
161
|
+
>
|
|
162
|
+
{{ title }}
|
|
163
|
+
</component>
|
|
164
|
+
</template>
|
|
165
|
+
|
|
166
|
+
<template
|
|
167
|
+
v-if="resolvedClose.show || icon || tooltip || $slots.header"
|
|
168
|
+
#header
|
|
169
|
+
>
|
|
170
|
+
<div :class="mergedUi.headerSlot">
|
|
171
|
+
<div class="flex w-full min-w-0 items-center justify-between gap-3">
|
|
172
|
+
<div :class="mergedUi.titleRow">
|
|
173
|
+
<span
|
|
174
|
+
v-if="icon"
|
|
175
|
+
:class="mergedUi.icon"
|
|
176
|
+
>
|
|
177
|
+
<UIcon
|
|
178
|
+
:name="icon"
|
|
179
|
+
class="size-full"
|
|
180
|
+
aria-hidden="true"
|
|
181
|
+
/>
|
|
182
|
+
</span>
|
|
183
|
+
<div class="flex min-w-0 items-center gap-1">
|
|
184
|
+
<component
|
|
185
|
+
:is="titleAs"
|
|
186
|
+
:class="mergedUi.title"
|
|
187
|
+
>
|
|
188
|
+
{{ title }}
|
|
189
|
+
</component>
|
|
190
|
+
<TileHintTooltip
|
|
191
|
+
v-if="tooltip"
|
|
192
|
+
:text="tooltip"
|
|
193
|
+
:label="title"
|
|
194
|
+
/>
|
|
195
|
+
</div>
|
|
196
|
+
</div>
|
|
197
|
+
<UButton
|
|
198
|
+
v-if="resolvedClose.show"
|
|
199
|
+
ref="closeButtonRef"
|
|
200
|
+
v-bind="resolvedClose.buttonProps"
|
|
201
|
+
:class="[
|
|
202
|
+
mergedUi.closeButton,
|
|
203
|
+
disabled ? 'relative z-[11]' : undefined,
|
|
204
|
+
]"
|
|
205
|
+
@click="handleClose"
|
|
206
|
+
>
|
|
207
|
+
<UIcon
|
|
208
|
+
:name="closeIcon"
|
|
209
|
+
class="size-4"
|
|
210
|
+
aria-hidden="true"
|
|
211
|
+
/>
|
|
212
|
+
</UButton>
|
|
213
|
+
</div>
|
|
214
|
+
<p
|
|
215
|
+
v-if="description"
|
|
216
|
+
class="mt-1 text-sm text-muted"
|
|
217
|
+
>
|
|
218
|
+
{{ description }}
|
|
219
|
+
</p>
|
|
220
|
+
<div
|
|
221
|
+
v-if="$slots.header"
|
|
222
|
+
:inert="inertValue"
|
|
223
|
+
>
|
|
224
|
+
<slot name="header" />
|
|
225
|
+
</div>
|
|
226
|
+
</div>
|
|
227
|
+
</template>
|
|
228
|
+
|
|
229
|
+
<div :inert="inertValue">
|
|
230
|
+
<slot />
|
|
231
|
+
</div>
|
|
232
|
+
|
|
233
|
+
<template v-if="$slots.footer" #footer>
|
|
234
|
+
<slot name="footer" />
|
|
235
|
+
</template>
|
|
236
|
+
</UCard>
|
|
237
|
+
<div
|
|
238
|
+
v-if="disabled"
|
|
239
|
+
:class="mergedUi.overlay"
|
|
240
|
+
aria-hidden="true"
|
|
241
|
+
/>
|
|
242
|
+
</div>
|
|
243
|
+
</template>
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { HTMLAttributes } from 'vue'
|
|
3
|
+
import { useClipboard } from '@vueuse/core'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Copyable label — Nuxt UI port of `UI/src/components/content/CopyToClipboard.tsx`.
|
|
7
|
+
*
|
|
8
|
+
* Uses `useClipboard`, `UButton` (link), and `UBadge` (success).
|
|
9
|
+
* For icon-only / table actions, prefer `useClipboard()` + `useToast()` directly.
|
|
10
|
+
*
|
|
11
|
+
* @see https://ui.nuxt.com/docs/components/input#with-copy-button
|
|
12
|
+
*/
|
|
13
|
+
const {
|
|
14
|
+
content,
|
|
15
|
+
label,
|
|
16
|
+
class: className,
|
|
17
|
+
labelClass,
|
|
18
|
+
truncate = true,
|
|
19
|
+
reverseIcon = false,
|
|
20
|
+
nestInsideLink = false,
|
|
21
|
+
} = defineProps<{
|
|
22
|
+
content: string
|
|
23
|
+
label?: string
|
|
24
|
+
class?: HTMLAttributes['class']
|
|
25
|
+
labelClass?: HTMLAttributes['class']
|
|
26
|
+
truncate?: boolean
|
|
27
|
+
reverseIcon?: boolean
|
|
28
|
+
nestInsideLink?: boolean
|
|
29
|
+
}>()
|
|
30
|
+
|
|
31
|
+
const displayLabel = computed(() => (label ?? content).trim())
|
|
32
|
+
|
|
33
|
+
const { copy, copied } = useClipboard({ copiedDuring: 2000 })
|
|
34
|
+
|
|
35
|
+
const iconName = computed(() =>
|
|
36
|
+
copied.value ? 'i-lucide-copy-check' : 'i-lucide-copy',
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
function handleActivate(event: Event) {
|
|
40
|
+
event.preventDefault()
|
|
41
|
+
event.stopPropagation()
|
|
42
|
+
if (!content)
|
|
43
|
+
return
|
|
44
|
+
void copy(content)
|
|
45
|
+
}
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<template>
|
|
49
|
+
<UButton
|
|
50
|
+
:as="nestInsideLink ? 'span' : 'button'"
|
|
51
|
+
variant="link"
|
|
52
|
+
color="primary"
|
|
53
|
+
size="xs"
|
|
54
|
+
class="max-w-full min-w-0"
|
|
55
|
+
:class="className"
|
|
56
|
+
:ui="{ base: 'gap-1 justify-start p-0 h-auto min-h-0 font-normal' }"
|
|
57
|
+
@click="handleActivate"
|
|
58
|
+
>
|
|
59
|
+
<UIcon
|
|
60
|
+
v-if="reverseIcon"
|
|
61
|
+
:name="iconName"
|
|
62
|
+
class="size-4 shrink-0"
|
|
63
|
+
:class="copied ? 'text-success' : ''"
|
|
64
|
+
/>
|
|
65
|
+
|
|
66
|
+
<span
|
|
67
|
+
class="relative isolate min-w-0 flex-1 overflow-hidden text-left"
|
|
68
|
+
>
|
|
69
|
+
<span
|
|
70
|
+
class="relative z-0 block w-full min-w-0 transition-opacity duration-150"
|
|
71
|
+
:class="[
|
|
72
|
+
labelClass,
|
|
73
|
+
truncate ? 'truncate' : 'break-all',
|
|
74
|
+
copied ? 'text-muted/30 opacity-40' : '',
|
|
75
|
+
]"
|
|
76
|
+
>
|
|
77
|
+
{{ displayLabel }}
|
|
78
|
+
</span>
|
|
79
|
+
|
|
80
|
+
<span
|
|
81
|
+
v-if="copied"
|
|
82
|
+
class="pointer-events-none absolute inset-0 z-10 flex items-center"
|
|
83
|
+
>
|
|
84
|
+
<UBadge
|
|
85
|
+
color="success"
|
|
86
|
+
variant="soft"
|
|
87
|
+
size="xs"
|
|
88
|
+
label="Copied!"
|
|
89
|
+
class="shadow-sm"
|
|
90
|
+
/>
|
|
91
|
+
</span>
|
|
92
|
+
</span>
|
|
93
|
+
|
|
94
|
+
<UIcon
|
|
95
|
+
v-if="!reverseIcon"
|
|
96
|
+
:name="iconName"
|
|
97
|
+
class="size-4 shrink-0"
|
|
98
|
+
:class="copied ? 'text-success' : ''"
|
|
99
|
+
/>
|
|
100
|
+
|
|
101
|
+
<span class="sr-only" aria-live="polite">
|
|
102
|
+
{{ copied ? 'Copied to clipboard' : '' }}
|
|
103
|
+
</span>
|
|
104
|
+
</UButton>
|
|
105
|
+
</template>
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { HTMLAttributes } from 'vue'
|
|
3
|
+
import type { FileRejection } from './fileDropzone.shared'
|
|
4
|
+
import {
|
|
5
|
+
formatFileSize,
|
|
6
|
+
toAcceptAttribute,
|
|
7
|
+
validateFile,
|
|
8
|
+
} from './fileDropzone.shared'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Generic drag-and-drop file picker with extension and size constraints.
|
|
12
|
+
*
|
|
13
|
+
* Emits `reject` when a picked file fails validation and leaves the model as it was;
|
|
14
|
+
* the consumer owns both the error copy and whether the previous pick survives.
|
|
15
|
+
* `invalid` only controls the error border — no message is rendered here.
|
|
16
|
+
*/
|
|
17
|
+
const {
|
|
18
|
+
accept,
|
|
19
|
+
maxSize,
|
|
20
|
+
disabled = false,
|
|
21
|
+
busy = false,
|
|
22
|
+
invalid = false,
|
|
23
|
+
label = 'Drag and drop a file here, or click to browse',
|
|
24
|
+
hint,
|
|
25
|
+
class: className,
|
|
26
|
+
} = defineProps<{
|
|
27
|
+
/** File **extensions** only (`.zip`, `zip`) — not media types. See `FileConstraints`. */
|
|
28
|
+
accept?: string[]
|
|
29
|
+
maxSize?: number
|
|
30
|
+
disabled?: boolean
|
|
31
|
+
/** Work is in flight — the zone is inert and shows a spinner. */
|
|
32
|
+
busy?: boolean
|
|
33
|
+
/** Draw the error border. The consumer owns the message. */
|
|
34
|
+
invalid?: boolean
|
|
35
|
+
label?: string
|
|
36
|
+
hint?: string
|
|
37
|
+
/** Extra classes for the zone. Accepts any Vue class binding, like Nuxt UI's `class`. */
|
|
38
|
+
class?: HTMLAttributes['class']
|
|
39
|
+
}>()
|
|
40
|
+
|
|
41
|
+
const emit = defineEmits<{
|
|
42
|
+
reject: [rejection: FileRejection]
|
|
43
|
+
}>()
|
|
44
|
+
|
|
45
|
+
const model = defineModel<File | null>({ default: null })
|
|
46
|
+
|
|
47
|
+
const fileInputRef = ref<HTMLInputElement | null>(null)
|
|
48
|
+
const isDraggingOver = ref(false)
|
|
49
|
+
|
|
50
|
+
const isInert = computed(() => disabled || busy)
|
|
51
|
+
|
|
52
|
+
const zoneClass = computed(() => [
|
|
53
|
+
// The native input is `sr-only`, so keyboard focus has to be shown on the zone.
|
|
54
|
+
// A ring rather than a border keeps the invalid state visible while focused.
|
|
55
|
+
'relative rounded-lg border-2 border-dashed transition-colors focus-within:ring-2 focus-within:ring-inset focus-within:ring-primary',
|
|
56
|
+
isInert.value ? 'opacity-50' : 'hover:bg-elevated',
|
|
57
|
+
isDraggingOver.value && !isInert.value
|
|
58
|
+
? 'border-primary bg-elevated'
|
|
59
|
+
: invalid
|
|
60
|
+
? 'border-error'
|
|
61
|
+
: 'border-muted',
|
|
62
|
+
className,
|
|
63
|
+
])
|
|
64
|
+
|
|
65
|
+
const pickerClass = computed(() => [
|
|
66
|
+
'flex w-full flex-col items-center justify-center gap-2 p-8',
|
|
67
|
+
isInert.value ? 'cursor-not-allowed' : 'cursor-pointer',
|
|
68
|
+
])
|
|
69
|
+
|
|
70
|
+
function resetInput() {
|
|
71
|
+
if (fileInputRef.value)
|
|
72
|
+
fileInputRef.value.value = ''
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function handleFile(file: File | null) {
|
|
76
|
+
if (isInert.value)
|
|
77
|
+
return
|
|
78
|
+
|
|
79
|
+
if (!file) {
|
|
80
|
+
model.value = null
|
|
81
|
+
resetInput()
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const rejection = validateFile(file, { accept, maxSize })
|
|
86
|
+
if (rejection) {
|
|
87
|
+
// The model is left alone on purpose: a bad pick reports itself and the consumer
|
|
88
|
+
// decides whether the previous valid file survives it. Clearing here would also
|
|
89
|
+
// emit `update:model-value(null)` at a controlled parent that is already resetting.
|
|
90
|
+
emit('reject', rejection)
|
|
91
|
+
resetInput()
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
model.value = file
|
|
96
|
+
resetInput()
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function onInputChange(event: Event) {
|
|
100
|
+
const input = event.target as HTMLInputElement
|
|
101
|
+
const file = input.files?.[0] ?? null
|
|
102
|
+
handleFile(file)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// The default is cancelled even while inert: a drop the browser handles itself opens
|
|
106
|
+
// the file in the tab, replacing the app. `drop` only fires when `dragover` was
|
|
107
|
+
// cancelled, so both have to prevent it regardless of whether the file is accepted.
|
|
108
|
+
function onDragOver(event: DragEvent) {
|
|
109
|
+
event.preventDefault()
|
|
110
|
+
if (isInert.value)
|
|
111
|
+
return
|
|
112
|
+
isDraggingOver.value = true
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function onDragEnter(event: DragEvent) {
|
|
116
|
+
event.preventDefault()
|
|
117
|
+
if (isInert.value)
|
|
118
|
+
return
|
|
119
|
+
isDraggingOver.value = true
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function onDragLeave(event: DragEvent) {
|
|
123
|
+
// `dragleave` also fires when the pointer crosses onto a child, which would
|
|
124
|
+
// drop the highlight while the file is still over the zone.
|
|
125
|
+
const zone = event.currentTarget as HTMLElement | null
|
|
126
|
+
const enteredNode = event.relatedTarget as Node | null
|
|
127
|
+
if (zone && enteredNode && zone.contains(enteredNode))
|
|
128
|
+
return
|
|
129
|
+
|
|
130
|
+
isDraggingOver.value = false
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function onDrop(event: DragEvent) {
|
|
134
|
+
event.preventDefault()
|
|
135
|
+
if (isInert.value)
|
|
136
|
+
return
|
|
137
|
+
isDraggingOver.value = false
|
|
138
|
+
const file = event.dataTransfer?.files?.[0] ?? null
|
|
139
|
+
handleFile(file)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function clearSelection() {
|
|
143
|
+
handleFile(null)
|
|
144
|
+
// This button unmounts with the selection it clears, which would drop focus to the
|
|
145
|
+
// body. The input is always mounted, so hand focus back there — the zone's
|
|
146
|
+
// focus-within ring then shows where the user is.
|
|
147
|
+
fileInputRef.value?.focus()
|
|
148
|
+
}
|
|
149
|
+
</script>
|
|
150
|
+
|
|
151
|
+
<template>
|
|
152
|
+
<div
|
|
153
|
+
:class="zoneClass"
|
|
154
|
+
@dragover="onDragOver"
|
|
155
|
+
@dragenter="onDragEnter"
|
|
156
|
+
@dragleave="onDragLeave"
|
|
157
|
+
@drop="onDrop"
|
|
158
|
+
>
|
|
159
|
+
<label :class="pickerClass">
|
|
160
|
+
<input
|
|
161
|
+
ref="fileInputRef"
|
|
162
|
+
type="file"
|
|
163
|
+
class="sr-only"
|
|
164
|
+
:accept="toAcceptAttribute(accept)"
|
|
165
|
+
:disabled="isInert"
|
|
166
|
+
@change="onInputChange"
|
|
167
|
+
>
|
|
168
|
+
|
|
169
|
+
<template v-if="busy">
|
|
170
|
+
<UIcon
|
|
171
|
+
name="i-lucide-loader-circle"
|
|
172
|
+
class="size-8 animate-spin text-muted"
|
|
173
|
+
/>
|
|
174
|
+
<!-- Keep the pick on screen while work runs; the drag prompt would be stale. -->
|
|
175
|
+
<template v-if="model">
|
|
176
|
+
<span class="max-w-full truncate text-sm font-medium text-default">
|
|
177
|
+
{{ model.name }}
|
|
178
|
+
</span>
|
|
179
|
+
<span class="text-sm text-muted">
|
|
180
|
+
{{ formatFileSize(model.size) }}
|
|
181
|
+
</span>
|
|
182
|
+
</template>
|
|
183
|
+
<span
|
|
184
|
+
v-else
|
|
185
|
+
class="text-sm text-muted"
|
|
186
|
+
>{{ label }}</span>
|
|
187
|
+
</template>
|
|
188
|
+
|
|
189
|
+
<template v-else-if="model">
|
|
190
|
+
<span class="max-w-full truncate text-sm font-medium text-default">
|
|
191
|
+
{{ model.name }}
|
|
192
|
+
</span>
|
|
193
|
+
<span class="text-sm text-muted">
|
|
194
|
+
{{ formatFileSize(model.size) }}
|
|
195
|
+
</span>
|
|
196
|
+
</template>
|
|
197
|
+
|
|
198
|
+
<template v-else>
|
|
199
|
+
<UIcon
|
|
200
|
+
name="i-lucide-file"
|
|
201
|
+
class="size-8 text-muted"
|
|
202
|
+
/>
|
|
203
|
+
<span class="text-center text-sm text-default">{{ label }}</span>
|
|
204
|
+
<span
|
|
205
|
+
v-if="hint"
|
|
206
|
+
class="text-center text-xs text-muted"
|
|
207
|
+
>
|
|
208
|
+
{{ hint }}
|
|
209
|
+
</span>
|
|
210
|
+
</template>
|
|
211
|
+
</label>
|
|
212
|
+
|
|
213
|
+
<UButton
|
|
214
|
+
v-if="model && !isInert"
|
|
215
|
+
variant="ghost"
|
|
216
|
+
icon="i-lucide-x"
|
|
217
|
+
size="xs"
|
|
218
|
+
aria-label="Clear selection"
|
|
219
|
+
class="absolute right-2 top-2"
|
|
220
|
+
@click="clearSelection"
|
|
221
|
+
/>
|
|
222
|
+
</div>
|
|
223
|
+
</template>
|