File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,12 +13,14 @@ const {
1313 className,
1414 bodyClassName,
1515 secondary,
16+ flat,
1617 ... rest
1718} = Astro .props
1819
1920const classes = [
2021 styles .card ,
2122 secondary && styles .secondary ,
23+ (flat && (compact || secondary )) && styles .flat ,
2224 className
2325]
2426
@@ -28,13 +30,18 @@ const bodyClasses = [
2830 bodyClassName
2931]
3032
33+ const titleClasses = [
34+ styles .title ,
35+ flat && styles .flat
36+ ]
37+
3138const Component = element
3239const Title = titleTag
3340---
3441
3542<Component class:list ={ classes } {... rest }>
3643 { title && (
37- <Title class :list = { styles . title } >{ title } </Title >
44+ <Title class :list = { titleClasses } >{ title } </Title >
3845 )}
3946 <div class:list ={ bodyClasses } >
4047 <slot />
Original file line number Diff line number Diff line change 1313 className,
1414 bodyClassName,
1515 secondary,
16+ flat,
1617 children,
1718 ... rest
1819 }: SvelteCardProps = $props ()
1920
2021 const classes = $derived (classNames ([
2122 styles .card ,
2223 secondary && styles .secondary ,
24+ (flat && (compact || secondary )) && styles .flat ,
2325 className
2426 ]))
2527
2830 compact && styles .compact ,
2931 bodyClassName
3032 ]))
33+
34+ const titleClasses = $derived (classNames ([
35+ styles .title ,
36+ flat && styles .flat ,
37+ (flat && compact ) && styles .compact
38+ ]))
3139 </script >
3240
3341<svelte:element this ={element } class ={classes } {...rest }>
3442 {#if title }
35- <svelte:element this ={titleTag } class ={styles . title }>
43+ <svelte:element this ={titleTag } class ={titleClasses }>
3644 {title }
3745 </svelte:element >
3846 {/if }
Original file line number Diff line number Diff line change @@ -13,13 +13,15 @@ const Card = ({
1313 className,
1414 bodyClassName,
1515 secondary,
16+ flat,
1617 children,
1718 ...rest
1819} : ReactCardProps ) => {
1920 const classes = classNames ( [
2021 styles . card ,
21- className ,
22- secondary && styles . secondary
22+ secondary && styles . secondary ,
23+ ( flat && ( compact || secondary ) ) && styles . flat ,
24+ className
2325 ] )
2426
2527 const bodyClasses = classNames ( [
@@ -28,10 +30,16 @@ const Card = ({
2830 bodyClassName
2931 ] )
3032
33+ const titleClasses = classNames ( [
34+ styles . title ,
35+ flat && styles . flat ,
36+ ( flat && compact ) && styles . compact
37+ ] )
38+
3139 return (
3240 < Element className = { classes } { ...rest } >
3341 { title && (
34- < TitleTag className = { styles . title } > { title } </ TitleTag >
42+ < TitleTag className = { titleClasses } > { title } </ TitleTag >
3543 ) }
3644 < div className = { bodyClasses } >
3745 { children }
Original file line number Diff line number Diff line change 11@use ' ../../scss/config.scss' as * ;
22
33.card {
4- @include border (primary- 50);
54 @include border-radius (md);
65 @include layout (flex , column );
76 @include background (primary- 70);
87 @include visibility (hidden );
8+
9+ & :not (.flat ) {
10+ @include border (primary- 50);
11+ }
912
10- & .secondary .body {
13+ & .secondary .body ,
14+ & .flat .title {
1115 @include background (primary- 60);
1216 }
1317
1418 .title {
15- @include spacing (p- default);
16- @include border (primary- 50, bottom );
1719 @include visibility (block );
20+ @include spacing (p- default);
21+
22+ & :not (.flat ) {
23+ @include border (primary- 50, bottom );
24+ }
1825 }
1926
2027 .body {
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ export type CardProps = {
99 className ?: string
1010 bodyClassName ?: string
1111 secondary ?: boolean
12+ flat ?: boolean
1213 [ key : string ] : any
1314}
1415
Original file line number Diff line number Diff line change @@ -60,6 +60,22 @@ const sections = getSections({
6060 <section.component compact = { true } >
6161 Compact card without title
6262 </section.component >
63+
64+ <section.component compact = { true } secondary = { true } >
65+ Compact + secondary card
66+ </section.component >
67+
68+ <section.component flat = { true } title = " Flat card title" >
69+ Flat card without <code >compact</code > or <code >secondary</code > still gets a border to prevent it from becoming invisible against the background.
70+ </section.component >
71+
72+ <section.component flat = { true } compact = { true } title = " Flat + Compact" >
73+ Flat + compact card with a title
74+ </section.component >
75+
76+ <section.component flat = { true } secondary = { true } title = " Flat + Secondary" >
77+ Flat + secondary card with a title
78+ </section.component >
6379 </div >
6480 ))}
6581</Layout >
You can’t perform that action at this time.
0 commit comments