@gfazioli/mantine-picker
A Mantine component that allows you to create a picker effect with a list of elements.
Installation
After installation import package styles at the root of your application:
You can import styles within a layer @layer mantine-picker
by importing @gfazioli/mantine-picker/styles.layer.css
file.
Usage
The Picker
component allows you to create a picker effect with any list of items.
It's inspired by the iOS picker and allows you to create a similar effect with any list of items.
- You can drag up and down to select the item you want
- You may also use the mouse wheel to scroll through the items
- Of course, you can also click on the item to select it
- Finally, you can use the keyboard to navigate through the items
Value: Rome
onChange
You can use the onChange
prop to get the selected item. It is called whenever the selected value changes, allowing you to handle the selection logic in your application. Of course, you can also use the value
prop to control the selected item.
Value: April
renderItem
You can use the renderItem
prop to customize the rendering of each item. This prop receives the item
as arguments and should return the JSX to be rendered.
Value:
Left and Right Sections
You can use the leftSection
and rightSection
props to add custom content to the left and right sides of the picker. This is useful for adding icons, buttons, or any other content you want.
As you can see, by using leftSection
and rightSection
props you can add any content you want to the left and right sides of the picker. In these cases the sections are fixed and do not scroll with the items. They will also inside the picker.
Alternatively, you can use a simple <Group/>
component to add any left (center) and right section you want.
👉
👈
:
Styles the Picker
You can change the default styles of the items by using the same props you use in the <Text/>
component.
readOnly
In addition to the disabled
prop, you can use the readOnly
prop to make the picker read-only. This will prevent the user from changing the selected item, but will still allow you to change it programmatically. It can be useful when you want to display the selected item without allowing the user to change it.
Example: Time Picker
The Picker
component can be used as a Time Picker. You can use the renderItem
prop to customize the rendering of each item and the onChange
prop to handle the selection logic. In this example, we will create a simple time picker that allows you to select the hour and minute.
🕑
:
min
Selected time: 16:31
:
Selected time: 04:31 pm
Example: Date Picker
The Picker
component can be used as a Date Picker.
Selected date: 14 April 2025
Example: Slot Machine
As funny as it may sound, the Picker
component can be used to create a slot machine effect.
🎉 Jackpot! 🎉