Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Svelte 5 - Marquee #27

Open
wants to merge 5 commits into
base: svelte-5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/spicy-lizards-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@288-toolkit/marquee": major
---

Migrate to svelte 5
35 changes: 7 additions & 28 deletions packages/components/marquee/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,26 @@ pnpm i @288-toolkit/marquee

A css animated generic marquee component.

## Props
## Css variables

### --gap

Should be set as a css variable.

To make a seamless marquee effect, the component generates whatever is in the slot twice or more.
The `gap` property represents the space between the copies. Default: `0`.

### --speed

Should be set as a css variable.

The marquee animation duration, which determines the speed of the marquee. The higher the number,
the slower the marquee. Default: `12000ms`.

### direction

The direction of the marquee.

```ts
export let direction: 'natural' | 'inverted' = 'natural';
```

### orientation

The orientation of the marquee. Default: `horizontal`.

```ts
export let orientation: 'vertical' | 'horizontal' = 'horizontal';
```

### stopOnHover

Whether the marquee should pause when hovered. Default: `false`.
## Props

```ts
export let stopOnHover = false;
```
- `direction` - `'natural' | 'inverted'`: The direction of the marquee. Default: `natural`.
- `orientation` - `'vertical' | 'horizontal'`: The orientation of the marquee. Default:
`horizontal`.
- `stopOnHover` - `boolean`: Whether the marquee should pause when hovered. Default: `false`.

## Slot props
## Children props

- `copy` (`boolean`): Wether the rendered slot is a copy of the original.

Expand Down
2 changes: 1 addition & 1 deletion packages/components/marquee/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}
},
"peerDependencies": {
"svelte": "4.x || 5.x"
"svelte": "5.x"
},
"dependencies": {
"@288-toolkit/timeout": "workspace:^"
Expand Down
38 changes: 24 additions & 14 deletions packages/components/marquee/src/lib/Marquee.svelte
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
<script lang="ts">
import { debounce } from '@288-toolkit/timeout';

/**
* The direction of the marquee.
*/
export let direction: 'natural' | 'inverted' = 'natural';
/**
* The orientation of the marquee. Default: `horizontal`.
*/
export let orientation: 'vertical' | 'horizontal' = 'horizontal';
/**
* Wether the marquee should pause when hovered. Default: `false`.
*/
export let stopOnHover = false;
interface Props {
/**
* The direction of the marquee.
*/
direction?: 'natural' | 'inverted';
/**
* The orientation of the marquee. Default: `horizontal`.
*/
orientation?: 'vertical' | 'horizontal';
/**
* Wether the marquee should pause when hovered. Default: `false`.
*/
stopOnHover?: boolean;
children?: import('svelte').Snippet<[{ copy: boolean }]>;
}

let {
direction = 'natural',
orientation = 'horizontal',
stopOnHover = false,
children
}: Props = $props();

const minCopies = 2;

let copies = minCopies;
let copies = $state(minCopies);

const setCopies = (el: HTMLElement) => {
const observer = new ResizeObserver(
Expand Down Expand Up @@ -55,7 +65,7 @@
{#each new Array(copies) as _, i}
{@const copy = i > 0}
<div class="_marquee" aria-hidden={copy || null}>
<slot {copy} />
{@render children?.({ copy })}
</div>
{/each}
{/key}
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading