generated from cp-20/nextjs-with-mantine-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from cp-20/feat/article-actions
記事の削除などをできるボタンを追加
- Loading branch information
Showing
14 changed files
with
717 additions
and
524 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
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
150 changes: 94 additions & 56 deletions
150
apps/web/src/client/Home/_components/Article/ArticleListItem.tsx
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 |
---|---|---|
@@ -1,93 +1,131 @@ | ||
import { css } from '@emotion/react'; | ||
import { Text, useMantineTheme } from '@mantine/core'; | ||
import { ActionIcon, Text, useMantineTheme } from '@mantine/core'; | ||
import type { Article } from '@read-stack/openapi'; | ||
import type { ComponentProps, FC, ReactNode } from 'react'; | ||
import { IconArchive, IconTrash } from '@tabler/icons-react'; | ||
import type { ComponentProps, ReactNode } from 'react'; | ||
|
||
export interface ArticleListItemProps { | ||
article: Article; | ||
renderActions?: (article: Article) => ReactNode; | ||
export interface ArticleListItemProps<T> { | ||
article: Article & T; | ||
renderActions?: (article: Article & T) => ReactNode; | ||
onDelete?: (article: Article & T) => void; | ||
onArchive?: (article: Article & T) => void; | ||
} | ||
|
||
export const ArticleListItem: FC<ArticleListItemProps & ComponentProps<'div'>> = | ||
({ article, renderActions, ...props }) => { | ||
const theme = useMantineTheme(); | ||
return ( | ||
<div {...props}> | ||
<div | ||
css={css` | ||
export const ArticleListItem = <T,>({ | ||
article, | ||
renderActions, | ||
onDelete, | ||
onArchive, | ||
...props | ||
}: ArticleListItemProps<T> & ComponentProps<'div'>) => { | ||
const theme = useMantineTheme(); | ||
return ( | ||
<div {...props}> | ||
<div | ||
css={css` | ||
padding: 1rem; | ||
border: 1px solid ${theme.colors.gray[2]}; | ||
border-radius: ${theme.radius.md}; | ||
`} | ||
> | ||
<div | ||
css={css` | ||
> | ||
<div | ||
css={css` | ||
display: grid; | ||
gap: 1rem; | ||
grid-template-columns: 1fr max(30%, 100px); | ||
`} | ||
> | ||
<div | ||
css={css` | ||
> | ||
<div | ||
css={css` | ||
display: flex; | ||
min-width: 0; | ||
flex-direction: column; | ||
gap: 0.5rem; | ||
`} | ||
> | ||
<Text fw="bold" lineClamp={2}> | ||
<a | ||
css={css` | ||
> | ||
<Text fw="bold" lineClamp={2}> | ||
<a | ||
css={css` | ||
color: ${theme.colors[theme.primaryColor][7]}; | ||
text-decoration: none; | ||
&:hover { | ||
text-decoration: underline; | ||
} | ||
`} | ||
href={article.url} | ||
rel="noopener noreferrer" | ||
target="_blank" | ||
> | ||
{article.title} | ||
</a> | ||
</Text> | ||
<Text color="dimmed" fz="sm" lineClamp={3}> | ||
{article.body} | ||
</Text> | ||
<Text | ||
color="dimmed" | ||
css={css` | ||
href={article.url} | ||
rel="noopener noreferrer" | ||
target="_blank" | ||
> | ||
{article.title} | ||
</a> | ||
</Text> | ||
<Text color="dimmed" fz="sm" lineClamp={3}> | ||
{article.body} | ||
</Text> | ||
<Text | ||
color="dimmed" | ||
css={css` | ||
display: flex; | ||
gap: 0.5rem; | ||
`} | ||
fz="sm" | ||
> | ||
<span>{new URL(article.url).host}</span> | ||
</Text> | ||
fz="sm" | ||
> | ||
<span>{new URL(article.url).host}</span> | ||
</Text> | ||
</div> | ||
<div> | ||
<div | ||
css={css` | ||
display: flex; | ||
justify-content: flex-end; | ||
border-radius: ${theme.radius.md}; | ||
margin-bottom: 0.5rem; | ||
background-color: ${theme.white}; | ||
color: ${theme.white}; | ||
gap: 0.1rem; | ||
`} | ||
> | ||
{onArchive ? ( | ||
<ActionIcon | ||
onClick={() => { | ||
onArchive(article); | ||
}} | ||
> | ||
<IconArchive /> | ||
</ActionIcon> | ||
) : null} | ||
{onDelete ? ( | ||
<ActionIcon | ||
onClick={() => { | ||
onDelete(article); | ||
}} | ||
> | ||
<IconTrash /> | ||
</ActionIcon> | ||
) : null} | ||
</div> | ||
<div> | ||
{article.ogImageUrl ? ( | ||
<img | ||
alt="" | ||
css={css` | ||
{article.ogImageUrl ? ( | ||
<img | ||
alt="" | ||
css={css` | ||
max-height: 120px; | ||
object-fit: cover; | ||
`} | ||
src={article.ogImageUrl} | ||
width="100%" | ||
/> | ||
) : null} | ||
</div> | ||
src={article.ogImageUrl} | ||
width="100%" | ||
/> | ||
) : null} | ||
</div> | ||
<div | ||
css={css` | ||
</div> | ||
<div | ||
css={css` | ||
margin-top: 1rem; | ||
`} | ||
> | ||
{renderActions ? renderActions(article) : null} | ||
</div> | ||
> | ||
{renderActions ? renderActions(article) : null} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.