From 352b6eda5dfb31ab50d64032a0578f62db7490ab Mon Sep 17 00:00:00 2001 From: DBSDs <379712747@qq.com> Date: Wed, 30 Nov 2022 02:21:05 +0800 Subject: [PATCH] feat: tab.action&tab.extra feat: Tab component Extra & Action fix: remove useless code fix: remove useless code --- docs/guide/page-tab.md | 13 ++++ examples/normal/a.tsx | 4 ++ .../slots/ContentTabs/index.less | 72 +++++++++++-------- .../theme-default/slots/ContentTabs/index.tsx | 44 ++++++++---- 4 files changed, 87 insertions(+), 46 deletions(-) diff --git a/docs/guide/page-tab.md b/docs/guide/page-tab.md index 49da1dc2f3..a7f309d369 100644 --- a/docs/guide/page-tab.md +++ b/docs/guide/page-tab.md @@ -36,4 +36,17 @@ export default (api: IApi) => { }; ``` +```ts +// a.tsx +import React from 'react'; + +export default () => <>Hi, hello; + +export const Extra = () => <>😄; + +export const Action = () => <>🏀; + +``` + `component` 放入我们自定义的 Tab 内容,`test` 可以写入正则来匹配路由,这样我们就实现了为 `/componets` 下的路由页面添加自定义 Tab。 +`component` 组件默认导出的是 Tab 页内容,`Extra` 和 `Action` 都是可选导出项,`Extra` 可以自定义每个 Tab 的紧跟内容,`Action` 可以自定义整个tab栏的右侧内容,同一路由下只有第一个 `Action` 有效。 diff --git a/examples/normal/a.tsx b/examples/normal/a.tsx index 23cb37801a..10b7ea8d82 100644 --- a/examples/normal/a.tsx +++ b/examples/normal/a.tsx @@ -1,3 +1,7 @@ import React from 'react'; export default () => <>Hi, hello; + +export const Extra = () => <>😄; + +export const Action = () => <>🏀; diff --git a/src/client/theme-default/slots/ContentTabs/index.less b/src/client/theme-default/slots/ContentTabs/index.less index 25cc0dbcac..5a3effa410 100644 --- a/src/client/theme-default/slots/ContentTabs/index.less +++ b/src/client/theme-default/slots/ContentTabs/index.less @@ -24,48 +24,58 @@ } } - > li { - height: inherit; + &-nav { + flex: auto; + display: flex; + height: 60px; - > button { - padding: 0; + >li { height: inherit; - color: @c-text-secondary; - font-size: 17px; - border: 0; - background: transparent; - cursor: pointer; - transition: all 0.2s; - &:hover { - color: @c-primary; + >button { + padding: 0; + height: inherit; + color: @c-text-secondary; + font-size: 17px; + border: 0; + background: transparent; + cursor: pointer; + transition: all 0.2s; + + &:hover { + color: @c-primary; + } } - } - &:not(last-child) { - margin-inline-end: 42px; + &:not(last-child) { + margin-inline-end: 42px; - @media @mobile { - margin-inline-end: 20px; + @media @mobile { + margin-inline-end: 20px; + } } - } - &[data-active] { - position: relative; + &[data-active] { + position: relative; - > button { - color: @c-text; - } + >button { + color: @c-text; + } - &::after { - content: ''; - position: absolute; - left: 0; - right: 0; - bottom: -1px; - height: 1px; - background-color: @c-primary; + &::after { + content: ''; + position: absolute; + left: 0; + right: 0; + bottom: -1px; + height: 1px; + background-color: @c-primary; + } } } } + + &-action { + flex: none; + } } diff --git a/src/client/theme-default/slots/ContentTabs/index.tsx b/src/client/theme-default/slots/ContentTabs/index.tsx index a5d6bb2fe9..e2f019ff02 100644 --- a/src/client/theme-default/slots/ContentTabs/index.tsx +++ b/src/client/theme-default/slots/ContentTabs/index.tsx @@ -4,6 +4,18 @@ import './index.less'; type IContentTabs = ReturnType['tabs']; +const TabsAction: FC<{ tabs: IContentTabs }> = ({ tabs }) => { + const tabActions = tabs + ?.map((tab) => tab.components.Action) + .filter((tab) => tab); + + return Boolean(tabActions?.length) ? ( +
+ {React.createElement(tabActions![0])} +
+ ) : null; +}; + export interface IContentTabsProps { tabs: IContentTabs; tabKey: string | null; @@ -17,24 +29,26 @@ const ContentTabs: FC = ({ }) => { const intl = useIntl(); - // TODO: tab.Extra & tab.Action render - return Boolean(tabs?.length) ? ( ) : null; };