-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathInlinePicker.tsx
More file actions
46 lines (43 loc) · 1.35 KB
/
InlinePicker.tsx
File metadata and controls
46 lines (43 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { useState } from 'react'
import Picker from 'react-mobile-picker'
function renderOptions(options: string[], selectedColor: string) {
return options.map((option) => (
<Picker.Item key={option} value={option}>
{({ selected }) => (
<div className={selected ? `font-semibold ${selectedColor}` : 'text-neutral-400'}>{option}</div>
)}
</Picker.Item>
))
}
export default function InlinePicker() {
const [pickerValue, setPickerValue] = useState({
title: 'Mr.',
firstName: 'Micheal',
lastName: 'Jordan'
})
return <>
<div
className="
mb-2 px-4 h-12 flex items-center bg-white
border-t border-b border-gray-200 border-solid
"
>Hi, {pickerValue.title} {pickerValue.firstName} {pickerValue.lastName}</div>
<Picker
className="px-4"
value={pickerValue}
onChange={setPickerValue}
wheelMode="natural"
mouseMode="drag"
>
<Picker.Column name="title">
{renderOptions(['Mr.', 'Mrs.', 'Ms.', 'Dr.'], 'text-red-600')}
</Picker.Column>
<Picker.Column name="firstName">
{renderOptions(['John', 'Micheal', 'Elizabeth'], 'text-yellow-600')}
</Picker.Column>
<Picker.Column name="lastName">
{renderOptions(['Lennon', 'Jackson', 'Jordan', 'Legend', 'Taylor'], 'text-green-600')}
</Picker.Column>
</Picker>
</>
}