@vjdesigns/vjdesigns-ui 3.6.0 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +204 -184
- package/README.md +1 -1
- package/dist/ai/llms-full.txt +268 -2
- package/dist/ai/llms.txt +5 -0
- package/dist/ai/registry.json +1010 -54
- package/dist/components/data-display/Poll/Poll.cjs.js +1 -0
- package/dist/components/data-display/Poll/Poll.d.ts +114 -0
- package/dist/components/data-display/Poll/Poll.mjs +335 -0
- package/dist/components/data-display/Poll/Poll.module.css.cjs.js +1 -0
- package/dist/components/data-display/Poll/Poll.module.css.mjs +46 -0
- package/dist/components/data-display/Poll/index.d.ts +1 -0
- package/dist/components/data-display/RatingBreakdown/RatingBreakdown.cjs.js +1 -0
- package/dist/components/data-display/RatingBreakdown/RatingBreakdown.d.ts +35 -0
- package/dist/components/data-display/RatingBreakdown/RatingBreakdown.mjs +88 -0
- package/dist/components/data-display/RatingBreakdown/RatingBreakdown.module.css.cjs.js +1 -0
- package/dist/components/data-display/RatingBreakdown/RatingBreakdown.module.css.mjs +21 -0
- package/dist/components/data-display/RatingBreakdown/index.d.ts +1 -0
- package/dist/components/data-display/ReviewCard/ReviewCard.cjs.js +1 -0
- package/dist/components/data-display/ReviewCard/ReviewCard.d.ts +67 -0
- package/dist/components/data-display/ReviewCard/ReviewCard.mjs +174 -0
- package/dist/components/data-display/ReviewCard/ReviewCard.module.css.cjs.js +1 -0
- package/dist/components/data-display/ReviewCard/ReviewCard.module.css.mjs +26 -0
- package/dist/components/data-display/ReviewCard/index.d.ts +1 -0
- package/dist/components/forms/RatingScale/RatingScale.cjs.js +1 -0
- package/dist/components/forms/RatingScale/RatingScale.d.ts +106 -0
- package/dist/components/forms/RatingScale/RatingScale.mjs +175 -0
- package/dist/components/forms/RatingScale/RatingScale.module.css.cjs.js +1 -0
- package/dist/components/forms/RatingScale/RatingScale.module.css.mjs +28 -0
- package/dist/components/forms/RatingScale/index.d.ts +1 -0
- package/dist/components/navigation/MobileNav/MobileNav.cjs.js +1 -0
- package/dist/components/navigation/MobileNav/MobileNav.d.ts +170 -0
- package/dist/components/navigation/MobileNav/MobileNav.mjs +174 -0
- package/dist/components/navigation/MobileNav/MobileNav.module.css.cjs.js +1 -0
- package/dist/components/navigation/MobileNav/MobileNav.module.css.mjs +46 -0
- package/dist/components/navigation/MobileNav/index.d.ts +1 -0
- package/dist/components/primitives/Icon/icons.cjs.js +1 -1
- package/dist/components/primitives/Icon/icons.d.ts +70 -0
- package/dist/components/primitives/Icon/icons.mjs +203 -134
- package/dist/components/primitives/Typography/Typography.d.ts +2 -2
- package/dist/i18n/en.cjs.js +1 -1
- package/dist/i18n/en.mjs +162 -0
- package/dist/i18n/types.d.ts +175 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.mjs +111 -106
- package/dist/locales/ar.cjs.js +1 -1
- package/dist/locales/ar.mjs +197 -0
- package/dist/locales/bn.cjs.js +1 -1
- package/dist/locales/bn.mjs +132 -0
- package/dist/locales/cs.cjs.js +1 -1
- package/dist/locales/cs.mjs +182 -0
- package/dist/locales/da.cjs.js +1 -1
- package/dist/locales/da.mjs +162 -0
- package/dist/locales/de.cjs.js +1 -1
- package/dist/locales/de.mjs +162 -0
- package/dist/locales/el.cjs.js +1 -1
- package/dist/locales/el.mjs +162 -0
- package/dist/locales/es.cjs.js +1 -1
- package/dist/locales/es.mjs +162 -0
- package/dist/locales/fa.cjs.js +1 -1
- package/dist/locales/fa.mjs +132 -0
- package/dist/locales/fi.cjs.js +1 -1
- package/dist/locales/fi.mjs +162 -0
- package/dist/locales/fr.cjs.js +1 -1
- package/dist/locales/fr.mjs +167 -0
- package/dist/locales/he.cjs.js +1 -1
- package/dist/locales/he.mjs +172 -0
- package/dist/locales/hi.cjs.js +1 -1
- package/dist/locales/hi.mjs +162 -0
- package/dist/locales/hu.cjs.js +1 -1
- package/dist/locales/hu.mjs +132 -0
- package/dist/locales/id.cjs.js +1 -1
- package/dist/locales/id.mjs +132 -0
- package/dist/locales/it.cjs.js +1 -1
- package/dist/locales/it.mjs +167 -0
- package/dist/locales/ja.cjs.js +1 -1
- package/dist/locales/ja.mjs +132 -0
- package/dist/locales/ko.cjs.js +1 -1
- package/dist/locales/ko.mjs +132 -0
- package/dist/locales/nb.cjs.js +1 -1
- package/dist/locales/nb.mjs +162 -0
- package/dist/locales/nl.cjs.js +1 -1
- package/dist/locales/nl.mjs +162 -0
- package/dist/locales/pl.cjs.js +1 -1
- package/dist/locales/pl.mjs +182 -0
- package/dist/locales/pt-BR.cjs.js +1 -1
- package/dist/locales/pt-BR.mjs +167 -0
- package/dist/locales/ro.cjs.js +1 -1
- package/dist/locales/ro.mjs +172 -0
- package/dist/locales/ru.cjs.js +1 -1
- package/dist/locales/ru.mjs +182 -0
- package/dist/locales/sv.cjs.js +1 -1
- package/dist/locales/sv.mjs +162 -0
- package/dist/locales/th.cjs.js +1 -1
- package/dist/locales/th.mjs +132 -0
- package/dist/locales/tr.cjs.js +1 -1
- package/dist/locales/tr.mjs +132 -0
- package/dist/locales/uk.cjs.js +1 -1
- package/dist/locales/uk.mjs +182 -0
- package/dist/locales/ur.cjs.js +1 -1
- package/dist/locales/ur.mjs +162 -0
- package/dist/locales/vi.cjs.js +1 -1
- package/dist/locales/vi.mjs +132 -0
- package/dist/locales/zh-Hans.cjs.js +1 -1
- package/dist/locales/zh-Hans.mjs +132 -0
- package/dist/locales/zh-Hant.cjs.js +1 -1
- package/dist/locales/zh-Hant.mjs +132 -0
- package/dist/vjdesigns-ui.css +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";const e=require("../../../hooks/useEnvironment.cjs.js"),t=require("../../../hooks/useControllableState.cjs.js"),n=require("../../../utils/announce.cjs.js"),r=require("../../../utils/cx.cjs.js"),i=require("../../../utils/fillSlot.cjs.js"),a=require("../../../utils/intl.cjs.js"),o=require("../../primitives/Button/Button.cjs.js"),s=require("../../primitives/Icon/icons.cjs.js"),c=require("../../utilities/LocaleProvider/LocaleProvider.cjs.js"),l=require("../../utilities/VisuallyHidden/VisuallyHidden.cjs.js"),u=require("./Poll.module.css.cjs.js");let d=require("react"),f=require("react/jsx-runtime");var ee={sm:u.default.sm,md:u.default.md,lg:u.default.lg},te={bars:u.default.bars,cards:u.default.cards,compact:u.default.compact,versus:u.default.versus},ne=globalThis.process?.env?.NODE_ENV!==`production`;function p(e,t=[]){let n=e.map(e=>Math.max(0,e.votes??0)),r=n.reduce((e,t)=>e+t,0),i=n.map(e=>r>0?e/r*100:0),a=i.map(Math.floor),o=r>0?100-a.reduce((e,t)=>e+t,0):0,s=i.map((e,t)=>({i:t,rest:e-Math.floor(e)})).sort((e,t)=>t.rest-e.rest);for(let{i:e}of s){if(o<=0)break;a[e]++,o--}let c=Math.max(0,...n),l=n.filter(e=>e===c).length;return e.map((e,i)=>({...e,votes:n[i],percent:a[i],mine:t.includes(e.value),leading:r>0&&n[i]===c&&l===1}))}function re(e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);return t?new Date(Number(t[1]),Number(t[2])-1,Number(t[3]),23,59,59,999).getTime():Date.parse(e)}function ie(e,t){let n=new Intl.RelativeTimeFormat(t,{numeric:`auto`}),r=e/6e4;if(r<60)return n.format(Math.max(1,Math.ceil(r)),`minute`);let i=r/60;return i<24?n.format(Math.ceil(i),`hour`):n.format(Math.ceil(i/24),`day`)}function m({question:m,options:g,layout:_=`bars`,multiple:ae=!1,maxChoices:v,value:oe,defaultValue:se=[],onValueChange:ce,voted:le,defaultVoted:ue=!1,onVotedChange:de,onVote:fe,submitMode:pe,showResults:y=`after-vote`,closed:me=!1,endsAt:b,totalVotes:he,allowChangeVote:x=!1,highlightWinner:S=!0,headingLevel:ge=3,size:C=`md`,labels:_e,className:ve,...ye}){let{messages:be,locale:w}=c.useLocale(),T={...be.poll};for(let[e,t]of Object.entries(_e??{}))t!==void 0&&(T[e]=t);let xe=e.useHydrated(),E=(0,d.useId)(),D=`${E}-question`,O=`${E}-hint`,k=(0,d.useRef)(null),A=(0,d.useRef)(!1),[j,M]=(0,d.useState)(!1),[N,P]=t.useControllableState({value:oe,defaultValue:se,onChange:ce}),[F,I]=t.useControllableState({value:le,defaultValue:ue,onChange:de}),L=_===`versus`,R=ae&&!L,Se=R?`button`:pe??`instant`;(0,d.useEffect)(()=>{ne&&L&&g.length!==2&&console.warn(`[Poll] layout="versus" needs exactly 2 options; got ${g.length}.`)},[L,g.length]);let z=b?re(b):NaN,B=xe?Date.now():NaN,V=Number.isFinite(z)&&Number.isFinite(B)&&z<=B,H=me||V,U=H||y===`always`||F&&y===`after-vote`,W=p(g,F||H?N:[]),G=he??W.reduce((e,t)=>e+t.votes,0),Ce=a.getNumberFormat(w,{style:`percent`,maximumFractionDigits:0}),K=e=>Ce.format(e/100);(0,d.useEffect)(()=>{if(!A.current)return;if(A.current=!1,!U){n.announce(T.voteRecorded);return}k.current?.focus();let e=W.find(e=>e.leading),t=e?T.leads(e.label,K(e.percent)):G>0?T.tied:``;n.announce(`${T.voteRecorded} ${t}`.trim())},[F]);let q=async e=>{if(!(j||e.length===0||H)){try{let t=fe?.(e);t&&typeof t.then==`function`&&(M(!0),await t)}catch{M(!1);return}M(!1),A.current=!0,I(!0)}},we=R&&v!==void 0&&N.length>=v,Te=`h${ge}`,J=e=>e.media!==void 0&&(_===`cards`||L)&&(0,f.jsx)(`span`,{className:u.default.media,"aria-hidden":`true`,children:(0,f.jsx)(i.FillSlotContext.Provider,{value:!0,children:e.media})}),Y=e=>(0,f.jsxs)(`span`,{className:u.default.choiceText,children:[(0,f.jsx)(`span`,{className:u.default.choiceLabel,children:e.label}),e.description!==void 0&&(0,f.jsx)(`span`,{className:u.default.choiceDescription,children:e.description})]}),X=(0,f.jsx)(`span`,{className:u.default.versusDivider,"aria-hidden":`true`,children:T.versus}),Ee=()=>{let e=F&&!U;return Se===`instant`?(0,f.jsx)(`div`,{role:`group`,"aria-labelledby":D,className:u.default.choices,children:g.map((t,n)=>(0,f.jsx)(h,{divider:L&&n===1?X:null,children:(0,f.jsxs)(`button`,{type:`button`,className:u.default.choice,"data-checked":e&&N.includes(t.value)||void 0,disabled:j||e||H,"aria-pressed":e?N.includes(t.value):void 0,onClick:()=>{P([t.value]),q([t.value])},children:[J(t),Y(t)]})},t.value))}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`fieldset`,{className:u.default.fieldset,"aria-labelledby":D,"aria-describedby":R&&v!==void 0?O:void 0,disabled:j||e||H,children:(0,f.jsx)(`div`,{className:u.default.choices,children:g.map((e,t)=>{let n=N.includes(e.value);return(0,f.jsx)(h,{divider:L&&t===1?X:null,children:(0,f.jsxs)(`label`,{className:u.default.choice,"data-checked":n||void 0,children:[(0,f.jsx)(`input`,{type:R?`checkbox`:`radio`,className:u.default.input,name:`${E}-choice`,value:e.value,checked:n,disabled:!n&&we,onChange:t=>{R?P(t.target.checked?[...N,e.value]:N.filter(t=>t!==e.value)):t.target.checked&&P([e.value])}}),J(e),(0,f.jsx)(`span`,{className:r.cx(u.default.indicator,R&&u.default.indicatorBox),"aria-hidden":`true`,children:n&&(0,f.jsx)(s.CheckIcon,{})}),Y(e)]})},e.value)})})}),!e&&!H&&(0,f.jsx)(`div`,{className:u.default.submitRow,children:(0,f.jsx)(o.Button,{size:C,onClick:()=>void q(N),disabled:N.length===0,loading:j,children:T.vote})})]})},Z=e=>(0,f.jsxs)(f.Fragment,{children:[e.mine&&(0,f.jsxs)(`span`,{className:u.default.tag,children:[(0,f.jsx)(s.CheckIcon,{"aria-hidden":`true`}),T.yourVote]}),S&&e.leading&&(0,f.jsx)(`span`,{className:u.default.tag,children:H?T.winner:T.leading})]}),De=()=>{if(L){let[e,t]=W;return(0,f.jsxs)(`div`,{ref:k,tabIndex:-1,className:u.default.results,"aria-labelledby":D,role:`group`,children:[(0,f.jsx)(`ul`,{className:u.default.versusList,"aria-label":T.results,children:[e,t].filter(Boolean).map(e=>(0,f.jsxs)(`li`,{className:u.default.versusSide,"data-mine":e.mine||void 0,"data-leading":S&&e.leading||void 0,children:[J(e),(0,f.jsx)(`span`,{className:u.default.resultLabel,children:e.label}),(0,f.jsx)(`span`,{className:u.default.bigPercent,children:K(e.percent)}),(0,f.jsx)(`span`,{className:u.default.votes,children:T.votes(e.votes)}),(0,f.jsx)(`span`,{className:u.default.tags,children:Z(e)})]},e.value))}),(0,f.jsxs)(`div`,{className:u.default.split,"aria-hidden":`true`,children:[(0,f.jsx)(`span`,{className:u.default.splitA,style:{flexGrow:G>0?e?.percent??0:1}}),(0,f.jsx)(`span`,{className:u.default.splitB,style:{flexGrow:G>0?t?.percent??0:1}})]})]})}return(0,f.jsx)(`div`,{ref:k,tabIndex:-1,className:u.default.results,"aria-labelledby":D,role:`group`,children:(0,f.jsx)(`ul`,{className:u.default.resultList,"aria-label":T.results,children:W.map(e=>(0,f.jsxs)(`li`,{className:u.default.result,"data-mine":e.mine||void 0,"data-leading":S&&e.leading||void 0,style:{"--poll-share":`${e.percent}%`},children:[J(e),(0,f.jsxs)(`span`,{className:u.default.resultRow,children:[(0,f.jsx)(`span`,{className:u.default.resultLabel,children:e.label}),(0,f.jsx)(`span`,{className:u.default.tags,children:Z(e)}),(0,f.jsx)(`span`,{className:u.default.percent,children:K(e.percent)})]}),_===`bars`?(0,f.jsx)(l.VisuallyHidden,{children:`, ${T.votes(e.votes)}`}):(0,f.jsx)(`span`,{className:u.default.votes,children:T.votes(e.votes)}),(0,f.jsx)(`span`,{className:u.default.bar,"aria-hidden":`true`,children:(0,f.jsx)(`span`,{className:u.default.barFill})})]},e.value))})})},Q=null;H?Q=V&&Number.isFinite(z)?T.ended(new Intl.DateTimeFormat(w,{month:`short`,day:`numeric`}).format(z)):T.finalResults:Number.isFinite(z)&&Number.isFinite(B)&&(Q=T.endsIn(ie(z-B,w)));let $=U||H;return(0,f.jsxs)(`div`,{...ye,className:r.cx(u.default.poll,ee[C],te[_],ve),"data-phase":U?`results`:`voting`,"data-closed":H||void 0,children:[(0,f.jsx)(Te,{id:D,className:u.default.question,children:m}),R&&v!==void 0&&!U&&(0,f.jsx)(`p`,{id:O,className:u.default.hint,children:T.chooseUpTo(v)}),U?De():Ee(),F&&!U&&(0,f.jsx)(`p`,{className:u.default.hint,children:T.voteRecorded}),($||Q||x&&F&&U&&!H)&&(0,f.jsxs)(`div`,{className:u.default.footer,children:[$&&(0,f.jsx)(`span`,{children:G>0?T.votes(G):T.noVotes}),$&&Q&&(0,f.jsx)(`span`,{className:u.default.dot,"aria-hidden":`true`,children:`·`}),Q&&(0,f.jsx)(`span`,{children:Q}),x&&F&&U&&!H&&y!==`always`&&(0,f.jsx)(o.Button,{variant:`ghost`,size:`sm`,className:u.default.changeVote,onClick:()=>I(!1),children:T.changeVote})]})]})}function h({divider:e,children:t}){return(0,f.jsxs)(f.Fragment,{children:[e,t]})}exports.Poll=m,exports.computePollResults=p;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { ComponentPropsWithRef, ReactNode } from 'react';
|
|
2
|
+
import { Size } from '../../../types/common';
|
|
3
|
+
/**
|
|
4
|
+
* How a poll is laid out: `bars` (stacked choices that fill to their share),
|
|
5
|
+
* `cards` (a grid of image or icon choices), `compact` (a dense list), or
|
|
6
|
+
* `versus` (exactly two choices, head to head, with one split bar).
|
|
7
|
+
*/
|
|
8
|
+
export type PollLayout = "bars" | "cards" | "compact" | "versus";
|
|
9
|
+
/** When results are shown: after voting, always (no voting), or only once closed. */
|
|
10
|
+
export type PollShowResults = "after-vote" | "always" | "never";
|
|
11
|
+
/** Vote with a submit button, or immediately on click (single choice only). */
|
|
12
|
+
export type PollSubmitMode = "button" | "instant";
|
|
13
|
+
/** One choice of a poll. */
|
|
14
|
+
export interface PollOption {
|
|
15
|
+
/** Unique value, reported by `onVote` and `onValueChange`. */
|
|
16
|
+
value: string;
|
|
17
|
+
/** Visible name of the choice. */
|
|
18
|
+
label: string;
|
|
19
|
+
/** Votes so far, including the viewer's once they voted. @default 0 */
|
|
20
|
+
votes?: number;
|
|
21
|
+
/** Secondary text under the label. */
|
|
22
|
+
description?: ReactNode;
|
|
23
|
+
/** Image or icon, shown in the `cards` and `versus` layouts. Media fills its slot. */
|
|
24
|
+
media?: ReactNode;
|
|
25
|
+
}
|
|
26
|
+
/** A choice with its computed share, as `computePollResults` returns it. */
|
|
27
|
+
export interface PollResult extends PollOption {
|
|
28
|
+
votes: number;
|
|
29
|
+
/** Whole-number share, 0 to 100. Shares add up to exactly 100 when anyone voted. */
|
|
30
|
+
percent: number;
|
|
31
|
+
/** The viewer chose this option. */
|
|
32
|
+
mine: boolean;
|
|
33
|
+
/** Has the most votes, alone (no tie). */
|
|
34
|
+
leading: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Computes each option's whole-number share with the largest remainder
|
|
38
|
+
* method, so the shares always add up to 100 (when anyone voted), and marks
|
|
39
|
+
* the viewer's choices and the sole leader.
|
|
40
|
+
*/
|
|
41
|
+
export declare function computePollResults(options: PollOption[], mine?: readonly string[]): PollResult[];
|
|
42
|
+
export interface PollProps extends Omit<ComponentPropsWithRef<"div">, "defaultValue" | "onChange" | "children"> {
|
|
43
|
+
/** The question, rendered as a heading (see `headingLevel`). */
|
|
44
|
+
question: ReactNode;
|
|
45
|
+
/** The choices, with their vote counts. Update `votes` after `onVote`, including the new vote. */
|
|
46
|
+
options: PollOption[];
|
|
47
|
+
/** Layout of both phases. `versus` needs exactly two options. @default "bars" */
|
|
48
|
+
layout?: PollLayout;
|
|
49
|
+
/** Allow more than one choice (checkboxes). @default false */
|
|
50
|
+
multiple?: boolean;
|
|
51
|
+
/** With `multiple`: the most choices one voter can pick. */
|
|
52
|
+
maxChoices?: number;
|
|
53
|
+
/** The viewer's choice (controlled). After voting, it marks "Your vote" in the results. */
|
|
54
|
+
value?: string[];
|
|
55
|
+
/** Initial choice (uncontrolled). @default [] */
|
|
56
|
+
defaultValue?: string[];
|
|
57
|
+
/** Called when the viewer's choice changes, before or as they vote. */
|
|
58
|
+
onValueChange?: (value: string[]) => void;
|
|
59
|
+
/** Whether the viewer has voted (controlled). Use with `onVotedChange`. */
|
|
60
|
+
voted?: boolean;
|
|
61
|
+
/** Initial voted state (uncontrolled), e.g. `true` when the server says they already voted. @default false */
|
|
62
|
+
defaultVoted?: boolean;
|
|
63
|
+
/** Called when the voted state changes (after a vote, or on "Change vote"). */
|
|
64
|
+
onVotedChange?: (voted: boolean) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Called with the chosen values when the viewer votes. Return a promise to
|
|
67
|
+
* show a loading state; if it rejects, the poll stays in the voting phase
|
|
68
|
+
* (show your own error message).
|
|
69
|
+
*/
|
|
70
|
+
onVote?: (values: string[]) => void | Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* `button`: choose, then press Vote. `instant`: clicking a choice votes
|
|
73
|
+
* (single choice only; each choice is a button). @default "instant" for a single choice, "button" with `multiple`
|
|
74
|
+
*/
|
|
75
|
+
submitMode?: PollSubmitMode;
|
|
76
|
+
/**
|
|
77
|
+
* When results show: `after-vote`, `always` (results only, no voting), or
|
|
78
|
+
* `never` (only once the poll is closed, which avoids bandwagon voting). @default "after-vote"
|
|
79
|
+
*/
|
|
80
|
+
showResults?: PollShowResults;
|
|
81
|
+
/** The poll is over: voting is off and the final results show. Also true once `endsAt` passes. @default false */
|
|
82
|
+
closed?: boolean;
|
|
83
|
+
/** When voting ends: an ISO date ("2026-12-01", the end of that day) or date-time. Shown as "Ends in 3 days". */
|
|
84
|
+
endsAt?: string;
|
|
85
|
+
/** Total votes, when it differs from the sum of `votes` (e.g. multiple choice counts voters). */
|
|
86
|
+
totalVotes?: number;
|
|
87
|
+
/** Show a "Change vote" button in the results while the poll is open. @default false */
|
|
88
|
+
allowChangeVote?: boolean;
|
|
89
|
+
/** Mark the sole leader with a "Leading" (or "Winner") tag and bold label. @default true */
|
|
90
|
+
highlightWinner?: boolean;
|
|
91
|
+
/** Heading level of the question. @default 3 */
|
|
92
|
+
headingLevel?: 2 | 3 | 4 | 5 | 6;
|
|
93
|
+
/** Text and control size. @default "md" */
|
|
94
|
+
size?: Size;
|
|
95
|
+
/** Overrides the built-in text (vote button, tags, footer, announcements). Localize it here. */
|
|
96
|
+
labels?: Partial<{
|
|
97
|
+
vote: string;
|
|
98
|
+
changeVote: string;
|
|
99
|
+
yourVote: string;
|
|
100
|
+
leading: string;
|
|
101
|
+
winner: string;
|
|
102
|
+
finalResults: string;
|
|
103
|
+
versus: string;
|
|
104
|
+
}>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A poll with two phases: voting (a question with choices) and results
|
|
108
|
+
* (each choice's share, printed as a percentage, with bars). Four layouts:
|
|
109
|
+
* `bars`, `cards`, `compact`, and `versus` for two choices head to head.
|
|
110
|
+
* The poll is UI only: it reports votes through `onVote` and shows the
|
|
111
|
+
* counts you pass in `options`; storing votes and enforcing one vote per
|
|
112
|
+
* person is up to your server.
|
|
113
|
+
*/
|
|
114
|
+
export declare function Poll({ question, options, layout, multiple, maxChoices, value: valueProp, defaultValue, onValueChange, voted: votedProp, defaultVoted, onVotedChange, onVote, submitMode: submitModeProp, showResults, closed: closedProp, endsAt, totalVotes: totalVotesProp, allowChangeVote, highlightWinner, headingLevel, size, labels, className, ...rest }: PollProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useHydrated as e } from "../../../hooks/useEnvironment.mjs";
|
|
3
|
+
import { useControllableState as t } from "../../../hooks/useControllableState.mjs";
|
|
4
|
+
import { announce as n } from "../../../utils/announce.mjs";
|
|
5
|
+
import { cx as r } from "../../../utils/cx.mjs";
|
|
6
|
+
import { FillSlotContext as i } from "../../../utils/fillSlot.mjs";
|
|
7
|
+
import { getNumberFormat as a } from "../../../utils/intl.mjs";
|
|
8
|
+
import { Button as o } from "../../primitives/Button/Button.mjs";
|
|
9
|
+
import { CheckIcon as s } from "../../primitives/Icon/icons.mjs";
|
|
10
|
+
import { useLocale as c } from "../../utilities/LocaleProvider/LocaleProvider.mjs";
|
|
11
|
+
import { VisuallyHidden as l } from "../../utilities/VisuallyHidden/VisuallyHidden.mjs";
|
|
12
|
+
import u from "./Poll.module.css.mjs";
|
|
13
|
+
import { useEffect as d, useId as ee, useRef as f, useState as te } from "react";
|
|
14
|
+
import { Fragment as p, jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
15
|
+
// src/components/data-display/Poll/Poll.tsx
|
|
16
|
+
var ne = {
|
|
17
|
+
sm: u.sm,
|
|
18
|
+
md: u.md,
|
|
19
|
+
lg: u.lg
|
|
20
|
+
}, re = {
|
|
21
|
+
bars: u.bars,
|
|
22
|
+
cards: u.cards,
|
|
23
|
+
compact: u.compact,
|
|
24
|
+
versus: u.versus
|
|
25
|
+
}, ie = globalThis.process?.env?.NODE_ENV !== "production";
|
|
26
|
+
function g(e, t = []) {
|
|
27
|
+
let n = e.map((e) => Math.max(0, e.votes ?? 0)), r = n.reduce((e, t) => e + t, 0), i = n.map((e) => r > 0 ? e / r * 100 : 0), a = i.map(Math.floor), o = r > 0 ? 100 - a.reduce((e, t) => e + t, 0) : 0, s = i.map((e, t) => ({
|
|
28
|
+
i: t,
|
|
29
|
+
rest: e - Math.floor(e)
|
|
30
|
+
})).sort((e, t) => t.rest - e.rest);
|
|
31
|
+
for (let { i: e } of s) {
|
|
32
|
+
if (o <= 0) break;
|
|
33
|
+
a[e]++, o--;
|
|
34
|
+
}
|
|
35
|
+
let c = Math.max(0, ...n), l = n.filter((e) => e === c).length;
|
|
36
|
+
return e.map((e, i) => ({
|
|
37
|
+
...e,
|
|
38
|
+
votes: n[i],
|
|
39
|
+
percent: a[i],
|
|
40
|
+
mine: t.includes(e.value),
|
|
41
|
+
leading: r > 0 && n[i] === c && l === 1
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
function ae(e) {
|
|
45
|
+
let t = /^(\d{4})-(\d{2})-(\d{2})$/.exec(e);
|
|
46
|
+
return t ? new Date(Number(t[1]), Number(t[2]) - 1, Number(t[3]), 23, 59, 59, 999).getTime() : Date.parse(e);
|
|
47
|
+
}
|
|
48
|
+
function oe(e, t) {
|
|
49
|
+
let n = new Intl.RelativeTimeFormat(t, { numeric: "auto" }), r = e / 6e4;
|
|
50
|
+
if (r < 60) return n.format(Math.max(1, Math.ceil(r)), "minute");
|
|
51
|
+
let i = r / 60;
|
|
52
|
+
return i < 24 ? n.format(Math.ceil(i), "hour") : n.format(Math.ceil(i / 24), "day");
|
|
53
|
+
}
|
|
54
|
+
function _({ question: _, options: y, layout: b = "bars", multiple: se = !1, maxChoices: x, value: ce, defaultValue: le = [], onValueChange: ue, voted: de, defaultVoted: fe = !1, onVotedChange: pe, onVote: me, submitMode: he, showResults: S = "after-vote", closed: ge = !1, endsAt: C, totalVotes: _e, allowChangeVote: w = !1, highlightWinner: T = !0, headingLevel: ve = 3, size: E = "md", labels: ye, className: be, ...xe }) {
|
|
55
|
+
let { messages: Se, locale: D } = c(), O = { ...Se.poll };
|
|
56
|
+
for (let [e, t] of Object.entries(ye ?? {})) t !== void 0 && (O[e] = t);
|
|
57
|
+
let Ce = e(), k = ee(), A = `${k}-question`, j = `${k}-hint`, M = f(null), N = f(!1), [P, F] = te(!1), [I, L] = t({
|
|
58
|
+
value: ce,
|
|
59
|
+
defaultValue: le,
|
|
60
|
+
onChange: ue
|
|
61
|
+
}), [R, z] = t({
|
|
62
|
+
value: de,
|
|
63
|
+
defaultValue: fe,
|
|
64
|
+
onChange: pe
|
|
65
|
+
}), B = b === "versus", V = se && !B, we = V ? "button" : he ?? "instant";
|
|
66
|
+
d(() => {
|
|
67
|
+
ie && B && y.length !== 2 && console.warn(`[Poll] layout="versus" needs exactly 2 options; got ${y.length}.`);
|
|
68
|
+
}, [B, y.length]);
|
|
69
|
+
let H = C ? ae(C) : NaN, U = Ce ? Date.now() : NaN, W = Number.isFinite(H) && Number.isFinite(U) && H <= U, G = ge || W, K = G || S === "always" || R && S === "after-vote", q = g(y, R || G ? I : []), J = _e ?? q.reduce((e, t) => e + t.votes, 0), Te = a(D, {
|
|
70
|
+
style: "percent",
|
|
71
|
+
maximumFractionDigits: 0
|
|
72
|
+
}), Y = (e) => Te.format(e / 100);
|
|
73
|
+
d(() => {
|
|
74
|
+
if (!N.current) return;
|
|
75
|
+
if (N.current = !1, !K) {
|
|
76
|
+
n(O.voteRecorded);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
M.current?.focus();
|
|
80
|
+
let e = q.find((e) => e.leading), t = e ? O.leads(e.label, Y(e.percent)) : J > 0 ? O.tied : "";
|
|
81
|
+
n(`${O.voteRecorded} ${t}`.trim());
|
|
82
|
+
}, [R]);
|
|
83
|
+
let X = async (e) => {
|
|
84
|
+
if (!(P || e.length === 0 || G)) {
|
|
85
|
+
try {
|
|
86
|
+
let t = me?.(e);
|
|
87
|
+
t && typeof t.then == "function" && (F(!0), await t);
|
|
88
|
+
} catch {
|
|
89
|
+
F(!1);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
F(!1), N.current = !0, z(!0);
|
|
93
|
+
}
|
|
94
|
+
}, Ee = V && x !== void 0 && I.length >= x, De = `h${ve}`, Z = (e) => e.media !== void 0 && (b === "cards" || B) && /* @__PURE__ */ m("span", {
|
|
95
|
+
className: u.media,
|
|
96
|
+
"aria-hidden": "true",
|
|
97
|
+
children: /* @__PURE__ */ m(i.Provider, {
|
|
98
|
+
value: !0,
|
|
99
|
+
children: e.media
|
|
100
|
+
})
|
|
101
|
+
}), Oe = (e) => /* @__PURE__ */ h("span", {
|
|
102
|
+
className: u.choiceText,
|
|
103
|
+
children: [/* @__PURE__ */ m("span", {
|
|
104
|
+
className: u.choiceLabel,
|
|
105
|
+
children: e.label
|
|
106
|
+
}), e.description !== void 0 && /* @__PURE__ */ m("span", {
|
|
107
|
+
className: u.choiceDescription,
|
|
108
|
+
children: e.description
|
|
109
|
+
})]
|
|
110
|
+
}), ke = /* @__PURE__ */ m("span", {
|
|
111
|
+
className: u.versusDivider,
|
|
112
|
+
"aria-hidden": "true",
|
|
113
|
+
children: O.versus
|
|
114
|
+
}), Ae = () => {
|
|
115
|
+
let e = R && !K;
|
|
116
|
+
return we === "instant" ? /* @__PURE__ */ m("div", {
|
|
117
|
+
role: "group",
|
|
118
|
+
"aria-labelledby": A,
|
|
119
|
+
className: u.choices,
|
|
120
|
+
children: y.map((t, n) => /* @__PURE__ */ m(v, {
|
|
121
|
+
divider: B && n === 1 ? ke : null,
|
|
122
|
+
children: /* @__PURE__ */ h("button", {
|
|
123
|
+
type: "button",
|
|
124
|
+
className: u.choice,
|
|
125
|
+
"data-checked": e && I.includes(t.value) || void 0,
|
|
126
|
+
disabled: P || e || G,
|
|
127
|
+
"aria-pressed": e ? I.includes(t.value) : void 0,
|
|
128
|
+
onClick: () => {
|
|
129
|
+
L([t.value]), X([t.value]);
|
|
130
|
+
},
|
|
131
|
+
children: [Z(t), Oe(t)]
|
|
132
|
+
})
|
|
133
|
+
}, t.value))
|
|
134
|
+
}) : /* @__PURE__ */ h(p, { children: [/* @__PURE__ */ m("fieldset", {
|
|
135
|
+
className: u.fieldset,
|
|
136
|
+
"aria-labelledby": A,
|
|
137
|
+
"aria-describedby": V && x !== void 0 ? j : void 0,
|
|
138
|
+
disabled: P || e || G,
|
|
139
|
+
children: /* @__PURE__ */ m("div", {
|
|
140
|
+
className: u.choices,
|
|
141
|
+
children: y.map((e, t) => {
|
|
142
|
+
let n = I.includes(e.value);
|
|
143
|
+
return /* @__PURE__ */ m(v, {
|
|
144
|
+
divider: B && t === 1 ? ke : null,
|
|
145
|
+
children: /* @__PURE__ */ h("label", {
|
|
146
|
+
className: u.choice,
|
|
147
|
+
"data-checked": n || void 0,
|
|
148
|
+
children: [
|
|
149
|
+
/* @__PURE__ */ m("input", {
|
|
150
|
+
type: V ? "checkbox" : "radio",
|
|
151
|
+
className: u.input,
|
|
152
|
+
name: `${k}-choice`,
|
|
153
|
+
value: e.value,
|
|
154
|
+
checked: n,
|
|
155
|
+
disabled: !n && Ee,
|
|
156
|
+
onChange: (t) => {
|
|
157
|
+
V ? L(t.target.checked ? [...I, e.value] : I.filter((t) => t !== e.value)) : t.target.checked && L([e.value]);
|
|
158
|
+
}
|
|
159
|
+
}),
|
|
160
|
+
Z(e),
|
|
161
|
+
/* @__PURE__ */ m("span", {
|
|
162
|
+
className: r(u.indicator, V && u.indicatorBox),
|
|
163
|
+
"aria-hidden": "true",
|
|
164
|
+
children: n && /* @__PURE__ */ m(s, {})
|
|
165
|
+
}),
|
|
166
|
+
Oe(e)
|
|
167
|
+
]
|
|
168
|
+
})
|
|
169
|
+
}, e.value);
|
|
170
|
+
})
|
|
171
|
+
})
|
|
172
|
+
}), !e && !G && /* @__PURE__ */ m("div", {
|
|
173
|
+
className: u.submitRow,
|
|
174
|
+
children: /* @__PURE__ */ m(o, {
|
|
175
|
+
size: E,
|
|
176
|
+
onClick: () => void X(I),
|
|
177
|
+
disabled: I.length === 0,
|
|
178
|
+
loading: P,
|
|
179
|
+
children: O.vote
|
|
180
|
+
})
|
|
181
|
+
})] });
|
|
182
|
+
}, je = (e) => /* @__PURE__ */ h(p, { children: [e.mine && /* @__PURE__ */ h("span", {
|
|
183
|
+
className: u.tag,
|
|
184
|
+
children: [/* @__PURE__ */ m(s, { "aria-hidden": "true" }), O.yourVote]
|
|
185
|
+
}), T && e.leading && /* @__PURE__ */ m("span", {
|
|
186
|
+
className: u.tag,
|
|
187
|
+
children: G ? O.winner : O.leading
|
|
188
|
+
})] }), Me = () => {
|
|
189
|
+
if (B) {
|
|
190
|
+
let [e, t] = q;
|
|
191
|
+
return /* @__PURE__ */ h("div", {
|
|
192
|
+
ref: M,
|
|
193
|
+
tabIndex: -1,
|
|
194
|
+
className: u.results,
|
|
195
|
+
"aria-labelledby": A,
|
|
196
|
+
role: "group",
|
|
197
|
+
children: [/* @__PURE__ */ m("ul", {
|
|
198
|
+
className: u.versusList,
|
|
199
|
+
"aria-label": O.results,
|
|
200
|
+
children: [e, t].filter(Boolean).map((e) => /* @__PURE__ */ h("li", {
|
|
201
|
+
className: u.versusSide,
|
|
202
|
+
"data-mine": e.mine || void 0,
|
|
203
|
+
"data-leading": T && e.leading || void 0,
|
|
204
|
+
children: [
|
|
205
|
+
Z(e),
|
|
206
|
+
/* @__PURE__ */ m("span", {
|
|
207
|
+
className: u.resultLabel,
|
|
208
|
+
children: e.label
|
|
209
|
+
}),
|
|
210
|
+
/* @__PURE__ */ m("span", {
|
|
211
|
+
className: u.bigPercent,
|
|
212
|
+
children: Y(e.percent)
|
|
213
|
+
}),
|
|
214
|
+
/* @__PURE__ */ m("span", {
|
|
215
|
+
className: u.votes,
|
|
216
|
+
children: O.votes(e.votes)
|
|
217
|
+
}),
|
|
218
|
+
/* @__PURE__ */ m("span", {
|
|
219
|
+
className: u.tags,
|
|
220
|
+
children: je(e)
|
|
221
|
+
})
|
|
222
|
+
]
|
|
223
|
+
}, e.value))
|
|
224
|
+
}), /* @__PURE__ */ h("div", {
|
|
225
|
+
className: u.split,
|
|
226
|
+
"aria-hidden": "true",
|
|
227
|
+
children: [/* @__PURE__ */ m("span", {
|
|
228
|
+
className: u.splitA,
|
|
229
|
+
style: { flexGrow: J > 0 ? e?.percent ?? 0 : 1 }
|
|
230
|
+
}), /* @__PURE__ */ m("span", {
|
|
231
|
+
className: u.splitB,
|
|
232
|
+
style: { flexGrow: J > 0 ? t?.percent ?? 0 : 1 }
|
|
233
|
+
})]
|
|
234
|
+
})]
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
return /* @__PURE__ */ m("div", {
|
|
238
|
+
ref: M,
|
|
239
|
+
tabIndex: -1,
|
|
240
|
+
className: u.results,
|
|
241
|
+
"aria-labelledby": A,
|
|
242
|
+
role: "group",
|
|
243
|
+
children: /* @__PURE__ */ m("ul", {
|
|
244
|
+
className: u.resultList,
|
|
245
|
+
"aria-label": O.results,
|
|
246
|
+
children: q.map((e) => /* @__PURE__ */ h("li", {
|
|
247
|
+
className: u.result,
|
|
248
|
+
"data-mine": e.mine || void 0,
|
|
249
|
+
"data-leading": T && e.leading || void 0,
|
|
250
|
+
style: { "--poll-share": `${e.percent}%` },
|
|
251
|
+
children: [
|
|
252
|
+
Z(e),
|
|
253
|
+
/* @__PURE__ */ h("span", {
|
|
254
|
+
className: u.resultRow,
|
|
255
|
+
children: [
|
|
256
|
+
/* @__PURE__ */ m("span", {
|
|
257
|
+
className: u.resultLabel,
|
|
258
|
+
children: e.label
|
|
259
|
+
}),
|
|
260
|
+
/* @__PURE__ */ m("span", {
|
|
261
|
+
className: u.tags,
|
|
262
|
+
children: je(e)
|
|
263
|
+
}),
|
|
264
|
+
/* @__PURE__ */ m("span", {
|
|
265
|
+
className: u.percent,
|
|
266
|
+
children: Y(e.percent)
|
|
267
|
+
})
|
|
268
|
+
]
|
|
269
|
+
}),
|
|
270
|
+
b === "bars" ? /* @__PURE__ */ m(l, { children: `, ${O.votes(e.votes)}` }) : /* @__PURE__ */ m("span", {
|
|
271
|
+
className: u.votes,
|
|
272
|
+
children: O.votes(e.votes)
|
|
273
|
+
}),
|
|
274
|
+
/* @__PURE__ */ m("span", {
|
|
275
|
+
className: u.bar,
|
|
276
|
+
"aria-hidden": "true",
|
|
277
|
+
children: /* @__PURE__ */ m("span", { className: u.barFill })
|
|
278
|
+
})
|
|
279
|
+
]
|
|
280
|
+
}, e.value))
|
|
281
|
+
})
|
|
282
|
+
});
|
|
283
|
+
}, Q = null;
|
|
284
|
+
G ? Q = W && Number.isFinite(H) ? O.ended(new Intl.DateTimeFormat(D, {
|
|
285
|
+
month: "short",
|
|
286
|
+
day: "numeric"
|
|
287
|
+
}).format(H)) : O.finalResults : Number.isFinite(H) && Number.isFinite(U) && (Q = O.endsIn(oe(H - U, D)));
|
|
288
|
+
let $ = K || G;
|
|
289
|
+
return /* @__PURE__ */ h("div", {
|
|
290
|
+
...xe,
|
|
291
|
+
className: r(u.poll, ne[E], re[b], be),
|
|
292
|
+
"data-phase": K ? "results" : "voting",
|
|
293
|
+
"data-closed": G || void 0,
|
|
294
|
+
children: [
|
|
295
|
+
/* @__PURE__ */ m(De, {
|
|
296
|
+
id: A,
|
|
297
|
+
className: u.question,
|
|
298
|
+
children: _
|
|
299
|
+
}),
|
|
300
|
+
V && x !== void 0 && !K && /* @__PURE__ */ m("p", {
|
|
301
|
+
id: j,
|
|
302
|
+
className: u.hint,
|
|
303
|
+
children: O.chooseUpTo(x)
|
|
304
|
+
}),
|
|
305
|
+
K ? Me() : Ae(),
|
|
306
|
+
R && !K && /* @__PURE__ */ m("p", {
|
|
307
|
+
className: u.hint,
|
|
308
|
+
children: O.voteRecorded
|
|
309
|
+
}),
|
|
310
|
+
($ || Q || w && R && K && !G) && /* @__PURE__ */ h("div", {
|
|
311
|
+
className: u.footer,
|
|
312
|
+
children: [
|
|
313
|
+
$ && /* @__PURE__ */ m("span", { children: J > 0 ? O.votes(J) : O.noVotes }),
|
|
314
|
+
$ && Q && /* @__PURE__ */ m("span", {
|
|
315
|
+
className: u.dot,
|
|
316
|
+
"aria-hidden": "true",
|
|
317
|
+
children: "·"
|
|
318
|
+
}),
|
|
319
|
+
Q && /* @__PURE__ */ m("span", { children: Q }),
|
|
320
|
+
w && R && K && !G && S !== "always" && /* @__PURE__ */ m(o, {
|
|
321
|
+
variant: "ghost",
|
|
322
|
+
size: "sm",
|
|
323
|
+
className: u.changeVote,
|
|
324
|
+
onClick: () => z(!1),
|
|
325
|
+
children: O.changeVote
|
|
326
|
+
})
|
|
327
|
+
]
|
|
328
|
+
})
|
|
329
|
+
]
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
function v({ divider: e, children: t }) {
|
|
333
|
+
return /* @__PURE__ */ h(p, { children: [e, t] });
|
|
334
|
+
}
|
|
335
|
+
export { _ as Poll, g as computePollResults };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=`_sm_1ht2i_39`,t=`_md_1ht2i_51`,n=`_lg_1ht2i_63`,r=`_bars_1ht2i_79`,i=`_cards_1ht2i_81`,a=`_compact_1ht2i_83`,o=`_versus_1ht2i_85`,s=`_poll_1ht2i_101`,c=`_question_1ht2i_123`,l=`_hint_1ht2i_143`,u=`_fieldset_1ht2i_157`,d=`_submitRow_1ht2i_171`,f=`_footer_1ht2i_179`,p=`_changeVote_1ht2i_201`,m=`_choices_1ht2i_217`,h=`_resultList_1ht2i_231`,g=`_choice_1ht2i_217`,_=`_input_1ht2i_331`,v=`_choiceLabel_1ht2i_387`,y=`_versusDivider_1ht2i_429`,b=`_indicator_1ht2i_477`,x=`_indicatorBox_1ht2i_501`,S=`_pop_1ht2i_1`,C=`_choiceText_1ht2i_551`,w=`_choiceDescription_1ht2i_577`,T=`_media_1ht2i_589`,E=`_results_1ht2i_669`,D=`_result_1ht2i_231`,O=`_resultRow_1ht2i_731`,k=`_resultLabel_1ht2i_751`,A=`_versusSide_1ht2i_763`,j=`_percent_1ht2i_771`,M=`_votes_1ht2i_787`,N=`_tags_1ht2i_799`,P=`_tag_1ht2i_799`,F=`_bar_1ht2i_79`,I=`_barFill_1ht2i_869`,L=`_versusList_1ht2i_1009`,R=`_bigPercent_1ht2i_1051`,z=`_split_1ht2i_1069`,B=`_splitA_1ht2i_1085`,V=`_splitB_1ht2i_1087`,H={sm:e,md:t,lg:n,bars:r,cards:i,compact:a,versus:o,poll:s,question:c,hint:l,fieldset:u,submitRow:d,footer:f,changeVote:p,choices:m,resultList:h,choice:g,input:_,choiceLabel:v,versusDivider:y,indicator:b,indicatorBox:x,pop:S,choiceText:C,choiceDescription:w,media:T,results:E,result:D,resultRow:O,resultLabel:k,versusSide:A,percent:j,votes:M,tags:N,tag:P,bar:F,barFill:I,versusList:L,bigPercent:R,split:z,splitA:B,splitB:V};exports.bar=F,exports.barFill=I,exports.bars=r,exports.bigPercent=R,exports.cards=i,exports.changeVote=p,exports.choice=g,exports.choiceDescription=w,exports.choiceLabel=v,exports.choiceText=C,exports.choices=m,exports.compact=a,exports.default=H,exports.fieldset=u,exports.footer=f,exports.hint=l,exports.indicator=b,exports.indicatorBox=x,exports.input=_,exports.lg=n,exports.md=t,exports.media=T,exports.percent=j,exports.poll=s,exports.pop=S,exports.question=c,exports.result=D,exports.resultLabel=k,exports.resultList=h,exports.resultRow=O,exports.results=E,exports.sm=e,exports.split=z,exports.splitA=B,exports.splitB=V,exports.submitRow=d,exports.tag=P,exports.tags=N,exports.versus=o,exports.versusDivider=y,exports.versusList=L,exports.versusSide=A,exports.votes=M;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/components/data-display/Poll/Poll.module.css
|
|
2
|
+
var e = "_sm_1ht2i_39", t = "_md_1ht2i_51", n = "_lg_1ht2i_63", r = "_bars_1ht2i_79", i = "_cards_1ht2i_81", a = "_compact_1ht2i_83", o = "_versus_1ht2i_85", s = "_poll_1ht2i_101", c = "_question_1ht2i_123", l = "_hint_1ht2i_143", u = "_fieldset_1ht2i_157", d = "_submitRow_1ht2i_171", f = "_footer_1ht2i_179", p = "_changeVote_1ht2i_201", m = "_choices_1ht2i_217", h = "_resultList_1ht2i_231", g = "_choice_1ht2i_217", _ = "_input_1ht2i_331", v = "_choiceLabel_1ht2i_387", y = "_versusDivider_1ht2i_429", b = "_indicator_1ht2i_477", x = "_indicatorBox_1ht2i_501", S = "_pop_1ht2i_1", C = "_choiceText_1ht2i_551", w = "_choiceDescription_1ht2i_577", T = "_media_1ht2i_589", E = "_results_1ht2i_669", D = "_result_1ht2i_231", O = "_resultRow_1ht2i_731", k = "_resultLabel_1ht2i_751", A = "_versusSide_1ht2i_763", j = "_percent_1ht2i_771", M = "_votes_1ht2i_787", N = "_tags_1ht2i_799", P = "_tag_1ht2i_799", F = "_bar_1ht2i_79", I = "_barFill_1ht2i_869", L = "_versusList_1ht2i_1009", R = "_bigPercent_1ht2i_1051", z = "_split_1ht2i_1069", B = "_splitA_1ht2i_1085", V = "_splitB_1ht2i_1087", H = {
|
|
3
|
+
sm: e,
|
|
4
|
+
md: t,
|
|
5
|
+
lg: n,
|
|
6
|
+
bars: r,
|
|
7
|
+
cards: i,
|
|
8
|
+
compact: a,
|
|
9
|
+
versus: o,
|
|
10
|
+
poll: s,
|
|
11
|
+
question: c,
|
|
12
|
+
hint: l,
|
|
13
|
+
fieldset: u,
|
|
14
|
+
submitRow: d,
|
|
15
|
+
footer: f,
|
|
16
|
+
changeVote: p,
|
|
17
|
+
choices: m,
|
|
18
|
+
resultList: h,
|
|
19
|
+
choice: g,
|
|
20
|
+
input: _,
|
|
21
|
+
choiceLabel: v,
|
|
22
|
+
versusDivider: y,
|
|
23
|
+
indicator: b,
|
|
24
|
+
indicatorBox: x,
|
|
25
|
+
pop: S,
|
|
26
|
+
choiceText: C,
|
|
27
|
+
choiceDescription: w,
|
|
28
|
+
media: T,
|
|
29
|
+
results: E,
|
|
30
|
+
result: D,
|
|
31
|
+
resultRow: O,
|
|
32
|
+
resultLabel: k,
|
|
33
|
+
versusSide: A,
|
|
34
|
+
percent: j,
|
|
35
|
+
votes: M,
|
|
36
|
+
tags: N,
|
|
37
|
+
tag: P,
|
|
38
|
+
bar: F,
|
|
39
|
+
barFill: I,
|
|
40
|
+
versusList: L,
|
|
41
|
+
bigPercent: R,
|
|
42
|
+
split: z,
|
|
43
|
+
splitA: B,
|
|
44
|
+
splitB: V
|
|
45
|
+
};
|
|
46
|
+
export { F as bar, I as barFill, r as bars, R as bigPercent, i as cards, p as changeVote, g as choice, w as choiceDescription, v as choiceLabel, C as choiceText, m as choices, a as compact, H as default, u as fieldset, f as footer, l as hint, b as indicator, x as indicatorBox, _ as input, n as lg, t as md, T as media, j as percent, s as poll, S as pop, c as question, D as result, k as resultLabel, h as resultList, O as resultRow, E as results, e as sm, z as split, B as splitA, V as splitB, d as submitRow, P as tag, N as tags, o as versus, y as versusDivider, L as versusList, A as versusSide, M as votes };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Poll';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";const e=require("../../../utils/cx.cjs.js"),t=require("../../../utils/intl.cjs.js"),n=require("../../forms/Rating/Rating.cjs.js"),r=require("../../primitives/Icon/icons.cjs.js"),i=require("../../utilities/LocaleProvider/LocaleProvider.cjs.js"),a=require("../../utilities/VisuallyHidden/VisuallyHidden.cjs.js"),o=require("./RatingBreakdown.module.css.cjs.js");let s=require("react/jsx-runtime");var c={sm:o.default.sm,md:o.default.md,lg:o.default.lg},l={stacked:o.default.stacked,inline:o.default.inline};function u({counts:u,average:d,total:f,max:p=5,onLevelSelect:m,selectedLevel:h=null,recommendPercent:g,layout:_=`stacked`,size:v=`md`,className:y,...b}){let{messages:x,locale:S}=i.useLocale(),C=x.ratingBreakdown,w=Math.max(1,Math.round(p)),T=Array.from({length:w},(e,t)=>w-t),E=e=>Math.max(0,u[e]??0),D=T.reduce((e,t)=>e+E(t),0),O=f??D,k=d??(D>0?T.reduce((e,t)=>e+t*E(t),0)/D:0),A=t.getNumberFormat(S,{style:`percent`,maximumFractionDigits:0}),j=e=>D>0?E(e)/D:0;return(0,s.jsxs)(`div`,{...b,className:e.cx(o.default.breakdown,c[v],l[_],y),children:[(0,s.jsxs)(`div`,{className:o.default.summary,children:[(0,s.jsx)(`span`,{className:o.default.average,"aria-hidden":`true`,children:n.formatRatingValue(k,S)}),(0,s.jsx)(n.RatingDisplay,{value:k,max:w,size:v}),(0,s.jsx)(`span`,{className:o.default.basedOn,children:C.basedOn(O)}),g!==void 0&&(0,s.jsx)(`span`,{className:o.default.recommend,children:C.wouldRecommend(A.format(Math.min(100,Math.max(0,g))/100))})]}),(0,s.jsx)(`ul`,{className:o.default.levels,"aria-label":C.distribution,children:T.map(t=>{let i=j(t),c=A.format(i),l=(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(`span`,{className:o.default.levelLabel,"aria-hidden":`true`,children:[n.formatRatingValue(t,S),(0,s.jsx)(r.StarFilledIcon,{})]}),(0,s.jsx)(`span`,{className:o.default.track,"aria-hidden":`true`,children:(0,s.jsx)(`span`,{className:o.default.fill,style:{"--breakdown-share":`${Math.round(i*1e3)/10}%`}})}),(0,s.jsx)(`span`,{className:o.default.percent,"aria-hidden":`true`,children:c}),(0,s.jsx)(a.VisuallyHidden,{children:C.level(t,E(t),c)})]});return(0,s.jsx)(`li`,{children:m?(0,s.jsx)(`button`,{type:`button`,className:e.cx(o.default.row,o.default.rowButton),"aria-pressed":h===t,onClick:()=>m(h===t?null:t),children:l}):(0,s.jsx)(`span`,{className:o.default.row,children:l})},t)})})]})}exports.RatingBreakdown=u;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ComponentPropsWithRef } from 'react';
|
|
2
|
+
import { Size } from '../../../types/common';
|
|
3
|
+
/** Where the average sits: above the level bars, or beside them. */
|
|
4
|
+
export type RatingBreakdownLayout = "stacked" | "inline";
|
|
5
|
+
export interface RatingBreakdownProps extends Omit<ComponentPropsWithRef<"div">, "children"> {
|
|
6
|
+
/** Reviews per level, e.g. `{ 5: 920, 4: 210, 3: 80, 2: 40, 1: 34 }`. Missing levels count as 0. */
|
|
7
|
+
counts: Record<number, number>;
|
|
8
|
+
/** The average rating. Computed from `counts` when omitted. */
|
|
9
|
+
average?: number;
|
|
10
|
+
/** Total reviews. The sum of `counts` when omitted. */
|
|
11
|
+
total?: number;
|
|
12
|
+
/** The highest level (number of stars). @default 5 */
|
|
13
|
+
max?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Called when a level row is pressed, with that level, or `null` when the
|
|
16
|
+
* pressed row is pressed again. Turns each row into a toggle button for
|
|
17
|
+
* filtering a review list.
|
|
18
|
+
*/
|
|
19
|
+
onLevelSelect?: (level: number | null) => void;
|
|
20
|
+
/** The level currently filtered on (shown pressed). Use with `onLevelSelect`. */
|
|
21
|
+
selectedLevel?: number | null;
|
|
22
|
+
/** Share of reviewers who would recommend, 0 to 100. Shown as "92% would recommend". */
|
|
23
|
+
recommendPercent?: number;
|
|
24
|
+
/** `stacked`: the average above the bars. `inline`: beside them (wraps on narrow screens). @default "stacked" */
|
|
25
|
+
layout?: RatingBreakdownLayout;
|
|
26
|
+
/** Text size. @default "md" */
|
|
27
|
+
size?: Size;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The summary above a review list: the average rating as a big number with
|
|
31
|
+
* stars, the review count, and one bar per level showing its share. Each
|
|
32
|
+
* row reads "5 stars: 920 reviews, 72%"; with `onLevelSelect` the rows are
|
|
33
|
+
* toggle buttons for filtering by level.
|
|
34
|
+
*/
|
|
35
|
+
export declare function RatingBreakdown({ counts, average: averageProp, total: totalProp, max, onLevelSelect, selectedLevel, recommendPercent, layout, size, className, ...rest }: RatingBreakdownProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cx as e } from "../../../utils/cx.mjs";
|
|
3
|
+
import { getNumberFormat as t } from "../../../utils/intl.mjs";
|
|
4
|
+
import { RatingDisplay as n, formatRatingValue as r } from "../../forms/Rating/Rating.mjs";
|
|
5
|
+
import { StarFilledIcon as i } from "../../primitives/Icon/icons.mjs";
|
|
6
|
+
import { useLocale as a } from "../../utilities/LocaleProvider/LocaleProvider.mjs";
|
|
7
|
+
import { VisuallyHidden as o } from "../../utilities/VisuallyHidden/VisuallyHidden.mjs";
|
|
8
|
+
import s from "./RatingBreakdown.module.css.mjs";
|
|
9
|
+
import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
10
|
+
// src/components/data-display/RatingBreakdown/RatingBreakdown.tsx
|
|
11
|
+
var d = {
|
|
12
|
+
sm: s.sm,
|
|
13
|
+
md: s.md,
|
|
14
|
+
lg: s.lg
|
|
15
|
+
}, f = {
|
|
16
|
+
stacked: s.stacked,
|
|
17
|
+
inline: s.inline
|
|
18
|
+
};
|
|
19
|
+
function p({ counts: p, average: m, total: h, max: g = 5, onLevelSelect: _, selectedLevel: v = null, recommendPercent: y, layout: b = "stacked", size: x = "md", className: S, ...C }) {
|
|
20
|
+
let { messages: w, locale: T } = a(), E = w.ratingBreakdown, D = Math.max(1, Math.round(g)), O = Array.from({ length: D }, (e, t) => D - t), k = (e) => Math.max(0, p[e] ?? 0), A = O.reduce((e, t) => e + k(t), 0), j = h ?? A, M = m ?? (A > 0 ? O.reduce((e, t) => e + t * k(t), 0) / A : 0), N = t(T, {
|
|
21
|
+
style: "percent",
|
|
22
|
+
maximumFractionDigits: 0
|
|
23
|
+
}), P = (e) => A > 0 ? k(e) / A : 0;
|
|
24
|
+
return /* @__PURE__ */ u("div", {
|
|
25
|
+
...C,
|
|
26
|
+
className: e(s.breakdown, d[x], f[b], S),
|
|
27
|
+
children: [/* @__PURE__ */ u("div", {
|
|
28
|
+
className: s.summary,
|
|
29
|
+
children: [
|
|
30
|
+
/* @__PURE__ */ l("span", {
|
|
31
|
+
className: s.average,
|
|
32
|
+
"aria-hidden": "true",
|
|
33
|
+
children: r(M, T)
|
|
34
|
+
}),
|
|
35
|
+
/* @__PURE__ */ l(n, {
|
|
36
|
+
value: M,
|
|
37
|
+
max: D,
|
|
38
|
+
size: x
|
|
39
|
+
}),
|
|
40
|
+
/* @__PURE__ */ l("span", {
|
|
41
|
+
className: s.basedOn,
|
|
42
|
+
children: E.basedOn(j)
|
|
43
|
+
}),
|
|
44
|
+
y !== void 0 && /* @__PURE__ */ l("span", {
|
|
45
|
+
className: s.recommend,
|
|
46
|
+
children: E.wouldRecommend(N.format(Math.min(100, Math.max(0, y)) / 100))
|
|
47
|
+
})
|
|
48
|
+
]
|
|
49
|
+
}), /* @__PURE__ */ l("ul", {
|
|
50
|
+
className: s.levels,
|
|
51
|
+
"aria-label": E.distribution,
|
|
52
|
+
children: O.map((t) => {
|
|
53
|
+
let n = P(t), a = N.format(n), d = /* @__PURE__ */ u(c, { children: [
|
|
54
|
+
/* @__PURE__ */ u("span", {
|
|
55
|
+
className: s.levelLabel,
|
|
56
|
+
"aria-hidden": "true",
|
|
57
|
+
children: [r(t, T), /* @__PURE__ */ l(i, {})]
|
|
58
|
+
}),
|
|
59
|
+
/* @__PURE__ */ l("span", {
|
|
60
|
+
className: s.track,
|
|
61
|
+
"aria-hidden": "true",
|
|
62
|
+
children: /* @__PURE__ */ l("span", {
|
|
63
|
+
className: s.fill,
|
|
64
|
+
style: { "--breakdown-share": `${Math.round(n * 1e3) / 10}%` }
|
|
65
|
+
})
|
|
66
|
+
}),
|
|
67
|
+
/* @__PURE__ */ l("span", {
|
|
68
|
+
className: s.percent,
|
|
69
|
+
"aria-hidden": "true",
|
|
70
|
+
children: a
|
|
71
|
+
}),
|
|
72
|
+
/* @__PURE__ */ l(o, { children: E.level(t, k(t), a) })
|
|
73
|
+
] });
|
|
74
|
+
return /* @__PURE__ */ l("li", { children: _ ? /* @__PURE__ */ l("button", {
|
|
75
|
+
type: "button",
|
|
76
|
+
className: e(s.row, s.rowButton),
|
|
77
|
+
"aria-pressed": v === t,
|
|
78
|
+
onClick: () => _(v === t ? null : t),
|
|
79
|
+
children: d
|
|
80
|
+
}) : /* @__PURE__ */ l("span", {
|
|
81
|
+
className: s.row,
|
|
82
|
+
children: d
|
|
83
|
+
}) }, t);
|
|
84
|
+
})
|
|
85
|
+
})]
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
export { p as RatingBreakdown };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=`_sm_ab5yd_23`,t=`_md_ab5yd_31`,n=`_lg_ab5yd_39`,r=`_breakdown_ab5yd_49`,i=`_stacked_ab5yd_65`,a=`_inline_ab5yd_73`,o=`_levels_ab5yd_83`,s=`_summary_ab5yd_91`,c=`_average_ab5yd_105`,l=`_basedOn_ab5yd_123`,u=`_recommend_ab5yd_125`,d=`_row_ab5yd_163`,f=`_rowButton_ab5yd_183`,p=`_levelLabel_ab5yd_243`,m=`_track_ab5yd_273`,h=`_fill_ab5yd_289`,g=`_percent_ab5yd_319`,_={sm:e,md:t,lg:n,breakdown:r,stacked:i,inline:a,levels:o,summary:s,average:c,basedOn:l,recommend:u,row:d,rowButton:f,levelLabel:p,track:m,fill:h,percent:g};exports.average=c,exports.basedOn=l,exports.breakdown=r,exports.default=_,exports.fill=h,exports.inline=a,exports.levelLabel=p,exports.levels=o,exports.lg=n,exports.md=t,exports.percent=g,exports.recommend=u,exports.row=d,exports.rowButton=f,exports.sm=e,exports.stacked=i,exports.summary=s,exports.track=m;
|