-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Gallery): add testid's to elements and refactor (#8015)
* feat(Gallery): add testid's to elements and refactor * fix(Gallery): reslove conflicts * doc(Gallery): fix JSDocs * fix(Gallery): remove object * fix(Gallery): fix formatting
- Loading branch information
1 parent
efa568a
commit c52e9bf
Showing
7 changed files
with
209 additions
and
126 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
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,36 @@ | ||
import * as React from 'react'; | ||
import { classNames } from '@vkontakte/vkjs'; | ||
import { type BaseGalleryProps } from './types'; | ||
import styles from './BaseGallery.module.css'; | ||
|
||
export interface BulletsTestIds { | ||
/** | ||
* Передает атрибут `data-testid` для bullets | ||
*/ | ||
bulletTestId?: (index: number, active: boolean) => string; | ||
} | ||
|
||
interface BulletsProps extends BulletsTestIds { | ||
bullets: Exclude<BaseGalleryProps['bullets'], false | undefined>; | ||
slideIndex: number; | ||
count: number; | ||
} | ||
|
||
const stylesBullets = { | ||
dark: styles.bulletsDark, | ||
light: styles.bulletsLight, | ||
}; | ||
|
||
export const Bullets: React.FC<BulletsProps> = ({ bullets, slideIndex, count, bulletTestId }) => { | ||
return ( | ||
<div aria-hidden className={classNames(styles.bullets, stylesBullets[bullets])}> | ||
{Array.from({ length: count }).map((_, index) => ( | ||
<div | ||
className={classNames(styles.bullet, index === slideIndex && styles.bulletActive)} | ||
data-testid={bulletTestId?.(index, index === slideIndex)} | ||
key={index} | ||
/> | ||
))} | ||
</div> | ||
); | ||
}; |
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
56 changes: 56 additions & 0 deletions
56
packages/vkui/src/components/BaseGallery/GalleryViewPort.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,56 @@ | ||
'use client'; | ||
|
||
import * as React from 'react'; | ||
import { type HasChildren } from '../../types'; | ||
import { type CustomTouchEvent, Touch } from '../Touch/Touch'; | ||
import { type BaseGalleryProps } from './types'; | ||
import styles from './BaseGallery.module.css'; | ||
|
||
type GalleryViewPortProps = Pick<BaseGalleryProps, 'slideWidth' | 'slideTestId'> & | ||
HasChildren & { | ||
onStart: (e: CustomTouchEvent) => void; | ||
onMoveX: (e: CustomTouchEvent) => void; | ||
onEnd: (e: CustomTouchEvent) => void; | ||
viewportRef: React.Ref<HTMLElement>; | ||
setSlideRef: (slideRef: HTMLDivElement | null, slideIndex: number) => void; | ||
layerRef?: React.Ref<HTMLDivElement>; | ||
layerStyle?: React.CSSProperties; | ||
}; | ||
|
||
export const GalleryViewPort: React.FC<GalleryViewPortProps> = ({ | ||
slideTestId, | ||
slideWidth, | ||
onStart, | ||
onMoveX, | ||
onEnd, | ||
viewportRef, | ||
layerRef, | ||
layerStyle, | ||
children, | ||
setSlideRef, | ||
}) => { | ||
return ( | ||
<Touch | ||
className={styles.viewport} | ||
onStartX={onStart} | ||
onMoveX={onMoveX} | ||
onEnd={onEnd} | ||
style={{ width: slideWidth === 'custom' ? '100%' : slideWidth }} | ||
getRootRef={viewportRef} | ||
noSlideClick | ||
> | ||
<div className={styles.layer} ref={layerRef} style={layerStyle}> | ||
{React.Children.map(children, (item: React.ReactNode, i: number) => ( | ||
<div | ||
className={styles.slide} | ||
key={`slide-${i}`} | ||
data-testid={slideTestId?.(i)} | ||
ref={(el) => setSlideRef(el, i)} | ||
> | ||
{item} | ||
</div> | ||
))} | ||
</div> | ||
</Touch> | ||
); | ||
}; |
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
Oops, something went wrong.