Skip to content

Commit acd6013

Browse files
committed
chore: update demo
1 parent 8c17535 commit acd6013

File tree

2 files changed

+48
-23
lines changed

2 files changed

+48
-23
lines changed

debug/state-api/index.html

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@
7272
background-color: #4caf50; /* 채워지는 색 */
7373
transition: width 0.3s ease; /* 부드럽게 변화 */
7474
}
75+
#scroll-progress-bar {
76+
width: 600px;
77+
height: 20px;
78+
border-radius: 20px;
79+
background-color: #e0e0e0;
80+
overflow: hidden;
81+
}
82+
#scroll-progress-fill {
83+
height: 100%;
84+
width: 0%; /* 초기에는 0% 채워짐 */
85+
background-color: #2196f3; /* 채워지는 색 */
86+
transition: width 0.3s ease; /* 부드럽게 변화 */
87+
}
7588
</style>
7689
</head>
7790
<body>
@@ -80,7 +93,7 @@
8093
<button class="navigation-btn" id="prev">Previous</button>
8194
<div class="flicking-viewport">
8295
<div class="flicking-camera">
83-
<div class="flicking-panel">x0</div>
96+
<div class="flicking-panel" style="width: 500px;">x0</div>
8497
<div class="flicking-panel">x1</div>
8598
<div class="flicking-panel">x2</div>
8699
<div class="flicking-panel">x3</div>
@@ -93,6 +106,9 @@
93106
<div id="progress-bar">
94107
<div id="progress-fill"></div>
95108
</div>
109+
<div id="scroll-progress-bar">
110+
<div id="scroll-progress-fill"></div>
111+
</div>
96112
</div>
97113

98114
<div class="add">
@@ -109,10 +125,16 @@
109125
<script src="../../dist/flicking.pkgd.js"></script>
110126
<script>
111127
document.addEventListener("DOMContentLoaded", () => {
112-
const flicking = new Flicking(".flicking-viewport");
128+
const flicking = new Flicking(".flicking-viewport", {renderOnlyVisible: true});
113129
const { connectFlickingStateApi } = Flicking;
114130
const reactiveObj = connectFlickingStateApi(flicking);
115-
const {isReachStart, isReachEnd, totalPanelCount, currentPanelIndex, moveTo} = reactiveObj
131+
const {
132+
isReachStart,
133+
isReachEnd,
134+
totalPanelCount,
135+
currentPanelIndex,
136+
moveTo,
137+
} = reactiveObj;
116138

117139
// Navigation buttons
118140
const prevButton = document.getElementById("prev");
@@ -191,21 +213,18 @@
191213
const paginationElement = document.getElementById("pagination");
192214
const progressFillElement = document.getElementById("progress-fill");
193215

194-
const pageNums = Array.from(
195-
{ length: totalPanelCount },
196-
(_, i) => {
197-
const div = document.createElement("div");
198-
div.className = `pagination-num ${
199-
i === currentPanelIndex ? "active" : ""
200-
}`;
201-
div.textContent = `${i}`;
202-
203-
div.addEventListener("click", (e) => {
204-
moveTo(i);
205-
});
206-
return div;
207-
}
208-
);
216+
const pageNums = Array.from({ length: totalPanelCount }, (_, i) => {
217+
const div = document.createElement("div");
218+
div.className = `pagination-num ${
219+
i === currentPanelIndex ? "active" : ""
220+
}`;
221+
div.textContent = `${i}`;
222+
223+
div.addEventListener("click", (e) => {
224+
moveTo(i);
225+
});
226+
return div;
227+
});
209228

210229
paginationElement.append(...pageNums);
211230

@@ -218,10 +237,15 @@
218237
});
219238
});
220239

221-
reactiveObj.subscribe("progress", (nextValue) => {
240+
reactiveObj.subscribe("indexProgress", (nextValue) => {
222241
progressFillElement.style.width = `${nextValue}%`;
223-
})
224-
242+
});
243+
244+
245+
const scrollProgressFillElement = document.getElementById("scroll-progress-fill");
246+
reactiveObj.subscribe("scrollProgress", (nextValue) => {
247+
scrollProgressFillElement.style.width = `${nextValue}%`;
248+
});
225249
});
226250
</script>
227251
</body>

packages/react-flicking/src/demo/StatePage.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import LinearProgress from "@mui/material/LinearProgress";
1313
const DebugPage: React.FC = () => {
1414
const flickingRef = useRef<Flicking>(null);
1515

16-
const {isReachStart, isReachEnd, progress, currentPanelIndex, totalPanelCount, moveTo} = useFlickingStateApi(flickingRef);
16+
const {isReachStart, isReachEnd, indexProgress, currentPanelIndex, totalPanelCount, moveTo} = useFlickingStateApi(flickingRef);
1717

1818
const onClickPrev = () => {
1919
flickingRef.current?.prev();
@@ -90,7 +90,8 @@ const DebugPage: React.FC = () => {
9090
<Pagination count={totalPanelCount} page={currentPanelIndex+1} onChange={(e, v) => {
9191
moveTo(v-1);
9292
}}/>
93-
<LinearProgress variant="determinate" value={progress}/>
93+
<LinearProgress variant="determinate" value={indexProgress}/>
94+
{/* <LinearProgress variant="determinate" value={scrollProgress}/> */}
9495
</Stack>
9596
</div>
9697

0 commit comments

Comments
 (0)