Skip to content

Commit 7dd96f2

Browse files
authored
Merge pull request #1475 from privy-open-source/fix/refine-card
refine card
2 parents b125801 + 42869c9 commit 7dd96f2

File tree

6 files changed

+153
-9
lines changed

6 files changed

+153
-9
lines changed

src/components/button/Button.vue

+25
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ defineSlots<{
165165
--p-button-md-padding-x: theme(spacing.5);
166166
--p-button-lg-padding-x: theme(spacing.8);
167167
168+
/**
169+
* only for button
170+
* variant link
171+
*/
172+
--p-button-xs-padding-y: theme(spacing[0.5]);
173+
--p-button-sm-padding-y: theme(spacing.1);
174+
--p-button-md-padding-y: theme(spacing[2.5]);
175+
--p-button-lg-padding-y: theme(spacing.4);
176+
168177
@apply inline-flex align-middle justify-center font-medium no-underline hover:no-underline disabled:opacity-50 disabled:pointer-events-none transition-all ease-in-out duration-200;
169178
170179
> svg {
@@ -181,18 +190,34 @@ defineSlots<{
181190
*/
182191
&&--xs {
183192
@apply px-[var(--p-button-xs-padding-x)] py-[2px] gap-1 text-sm rounded-xs;
193+
194+
&:where(.btn--variant-link) {
195+
@apply py-[var(--p-button-xs-padding-y)];
196+
}
184197
}
185198
186199
&&--sm {
187200
@apply px-[var(--p-button-sm-padding-x)] py-1 gap-2 text-base tracking-wider rounded-sm;
201+
202+
&:where(.btn--variant-link) {
203+
@apply py-[var(--p-button-sm-padding-y)];
204+
}
188205
}
189206
190207
&&--md {
191208
@apply px-[var(--p-button-md-padding-x)] py-[10px] gap-3 text-base tracking-wider rounded;
209+
210+
&:where(.btn--variant-link) {
211+
@apply py-[var(--p-button-md-padding-y)];
212+
}
192213
}
193214
194215
&&--lg {
195216
@apply px-[var(--p-button-lg-padding-x)] py-4 gap-4 text-base tracking-wider rounded;
217+
218+
&:where(.btn--variant-link) {
219+
@apply py-[var(--p-button-lg-padding-y)];
220+
}
196221
}
197222
198223
/*

src/components/button/index.md

+6
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,12 @@ Button use local CSS variables on `.btn` for enhanced real-time customization.
300300
--p-button-sm-padding-x: theme(spacing.4);
301301
--p-button-md-padding-x: theme(spacing.5);
302302
--p-button-lg-padding-x: theme(spacing.8);
303+
304+
/** only work in button variant link */
305+
--p-button-xs-padding-y: theme(spacing[0.5]);
306+
--p-button-sm-padding-y: theme(spacing.1);
307+
--p-button-md-padding-y: theme(spacing[2.5]);
308+
--p-button-lg-padding-y: theme(spacing.4);
303309
```
304310

305311
## API

src/components/card/Card.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,19 @@ it('should have custom body class via "body-class" props', () => {
192192
expect(body).toBeInTheDocument()
193193
expect(body).toHaveClass('bg-info')
194194
})
195+
196+
it('should have custom spacing via `spacing` props', () => {
197+
const screen = render({
198+
components: { Card },
199+
template : `
200+
<Card spacing="lg">
201+
Content
202+
</Card>
203+
`,
204+
})
205+
206+
const body = screen.queryByTestId('card')
207+
208+
expect(body).toBeInTheDocument()
209+
expect(body).toHaveClass('card--spacing-lg')
210+
})

src/components/card/Card.vue

+44-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import type { PropType, VNode } from 'vue-demi'
5757
import { computed, ref } from 'vue-demi'
5858
import IconClose from '@privyid/persona-icon/vue/close/16.vue'
5959
import Heading from '../heading/Heading.vue'
60-
import type { ElementVariant } from '.'
60+
import type { ElementVariant, SpacingVariant } from '.'
6161
6262
const props = defineProps({
6363
element: {
@@ -88,6 +88,10 @@ const props = defineProps({
8888
type : [String, Array],
8989
default: undefined,
9090
},
91+
spacing: {
92+
type : String as PropType<SpacingVariant>,
93+
default: 'md',
94+
},
9195
})
9296
9397
const emit = defineEmits<{
@@ -108,6 +112,9 @@ const classNames = computed(() => {
108112
if (props.callout)
109113
result.push('card--callout')
110114
115+
if (props.spacing)
116+
result.push(`card--spacing-${props.spacing}`)
117+
111118
return result
112119
})
113120
@@ -147,16 +154,40 @@ defineSlots<{
147154
--p-card-border-dark: theme(borderColor.dark.default.DEFAULT);
148155
--p-card-color: theme(textColor.default);
149156
--p-card-color-dark: theme(textColor.dark.default);
157+
--p-card-border-radius: theme(borderRadius.md);
158+
--p-card-inside-border-radius: theme(borderRadius.DEFAULT);
150159
151-
@apply border bg-[color:var(--p-card-bg)] border-[color:var(--p-card-border)] text-[color:var(--p-card-color)] rounded-md;
160+
@apply border bg-[color:var(--p-card-bg)] border-[color:var(--p-card-border)] text-[color:var(--p-card-color)] rounded-[var(--p-card-border-radius)];
152161
@apply dark:bg-[color:var(--p-card-bg-dark)] dark:border-[color:var(--p-card-border-dark)] dark:text-[color:var(--p-card-color-dark)];
153162
154163
/**
155164
* Card inside card
156165
* has 8px rounded
157166
*/
158167
.card {
159-
@apply rounded;
168+
@apply rounded-[var(--p-card-inside-border-radius)];
169+
}
170+
171+
&&--spacing {
172+
&-sm {
173+
--p-card-padding-x: theme(spacing.4);
174+
--p-card-padding-y: theme(spacing.4);
175+
}
176+
177+
&-md {
178+
--p-card-padding-x: theme(spacing.6);
179+
--p-card-padding-y: theme(spacing.6);
180+
}
181+
182+
&-lg {
183+
--p-card-padding-x: theme(spacing.9);
184+
--p-card-padding-y: theme(spacing.9);
185+
}
186+
187+
&-xl {
188+
--p-card-padding-x: theme(spacing.12);
189+
--p-card-padding-y: theme(spacing.12);
190+
}
160191
}
161192
162193
/*
@@ -236,6 +267,10 @@ defineSlots<{
236267
}
237268
238269
&__header {
270+
.heading {
271+
@apply font-medium leading-none;
272+
}
273+
239274
&&--default {
240275
@apply flex justify-between items-center;
241276
}
@@ -257,6 +292,11 @@ defineSlots<{
257292
@apply text-default/30 hover:text-default/50 hover:cursor-pointer;
258293
@apply dark:text-dark-default/30 hover:dark:text-dark-default/50;
259294
}
295+
296+
+ .card__body,
297+
+ .card__section > .card__body {
298+
@apply pt-4;
299+
}
260300
}
261301
262302
&__section {
@@ -279,7 +319,7 @@ defineSlots<{
279319
}
280320
281321
&__footer {
282-
@apply pb-[var(--p-card-padding-y)] px-[var(--p-card-padding-x)] pt-3;
322+
@apply pb-[var(--p-card-padding-y)] px-[var(--p-card-padding-x)] pt-8;
283323
}
284324
}
285325
</style>

src/components/card/index.md

+61-5
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ description: Take picture from user's camera
6969
<p-card
7070
title="Any Title Should Here">
7171
<template #action>
72-
<p-button color="info" variant="link">Button Text</p-button>
72+
<p-button color="info" variant="link" style="--p-button-md-padding-y:0; --p-button-md-padding-x:0;">Button Text</p-button>
7373
</template>
7474
While here you will see the content of cards, everything goes here.
7575
If you need custom cards, take the component which more represent to
@@ -151,7 +151,7 @@ description: Take picture from user's camera
151151
title="Card with Sub-Section"
152152
sectioned>
153153
<template #action>
154-
<p-button variant="link" color="info">Button Text</p-button>
154+
<p-button variant="link" color="info" style="--p-button-md-padding-y:0; --p-button-md-padding-x:0;">Button Text</p-button>
155155
</template>
156156
<p-card-section>
157157
While here you will see the content of cards, everything goes here.
@@ -266,12 +266,67 @@ description: Take picture from user's camera
266266
</template>
267267
```
268268

269+
## Spacing
270+
Card component features 4 distinct spacing variants that adjust the size and
271+
layout of the content within the card body. Each variant is designed to offer
272+
flexibility in presentation and to suit different design needs.
273+
There are `sm`, `md`, `lg` and `xl`. Default spacing are `md`.
274+
The spacing feature also work in `Sectioned card`.
275+
276+
<preview>
277+
<p-card spacing="sm">
278+
While here you will see the content of cards, everything goes here.
279+
If you need custom cards, take the component which more represent to
280+
what you need and detach it.
281+
</p-card>
282+
<p-card spacing="md">
283+
While here you will see the content of cards, everything goes here.
284+
If you need custom cards, take the component which more represent to
285+
what you need and detach it.
286+
</p-card>
287+
<p-card spacing="lg">
288+
While here you will see the content of cards, everything goes here.
289+
If you need custom cards, take the component which more represent to
290+
what you need and detach it.
291+
</p-card>
292+
<p-card spacing="xl">
293+
While here you will see the content of cards, everything goes here.
294+
If you need custom cards, take the component which more represent to
295+
what you need and detach it.
296+
</p-card>
297+
</preview>
298+
299+
```vue
300+
<template>
301+
<p-card spacing="sm">
302+
While here you will see the content of cards, everything goes here.
303+
If you need custom cards, take the component which more represent to
304+
what you need and detach it.
305+
</p-card>
306+
<p-card spacing="md">
307+
While here you will see the content of cards, everything goes here.
308+
If you need custom cards, take the component which more represent to
309+
what you need and detach it.
310+
</p-card>
311+
<p-card spacing="lg">
312+
While here you will see the content of cards, everything goes here.
313+
If you need custom cards, take the component which more represent to
314+
what you need and detach it.
315+
</p-card>
316+
<p-card spacing="xl">
317+
While here you will see the content of cards, everything goes here.
318+
If you need custom cards, take the component which more represent to
319+
what you need and detach it.
320+
</p-card>
321+
</template>
322+
```
323+
269324
## Variables
270325
Card use local CSS variables on `.card` for enhanced real-time customization.
271326

272327
```sass
273-
--p-card-padding-x: theme(spacing.6);
274-
--p-card-padding-y: theme(spacing.6);
328+
--p-card-border-radius: theme(borderRadius.md);
329+
--p-card-inside-border-radius: theme(borderRadius.DEFAULT);
275330
--p-card-bg: theme(backgroundColor.default.DEFAULT);
276331
--p-card-bg-dark: theme(backgroundColor.dark.default.DEFAULT);
277332
--p-card-border: theme(borderColor.default.DEFAULT);
@@ -286,12 +341,13 @@ Card use local CSS variables on `.card` for enhanced real-time customization.
286341

287342
| Props | Type | Default | Description |
288343
|---------------|:---------:|:---------:|--------------------------------------------------------------|
289-
| `element` | `String` | `section` | Card element, valid value is `div`, `section`, and `article` |
344+
| `element` | `String` | `section` | Card element, valid value are `div`, `section` and `article` |
290345
| `title` | `String` | - | Card Header Title |
291346
| `sectioned` | `Boolean` | `false` | Enable Card Section |
292347
| `disabled` | `Boolean` | `false` | Disable (look-like) Card |
293348
| `callout` | `Boolean` | `false` | Enable Callout |
294349
| `dismissable` | `Boolean` | `true` | Show / Hide dismiss button |
350+
| `spacing` | `String` | `md` | Card spacing, valid value are `sm`, `md`, `lg` and `xl` |
295351

296352
### Slots
297353
| Name | Description |

src/components/card/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export type ElementVariant = 'div' | 'section' | 'article'
2+
export type SpacingVariant = 'sm' | 'md' | 'lg' | 'xl'

0 commit comments

Comments
 (0)