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

Product gallery image grid - GCOM-1052 #2153

Draft
wants to merge 6 commits into
base: canary
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
"editor.formatOnSave": true,
"editor.tabSize": 2,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": { "source.fixAll.eslint": false },
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "never"
},
"editor.snippetSuggestions": "none",
"emmet.showExpandedAbbreviation": "never",
"editor.wordBasedSuggestions": false,
"editor.wordBasedSuggestions": "off",
"javascript.suggest.names": false,
"typescript.tsdk": "node_modules/typescript/lib",
"search.exclude": {
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,6 @@ Number of recently viewed products to be stored in localStorage

SidebarGalleryConfig will contain all configuration values for the Sidebar Gallery component.

#### paginationVariant: 'DOTS' | 'THUMBNAILS_BOTTOM'
#### paginationVariant: 'DOTS' | 'GRID' | 'THUMBNAILS_BOTTOM'

Variant used for the pagination
3 changes: 2 additions & 1 deletion examples/magento-graphcms/pages/blog/[url].tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PageOptions } from '@graphcommerce/framer-next-pages'
import { hygraphPageContent, HygraphPagesQuery } from '@graphcommerce/graphcms-ui'
import { StoreConfigDocument } from '@graphcommerce/magento-store'
import { redirectOrNotFound, StoreConfigDocument } from '@graphcommerce/magento-store'
import {
PageMeta,
BlogTitle,
Expand Down Expand Up @@ -94,6 +94,7 @@ export const getStaticProps: GetPageStaticProps = async ({ locale, params }) =>
query: BlogListDocument,
variables: { currentUrl: [`blog/${urlKey}`], first: limit },
})

if (!(await page).data.pages?.[0]) return { notFound: true }

return {
Expand Down
2 changes: 2 additions & 0 deletions packages/framer-scroller/components/ScrollerProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ export function ScrollerProvider(props: ScrollerProviderProps) {
const itemsArr: unknown[] = items.get().slice()
itemsArr.length = count

console.log('Registering children', itemsArr)

items.set(
itemsArr.fill(undefined).map<ItemState>((_, i) => ({
visibility: motionValue(i === 0 ? 1 : 0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type AutoScrollProps = {
}

export function AutoScroll(props: AutoScrollProps) {
const { getScrollSnapPositions, getSnapPosition, scrollerRef, scroll } = useScrollerContext()
const { getScrollSnapPositions, getSnapPosition, scroll } = useScrollerContext()
const scrollTo = useScrollTo()
const { pause = false, timePerSlide = 7500 } = props
const { xProgress } = scroll
Expand Down
50 changes: 50 additions & 0 deletions packages/magento-product/hooks/useStickyEffect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { useEffect, useRef } from 'react'

export function useStickyEffect() {
const marginRef = useRef<HTMLDivElement>(null)
const sidebarRef = useRef<HTMLDivElement>(null)
const wrapperRef = useRef<HTMLDivElement>(null)

const lastScrollTop = useRef(typeof document === 'undefined' ? 0 : document.body.scrollTop)

const handleScroll = () => {
const marginElement = marginRef.current
const sidebarElement = sidebarRef.current
const wrapperElement = wrapperRef.current

if (!(marginElement && sidebarElement && wrapperElement)) return

const { height: sidebarHeight } = sidebarElement.getBoundingClientRect()
const { scrollTop } = document.documentElement
const scrollDirection = scrollTop > lastScrollTop.current ? 1 : 0

if (lastScrollTop.current === scrollTop || sidebarHeight <= window.innerHeight) {
sidebarElement.style.top = '0px'
sidebarElement.style.bottom = ''
marginElement.style.marginTop = ''
return
}

const wrapperBounds = wrapperElement.getBoundingClientRect()
const sidebarBounds = sidebarElement.getBoundingClientRect()

marginElement.style.marginTop = `${sidebarBounds.top - wrapperBounds.top}px`

if (scrollDirection === 1) {
sidebarElement.style.bottom = ''
sidebarElement.style.top = `-${sidebarHeight - window.innerHeight}px`
} else {
sidebarElement.style.top = ''
sidebarElement.style.bottom = `-${sidebarHeight - window.innerHeight}px`
}

lastScrollTop.current = scrollTop
}

useEffect(() => {
window.addEventListener('scroll', handleScroll)
return () => window.removeEventListener('scroll', handleScroll)
}, [])

return [marginRef, sidebarRef, wrapperRef]
}
1 change: 1 addition & 0 deletions packages/next-ui/Config.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Enumeration of all possible positions for the sidebar gallery thumbnails.
enum SidebarGalleryPaginationVariant {
DOTS
THUMBNAILS_BOTTOM
GRID
}

"""
Expand Down
12 changes: 12 additions & 0 deletions packages/next-ui/FramerScroller/GalleryZoom.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react'
import { UseGalleryZoomProps, useGalleryZoom } from '../hooks/useGalleryZoom'

type GalleryZoomProps = UseGalleryZoomProps & {
children?: (props: ReturnType<typeof useGalleryZoom>) => React.ReactNode
}

export function GalleryZoom(props: GalleryZoomProps) {
const { children, ...rest } = props
const galleryZoom = useGalleryZoom(rest)
return <>{children?.(galleryZoom)}</>
}
Loading