File tree Expand file tree Collapse file tree 4 files changed +50
-0
lines changed Expand file tree Collapse file tree 4 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1+ export * from './Illustration' ;
You can’t perform that action at this time.
0 commit comments