@ncdai/react-wheel-picker 1.0.0 → 1.0.2

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/README.md CHANGED
@@ -1,3 +1,153 @@
1
- # react-wheel-picker
1
+ # React Wheel Picker
2
2
 
3
3
  iOS-like wheel picker for React with smooth inertia scrolling and infinite loop support.
4
+
5
+ Check out the live demo: [react-wheel-picker.chanhdai.com](https://react-wheel-picker.chanhdai.com)
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pnpm add @ncdai/react-wheel-picker
11
+ # or
12
+ yarn add @ncdai/react-wheel-picker
13
+ # or
14
+ npm install @ncdai/react-wheel-picker
15
+ ```
16
+
17
+ ## Anatomy
18
+
19
+ The wheel picker consists of two main components:
20
+
21
+ ### WheelPickerWrapper
22
+
23
+ The wrapper component that contains one or more wheel pickers. It provides the container structure and handles the layout of multiple wheels.
24
+
25
+ ```tsx
26
+ <WheelPickerWrapper>
27
+ <WheelPicker />
28
+ <WheelPicker />
29
+ <WheelPicker />
30
+ </WheelPickerWrapper>
31
+ ```
32
+
33
+ ### WheelPicker
34
+
35
+ The core component that renders a single wheel of options. Each wheel picker consists of:
36
+
37
+ - A container with a 3D perspective
38
+ - A scrollable list of options
39
+ - A highlight area that indicates the selected option
40
+ - A mask that creates the fade effect at the top and bottom
41
+
42
+ ```tsx
43
+ <WheelPicker
44
+ options={[
45
+ { label: "React", value: "react" },
46
+ { label: "Vue", value: "vue" },
47
+ { label: "Angular", value: "angular" },
48
+ ]}
49
+ />
50
+ ```
51
+
52
+ ## Usage
53
+
54
+ ### Import CSS
55
+
56
+ ```tsx
57
+ import "@ncdai/react-wheel-picker/dist/style.css";
58
+ ```
59
+
60
+ This CSS file includes only the core layout for the wheel picker. For custom visuals, use the `classNames` prop as shown in the Tailwind CSS example below.
61
+
62
+ ### Import components
63
+
64
+ ```tsx
65
+ import {
66
+ WheelPicker,
67
+ WheelPickerWrapper,
68
+ type WheelPickerOption,
69
+ type WheelPickerClassNames,
70
+ } from "@ncdai/react-wheel-picker";
71
+ ```
72
+
73
+ ### Example with Tailwind CSS
74
+
75
+ ```tsx
76
+ const options: WheelPickerOption[] = [
77
+ {
78
+ label: "React",
79
+ value: "react",
80
+ },
81
+ {
82
+ label: "Vue",
83
+ value: "vue",
84
+ },
85
+ {
86
+ label: "Angular",
87
+ value: "angular",
88
+ },
89
+ {
90
+ label: "Svelte",
91
+ value: "svelte",
92
+ },
93
+ ];
94
+
95
+ const classNames: WheelPickerClassNames = {
96
+ optionItem: "text-zinc-400",
97
+ highlightWrapper: "bg-zinc-100 text-zinc-950",
98
+ };
99
+
100
+ export function WheelPickerDemo() {
101
+ return (
102
+ <WheelPickerWrapper className="max-w-56 rounded-md border border-zinc-200 bg-white shadow-xs">
103
+ <WheelPicker options={options} classNames={classNames} />
104
+ </WheelPickerWrapper>
105
+ );
106
+ }
107
+ ```
108
+
109
+ ## API
110
+
111
+ ### WheelPicker
112
+
113
+ Props for the WheelPicker component:
114
+
115
+ | Prop | Type | Default | Description |
116
+ | ----------------- | ------------------------- | ---------- | -------------------------------------------------------------- |
117
+ | `options` | `WheelPickerOption[]` | (required) | Array of options to display in the wheel |
118
+ | `value` | `string` | - | Current value of the picker (controlled mode) |
119
+ | `defaultValue` | `string` | - | Default value of the picker (uncontrolled mode) |
120
+ | `onValueChange` | `(value: string) => void` | - | Callback fired when the selected value changes |
121
+ | `infinite` | `boolean` | `false` | Enable infinite scrolling |
122
+ | `visibleCount` | `number` | `20` | Number of options visible on the wheel (must be multiple of 4) |
123
+ | `dragSensitivity` | `number` | `3` | Sensitivity of the drag interaction (higher = more sensitive) |
124
+ | `classNames` | `WheelPickerClassNames` | - | Custom class names for styling |
125
+
126
+ ### WheelPickerWrapper
127
+
128
+ Props for the WheelPickerWrapper component:
129
+
130
+ | Prop | Type | Default | Description |
131
+ | ----------- | ----------------- | ---------- | -------------------------- |
132
+ | `className` | `string` | - | CSS class name for wrapper |
133
+ | `children` | `React.ReactNode` | (required) | WheelPicker components |
134
+
135
+ ### Types
136
+
137
+ ```tsx
138
+ type WheelPickerOption = {
139
+ /** Value that will be returned when this option is selected */
140
+ value: string;
141
+ /** Text label displayed for this option */
142
+ label: string;
143
+ };
144
+
145
+ type WheelPickerClassNames = {
146
+ /** Class name for individual option items */
147
+ optionItem?: string;
148
+ /** Class name for the wrapper of the highlighted area */
149
+ highlightWrapper?: string;
150
+ /** Class name for the highlighted item */
151
+ highlightItem?: string;
152
+ };
153
+ ```
package/dist/index.js CHANGED
@@ -446,10 +446,7 @@ const WheelPicker = ({ defaultValue, value: valueProp, onValueChange, options: o
446
446
  container.addEventListener("wheel", handleWheelEvent, opts);
447
447
  document.addEventListener("mousedown", handleDragStartEvent, opts);
448
448
  document.addEventListener("mouseup", handleDragEndEvent, opts);
449
- return ()=>{
450
- console.log("cleanup");
451
- controller.abort();
452
- };
449
+ return ()=>controller.abort();
453
450
  }, [
454
451
  handleDragEndEvent,
455
452
  handleDragStartEvent,
@@ -462,7 +459,6 @@ const WheelPicker = ({ defaultValue, value: valueProp, onValueChange, options: o
462
459
  value,
463
460
  valueProp
464
461
  ]);
465
- console.log("render WheelPicker", valueProp);
466
462
  return /*#__PURE__*/ React__default.default.createElement("div", {
467
463
  ref: containerRef,
468
464
  "data-rwp": true,
package/dist/index.mjs CHANGED
@@ -440,10 +440,7 @@ const WheelPicker = ({ defaultValue, value: valueProp, onValueChange, options: o
440
440
  container.addEventListener("wheel", handleWheelEvent, opts);
441
441
  document.addEventListener("mousedown", handleDragStartEvent, opts);
442
442
  document.addEventListener("mouseup", handleDragEndEvent, opts);
443
- return ()=>{
444
- console.log("cleanup");
445
- controller.abort();
446
- };
443
+ return ()=>controller.abort();
447
444
  }, [
448
445
  handleDragEndEvent,
449
446
  handleDragStartEvent,
@@ -456,7 +453,6 @@ const WheelPicker = ({ defaultValue, value: valueProp, onValueChange, options: o
456
453
  value,
457
454
  valueProp
458
455
  ]);
459
- console.log("render WheelPicker", valueProp);
460
456
  return /*#__PURE__*/ React.createElement("div", {
461
457
  ref: containerRef,
462
458
  "data-rwp": true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ncdai/react-wheel-picker",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "iOS-like wheel picker for React with smooth inertia scrolling and infinite loop support.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -27,11 +27,16 @@
27
27
  "type-check": "tsc --noEmit",
28
28
  "copy-assets": "cp -r ./src/style.css ./dist/style.css",
29
29
  "dev:website": "turbo run dev --filter=website...",
30
- "lint": "eslint . --ext .ts,.tsx --ignore-pattern 'website/**'",
30
+ "prettier:check": "prettier --check .",
31
31
  "format": "prettier --write .",
32
32
  "test": "echo \"Error: no test specified\" && exit 1"
33
33
  },
34
- "keywords": [],
34
+ "keywords": [
35
+ "react",
36
+ "wheel picker",
37
+ "wheel",
38
+ "picker"
39
+ ],
35
40
  "author": "Nguyen Chanh Dai <dai@chanhdai.com>",
36
41
  "license": "MIT",
37
42
  "homepage": "https://react-wheel-picker.chanhdai.com",
@@ -55,4 +60,4 @@
55
60
  "peerDependencies": {
56
61
  "react": "^16.8 || ^17.0 || ^18.0 || ^19.0.0 || ^19.0.0-rc"
57
62
  }
58
- }
63
+ }