react-raffle-picker 0.1.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/LICENSE +21 -0
- package/README.md +200 -0
- package/dist/index.cjs +549 -0
- package/dist/index.d.cts +151 -0
- package/dist/index.d.mts +151 -0
- package/dist/index.mjs +542 -0
- package/package.json +110 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kirill
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://i.ibb.co/k2MRQCqT/logo-nbg.png" alt="react-raffle-picker logo placeholder" width="160" />
|
|
3
|
+
|
|
4
|
+
<h1>react-raffle-picker</h1>
|
|
5
|
+
|
|
6
|
+
<p><strong>Tiny raffle engine. Big winner energy.</strong></p>
|
|
7
|
+
|
|
8
|
+
<p>
|
|
9
|
+
<a href="https://react-raffle-one.vercel.app/">Live demo</a>
|
|
10
|
+
·
|
|
11
|
+
<a href="https://kirilinsky.github.io/react-raffle-picker/">Storybook</a>
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
<p>
|
|
15
|
+
<a href="https://kirilinsky.github.io/react-raffle-picker/">
|
|
16
|
+
<img src="https://img.shields.io/badge/storybook-live-ff4785?logo=storybook&logoColor=white" alt="Storybook" />
|
|
17
|
+
</a>
|
|
18
|
+
<a href="https://codecov.io/gh/kirilinsky/react-raffle-picker">
|
|
19
|
+
<img src="https://codecov.io/gh/kirilinsky/react-raffle-picker/branch/main/graph/badge.svg" alt="Codecov coverage" />
|
|
20
|
+
</a>
|
|
21
|
+
<a href="https://bundlephobia.com/package/react-raffle-picker">
|
|
22
|
+
<img src="https://img.shields.io/bundlephobia/minzip/react-raffle-picker?label=gzip" alt="Gzip bundle size" />
|
|
23
|
+
</a>
|
|
24
|
+
</p>
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
A headless, composable React component for giveaways, raffles, and slot-machine UIs. Cycles numbers or names with smooth animations and freezes on a winner. Performant on slow devices — high-frequency tick updates bypass React.
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install react-raffle-picker
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Preview
|
|
34
|
+
|
|
35
|
+
<table>
|
|
36
|
+
<tr>
|
|
37
|
+
<td align="center">
|
|
38
|
+
<img src="https://i.ibb.co/C3T73bkM/1.gif" alt="Headless" width="280" /><br/>
|
|
39
|
+
<sub><b>Headless</b> — zero styles, full control</sub>
|
|
40
|
+
</td>
|
|
41
|
+
<td align="center">
|
|
42
|
+
<img src="https://i.ibb.co/mVMHJztJ/2.gif" alt="English Names" width="280" /><br/>
|
|
43
|
+
<sub><b>English Names</b> — items mode + reel</sub>
|
|
44
|
+
</td>
|
|
45
|
+
</tr>
|
|
46
|
+
<tr>
|
|
47
|
+
<td align="center">
|
|
48
|
+
<img src="https://i.ibb.co/ZrdSS7G/3.gif" alt="Countdown" width="280" /><br/>
|
|
49
|
+
<sub><b>Countdown</b> — auto-freeze with ring</sub>
|
|
50
|
+
</td>
|
|
51
|
+
<td align="center">
|
|
52
|
+
<img src="https://i.ibb.co/kVSXdPnJ/4.gif" alt="Slot Machine" width="280" /><br/>
|
|
53
|
+
<sub><b>Slot Machine</b> — independent reels</sub>
|
|
54
|
+
</td>
|
|
55
|
+
</tr>
|
|
56
|
+
</table>
|
|
57
|
+
|
|
58
|
+
## Idea
|
|
59
|
+
|
|
60
|
+
`react-raffle-picker` ships as a **headless compound component**, not a monolithic widget. The root owns the engine — cycling, phase machine, freeze logic — and exposes it through React context. Sub-components (`Value`, `Button`, `Countdown`, `Slots`) are dumb consumers that you compose anywhere in your tree.
|
|
61
|
+
|
|
62
|
+
This means:
|
|
63
|
+
|
|
64
|
+
- **No layout opinions.** Wrap pieces in your own card, modal, sidebar, paragraph.
|
|
65
|
+
- **No style props soup.** Style each piece directly via `className` / `style`.
|
|
66
|
+
- **One source of truth.** All state lives in the root. Sub-components read context.
|
|
67
|
+
- **Performance preserved.** Tick updates write to DOM imperatively via refs — no React re-render per tick. Context only re-renders on phase boundaries (start, settle, freeze).
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
import { RafflePick } from 'react-raffle-picker'
|
|
71
|
+
|
|
72
|
+
<RafflePick min={1} max={100} interval={100} inertia onSelect={(v) => console.log(v)}>
|
|
73
|
+
<RafflePick.Value animation="roll" className="my-value" />
|
|
74
|
+
<RafflePick.Button startLabel="Pick" stopLabel="Stop" />
|
|
75
|
+
</RafflePick>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Components
|
|
79
|
+
|
|
80
|
+
### `<RafflePick>` (root)
|
|
81
|
+
|
|
82
|
+
Provides context. Renders an optional wrapper element (`as` prop, default `'div'`).
|
|
83
|
+
|
|
84
|
+
| Prop | Type | Default | Notes |
|
|
85
|
+
| ------------ | --------------------------- | ---------- | --------------------------------------------- |
|
|
86
|
+
| `min`, `max` | `number` | `1`, `100` | Numeric range. Ignored if `items` provided. |
|
|
87
|
+
| `items` | `string[]` | — | Switches to item mode (cycles through names). |
|
|
88
|
+
| `interval` | `number` (ms, clamped ≥ 50) | `100` | Tick speed. |
|
|
89
|
+
| `random` | `boolean` | `true` | Random pick vs sequential. |
|
|
90
|
+
| `inertia` | `boolean` | `false` | Soft start / soft stop ramp. |
|
|
91
|
+
| `autoStart` | `boolean` | `true` | Begin cycling on mount. |
|
|
92
|
+
| `onSelect` | `(value) => void` | — | Fires once per round on freeze. |
|
|
93
|
+
| `as` | `ElementType` | `'div'` | Wrapper tag. |
|
|
94
|
+
| `className` | `string` | — | Wrapper class. |
|
|
95
|
+
| `style` | `CSSProperties` | — | Wrapper style. |
|
|
96
|
+
| `children` | `ReactNode` | — | Sub-components. |
|
|
97
|
+
|
|
98
|
+
### `<RafflePick.Value>`
|
|
99
|
+
|
|
100
|
+
Renders the cycling value. Updates `textContent` imperatively each tick (no React re-render).
|
|
101
|
+
|
|
102
|
+
| Prop | Type | Default |
|
|
103
|
+
| ----------- | -------------------------------------- | -------- |
|
|
104
|
+
| `animation` | `'roll' \| 'fade' \| 'blur' \| 'reel'` | `'roll'` |
|
|
105
|
+
| `as` | `ElementType` | `'span'` |
|
|
106
|
+
| `className` | `string` | — |
|
|
107
|
+
| `style` | `CSSProperties` | — |
|
|
108
|
+
|
|
109
|
+
Multiple `Value` instances inside one root are supported — all subscribe to the same tick.
|
|
110
|
+
|
|
111
|
+
### `<RafflePick.Button>`
|
|
112
|
+
|
|
113
|
+
Toggles start / freeze based on phase. Disabled during settling.
|
|
114
|
+
|
|
115
|
+
| Prop | Type | Notes |
|
|
116
|
+
| ------------ | --------------- | ------------------------------------------------ |
|
|
117
|
+
| `startLabel` | `ReactNode` | Shown in `idle` / `frozen` (click starts). |
|
|
118
|
+
| `stopLabel` | `ReactNode` | Shown in `running` / `starting` (click stops). |
|
|
119
|
+
| `waitLabel` | `ReactNode` | Shown in `settling` (button disabled). |
|
|
120
|
+
| `children` | `ReactNode` | Fallback label when state-specific label absent. |
|
|
121
|
+
| `className` | `string` | — |
|
|
122
|
+
| `style` | `CSSProperties` | — |
|
|
123
|
+
|
|
124
|
+
### `<RafflePick.Countdown>`
|
|
125
|
+
|
|
126
|
+
Schedules auto-freeze after `seconds`. Renders an SVG ring + numeric label by default. Optional render-prop for custom output.
|
|
127
|
+
|
|
128
|
+
| Prop | Type | Notes |
|
|
129
|
+
| ----------- | ---------------------------------- | ---------------------------------------------- |
|
|
130
|
+
| `seconds` | `number` (required) | Auto-freeze delay. Renders only while running. |
|
|
131
|
+
| `className` | `string` | — |
|
|
132
|
+
| `style` | `CSSProperties` | — |
|
|
133
|
+
| `children` | `(remaining: number) => ReactNode` | Render-prop for custom UI. |
|
|
134
|
+
|
|
135
|
+
### `<RafflePick.Slots>`
|
|
136
|
+
|
|
137
|
+
Independent multi-reel slot machine. Each reel ticks on its own and stops with a stagger.
|
|
138
|
+
|
|
139
|
+
| Prop | Type | Default | Notes |
|
|
140
|
+
| -------------------------------------------------- | -------------------------- | -------------- | -------------------------------------------- |
|
|
141
|
+
| `length` | `number` | `3` | Number of reels. |
|
|
142
|
+
| `chars` | `string` | `'0123456789'` | Charset pool. Emoji-safe (code-point split). |
|
|
143
|
+
| `spinInterval` | `number` (ms, ≥ 50) | `80` | Tick rate per reel. |
|
|
144
|
+
| `staggerMs` | `number` | `220` | Delay between consecutive reel stops. |
|
|
145
|
+
| `onResult` | `(joined: string) => void` | — | Fires when the last reel lands. |
|
|
146
|
+
| `className`, `slotClassName`, `style`, `slotStyle` | various | — | Style hooks. |
|
|
147
|
+
|
|
148
|
+
## Recipes
|
|
149
|
+
|
|
150
|
+
### Inline chip in a sentence
|
|
151
|
+
|
|
152
|
+
```tsx
|
|
153
|
+
<RafflePick min={1} max={36} as="p" autoStart={false}>
|
|
154
|
+
Roulette landed on <RafflePick.Value animation="roll" className="chip" /> —{' '}
|
|
155
|
+
<RafflePick.Button startLabel="spin again" stopLabel="stop" className="link-btn" />
|
|
156
|
+
</RafflePick>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Hero with countdown ring
|
|
160
|
+
|
|
161
|
+
```tsx
|
|
162
|
+
<RafflePick min={1} max={999} inertia autoStart={false} className="hero">
|
|
163
|
+
<RafflePick.Countdown seconds={5} className="hero__ring" />
|
|
164
|
+
<RafflePick.Value animation="blur" className="hero__value" />
|
|
165
|
+
<RafflePick.Button startLabel="Start Draw" stopLabel="Stop" className="hero__btn" />
|
|
166
|
+
</RafflePick>
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Slot machine with custom result handler
|
|
170
|
+
|
|
171
|
+
```tsx
|
|
172
|
+
<RafflePick inertia autoStart={false}>
|
|
173
|
+
<RafflePick.Slots
|
|
174
|
+
length={5}
|
|
175
|
+
chars="0123456789"
|
|
176
|
+
staggerMs={260}
|
|
177
|
+
onResult={(code) => console.log('winning code:', code)}
|
|
178
|
+
/>
|
|
179
|
+
<RafflePick.Button startLabel="Spin" stopLabel="Stop" />
|
|
180
|
+
</RafflePick>
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Roadmap
|
|
184
|
+
|
|
185
|
+
- **Winner position** — emit row/index alongside value (`onSelect` receives `{ value, index }`) and a `<RafflePick.WinnerPosition>` consumer that reflects the landed position.
|
|
186
|
+
- **`bounce` animation** — vertical hop on each tick, easing back to baseline.
|
|
187
|
+
- **`glitch` animation** — offset color-channel pulse for a digital noise feel during running.
|
|
188
|
+
- Headless `useRafflePick()` hook for users who want zero rendering from the lib.
|
|
189
|
+
- Render-prop variant of `<Value>` for fully custom DOM.
|
|
190
|
+
|
|
191
|
+
## Performance notes
|
|
192
|
+
|
|
193
|
+
- Cycle ticks (every `interval` ms) write `textContent` directly via refs — no React render.
|
|
194
|
+
- Phase machine re-renders only on transitions (start, inertia step, settle, freeze).
|
|
195
|
+
- CSS animation duration is bound to `--rrp-tick` so each cycle aligns with one tick — no cross-frame tearing.
|
|
196
|
+
- `will-change` is scoped to running / inertia phases only, so idle / frozen text renders with crisp subpixel anti-aliasing.
|
|
197
|
+
|
|
198
|
+
## License
|
|
199
|
+
|
|
200
|
+
MIT
|