Skip to content

Commit fa29cf2

Browse files
authored
Merge pull request #22 from Commencis/feature/icons
feat: add icon component and implementations
2 parents 2ef0686 + 6105eb1 commit fa29cf2

File tree

15 files changed

+100
-9
lines changed

15 files changed

+100
-9
lines changed

.changeset/five-keys-rush.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@commencis/starter-react-vite': minor
3+
---
4+
5+
feature: `<Icon />` component and implementations

.changeset/olive-kings-fold.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@commencis/starter-react-vite': patch
3+
---
4+
5+
fix: ImportMeta types

src/assets/icons/chevron-down.svg

Lines changed: 3 additions & 0 deletions
Loading

src/assets/icons/chevron-left.svg

Lines changed: 3 additions & 0 deletions
Loading

src/assets/icons/chevron-right.svg

Lines changed: 3 additions & 0 deletions
Loading

src/assets/icons/chevron-up.svg

Lines changed: 3 additions & 0 deletions
Loading

src/components/ui/Icon/Icon.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { ReactElement, Suspense, useMemo } from 'react';
2+
3+
import { SVGComponentProps } from '@/types';
4+
5+
import { IconName } from './Icon.types';
6+
import { lazyLoadIcon } from './Icon.utils';
7+
8+
export type IconProps = {
9+
name: IconName;
10+
color?: string;
11+
} & Omit<SVGComponentProps, 'fill'>;
12+
13+
export function Icon({
14+
name,
15+
color,
16+
width = '32px',
17+
height = '32px',
18+
...props
19+
}: IconProps): ReactElement {
20+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
21+
const { ref: _, ...svgProps } = props;
22+
const IconComponent = useMemo(() => lazyLoadIcon(name), [name]);
23+
24+
return (
25+
<Suspense fallback={null}>
26+
<IconComponent width={width} height={height} fill={color} {...svgProps} />
27+
</Suspense>
28+
);
29+
}

src/components/ui/Icon/Icon.types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type IconName =
2+
| 'chevron-right'
3+
| 'chevron-left'
4+
| 'chevron-up'
5+
| 'chevron-down';

src/components/ui/Icon/Icon.utils.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { type FunctionComponent, lazy, type LazyExoticComponent } from 'react';
2+
3+
import { SVGComponentProps } from '@/types';
4+
5+
import { IconName } from './Icon.types';
6+
7+
export type LazyLoadIconReturnType = LazyExoticComponent<
8+
FunctionComponent<SVGComponentProps>
9+
>;
10+
11+
export function lazyLoadIcon(name: IconName): LazyLoadIconReturnType {
12+
return lazy(() => import(`@/assets/icons/${name}.svg`));
13+
}

src/components/ui/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './Icon/Icon';
2+
export * from './Icon/Icon.types';

0 commit comments

Comments
 (0)