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

✨ Carousel: InlineGallery and Pagination components #29674

Merged
merged 12 commits into from Aug 25, 2020

Conversation

caroqliu
Copy link
Contributor

@caroqliu caroqliu commented Aug 4, 2020

Alternative approach to #29545

@google-cla google-cla bot added the cla: yes label Aug 4, 2020
@caroqliu caroqliu requested a review from dvoytenko August 4, 2020 22:46
Copy link
Contributor

@dvoytenko dvoytenko left a 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".

extensions/amp-inline-gallery/1.0/inline-gallery.js Outdated Show resolved Hide resolved
return (
<>
<WithStyles>
<InlineGallery style={{width, position: 'relative'}}>
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@caroqliu caroqliu marked this pull request as ready for review August 21, 2020 20:51
extensions/amp-base-carousel/1.0/base-carousel.js Outdated Show resolved Hide resolved
extensions/amp-base-carousel/1.0/base-carousel.js Outdated Show resolved Hide resolved
extensions/amp-base-carousel/1.0/base-carousel.js Outdated Show resolved Hide resolved
extensions/amp-inline-gallery/1.0/inline-gallery.js Outdated Show resolved Hide resolved
extensions/amp-inline-gallery/1.0/inline-gallery.js Outdated Show resolved Hide resolved
extensions/amp-inline-gallery/1.0/inline-gallery.type.js Outdated Show resolved Hide resolved
extensions/amp-inline-gallery/1.0/inline-gallery.js Outdated Show resolved Hide resolved
Copy link
Contributor

@dvoytenko dvoytenko left a 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} */ ({})
Copy link
Contributor

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.

Copy link
Contributor Author

@caroqliu caroqliu Aug 24, 2020

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@caroqliu caroqliu merged commit a231122 into ampproject:master Aug 25, 2020
ed-bird pushed a commit to ed-bird/amphtml that referenced this pull request Dec 10, 2020
* 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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants