-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ded1c53
commit c3f895d
Showing
80 changed files
with
1,334 additions
and
1,065 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,94 @@ | ||
[data-scope='carousel'][data-part='viewport'] { | ||
max-width: 600px; | ||
margin-top: 40px; | ||
overflow-x: hidden; | ||
[data-scope="carousel"][data-part="root"] { | ||
display: flex; | ||
align-items: flex-start; | ||
flex-direction: column; | ||
gap: 16px; | ||
} | ||
|
||
[data-scope="carousel"][data-part="root"][data-orientation="horizontal"] { | ||
max-width: 400px; | ||
} | ||
|
||
[data-scope="carousel"][data-part="root"][data-orientation="vertical"] { | ||
max-height: 400px; | ||
} | ||
|
||
[data-scope="carousel"][data-part="control"] { | ||
display: flex; | ||
gap: 8px; | ||
align-self: stretch; | ||
} | ||
|
||
[data-scope="carousel"][data-part="item-group"] { | ||
align-self: stretch; | ||
/* Hide scrollbar */ | ||
scrollbar-width: none; | ||
-webkit-scrollbar-width: none; | ||
-ms-overflow-style: none; | ||
&::-webkit-scrollbar { | ||
display: none; | ||
} | ||
} | ||
|
||
[data-scope="carousel"][data-part="item"] { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
font-size: 24px; | ||
border: 1px solid lightgray; | ||
} | ||
|
||
[data-scope="carousel"][data-part="item"] img { | ||
margin: 0; | ||
object-fit: cover; | ||
} | ||
|
||
[data-scope="carousel"][data-part="item"][data-orientation="horizontal"] img { | ||
height: 300px; | ||
width: 100%; | ||
} | ||
|
||
[data-scope="carousel"][data-part="item"][data-orientation="vertical"] img { | ||
height: 100%; | ||
width: 400px; | ||
} | ||
|
||
[data-scope="carousel"][data-part="indicator-group"] { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
margin-block: 8px; | ||
gap: 8px; | ||
} | ||
|
||
[data-scope="carousel"][data-part="indicator"] { | ||
display: flex; | ||
border: none; | ||
justify-content: center; | ||
align-items: center; | ||
height: 12px; | ||
width: 12px; | ||
border-radius: 6px; | ||
cursor: pointer; | ||
background-color: lightgray; | ||
transition: background-color 0.2s ease-in-out; | ||
} | ||
|
||
[data-scope="carousel"][data-part="indicator"][data-current] { | ||
background-color: blue; | ||
} | ||
|
||
[data-scope="carousel"][data-part="autoplay-trigger"] { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.carousel-spacer { | ||
flex-grow: 1; | ||
} | ||
|
||
[data-scope="carousel"][data-part="autoplay-trigger"] svg { | ||
width: 12px; | ||
height: 12px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/react/src/components/carousel/carousel-autoplay-trigger.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { mergeProps } from '@zag-js/react' | ||
import { forwardRef } from 'react' | ||
import { type HTMLProps, type PolymorphicProps, ark } from '../factory' | ||
import { useCarouselContext } from './use-carousel-context' | ||
|
||
export interface CarouselAutoplayTriggerBaseProps extends PolymorphicProps {} | ||
export interface CarouselAutoplayTriggerProps | ||
extends HTMLProps<'button'>, | ||
CarouselAutoplayTriggerBaseProps {} | ||
|
||
export const CarouselAutoplayTrigger = forwardRef<HTMLButtonElement, CarouselAutoplayTriggerProps>( | ||
(props, ref) => { | ||
const carousel = useCarouselContext() | ||
const mergedProps = mergeProps(carousel.getAutoplayTriggerProps(), props) | ||
|
||
return <ark.button {...mergedProps} ref={ref} /> | ||
}, | ||
) | ||
|
||
CarouselAutoplayTrigger.displayName = 'CarouselAutoplayTrigger' |
12 changes: 8 additions & 4 deletions
12
packages/react/src/components/carousel/carousel-control.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
import { mergeProps } from '@zag-js/react' | ||
import { forwardRef } from 'react' | ||
import { type HTMLProps, type PolymorphicProps, ark } from '../factory' | ||
import { carouselAnatomy } from './carousel.anatomy' | ||
import { useCarouselContext } from './use-carousel-context' | ||
|
||
export interface CarouselControlBaseProps extends PolymorphicProps {} | ||
export interface CarouselControlProps extends HTMLProps<'div'>, CarouselControlBaseProps {} | ||
|
||
export const CarouselControl = forwardRef<HTMLDivElement, CarouselControlProps>((props, ref) => ( | ||
<ark.div {...carouselAnatomy.build().control.attrs} {...props} ref={ref} /> | ||
)) | ||
export const CarouselControl = forwardRef<HTMLDivElement, CarouselControlProps>((props, ref) => { | ||
const carousel = useCarouselContext() | ||
const mergedProps = mergeProps(carousel.getControlProps(), props) | ||
|
||
return <ark.div {...mergedProps} {...props} ref={ref} /> | ||
}) | ||
|
||
CarouselControl.displayName = 'CarouselControl' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
packages/react/src/components/carousel/carousel-viewport.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
import { anatomy } from '@zag-js/carousel' | ||
|
||
export const carouselAnatomy = anatomy.extendWith('control') | ||
export { anatomy as carouselAnatomy } from '@zag-js/carousel' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { cleanup, render, screen, waitFor } from '@testing-library/react/pure' | ||
import { axe } from 'vitest-axe' | ||
import { Carousel, carouselAnatomy } from '.' | ||
import { getExports, getParts } from '../../setup-test' | ||
import { Basic as ComponentUnderTest } from './examples/basic' | ||
|
||
describe('Carousel / Parts & Exports', () => { | ||
afterAll(() => { | ||
cleanup() | ||
}) | ||
|
||
render(<ComponentUnderTest />) | ||
|
||
const renderedParts = getParts(carouselAnatomy).filter( | ||
(part) => !part.includes('[data-part="autoplay-trigger"]'), | ||
) | ||
|
||
it.each(renderedParts)('should render part %s', async (part) => { | ||
expect(document.querySelector(part)).toBeInTheDocument() | ||
}) | ||
|
||
it.each(getExports(carouselAnatomy))('should export %s', async (part) => { | ||
expect(Carousel[part]).toBeDefined() | ||
}) | ||
}) | ||
|
||
describe('Carousel', () => { | ||
afterEach(() => { | ||
cleanup() | ||
}) | ||
|
||
it('should have no a11y violations', async () => { | ||
const { container } = render(<ComponentUnderTest />) | ||
const results = await axe(container) | ||
|
||
expect(results).toHaveNoViolations() | ||
}) | ||
|
||
it('should have the correct disabled / enabled states for control buttons', async () => { | ||
render(<ComponentUnderTest />) | ||
const prevButton = screen.getByRole('button', { name: 'Previous slide' }) | ||
const nextButton = screen.getByRole('button', { name: 'Next slide' }) | ||
|
||
await waitFor(() => expect(prevButton).toBeDisabled()) | ||
await waitFor(() => expect(nextButton).toBeEnabled()) | ||
}) | ||
}) |
Oops, something went wrong.