Skip to content

Commit

Permalink
WIP: Move captionposition logic #2610
Browse files Browse the repository at this point in the history
  • Loading branch information
millianapia committed Jan 28, 2025
1 parent d54b21d commit 160c62b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
7 changes: 0 additions & 7 deletions sanityv3/schemas/objects/carouselImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ export default {
title: 'Credit',
type: 'string',
},
{
type: 'boolean',
name: 'captionPositionUnderImage',
title: 'Position caption and credit under image',
description: 'Toggle to display caption and credit under the image.',
initialValue: false,
},
{
name: 'action',
title: 'Link',
Expand Down
7 changes: 7 additions & 0 deletions sanityv3/schemas/objects/imageCarousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ export default {
{ type: 'carouselImage' }],
validation: (Rule: Rule) => Rule.required().min(2),
},
{
type: 'boolean',
name: 'captionPositionUnderImage',
title: 'Position caption and credit under image',
description: 'Toggle to display caption and credit under the images.',
initialValue: false,
},
{
type: 'number',
name: 'delay',
Expand Down
4 changes: 3 additions & 1 deletion web/core/Carousel/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type CarouselProps = {
autoRotation?: boolean
hasSectionTitle?: boolean
title?: PortableTextBlock[]
captionPositionUnderImage?: boolean
} & Omit<HTMLAttributes<HTMLDivElement>, 'title'>

const TRANSLATE_X_AMOUNT_LG = 1000
Expand All @@ -68,7 +69,7 @@ export const Carousel = forwardRef<HTMLElement, CarouselProps>(function Carousel
className = '',
listClassName = '',
hasSectionTitle = false,
},
captionPositionUnderImage},
ref,
) {
const CarouselTag = hasSectionTitle ? (`div` as ElementType) : (`section` as ElementType)
Expand Down Expand Up @@ -266,6 +267,7 @@ export const Carousel = forwardRef<HTMLElement, CarouselProps>(function Carousel
displayMode={displayMode}
aria-label={ariaLabel}
active={i === currentIndex}
captionPositionUnderImage={captionPositionUnderImage}
{...(variant === 'image' &&
displayMode === 'single' && {
style: {
Expand Down
3 changes: 2 additions & 1 deletion web/sections/ImageCarousel/ImageCarousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ImageCarousel = forwardRef<HTMLUListElement, ImageCarouselProps>(function
{ anchor, data, className },
ref,
) {
const { title, hideTitle, ingress, items, designOptions, options } = data
const { title, hideTitle, ingress, items, designOptions, options, captionPositionUnderImage } = data
const { background } = designOptions
const headingId = useId()

Expand Down Expand Up @@ -43,6 +43,7 @@ const ImageCarousel = forwardRef<HTMLUListElement, ImageCarouselProps>(function
labelledbyId={title && !hideTitle ? headingId : undefined}
title={title}
autoRotation={options?.autoplay}
captionPositionUnderImage={captionPositionUnderImage}
/>
</BackgroundContainer>
)
Expand Down
2 changes: 1 addition & 1 deletion web/types/imageTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export type ImageCarouselData = {
ingress?: PortableTextBlock[]
hideTitle?: boolean
items: ImageCarouselItem[]
captionPositionUnderImage?: boolean
options: {
autoplay: boolean
delay: number
Expand All @@ -65,6 +66,5 @@ export type ImageCarouselData = {

export type ImageCarouselItem = {
id: string
captionPositionUnderImage?: boolean
action?: any
} & ImageWithCaptionData

0 comments on commit 160c62b

Please sign in to comment.