-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* *: upgrade antd from 4.2.5 to 4.8.5 * yarn upgrade dayjs --latest * fix tabs style * fix tabs style * wip * only use CardTabs as the indicator * use variables in less * refine * refactor CardTabs * refine style Co-authored-by: Wenxuan <hi@breeswish.org>
- Loading branch information
1 parent
68ca2fc
commit 8ad48d9
Showing
8 changed files
with
515 additions
and
477 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@import '~antd/es/style/themes/default.less'; | ||
|
||
.card_tab_navs { | ||
padding-left: @padding-page; // 48px | ||
padding-right: @padding-page; // 48px | ||
height: @padding-page; // 48px | ||
margin-bottom: @padding-md; // 16px | ||
border-bottom: 1px solid @gray-4; | ||
|
||
:global { | ||
.ant-tabs-ink-bar { | ||
height: @outline-width; // 2px | ||
} | ||
} | ||
} |
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
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
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,23 +1,57 @@ | ||
import React from 'react' | ||
import React, { useState } from 'react' | ||
import { Tabs } from 'antd' | ||
import cx from 'classnames' | ||
import styles from './index.module.less' | ||
import { TabsProps } from 'antd/es/tabs' | ||
|
||
type Tab = { | ||
key: string | ||
title: string | ||
content: () => React.ReactNode | ||
} | ||
|
||
export interface ICardTabsProps extends TabsProps { | ||
className?: string | ||
children?: React.ReactNode | ||
tabs: Tab[] | ||
} | ||
|
||
function renderCardTabBar(props, DefaultTabBar) { | ||
return <DefaultTabBar {...props} className={styles.card_tab_navs} /> | ||
} | ||
|
||
function CardTabs({ className, children, ...restProps }: ICardTabsProps) { | ||
function CardTabs({ | ||
className, | ||
tabs, | ||
defaultActiveKey, | ||
onChange, | ||
renderTabBar, | ||
...restProps | ||
}: ICardTabsProps) { | ||
const [tabKey, setTabKey] = useState(defaultActiveKey || tabs[0].key) | ||
const c = cx(styles.tabs, className) | ||
const selectedTab = tabs.find((tab) => tab.key === tabKey) | ||
|
||
function changeTab(tabKey) { | ||
setTabKey(tabKey) | ||
onChange && onChange(tabKey) | ||
} | ||
|
||
return ( | ||
<Tabs className={c} {...restProps}> | ||
{children} | ||
</Tabs> | ||
<> | ||
<Tabs | ||
className={c} | ||
defaultActiveKey={tabKey} | ||
onChange={changeTab} | ||
renderTabBar={renderTabBar || renderCardTabBar} | ||
{...restProps} | ||
> | ||
{tabs.map((tab) => ( | ||
<Tabs.TabPane tab={tab.title} key={tab.key} /> | ||
))} | ||
</Tabs> | ||
{selectedTab?.content()} | ||
</> | ||
) | ||
} | ||
|
||
CardTabs.TabPane = Tabs.TabPane | ||
|
||
export default CardTabs |
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
Oops, something went wrong.