Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

ApproachTabs.tsx

45 lines1.2 KB

1import { useState } from 'preact/hooks'
2import TodoListUI from './TodoListUI'
3import TodoListCache from './TodoListCache'
4import type { CSSProperties } from 'preact'
5​
6type Tab = 'ui-variables' | 'cache'
7​
8export default function ApproachTabs() {
9 const [activeTab, setActiveTab] = useState<Tab>('ui-variables')
10​
11 const tabStyle = (tab: Tab): CSSProperties => ({
12 padding: '0.5rem 1rem',
13 border: 'none',
14 borderBottom:
15 activeTab === tab ? '2px solid #0070f3' : '2px solid transparent',
16 background: 'none',
17 cursor: 'pointer',
18 fontWeight: activeTab === tab ? 600 : 400,
19 color: activeTab === tab ? '#0070f3' : '#555',
20 })
21​
22 return (
23 <div>
24 <div
25 style={{
26 display: 'flex',
27 borderBottom: '1px solid #ddd',
28 marginBottom: '1.5rem',
29 }}
30 >
31 <button
32 style={tabStyle('ui-variables')}
33 onClick={() => setActiveTab('ui-variables')}
34 >
35 Via UI Variables
36 </button>
37 <button style={tabStyle('cache')} onClick={() => setActiveTab('cache')}>
38 Via Cache Manipulation
39 </button>
40 </div>
41​
42 {activeTab === 'ui-variables' ? <TodoListUI /> : <TodoListCache />}
43 </div>
44 )