Skip to content

Commit 7d10880

Browse files
committed
feat: add Illustration component
1 parent 7cfd97e commit 7d10880

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

src/assets/illustrations/dark/403.svg

Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import {useEffect, useState} from 'react';
2+
import cn from 'bem-cn-lite';
3+
import {useThemeValue} from '@yandex-cloud/uikit';
4+
5+
export interface IllustrationProps {
6+
name: string;
7+
className?: string;
8+
}
9+
10+
type IllustrationStore = Record<string, Record<string, () => Promise<{default: any}>>>;
11+
12+
const store: IllustrationStore = {
13+
light: {
14+
403: () => import('../../assets/illustrations/light/403.svg'),
15+
},
16+
dark: {
17+
403: () => import('../../assets/illustrations/dark/403.svg'),
18+
},
19+
};
20+
21+
const b = cn('kv-illustration');
22+
23+
export const Illustration = ({name, className, ...props}: IllustrationProps) => {
24+
const theme = useThemeValue();
25+
const [src, setSrc] = useState('');
26+
const srcGetter = store[theme] && store[theme][name];
27+
28+
useEffect(() => {
29+
if (typeof srcGetter === 'function') {
30+
srcGetter()
31+
.then((svg) => setSrc(svg.default))
32+
.catch((e) => {
33+
console.error(e);
34+
setSrc('');
35+
});
36+
}
37+
}, [srcGetter]);
38+
39+
return (
40+
<img
41+
alt={name}
42+
src={src}
43+
className={b(null, className)}
44+
{...props}
45+
/>
46+
);
47+
}

src/components/Illustration/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Illustration';

0 commit comments

Comments
 (0)