11import React , { FC , useMemo } from "react" ;
2- import { styled } from "goober" ;
2+ import { styled } from "goober" ;
33import { IEditorTabs , ISnippet } from "../types" ;
44import EditorSetup from "./EditorSetup" ;
55import { ITabConfig } from "../types" ;
@@ -12,7 +12,7 @@ import {
1212} from "../TabStyles" ;
1313
1414const TabContainer = styled ( StyledTabs ) `
15- min-width: ${ props => props . theme . container . minWidth } ;
15+ min-width: ${ ( props ) => props . theme . container . minWidth } ;
1616` ;
1717
1818interface IProps {
@@ -23,34 +23,44 @@ interface IProps {
2323}
2424
2525const Editor : FC < IProps > = ( { code, defaultTab, onChange, width } ) => {
26- const tabs : Readonly < ITabConfig < IEditorTabs > [ ] > = useMemo (
27- ( ) => [
28- { name : "HTML" , value : "markup" } ,
29- { name : "CSS" , value : "css" } ,
30- { name : "JS" , value : "javascript" } ,
31- ] ,
32- [ ]
33- ) ;
26+ const tabs : Readonly < ITabConfig < IEditorTabs > [ ] > = useMemo ( ( ) => {
27+ const tabsArr = [ ] ;
28+ if ( code . markup ) {
29+ tabsArr . push ( { name : "HTML" , value : "markup" , code : code . markup } ) ;
30+ }
31+ if ( code . css ) {
32+ tabsArr . push ( { name : "CSS" , value : "css" , code : code . css } ) ;
33+ }
34+ if ( code . javascript ) {
35+ tabsArr . push ( { name : "JS" , value : "javascript" , code : code . javascript } ) ;
36+ }
37+ return tabsArr ;
38+ } , [ ] ) ;
3439 return (
3540 < TabContainer
36- defaultIndex = { tabs . findIndex ( tab => tab . value === defaultTab ) }
41+ defaultIndex = { tabs . findIndex (
42+ ( tab ) => tab . code && tab . value === defaultTab
43+ ) }
3744 style = { { width : width } }
3845 >
3946 < StyledTabList >
40- { tabs . map ( tab => (
41- < StyledTab key = { tab . value } > { tab . name } </ StyledTab >
42- ) ) }
47+ { tabs . map (
48+ ( tab ) => tab . code && < StyledTab key = { tab . value } > { tab . name } </ StyledTab >
49+ ) }
4350 </ StyledTabList >
4451 < StyledTabPanels >
45- { tabs . map ( tab => (
46- < StyledTabPanel key = { tab . value } >
47- < EditorSetup
48- code = { code [ tab . value ] }
49- onChange = { onChange }
50- language = { tab . value }
51- />
52- </ StyledTabPanel >
53- ) ) }
52+ { tabs . map (
53+ ( tab ) =>
54+ tab . code && (
55+ < StyledTabPanel key = { tab . value } >
56+ < EditorSetup
57+ code = { tab . code }
58+ onChange = { onChange }
59+ language = { tab . value }
60+ />
61+ </ StyledTabPanel >
62+ )
63+ ) }
5464 </ StyledTabPanels >
5565 </ TabContainer >
5666 ) ;
0 commit comments