@happydesigns/ui 0.13.5

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.
Files changed (45) hide show
  1. package/README.md +94 -0
  2. package/app/app.config.ts +169 -0
  3. package/app/assets/css/main.css +14 -0
  4. package/app/components/article/ArticleGrid.vue +158 -0
  5. package/app/components/article/ArticleGridDate.vue +16 -0
  6. package/app/components/article/ArticleHeaderBody.vue +20 -0
  7. package/app/components/article/ArticleHeadlineMeta.vue +26 -0
  8. package/app/components/article/ArticleList.vue +95 -0
  9. package/app/components/article/ArticlePage.vue +16 -0
  10. package/app/components/content/Carousel.vue +11 -0
  11. package/app/components/content/Snippet.vue +31 -0
  12. package/app/components/footer/FooterButtons.vue +13 -0
  13. package/app/components/footer/FooterColumnHeading.vue +5 -0
  14. package/app/components/footer/FooterColumns.vue +105 -0
  15. package/app/components/footer/FooterCopyright.vue +29 -0
  16. package/app/components/traits/Authors.vue +20 -0
  17. package/app/components/traits/BackButton.vue +26 -0
  18. package/app/components/traits/Category.vue +9 -0
  19. package/app/components/traits/CopyButton.vue +39 -0
  20. package/app/components/traits/Dates.vue +20 -0
  21. package/app/components/traits/Links.vue +17 -0
  22. package/app/components/traits/Location.vue +20 -0
  23. package/app/components/traits/Separator.vue +26 -0
  24. package/app/components/traits/SeparatorButtons.vue +56 -0
  25. package/app/components/traits/Surround.vue +60 -0
  26. package/app/components/traits/Toc.vue +16 -0
  27. package/app/composables/useArticleList.ts +156 -0
  28. package/app/composables/useCategoryBadge.ts +27 -0
  29. package/app/composables/useClipboard.ts +26 -0
  30. package/app/composables/usePageContent.ts +31 -0
  31. package/app/composables/usePageSeo.ts +30 -0
  32. package/app/layouts/article.vue +128 -0
  33. package/app/layouts/content.vue +67 -0
  34. package/app/layouts/default.vue +12 -0
  35. package/app/types/config.ts +6 -0
  36. package/app/utils/formatDate.ts +26 -0
  37. package/app/utils/formatDateTime.ts +28 -0
  38. package/app/utils/resolvePageHeader.ts +16 -0
  39. package/app/utils/resolveUsers.ts +16 -0
  40. package/content.config.ts +6 -0
  41. package/nuxt.config.ts +80 -0
  42. package/package.json +60 -0
  43. package/schemas/collections.ts +46 -0
  44. package/schemas/index.ts +2 -0
  45. package/schemas/traits.ts +90 -0
@@ -0,0 +1,31 @@
1
+ import type { Collections } from '@nuxt/content'
2
+ import type { AsyncData } from 'nuxt/app'
3
+ import type { MaybeRefOrGetter } from 'vue'
4
+ import { computed, toValue } from 'vue'
5
+
6
+ interface UsePageContentOptions<C extends keyof Collections = 'page'> {
7
+ path?: MaybeRefOrGetter<string | undefined>
8
+ collection?: MaybeRefOrGetter<C>
9
+ }
10
+
11
+ /**
12
+ * Composable to fetch content from a Nuxt Content collection.
13
+ *
14
+ * @param options - Configuration options for fetching content
15
+ * @param options.path - Optional path to fetch. Defaults to current route path.
16
+ * @param options.collection - Optional collection to fetch from. Defaults to 'page'.
17
+ */
18
+ export function usePageContent<C extends keyof Collections = 'page', B = object>(
19
+ { path, collection }: UsePageContentOptions<C> = {},
20
+ ) {
21
+ const route = useRoute()
22
+ const resolvedPath = computed(() => toValue(path) ?? route.path)
23
+ const resolvedCollection = computed(() => (toValue(collection) ?? ('page' as C)) as C)
24
+ const key = computed(() => `${String(resolvedCollection.value)}:${resolvedPath.value}`)
25
+
26
+ const handler = () => queryCollection(resolvedCollection.value as keyof Collections).path(resolvedPath.value).first()
27
+
28
+ return useAsyncData(key, handler, {
29
+ watch: [resolvedPath, resolvedCollection],
30
+ }) as unknown as AsyncData<(Collections[C] & B) | null, Error | null>
31
+ }
@@ -0,0 +1,30 @@
1
+ import { watchEffect } from 'vue'
2
+
3
+ interface SeoRelevantPageData {
4
+ seo?: {
5
+ title?: string
6
+ description?: string
7
+ ogTitle?: string
8
+ ogDescription?: string
9
+ }
10
+ title?: string
11
+ description?: string
12
+ }
13
+
14
+ export function usePageSeo(page: Ref<SeoRelevantPageData | null | undefined>) {
15
+ watchEffect(() => {
16
+ if (page.value) {
17
+ const title = page.value.seo?.title || page.value.title
18
+ const description = page.value.seo?.description || page.value.description
19
+ const ogTitle = page.value.seo?.ogTitle || title
20
+ const ogDescription = page.value.seo?.ogDescription || description
21
+
22
+ useSeoMeta({
23
+ title,
24
+ ogTitle,
25
+ description,
26
+ ogDescription,
27
+ })
28
+ }
29
+ })
30
+ }
@@ -0,0 +1,128 @@
1
+ <script setup lang="ts" generic="C extends keyof PageCollections & ('article' | 'event') = 'article'">
2
+ import type { PageCollections } from '@nuxt/content'
3
+
4
+ const {
5
+ path,
6
+ collection = 'article' as C,
7
+ } = defineProps<{
8
+ path?: string
9
+ collection?: C
10
+ }>()
11
+
12
+ const route = useRoute()
13
+
14
+ const { data: page } = await usePageContent<C>({
15
+ path: () => path,
16
+ collection: () => collection,
17
+ })
18
+
19
+ const { config, has } = useVariant(collection)
20
+ const hasHeader = has('header')
21
+ const hasBackButton = has('backButton')
22
+ const hasCopyButton = has('copyButton')
23
+ const hasSeparator = has('separator')
24
+ const hasSurround = has('surround')
25
+ const hasToc = has('toc')
26
+
27
+ if (!page.value) {
28
+ throw createError({
29
+ statusCode: 404,
30
+ statusMessage: `${collection} ${path || route.path} not found`,
31
+ fatal: true,
32
+ })
33
+ }
34
+
35
+ usePageSeo(page)
36
+
37
+ const header = computed(() => resolvePageHeader(page.value))
38
+
39
+ const breadcrumbsBase = computed(() => config.value.breadcrumbs ?? [])
40
+
41
+ const breadcrumbItems = computed(() => {
42
+ return [
43
+ ...breadcrumbsBase.value,
44
+ { label: page.value?.title, to: page.value?.path },
45
+ ]
46
+ })
47
+
48
+ const backLink = computed(() => {
49
+ const lastBreadcrumb = breadcrumbsBase.value.at(-1)
50
+
51
+ if (!lastBreadcrumb && !config.value?.backButton)
52
+ return null
53
+
54
+ return { ...(lastBreadcrumb ?? {}), ...config.value?.backButton }
55
+ })
56
+ </script>
57
+
58
+ <template>
59
+ <div>
60
+ <AppHeader />
61
+
62
+ <UMain v-if="page">
63
+ <UContainer>
64
+ <UPageHeader
65
+ v-if="hasHeader && header"
66
+ v-bind="header"
67
+ :ui="{
68
+ headline: 'all:flex flex-col gap-y-8 items-start',
69
+ wrapper: 'lg:flex-row',
70
+ }"
71
+ >
72
+ <template #headline>
73
+ <UBreadcrumb
74
+ :ui="{ root: 'max-w-full' }"
75
+ :items="breadcrumbItems"
76
+ />
77
+ <HArticleHeadlineMeta :page="page" :collection="collection" />
78
+ </template>
79
+ <HArticleHeaderBody :page="page" :collection="collection">
80
+ <slot name="header" />
81
+ </HArticleHeaderBody>
82
+ </UPageHeader>
83
+
84
+ <UPage>
85
+ <UPageBody>
86
+ <slot />
87
+
88
+ <div
89
+ v-if="hasBackButton || hasCopyButton"
90
+ class="all:flex items-center justify-between mt-12"
91
+ >
92
+ <HBackButton
93
+ v-if="hasBackButton && backLink"
94
+ :to="backLink.to"
95
+ :label="backLink.label"
96
+ :icon="backLink.icon"
97
+ />
98
+ <div class="all:flex justify-end items-center gap-1.5 ml-auto">
99
+ <HCopyButton v-if="hasCopyButton" />
100
+ </div>
101
+ </div>
102
+
103
+ <HSeparator
104
+ v-if="hasSeparator"
105
+ :stem="page?.stem"
106
+ :extension="page?.extension"
107
+ />
108
+
109
+ <HSurround
110
+ v-if="hasSurround"
111
+ :collection="collection"
112
+ />
113
+ </UPageBody>
114
+
115
+ <template #right>
116
+ <HToc
117
+ v-if="hasToc && page?.toc !== false"
118
+ :links="page?.body?.toc?.links"
119
+ :title="page?.body?.toc?.title"
120
+ />
121
+ </template>
122
+ </UPage>
123
+ </UContainer>
124
+ </UMain>
125
+
126
+ <AppFooter />
127
+ </div>
128
+ </template>
@@ -0,0 +1,67 @@
1
+ <script setup lang="ts" generic="C extends 'page' = 'page'">
2
+ import type { Collections } from '@nuxt/content'
3
+
4
+ const {
5
+ path,
6
+ collection = 'page' as C,
7
+ } = defineProps<{
8
+ path?: string
9
+ collection?: C
10
+ }>()
11
+
12
+ const appConfig = useAppConfig()
13
+ const route = useRoute()
14
+
15
+ const { data: page } = await usePageContent<C, Collections['page']>({
16
+ path: () => path,
17
+ collection: () => collection,
18
+ })
19
+
20
+ const { has } = useVariant(collection)
21
+ const hasHeader = has('header')
22
+ const hasToc = has('toc')
23
+
24
+ if (!page.value) {
25
+ throw createError({
26
+ statusCode: 404,
27
+ statusMessage: `${collection} ${path || route.path} not found`,
28
+ fatal: true,
29
+ })
30
+ }
31
+
32
+ usePageSeo(page)
33
+
34
+ const renderToc = computed(() => hasToc.value && page.value?.toc !== false)
35
+ const header = computed(() => resolvePageHeader(page.value))
36
+ </script>
37
+
38
+ <template>
39
+ <div>
40
+ <AppHeader />
41
+
42
+ <UMain v-if="page">
43
+ <UContainer>
44
+ <UPage>
45
+ <UPageHeader
46
+ v-if="hasHeader && header"
47
+ v-bind="header"
48
+ />
49
+
50
+ <UPageBody>
51
+ <slot />
52
+ </UPageBody>
53
+
54
+ <template #right>
55
+ <UContentToc
56
+ v-if="renderToc && page.body?.toc?.links?.length"
57
+ :links="page.body.toc.links"
58
+ :title="page.body.toc.title || appConfig.app.toc?.title"
59
+ />
60
+ </template>
61
+ </UPage>
62
+ </UContainer>
63
+ </UMain>
64
+
65
+ <AppFooter />
66
+ </div>
67
+ </template>
@@ -0,0 +1,12 @@
1
+ <script setup lang="ts">
2
+ const { data: page } = await usePageContent()
3
+ usePageSeo(page)
4
+ </script>
5
+
6
+ <template>
7
+ <AppHeader />
8
+ <UMain>
9
+ <slot />
10
+ </UMain>
11
+ <AppFooter />
12
+ </template>
@@ -0,0 +1,6 @@
1
+ import type { ButtonProps } from '@nuxt/ui'
2
+
3
+ export type ActionButton = ButtonProps & {
4
+ /** Built-in type for a dynamic GitHub link (URL resolved from app.meta.github) */
5
+ type?: 'github-edit' | 'report-github-issue'
6
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Formats a date string, number, or Date object into a localized string.
3
+ *
4
+ * @param date - The date to format
5
+ * @returns A formatted date string
6
+ */
7
+ export default function formatDate(date?: string | number | Date): string {
8
+ if (!date) {
9
+ return ''
10
+ }
11
+
12
+ const d = new Date(date)
13
+ if (Number.isNaN(d.getTime())) {
14
+ return ''
15
+ }
16
+
17
+ const appConfig = useAppConfig()
18
+ const locale = appConfig.app.date?.locale || 'en'
19
+ const options = appConfig.app.date?.options || {
20
+ year: 'numeric',
21
+ month: 'short',
22
+ day: 'numeric',
23
+ }
24
+
25
+ return d.toLocaleDateString(locale, options)
26
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Formats a date string, number, or Date object into a localized datetime string (including time).
3
+ *
4
+ * @param date - The date to format
5
+ * @returns A formatted datetime string
6
+ */
7
+ export default function formatDateTime(date?: string | number | Date): string {
8
+ if (!date) {
9
+ return ''
10
+ }
11
+
12
+ const d = new Date(date)
13
+ if (Number.isNaN(d.getTime())) {
14
+ return ''
15
+ }
16
+
17
+ const appConfig = useAppConfig()
18
+ const locale = appConfig.app.date?.locale || 'en'
19
+ const options = appConfig.app.date?.datetimeOptions || {
20
+ year: 'numeric',
21
+ month: 'short',
22
+ day: 'numeric',
23
+ hour: 'numeric',
24
+ minute: 'numeric',
25
+ }
26
+
27
+ return d.toLocaleString(locale, options)
28
+ }
@@ -0,0 +1,16 @@
1
+ import type { PageCollectionItemBase } from '@nuxt/content'
2
+ import type { PageHeaderProps } from '@nuxt/ui'
3
+
4
+ export default function resolvePageHeader(page: Partial<PageCollectionItemBase> | null | undefined): PageHeaderProps | null {
5
+ if (!page) {
6
+ return null
7
+ }
8
+
9
+ const { header } = page as PageCollectionItemBase & { header?: Partial<PageHeaderProps> }
10
+
11
+ return {
12
+ ...header,
13
+ title: header?.title ?? page.title,
14
+ description: header?.description ?? page.description,
15
+ }
16
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Fetches user details from the Nuxt Content user collection.
3
+ *
4
+ * @param users - A single username or an array of usernames
5
+ * @returns A promise resolving to the selected user profiles
6
+ */
7
+ export default async function resolveUsers(users: string | string[], extraProps: Record<string, any> = {}) {
8
+ const userList = Array.isArray(users) ? users : [users]
9
+
10
+ const resolved = await queryCollection('user')
11
+ .where('username', 'IN', userList)
12
+ .select('username', 'name', 'description', 'to', 'avatar')
13
+ .all()
14
+
15
+ return resolved.map(user => ({ ...user, ...extraProps }))
16
+ }
@@ -0,0 +1,6 @@
1
+ import { defineContentConfig } from '@nuxt/content'
2
+ import { collections } from './schemas'
3
+
4
+ export default defineContentConfig({
5
+ collections,
6
+ })
package/nuxt.config.ts ADDED
@@ -0,0 +1,80 @@
1
+ import { dirname } from 'node:path'
2
+ import { fileURLToPath } from 'node:url'
3
+ import { resolve } from 'pathe'
4
+
5
+ const currentDir: string = dirname(fileURLToPath(import.meta.url))
6
+
7
+ // https://nuxt.com/docs/api/configuration/nuxt-config
8
+ export default defineNuxtConfig({
9
+
10
+ $meta: {
11
+ name: '@happydesigns/ui',
12
+ },
13
+
14
+ components: [
15
+ { path: './components', pathPrefix: false, prefix: 'H' },
16
+ ],
17
+
18
+ css: [
19
+ resolve(currentDir, './app/assets/css/main.css'),
20
+ ],
21
+
22
+ devtools: { enabled: true },
23
+
24
+ modules: [
25
+ '@nuxt/eslint',
26
+ '@happydesigns/nuxt-variants',
27
+ '@nuxt/ui',
28
+ '@nuxt/content',
29
+ 'nuxt-studio',
30
+ ],
31
+
32
+ variants: {
33
+ registry: {
34
+ // Data features — schema only, no config
35
+ dates: {},
36
+ authors: {},
37
+ category: {},
38
+ status: {},
39
+ header: {},
40
+ toc: {},
41
+ links: {},
42
+ location: {},
43
+ layout: {},
44
+ separatorButtons: {},
45
+
46
+ // UI features — config defined in app.config.ts
47
+ user: {},
48
+ backButton: {},
49
+ copyButton: {},
50
+ separator: {},
51
+ surround: {},
52
+
53
+ // Collection variants — extends chains defined here for graph generation
54
+ snippet: {},
55
+ article: {
56
+ extends: ['dates', 'authors', 'category', 'status', 'header', 'toc', 'surround', 'copyButton', 'separator', 'backButton', 'user'],
57
+ config: {},
58
+ },
59
+ event: {
60
+ extends: ['dates', 'location', 'category', 'links', 'status', 'header', 'toc', 'surround', 'copyButton', 'separator', 'backButton', 'user'],
61
+ config: {},
62
+ },
63
+ page: {
64
+ extends: ['layout', 'header', 'toc'],
65
+ config: {},
66
+ },
67
+ },
68
+ },
69
+
70
+ eslint: {
71
+ config: {
72
+ stylistic: true,
73
+ standalone: false,
74
+ },
75
+ },
76
+
77
+ studio: {
78
+ dev: true,
79
+ },
80
+ })
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@happydesigns/ui",
3
+ "type": "module",
4
+ "version": "0.13.5",
5
+ "private": false,
6
+ "packageManager": "pnpm@10.33.0",
7
+ "author": "happydesigns",
8
+ "homepage": "https://github.com/happydesigns",
9
+ "exports": {
10
+ ".": "./nuxt.config.ts",
11
+ "./schemas": "./schemas/index.ts"
12
+ },
13
+ "main": "./nuxt.config.ts",
14
+ "files": [
15
+ "app",
16
+ "content.config.ts",
17
+ "nuxt.config.ts",
18
+ "schemas"
19
+ ],
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "scripts": {
24
+ "dev": "nuxt dev playground",
25
+ "docs": "nuxt dev docs --extends docus",
26
+ "prepare": "nuxt prepare && nuxt prepare playground",
27
+ "build": "nuxt build playground",
28
+ "preview": "nuxt preview playground",
29
+ "lint": "eslint .",
30
+ "lint:fix": "eslint . --fix",
31
+ "release": "changelogen --release",
32
+ "release:pre": "changelogen --release --prerelease",
33
+ "release:alpha": "changelogen --release --versionSuffix alpha.0",
34
+ "release:beta": "changelogen --release --versionSuffix beta.0"
35
+ },
36
+ "dependencies": {
37
+ "@iconify-json/heroicons": "^1.2.3",
38
+ "@iconify-json/lucide": "^1.2.101",
39
+ "@iconify-json/simple-icons": "^1.2.76",
40
+ "@nuxt/content": "^3.12.0",
41
+ "@nuxt/ui": "^4.6.1",
42
+ "better-sqlite3": "^12.8.0",
43
+ "nuxt-studio": "^1.5.1"
44
+ },
45
+ "devDependencies": {
46
+ "@antfu/eslint-config": "^8.0.0",
47
+ "@antfu/ni": "^30.0.0",
48
+ "@happydesigns/nuxt-variants": "^0.0.5",
49
+ "@nuxt/eslint": "^1.15.2",
50
+ "changelogen": "^0.6.2",
51
+ "cross-env": "^10.1.0",
52
+ "eslint": "^10.2.0",
53
+ "nuxt": "^4.4.2",
54
+ "typescript": "^6.0.2",
55
+ "zod": "^4.3.6"
56
+ },
57
+ "resolutions": {
58
+ "@happydesigns/ui": "workspace:*"
59
+ }
60
+ }
@@ -0,0 +1,46 @@
1
+ import { mergeVariantSchemas } from '@happydesigns/nuxt-variants/schemas'
2
+ import { defineCollection } from '@nuxt/content'
3
+ import { variantSchemas } from './traits'
4
+
5
+ export const collections = {
6
+ snippet: defineCollection({
7
+ type: 'page',
8
+ source: {
9
+ include: 'snippets/**/*.{md,yaml}',
10
+ prefix: '/snippets',
11
+ },
12
+ }),
13
+
14
+ article: defineCollection({
15
+ type: 'page',
16
+ source: {
17
+ include: 'articles/**/*.{md,yaml}',
18
+ prefix: '/articles',
19
+ },
20
+ schema: mergeVariantSchemas(['article'], variantSchemas),
21
+ }),
22
+
23
+ event: defineCollection({
24
+ type: 'page',
25
+ source: {
26
+ include: 'events/**/*.{md,yaml}',
27
+ prefix: '/events',
28
+ },
29
+ schema: mergeVariantSchemas(['event'], variantSchemas),
30
+ }),
31
+
32
+ page: defineCollection({
33
+ type: 'page',
34
+ source: {
35
+ include: 'pages/**/*.{md,yaml}',
36
+ prefix: '/',
37
+ },
38
+ schema: mergeVariantSchemas(['page'], variantSchemas),
39
+ }),
40
+
41
+ user: defineCollection({
42
+ type: 'data',
43
+ source: 'users/**/*.{md,yaml}',
44
+ schema: mergeVariantSchemas(['user'], variantSchemas),
45
+ }),
46
+ }
@@ -0,0 +1,2 @@
1
+ export * from './collections'
2
+ export * from './traits'
@@ -0,0 +1,90 @@
1
+ import { property } from '@nuxt/content'
2
+ import { z } from 'zod'
3
+
4
+ export const datesTrait = {
5
+ schema: z.object({
6
+ date: z.date().optional(),
7
+ dateEnd: z.date().optional(),
8
+ }),
9
+ }
10
+
11
+ export const authorsTrait = {
12
+ schema: z.object({
13
+ authors: z.array(z.string()).optional(),
14
+ }),
15
+ }
16
+
17
+ export const categoryTrait = {
18
+ schema: z.object({
19
+ category: z.string().optional(),
20
+ }),
21
+ }
22
+
23
+ export const statusTrait = {
24
+ schema: z.object({
25
+ status: z.enum(['published', 'draft', 'archived']).default('published'),
26
+ }),
27
+ }
28
+
29
+ export const headerTrait = {
30
+ schema: z.object({
31
+ header: property(z.object({})).inherit('@nuxt/ui/components/PageHeader.vue').optional(),
32
+ }),
33
+ }
34
+
35
+ export const tocTrait = {
36
+ schema: z.object({
37
+ toc: z.boolean().default(true),
38
+ }),
39
+ }
40
+
41
+ export const linksTrait = {
42
+ schema: z.object({
43
+ links: z.array(
44
+ property(z.object({})).inherit('@nuxt/ui/components/Button.vue'),
45
+ ).optional(),
46
+ }),
47
+ }
48
+
49
+ export const locationTrait = {
50
+ schema: z.object({
51
+ location: z.object({
52
+ name: z.string(),
53
+ url: z.string().optional(),
54
+ }).optional(),
55
+ }),
56
+ }
57
+
58
+ export const layoutTrait = {
59
+ schema: z.object({
60
+ layout: z.enum(['default', 'content']).optional(),
61
+ }),
62
+ }
63
+
64
+ export const userTrait = {
65
+ schema: z.object({
66
+ username: z.string(),
67
+ name: z.string().optional(),
68
+ description: z.string().optional(),
69
+ to: z.string().optional(),
70
+ avatar: property(z.object({})).inherit('@nuxt/ui/components/Avatar.vue').optional(),
71
+ socials: z.array(z.object({
72
+ name: z.string(),
73
+ url: z.url(),
74
+ })).optional(),
75
+ email: z.email().optional(),
76
+ }),
77
+ }
78
+
79
+ export const variantSchemas = {
80
+ dates: datesTrait.schema,
81
+ authors: authorsTrait.schema,
82
+ category: categoryTrait.schema,
83
+ status: statusTrait.schema,
84
+ header: headerTrait.schema,
85
+ toc: tocTrait.schema,
86
+ links: linksTrait.schema,
87
+ location: locationTrait.schema,
88
+ layout: layoutTrait.schema,
89
+ user: userTrait.schema,
90
+ }