Skip to content

Commit ceef708

Browse files
authored
Merge pull request #1 from camiha/develop
create package
2 parents bf02b82 + a2a5c7b commit ceef708

File tree

15 files changed

+2986
-1
lines changed

15 files changed

+2986
-1
lines changed

.vscode/settings.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"[javascript]": {
3+
"editor.defaultFormatter": "biomejs.biome",
4+
"editor.formatOnSave": true
5+
},
6+
"[typescript]": {
7+
"editor.defaultFormatter": "biomejs.biome",
8+
"editor.formatOnSave": true
9+
},
10+
"[typescriptreact]": {
11+
"editor.defaultFormatter": "biomejs.biome",
12+
"editor.formatOnSave": true
13+
}
14+
}

LICENCE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023-present, KAMIHARA Takumi (camiha)
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.

README.md

Lines changed: 165 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,166 @@
1-
# React-Hook-Roulette
1+
# React Hook Roulette
22
Minimal roulette wheel component. built with React Hooks.
3+
4+
## Features
5+
- Easy Setup: Seamlessly integrates into React apps using React Hooks, simplifying embedding and state management.
6+
- Canvas-Based Rendering: Uses HTML Canvas for high-performance rendering.
7+
- Simple API: easy-to-use API for customization.
8+
9+
## Demo
10+
![demo](https://github.com/camiha/React-Hook-Roulette/assets/65489256/26785362-c7a2-402e-bdb1-7877531438bd)
11+
12+
## Setup
13+
### npm
14+
```sh
15+
npm install react-hook-roulette
16+
```
17+
### pnpm
18+
```sh
19+
pnpm add react-hook-roulette
20+
```
21+
### yarn
22+
```sh
23+
yarn add react-hook-roulette
24+
```
25+
26+
### Code Example
27+
```tsx
28+
import { Roulette, useRoulette } from 'react-hook-roulette';
29+
30+
const App = () => {
31+
const data = [
32+
{ name: "label1" },
33+
{ name: "label2" },
34+
{ name: "label3" },
35+
{ name: "label4" },
36+
{ name: "label5" },
37+
{ name: "label6" },
38+
];
39+
const { roulette, onStart, onStop, result } = useRoulette({ items: data });
40+
41+
return (
42+
<div>
43+
<Roulette roulette={roulette} />
44+
<button onClick={onStart}>Start</button>
45+
<button onClick={onStop}>Stop</button>
46+
{result && <div>Result: {result}</div>}
47+
</div>
48+
);
49+
};
50+
```
51+
52+
## API References
53+
### `RouletteItem`
54+
| Property | Type | Description |
55+
|-----------|-----------|---------------------------------------------------|
56+
| `name` | `string` | Label for the roulette segment. |
57+
| `bg` | `string?` | Background color of the roulette segment. |
58+
| `color` | `string?` | Text color for the segment label. |
59+
| `weight` | `number?` | Determines the segment's size relative to others. |
60+
61+
If you want to set styling globally, please refer to the [StyleOption](####StyleOption) section. (If both are specified, the one specified in rouletteItem takes precedence.)
62+
63+
### `useRoulette` Hook
64+
#### Props
65+
| Property | Type | Description |
66+
|----------|---------------------|------------------------------------------------------|
67+
| `items` | `RouletteItem[]` | Array of items to display on the roulette wheel. |
68+
| `options`| `RouletteOptions` | Optional settings to customize the roulette wheel. |
69+
70+
#### Return Values
71+
| Property | Type | Description |
72+
|-------------|------------------|----------------------------------------|
73+
| `roulette` | `RouletteCanvas` | Contains the size of the roulette and a ref to the canvas element. |
74+
| `result` | `string` | The result after the wheel stops spinning. |
75+
| `onStart` | `() => void` | Function to start the wheel spinning. |
76+
| `onStop` | `() => void` | Function to stop the wheel spinning. |
77+
78+
#### Options
79+
| Property | Type | Default Value | Description |
80+
|---------------------|----------------------|---------------|--------------------------------------------------|
81+
| `size` | `number` | `400` | Diameter of the roulette wheel. |
82+
| `initialAngle` | `number` | `0` | Starting angle of the wheel. |
83+
| `rotationDirection` | `RotationDirection` | `"clockwise"` | Rotation direction. |
84+
| `maxSpeed` | `number` | `100` | Maximum rotation speed. |
85+
| `acceleration` | `number` | `1` | Acceleration rate until reaching max speed. |
86+
| `deceleration` | `number` | `1` | Deceleration rate after stopping. |
87+
| `determineAngle` | `number` | `75` | Angle for determining the selected item. |
88+
| `showArrow` | `boolean` | `true` | Controls visibility of the selection arrow. |
89+
| `style` | `StyleOption` | | Customize roulette stylings. |
90+
91+
#### StyleOption
92+
##### CanvasStyle
93+
| Property | Type | Description |
94+
|-----------------|---------------------|---------------------------------------------------|
95+
| `bg` | `string` | Background color of the canvas. |
96+
97+
##### PieStyle
98+
| Property | Type | Description |
99+
|-----------------|---------------------|---------------------------------------------------|
100+
| `theme` | `PieTheme[]` | Array of theme options for the pie segments. |
101+
102+
##### LabelStyle
103+
| Property | Type | Description |
104+
|-----------------|---------------------|---------------------------------------------------|
105+
| `font` | `string` | Font style and size for the label text. |
106+
| `defaultColor` | `string` | Default text color for the label. |
107+
| `align` | `CanvasTextAlign` | Horizontal alignment of the label text. |
108+
| `baseline` | `CanvasTextBaseline`| Vertical alignment of the label text. |
109+
| `offset` | `number` | Position offset of the label from the center. |
110+
111+
##### ArrowStyle
112+
| Property | Type | Description |
113+
|-----------------|---------------------|---------------------------------------------------|
114+
| `bg` | `string` | Background color of the arrow. |
115+
| `size` | `number` | Size of the arrow. |
116+
117+
#### Default config
118+
```ts
119+
const option = {
120+
size: 400,
121+
maxSpeed: 100,
122+
rotationDirection: "clockwise",
123+
acceleration: 1,
124+
deceleration: 1,
125+
initialAngle: 0,
126+
determineAngle: 75,
127+
showArrow: true,
128+
style: {
129+
canvas: {
130+
bg: "#fff",
131+
},
132+
arrow: {
133+
bg: "#000",
134+
size: 16,
135+
},
136+
label: {
137+
font: "16px Arial",
138+
align: "right",
139+
baseline: "middle",
140+
offset: 0.75,
141+
defaultColor: "#000",
142+
},
143+
pie: {
144+
theme: [
145+
{
146+
bg: "#e0e7ff",
147+
},
148+
{
149+
bg: "#a5b4fc",
150+
},
151+
{
152+
bg: "#6366f1",
153+
color: "#fff",
154+
},
155+
{
156+
bg: "#4338ca",
157+
color: "#fff",
158+
},
159+
],
160+
},
161+
},
162+
}
163+
```
164+
165+
### License
166+
MIT

biome.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.3.3/schema.json",
3+
"organizeImports": {
4+
"enabled": true
5+
},
6+
"linter": {
7+
"enabled": true,
8+
"rules": {
9+
"recommended": true
10+
}
11+
}
12+
}

package.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "react-hook-roulette",
3+
"version": "0.0.1",
4+
"description": "Minimal roulette wheel component. built with React Hooks.",
5+
"homepage": "https://github.com/camiha/React-Hook-Roulette",
6+
"type": "module",
7+
"exports": {
8+
".": {
9+
"import": "./dist/index.mjs",
10+
"require": "./dist/index.cjs"
11+
}
12+
},
13+
"main": "./dist/index.cjs",
14+
"typings": "./dist/index.d.ts",
15+
"files": [
16+
"dist",
17+
"LICENSE",
18+
"package.json",
19+
"README.md"
20+
],
21+
"scripts": {
22+
"test": "echo \"Error: no test specified\" && exit 1",
23+
"build": "unbuild"
24+
},
25+
"keywords": [
26+
"react",
27+
"react-hooks",
28+
"roulette",
29+
"wheel"
30+
],
31+
"author": "",
32+
"license": "MIT",
33+
"devDependencies": {
34+
"@biomejs/biome": "^1.4.1",
35+
"unbuild": "^2.0.0"
36+
},
37+
"peerDependencies": {
38+
"@types/react": "^18",
39+
"@types/react-dom": "^18",
40+
"react": "^18"
41+
}
42+
}

0 commit comments

Comments
 (0)