@altafusion/fugue-ui 0.5.0 → 0.6.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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # @altafusion/fugue-ui
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Patch Changes
6
+
7
+ - e07bde1: Add `FloatingDock`: a bar fixed to the bottom of the page that the user drags by its grip (or moves with the arrow keys), that remembers its position, and whose button opens a panel above it. Set `storage-key` and `label`.
8
+
9
+ `FloatingDock` also takes `align` (which end of its box the bar sits at) and `margin` (distance from the page edges), so a dock can line up with something beside it.
10
+ - @altafusion/fugue-nuxt-ui@0.6.0
11
+
3
12
  ## 0.5.0
4
13
 
5
14
  ### Patch Changes
package/README.md CHANGED
@@ -22,10 +22,45 @@ export default defineNuxtConfig({
22
22
  })
23
23
  ```
24
24
 
25
- Components under **`components/`** auto-import: **`AccentSectionCard`**, **`CopyToClipboard`**, **`TileSelector`** (+ **`TileSelectorMultiple`**), **`FileDropzone`**.
25
+ Components under **`components/`** auto-import: **`AccentSectionCard`**, **`CopyToClipboard`**, **`TileSelector`** (+ **`TileSelectorMultiple`**), **`FileDropzone`**, **`FloatingDock`**.
26
26
 
27
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
28
 
29
+ ## FloatingDock
30
+
31
+ A small bar fixed to the bottom of the page. The user drags it left and right by its grip (or with the arrow keys, Home and End from the focused grip), it remembers its position in `localStorage`, and its button opens a panel above it. Needs only Nuxt UI and VueUse.
32
+
33
+ ```vue
34
+ <FloatingDock v-model:open="open" storage-key="my-app:dock" label="Tools">
35
+ <!-- the panel's content; leave it out and the button only toggles `open` -->
36
+ </FloatingDock>
37
+ ```
38
+
39
+ | Prop | |
40
+ |---|---|
41
+ | `storageKey` (required) | `localStorage` key the position is remembered under |
42
+ | `label` (required) | text on the open/close button; also names the grip and the panel |
43
+ | `defaultPercent` | where it starts, 0 (flush left) to 100 (flush right); default `50` |
44
+ | `align` | which end of the dock's box the bar sits at: `start`, `center` (default) or `end`. With `end` and `defaultPercent` `100` the bar's right end meets the page margin |
45
+ | `margin` | distance in px from each page edge at 0 and 100 percent; default `8` |
46
+ | `bottomClass` | Tailwind class for the distance from the bottom edge; default `bottom-20`. Pass a literal class that exists in your app's source, such as `bottom-4` |
47
+ | `v-model:open` | whether the panel is showing (or, with no slot, what the button toggles) |
48
+
49
+ Pieces: `components/FloatingDock.vue`, `composables/useDraggableDock.ts` (VueUse `useDraggable` turned into one saved percentage, plus the keys), and `lib/floating-dock-position.ts` (pure position math, unit tested).
50
+
51
+ Design choices worth keeping:
52
+
53
+ - **One percentage** places the dock (CSS `left` plus `translateX`), so nothing is measured and the first paint is correct.
54
+ - **Only the grip drags.** The label button only toggles the panel. Handlers sit on a plain element around the grip button because forwarding pointer events through `UButton` was unreliable.
55
+ - **One fixed width** (`w-56`) open or closed; the bar is centred in it and the panel is a separate box above it.
56
+ - **Teleported to `body`**, so no transformed ancestor becomes the fixed reference.
57
+
58
+ ### Nuxt Studio moves fixed elements
59
+
60
+ Nuxt Studio (`nuxt-studio`, `runtime/utils/sidebar.js`, `adjustFixedElements`) sets the inline `left` of **every `position: fixed` element on the page** to its sidebar's width, or to nothing when the sidebar is collapsed, when it activates and each time its sidebar opens or closes. A dock placed with its own inline `left` was thrown off the page on load (`left` cleared, so `translateX(-50%)` pushed it half off-screen). So the dock sits in a fixed wrapper (`inset-0`, from a class so clearing the inline style leaves it alone) and is only `absolute` inside it. Studio shifts the wrapper, which also keeps the dock beside its sidebar, and the dock's percentage is measured in the wrapper (the `area` argument). Use `right`, `top` or `bottom` for any other fixed element; Studio only touches `left`.
61
+
62
+ Not done yet: docking to other edges, a minimized nub, auto-hide, touch checks on a phone. The position math follows the draggable control in Nuxt DevTools (`@devframes/hub`, MIT).
63
+
29
64
  ## Component naming
30
65
 
31
66
  - **Generic primitives** — **`components/<Widget>.vue`** at layer root → **`<CopyToClipboard />`**. No `F*` prefix.
@@ -0,0 +1,104 @@
1
+ <script setup lang="ts">
2
+ defineOptions({ name: 'FloatingDock' })
3
+
4
+ /**
5
+ * A small bar fixed to the bottom of the page that the user drags left and right by its grip (or moves with the arrow keys
6
+ * from the grip). It remembers where it was left. The label button opens and closes the panel, a separate rounded box just
7
+ * above the bar; the default slot is the panel's content. Leave the slot out and the box does not render: the button then only
8
+ * toggles `open`, for a dock that switches something else (a drawer, say). The bar keeps its size and place when the panel opens (the dock
9
+ * has one fixed width and the bar sits centred in it). Needs only Nuxt UI and VueUse. `storageKey` and `label` are
10
+ * required so each dock keeps its own remembered position and names its own button.
11
+ */
12
+ const {
13
+ storageKey,
14
+ label,
15
+ defaultPercent = 50,
16
+ bottomClass = 'bottom-20',
17
+ align = 'center',
18
+ margin = 8,
19
+ } = defineProps<{
20
+ /** localStorage key the bar's position is remembered under. */
21
+ storageKey: string
22
+ /** Text on the open and close button. */
23
+ label: string
24
+ /** Where the bar starts, as a percentage (0 is flush left, 100 flush right). */
25
+ defaultPercent?: number
26
+ /** Tailwind class for the distance from the bottom edge. It must be visible to the app's Tailwind (a literal class in its source). */
27
+ bottomClass?: string
28
+ /** Which end of the dock's fixed-width box the bar sits at. With `end` and `defaultPercent` 100 the bar's right end meets the page margin. */
29
+ align?: 'start' | 'center' | 'end'
30
+ /** Distance in px from each page edge at the extremes (0 and 100 percent). */
31
+ margin?: number
32
+ }>()
33
+
34
+ const open = defineModel<boolean>('open', { default: false })
35
+
36
+ const dock = useTemplateRef<HTMLElement>('dock')
37
+ const area = useTemplateRef<HTMLElement>('area')
38
+ const grip = useTemplateRef<HTMLElement>('grip')
39
+ const { dragging, dockStyle, onKeydown } = useDraggableDock(dock, grip, area, { storageKey, defaultPercent, margin })
40
+ </script>
41
+
42
+ <template>
43
+ <!-- In the body, so no transformed ancestor (a layout shell, a page transition) can become the "fixed" reference. -->
44
+ <Teleport to="body">
45
+ <!--
46
+ The dock sits in a fixed wrapper that covers the page, and is itself only absolute. Nuxt Studio rewrites the inline `left`
47
+ of every `position: fixed` element on the page (to the sidebar's width, or to nothing) whenever it activates or its
48
+ sidebar opens or closes, which wiped the dock's own `left` and threw it off the page on load. The wrapper takes that
49
+ rewrite instead (its `left` then also keeps the dock beside Studio's sidebar), and the dock's percentage is measured in it.
50
+ -->
51
+ <div
52
+ ref="area"
53
+ class="pointer-events-none fixed inset-0 z-40"
54
+ >
55
+ <div
56
+ ref="dock"
57
+ class="pointer-events-none absolute flex w-56 flex-col gap-0.5"
58
+ :class="[bottomClass, { 'select-none': dragging }]"
59
+ :style="dockStyle"
60
+ >
61
+ <div
62
+ v-if="open && $slots.default"
63
+ class="pointer-events-auto rounded-xl border border-primary/40 bg-default px-4 py-3 shadow-lg"
64
+ role="group"
65
+ :aria-label="label"
66
+ >
67
+ <slot />
68
+ </div>
69
+ <div
70
+ class="pointer-events-auto flex w-fit items-center rounded-full border border-primary/40 bg-default p-0.5 shadow-lg"
71
+ :class="{ 'self-start': align === 'start', 'self-center': align === 'center', 'self-end': align === 'end' }"
72
+ >
73
+ <!-- The drag handle is a plain element: pointer events bubble up to it from the button, and no component has to forward them. -->
74
+ <div
75
+ ref="grip"
76
+ class="touch-none rounded-full"
77
+ :class="dragging ? 'cursor-grabbing' : 'cursor-grab'"
78
+ >
79
+ <UButton
80
+ icon="i-lucide-grip-vertical"
81
+ :aria-label="`Move ${label}`"
82
+ title="Drag, or use the arrow keys"
83
+ color="neutral"
84
+ variant="ghost"
85
+ size="xs"
86
+ class="rounded-full **:cursor-[inherit] cursor-[inherit]"
87
+ @keydown="onKeydown"
88
+ />
89
+ </div>
90
+ <UButton
91
+ :label
92
+ :aria-label="open ? `Close ${label}` : `Open ${label}`"
93
+ :aria-expanded="open"
94
+ color="neutral"
95
+ variant="ghost"
96
+ size="xs"
97
+ class="rounded-full"
98
+ @click="open = !open"
99
+ />
100
+ </div>
101
+ </div>
102
+ </div>
103
+ </Teleport>
104
+ </template>
@@ -0,0 +1,68 @@
1
+ import type { Ref } from 'vue'
2
+ import { useDraggable, useLocalStorage } from '@vueuse/core'
3
+ import { computed } from 'vue'
4
+ import { clampPercent, dockPlacement, leftEdgeToPercent } from '../lib/floating-dock-position'
5
+
6
+ /** Arrow keys move the bar by this many percent of the room it has; Shift makes it five times that. */
7
+ const KEY_STEP_PERCENT = 4
8
+
9
+ /**
10
+ * Drag a bar left and right along the bottom of the viewport, remembered in the browser under `storageKey`. `el` is the bar
11
+ * and `handle` the part that grabs it (the grip). `area` is the box the bar moves in. VueUse's `useDraggable` does the pointer work (press on the handle, follow
12
+ * the pointer on `window`, stop on release); this turns its pixel position into one percentage, 0 flush left to 100 flush
13
+ * right, so the position holds at any viewport width. `onKeydown` moves it with the arrow keys from a focused grip. The bar is
14
+ * placed with `left` plus `translateX` in CSS, so nothing is measured and the first paint is already right.
15
+ */
16
+ export function useDraggableDock(
17
+ el: Ref<HTMLElement | null | undefined>,
18
+ handle: Ref<HTMLElement | null | undefined>,
19
+ area: Ref<HTMLElement | null | undefined>,
20
+ options: { storageKey: string, defaultPercent?: number, margin?: number },
21
+ ) {
22
+ const { storageKey, defaultPercent = 50, margin = 8 } = options
23
+ const percent = useLocalStorage(storageKey, defaultPercent, { initOnMounted: true })
24
+
25
+ // A damaged or hand-edited saved value must not move the bar off the page: read it through `clampPercent`.
26
+ const current = computed(() => clampPercent(percent.value, defaultPercent))
27
+ const dockStyle = computed(() => dockPlacement(current.value, margin))
28
+
29
+ const { isDragging: dragging } = useDraggable(el, {
30
+ handle,
31
+ axis: 'x',
32
+ // Cancelling the press keeps the page from starting a text selection or a native drag under the pointer.
33
+ preventDefault: true,
34
+ // `x` is the bar's left edge in viewport pixels; the percentage is measured inside `area`, the box the bar moves in.
35
+ onMove: ({ x }) => {
36
+ const box = area.value?.getBoundingClientRect()
37
+ if (!box || !el.value)
38
+ return
39
+ percent.value = leftEdgeToPercent({
40
+ leftEdgePx: x - box.left,
41
+ dockWidth: el.value.getBoundingClientRect().width,
42
+ viewportWidth: box.width,
43
+ margin,
44
+ })
45
+ },
46
+ })
47
+
48
+ function onKeydown(event: KeyboardEvent) {
49
+ const step = KEY_STEP_PERCENT * (event.shiftKey ? 5 : 1)
50
+ const next = {
51
+ ArrowLeft: current.value - step,
52
+ ArrowRight: current.value + step,
53
+ Home: 0,
54
+ End: 100,
55
+ }[event.key]
56
+ if (next === undefined)
57
+ return
58
+ event.preventDefault()
59
+ percent.value = clampPercent(next)
60
+ }
61
+
62
+ return {
63
+ percent: current,
64
+ dragging,
65
+ dockStyle,
66
+ onKeydown,
67
+ }
68
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Pure position math for the Floating Dock. No Vue, no Nuxt.
3
+ * The snap to centre is adapted from `dock-layout.ts` in `devframes/devframe` (MIT).
4
+ *
5
+ * The dock's position is one number, `percent` (0 to 100): 0 is flush left, 100 is flush right, 50 is centred, whatever the
6
+ * bar's width. The bar is placed with CSS only (`left` of `percent` plus a matching `translateX`), so nothing is measured.
7
+ */
8
+
9
+ /** A percentage within this distance of the middle snaps to 50. */
10
+ export const CENTER_SNAP_PERCENT = 2
11
+
12
+ /** Snap a 0 to 100 percentage to the middle of the viewport when it is close to it. */
13
+ export function snapToCenter(percent: number, snap = CENTER_SNAP_PERCENT): number {
14
+ return Math.abs(percent - 50) < snap
15
+ ? 50
16
+ : percent
17
+ }
18
+
19
+ /** A usable percentage: `value` limited to 0 to 100, or `fallback` when it is not a finite number (a damaged saved value). */
20
+ export function clampPercent(value: unknown, fallback = 50): number {
21
+ const number = typeof value === 'number'
22
+ ? value
23
+ : Number.NaN
24
+ if (!Number.isFinite(number))
25
+ return fallback
26
+ return Math.min(Math.max(number, 0), 100)
27
+ }
28
+
29
+ /** The CSS `left` and `transform` that place a bar at `percent`, `margin` px from each edge at the extremes. */
30
+ export function dockPlacement(percent: number, margin = 8): { left: string, transform: string } {
31
+ return {
32
+ left: `calc(${margin}px + (100% - ${margin * 2}px) * ${percent / 100})`,
33
+ transform: `translateX(-${percent}%)`,
34
+ }
35
+ }
36
+
37
+ /**
38
+ * The percentage that puts the bar's left edge at `leftEdgePx`, the inverse of `dockPlacement`. Clamped to 0 to 100 and
39
+ * snapped to the middle. A bar as wide as the room it has stays at 50.
40
+ */
41
+ export function leftEdgeToPercent(params: {
42
+ leftEdgePx: number
43
+ dockWidth: number
44
+ viewportWidth: number
45
+ margin?: number
46
+ }): number {
47
+ const { leftEdgePx, dockWidth, viewportWidth, margin = 8 } = params
48
+ const room = viewportWidth - margin * 2 - dockWidth
49
+ if (room <= 0)
50
+ return 50
51
+ const percent = Math.min(Math.max((leftEdgePx - margin) / room * 100, 0), 100)
52
+ return snapToCenter(percent)
53
+ }
package/nuxt.config.ts CHANGED
@@ -4,9 +4,24 @@
4
4
  * Generic Vue UI primitives on Nuxt UI. Altafusion FugueAppHeader* variants stay in `./components`.
5
5
  */
6
6
 
7
+ import { resolve } from 'node:path'
8
+
7
9
  export default defineNuxtConfig({
8
10
  extends: ['@altafusion/fugue-nuxt-ui'],
9
11
 
12
+ /**
13
+ * The layer root is type-checked as a whole by every app that extends it. The playground's own `nuxt.config.ts` is a config
14
+ * file (`defineNuxtConfig` is not a global in those apps), so it is left out. List any further playground file that relies
15
+ * on a layer the other apps do not extend.
16
+ */
17
+ typescript: {
18
+ tsConfig: {
19
+ exclude: [
20
+ resolve(__dirname, 'playground/nuxt.config.ts'),
21
+ ],
22
+ },
23
+ },
24
+
10
25
  components: [
11
26
  {
12
27
  path: './components',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@altafusion/fugue-ui",
3
3
  "type": "module",
4
- "version": "0.5.0",
4
+ "version": "0.6.0",
5
5
  "description": "Generic Vue UI primitives on Nuxt UI — reusable across Altafusion apps",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/altafusion/fugue/tree/main/packages-fugue/fugue-ui#readme",
@@ -27,15 +27,15 @@
27
27
  "vue": "^3.5.0"
28
28
  },
29
29
  "dependencies": {
30
- "@altafusion/fugue-nuxt-ui": "0.5.0",
30
+ "@altafusion/fugue-nuxt-ui": "0.6.0",
31
31
  "@vueuse/core": "^14.4.0",
32
32
  "tailwind-merge": "^3.7.1"
33
33
  },
34
34
  "devDependencies": {
35
- "@altafusion/eslint-config": "0.5.0",
36
- "@altafusion/nuxt-base": "0.5.0",
35
+ "@altafusion/eslint-config": "0.6.0",
36
+ "@altafusion/nuxt-base": "0.6.0",
37
37
  "@nuxt/ui": "^4.13.1",
38
- "@types/node": "^26.6.10",
38
+ "@types/node": "^26.6.11",
39
39
  "eslint": "^10.15.0",
40
40
  "nuxt": "^4.7.0",
41
41
  "typescript": "^6.0.3",
@@ -47,10 +47,12 @@
47
47
  "!**/.nuxt",
48
48
  "!**/.output",
49
49
  "!**/.data",
50
+ "!playground",
50
51
  "!**/coverage",
51
52
  "!**/node_modules"
52
53
  ],
53
54
  "scripts": {
55
+ "dev": "pnpm --filter @altafusion/fugue-ui-playground dev",
54
56
  "clean": "rm -rf .output .nuxt node_modules/.cache dist",
55
57
  "lint": "eslint .",
56
58
  "lint:fix": "eslint . --fix"