@happydesigns/ui 0.13.5 → 0.14.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.
Files changed (37) hide show
  1. package/README.md +94 -94
  2. package/app/app.config.ts +168 -169
  3. package/app/app.vue +11 -0
  4. package/app/components/article/ArticleGrid.vue +125 -149
  5. package/app/components/article/ArticleHeaderBody.vue +20 -20
  6. package/app/components/article/ArticleHeadlineMeta.vue +26 -26
  7. package/app/components/article/ArticleList.vue +80 -95
  8. package/app/components/article/ArticlePage.vue +15 -14
  9. package/app/components/footer/FooterColumnHeading.vue +5 -5
  10. package/app/components/footer/FooterCopyright.vue +29 -29
  11. package/app/components/traits/Authors.vue +19 -20
  12. package/app/components/traits/BackButton.vue +15 -26
  13. package/app/components/traits/Category.vue +9 -9
  14. package/app/components/traits/CopyButton.vue +32 -39
  15. package/app/components/traits/Dates.vue +20 -20
  16. package/app/components/traits/Links.vue +17 -17
  17. package/app/components/traits/Location.vue +20 -20
  18. package/app/components/traits/Separator.vue +21 -26
  19. package/app/components/traits/SeparatorButtons.vue +53 -56
  20. package/app/components/traits/Surround.vue +48 -60
  21. package/app/components/traits/Toc.vue +16 -16
  22. package/app/composables/useArticleList.ts +24 -26
  23. package/app/composables/useArticleListQuery.ts +54 -0
  24. package/app/composables/useCategoryBadge.ts +27 -27
  25. package/app/composables/useClipboard.ts +26 -26
  26. package/app/composables/usePageContent.ts +18 -18
  27. package/app/composables/usePageSeo.ts +30 -30
  28. package/app/layouts/article.vue +117 -125
  29. package/app/layouts/content.vue +57 -65
  30. package/app/layouts/default.vue +3 -12
  31. package/app/types/config.ts +13 -6
  32. package/content.config.ts +6 -6
  33. package/nuxt.config.ts +80 -80
  34. package/package.json +3 -3
  35. package/schemas/collections.ts +46 -46
  36. package/schemas/index.ts +2 -2
  37. package/schemas/traits.ts +90 -90
@@ -1,158 +1,134 @@
1
- <script setup lang="ts" generic="C extends keyof PageCollections = 'article'">
2
- import type { PageCollections } from '@nuxt/content'
3
- import type { ArticleFilter } from '~/composables/useArticleList'
4
-
5
- const props = withDefaults(defineProps<{
6
- /** Optional fixed category to filter by */
7
- category?: string
8
- /** The orientation of the blog posts list */
9
- orientation?: 'horizontal' | 'vertical'
10
- /** The collection to fetch articles from */
11
- collection?: C
12
- /** Additional custom filters */
13
- where?: ArticleFilter[]
14
- /** Field to sort by. Set to false to disable default sorting. */
15
- sort?: { field: string, direction: 'ASC' | 'DESC' } | false
16
- /** Status to filter by. Set to false to disable default status filtering. */
17
- status?: string | false
18
- /** Optional items per page override */
19
- itemsPerPage?: number
20
- }>(), {
21
- sort: undefined,
22
- status: undefined,
23
- })
24
-
25
- const route = useRoute()
26
-
27
- /** Resolve the configuration for this collection using the smart merger */
28
- const { config: collectionConfig } = useVariant(() => props.collection || 'article')
29
-
30
- const itemsPerPage = computed(() => props.itemsPerPage || collectionConfig.value.list?.itemsPerPage || 12)
31
- const labelAll = computed(() => collectionConfig.value.list?.labelAll || 'All')
32
- const noResultsMessage = computed(() => collectionConfig.value.list?.noResultsMessage || 'No items found.')
33
- const noResultsIcon = computed(() => collectionConfig.value.list?.noResultsIcon)
34
-
35
- const page = ref(Number(route.query.page) || 1)
36
- const selectedCategory = ref(props.category || (route.query.category as string) || String(labelAll.value))
37
- const resolvedOrientation = computed(() => props.orientation || 'horizontal')
38
-
39
- // Update internal state when props change (from ArticleList or parent)
40
- watch(() => props.category, (newCategory) => {
41
- if (newCategory) {
42
- selectedCategory.value = newCategory
43
- }
44
- })
45
-
46
- // Fetch articles using the composable
1
+ <script setup lang="ts" generic="C extends keyof PageCollections = 'article'">
2
+ import type { PageCollections } from '@nuxt/content'
3
+ import type { ArticleFilter } from '~/composables/useArticleList'
4
+
5
+ const props = withDefaults(defineProps<{
6
+ /** Optional fixed category to filter by */
7
+ category?: string
8
+ /** The orientation of the blog posts list */
9
+ orientation?: 'horizontal' | 'vertical'
10
+ /** The collection to fetch articles from */
11
+ collection?: C
12
+ /** Additional custom filters */
13
+ where?: ArticleFilter[]
14
+ /** Field to sort by. Set to false to disable default sorting. */
15
+ sort?: { field: string, direction: 'ASC' | 'DESC' } | false
16
+ /** Status to filter by. Set to false to disable default status filtering. */
17
+ status?: string | false
18
+ /** Optional items per page override */
19
+ itemsPerPage?: number
20
+ }>(), {
21
+ sort: undefined,
22
+ status: undefined,
23
+ })
24
+
25
+ /** Resolve the configuration for this collection using the smart merger */
26
+ const { config } = useVariant(() => props.collection || 'article')
27
+
28
+ const itemsPerPage = computed(() => props.itemsPerPage || config.value.list?.itemsPerPage || 12)
29
+ const labelAll = computed(() => config.value.list?.labelAll || 'All')
30
+ const noResultsMessage = computed(() => config.value.list?.noResultsMessage || 'No items found.')
31
+ const noResultsIcon = computed(() => config.value.list?.noResultsIcon)
32
+
33
+ const { page, selectedCategory, updateQuery } = useArticleListQuery({
34
+ labelAll,
35
+ fixedCategory: computed(() => props.category),
36
+ })
37
+
47
38
  const { data, status: fetchStatus } = await useArticleList({
48
- page,
49
- itemsPerPage,
50
- category: selectedCategory,
51
- labelAll,
52
- collection: () => props.collection || 'article' as C,
39
+ page,
40
+ itemsPerPage,
41
+ category: selectedCategory,
42
+ labelAll,
43
+ collection: () => props.collection || 'article' as C,
53
44
  where: () => props.where,
54
45
  sort: () => props.sort,
55
46
  status: () => props.status,
56
47
  })
57
48
 
58
- // Watchers and lifecycle
59
- function updateQuery() {
60
- const query: Record<string, any> = { ...route.query }
61
- if (page.value > 1)
62
- query.page = page.value
63
- else
64
- delete query.page
65
-
66
- // Only update category in query if we are not in a fixed category mode
67
- if (!props.category) {
68
- if (selectedCategory.value !== labelAll.value)
69
- query.category = selectedCategory.value
70
- else
71
- delete query.category
72
- }
73
-
74
- navigateTo({ query })
75
- }
76
-
77
- watch(page, () => {
78
- updateQuery()
79
- if (import.meta.client) {
80
- window.scrollTo({ top: 0, behavior: 'smooth' })
81
- }
82
- })
83
-
84
- // Sync state with query on back/forward navigation
85
- watch(() => route.query, (newQuery) => {
86
- page.value = Number(newQuery.page) || 1
87
- if (!props.category) {
88
- selectedCategory.value = (newQuery.category as string) || labelAll.value
89
- }
49
+ const hasArticles = computed(() => Boolean(data.value?.articles.length))
50
+ const isInitialLoading = computed(() => {
51
+ return !hasArticles.value && (fetchStatus.value === 'idle' || fetchStatus.value === 'pending')
90
52
  })
91
-
92
- // Delayed loader to avoid flickering on fast navigations
93
- const showLoader = ref(false)
94
- let loaderTimeout: any = null
95
-
96
- watch(fetchStatus, (newStatus) => {
97
- if (newStatus === 'pending') {
98
- loaderTimeout = setTimeout(() => {
99
- showLoader.value = true
100
- }, 200)
101
- }
102
- else {
103
- clearTimeout(loaderTimeout)
104
- showLoader.value = false
105
- }
106
- }, { immediate: true })
107
- </script>
108
-
109
- <template>
110
- <div class="all:flex flex-col gap-8">
111
- <div v-if="showLoader && !data?.articles.length" class="all:flex justify-center py-20">
112
- <UIcon name="i-lucide-loader-circle" class="size-12 animate-spin text-muted" />
113
- </div>
114
-
115
- <UBlogPosts
116
- v-else-if="data?.articles.length"
117
- :orientation="resolvedOrientation"
118
- :ui="{
119
- base: resolvedOrientation === 'horizontal' ? 'sm:grid sm:grid-cols-2 lg:grid-cols-3' : '',
120
- }"
121
- :class="{ 'opacity-50 transition-opacity': fetchStatus === 'pending' }"
122
- >
123
- <UBlogPost
124
- v-for="article in data.articles"
125
- :key="article.path"
126
- :to="article.path"
127
- :title="article.title"
128
- :description="article.description"
129
- :badge="article.resolvedBadge"
130
- :authors="article.resolvedAuthors"
131
- variant="subtle"
132
- :ui="{
133
- title: 'line-clamp-2',
134
- description: 'line-clamp-3',
135
- }"
136
- >
137
- <template #date>
138
- <slot name="date" :article="article">
139
- <HArticleGridDate :article="article" />
140
- </slot>
141
- </template>
142
- </UBlogPost>
143
- </UBlogPosts>
144
-
145
- <div v-else class="all:flex flex-col items-center justify-center py-20 text-muted text-center">
146
- <UIcon v-if="noResultsIcon" :name="noResultsIcon" class="size-12 mb-4 opacity-20" />
147
- <p>{{ noResultsMessage }}</p>
148
- </div>
149
-
150
- <div v-if="data && data.total > itemsPerPage" class="all:flex justify-center mt-8">
151
- <UPagination
152
- v-model:page="page"
153
- :total="data.total"
154
- :items-per-page="itemsPerPage"
53
+
54
+ watch(page, () => {
55
+ updateQuery()
56
+ if (import.meta.client) {
57
+ window.scrollTo({ top: 0, behavior: 'smooth' })
58
+ }
59
+ })
60
+
61
+ // Delayed loader to avoid flickering on fast navigations
62
+ const showLoader = ref(false)
63
+ let loaderTimeout: ReturnType<typeof setTimeout> | null = null
64
+
65
+ watch(fetchStatus, (newStatus) => {
66
+ if (newStatus === 'pending') {
67
+ loaderTimeout = setTimeout(() => {
68
+ showLoader.value = true
69
+ }, 200)
70
+ }
71
+ else {
72
+ if (loaderTimeout !== null) {
73
+ clearTimeout(loaderTimeout)
74
+ loaderTimeout = null
75
+ }
76
+ showLoader.value = false
77
+ }
78
+ }, { immediate: true })
79
+ </script>
80
+
81
+ <template>
82
+ <div class="all:flex flex-col gap-8">
83
+ <div v-if="isInitialLoading" class="all:flex justify-center py-20">
84
+ <UIcon
85
+ v-if="showLoader || fetchStatus === 'idle'"
86
+ name="i-lucide-loader-circle"
87
+ class="size-12 animate-spin text-muted"
155
88
  />
156
89
  </div>
157
- </div>
158
- </template>
90
+
91
+ <UBlogPosts
92
+ v-else-if="hasArticles"
93
+ :orientation="orientation || 'horizontal'"
94
+ :ui="{
95
+ base: (orientation || 'horizontal') === 'horizontal' ? 'sm:grid sm:grid-cols-2 lg:grid-cols-3' : '',
96
+ }"
97
+ :class="{ 'opacity-50 transition-opacity': fetchStatus === 'pending' }"
98
+ >
99
+ <UBlogPost
100
+ v-for="article in data.articles"
101
+ :key="article.path"
102
+ :to="article.path"
103
+ :title="article.title"
104
+ :description="article.description"
105
+ :badge="article.resolvedBadge"
106
+ :authors="article.resolvedAuthors"
107
+ variant="subtle"
108
+ :ui="{
109
+ title: 'line-clamp-2',
110
+ description: 'line-clamp-3',
111
+ }"
112
+ >
113
+ <template #date>
114
+ <slot name="date" :article="article">
115
+ <HArticleGridDate :article="article" />
116
+ </slot>
117
+ </template>
118
+ </UBlogPost>
119
+ </UBlogPosts>
120
+
121
+ <div v-else class="all:flex flex-col items-center justify-center py-20 text-muted text-center">
122
+ <UIcon v-if="noResultsIcon" :name="noResultsIcon" class="size-12 mb-4 opacity-20" />
123
+ <p>{{ noResultsMessage }}</p>
124
+ </div>
125
+
126
+ <div v-if="data && data.total > itemsPerPage" class="all:flex justify-center mt-8">
127
+ <UPagination
128
+ v-model:page="page"
129
+ :total="data.total"
130
+ :items-per-page="itemsPerPage"
131
+ />
132
+ </div>
133
+ </div>
134
+ </template>
@@ -1,20 +1,20 @@
1
- <script setup lang="ts">
2
- import type { PageCollections } from '@nuxt/content'
3
-
4
- const props = defineProps<{
5
- page?: any
6
- collection?: keyof PageCollections
7
- }>()
8
-
9
- const { has } = useVariant(() => props.collection || 'article')
10
- const hasAuthors = has('authors')
11
- const hasLinks = has('links')
12
- </script>
13
-
14
- <template>
15
- <div class="mt-4 all:flex flex-wrap items-center gap-3">
16
- <HAuthors v-if="hasAuthors" :authors="page?.authors" />
17
- <HLinks v-if="hasLinks && page?.links?.length" :links="page?.links" />
18
- <slot />
19
- </div>
20
- </template>
1
+ <script setup lang="ts">
2
+ import type { PageCollections } from '@nuxt/content'
3
+
4
+ const props = defineProps<{
5
+ page?: any
6
+ collection?: keyof PageCollections
7
+ }>()
8
+
9
+ const { has } = useVariant(() => props.collection || 'article')
10
+ const hasAuthors = has('authors')
11
+ const hasLinks = has('links')
12
+ </script>
13
+
14
+ <template>
15
+ <div class="mt-4 all:flex flex-wrap items-center gap-3">
16
+ <HAuthors v-if="hasAuthors" :authors="page?.authors" />
17
+ <HLinks v-if="hasLinks && page?.links?.length" :links="page?.links" />
18
+ <slot />
19
+ </div>
20
+ </template>
@@ -1,26 +1,26 @@
1
- <script setup lang="ts">
2
- import type { PageCollections } from '@nuxt/content'
3
-
4
- const props = defineProps<{
5
- page?: any
6
- collection?: keyof PageCollections
7
- }>()
8
-
9
- const { has } = useVariant(() => props.collection || 'article')
10
-
11
- const showCategory = computed(() => has('category').value && props.page?.category)
12
- const showDates = computed(() => has('dates').value && props.page?.date)
13
- const showLocation = computed(() => has('location').value && props.page?.location?.name)
14
- </script>
15
-
16
- <template>
17
- <div class="all:flex flex-wrap items-center gap-x-3 gap-y-2 text-muted">
18
- <HCategory v-if="showCategory" :category="page?.category" />
19
-
20
- <span v-if="showCategory && showDates" class="all:hidden sm:inline opacity-50">&middot;</span>
21
- <HDates v-if="showDates" :date="page?.date" :date-end="page?.dateEnd" />
22
-
23
- <span v-if="(showCategory || showDates) && showLocation" class="all:hidden sm:inline opacity-50">&middot;</span>
24
- <HLocation v-if="showLocation" :location="page?.location" />
25
- </div>
26
- </template>
1
+ <script setup lang="ts">
2
+ import type { PageCollections } from '@nuxt/content'
3
+
4
+ const props = defineProps<{
5
+ page?: any
6
+ collection?: keyof PageCollections
7
+ }>()
8
+
9
+ const { has } = useVariant(() => props.collection || 'article')
10
+
11
+ const showCategory = computed(() => has('category').value && props.page?.category)
12
+ const showDates = computed(() => has('dates').value && props.page?.date)
13
+ const showLocation = computed(() => has('location').value && props.page?.location?.name)
14
+ </script>
15
+
16
+ <template>
17
+ <div class="all:flex flex-wrap items-center gap-x-3 gap-y-2 text-muted">
18
+ <HCategory v-if="showCategory" :category="page?.category" />
19
+
20
+ <span v-if="showCategory && showDates" class="all:hidden sm:inline opacity-50">&middot;</span>
21
+ <HDates v-if="showDates" :date="page?.date" :date-end="page?.dateEnd" />
22
+
23
+ <span v-if="(showCategory || showDates) && showLocation" class="all:hidden sm:inline opacity-50">&middot;</span>
24
+ <HLocation v-if="showLocation" :location="page?.location" />
25
+ </div>
26
+ </template>
@@ -1,95 +1,80 @@
1
- <script setup lang="ts" generic="C extends keyof PageCollections = 'article'">
2
- import type { PageCollections } from '@nuxt/content'
3
- import type { ArticleFilter } from '~/composables/useArticleList'
4
-
5
- const props = withDefaults(defineProps<{
6
- /** Optional fixed category to filter by */
7
- category?: string
8
- /** The orientation of the blog posts list */
9
- orientation?: 'horizontal' | 'vertical'
10
- /** The collection to fetch articles from */
11
- collection?: C
12
- /** Additional custom filters */
13
- where?: ArticleFilter[]
14
- /** Field to sort by. Set to false to disable default sorting. */
15
- sort?: { field: string, direction: 'ASC' | 'DESC' } | false
16
- /** Status to filter by. Set to false to disable default status filtering. */
17
- status?: string | false
18
- /** Optional items per page override */
19
- itemsPerPage?: number
20
- }>(), {
21
- sort: undefined,
22
- status: undefined,
23
- })
24
-
25
- const route = useRoute()
26
-
27
- /** Resolve the configuration for this collection using the smart merger */
28
- const { config: collectionConfig } = useVariant(() => props.collection || 'article')
29
-
30
- const labelAll = computed(() => collectionConfig.value.list?.labelAll || 'All')
31
-
32
- const selectedCategory = ref(props.category || (route.query.category as string) || String(labelAll.value))
33
-
34
- const categories = computed(() => {
35
- const cats = collectionConfig.value.categories || {}
36
- const items = [
37
- { label: String(labelAll.value), value: String(labelAll.value) },
38
- ...Object.keys(cats).map(key => ({
39
- label: String(cats[key]?.label || key),
40
- value: String(key),
41
- })),
42
- ]
43
-
44
- return items.map(item => ({
45
- label: item.label,
46
- active: selectedCategory.value === item.value,
47
- onSelect: () => {
48
- selectedCategory.value = item.value
49
- updateQuery()
50
- },
51
- }))
52
- })
53
-
54
- function updateQuery() {
55
- const query: Record<string, any> = { ...route.query }
56
- delete query.page // Omit page 1 from query
57
-
58
- if (selectedCategory.value !== labelAll.value)
59
- query.category = selectedCategory.value
60
- else
61
- delete query.category
62
-
63
- navigateTo({ query })
64
- }
65
-
66
- // Sync state with query on back/forward navigation
67
- watch(() => route.query.category, (newCategory) => {
68
- selectedCategory.value = (newCategory as string) || labelAll.value
69
- })
70
- </script>
71
-
72
- <template>
73
- <div class="all:flex flex-col gap-8">
74
- <div v-if="!props.category" class="border-b border-gray-200 dark:border-gray-800">
75
- <UNavigationMenu
76
- :items="categories"
77
- highlight
78
- />
79
- </div>
80
-
81
- <HArticleGrid
82
- :category="selectedCategory"
83
- :orientation="props.orientation"
84
- :collection="props.collection"
85
- :where="props.where"
86
- :sort="props.sort"
87
- :status="props.status"
88
- :items-per-page="props.itemsPerPage"
89
- >
90
- <template v-for="(_, name) in $slots" #[name]="slotData">
91
- <slot :name="name" v-bind="slotData" />
92
- </template>
93
- </HArticleGrid>
94
- </div>
95
- </template>
1
+ <script setup lang="ts" generic="C extends keyof PageCollections = 'article'">
2
+ import type { PageCollections } from '@nuxt/content'
3
+ import type { ArticleFilter } from '~/composables/useArticleList'
4
+ import { useArticleListQuery } from '~/composables/useArticleListQuery'
5
+
6
+ const props = withDefaults(defineProps<{
7
+ /** Optional fixed category to filter by */
8
+ category?: string
9
+ /** The orientation of the blog posts list */
10
+ orientation?: 'horizontal' | 'vertical'
11
+ /** The collection to fetch articles from */
12
+ collection?: C
13
+ /** Additional custom filters */
14
+ where?: ArticleFilter[]
15
+ /** Field to sort by. Set to false to disable default sorting. */
16
+ sort?: { field: string, direction: 'ASC' | 'DESC' } | false
17
+ /** Status to filter by. Set to false to disable default status filtering. */
18
+ status?: string | false
19
+ /** Optional items per page override */
20
+ itemsPerPage?: number
21
+ }>(), {
22
+ sort: undefined,
23
+ status: undefined,
24
+ })
25
+
26
+ /** Resolve the configuration for this collection using the smart merger */
27
+ const { config: collectionConfig } = useVariant(() => props.collection || 'article')
28
+
29
+ const labelAll = computed(() => collectionConfig.value.list?.labelAll || 'All')
30
+
31
+ const { selectedCategory, updateQuery } = useArticleListQuery({
32
+ labelAll,
33
+ fixedCategory: computed(() => props.category),
34
+ })
35
+
36
+ const categories = computed(() => {
37
+ const cats = collectionConfig.value.categories || {}
38
+ const items = [
39
+ { label: String(labelAll.value), value: String(labelAll.value) },
40
+ ...Object.keys(cats).map(key => ({
41
+ label: String(cats[key]?.label || key),
42
+ value: String(key),
43
+ })),
44
+ ]
45
+
46
+ return items.map(item => ({
47
+ label: item.label,
48
+ active: selectedCategory.value === item.value,
49
+ onSelect: () => {
50
+ selectedCategory.value = item.value
51
+ updateQuery({ resetPage: true })
52
+ },
53
+ }))
54
+ })
55
+ </script>
56
+
57
+ <template>
58
+ <div class="all:flex flex-col gap-8">
59
+ <div v-if="!props.category" class="border-b border-gray-200 dark:border-gray-800">
60
+ <UNavigationMenu
61
+ :items="categories"
62
+ highlight
63
+ />
64
+ </div>
65
+
66
+ <HArticleGrid
67
+ :category="selectedCategory"
68
+ :orientation="props.orientation"
69
+ :collection="props.collection"
70
+ :where="props.where"
71
+ :sort="props.sort"
72
+ :status="props.status"
73
+ :items-per-page="props.itemsPerPage"
74
+ >
75
+ <template v-for="(_, name) in $slots" #[name]="slotData">
76
+ <slot :name="name" v-bind="slotData" />
77
+ </template>
78
+ </HArticleGrid>
79
+ </div>
80
+ </template>
@@ -1,16 +1,17 @@
1
- <script setup lang="ts">
2
- import type { PageCollections } from '@nuxt/content'
3
-
4
- const { collection = 'article' } = defineProps<{
5
- collection?: keyof PageCollections
6
- path?: string
7
- }>()
8
-
9
- const { data: page } = await usePageContent({ collection: () => collection })
10
- </script>
11
-
1
+ <script setup lang="ts">
2
+ import type { PageCollections } from '@nuxt/content'
3
+
4
+ const { collection = 'article', path } = defineProps<{
5
+ collection?: keyof PageCollections
6
+ path?: string
7
+ }>()
8
+
9
+ const { data: page } = await usePageContent({
10
+ collection: () => collection,
11
+ path: () => path,
12
+ })
13
+ </script>
14
+
12
15
  <template>
13
- <NuxtLayout name="article" :collection="collection">
14
- <ContentRenderer v-if="page" :value="page" />
15
- </NuxtLayout>
16
+ <ContentRenderer v-if="page" :value="page" />
16
17
  </template>
@@ -1,5 +1,5 @@
1
- <template>
2
- <h3 class="font-semibold mb-6">
3
- <slot />
4
- </h3>
5
- </template>
1
+ <template>
2
+ <h3 class="font-semibold mb-6">
3
+ <slot />
4
+ </h3>
5
+ </template>