-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathSvg.svelte
73 lines (60 loc) · 2.18 KB
/
Svg.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!--
@component
SVG layout component
-->
<script>
import { getContext } from 'svelte';
/** @type {Element|undefined} [element] The layer's `<svg>` tag. Useful for bindings. */
export let element = undefined;
/** @type {Element|undefined} [innerElement] The layer's `<g>` tag. Useful for bindings. */
export let innerElement = undefined;
/** @type {Number|undefined} [zIndex] The layer's z-index. */
export let zIndex = undefined;
/** @type {boolean|undefined} [pointerEvents] Set this to `false` to set `pointer-events: none;` on the entire layer. */
export let pointerEvents = undefined;
/** @type {String|undefined} [viewBox] A string passed to the `viewBox` property on the `<svg>` tag. */
export let viewBox = undefined;
/** @type {String|undefined} [label] A string passed to the `aria-label` property on the `<svg>` tag. */
export let label = undefined;
/** @type {String|undefined} [labelledBy] A string passed to the `aria-labelledby property` on the `<svg>` tag. */
export let labelledBy = undefined;
/** @type {String|undefined} [describedBy] A string passed to the `aria-describedby` property on the `<svg>` tag. */
export let describedBy = undefined;
/** @type {String|undefined} [title] Shorthand to set the contents of `<title></title>` for accessibility. You can also set arbitrary HTML via the "title" slot but this is a convenient shorthand. If you use the "title" slot, this prop is ignored. */
export let title = undefined;
const { containerWidth, containerHeight, padding } = getContext('LayerCake');
</script>
<svg
bind:this={element}
class="layercake-layout-svg"
{viewBox}
width={$containerWidth}
height={$containerHeight}
style:z-index={zIndex}
style:pointer-events={pointerEvents === false ? 'none' : null}
aria-label={label}
aria-labelledby={labelledBy}
aria-describedby={describedBy}
>
<slot name="title"
>{#if title}<title>{title}</title>{/if}</slot
>
<defs>
<slot name="defs"></slot>
</defs>
<g
bind:this={innerElement}
class="layercake-layout-svg_g"
transform="translate({$padding.left}, {$padding.top})"
>
<slot {element}></slot>
</g>
</svg>
<style>
svg {
position: absolute;
top: 0;
left: 0;
overflow: visible;
}
</style>