-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
陶雅阁
authored and
陶雅阁
committed
Jul 13, 2022
1 parent
9f1c250
commit 4fe21ed
Showing
7 changed files
with
114 additions
and
14 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 |
---|---|---|
@@ -1 +1,17 @@ | ||
import React from 'react'; | ||
import InternalSidebar from '@/sidebar/sidebar'; | ||
import SidebarItem from '@/sidebar/sidebar-item'; | ||
|
||
export type { SidebarProps } from '@/sidebar/sidebar'; | ||
export type { SidebarItemProps } from '@/sidebar/sidebar-item'; | ||
|
||
type InternalSidebarType = typeof InternalSidebar; | ||
|
||
export interface SidebarInterface extends InternalSidebarType { | ||
Item: typeof SidebarItem; | ||
} | ||
|
||
const Sidebar = InternalSidebar as SidebarInterface; | ||
|
||
Sidebar.Item = SidebarItem; | ||
|
||
export default Sidebar; |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
|
||
export interface SidebarItemProps { | ||
key: string; | ||
title: React.ReactNode; | ||
className?: string; | ||
children: React.ReactNode; | ||
} | ||
|
||
const SidebarItem: React.FC<SidebarItemProps> = React.memo((props) => { | ||
return props.children as React.ReactElement; | ||
}); | ||
|
||
SidebarItem.displayName = 'SidebarItem'; | ||
|
||
export default SidebarItem; |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
|
||
import SidebarItem from '@/sidebar/sidebar-item'; | ||
|
||
export interface SidebarProps { | ||
activeKey: string; | ||
onChange?: (key: string) => void; | ||
children?: React.ReactNode; | ||
} | ||
|
||
const classPrefix = `ygm-sidebar`; | ||
|
||
const Sidebar: React.FC<SidebarProps> = React.memo((props) => { | ||
const [activeKey, setActiveKey] = React.useState<string>(props.activeKey); | ||
|
||
const items: React.ReactElement<React.ComponentProps<typeof SidebarItem>>[] = []; | ||
|
||
React.Children.forEach(props.children, (child) => { | ||
if (!React.isValidElement(child)) return; | ||
if (!child.key) return; | ||
items.push(child); | ||
}); | ||
|
||
const onItem = React.useCallback(() => {}, []); | ||
|
||
return ( | ||
<div className={classPrefix}> | ||
<div className={`${classPrefix}-items`}> | ||
{items.map((item) => { | ||
const active = item.key === activeKey; | ||
|
||
return ( | ||
<div | ||
className={cx(`${classPrefix}-item`, { | ||
[`${classPrefix}-item-active`]: active, | ||
})} | ||
key={item.key} | ||
onClick={onItem} | ||
> | ||
<div className={`${classPrefix}-item-title`}>{item.props.title}</div> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
|
||
{items.map((item) => ( | ||
<div key={item.key} className={`${classPrefix}-content`}> | ||
{item.props.children} | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}); | ||
|
||
Sidebar.displayName = 'Sidebar'; | ||
|
||
export default Sidebar; |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@import '../../styles/variable.scss'; | ||
|
||
$class-prefix-space: 'ygm-sidebar'; | ||
|
||
.#{$class-prefix-tabs} { | ||
--height: 100%; | ||
--width: 105px; | ||
--item-border-radius: 8px; | ||
--background-color: ; | ||
} |
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,17 +1,17 @@ | ||
import Tabs from '@/tabs/tabs'; | ||
import InternalTabs from '@/tabs/tabs'; | ||
import Tab from '@/tabs/tab'; | ||
|
||
export type { TabsProps } from '@/tabs/tabs'; | ||
export type { TabProps } from '@/tabs/tab'; | ||
|
||
type TTabs = typeof Tabs; | ||
type InternalTabsType = typeof InternalTabs; | ||
|
||
export interface ITabs extends TTabs { | ||
export interface TabsInterface extends InternalTabsType { | ||
Tab: typeof Tab; | ||
} | ||
|
||
const MyTabs: ITabs = Tabs as ITabs; | ||
const Tabs = InternalTabs as TabsInterface; | ||
|
||
MyTabs.Tab = Tab; | ||
Tabs.Tab = Tab; | ||
|
||
export default MyTabs; | ||
export default Tabs; |
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