Pro (paid add-on)
Polls
ProPollBuilder is a ready-made form for creating a poll, with a live preview beside it. PollResultsChart shows the results as a chart with a data table. Both work with the free [Poll](/docs/components/poll).
Part of Pro
This page documents part of @vjdesigns-pro/ui, the paid add-on package. Using it needs a Pro license and @vjdesigns/vjdesigns-ui 3.8.0 or later. Like the free package, it works in both modes, every brand, all 32 languages and right to left. Install it as described in Account forms.
Example
PollBuilder asks for the question, 2 to 10 options, whether people can pick more than one (and how many), an end date, and when results show. It catches empty and duplicate options, and onSubmit gets a PollDefinition that you can pass straight to the free Poll.
import { PollBuilder } from "@vjdesigns-pro/ui";
import { Poll } from "@vjdesigns/vjdesigns-ui";
<PollBuilder title="Create a poll" onSubmit={savePoll} onSuccess={setPoll} />
// The PollDefinition it returns passes straight to the free Poll:
<Poll {...poll} options={withVoteCounts(poll.options)} onVote={vote} />
Building a poll
- Options can be added, removed and reordered with buttons, so no dragging is needed.
showPreviewshows a livePollbeside the form, in thebarsorcompactlayout (previewLayout).minOptions,maxOptions,allowMultipleandallowEndDateset what the form offers, anddefaultValuestarts from a template or a draft.- Return an
errorfromonSubmitto show a server error.
Results chart
PollResultsChart takes the same options you pass to Poll and draws them as a donut (parts of the whole, with the total in the middle) or a bar chart (easier to compare close results). It's one of the Pro charts, so it has a legend, keyboard access and a data table.
<PollResultsChart
title="When should the summer league play?"
description="Saturday morning won by a wide margin."
options={options}
kind="bar"
/>
Accessible by default
- Moving an option keeps focus on it and announces its new place ("Moved to position 2 of 4"); removing one moves focus to a neighbor and announces it.
- Each move and remove button is named for its option ("Move option 3 up").
- The form lists problems in an error summary, and the preview is a labeled region.
Props
PollBuilder
A ready-made "create a poll" form: the question, 2 to 10 options (add, remove, and reorder them with buttons), multiple choice with a limit, an end date, and when results show, beside a live Poll preview. Validates required and duplicate options, and returns a PollDefinition you can pass straight to Poll.
| Prop | Type | Default |
|---|---|---|
onSubmitRequiredCalls your backend with the new poll. | (poll: PollDefinition) => PollSubmitResult | Promise<PollSubmitResult> | — |
onSuccessCalled after | (poll: PollDefinition) => void | — |
defaultValuePrefilled poll, e.g. a template or a draft. | Partial<PollDefinition> | — |
minOptionsFewest options. | number | 2 |
maxOptionsMost options. | number | 10 |
allowMultipleOffer "Allow multiple choices". | boolean | true |
allowEndDateOffer an end date. | boolean | true |
showPreviewShow a live | boolean | true |
previewLayoutLayout of the preview poll. | "bars""compact" | "bars" |
titleHeading. Pass | ReactNode | "Create a poll" |
descriptionText under the heading. | ReactNode | — |
headingLevelHeading level. | 123456 | 2 |
submitLabelSubmit button text. | ReactNode | "Create poll" |
variant
| "card""plain" | "card" |
classNameClass name for the root. | string | — |
styleStyle for the root. | CSSProperties | — |
PollResultsChart
A poll's results as an accessible Pro chart: a donut (with the total in the middle) or a bar chart, with a legend, keyboard-explorable marks, and a data table. For dashboards and detailed results views.
| Prop | Type | Default |
|---|---|---|
titleRequiredThe chart's title, e.g. the poll question. Names the figure. | string | — |
descriptionOne-sentence takeaway under the title. | ReactNode | — |
optionsRequiredThe poll's options with their vote counts (the same array you pass to | readonly PollOption[] | — |
kind
| "donut""bar" | "donut" |
defaultShowTableShow the data table instead of the chart at first. | boolean | false |
classNameClass name for the figure. | string | — |
styleStyle for the figure. | CSSProperties | — |
PollDefinition
A poll as PollBuilder creates it. Spread it straight into Poll: <Poll {...definition} />.
| Prop | Type | Default |
|---|---|---|
questionRequired | string | — |
optionsRequiredThe choices, in order. | { value: string; label: string; }[] | — |
multipleRequired | boolean | — |
maxChoicesWith | number | — |
endsAtISO date ("YYYY-MM-DD"): voting closes at the end of that day. | string | — |
showResultsRequired | "after-vote""always""never" | — |
PollSubmitResult
What a PollBuilder onSubmit handler returns. Return nothing when it worked; error for one message above the form, and/or fieldErrors by field name (question, endsAt, maxChoices).
| Prop | Type | Default |
|---|---|---|
error | ReactNode | — |
fieldErrors | FormErrors | — |