Skip to content

Commit

Permalink
add more option to align property
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandra-c committed Feb 19, 2024
1 parent 3164a83 commit 7f0faf9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/components/surfaces/Card/CardActions/CardActionsStyles.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import { Theme } from '@mui/material'
import MuiCardActions from '@mui/material/CardActions'
import { styled } from '@mui/material/styles'
import { includes } from 'ramda'
import { T, always, cond, equals, includes } from 'ramda'
import { ActionAlign } from '../types'

type StyledProps = { theme: Theme; filled: boolean; align: ActionAlign }

const contentAlignment = cond([
[equals('left'), always('flex-start')],
[equals('right'), always('flex-end')],
[equals('center'), always('center')],
[T, always('flex-start')]
])

const CardActions = styled(MuiCardActions, {
shouldForwardProp: prop => !includes(prop, ['align', 'filled'])
})(({ theme, filled, align = 'left' }: Partial<StyledProps>) => ({
})(({ theme, filled, align }: Partial<StyledProps>) => ({
...(filled && {
backgroundColor: theme?.palette.grey[200],
minHeight: '48px',
padding: theme?.spacing(2, 3)
}),
justifyContent: align === 'left' ? 'flex-start' : 'flex-end'
justifyContent: contentAlignment(align)
}))

export default CardActions
2 changes: 1 addition & 1 deletion src/components/surfaces/Card/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type CardVariant = 'elevation' | 'outlined'

export type CardColor = Exclude<Color, 'default' | 'white' | 'transparent'>

export type ActionAlign = 'left' | 'right'
export type ActionAlign = 'left' | 'right' | 'center'

export type CardMediaProps = MuiCardMediaProps & {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/stories/surfaces/Card/BasicCardsPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const BasicCardsPreview = () => {
</Card>
</Grid>
<Grid item xs={10}>
<Card footer={<LearnMoreButton />}>
<Card footer={<LearnMoreButton />} footerProps={{ align: 'center' }}>
<Grid container spacing={2}>
<Grid item xs={8}>
<Typography gutterBottom variant="h5">
Expand Down

0 comments on commit 7f0faf9

Please sign in to comment.