Skip to content

Commit

Permalink
Merge pull request #131 from kevinfarrugia/dynamic-data
Browse files Browse the repository at this point in the history
Render dynamic data inside glider-track
  • Loading branch information
kevinfarrugia authored Oct 7, 2022
2 parents aa30cea + 8a6444a commit b914c89
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/demos.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from "react";

import DynamicDataGlider from "../examples/dynamicDataGlider";
import SingleItemGlider from "../examples/singleItemGlider";
import MultipleItemsGlider from "../examples/multipleItemsGlider";
import ResponsiveGlider from "../examples/responsiveGlider";
Expand Down Expand Up @@ -72,6 +73,10 @@ function Demos() {
<h3>Skip Track</h3>
<SkipTrackGlider />
</div>
<div className="item">
<h3>Dynamic Data</h3>
<DynamicDataGlider />
</div>
</div>
);
}
Expand Down
39 changes: 39 additions & 0 deletions examples/dynamicDataGlider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as React from "react";

import Glider from "../src";

function DynamicDataGlider() {
const [data, setData] = React.useState([1, 2, 3, 4, 5, 6]);

return (
<div className="container">
<input
type="button"
onClick={() => {
const newData = [
...new Array(Math.floor(Math.random() * 12) + 1),
].map((_, index) => index + 1);
setData(newData);
}}
value="Randomize"
/>
<div className="container">
<Glider
className="glider-container"
slidesToShow={1}
scrollLock
hasDots
draggable
>
{data.map((n) => (
<div key={n} className="slide">
<span>{n}</span>
</div>
))}
</Glider>
</div>
</div>
);
}

export default DynamicDataGlider;
4 changes: 3 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const makeGliderOptions: (
...restProps
}) => ({
...restProps,
skipTrack: true,
arrows:
(hasArrows && {
next: (arrows && arrows.next) || nextButtonEl,
Expand All @@ -42,6 +43,7 @@ const GliderComponent = React.forwardRef(
scrollToPage,
iconLeft,
iconRight,
skipTrack,
children,
onLoad,
onSlideVisible,
Expand Down Expand Up @@ -222,7 +224,7 @@ const GliderComponent = React.forwardRef(
)}

<div id={id || autoId} className={className} ref={callbackRef}>
{children}
{skipTrack ? children : <div>{children}</div>}
</div>

{hasDots && !dots && <div ref={dotsRef} />}
Expand Down

1 comment on commit b914c89

@vercel
Copy link

@vercel vercel bot commented on b914c89 Oct 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.