From d0e92bc6b052ad20ca2379dd26cfde2e7aff0f55 Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Thu, 9 Feb 2023 12:02:06 +0930 Subject: [PATCH] feat(Components): add target prop to Button, Fab, and IconButton --- components/mdc/Button/Button.svelte | 2 ++ components/mdc/Fab/Fab.svelte | 3 ++- components/mdc/IconButton/IconButton.svelte | 18 +++++++++++------- index.d.ts | 11 +++++++---- stories/Button.stories.svelte | 16 +++++++++++++++- stories/Fab.stories.svelte | 3 +++ stories/IconButton.stories.svelte | 14 +++++++++++++- 7 files changed, 53 insertions(+), 14 deletions(-) diff --git a/components/mdc/Button/Button.svelte b/components/mdc/Button/Button.svelte index 5a12ce1f..b1268e8d 100644 --- a/components/mdc/Button/Button.svelte +++ b/components/mdc/Button/Button.svelte @@ -9,6 +9,7 @@ export let raised = false export let prependIcon = undefined export let appendIcon = undefined export let url = undefined +export let target = '' let element = {} onMount(() => { @@ -24,6 +25,7 @@ onMount(() => { role="button" class:mdc-button--outlined={outlined} class:mdc-button--raised={raised} + {target} {disabled} on:click bind:this={element} diff --git a/components/mdc/Fab/Fab.svelte b/components/mdc/Fab/Fab.svelte index efd53def..ed6d1892 100644 --- a/components/mdc/Fab/Fab.svelte +++ b/components/mdc/Fab/Fab.svelte @@ -9,6 +9,7 @@ export let mini = false export let extended = false export let url = '' export let action = {} +export let target = '' let element = {} @@ -38,7 +39,7 @@ onMount(() => { {label} {:else if url} - +
{icon} diff --git a/components/mdc/IconButton/IconButton.svelte b/components/mdc/IconButton/IconButton.svelte index 53423a1b..be67e212 100644 --- a/components/mdc/IconButton/IconButton.svelte +++ b/components/mdc/IconButton/IconButton.svelte @@ -7,6 +7,7 @@ export let icon export let ariaLabel export let url = '' export let disabled = false +export let target = '' let element = {} onMount(() => { @@ -25,15 +26,17 @@ onMount(() => { class="mdc-icon-button material-icons {$$props.class}" aria-label={ariaLabel} {disabled} + {target} on:click on:mousedown on:blur on:focus - bind:this={element}> -
- + bind:this={element} + > +
+ {icon} - + {:else} {/if} diff --git a/index.d.ts b/index.d.ts index db4fa8c7..b92681f0 100644 --- a/index.d.ts +++ b/index.d.ts @@ -5,11 +5,12 @@ declare module '@silintl/ui-components' { export type actions = writable interface ButtonProps extends svelte.JSX.HTMLAttributes { + appendIcon?: string disabled?: boolean outlined?: boolean - raised?: boolean prependIcon?: string - appendIcon?: string + raised?: boolean + target?: string url?: string } export class Button extends SvelteComponentTyped {} @@ -134,14 +135,16 @@ declare module '@silintl/ui-components' { extended?: boolean url?: string action?: Function + target?: string } export class Fab extends SvelteComponentTyped {} interface IconButtonProps extends svelte.JSX.HTMLAttributes { - icon?: string ariaLabel?: string - url?: string disabled?: boolean + icon?: string + target?: string + url?: string } export class IconButton extends SvelteComponentTyped {} diff --git a/stories/Button.stories.svelte b/stories/Button.stories.svelte index 75cdee66..18472109 100644 --- a/stories/Button.stories.svelte +++ b/stories/Button.stories.svelte @@ -28,5 +28,19 @@ const args = { {} })} + args={copyAndModifyArgs(args, { + url: '/?path=/story/atoms-button--url', + raised: false, + 'on:click': () => {}, + })} +/> + + {}, + })} /> diff --git a/stories/Fab.stories.svelte b/stories/Fab.stories.svelte index 2f9c59f6..4c5fb70c 100644 --- a/stories/Fab.stories.svelte +++ b/stories/Fab.stories.svelte @@ -20,3 +20,6 @@ const args = { + alert('This is an action') })} /> + + diff --git a/stories/IconButton.stories.svelte b/stories/IconButton.stories.svelte index 4958a491..16a97342 100644 --- a/stories/IconButton.stories.svelte +++ b/stories/IconButton.stories.svelte @@ -26,7 +26,19 @@ import { IconButton } from '../components/mdc' icon: 'done', ariaLabel: 'ariaLabel', class: '', //will only work with global class - url: 'https://google.com', + url: '/?path=/story/atoms-iconbutton--url', + disabled: false, + 'on:click': () => alert('click'), + }} +/> + alert('click'), }}