-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: first draft of the folde card * fix: first versions * fix: add reference * fix: collapse component * fix: card description * fix: last tweeks * fix: remove mr * fix: remove height of description when not set
- Loading branch information
Showing
7 changed files
with
2,361 additions
and
4,301 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Meta, StoryObj, composeStories } from '@storybook/react'; | ||
|
||
import { BrowserRouter } from 'react-router-dom'; | ||
|
||
import { TextDisplay } from '..'; | ||
import * as TextDisplayStories from '../TextDisplay/TextDisplay.stories'; | ||
import FolderCard from './FolderCard'; | ||
|
||
const { SimpleText } = composeStories(TextDisplayStories); | ||
|
||
const meta = { | ||
title: 'Card/Folder', | ||
component: FolderCard, | ||
decorators: [ | ||
(story) => { | ||
return <BrowserRouter>{story()}</BrowserRouter>; | ||
}, | ||
], | ||
args: { | ||
name: 'Example folder', | ||
description: 'Optional description', | ||
to: 'https://graasp.org', | ||
}, | ||
} satisfies Meta<typeof FolderCard>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default = { | ||
args: { | ||
thumbnail: 'https://picsum.photos/256/256', | ||
}, | ||
} satisfies Story; | ||
|
||
export const NoThumbnail = { | ||
args: { thumbnail: undefined }, | ||
} satisfies Story; | ||
|
||
export const OverflowDescription = { | ||
args: { | ||
thumbnail: undefined, | ||
description: <SimpleText />, | ||
}, | ||
} satisfies Story; | ||
|
||
export const LongHtmlDescription = { | ||
args: { | ||
thumbnail: undefined, | ||
description: ( | ||
<TextDisplay content='<p>Hello wefh uwhf uqhw hqwkjehr jkqwher jkqwhej khqwefhj hwkjefh jwhef jahwefj khawjkf hawjkf hajkwefh ajk hajkhf wkej </p><p>World</p>' /> | ||
), | ||
}, | ||
} satisfies Story; | ||
|
||
export const LongTitle = { | ||
args: { | ||
thumbnail: undefined, | ||
name: 'aewrfgaf jawef kjkew hqwjerh jweqh jhkjqwehjwkrmwfkmacqjfiqfm34ion q3fmqifjkamsdk we whj hjhkwjehf jhkjweh jkwhejk hwjkehr jwkeh jf jiajweifiaiowef uawefu iuaioweuiouoi auwer ', | ||
}, | ||
} satisfies Story; | ||
|
||
export const NoDescription = { | ||
args: { | ||
thumbnail: undefined, | ||
description: null, | ||
}, | ||
} satisfies Story; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import Thumbnail from '@/Thumbnail/Thumbnail'; | ||
import ItemIcon from '@/icons/ItemIcon'; | ||
import { ChevronRight } from 'lucide-react'; | ||
|
||
import { | ||
Box, | ||
Card, | ||
CardActionArea, | ||
CardHeader, | ||
Stack, | ||
useTheme, | ||
} from '@mui/material'; | ||
|
||
import { Link } from 'react-router-dom'; | ||
|
||
const CARD_HEIGHT = '76px'; | ||
|
||
type CardThumbnailProps = { | ||
thumbnail?: string; | ||
alt: string; | ||
}; | ||
const CardThumbnail = ({ thumbnail, alt }: CardThumbnailProps): JSX.Element => { | ||
if (thumbnail) { | ||
return <Thumbnail url={thumbnail} alt={alt} maxHeight='100%' />; | ||
} | ||
|
||
return ( | ||
<Box | ||
display='flex' | ||
alignItems='center' | ||
justifyContent='center' | ||
bgcolor='#E4DFFF' | ||
width={CARD_HEIGHT} | ||
height='100%' | ||
flexShrink={0} | ||
minHeight={CARD_HEIGHT} | ||
// minHeight={0} | ||
minWidth={0} | ||
> | ||
<ItemIcon type='folder' alt={alt} /> | ||
</Box> | ||
); | ||
}; | ||
|
||
type Props = { | ||
id?: string; | ||
name: string; | ||
description?: string | null | JSX.Element; | ||
thumbnail?: string; | ||
/** | ||
* React Router Link target | ||
*/ | ||
to: string; | ||
}; | ||
const FolderCard = ({ | ||
id, | ||
name, | ||
description, | ||
thumbnail, | ||
to, | ||
}: Props): JSX.Element => { | ||
const theme = useTheme(); | ||
|
||
return ( | ||
<Card | ||
id={id} | ||
sx={{ | ||
// card should not be longer than the content | ||
width: 'max-content', | ||
// but should not overflow the parent | ||
maxWidth: '100%', | ||
// set the height of the card to be fixed | ||
height: CARD_HEIGHT, | ||
}} | ||
> | ||
<CardActionArea component={Link} to={to} sx={{ height: '100%' }}> | ||
<Stack direction='row' alignItems='center' height='100%' minWidth={0}> | ||
<CardThumbnail thumbnail={thumbnail} alt={name} /> | ||
<CardHeader | ||
sx={{ | ||
// needed to make container not overflow parent | ||
minWidth: '0px', | ||
'& .MuiCardHeader-content': { | ||
// needed to make container not overflow parent | ||
minWidth: '0px', | ||
}, | ||
}} | ||
title={name} | ||
subheader={description} | ||
titleTypographyProps={{ | ||
color: 'primary', | ||
minWidth: '0px', | ||
// needed to force long title into ellipsis | ||
noWrap: true, | ||
width: '100%', | ||
}} | ||
subheaderTypographyProps={{ | ||
overflow: 'hidden', | ||
height: description ? '1lh' : 'unset', | ||
textOverflow: 'ellipsis', | ||
minWidth: 0, | ||
'& p': { | ||
margin: 0, | ||
marginBlocStart: 0, | ||
}, | ||
}} | ||
/> | ||
<ChevronRight | ||
size={35} | ||
color={theme.palette.primary.main} | ||
style={{ flexShrink: 0, margin: theme.spacing(2, 2, 2, 0) }} | ||
/> | ||
</Stack> | ||
</CardActionArea> | ||
</Card> | ||
); | ||
}; | ||
export default FolderCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.