Skip to content

Commit 878989c

Browse files
committed
allow passing thru of data-sveltekit- attributes
1 parent abfd777 commit 878989c

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed

src/lib/marks/Frame.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
BaseMarkProps,
88
'fill' | 'stroke' | 'fillOpacity' | 'strokeOpacity'
99
> &
10+
LinkableMarkProps &
1011
Omit<
1112
BaseRectMarkProps,
1213
'inset' | 'insetLeft' | 'insetRight' | 'insetTop' | 'insetBottom'
@@ -27,7 +28,7 @@
2728
<script lang="ts">
2829
import Mark from '../Mark.svelte';
2930
import { getContext } from 'svelte';
30-
import type { PlotContext, BaseRectMarkProps } from '../types.js';
31+
import type { PlotContext, BaseRectMarkProps, LinkableMarkProps } from '../types.js';
3132
import type { BaseMarkProps } from '../types.js';
3233
import RectPath from './helpers/RectPath.svelte';
3334

src/lib/marks/Sphere.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Geo mark with Sphere geometry object -->
33

44
<script module lang="ts">
5-
import { type BaseMarkProps } from '$lib/types.js';
6-
export type SphereMarkProps = BaseMarkProps;
5+
import { type BaseMarkProps, type LinkableMarkProps } from '$lib/types.js';
6+
export type SphereMarkProps = BaseMarkProps & LinkableMarkProps;
77
</script>
88

99
<script lang="ts">

src/lib/marks/helpers/Anchor.svelte

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
const rel = $derived(resolveProp(options.rel, datum, null));
99
const type = $derived(resolveProp(options.type, datum, null));
1010
const download = $derived(resolveProp(options.download, datum, null));
11+
12+
// filter data attributes from options
13+
const dataAttributes = $derived(
14+
Object.fromEntries(
15+
Object.entries(options).filter(([key]) => key.startsWith('data-sveltekit-'))
16+
)
17+
);
1118
</script>
1219

1320
{#if href}
@@ -20,6 +27,7 @@
2027
{rel}
2128
{type}
2229
{download}
30+
{...dataAttributes}
2331
aria-label="link"
2432
xmlns="http://www.w3.org/2000/svg">
2533
{@render children?.()}

src/lib/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,8 @@ export type LinkableMarkProps = {
657657
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#download
658658
*/
659659
download: ConstantAccessor<boolean>;
660+
// allow data-sveltekit-* attributes on the link element, e.g. data-sveltekit-reload
661+
[key: `data-sveltekit-${string}`]: string | boolean;
660662
};
661663

662664
export type BaseMarkProps = Partial<{

src/routes/examples/bar/linked-bars.svelte

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,30 @@
77
<script>
88
import { Plot, BarX } from 'svelteplot';
99
import { page } from '$app/state';
10+
const data = [
11+
{
12+
url: '/marks/line',
13+
label: 'Line',
14+
value: 5
15+
},
16+
{
17+
url: '/marks/bar',
18+
label: 'Bar',
19+
value: 3
20+
},
21+
{
22+
url: '/marks/dot',
23+
label: 'Dot',
24+
value: 4
25+
}
26+
];
1027
</script>
1128

1229
<Plot>
1330
<BarX
14-
data={[1, 2, 3, 4, 5]}
15-
href={(d) => `#/${d}`}
16-
target="_blank" />
31+
{data}
32+
x="value"
33+
y="label"
34+
data-sveltekit-noscroll
35+
href="url" />
1736
</Plot>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy