Skip to content

Commit a3a4118

Browse files
authored
refactor!: change component type props to snippets (#17)
1 parent 785e095 commit a3a4118

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ npm install --save svelte-medium-image-zoom
3232

3333
## API
3434

35+
Note: component type props are rendered as `snippets`, check [this](https://svelte.dev/docs/svelte/snippet) for more.
36+
[example use](https://github.com/moonlitgrace/svelte-medium-image-zoom/pull/17)
37+
3538
```typescript
3639
export interface ZoomProps {
3740
// Accessible label text for when you want to unzoom.
@@ -50,11 +53,11 @@ export interface ZoomProps {
5053

5154
// Provide your own unzoom button icon.
5255
// Default: ICompress
53-
IconUnzoom?: Component | Snippet;
56+
icon_unzoom?: Snippet;
5457

5558
// Provide your own zoom button icon.
5659
// Default: IEnlarge
57-
IconZoom?: Component | Snippet;
60+
icon_zoom?: Snippet;
5861

5962
// Tell the component whether or not it should be zoomed
6063
// Default: false

src/lib/components/zoom.svelte

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
a11y_name_button_zoom = 'Expand image',
5454
children,
5555
dialog_class,
56-
IconUnzoom = ICompress,
57-
IconZoom = IEnlarge,
56+
icon_unzoom,
57+
icon_zoom,
5858
is_zoomed,
5959
on_zoom_change,
6060
wrap_element = 'div',
@@ -408,7 +408,11 @@
408408
onclick={handle_zoom}
409409
type="button"
410410
>
411-
<IconZoom />
411+
{#if icon_zoom}
412+
{@render icon_zoom()}
413+
{:else}
414+
<IEnlarge />
415+
{/if}
412416
</button>
413417
</svelte:element>
414418
<!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_noninteractive_element_interactions -->
@@ -444,7 +448,11 @@
444448
onclick={handle_unzoom_btn_click}
445449
type="button"
446450
>
447-
<IconUnzoom />
451+
{#if icon_unzoom}
452+
{@render icon_unzoom()}
453+
{:else}
454+
<ICompress />
455+
{/if}
448456
</button>
449457
</div>
450458
</dialog>

src/lib/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Component, Snippet } from 'svelte';
1+
import type { Snippet } from 'svelte';
22

33
// ==================================================
44

@@ -18,8 +18,8 @@ export interface ZoomProps {
1818
a11y_name_button_zoom?: string;
1919
children: Snippet;
2020
dialog_class?: string;
21-
IconUnzoom?: Component;
22-
IconZoom?: Component;
21+
icon_unzoom?: Snippet;
22+
icon_zoom?: Snippet;
2323
is_zoomed?: boolean;
2424
on_zoom_change?: (value: boolean) => void;
2525
wrap_element?: 'div' | 'span';

0 commit comments

Comments
 (0)