Skip to content

Commit

Permalink
Add progress to icon button (#519)
Browse files Browse the repository at this point in the history
  • Loading branch information
micheal-parks committed May 16, 2024
1 parent 7dd93fb commit 7971d1d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@viamrobotics/prime-core",
"version": "0.0.117",
"version": "0.0.118",
"publishConfig": {
"access": "public"
},
Expand Down
10 changes: 9 additions & 1 deletion packages/core/src/lib/button/icon-button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ For user triggered actions.
import cx from 'classnames';
import { Icon, type IconName } from '$lib';
import { preventHandler } from '$lib/prevent-handler';
import Progress from '$lib/progress/progress.svelte';
/** The icon shown in the button. */
export let icon: IconName;
Expand All @@ -29,6 +30,9 @@ export let type: 'button' | 'submit' | 'reset' = 'button';
/** The communicated action type to the user. */
export let variant: 'primary' | 'secondary' | 'danger' = 'primary';
/** Shows progress indicator. Determinite progress is a @TODO */
export let progress: 'indeterminate' | number | undefined = undefined;
/** Additional CSS classes to pass to the button. */
let extraClasses: cx.Argument = '';
export { extraClasses as cx };
Expand Down Expand Up @@ -59,5 +63,9 @@ $: handleDisabled = preventHandler(disabled);
on:click
on:click|capture={handleDisabled}
>
<Icon name={icon} />
{#if progress}
<Progress variant={variant === 'danger' ? 'light' : 'dark'} />
{:else}
<Icon name={icon} />
{/if}
</button>
13 changes: 5 additions & 8 deletions packages/core/src/lib/progress/progress.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ export let variant: 'dark' | 'light' = 'dark';
</script>

<div
class={cx(
'container -ml-1 flex h-4 w-4 items-center justify-center p-[1.5px]',
{
'': size === 'small',
'scale-[1.125]': size === 'medium',
'scale-[1.5]': size === 'large',
}
)}
class={cx('container flex h-4 w-4 items-center justify-center p-[1.5px]', {
'': size === 'small',
'scale-[1.125]': size === 'medium',
'scale-[1.5]': size === 'large',
})}
>
<div class="translate-x-[-6.5px]">
{#each { length: 8 } as _, index}
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,13 @@ const onHoverDelayMsInput = (event: Event) => {
</Button>

<Button progress="indeterminate">Loading</Button>
<IconButton
label="Pause"
variant="secondary"
progress="indeterminate"
icon="pause"
cx="border border-light"
/>
<Button
progress="indeterminate"
variant="danger">Loading</Button
Expand Down
4 changes: 4 additions & 0 deletions packages/storybook/src/stories/icon-button.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ import { IconButton } from '@viamrobotics/prime-core';
<Canvas>
<Story of={IconButtonStories.Disabled} />
</Canvas>

<Canvas>
<Story of={IconButtonStories.Progress} />
</Canvas>
8 changes: 8 additions & 0 deletions packages/storybook/src/stories/icon-button.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ import { IconButton } from '@viamrobotics/prime-core';
disabled
/>
</Story>

<Story name="Progress">
<IconButton
icon="refresh"
progress="indeterminate"
label="Restart object"
/>
</Story>

0 comments on commit 7971d1d

Please sign in to comment.