Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Page Designer Carousel Component #977

Merged
merged 29 commits into from
Feb 24, 2023

Conversation

bendvc
Copy link
Collaborator

@bendvc bendvc commented Feb 9, 2023

Description

This PR implements the Page Designer Carousel component. The implementation takes its design from the preexisting Product Scroller component in order to cut down on implementation time due to its simple implementation. The component achieves its carousel like feel using the scrollSnapType property, as a result the scroll indicator / pip's that are in the SFRA implementation manifest themself as the horizontal scroll bar. The visibility of this indicator/scrollbar is controlled by the mdCarouselIndicators option set in page designer. One caveat however is that the indicator is always shown on non-webkit browsers for the time being.

Screenshot 2023-02-14 at 5 00 19 PM

Types of Changes

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Breaking change (could cause existing functionality to not work as expected)
  • Other changes (non-breaking changes that does not fit any of the above)

Changes

  • (change1)

How to Test-Drive This PR

  • Checkout this code. git checkout feature/experience-carousel-component
  • Install deps. npm ci
  • Run the dev server. npm start
  • Visit the following URL after your browser opens. http://localhost:3000/page-viewer
  • Pay around with the carousel, swiping and changing your screen size.
  • If you want to change the appearance of the carousel edit the sample-page.json file. Inside you'll find a serialized page, you can edit the options for the carousel by searching for commerce_layouts.carousel and editing the data object values for that object. E.g. change the number of items to show for the given device width or whether or not the controls and/or indicators are showing.

Checklists

General

  • Changes are covered by test cases
  • CHANGELOG.md updated with a short description of changes (not required for documentation updates)

TODO

  • Add indicators for item selection.

@bendvc bendvc added the wip Work in process label Feb 9, 2023
@bendvc bendvc requested a review from a team as a code owner February 9, 2023 23:40
@bendvc bendvc added ready for review PR is ready to be reviewed and removed wip Work in process labels Feb 15, 2023
Copy link
Collaborator

@adamraya adamraya left a comment

Choose a reason for hiding this comment

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

Minor comments mostly seen by comparing the SFRA carousel with the current solution.

Comment on lines 82 to 94
// Our indicator implementation uses the scrollbar to show the context of the current
// item selected. Because MacOS hides scroll bars after they come to rest we need to
// force them to show. Please note that this feature only works on web-kit browsers,
// for all other brosers the scroller/indicator will be shown.
const css = `
.scroll-indicator::-webkit-scrollbar {
display:${overflowXScrollValue};
-webkit-appearance: none;
height: 8px;
}
.scroll-indicator::-webkit-scrollbar-thumb {
background-color: rgba(0, 0, 0, 0.5);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

The SFRA carousel shows one indicator per element, highlighting the current element. Are we missing implementing that navigation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As discussed IRL our design here is diverging as we have decided to base out implementation off of a previous already implemented component called the product slider. This was done to save implementation time, 1-1 parity with the UI from SFRA and PWA kit is the tradeoff. However this design, because it's based off of a pre-existing component, fits the UI better.

Comment on lines 72 to 80
// Scroll the container left or right by 100%. Passing no args or `1`
// scrolls to the right, and passing `-1` scrolls left.
const scroll = useCallback((direction = 1) => {
scrollRef.current?.scrollBy({
top: 0,
left: (direction * window.innerWidth) / itemCount,
behavior: 'smooth'
})
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

The scrolling in the SFRA carousel by default implements an infinite loop behaviour when scrolling in either direction. Is this something we need to implement?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When this PR was first estimated, it was estimated with the idea that we were going to reuse the code from the product scroller. Because this implementation uses a simple overflow with snap, it would be significant effort to make the carousel behave exactly like sfra. I think it's ok to not verbatim match srfa's implementation, instead be more inline with the PWA implementation

{/* Button Controls */}
<Fragment>
<Box
display={controlDisplay}
Copy link
Collaborator

Choose a reason for hiding this comment

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

The SFRA carousel only shows the control buttons when the items don't fit in the current view.
i.e. left/right scroll buttons are not rendered when the elements are less or equal to the defined number of CarouselSlidesToDisplay that fit in the view.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this is valuable. I've added logic to detect if there is overflow and only if there is overflow will it obey the control visibility prop configurations.

style={{scrollSnapAlign: 'start'}}
>
<AspectRatio ratio={1}>
<Component component={{...component, index}} />
Copy link
Collaborator

Choose a reason for hiding this comment

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

The prop index is not a key that exists in the component API response. We may want to remove it before merging.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call. I did this because I was passing that index through and using it for the image provider as an id value. I've changed the usage for my example to no require the id value, instead it uses the components id as a seed to get the image. Not that it's important because that page is only an example and isn't going to be commited.


return (
<Box className={'carousel'} position="relative" data-testid="carousel">
<style>{css}</style>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this the proper way to add custom CSS? Do we want to use the sx or __css Chakra props?

The browser console is showing the warning:

Warning: Did not expect server HTML to contain the text node

Probably unrelated to this CSS usage tho.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Been soo long working on component that I just forgot. I've changed it to use the sx prop.

packages/template-retail-react-app/jest.config.js Outdated Show resolved Hide resolved
import React, {Fragment, useCallback, useRef} from 'react'
import PropTypes from 'prop-types'
import {AspectRatio, Box, Heading, IconButton, Stack, useBreakpointValue} from '@chakra-ui/react'
import {Component} from 'commerce-sdk-react-preview/components'
Copy link
Collaborator

Choose a reason for hiding this comment

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

A reminder that I understood we mentioned that we want to import these components directly in the template for now until we release the new commerce-sdk package.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

From the sounds of it, we'll be copying over those components from the library into the template, we'll have to update this import.

Copy link
Collaborator

@adamraya adamraya left a comment

Choose a reason for hiding this comment

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

Thanks @bendvc for the nice work! 🎉

The changes LGTM. Feel free to merge whenever you see it's ready.

Comment on lines 42 to 48
'img-src': [
"'self'",
'*.commercecloud.salesforce.com',
'picsum.photos',
'*.picsum.photos',
'data:'
],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TODO: Remove this before merging the PR

@bendvc bendvc requested a review from adamraya February 24, 2023 00:27
Copy link
Collaborator

@adamraya adamraya left a comment

Choose a reason for hiding this comment

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

Docs Typos

@bendvc bendvc merged commit cfa5811 into develop Feb 24, 2023
bfeister added a commit that referenced this pull request Feb 28, 2023
* develop:
  Support Node 16 (#965)
  [W-12450361] Introduce short-circuit method for bypassing auth in Commerce Provider by passing in a fetchedToken (#1010)
  remove jest-silent-reporter (#1009)
  Clean up Page Designer Code (#1004)
  [Shopper Experience] `ImageWithText` component (#991)
  Feature: Page Designer Carousel Component (#977)
  [Feature] Page Designer Layout Components WIP (#993)
  remove updatePw from not implemented list (#996)
  Back-port Shopper Experience Base Components into Retail Template (#992)

# Conflicts:
#	packages/commerce-sdk-react/package-lock.json
#	packages/commerce-sdk-react/package.json
#	packages/pwa-kit-dev/package-lock.json
#	packages/pwa-kit-dev/src/configs/webpack/config.js
#	packages/template-retail-react-app/package-lock.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants