Poll Bars
React Native (Expo)
A React Native poll whose options turn into animated result bars with percentages once a vote is cast.
A poll. Before anyone has voted each option is a button. After a vote the options turn into bars that grow to each one's share of the votes, with percentages, and the chosen option is marked. Results are read out for each option, along with which one is yours. Built for React Native and Expo with react-native only; this page previews it in the browser through react-native-web.
Installation
CLI
npx @modus-ui/cli add poll-barsManual
- Copy the code from the component tab.
- Create a file at
components/ui/poll-bars.tsx. - Paste the code.
It needs no packages beyond react-native, which your Expo or React Native app already has.
Usage
tsx
Props
| Prop | Type | Default | Description |
|---|---|---|---|
options | PollOption[] | - | The choices, each with an id, a label and its votes. |
selected | string | - | The id voted for; once set, results show. |
onVote | (id: string) => void | - | Called with the id when an option is pressed. |
colors | Partial<PollBarsColors> | - | Overrides bar, chosenBar, surface, border and text. |
style | StyleProp<ViewStyle> | - | Style for the poll. |
Comments