mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-05-06 01:56:41 +07:00
refactor editos
This commit is contained in:
parent
03ddb1862c
commit
5e9c111e0f
149 changed files with 416 additions and 317 deletions
60
src/components/common/Tabs/index.tsx
Normal file
60
src/components/common/Tabs/index.tsx
Normal file
|
@ -0,0 +1,60 @@
|
|||
import React, { createContext, FC, useContext, useMemo, useState, VFC } from 'react';
|
||||
|
||||
import classNames from 'classnames';
|
||||
|
||||
import styles from './styles.module.scss';
|
||||
|
||||
interface TabProps {
|
||||
items: string[];
|
||||
}
|
||||
|
||||
const TabContext = createContext({
|
||||
activeTab: 0,
|
||||
setActiveTab: (activeTab: number) => {},
|
||||
});
|
||||
|
||||
const HorizontalList: VFC<TabProps> = ({ items }) => {
|
||||
const { activeTab, setActiveTab } = useContext(TabContext);
|
||||
|
||||
return (
|
||||
<div className={styles.tabs}>
|
||||
{items.map((it, index) => (
|
||||
<div
|
||||
className={classNames(styles.tab, { [styles.active]: activeTab === index })}
|
||||
onClick={() => setActiveTab(index)}
|
||||
key={it}
|
||||
>
|
||||
{it}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const Content: FC<any> = ({ children }) => {
|
||||
const { activeTab } = useContext(TabContext);
|
||||
const notEmptyChildren = useMemo(() => {
|
||||
if (!Array.isArray(children)) {
|
||||
return [children];
|
||||
}
|
||||
|
||||
return children.filter(it => it);
|
||||
}, [children]);
|
||||
|
||||
if (Array.isArray(notEmptyChildren) && notEmptyChildren.length - 1 < activeTab) {
|
||||
return notEmptyChildren[notEmptyChildren.length - 1];
|
||||
}
|
||||
|
||||
return notEmptyChildren[activeTab];
|
||||
};
|
||||
|
||||
const Tabs = function({ children }) {
|
||||
const [activeTab, setActiveTab] = useState(0);
|
||||
|
||||
return <TabContext.Provider value={{ activeTab, setActiveTab }}>{children}</TabContext.Provider>;
|
||||
};
|
||||
|
||||
Tabs.Horizontal = HorizontalList;
|
||||
Tabs.Content = Content;
|
||||
|
||||
export { Tabs };
|
32
src/components/common/Tabs/styles.module.scss
Normal file
32
src/components/common/Tabs/styles.module.scss
Normal file
|
@ -0,0 +1,32 @@
|
|||
@import 'src/styles/variables';
|
||||
|
||||
.wrap {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: flex-start;
|
||||
padding: 0 $gap * 0.5;
|
||||
}
|
||||
|
||||
.tab {
|
||||
@include outer_shadow();
|
||||
|
||||
padding: $gap;
|
||||
margin-right: $gap;
|
||||
border-radius: $radius $radius 0 0;
|
||||
font: $font_14_semibold;
|
||||
text-transform: uppercase;
|
||||
cursor: pointer;
|
||||
background-color: $content_bg;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
border: none;
|
||||
|
||||
&.active {
|
||||
background: $content_bg_lighter;
|
||||
}
|
||||
}
|
||||
|
||||
.tabs {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue