Skip to content

Commit

Permalink
🚧 rename "useCarousel" => "useHorizontalScroll"; enable by default on…
Browse files Browse the repository at this point in the history
… mobile (#1373)
  • Loading branch information
SvSven committed Dec 20, 2022
1 parent 9c3ea76 commit ae45c36
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions studio/schemas/objects/promotion/promotion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ export default {
validation: (Rule: Rule) => Rule.required().min(1).max(1),
},
{
name: 'useCarousel',
title: 'Use carousel',
name: 'useHorizontalScroll',
title: 'Use horizontal scroll',
description:
'When this is enabled, the promotion will automatically be displayed in a horizontal carousel if the amount of content is more than the screen size allows',
'When this is enabled, the promotion will use horizontal scroll if the amount of content is greater than the screen size allows. This feature is enabled by default for smaller screen sizes.',
type: 'boolean',
initialValue: false,
readOnly: !Flags.IS_DEV,
Expand Down
2 changes: 1 addition & 1 deletion web/lib/queries/common/pageContentFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ const pageContentFields = /* groq */ `
...,
${markDefs},
},
"useCarousel": useCarousel,
"useHorizontalScroll": useHorizontalScroll,
"content": promotion[0]{
"id": _key,
"type": _type,
Expand Down
4 changes: 2 additions & 2 deletions web/pageComponents/topicPages/Promotion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const StyledHeading = styled(TitleText)`
`

const Promotion = ({ data, anchor, ...rest }: { data: PromotionData; anchor?: string }) => {
const { title, ingress, content, useCarousel, designOptions } = data
const { title, ingress, content, useHorizontalScroll, designOptions } = data
// const { articles = [], pages = [] } = data.promotion
const promotions = content?.promotions || []
const variant = data.content?.type
Expand All @@ -52,7 +52,7 @@ const Promotion = ({ data, anchor, ...rest }: { data: PromotionData; anchor?: st
variant={variant}
hasSectionTitle={!!title}
eventPromotionSettings={content?.eventPromotionSettings}
useCarousel={useCarousel}
useHorizontalScroll={useHorizontalScroll}
/>
)}
</Wrapper>
Expand Down
10 changes: 7 additions & 3 deletions web/pageComponents/topicPages/promotions/MultiplePromotions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import PeopleCard from '../../cards/PeopleCard/PeopleCard'
import MultipleEventCards from './MultipleEventCards'
import { HorizontalScroll, HorizontalScrollItem } from '../../shared/Carousel'
import { Flags } from '../../../common/helpers/datasetHelpers'
import useWindowSize from '../../../lib/hooks/useWindowSize'

const CardsWrapper = styled.div`
width: 100%;
Expand Down Expand Up @@ -75,13 +76,13 @@ const MultiplePromotions = ({
variant,
hasSectionTitle,
eventPromotionSettings,
useCarousel = false,
useHorizontalScroll = false,
}: {
data: CardData[] | PeopleCardData[] | EventCardData[]
variant: PromotionType
hasSectionTitle: boolean
eventPromotionSettings?: EventPromotionSettings
useCarousel?: boolean | undefined
useHorizontalScroll?: boolean | undefined
}) => {
const getCard = (data: CardProps) => {
switch (data.type) {
Expand All @@ -98,6 +99,9 @@ const MultiplePromotions = ({
}
}

const { width } = useWindowSize()
const renderScroll = useHorizontalScroll || (width && width <= 800)

if (variant === 'promoteEvents') {
return (
<MultipleEventCards
Expand All @@ -108,7 +112,7 @@ const MultiplePromotions = ({
)
}

if (Flags.IS_DEV && useCarousel) {
if (Flags.IS_DEV && renderScroll) {
return (
<HorizontalScroll type="card">
{data.map((item) => {
Expand Down
2 changes: 1 addition & 1 deletion web/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ export type PromotionData = {
type: PromotionType
eventPromotionSettings?: EventPromotionSettings
}
useCarousel?: boolean | undefined
useHorizontalScroll?: boolean | undefined
designOptions?: DesignOptions
}

Expand Down

0 comments on commit ae45c36

Please sign in to comment.