diff --git a/docs/app/components/content/examples/card/CardSizeExample.vue b/docs/app/components/content/examples/card/CardSizeExample.vue new file mode 100644 index 00000000..c9833f0e --- /dev/null +++ b/docs/app/components/content/examples/card/CardSizeExample.vue @@ -0,0 +1,17 @@ + + + diff --git a/docs/content/docs/2.components/card.md b/docs/content/docs/2.components/card.md index 5aa8fa71..e5de090c 100644 --- a/docs/content/docs/2.components/card.md +++ b/docs/content/docs/2.components/card.md @@ -95,6 +95,16 @@ slots: :placeholder{class="h-32"} :: +### Size + +Use the `size` prop to control the padding of the header, body and footer. + +::component-example +--- +name: 'card-size-example' +--- +:: + ### Variant Use the `variant` prop to change the variant of the Card. diff --git a/playgrounds/demo/app/pages/components/card.vue b/playgrounds/demo/app/pages/components/card.vue index 47eaa60a..df3bbcbf 100644 --- a/playgrounds/demo/app/pages/components/card.vue +++ b/playgrounds/demo/app/pages/components/card.vue @@ -2,8 +2,10 @@ import theme from '#build/b24ui/card' const variants = Object.keys(theme.variants.variant) +const sizes = Object.keys(theme.variants.size) const attrs = reactive({ - variant: [theme.defaultVariants.variant] + variant: [theme.defaultVariants.variant], + size: [theme.defaultVariants.size] }) @@ -18,6 +20,14 @@ const attrs = reactive({ multiple size="xs" /> + diff --git a/playgrounds/nuxt/app/pages/components/card.vue b/playgrounds/nuxt/app/pages/components/card.vue index e9afc843..d38dce5d 100644 --- a/playgrounds/nuxt/app/pages/components/card.vue +++ b/playgrounds/nuxt/app/pages/components/card.vue @@ -2,8 +2,10 @@ import theme from '#build/b24ui/card' const variants = Object.keys(theme.variants.variant) +const sizes = Object.keys(theme.variants.size) const attrs = reactive({ - variant: [theme.defaultVariants.variant] + variant: [theme.defaultVariants.variant], + size: [theme.defaultVariants.size] }) @@ -18,6 +20,14 @@ const attrs = reactive({ multiple size="xs" /> + diff --git a/src/runtime/components/Card.vue b/src/runtime/components/Card.vue index d78c0677..24cdffcc 100644 --- a/src/runtime/components/Card.vue +++ b/src/runtime/components/Card.vue @@ -18,6 +18,10 @@ export interface CardProps { * @defaultValue 'outline' */ variant?: Card['variants']['variant'] + /** + * @defaultValue 'md' + */ + size?: Card['variants']['size'] class?: any b24ui?: Card['slots'] } @@ -47,7 +51,8 @@ const appConfig = useAppConfig() as Card['AppConfig'] // eslint-disable-next-line vue/no-dupe-keys const b24ui = computed(() => tv({ extend: theme, ...(appConfig.b24ui?.card || {}) })({ - variant: props.variant + variant: props.variant, + size: props.size })) diff --git a/src/theme/card.ts b/src/theme/card.ts index 64cba7f6..26acb92b 100644 --- a/src/theme/card.ts +++ b/src/theme/card.ts @@ -10,7 +10,7 @@ export default { 'overflow-hidden', 'rounded-(--ui-border-radius-md)' ].join(' '), - header: 'p-[24px] sm:px-[22px] sm:py-[15px]', + header: '', title: [ 'font-[family-name:var(--ui-font-family-primary)]', 'font-(--ui-font-weight-semi-bold)', @@ -22,8 +22,8 @@ export default { 'mt-1 text-pretty', 'text-(length:--ui-font-size-lg)/[normal] text-pretty' ].join(' '), - body: 'p-[24px] sm:px-[22px] sm:py-[15px]', - footer: 'p-[24px] sm:px-[22px] sm:py-[15px]' + body: '', + footer: '' }, variants: { variant: { @@ -324,9 +324,32 @@ export default { title: 'text-(--ui-color-design-selection-content)', description: 'text-(--ui-color-design-selection-content)' } + }, + size: { + xs: { + header: 'p-[12px] sm:px-[10px] sm:py-[8px]', + body: 'p-[12px] sm:px-[10px] sm:py-[8px]', + footer: 'p-[12px] sm:px-[10px] sm:py-[8px]' + }, + sm: { + header: 'p-[16px] sm:px-[14px] sm:py-[10px]', + body: 'p-[16px] sm:px-[14px] sm:py-[10px]', + footer: 'p-[16px] sm:px-[14px] sm:py-[10px]' + }, + md: { + header: 'p-[24px] sm:px-[22px] sm:py-[15px]', + body: 'p-[24px] sm:px-[22px] sm:py-[15px]', + footer: 'p-[24px] sm:px-[22px] sm:py-[15px]' + }, + lg: { + header: 'p-[32px] sm:px-[30px] sm:py-[20px]', + body: 'p-[32px] sm:px-[30px] sm:py-[20px]', + footer: 'p-[32px] sm:px-[30px] sm:py-[20px]' + } } }, defaultVariants: { - variant: 'outline' + variant: 'outline', + size: 'md' } } diff --git a/test/components/__snapshots__/Card-vue.spec.ts.snap b/test/components/__snapshots__/Card-vue.spec.ts.snap index 69bd2586..1c25743b 100644 --- a/test/components/__snapshots__/Card-vue.spec.ts.snap +++ b/test/components/__snapshots__/Card-vue.spec.ts.snap @@ -34,7 +34,7 @@ exports[`Card > renders with default slot correctly 1`] = ` exports[`Card > renders with description correctly 1`] = ` "
-
+
Description
@@ -45,7 +45,7 @@ exports[`Card > renders with description correctly 1`] = ` exports[`Card > renders with description slot correctly 1`] = ` "
-
+
Description slot
@@ -58,13 +58,13 @@ exports[`Card > renders with footer slot correctly 1`] = ` "
-
Footer slot
+
Footer slot
" `; exports[`Card > renders with header slot correctly 1`] = ` "
-
Header slot
+
Header slot
" @@ -72,7 +72,7 @@ exports[`Card > renders with header slot correctly 1`] = ` exports[`Card > renders with title and description correctly 1`] = ` "
-
+
Title
Description
@@ -83,7 +83,7 @@ exports[`Card > renders with title and description correctly 1`] = ` exports[`Card > renders with title correctly 1`] = ` "
-
+
Title
@@ -94,7 +94,7 @@ exports[`Card > renders with title correctly 1`] = ` exports[`Card > renders with title slot correctly 1`] = ` "
-
+
Title slot
diff --git a/test/components/__snapshots__/Card.spec.ts.snap b/test/components/__snapshots__/Card.spec.ts.snap index 69bd2586..1c25743b 100644 --- a/test/components/__snapshots__/Card.spec.ts.snap +++ b/test/components/__snapshots__/Card.spec.ts.snap @@ -34,7 +34,7 @@ exports[`Card > renders with default slot correctly 1`] = ` exports[`Card > renders with description correctly 1`] = ` "
-
+
Description
@@ -45,7 +45,7 @@ exports[`Card > renders with description correctly 1`] = ` exports[`Card > renders with description slot correctly 1`] = ` "
-
+
Description slot
@@ -58,13 +58,13 @@ exports[`Card > renders with footer slot correctly 1`] = ` "
-
Footer slot
+
Footer slot
" `; exports[`Card > renders with header slot correctly 1`] = ` "
-
Header slot
+
Header slot
" @@ -72,7 +72,7 @@ exports[`Card > renders with header slot correctly 1`] = ` exports[`Card > renders with title and description correctly 1`] = ` "
-
+
Title
Description
@@ -83,7 +83,7 @@ exports[`Card > renders with title and description correctly 1`] = ` exports[`Card > renders with title correctly 1`] = ` "
-
+
Title
@@ -94,7 +94,7 @@ exports[`Card > renders with title correctly 1`] = ` exports[`Card > renders with title slot correctly 1`] = ` "
-
+
Title slot