1
0
mirror of https://github.com/phuoc-ng/csslayout.git synced 2025-10-24 03:06:22 +02:00
Files
csslayout/client/patterns/tab/Details.tsx
2019-12-30 22:32:06 +07:00

121 lines
3.9 KiB
TypeScript

/**
* A collection of popular layouts and patterns made with CSS (https://csslayout.io)
* (c) 2019 - 2020 Nguyen Huu Phuoc <https://twitter.com/nghuuphuoc>
*/
import React, { useState } from 'react';
import { Helmet } from 'react-helmet';
import DetailsLayout from '../../layouts/DetailsLayout';
import BrowserFrame from '../../placeholders/BrowserFrame';
import Rectangle from '../../placeholders/Rectangle';
interface TabProps {
tabIndex: number;
}
const Details: React.FC<{}> = () => {
const [activeTab, setActiveTab] = useState(0);
const Tab: React.FC<TabProps> = ({ tabIndex, children }) => {
const isActive = tabIndex === activeTab;
const click = () => setActiveTab(tabIndex);
return (
<div
style={{
[isActive ? 'border' : 'borderBottom']: '1px solid rgba(0, 0, 0, 0.3)',
borderBottomColor: isActive ? 'transparent' : 'rgba(0, 0, 0, 0.3)',
borderTopLeftRadius: '4px',
borderTopRightRadius: '4px',
cursor: 'pointer',
padding: '16px',
}}
onClick={click}
>
{children}
</div>
);
};
return (
<DetailsLayout title="Tab">
<Helmet>
<meta name="description" content="Create tabs with CSS flexbox" />
<meta name="keywords" content="css flexbox, css navigation, css tab" />
</Helmet>
<div style={{ padding: '64px 32px' }}>
<BrowserFrame
content={(
<div
style={{
alignItems: 'center',
display: 'flex',
flexDirection: 'column',
height: '100%',
justifyContent: 'center',
padding: '8px',
}}
>
<div
style={{
alignItems: 'center',
display: 'flex',
justifyContent: 'center',
}}
>
<Tab tabIndex={0}>
<div style={{ width: '64px' }}>
<Rectangle height={8} />
</div>
</Tab>
<Tab tabIndex={1}>
<div style={{ width: '32px' }}>
<Rectangle height={8} />
</div>
</Tab>
<Tab tabIndex={2}>
<div style={{ width: '128px' }}>
<Rectangle height={8} />
</div>
</Tab>
</div>
</div>
)}
source={`
<div style="
/* Center the content */
align-items: center;
display: flex;
justify-content: center;
">
<!-- Active tab -->
<div style="
/* Border */
border: 1px solid rgba(0, 0, 0, 0.3);
/* Hide the bottom border */
border-bottom-color: transparent;
/* Border radius */
border-top-left-radius: 2px;
border-top-right-radius: 2px;
">
...
</div>
<!-- Inactive tab -->
<div style="
/* Has only the bottom border */
border-bottom: 1px solid rgba(0, 0, 0, 0.3);
">
...
</div>
</div>
`}
/>
</div>
</DetailsLayout>
);
};
export default Details;