@watcha-authentic/react-slider 0.0.1 → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 @edge-effect#dark1451
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,84 @@
1
+ # @watcha-authentic/react-slider
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@watcha-authentic/react-slider)](https://www.npmjs.com/package/@watcha-authentic/react-slider)
4
+
5
+ 리액트기반 슬라이더 컴포넌트입니다. 드래그/스와이프, 키보드 네비게이션을 지원하며 무한 루프 슬라이더를 제공합니다.
6
+
7
+ ## 피어 종속성
8
+
9
+ 이 패키지는 다음 패키지들을 피어 종속성으로 요구합니다.
10
+
11
+ ```bash
12
+ pnpm add react@>=18.0.0 react-dom@>=18.0.0
13
+ ```
14
+
15
+ ## 설치
16
+
17
+ ```bash
18
+ pnpm add @watcha-authentic/react-slider react@>=18.0.0 react-dom@>=18.0.0
19
+ ```
20
+
21
+ ## 사용 예
22
+
23
+ ### 기본 사용
24
+
25
+ ```tsx
26
+ import { Slider } from "@watcha-authentic/react-slider";
27
+ import "@watcha-authentic/react-slider/style.css";
28
+
29
+ const items = [
30
+ { id: 1, title: "Item 1" },
31
+ { id: 2, title: "Item 2" },
32
+ { id: 3, title: "Item 3" },
33
+ ];
34
+
35
+ function App() {
36
+ return (
37
+ <Slider
38
+ items={items}
39
+ onItemKey={(item) => item.id}
40
+ onCreateItemView={(item) => <div>{item.title}</div>}
41
+ onIndexChange={(newIndex) => console.log("Index changed:", newIndex)}
42
+ />
43
+ );
44
+ }
45
+ ```
46
+
47
+ ### 스타일 import
48
+
49
+ CSS 스타일을 import하여 사용할 수 있습니다:
50
+
51
+ ```tsx
52
+ import "@watcha-authentic/react-slider/style.css";
53
+ ```
54
+
55
+ ### Context 사용
56
+
57
+ ```tsx
58
+ import {
59
+ Slider,
60
+ SliderContextProvider,
61
+ useSliderContext,
62
+ } from "@watcha-authentic/react-slider";
63
+
64
+ function CustomNavigation() {
65
+ const { currentIndex, goToIndex } = useSliderContext();
66
+
67
+ return (
68
+ <div>
69
+ <button onClick={() => goToIndex(currentIndex - 1)}>Previous</button>
70
+ <span>Current: {currentIndex}</span>
71
+ <button onClick={() => goToIndex(currentIndex + 1)}>Next</button>
72
+ </div>
73
+ );
74
+ }
75
+
76
+ function App() {
77
+ return (
78
+ <SliderContextProvider>
79
+ <Slider items={items} onItemKey={(item) => item.id} onCreateItemView={(item) => <div>{item.title}</div>} />
80
+ <CustomNavigation />
81
+ </SliderContextProvider>
82
+ );
83
+ }
84
+ ```
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "SliderItemContextProvider", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return SliderItemContextProvider;
9
+ }
10
+ });
11
+ const _jsxruntime = require("react/jsx-runtime");
12
+ const _slidercontext = require("./slider-context");
13
+ const SliderItemContextProvider = ({ children, immediate, isFocused, itemIndex, slideTriggerEvent, transition })=>{
14
+ const value = {
15
+ immediate,
16
+ isFocused,
17
+ itemIndex,
18
+ slideTriggerEvent,
19
+ transition
20
+ };
21
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_slidercontext.SliderItemContext.Provider, {
22
+ value: value,
23
+ children: children
24
+ });
25
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "SliderItemContext", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return SliderItemContext;
9
+ }
10
+ });
11
+ const _react = /*#__PURE__*/ _interop_require_default(require("react"));
12
+ function _interop_require_default(obj) {
13
+ return obj && obj.__esModule ? obj : {
14
+ default: obj
15
+ };
16
+ }
17
+ const SliderItemContext = /*#__PURE__*/ _react.default.createContext(null);
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useSliderContext", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return useSliderContext;
9
+ }
10
+ });
11
+ const _reacteventcallback = require("@watcha-authentic/react-event-callback");
12
+ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
13
+ const _slidercontext = require("../context/slider-context");
14
+ function _getRequireWildcardCache(nodeInterop) {
15
+ if (typeof WeakMap !== "function") return null;
16
+ var cacheBabelInterop = new WeakMap();
17
+ var cacheNodeInterop = new WeakMap();
18
+ return (_getRequireWildcardCache = function(nodeInterop) {
19
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
20
+ })(nodeInterop);
21
+ }
22
+ function _interop_require_wildcard(obj, nodeInterop) {
23
+ if (!nodeInterop && obj && obj.__esModule) {
24
+ return obj;
25
+ }
26
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
27
+ return {
28
+ default: obj
29
+ };
30
+ }
31
+ var cache = _getRequireWildcardCache(nodeInterop);
32
+ if (cache && cache.has(obj)) {
33
+ return cache.get(obj);
34
+ }
35
+ var newObj = {
36
+ __proto__: null
37
+ };
38
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
39
+ for(var key in obj){
40
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
41
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
42
+ if (desc && (desc.get || desc.set)) {
43
+ Object.defineProperty(newObj, key, desc);
44
+ } else {
45
+ newObj[key] = obj[key];
46
+ }
47
+ }
48
+ }
49
+ newObj.default = obj;
50
+ if (cache) {
51
+ cache.set(obj, newObj);
52
+ }
53
+ return newObj;
54
+ }
55
+ const useSliderContext = (callbacks)=>{
56
+ const context = _react.default.useContext(_slidercontext.SliderItemContext);
57
+ if (!context) {
58
+ throw new Error("useSliderContext must be used within SliderItemContextProvider");
59
+ }
60
+ const stableOnBlur = (0, _reacteventcallback.useEventCallback)(callbacks.onBlur);
61
+ const stableOnFocus = (0, _reacteventcallback.useEventCallback)(callbacks.onFocus);
62
+ const stableOnInitialState = (0, _reacteventcallback.useEventCallback)(callbacks.onInitialState);
63
+ const stableOnTransitionChange = (0, _reacteventcallback.useEventCallback)(callbacks.onTransitionChange);
64
+ const prevFocusedRef = (0, _react.useRef)(null);
65
+ /**
66
+ * - 초기 마운트 또는 상태 변경시 콜백 호출
67
+ */ (0, _react.useLayoutEffect)(()=>{
68
+ const isInitialMount = prevFocusedRef.current === null;
69
+ if (prevFocusedRef.current !== context.isFocused) {
70
+ if (isInitialMount) {
71
+ // 초기 마운트 시 onInitialState 호출
72
+ stableOnInitialState(context.isFocused);
73
+ } else {
74
+ // 상태 변경 시 onBlur/onFocus 호출
75
+ if (context.isFocused) {
76
+ stableOnFocus(context.slideTriggerEvent === "swipe");
77
+ } else {
78
+ stableOnBlur();
79
+ }
80
+ }
81
+ prevFocusedRef.current = context.isFocused;
82
+ }
83
+ }, [
84
+ context.isFocused,
85
+ context.slideTriggerEvent,
86
+ stableOnBlur,
87
+ stableOnFocus,
88
+ stableOnInitialState
89
+ ]);
90
+ /**
91
+ * - transition 값 변경 시 콜백 호출
92
+ */ (0, _react.useLayoutEffect)(()=>{
93
+ stableOnTransitionChange(context.transition, context.immediate);
94
+ }, [
95
+ context.transition,
96
+ context.immediate,
97
+ stableOnTransitionChange
98
+ ]);
99
+ };