1
0
mirror of https://github.com/phuoc-ng/csslayout.git synced 2025-08-06 06:07:33 +02:00

feat: Tab

This commit is contained in:
Phuoc Nguyen
2022-09-21 15:56:16 +07:00
parent 151fed0eaa
commit ab1e4a12c4
7 changed files with 99 additions and 171 deletions

View File

@@ -0,0 +1,11 @@
<div class="tab">
<div class="tab__item tab__item--active">
{% circle %}
</div>
<div class="tab__item tab__item--inactive">
{% circle %}
</div>
<div class="tab__item tab__item--inactive">
{% circle %}
</div>
</div>

View File

@@ -129,6 +129,7 @@ eleventyExcludeFromCollections: true
{% pattern "Circular navigation" %}{% include "covers/circular-navigation.njk" %}{% endpattern %}
{% pattern "Dot navigation" %}{% include "covers/dot-navigation.njk" %}{% endpattern %}
{% pattern "Drawer" %}{% include "covers/drawer.njk" %}{% endpattern %}
{% pattern "Tab" %}{% include "covers/tab.njk" %}{% endpattern %}
{% pattern "Wizard" %}{% include "covers/wizard.njk" %}{% endpattern %}
</div>
</div>

58
contents/tab.md Normal file
View File

@@ -0,0 +1,58 @@
---
layout: layouts/post.njk
title: Tab
description: Create tabs with CSS flexbox
keywords: css flexbox, css navigation, css tab
---
## HTML
```html
<div class="tab">
<!-- Active tab -->
<div class="tab__item tab__item--active">
...
</div>
<!-- Inactive tab -->
<div class="tab__item tab__item--inactive">
...
</div>
</div>
```
## CSS
```css
.tab {
/* Center the content */
align-items: center;
display: flex;
justify-content: center;
}
.tab__item {
border-top-left-radius: 0.25rem;
border-top-right-radius: 0.25rem;
padding: 0.5rem 1rem;
}
.tab__item--active {
/* Border */
border: 1px solid #d1d5db;
/* Hide the bottom border */
border-bottom-color: transparent;
/* Border radius */
border-top-left-radius: 2px;
border-top-right-radius: 2px;
}
.tab__item--inactive {
/* Has only the bottom border */
border-bottom: 1px solid #d1d5db;
}
```
{% demo %}{% include "covers/tab.njk" %}{% enddemo %}

View File

@@ -1,122 +0,0 @@
import * as React from 'react';
import Head from 'next/head';
import { Pattern } from '../../constants/Pattern';
import { PatternLayout } from '../../layouts/PatternLayout';
import BrowserFrame from '../../placeholders/BrowserFrame';
import Rectangle from '../../placeholders/Rectangle';
interface TabProps {
tabIndex: number;
}
const Details: React.FC<{}> = () => {
const [activeTab, setActiveTab] = React.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 #d1d5db',
borderBottomColor: isActive ? 'transparent' : '#d1d5db',
borderTopLeftRadius: '4px',
borderTopRightRadius: '4px',
cursor: 'pointer',
padding: '16px',
}}
onClick={click}
>
{children}
</div>
);
};
return (
<PatternLayout pattern={Pattern.Tab}>
<Head>
<meta name="description" content="Create tabs with CSS flexbox" />
<meta name="og:description" content="Create tabs with CSS flexbox" />
<meta name="twitter:description" content="Create tabs with CSS flexbox" />
<meta name="keywords" content="css flexbox, css navigation, css tab" />
</Head>
<BrowserFrame
html={`
<div class="tabs">
<!-- Active tab -->
<div class="tabs__tab--active">
...
</div>
<!-- Inactive tab -->
<div class="tabs__tab--inactive">
...
</div>
</div>
`}
css={`
.tabs {
/* Center the content */
align-items: center;
display: flex;
justify-content: center;
}
.tabs__tab--active {
/* Border */
border: 1px solid #d1d5db;
/* Hide the bottom border */
border-bottom-color: transparent;
/* Border radius */
border-top-left-radius: 2px;
border-top-right-radius: 2px;
}
.tabs__tab--inactive {
/* Has only the bottom border */
border-bottom: 1px solid #d1d5db;
}
`}
>
<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>
</BrowserFrame>
</PatternLayout>
);
};
export default Details;

View File

@@ -1,49 +0,0 @@
import * as React from 'react';
import Circle from '../../placeholders/Circle';
import Frame from '../../placeholders/Frame';
const Cover: React.FC<{}> = () => {
return (
<Frame>
<div
style={{
alignItems: 'center',
display: 'flex',
flexDirection: 'column',
height: '100%',
justifyContent: 'center',
padding: '8px',
}}
>
<div
style={{
alignItems: 'center',
display: 'flex',
justifyContent: 'center',
}}
>
<div
style={{
border: '1px solid #d1d5db',
borderBottomColor: 'transparent',
borderTopLeftRadius: '4px',
borderTopRightRadius: '4px',
padding: '4px 8px',
}}
>
<Circle size={8} />
</div>
<div style={{ borderBottom: '1px solid #d1d5db', padding: '4px 8px' }}>
<Circle size={8} />
</div>
<div style={{ borderBottom: '1px solid #d1d5db', padding: '4px 8px' }}>
<Circle size={8} />
</div>
</div>
</div>
</Frame>
);
};
export default Cover;

View File

@@ -90,6 +90,7 @@
@import './patterns/sticky-table-column';
@import './patterns/sticky-table-headers';
@import './patterns/switch';
@import './patterns/tab';
@import './patterns/teardrop';
@import './patterns/three-dimensions-card';
@import './patterns/timeline';

28
styles/patterns/_tab.scss Normal file
View File

@@ -0,0 +1,28 @@
.tab {
/* Center the content */
align-items: center;
display: flex;
justify-content: center;
}
.tab__item {
border-top-left-radius: 0.25rem;
border-top-right-radius: 0.25rem;
padding: 0.5rem 1rem;
}
.tab__item--active {
/* Border */
border: 1px solid #d1d5db;
/* Hide the bottom border */
border-bottom-color: transparent;
/* Border radius */
border-top-left-radius: 2px;
border-top-right-radius: 2px;
}
.tab__item--inactive {
/* Has only the bottom border */
border-bottom: 1px solid #d1d5db;
}