-
Notifications
You must be signed in to change notification settings - Fork 129
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
feat(components): Carousel and Step components #482
Conversation
Codecov Report
@@ Coverage Diff @@
## alpha #482 +/- ##
==========================================
+ Coverage 79.76% 79.79% +0.03%
==========================================
Files 187 188 +1
Lines 3251 3256 +5
Branches 887 887
==========================================
+ Hits 2593 2598 +5
Misses 542 542
Partials 116 116
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love how clean and flexible this code is! Beautifully done ✨
What did you think of the new testing setup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pushing it through, and thanks for also providing such in depth examples. I just wrote down some small ideas.
import Carousel from './Carousel'; | ||
import { SLIDES } from './__fixtures__'; | ||
|
||
describe('Carousel', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we also add functional tests to the Carousel?
Like:
- clicking the next slide and expecting it to be the active one
- clicking on the last slide and expecting it to loop
- waiting for the timer to change the active slide
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yo @fernandofleury, thanks for suggestion, however all the points you mentioned are covered by the tests in useStep hook which is used inside Carousel component and is responsible for managing the state - https://github.com/sumup-oss/circuit-ui/blob/feature/add-carousel-and-step-components/src/components/Step/hooks/use-step.spec.js
Also all possible variations of internal Carousel component styles are tested separately inside components itself by passing necessary props and matching the snapshots (e.g. Slide component and its' different animations).
All components in Step and Carousel have 100% code coverage.
I agree that having functional/e2e test is nice addition but in current setup (react-testing-library) we will end up with just testing React onClick handlers calling the right functions. This is totally fine but it also feels like having too match hassle (e.g. adding a lot of data-selectors) for no real benefit.
WDYT?
|
||
const slideIn = keyframes` | ||
from { | ||
width: 0%; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to use transform: scaleX
instead of width
? This way the animation can be optimised by the GPU.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${isAnimating && | ||
css` | ||
animation-name: ${animationName}; | ||
animation-duration: ${animationDuration}ms; | ||
animation-fill-mode: forwards; | ||
animation-timing-function: ${theme.transitions.easeInOutCubic}; | ||
`}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${isAnimating && | |
css` | |
animation-name: ${animationName}; | |
animation-duration: ${animationDuration}ms; | |
animation-fill-mode: forwards; | |
animation-timing-function: ${theme.transitions.easeInOutCubic}; | |
`}; | |
animation-name: ${animationName}; | |
animation-duration: ${animationDuration}ms; | |
animation-fill-mode: forwards; | |
animation-timing-function: ${theme.transitions.easeInOutCubic}; | |
animation-play-state: ${isAnimating ? 'running' : 'paused'} |
Maybe we can use the play-state here? This way you don't have to conditionally add rules, just one value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to the way animation-play-state
prop works, it leads to inconsistent sliding animations -
Resuming a paused animation will start the animation from where it left off at the time it was paused, rather than starting over from the beginning of the animation sequence.
Co-Authored-By: Connor Bär <[email protected]>
Co-Authored-By: Connor Bär <[email protected]>
Co-Authored-By: Connor Bär <[email protected]>
@voronianski What's the state of this PR? Could you please address the review comments so we can merge it soon? Is there anything I can help you with? :) |
@connor-baer, thanks a lot but no help is needed, it's just a question of time :) will address this asap |
This pull request is being automatically deployed with ZEIT Now (learn more). 🔍 Inspect: https://zeit.co/sumup-oss/circuit-ui/1zg2bhx28 |
yo @connor-baer, I addressed all the comments, feel free to recheck the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I loooooove the work you've put into this pull request. So much attention to detail! Also kudos for keeping it in sync with the many upstream changes 👏👏
Let's merge this baby!
🎉 This PR is included in version 2.0.0-alpha.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Can we close #409? @connor-baer |
🎉 This PR is included in version 2.0.0-beta.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 2.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Closes #409.
Approach and changes
Step
component and hook for managing state in step/index based UIs and componentsAspectRatio
component for keeping proper image proportionsCarousel
component powered byStep
andAspectRatio
componentsCarousel
likeButtons
,Progress
,Status
,Slide
, etc. for composing them in a Custom carousel experienceStep component
Technically component uses the "function as child" and "prop getter" patterns but it's also possible to use it just as a hook:
vs.
Here are the examples below of how
Step
component can be used in a different ways to build index-based UIs.Simple image slider
Multistep form
Step
is suitable not only for image sliders. Any multi-step guides or slideshows can be achieved with it too:Yes/No slider with react-swipeable
And here is the interesting example of how you can easily add swipe/touch support into your slider-like UI if it's necessary:
Carousel component
Carousel
is a port of component designed for the website and you can also see it in action as part of Testimonials component on careers page (more details in proposal - #409).So currently there are 2 ways of using it.
Stateful
First one is just as simple as passing array of images into it. All internal state management is handled by
Step
component automatically:Composed
Second approach is compositional which means you get the building blocks and arrange them in a way that you want. Keep in mind that you will need to manage state by yourself (or via
Step
):Limitations
As I mentioned before
Step
is just purely state management abstraction and it doesn't contain any touch/swipe event support into it. I also decided not to introduce any 3rd party "swipeable" component dependency for now. This means that currentlyCarousel
component doesn't support swiping of images on mobiles. I see 2 ways of solving it:react-swipeable
as a dependency to Circuit UISwipe
component inside Circuit UI by ourselves (which should be addressed in a separate PR)I leave it as an open question and your feedback is welcome.
Definition of done