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
✨ Carousel: InlineGallery and Pagination components #29674
✨ Carousel: InlineGallery and Pagination components #29674
Conversation
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 agree by far that this is more preferable to the prop-based. But I think we need to try this with a context. E.g. the InlineGallery
would set up the context and context provider, and all other components can optionally "listen to it".
return ( | ||
<> | ||
<WithStyles> | ||
<InlineGallery style={{width, position: 'relative'}}> |
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.
IMHO, InlineGallery
should be inherently relative
. Should we try to use ContainWrapper
on it?
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.
Ideally InlineGallery
is more like layout=container
-- its height is exactly the sum of its children's heights. IMO it is a bit clunky to have to specify this manually -- if I size my BaseCarousel
and don't size Pagination
(with default height of 20px) this should just work.
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.
Definitely agree with this. But ContainWrapper
doesn't have to be size=true
, which should work here - it'd rely on its children to provide the size.
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.
The latest changes use ContainWrapper
, but still need to resolve edge cases when there are multiple Pagination
components and a subset of them are inset
.
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.
Approved with one request.
import {createContext} from '../../../src/preact'; | ||
|
||
const CarouselContext = createContext( | ||
/** @type {BaseCarouselDef.ContextProps} */ ({}) |
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.
Hmm. But now we do need to provide setSlideCount
and setCurrentSlide
here - right? They'll just be empty functions, but then (a) we don't need to test for them everywhere, and (b) it self-documents.
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.
Happy to put setSlideCount
, however setCurrentSlide
should fallback to the one given by useState
if the CarouselContext
is not used. One option could be to use useState
in carousel-context
as the default value instead, but I believe this will have an issue with being called at the top level. WDYT?
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 see. I didn't think about that. Ok. In that case, i'm all good with the undefined function fields and checks. Sorry for the confusion.
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.
We can still define setSlideCount
, just not setCurrentSlide
! I did this in ae93511.
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.
Sounds good. Let's go with that.
* Add storybook sample * Prototype * Add Storybook for looping * Update styles * Use context provider * Update unit tests * Use ContainWrapper * Pull context into a separate file * Update slide count in useEffect * Define default `setSlideCount`
Alternative approach to #29545