-
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.
feat: TET-905 add FileIcon component (#156)
* feat: TET-905 add FileIcon component * feat: TET-905 fix catalogs name
- Loading branch information
1 parent
99f8a15
commit 06a584e
Showing
10 changed files
with
851 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { BaseProps } from '@/types'; | ||
|
||
export type IconType = | ||
| 'Sketch' | ||
| 'Photoshop' | ||
| 'Excel' | ||
| 'Word' | ||
| 'Pdf' | ||
| 'Spreadsheet' | ||
| 'Document' | ||
| 'File' | ||
| 'Archive' | ||
| 'Figma'; | ||
export type Size = 'Large' | 'Medium'; | ||
|
||
export type FileIconProps = { | ||
iconType: IconType; | ||
size?: Size; | ||
custom?: BaseProps; | ||
}; |
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,31 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { FileIcon } from './FileIcon'; | ||
|
||
import { FileIconDocs } from '@/docs-components/FileIconDocs'; | ||
import { TetDocs } from '@/docs-components/TetDocs'; | ||
|
||
const meta = { | ||
title: 'File Icon', | ||
component: FileIcon, | ||
tags: ['autodocs'], | ||
parameters: { | ||
docs: { | ||
page: () => ( | ||
<TetDocs docs=""> | ||
<FileIconDocs /> | ||
</TetDocs> | ||
), | ||
}, | ||
}, | ||
} satisfies Meta<typeof FileIcon>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
iconType: 'Archive', | ||
size: 'Large', | ||
}, | ||
}; |
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,9 @@ | ||
import { BaseProps } from '@/types'; | ||
|
||
export type FileIconConfig = BaseProps; | ||
|
||
export const defaultConfig = {} satisfies FileIconConfig; | ||
|
||
export const fileIconStyles = { | ||
defaultConfig, | ||
}; |
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,24 @@ | ||
import { FileIcon } from './FileIcon'; | ||
|
||
import { customPropTester } from '@/tests/customPropTester'; | ||
import { render } from '@/tests/render'; | ||
|
||
const getFileIcon = (jsx: JSX.Element) => { | ||
const { getByTestId } = render(jsx); | ||
|
||
return getByTestId('file-icon'); | ||
}; | ||
|
||
describe('FileIcon', () => { | ||
customPropTester(<FileIcon iconType="Photoshop" />, { | ||
containerId: 'file-icon', | ||
props: { | ||
size: ['Large', 'Medium'], | ||
}, | ||
}); | ||
|
||
it('should render the file icon', () => { | ||
const fileIcon = getFileIcon(<FileIcon iconType="Photoshop" />); | ||
expect(fileIcon).toBeInTheDocument(); | ||
}); | ||
}); |
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,23 @@ | ||
import { useMemo, type FC } from 'react'; | ||
|
||
import { FileIconProps } from './FileIcon.props'; | ||
import { stylesBuilder } from './stylesBuilder'; | ||
import { renderProperIcon } from './utils'; | ||
|
||
import { tet } from '@/tetrisly'; | ||
import type { MarginProps } from '@/types'; | ||
|
||
export const FileIcon: FC<FileIconProps & MarginProps> = ({ | ||
iconType, | ||
size = 'Large', | ||
custom, | ||
...restProps | ||
}) => { | ||
const styles = useMemo(() => stylesBuilder(custom), [custom]); | ||
|
||
return ( | ||
<tet.div {...styles.container} data-testid="file-icon" {...restProps}> | ||
{renderProperIcon(iconType, size)} | ||
</tet.div> | ||
); | ||
}; |
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,2 @@ | ||
export { FileIcon } from './FileIcon'; | ||
export type { FileIconProps } from './FileIcon.props'; |
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,18 @@ | ||
import { defaultConfig, FileIconConfig } from './FileIcon.styles'; | ||
|
||
import { mergeConfigWithCustom } from '@/services'; | ||
import { BaseProps } from '@/types'; | ||
|
||
type StylesBuilderParams = { | ||
container: BaseProps; | ||
}; | ||
|
||
export const stylesBuilder = (custom?: FileIconConfig): StylesBuilderParams => { | ||
const { ...container } = mergeConfigWithCustom({ defaultConfig, custom }); | ||
|
||
return { | ||
container: { | ||
...container, | ||
}, | ||
}; | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
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,54 @@ | ||
import { FileIcon } from '@/components/FileIcon/FileIcon'; | ||
import { tet } from '@/tetrisly'; | ||
|
||
const iconTypes = [ | ||
'Sketch', | ||
'Photoshop', | ||
'Excel', | ||
'Word', | ||
'Pdf', | ||
'Spreadsheet', | ||
'Document', | ||
'File', | ||
'Archive', | ||
'Figma', | ||
] as const; | ||
|
||
export const FileIconDocs = () => ( | ||
<tet.section py="$space-component-padding-4xLarge"> | ||
<tet.div px="$dimension-1000" py="$dimension-500"> | ||
<tet.div display="flex" gap="30px 50px" flexWrap="wrap"> | ||
{iconTypes.map((iconType) => ( | ||
<tet.div | ||
display="flex" | ||
flexDirection="column" | ||
alignItems="center" | ||
w="64px" | ||
> | ||
<tet.div marginBottom="5px" color="rgb(85, 95, 109)"> | ||
{iconType} | ||
</tet.div> | ||
<tet.div | ||
key={iconType} | ||
display="flex" | ||
flexDirection="column" | ||
flexShrink="0" | ||
flexGrow="1" | ||
w="64px" | ||
h="128px" | ||
border="1.2px dashed" | ||
borderColor="rgba(151, 71, 255, 1)" | ||
borderRadius="8px" | ||
opacity="0px" | ||
padding="16px" | ||
gap="16px" | ||
> | ||
<FileIcon iconType={iconType} size="Large" /> | ||
<FileIcon iconType={iconType} size="Medium" /> | ||
</tet.div> | ||
</tet.div> | ||
))} | ||
</tet.div> | ||
</tet.div> | ||
</tet.section> | ||
); |
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