2023-07-02 05:08:42 +00:00
|
|
|
import 'solid-js'
|
2024-02-05 15:49:08 +00:00
|
|
|
import { JSX, JSXElement, Ref } from 'solid-js'
|
|
|
|
import { AutoplayOptions, SlideData, Swiper, SwiperOptions } from 'swiper'
|
|
|
|
|
|
|
|
type SwiperSlideProps = {
|
|
|
|
/**
|
|
|
|
* Slide tag
|
|
|
|
*
|
|
|
|
* @default 'div'
|
|
|
|
*/
|
|
|
|
tag?: string
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enables additional wrapper required for zoom mode
|
|
|
|
*
|
|
|
|
* @default false
|
|
|
|
*/
|
|
|
|
zoom?: boolean
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds lazy preloader to the slide
|
|
|
|
*
|
|
|
|
* @default false
|
|
|
|
*/
|
|
|
|
lazy?: boolean
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Slide's index in slides array/collection
|
|
|
|
*
|
|
|
|
* @default false
|
|
|
|
*/
|
|
|
|
virtualIndex?: number
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Slide's child element or render function
|
|
|
|
*
|
|
|
|
* @default undefined
|
|
|
|
*/
|
|
|
|
children?: JSX.Element | ((slideData: SlideData) => JSX.Element)
|
|
|
|
}
|
2023-07-02 05:08:42 +00:00
|
|
|
|
|
|
|
type Kebab<T extends string, A extends string = ''> = T extends `${infer F}${infer R}`
|
|
|
|
? Kebab<R, `${A}${F extends Lowercase<F> ? '' : '-'}${Lowercase<F>}`>
|
|
|
|
: A
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper for converting object keys to kebab case because Swiper web components parameters are available as kebab-case attributes.
|
|
|
|
* @link https://swiperjs.com/element#parameters-as-attributes
|
|
|
|
*/
|
|
|
|
type KebabObjectKeys<T> = {
|
2024-02-04 09:03:15 +00:00
|
|
|
// biome-ignore lint/suspicious/noExplicitAny: TODO: <explanation>
|
|
|
|
[key in keyof T as Kebab<key & string>]: T[key] extends Record<string, any>
|
|
|
|
? KebabObjectKeys<T[key]>
|
|
|
|
: T[key]
|
2023-07-02 05:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Swiper 9 doesn't support Typescript yet, we are watching the following issue:
|
|
|
|
* @link https://github.com/nolimits4web/swiper/issues/6466
|
|
|
|
*
|
|
|
|
* All parameters can be found on the following page:
|
|
|
|
* @link https://swiperjs.com/swiper-api#parameters
|
|
|
|
*/
|
|
|
|
type SwiperRef = HTMLElement & { swiper: Swiper; initialize: () => void }
|
|
|
|
|
|
|
|
declare module 'solid-js' {
|
|
|
|
namespace JSX {
|
|
|
|
interface IntrinsicElements {
|
|
|
|
'swiper-container': SwiperContainerAttributes
|
|
|
|
'swiper-slide': SwiperSlideAttributes
|
|
|
|
}
|
|
|
|
|
|
|
|
interface SwiperContainerAttributes extends KebabObjectKeys<SwiperOptions> {
|
2024-02-05 15:49:08 +00:00
|
|
|
ref?: Ref<SwiperRef>
|
2023-07-02 05:08:42 +00:00
|
|
|
children?: JSX.Element
|
|
|
|
onSlideChange?: () => void
|
2023-08-17 10:36:27 +00:00
|
|
|
onBeforeSlideChangeStart?: () => void
|
2023-07-02 05:08:42 +00:00
|
|
|
class?: string
|
2024-01-15 15:05:38 +00:00
|
|
|
observer?: boolean
|
|
|
|
loop?: boolean
|
|
|
|
speed?: number
|
|
|
|
slidesPerGroupAuto?: boolean
|
|
|
|
navigation?: boolean
|
2023-11-02 10:34:38 +00:00
|
|
|
breakpoints?: {
|
|
|
|
[width: number]: SwiperOptions
|
|
|
|
[ratio: string]: SwiperOptions
|
|
|
|
}
|
2024-01-15 15:05:38 +00:00
|
|
|
direction?: 'horizontal' | 'vertical'
|
2023-11-02 10:34:38 +00:00
|
|
|
autoplay?: AutoplayOptions | boolean
|
2023-07-02 05:08:42 +00:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
|
|
interface SwiperSlideAttributes extends KebabObjectKeys<SwiperSlideProps> {
|
|
|
|
style?: unknown
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|