-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move state for widget-tabs to app
- Loading branch information
1 parent
ec8c1e9
commit 0e7efeb
Showing
3 changed files
with
37 additions
and
41 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 |
---|---|---|
|
@@ -3,4 +3,5 @@ node_modules | |
/*.log | ||
*.lock | ||
|
||
package-lock.json | ||
package-lock.json | ||
.firebase |
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
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 |
---|---|---|
@@ -1,44 +1,19 @@ | ||
import { useEffect, useState } from 'preact/compat' | ||
import Tabs from '../tabs' | ||
import TabList from '../tab-list' | ||
import TabButton from '../tab-button' | ||
import TabPanel from '../tab-panel' | ||
import { TabsEnum } from '../../constants/tabs' | ||
|
||
const DEFAULT_ACTIVE_TAB = TabsEnum.FILE | ||
const DEFAULT_TABS = Object.values(TabsEnum) | ||
|
||
const WidgetTabs = props => { | ||
const [activeTab, setActiveTab] = useState(props.activeTab || DEFAULT_ACTIVE_TAB) | ||
const [tabs, setTabs] = useState(props.tabs || DEFAULT_TABS) | ||
|
||
useEffect(() => { | ||
setTabs(props.tabs) | ||
}, [props.tabs]) | ||
|
||
useEffect(() => { | ||
setActiveTab(props.activeTab) | ||
}, [props.activeTab]) | ||
|
||
const onClickTab = (tab) => { | ||
return e => { | ||
e.preventDefault() | ||
setActiveTab(tab) | ||
} | ||
} | ||
|
||
return ( | ||
<Tabs> | ||
<TabList> | ||
{tabs.map((tab) => ( | ||
<TabButton tab={tab} onClick={onClickTab(tab)} isActive={tab === activeTab}> | ||
{tab} | ||
</TabButton> | ||
))} | ||
</TabList> | ||
<TabPanel activeTab={activeTab} /> | ||
</Tabs> | ||
) | ||
} | ||
const WidgetTabs = ({tabs, activeTab, onClick}) => ( | ||
<Tabs> | ||
<TabList> | ||
{tabs.map((tab) => ( | ||
<TabButton tab={tab} onClick={onClick(tab)} isActive={tab === activeTab}> | ||
{tab} | ||
</TabButton> | ||
))} | ||
</TabList> | ||
<TabPanel activeTab={activeTab} /> | ||
</Tabs> | ||
) | ||
|
||
export default WidgetTabs |