Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit 7ffe563

Browse files
lekoafTigge
authored andcommitted
docs: improve Tab component example
The tab example wasn't very clear, so I added a bit more real world example feel to it. Fixes #23.
1 parent 3fd56a5 commit 7ffe563

File tree

1 file changed

+76
-44
lines changed
  • packages/docs/src/mdx/coreComponents

1 file changed

+76
-44
lines changed

packages/docs/src/mdx/coreComponents/Tab.mdx

Lines changed: 76 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ import {
1111
VerticalTab,
1212
TabBase,
1313
Typography,
14+
Paper,
1415
} from 'practical-react-components-core'
15-
import { DeviceIcon } from 'practical-react-components-icons'
16+
import {
17+
HomeIcon,
18+
SystemAccessoriesIcon,
19+
} from 'practical-react-components-icons'
1620

1721
# Tab
1822

@@ -48,75 +52,103 @@ export const VContainer = styled.div`
4852
export const HTABS = [
4953
{
5054
id: '1',
51-
label: 'Large device',
52-
icon: DeviceIcon,
55+
label: 'Home',
56+
icon: HomeIcon,
5357
},
5458
{
5559
id: '2',
56-
label: 'Very large device',
60+
label: 'Contact',
61+
icon: SystemAccessoriesIcon,
5762
},
5863
]
5964

6065
export const VTABS = [
6166
{
62-
id: '3',
63-
label: 'Tiny cup',
64-
icon: DeviceIcon,
67+
id: '1',
68+
label: 'Home',
69+
icon: HomeIcon,
6570
},
6671
{
67-
id: '4',
68-
label: 'Cup',
72+
id: '2',
73+
label: 'Contact',
74+
icon: SystemAccessoriesIcon,
6975
},
7076
]
7177

7278
export const Container = styled.div`
7379
display: ${({ show }) => (show ? 'unset' : 'none')};
7480
`
7581

82+
export const ExamplePaper = styled(Paper)`
83+
background-color: ${({ theme }) => theme.color.background03()};
84+
`
85+
86+
export const TabPaper = styled(Paper)`
87+
max-width: 500px;
88+
margin: 0 12px;
89+
`
90+
7691
export const DemoComponent = ({}) => {
77-
const [selectedTab, setSelectedTab] = useState('none')
92+
const [selectedHTab, setSelectedHTab] = useState('1')
93+
const [selectedVTab, setSelectedVTab] = useState('1')
7894
return (
7995
<>
80-
<HorizontalTabContainer>
81-
{HTABS.map(tab => (
82-
<Tab
83-
key={tab.id}
84-
id={tab.id}
85-
label={tab.label}
86-
icon={tab.icon}
87-
selected={tab.id === selectedTab}
88-
onSelect={setSelectedTab}
89-
className="my-tab"
90-
/>
91-
))}
92-
</HorizontalTabContainer>
93-
<Container show={selectedTab === '1'}>
94-
<Typography variant="page-heading">1</Typography>
95-
</Container>
96-
<Container show={selectedTab === '2'}>
97-
<Typography variant="page-heading">2</Typography>
98-
</Container>
99-
<br />
100-
<VContainer>
101-
<VerticalTabContainer>
102-
{VTABS.map(tab => (
103-
<VerticalTab
96+
<ExamplePaper space={true}>
97+
<HorizontalTabContainer>
98+
{HTABS.map(tab => (
99+
<Tab
104100
key={tab.id}
105101
id={tab.id}
106102
label={tab.label}
107103
icon={tab.icon}
108-
selected={tab.id === selectedTab}
109-
onSelect={setSelectedTab}
104+
selected={tab.id === selectedHTab}
105+
onSelect={setSelectedHTab}
106+
className="my-tab"
110107
/>
111108
))}
112-
</VerticalTabContainer>
113-
<Container show={selectedTab === '3'}>
114-
<Typography variant="page-heading">3</Typography>
109+
</HorizontalTabContainer>
110+
<Container show={selectedHTab === '1'}>
111+
<TabPaper space={true}>
112+
<Typography variant="page-heading">Home tab</Typography>
113+
<Typography>This is the content of the Home tab.</Typography>
114+
</TabPaper>
115115
</Container>
116-
<Container show={selectedTab === '4'}>
117-
<Typography variant="page-heading">4</Typography>
116+
<Container show={selectedHTab === '2'}>
117+
<TabPaper space={true}>
118+
<Typography variant="page-heading">Contact tab</Typography>
119+
<Typography>This is the content of the Contact tab.</Typography>
120+
</TabPaper>
118121
</Container>
119-
</VContainer>
122+
</ExamplePaper>
123+
<br />
124+
<ExamplePaper space={true}>
125+
<VContainer>
126+
<VerticalTabContainer>
127+
{VTABS.map(tab => (
128+
<VerticalTab
129+
key={tab.id}
130+
id={tab.id}
131+
label={tab.label}
132+
icon={tab.icon}
133+
selected={tab.id === selectedVTab}
134+
onSelect={setSelectedVTab}
135+
/>
136+
))}
137+
</VerticalTabContainer>
138+
<Container show={selectedVTab === '1'}>
139+
<TabPaper space={true}>
140+
<Typography variant="page-heading">Home tab</Typography>
141+
<Typography>This is the content of the Home tab.</Typography>
142+
</TabPaper>
143+
</Container>
144+
<Container show={selectedVTab === '2'}>
145+
<TabPaper space={true}>
146+
<Typography variant="page-heading">Contact tab</Typography>
147+
<Typography>This is the content of the Contact tab.</Typography>
148+
</TabPaper>
149+
</Container>
150+
</VContainer>
151+
</ExamplePaper>
120152
</>
121153
)
122154
}
@@ -128,8 +160,8 @@ export const DemoComponent = ({}) => {
128160
```typescript type=live
129161
<Tab
130162
id="id1"
131-
label="Large device"
132-
icon={DeviceIcon}
163+
label="Home"
164+
icon={HomeIcon}
133165
selected={true}
134166
onSelect={() => {}}
135167
/>

0 commit comments

Comments
 (0)