Skip to content

Commit

Permalink
feat(redmine 1275779): add Thumbnail component for migration V7 (#129)
Browse files Browse the repository at this point in the history
* feat(redmine 1275779): add Thumbnail component migration V7

* feat(redmine 1275779): add ThumbnailGrid component for migration V7
  • Loading branch information
vapersmile authored Feb 1, 2024
1 parent f8c08dc commit e62dee2
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 92 deletions.
2 changes: 2 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const config: StorybookConfig = {
'../packages/react-front-kit/src/Components/SearchableCheckboxList/*.stories.tsx',
'../packages/react-front-kit/src/Components/SelectableList/*.stories.tsx',
'../packages/react-front-kit/src/Components/SidebarMenu/*.stories.tsx',
'../packages/react-front-kit/src/Components/Thumbnail/*.stories.tsx',
'../packages/react-front-kit/src/Components/ThumbnailGrid/*.stories.tsx',
// '../packages/*/src/**/*.mdx', // TODO: once all components are migrated, revert to this
// '../packages/*/src/**/*.stories.@(js|jsx|ts|tsx)',
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
.dotsIcon {
color: var(--mantine-primary-color-filled);
}

.fileIcon {
min-width: 22px;
}

.headerContainer {
display: flex;
flex-wrap: nowrap;
justify-content: space-between;
margin-bottom: 22px;
margin-top: 10px;
}

.icon {
height: fit-content;
margin: auto;
}

.iconTitle {
min-width: 28px;
}

.menuButton {
background-color: var(--mantine-color-white-1);
&:hover {
background-color: var(--mantine-color-white);
}
&[aria-expanded='true'] {
svg {
filter: brightness(0) invert(1);
}

background-color: var(--mantine-primary-color-filled);
border-radius: 4px;
display: flex;
height: 28px;
width: 28px;
}
}

.menuButtonSelected {
svg {
filter: brightness(0) invert(1);
}

&[aria-expanded='true'] {
svg {
filter: none;
}

background-color: var(--mantine-primary-color-0);
}
}

.root {
background: var(--mantine-color-white-1);
border-radius: 16px;
cursor: pointer;
height: auto;
padding: 16px;
width: auto;
}

.rootSelected {
background: var(--mantine-primary-color-filled);
color: var(--mantine-color-white);
}

.title {
margin: 0 19px 0 0;
padding-left: 10px;
font-weight: 700;
}

.titleContainer {
align-items: center;
display: flex;
justify-content: center;
overflow: hidden;
}

This file was deleted.

19 changes: 12 additions & 7 deletions packages/react-front-kit/src/Components/Thumbnail/Thumbnail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Image,
Menu,
Text,
getThemeColor,
useMantineTheme,
} from '@mantine/core';
import { DotsThreeVertical } from '@phosphor-icons/react';
Expand All @@ -20,7 +21,7 @@ import { useState } from 'react';
import defaultImage from '../../../assets/defaultImage.jpg';
import { ConfirmModal } from '../ConfirmModal/ConfirmModal';

import { useStyles } from './Thumbnail.style';
import classes from './Thumbnail.module.css';

export interface IThumbnailProps extends IThumbnail {
actions?: IThumbnailAction[];
Expand All @@ -39,8 +40,6 @@ export function Thumbnail(props: IThumbnailProps): ReactElement {
const [confirmAction, setConfirmAction] =
useState<IActionConfirmModalProps<IThumbnail> | null>(null);

const { classes } = useStyles();

function clearConfirmAction(): void {
setConfirmAction(null);
}
Expand Down Expand Up @@ -82,7 +81,11 @@ export function Thumbnail(props: IThumbnailProps): ReactElement {
return (
<>
<Box
bg={String(selected ? theme.fn.primaryColor() : theme.colors.gray[1])}
bg={String(
selected
? getThemeColor(theme.primaryColor, theme)
: theme.colors.gray[1],
)}
className={rootClasses.join(' ')}
onClick={onClick}
>
Expand All @@ -91,13 +94,15 @@ export function Thumbnail(props: IThumbnailProps): ReactElement {
<FileIcon
className={classes.fileIcon}
color={String(
selected ? theme.colors.gray[1] : theme.fn.primaryColor(),
selected
? theme.colors.gray[1]
: getThemeColor(theme.primaryColor, theme),
)}
size={22}
type={iconType}
weight="bold"
/>
<Text component="h3" truncate>
<Text className={classes.title} component="h3" truncate>
{label}
</Text>
</div>
Expand Down Expand Up @@ -128,7 +133,7 @@ export function Thumbnail(props: IThumbnailProps): ReactElement {
// eslint-disable-next-line react/no-array-index-key
key={index}
color={action.color}
icon={
leftSection={
typeof action.icon === 'function'
? action.icon(props)
: action.icon
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.container {
display: flex;
flex-direction: column;
gap: 24px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,11 @@ import type { SimpleGridProps } from '@mantine/core';
import type { ReactElement } from 'react';

import { SimpleGrid } from '@mantine/core';
import { createStyles } from '@mantine/styles';

import { ActionBar } from '../ActionBar/ActionBar';
import { Thumbnail } from '../Thumbnail/Thumbnail';

const useStyles = createStyles(() => ({
container: {
display: 'flex',
flexDirection: 'column',
gap: 24,
},
}));
import classes from './ThumbnailGrid.module.css';

function defaultSelectedElementsText(n: number): string {
return `${n} selected file${n > 1 ? 's' : ''}`;
Expand Down Expand Up @@ -44,8 +37,6 @@ export function ThumbnailGrid(props: IThumbnailGridProps): ReactElement {
const massActions = actions.filter(({ isMassAction }) => isMassAction);
const itemActions = actions.filter(({ isItemAction = true }) => isItemAction);

const { classes } = useStyles();

function handleSelect(index: number): void {
onThumbnailClick?.(thumbnails[index], index);
}
Expand Down

0 comments on commit e62dee2

Please sign in to comment.