Skip to content

Commit

Permalink
fix(react): add missing attributes back
Browse files Browse the repository at this point in the history
  • Loading branch information
p-m-p committed Feb 14, 2024
1 parent 5afbd82 commit de949f9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/react/src/Carousel.tsx
Expand Up @@ -19,7 +19,7 @@ export function CarouselSlider({
timingFunction,
...props
}: CarouselSliderProps) {
const { attributes, extraProps } = extractSliderAttributes(props)
const { attributes, eventHandlers } = extractSliderAttributes(props)
const htmlAttributes = { ...attributes }

if (timingFunction) {
Expand All @@ -33,7 +33,7 @@ export function CarouselSlider({
return (
<bs-carousel
{...htmlAttributes}
ref={sliderRefCallback(extraProps, sliderRef)}
ref={sliderRefCallback(eventHandlers, sliderRef)}
class={className}>
{children}
</bs-carousel>
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/Cube.tsx
Expand Up @@ -19,7 +19,7 @@ export function Cube({
sliderRef,
...props
}: CubeSliderProps) {
const { attributes, extraProps } = extractSliderAttributes(props)
const { attributes, eventHandlers } = extractSliderAttributes(props)
const htmlAttributes = { ...attributes }

if (direction !== undefined) {
Expand All @@ -33,7 +33,7 @@ export function Cube({
return (
<bs-cube
{...htmlAttributes}
ref={sliderRefCallback(extraProps, sliderRef)}
ref={sliderRefCallback(eventHandlers, sliderRef)}
class={className}>
{children}
</bs-cube>
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/Fade.tsx
Expand Up @@ -17,7 +17,7 @@ export function FadeSlider({
timingFunction,
...props
}: FadeSliderProps) {
const { attributes, extraProps } = extractSliderAttributes(props)
const { attributes, eventHandlers } = extractSliderAttributes(props)
const htmlAttributes = { ...attributes }

if (timingFunction) {
Expand All @@ -27,7 +27,7 @@ export function FadeSlider({
return (
<bs-fade
{...htmlAttributes}
ref={sliderRefCallback(extraProps, sliderRef)}
ref={sliderRefCallback(eventHandlers, sliderRef)}
class={className}>
{children}
</bs-fade>
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/Tile.tsx
Expand Up @@ -22,7 +22,7 @@ export function TileSlider({
tileEffect,
...props
}: TileSliderProps) {
const { attributes, extraProps } = extractSliderAttributes(props)
const { attributes, eventHandlers } = extractSliderAttributes(props)
const htmlAttributes = { ...attributes }

if (rows !== undefined) {
Expand All @@ -40,7 +40,7 @@ export function TileSlider({
return (
<bs-tile
{...htmlAttributes}
ref={sliderRefCallback(extraProps, sliderRef)}
ref={sliderRefCallback(eventHandlers, sliderRef)}
class={className}>
{children}
</bs-tile>
Expand Down
34 changes: 29 additions & 5 deletions packages/react/src/core.ts
Expand Up @@ -59,11 +59,25 @@ export type BaseComponentProps<T extends ElementName> = BoxSliderProps &
export function extractSliderAttributes<T extends BoxSliderProps>(props: T) {
const {
autoScroll,
onAfter,
onBefore,
onDestroy,
onPause,
onPlay,
pauseOnHover,
startIndex,
speed,
swipe,
swipeTolerance,
...extraProps
timeout,
} = props
const eventHandlers = {
onAfter,
onBefore,
onDestroy,
onPause,
onPlay,
}
const attributes: Record<string, string> = {}

if (autoScroll !== undefined) {
Expand All @@ -74,23 +88,33 @@ export function extractSliderAttributes<T extends BoxSliderProps>(props: T) {
attributes['pause-on-hover'] = `${pauseOnHover}`
}

if (speed !== undefined) {
attributes.speed = `${speed}`
}

if (startIndex !== undefined) {
attributes['start-index'] = `${startIndex}`
}

if (swipe !== undefined) {
attributes.swipe = `${swipe}`
}

if (swipeTolerance !== undefined) {
attributes['swipe-tolerance'] = `${swipeTolerance}`
}

return { attributes, extraProps }
if (timeout !== undefined) {
attributes.timeout = `${timeout}`
}

return { attributes, eventHandlers }
}

export function sliderRefCallback<T extends BoxSliderProps>(
props: T,
{ onAfter, onBefore, onDestroy, onPause, onPlay }: T,
sliderRef?: MutableRefObject<BoxSlider | null>,
): RefCallback<SliderElement> {
const { onAfter, onBefore, onDestroy, onPause, onPlay } = props

return (el: SliderElement) => {
const slider = el?.slider

Expand Down

0 comments on commit de949f9

Please sign in to comment.