Skip to content

Commit

Permalink
chore(docs): add example for carousel with padding
Browse files Browse the repository at this point in the history
  • Loading branch information
Grsmto committed Sep 26, 2022
1 parent 68d5c85 commit b913dcf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/core/src/smoothScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,6 @@ export const smoothScroll = (
duration: number
) => {
if (!node) return;
// Can't use scrollIntoView() yet since Safari support is still weak: https://caniuse.com/scrollintoview
return smoothScrollPolyfill({ node, scrollTarget, duration });
};
13 changes: 11 additions & 2 deletions packages/docs/stories/carousel.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
object-fit: contain;
}

.carousel-story.thumbnails .slide {
scroll-snap-align: start;
.carousel-story .slide {
scroll-snap-align: center;
}

/* .slide:first-child {
Expand Down Expand Up @@ -57,3 +57,12 @@
display: none;
}
} */

.carousel-story.with-padding .carousel-container {
padding-left: 300px;
scroll-padding-left: 300px;
}

.carousel-story.with-padding-child .carousel-container .slide:first-child {
padding-left: 300px;
}
17 changes: 14 additions & 3 deletions packages/docs/stories/carousel.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const Carousel: FC<{

const scrollTo = useScroll({ ref });
const index = useActiveSnap({ ref });

// const index = 0;
const slides = Array.from(new Array(6));

Expand Down Expand Up @@ -121,9 +122,7 @@ Thumbnails.args = {
Thumbnails.play = async ({ args, canvasElement }) => {
const canvas = within(canvasElement);

const nextBtn = canvas.getByText('Next', {
selector: 'button',
});
const nextBtn = canvasElement.querySelector('.carousel-nav__btn--next');

await userEvent.click(nextBtn);

Expand All @@ -134,3 +133,15 @@ Thumbnails.play = async ({ args, canvasElement }) => {
);
await waitFor(() => expect(args.onChange).toHaveBeenCalled());
};

export const WithPadding = Template.bind({});
WithPadding.args = {
className: 'with-padding',
onChange: () => {},
};

export const WithPaddingChild = Template.bind({});
WithPaddingChild.args = {
className: 'with-padding-child',
onChange: () => {},
};
15 changes: 8 additions & 7 deletions packages/docs/stories/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ button {
height: 100%;
scroll-snap-align: center;
background-color: #c9edf2;
background-clip: content-box;
box-sizing: border-box;
display: grid;
place-items: center;
Expand Down Expand Up @@ -78,22 +77,24 @@ button {
overflow: hidden;
position: absolute;
text-align: center;
transition: background-color .1s linear, color .1s linear, opacity .1s linear;
transition: background-color 0.1s linear, color 0.1s linear,
opacity 0.1s linear;
width: 52px;
height: 52px;
border-radius: 52px;
top: 49%;
margin-top: -21px;
transform: scale(.8);
transform: scale(0.8);
opacity: 0;
transition: transform .5s ease-in,opacity .7s cubic-bezier(.15,0,.2,1) .1s;
background-color: rgba(0,0,0,.2);
transition: transform 0.5s ease-in,
opacity 0.7s cubic-bezier(0.15, 0, 0.2, 1) 0.1s;
background-color: rgba(0, 0, 0, 0.2);
color: #fff;
line-height: 0;
}

.carousel-nav button:hover {
background-color: rgba(0,0,0,.6);
background-color: rgba(0, 0, 0, 0.6);
}

.carousel:hover .carousel-nav button:hover:not([disabled]),
Expand All @@ -107,7 +108,7 @@ button {
}

.carousel-nav__btn--previous svg {
transform: rotateZ(90deg)
transform: rotateZ(90deg);
}

.carousel-nav__btn--next {
Expand Down

0 comments on commit b913dcf

Please sign in to comment.