Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
36 changes: 36 additions & 0 deletions docs/content/docs/2.components/card.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,42 @@ slots:
:placeholder{class="h-8"}
::

### Size

Use the `size` prop to change the size of the Card.

::component-code
---
prettier: true
hide:
- class
props:
size: md
class: 'w-full'
slots:
header: |

<Placeholder class="h-8" />

default: |

<Placeholder class="h-32" />

footer: |

<Placeholder class="h-8" />
---

#header
:placeholder{class="h-8"}

#default
:placeholder{class="h-32"}

#footer
:placeholder{class="h-8"}
::

## API

### Props
Expand Down
7 changes: 6 additions & 1 deletion src/runtime/components/Card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export interface CardProps {
*/
variant?: Card['variants']['variant']
class?: any
/**
* @defaultValue 'md'
*/
size?: Card['variants']['size']
ui?: Card['slots']
}

Expand All @@ -38,7 +42,8 @@ const slots = defineSlots<CardSlots>()
const appConfig = useAppConfig() as Card['AppConfig']

const ui = computed(() => tv({ extend: tv(theme), ...(appConfig.ui?.card || {}) })({
variant: props.variant
variant: props.variant,
size: props.size
}))
</script>

Expand Down
30 changes: 29 additions & 1 deletion src/theme/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,33 @@ export default {
footer: 'p-4 sm:px-6'
},
variants: {
size: {
xs: {
header: 'p-2 sm:px-4',
body: 'p-2 sm:p-4',
footer: 'p-2 sm:px-4'
},
sm: {
header: 'p-3 sm:px-5',
body: 'p-3 sm:p-5',
footer: 'p-3 sm:px-5'
},
md: {
header: 'p-4 sm:px-6',
body: 'p-4 sm:p-6',
footer: 'p-4 sm:px-6'
},
lg: {
header: 'p-5 sm:px-7',
body: 'p-5 sm:p-7',
footer: 'p-5 sm:px-7'
},
xl: {
header: 'p-6 sm:px-8',
body: 'p-6 sm:p-8',
footer: 'p-6 sm:px-8'
}
},
variant: {
solid: {
root: 'bg-inverted text-inverted'
Expand All @@ -22,6 +49,7 @@ export default {
}
},
defaultVariants: {
variant: 'outline'
variant: 'outline',
size: 'md'
}
}
14 changes: 11 additions & 3 deletions test/components/Card.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,28 @@

describe('Card', () => {
const variants = Object.keys(theme.variants.variant) as any
const sizes = Object.keys(theme.variants.size) as any

const slots = {
default: () => 'Default slot',
header: () => 'Header slot',
footer: () => 'Footer slot'
}

it.each([
// Props
['with as', { props: { as: 'section' } }],
...variants.map((variant: string) => [`with variant ${variant}`, { props: { variant } }]),
...sizes.map((size: string) => [`with size ${size}`, { props: { size }, slots }]),
['with class', { props: { class: 'rounded-xl' } }],
['with ui', { props: { ui: { body: 'font-bold' } } }],
// Slots
['with default slot', { slots: { default: () => 'Default slot' } }],
['with header slot', { slots: { header: () => 'Header slot' } }],
['with footer slot', { slots: { footer: () => 'Footer slot' } }]
['with default slot', { slots: { default: slots.default }, props: { size: 'md' } }],
['with header slot', { slots: { header: slots.header }, props: { size: 'md' } }],
['with footer slot', { slots: { footer: slots.footer }, props: { size: 'md' } }]
])('renders %s correctly', async (nameOrHtml: string, options: { props?: CardProps, slots?: Partial<CardSlots> }) => {
const html = await ComponentRender(nameOrHtml, options, Card)
expect(html).toMatchSnapshot()

Check failure on line 32 in test/components/Card.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

../components/Card.spec.ts > Card > renders with size xl correctly

Error: Snapshot `Card > renders with size xl correctly 1` mismatched ❯ ../components/Card.spec.ts:32:18

Check failure on line 32 in test/components/Card.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

../components/Card.spec.ts > Card > renders with size lg correctly

Error: Snapshot `Card > renders with size lg correctly 1` mismatched ❯ ../components/Card.spec.ts:32:18

Check failure on line 32 in test/components/Card.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

../components/Card.spec.ts > Card > renders with size md correctly

Error: Snapshot `Card > renders with size md correctly 1` mismatched ❯ ../components/Card.spec.ts:32:18

Check failure on line 32 in test/components/Card.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

../components/Card.spec.ts > Card > renders with size sm correctly

Error: Snapshot `Card > renders with size sm correctly 1` mismatched ❯ ../components/Card.spec.ts:32:18

Check failure on line 32 in test/components/Card.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

../components/Card.spec.ts > Card > renders with size xs correctly

Error: Snapshot `Card > renders with size xs correctly 1` mismatched ❯ ../components/Card.spec.ts:32:18

Check failure on line 32 in test/components/Card.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

../components/Card.spec.ts > Card > renders with variant subtle correctly

Error: Snapshot `Card > renders with variant subtle correctly 1` mismatched ❯ ../components/Card.spec.ts:32:18

Check failure on line 32 in test/components/Card.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

../components/Card.spec.ts > Card > renders with variant soft correctly

Error: Snapshot `Card > renders with variant soft correctly 1` mismatched ❯ ../components/Card.spec.ts:32:18

Check failure on line 32 in test/components/Card.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

../components/Card.spec.ts > Card > renders with variant outline correctly

Error: Snapshot `Card > renders with variant outline correctly 1` mismatched ❯ ../components/Card.spec.ts:32:18

Check failure on line 32 in test/components/Card.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

../components/Card.spec.ts > Card > renders with variant solid correctly

Error: Snapshot `Card > renders with variant solid correctly 1` mismatched ❯ ../components/Card.spec.ts:32:18

Check failure on line 32 in test/components/Card.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

../components/Card.spec.ts > Card > renders with as correctly

Error: Snapshot `Card > renders with as correctly 1` mismatched ❯ ../components/Card.spec.ts:32:18
})

it('passes accessibility tests', async () => {
Expand Down
81 changes: 0 additions & 81 deletions test/components/__snapshots__/Card-vue.spec.ts.snap

This file was deleted.

81 changes: 0 additions & 81 deletions test/components/__snapshots__/Card.spec.ts.snap

This file was deleted.