@ncdai/react-wheel-picker 1.0.0 → 1.0.1

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,186 @@
1
1
  # react-wheel-picker
2
2
 
3
3
  iOS-like wheel picker for React with smooth inertia scrolling and infinite loop support.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @ncdai/react-wheel-picker
9
+ # or
10
+ yarn add @ncdai/react-wheel-picker
11
+ # or
12
+ pnpm add @ncdai/react-wheel-picker
13
+ ```
14
+
15
+ ## Anatomy
16
+
17
+ The wheel picker consists of two main components:
18
+
19
+ ### WheelPickerWrapper
20
+
21
+ The wrapper component that contains one or more wheel pickers. It provides the container structure and handles the layout of multiple wheels.
22
+
23
+ ```tsx
24
+ <WheelPickerWrapper>
25
+ <WheelPicker />
26
+ <WheelPicker />
27
+ <WheelPicker />
28
+ </WheelPickerWrapper>
29
+ ```
30
+
31
+ ### WheelPicker
32
+
33
+ The core component that renders a single wheel of options. Each wheel picker consists of:
34
+
35
+ - A container with a 3D perspective
36
+ - A scrollable list of options
37
+ - A highlight area that indicates the selected option
38
+ - A mask that creates the fade effect at the top and bottom
39
+
40
+ ```tsx
41
+ <WheelPicker
42
+ options={[
43
+ { label: "Option 1", value: "1" },
44
+ { label: "Option 2", value: "2" },
45
+ ]}
46
+ value="1"
47
+ onValueChange={(value) => {}}
48
+ />
49
+ ```
50
+
51
+ > **Styling:** The component is unstyled by default. You can customize the appearance using the `classNames` prop to style:
52
+ >
53
+ > - Individual options (`optionItem`)
54
+ > - The highlight area (`highlightWrapper`)
55
+ > - The highlighted option (`highlightItem`)
56
+ >
57
+ > Check out the TailwindCSS example below to see how to style the component.
58
+
59
+ ## Usage
60
+
61
+ 1. Import CSS:
62
+
63
+ ```tsx
64
+ import "@ncdai/react-wheel-picker/dist/style.css";
65
+ ```
66
+
67
+ 2. Import components:
68
+
69
+ ```tsx
70
+ import {
71
+ WheelPicker,
72
+ WheelPickerWrapper,
73
+ type WheelPickerOption,
74
+ type WheelPickerClassNames,
75
+ } from "@ncdai/react-wheel-picker";
76
+ ```
77
+
78
+ 3. Example with TailwindCSS:
79
+
80
+ ```tsx
81
+ const createArray = (length: number, add = 0): WheelPickerOption[] =>
82
+ Array.from({ length }, (_, i) => {
83
+ const value = i + add;
84
+ return {
85
+ label: value.toString().padStart(2, "0"),
86
+ value: value.toString(),
87
+ };
88
+ });
89
+
90
+ const hourOptions = createArray(12, 1);
91
+ const minuteOptions = createArray(60);
92
+ const meridiemOptions: WheelPickerOption[] = [
93
+ { label: "AM", value: "AM" },
94
+ { label: "PM", value: "PM" },
95
+ ];
96
+
97
+ const classNames: WheelPickerClassNames = {
98
+ optionItem: "text-muted-foreground",
99
+ highlightWrapper: "bg-accent text-accent-foreground",
100
+ };
101
+
102
+ export function TimePicker() {
103
+ const [hour, setHour] = useState("8");
104
+ const [minute, setMinute] = useState("30");
105
+ const [meridiem, setMeridiem] = useState("PM");
106
+
107
+ return (
108
+ <div className="container mx-auto space-y-4 p-4">
109
+ <div className="mx-auto flex h-8 max-w-56 items-center justify-center text-lg font-semibold">
110
+ {hour.padStart(2, "0")}:{minute.padStart(2, "0")} {meridiem}
111
+ </div>
112
+
113
+ <WheelPickerWrapper className="mx-auto max-w-56 rounded-xl border bg-background">
114
+ <WheelPicker
115
+ options={hourOptions}
116
+ value={hour}
117
+ onValueChange={setHour}
118
+ infinite
119
+ classNames={classNames}
120
+ />
121
+ <WheelPicker
122
+ options={minuteOptions}
123
+ value={minute}
124
+ onValueChange={setMinute}
125
+ infinite
126
+ classNames={classNames}
127
+ />
128
+ <WheelPicker
129
+ options={meridiemOptions}
130
+ value={meridiem}
131
+ onValueChange={setMeridiem}
132
+ classNames={classNames}
133
+ />
134
+ </WheelPickerWrapper>
135
+ </div>
136
+ );
137
+ }
138
+ ```
139
+
140
+ > View the complete source code at [https://github.com/ncdai/react-wheel-picker/tree/main/website](https://github.com/ncdai/react-wheel-picker/tree/main/website)
141
+
142
+ ## API
143
+
144
+ ### WheelPicker
145
+
146
+ Props for the WheelPicker component:
147
+
148
+ | Prop | Type | Default | Description |
149
+ | ----------------- | ------------------------- | ---------- | -------------------------------------------------------------- |
150
+ | `options` | `WheelPickerOption[]` | (required) | Array of options to display in the wheel |
151
+ | `value` | `string` | - | Current value of the picker (controlled mode) |
152
+ | `defaultValue` | `string` | - | Default value of the picker (uncontrolled mode) |
153
+ | `onValueChange` | `(value: string) => void` | - | Callback fired when the selected value changes |
154
+ | `infinite` | `boolean` | `false` | Enable infinite scrolling |
155
+ | `visibleCount` | `number` | `20` | Number of options visible on the wheel (must be multiple of 4) |
156
+ | `dragSensitivity` | `number` | `3` | Sensitivity of the drag interaction (higher = more sensitive) |
157
+ | `classNames` | `WheelPickerClassNames` | - | Custom class names for styling |
158
+
159
+ ### WheelPickerWrapper
160
+
161
+ Props for the WheelPickerWrapper component:
162
+
163
+ | Prop | Type | Default | Description |
164
+ | ----------- | ----------------- | ---------- | -------------------------- |
165
+ | `className` | `string` | - | CSS class name for wrapper |
166
+ | `children` | `React.ReactNode` | (required) | WheelPicker components |
167
+
168
+ ### Types
169
+
170
+ ```tsx
171
+ type WheelPickerOption = {
172
+ /** Value that will be returned when this option is selected */
173
+ value: string;
174
+ /** Text label displayed for this option */
175
+ label: string;
176
+ };
177
+
178
+ type WheelPickerClassNames = {
179
+ /** Class name for individual option items */
180
+ optionItem?: string;
181
+ /** Class name for the wrapper of the highlighted area */
182
+ highlightWrapper?: string;
183
+ /** Class name for the highlighted item */
184
+ highlightItem?: string;
185
+ };
186
+ ```
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.1",
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",