@octabits-io/nuxt-ui-kit 0.2.1 → 0.3.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.
@@ -0,0 +1,110 @@
1
+ <script setup lang="ts">
2
+ // Shipped as source: the consumer's Vite compiles this SFC. All imports are
3
+ // explicit — no reliance on the consumer's auto-import configuration.
4
+ // i18n key contract: pageChrome.back (+ PageActionMenu/PageUtilityActions keys).
5
+ import { computed } from 'vue'
6
+ import { useI18n } from 'vue-i18n'
7
+ import { useRouter, type RouteLocationRaw } from 'vue-router'
8
+ import UButton from '@nuxt/ui/components/Button.vue'
9
+ import USkeleton from '@nuxt/ui/components/Skeleton.vue'
10
+ import type { DropdownMenuItem } from '@nuxt/ui'
11
+ import PageActionMenu from './PageActionMenu.vue'
12
+ import PageUtilityActions from './PageUtilityActions.vue'
13
+
14
+ /**
15
+ * Standard page header.
16
+ *
17
+ * Conventions enforced by this component and its siblings:
18
+ * - Max 3 neutral icon buttons inline in `#actions`; more go in `overflowItems`.
19
+ * - Destructive actions are ALWAYS placed inside the overflow menu, never inline.
20
+ * - Header height, spacing, and tooltip behavior are normalized via `PageAction`.
21
+ * - Utility triggers (Help, AI history, …) live in `#utility` (default =
22
+ * `PageUtilityActions`) and render as LABELED buttons, not icon-only.
23
+ */
24
+ const props = withDefaults(defineProps<{
25
+ title?: string
26
+ subtitle?: string
27
+ /** Show a leading back button. `true` uses router.back(); pass `{ to }` to navigate. */
28
+ back?: boolean | { to: RouteLocationRaw }
29
+ /** Show skeleton title while loading. */
30
+ loading?: boolean
31
+ /**
32
+ * `default` = full-width top-of-page header with padding.
33
+ * `compact` = sits inside a detail panel / sidebar; smaller title + thinner divider.
34
+ * `flush` = no padding/border (caller wraps it).
35
+ */
36
+ density?: 'default' | 'compact' | 'flush'
37
+ /** When false, the default utility cluster is hidden. */
38
+ utility?: boolean
39
+ /** Optional grouped overflow items. Alternative to using the #overflow slot. */
40
+ overflowItems?: DropdownMenuItem[][]
41
+ }>(), {
42
+ back: false,
43
+ loading: false,
44
+ density: 'default',
45
+ utility: true,
46
+ overflowItems: () => [],
47
+ })
48
+
49
+ const { t } = useI18n()
50
+ const router = useRouter()
51
+
52
+ function onBack() {
53
+ if (typeof props.back === 'object' && props.back && 'to' in props.back) {
54
+ router.push(props.back.to)
55
+ return
56
+ }
57
+ router.back()
58
+ }
59
+
60
+ const wrapperClass = computed(() => {
61
+ switch (props.density) {
62
+ case 'compact':
63
+ return 'flex items-center gap-2 flex-wrap border-b border-default px-6 py-4'
64
+ case 'flush':
65
+ return 'flex items-center gap-2 flex-wrap'
66
+ case 'default':
67
+ default:
68
+ return 'flex items-center gap-2 flex-wrap'
69
+ }
70
+ })
71
+
72
+ const titleClass = computed(() => props.density === 'compact' ? 'font-display text-lg font-semibold tracking-tight' : 'font-display text-2xl font-semibold tracking-tight')
73
+ </script>
74
+
75
+ <template>
76
+ <div :class="wrapperClass">
77
+ <UButton
78
+ v-if="back"
79
+ icon="i-lucide-arrow-left"
80
+ color="neutral"
81
+ variant="ghost"
82
+ size="sm"
83
+ :aria-label="t('pageChrome.back')"
84
+ @click="onBack"
85
+ />
86
+
87
+ <div class="min-w-0">
88
+ <slot name="title">
89
+ <USkeleton v-if="loading" class="h-7 w-40" />
90
+ <h1 v-else-if="title" :class="titleClass">{{ title }}</h1>
91
+ </slot>
92
+ <p v-if="subtitle && !loading" class="text-sm text-muted mt-1">{{ subtitle }}</p>
93
+ </div>
94
+
95
+ <div v-if="$slots.badges" class="flex items-center gap-2">
96
+ <slot name="badges" />
97
+ </div>
98
+
99
+ <div class="ml-auto flex items-center gap-1">
100
+ <slot name="actions" />
101
+ <PageActionMenu
102
+ v-if="overflowItems.length"
103
+ :items="overflowItems"
104
+ />
105
+ <slot name="utility">
106
+ <PageUtilityActions v-if="utility" />
107
+ </slot>
108
+ </div>
109
+ </div>
110
+ </template>
@@ -0,0 +1,31 @@
1
+ <script setup lang="ts">
2
+ // Shipped as source: the consumer's Vite compiles this SFC. All imports are
3
+ // explicit — no reliance on the consumer's auto-import configuration.
4
+ // i18n key contract: pageChrome.help.
5
+ // Utility triggers stay LABELED buttons (not icon-only) by convention.
6
+ import { computed, inject } from 'vue'
7
+ import { useI18n } from 'vue-i18n'
8
+ import USeparator from '@nuxt/ui/components/Separator.vue'
9
+ import UButton from '@nuxt/ui/components/Button.vue'
10
+ import { HELP_PANEL_KEY } from '@octabits-io/nuxt-ui-kit'
11
+
12
+ const { t } = useI18n()
13
+ const helpPanel = inject(HELP_PANEL_KEY, null)
14
+
15
+ const showHelp = computed(() => Boolean(helpPanel?.hasActions.value))
16
+ </script>
17
+
18
+ <template>
19
+ <div v-if="showHelp" class="flex items-center gap-1">
20
+ <USeparator orientation="vertical" class="h-5 mx-1" />
21
+ <UButton
22
+ v-if="helpPanel"
23
+ icon="i-lucide-circle-help"
24
+ :label="t('pageChrome.help')"
25
+ size="sm"
26
+ color="neutral"
27
+ :variant="helpPanel.isOpen.value ? 'soft' : 'ghost'"
28
+ @click="helpPanel.toggle()"
29
+ />
30
+ </div>
31
+ </template>
@@ -0,0 +1,65 @@
1
+ <script setup lang="ts">
2
+ // Shipped as source: the consumer's Vite compiles this SFC. All imports are
3
+ // explicit — no reliance on the consumer's auto-import configuration.
4
+ // i18n key contract: localeField.translationStatus.complete / .missing.
5
+ // Requires provideLocaleFieldContext() near the app root.
6
+ import { computed, toValue } from 'vue'
7
+ import { useI18n } from 'vue-i18n'
8
+ import UTooltip from '@nuxt/ui/components/Tooltip.vue'
9
+ import UBadge from '@nuxt/ui/components/Badge.vue'
10
+ import UIcon from '@nuxt/ui/components/Icon.vue'
11
+ import {
12
+ useLocaleFieldContext,
13
+ type TranslationStatus,
14
+ } from '@octabits-io/nuxt-ui-kit/locale'
15
+
16
+ /**
17
+ * Translation-completeness badge for list rows and detail headers.
18
+ *
19
+ * - Hidden for single-locale content (nothing to translate into).
20
+ * - Green check when every in-use translatable leaf covers all supported
21
+ * locales (register variants inherit their base).
22
+ * - Orange with the total missing-leaf count otherwise; the tooltip breaks
23
+ * the count down per locale.
24
+ */
25
+ const props = defineProps<{
26
+ status: TranslationStatus | undefined
27
+ }>()
28
+
29
+ const { t } = useI18n()
30
+ const { locales } = useLocaleFieldContext().useSource()
31
+
32
+ const visible = computed(() => !!props.status && toValue(locales).length > 1)
33
+
34
+ const totalMissing = computed(() =>
35
+ Object.values(props.status?.missing ?? {}).reduce((sum, n) => sum + n, 0),
36
+ )
37
+
38
+ const tooltip = computed(() => {
39
+ if (!props.status) return ''
40
+ if (props.status.complete) return t('localeField.translationStatus.complete')
41
+ const perLocale = Object.entries(props.status.missing)
42
+ .map(([locale, n]) => `${locale.toUpperCase()}: ${n}`)
43
+ .join(', ')
44
+ return t('localeField.translationStatus.missing', { details: perLocale })
45
+ })
46
+ </script>
47
+
48
+ <template>
49
+ <UTooltip v-if="visible" :text="tooltip">
50
+ <UBadge
51
+ v-if="!status!.complete"
52
+ color="warning"
53
+ variant="subtle"
54
+ size="xs"
55
+ icon="i-lucide-languages"
56
+ :label="String(totalMissing)"
57
+ />
58
+ <UIcon
59
+ v-else
60
+ name="i-lucide-check-circle-2"
61
+ class="size-4 text-success"
62
+ :aria-label="t('localeField.translationStatus.complete')"
63
+ />
64
+ </UTooltip>
65
+ </template>