Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/content/docs/2.components/page-card.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,35 @@ slots:
:img{src="/tailwindcss-v4.svg" alt="Tailwind CSS" class="w-full"}
::

### Links

Use the `links` prop to display a list of [Button](/docs/components/button) under the description.

::component-code{slug="page-Card"}
---
prettier: true
hide:
- class
ignore:
- title
- description
- icon
- orientation
- links
props:
title: 'Tailwind CSS'
description: 'Nuxt UI integrates with latest Tailwind CSS v4, bringing significant improvements.'
icon: 'i-simple-icons-tailwindcss'
links:
- label: 'Get started'
color: 'neutral'
- label: 'Learn more'
color: 'neutral'
variant: 'subtle'
trailingIcon: 'i-lucide-arrow-right'
---
::

### Highlight

Use the `highlight` and `highlight-color` props to display a highlighted border around the card.
Expand Down
31 changes: 16 additions & 15 deletions src/runtime/components/PageCard.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import type { AppConfig } from '@nuxt/schema'
import theme from '#build/ui/page-card'
import type { IconProps, LinkProps } from '../types'
import type { IconProps, LinkProps, ButtonProps } from '../types'
import type { ComponentConfig } from '../types/tv'

type PageCard = ComponentConfig<typeof theme, AppConfig, 'pageCard'>
Expand Down Expand Up @@ -53,6 +53,7 @@ export interface PageCardProps {
target?: LinkProps['target']
onClick?: (event: MouseEvent) => void | Promise<void>
class?: any
links?: ButtonProps[]
ui?: PageCard['slots']
}

Expand All @@ -63,6 +64,7 @@ export interface PageCardSlots {
title(props?: {}): any
description(props?: {}): any
footer(props?: {}): any
links(props?: {}): any
default(props?: {}): any
}
</script>
Expand Down Expand Up @@ -132,18 +134,17 @@ const ariaLabel = computed(() => {
<div v-if="props.spotlight" :class="ui.spotlight({ class: props.ui?.spotlight })" />

<div :class="ui.container({ class: props.ui?.container })">
<div v-if="!!slots.header || (icon || !!slots.leading) || !!slots.body || (title || !!slots.title) || (description || !!slots.description) || !!slots.footer" :class="ui.wrapper({ class: props.ui?.wrapper })">
<div v-if="!!slots.header || (icon || !!slots.leading) || !!slots.body || (title || !!slots.title) || (description || !!slots.description) || !!slots.footer || (links?.length || !!slots.links)" :class="ui.wrapper({ class: props.ui?.wrapper })">
<div v-if="!!slots.header" :class="ui.header({ class: props.ui?.header })">
<slot name="header" />
</div>

<div v-if="icon || !!slots.leading" :class="ui.leading({ class: props.ui?.leading })">
<slot name="leading">
<UIcon v-if="icon" :name="icon" :class="ui.leadingIcon({ class: props.ui?.leadingIcon })" />
</slot>
</div>

<div v-if="!!slots.body || (title || !!slots.title) || (description || !!slots.description)" :class="ui.body({ class: props.ui?.body })">
<div v-if="icon || !!slots.leading" :class="ui.leading({ class: props.ui?.leading })">
<slot name="leading">
<UIcon v-if="icon" :name="icon" :class="ui.leadingIcon({ class: props.ui?.leadingIcon })" />
</slot>
</div>
<slot name="body">
<div v-if="title || !!slots.title" :class="ui.title({ class: props.ui?.title })">
<slot name="title">
Expand All @@ -159,6 +160,12 @@ const ariaLabel = computed(() => {
</slot>
</div>

<div v-if="links?.length || !!slots.links" :class="ui.links({ class: props.ui?.links })">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we shouldn't move the links inside the #footer slot like the PageHero and PageSection components πŸ€”

<slot name="links">
<UButton v-for="(link, index) in links" :key="index" v-bind="link" />
</slot>
</div>

<div v-if="!!slots.footer" :class="ui.footer({ class: props.ui?.footer })">
<slot name="footer" />
</div>
Expand All @@ -167,13 +174,7 @@ const ariaLabel = computed(() => {
<slot />
</div>

<ULink
v-if="to"
:aria-label="ariaLabel"
v-bind="{ to, target, ...$attrs }"
class="focus:outline-none peer"
raw
>
<ULink v-if="to" :aria-label="ariaLabel" v-bind="{ to, target, ...$attrs }" class="focus:outline-none peer" raw>
<span class="absolute inset-0" aria-hidden="true" />
</ULink>
</Primitive>
Expand Down
13 changes: 9 additions & 4 deletions src/theme/page-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@ export default (options: Required<NuxtOptions['ui']>) => ({
root: 'relative flex rounded-lg',
spotlight: 'absolute inset-0 rounded-[inherit] pointer-events-none bg-default/90',
container: 'relative flex flex-col flex-1 lg:grid gap-x-8 gap-y-4 p-4 sm:p-6',
wrapper: 'flex flex-col flex-1 items-start',
wrapper: 'flex flex-col flex-1 items-start gap-2.5 flex-wrap',
header: 'mb-4',
body: 'flex-1',
footer: 'pt-4 mt-auto',
leading: 'inline-flex items-center mb-2.5',
leadingIcon: 'size-5 shrink-0 text-primary',
title: 'text-base text-pretty font-semibold text-highlighted',
description: 'text-[15px] text-pretty'
description: 'text-[15px] text-pretty',
links: 'inline-flex flex-wrap gap-2.5'
},
variants: {
orientation: {
horizontal: {
container: 'lg:grid-cols-2 lg:items-center'
container: 'lg:grid-cols-2 lg:items-center',
wrapper: '',
links: ''
},
vertical: {
container: ''
container: '',
wrapper: 'flex-row',
links: 'self-center'
}
},
reverse: {
Expand Down
2 changes: 2 additions & 0 deletions test/components/PageCard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('PageCard', () => {
['with icon', { props: { icon: 'i-lucide-house' } }],
['with title', { props: { title: 'Title' } }],
['with description', { props: { description: 'Description' } }],
['with links', { props: { links: [{ label: 'Get started' }] } }],
['with to', { props: { to: 'https://github.com/benjamincanac' } }],
...variants.map((variant: string) => [`with variant ${variant}`, { props: { ...props, variant } }]),
...variants.map((variant: string) => [`with variant ${variant} to`, { props: { ...props, variant, to: 'https://github.com/benjamincanac' } }]),
Expand All @@ -43,6 +44,7 @@ describe('PageCard', () => {
['with title slot', { props, slots: { title: () => 'Title slot' } }],
['with description slot', { props, slots: { description: () => 'Description slot' } }],
['with footer slot', { props, slots: { footer: () => 'Footer slot' } }],
['with links slot', { props, slots: { links: () => 'Links slot' } }],
['with default slot', { props, slots: { default: () => 'Default slot' } }]
])('renders %s correctly', async (nameOrHtml: string, options: { props?: PageCardProps, slots?: Partial<PageCardSlots> }) => {
const html = await ComponentRender(nameOrHtml, options, PageCard)
Expand Down
Loading
Loading