forked from themesberg/flowbite-svelte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix: Carousel swiping event listener error, Feat: Re-Expose Image …
…Class styling for Carousel (themesberg#1079) * Bugfix: Fix Carousel swipe error * Feat: Add img class styling prop * Bugfix: Unable to preventDefault inside passive event listener invocation * Bugfix: Button click not working on iPad devices * Feat: Re-designed and optimized Carousel transitions
- Loading branch information
1 parent
1ac1eb1
commit 6f90ec5
Showing
6 changed files
with
189 additions
and
51 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,16 @@ | ||
export const canChangeSlide = ({ | ||
lastSlideChange, | ||
slideDuration, | ||
slideDurationRatio = 1, | ||
}: { | ||
lastSlideChange: Date, | ||
slideDuration: number, | ||
slideDurationRatio?: number, // Allows for starting a new transition before the previous completes | ||
}) => { | ||
if (lastSlideChange && new Date().getTime() - lastSlideChange.getTime() < slideDuration * slideDurationRatio) { | ||
console.warn("Can't change slide yet, too soon"); | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
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 |
---|---|---|
@@ -1,26 +1,51 @@ | ||
<script lang="ts"> | ||
import { quintOut } from 'svelte/easing'; | ||
import type { HTMLImgAttributes } from 'svelte/elements'; | ||
import { fade, type TransitionConfig } from 'svelte/transition'; | ||
import { fly, type TransitionConfig } from 'svelte/transition'; | ||
import { twMerge } from 'tailwind-merge'; | ||
import { getContext } from 'svelte'; | ||
import type { Writable } from 'svelte/store'; | ||
import type { State } from './Carousel.svelte'; | ||
const state = getContext<Writable<State>>('state'); | ||
type TransitionFunc = (node: HTMLElement, params: any) => TransitionConfig; | ||
export let image: HTMLImgAttributes; | ||
export let transition: TransitionFunc = (x) => fade(x, { duration: 700, easing: quintOut }); | ||
export let transition: TransitionFunc | null = null; // Optional transition function, overrides default slide transition | ||
$: transitionSlideIn = { | ||
x: $state.forward ? '100%' : '-100%', | ||
opacity: 1, | ||
width: '100%', | ||
height: '100%', | ||
duration: $state.slideDuration | ||
}; | ||
$: transitionSlideOut = { | ||
x: $state.forward ? '-100%' : '100%', | ||
opacity: 0.9, | ||
width: '100%', | ||
height: '100%', | ||
duration: $state.slideDuration | ||
}; | ||
let imgClass: string; | ||
$: imgClass = twMerge('absolute block w-full -translate-x-1/2 -translate-y-1/2 top-1/2 left-1/2 object-cover', $$props.class); | ||
$: imgClass = twMerge('absolute block !w-full h-full object-cover', $$props.class); | ||
</script> | ||
|
||
{#key image} | ||
<img alt="..." {...image} transition:transition={{}} {...$$restProps} class={imgClass} /> | ||
{/key} | ||
{#if transition} | ||
{#key image} | ||
<img alt="..." {...image} transition:transition={{}} {...$$restProps} class={imgClass} /> | ||
{/key} | ||
{:else} | ||
{#key image} | ||
<img alt="..." {...image} {...$$restProps} out:fly={transitionSlideOut} in:fly={transitionSlideIn} class={imgClass} /> | ||
{/key} | ||
{/if} | ||
|
||
<!-- | ||
@component | ||
[Go to docs](https://flowbite-svelte.com/) | ||
## Props | ||
@prop export let image: HTMLImgAttributes; | ||
@prop export let transition: TransitionFunc = (x) => fade(x, { duration: 700, easing: quintOut }); | ||
@prop export let transition: TransitionFunc | null = null; | ||
--> |
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.