dashboard/src/components/bookmarks.tsx

106 lines
2.2 KiB
TypeScript
Raw Normal View History

2020-07-08 19:36:36 +02:00
import styled from "styled-components";
2021-06-14 11:29:03 +02:00
import {
Headline,
Item,
ItemList,
ListContainer,
SubHeadline,
} from "./elements";
2020-07-08 19:36:36 +02:00
const GroupContainer = styled.div`
display: flex;
flex-direction: column;
flex: 2 1 auto;
padding: 1rem 0;
`;
2022-01-14 14:53:18 +01:00
const BookmarkElement = styled.a`
2020-07-08 19:36:36 +02:00
font-weight: 400;
text-decoration: none;
2021-07-10 23:57:08 +02:00
color: ${(props) => props.theme.accentColor};
2020-07-08 19:36:36 +02:00
padding-top: 0.75rem;
font-size: 0.9rem;
&:hover {
text-decoration: underline;
}
`;
export interface IBookmarkProps {
2020-07-08 19:36:36 +02:00
name: string;
url: string;
2022-01-14 14:53:18 +01:00
newTab?: boolean;
2020-07-08 19:36:36 +02:00
}
export interface IBookmarkGroupProps {
2021-03-21 20:19:44 +01:00
name: string;
items: Array<IBookmarkProps>;
2020-07-08 19:36:36 +02:00
}
2021-06-14 11:29:03 +02:00
export interface IBookmarkListProps {
2022-02-13 20:57:26 +01:00
groups?: Array<IBookmarkGroupProps>;
2021-06-14 11:29:03 +02:00
}
2022-01-14 14:53:18 +01:00
export const Bookmark = ({ name, url, newTab }: IBookmarkProps) => {
const linkAttrs =
newTab !== undefined && newTab
? {
target: "_blank",
rel: "noopener noreferrer",
}
: {};
return (
<BookmarkElement href={url} {...linkAttrs}>
{name}
</BookmarkElement>
);
};
2021-03-21 19:59:18 +01:00
/**
* Renders a given bookmark group
2021-06-14 11:29:03 +02:00
* @param {IBookmarkGroupProps} props given props of the bookmark group
* @returns {React.ReactNode} the bookmark group component
2021-03-21 19:59:18 +01:00
*/
2021-03-21 20:19:44 +01:00
export const BookmarkGroup = ({ name, items }: IBookmarkGroupProps) => (
2020-07-08 19:36:36 +02:00
<Item>
<GroupContainer>
2021-03-21 20:19:44 +01:00
<SubHeadline>{name}</SubHeadline>
2022-01-14 14:53:18 +01:00
{items.map(({ name, url, newTab }, index) => (
<Bookmark
key={[name, index].join("")}
name={name}
url={url}
newTab={newTab}
/>
2020-07-08 19:36:36 +02:00
))}
</GroupContainer>
</Item>
);
2021-06-14 11:29:03 +02:00
/**
* Renders a given list of categorized bookmarks
* @param {IBookmarkListProps} props props of the given bookmark list
* @returns {React.ReactNode} the bookmark list component
*/
2022-02-13 20:57:26 +01:00
const BookmarkList = ({ groups }: IBookmarkListProps) => {
if (groups === undefined || groups.length <= 0) return <></>;
return (
<ListContainer>
<Headline>Bookmarks</Headline>
<ItemList>
{groups.map(({ name, items }, index) => (
<BookmarkGroup
key={[name, index].join("")}
name={name}
items={items}
/>
))}
</ItemList>
</ListContainer>
);
};
2021-06-14 11:29:03 +02:00
export default BookmarkList;