1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-29 15:11:58 +00:00

feat: migrate CircleIconButton and add it to Storybook

Breaking change: removing the "buttonSize" prop
This commit is contained in:
ben-basten 2024-06-04 23:06:03 -04:00
parent 146f24eaae
commit 4c87890a03
No known key found for this signature in database
GPG key ID: 78803E894B258348
3 changed files with 98 additions and 1 deletions

View file

@ -0,0 +1,44 @@
<script lang="ts">
import Icon from '$lib/components/elements/icon.svelte';
type Color = 'transparent' | 'light' | 'dark' | 'gray' | 'primary' | 'opaque';
export let color: Color = 'transparent';
export let hideMobile = false;
export let icon: string;
export let padding = 3;
export let size = 24;
export let title: string; // done
export let type: 'button' | 'submit' | 'reset' = 'button';
/**
* viewBox attribute for the SVG icon.
*/
export let viewBox: string | undefined = undefined;
/**
* Override the default styling of the button for specific use cases, such as the icon color.
*/
let className = '';
export { className as class };
const colorClasses: Record<Color, string> = {
transparent: 'bg-transparent hover:bg-[#d3d3d3] dark:text-immich-dark-fg',
opaque: 'bg-transparent hover:bg-immich-bg/30 text-white hover:dark:text-white',
light: 'bg-white hover:bg-[#d3d3d3]',
dark: 'bg-[#202123] hover:bg-[#d3d3d3]',
gray: 'bg-[#d3d3d3] hover:bg-[#e2e7e9] text-immich-dark-gray hover:text-black',
primary:
'bg-immich-primary dark:bg-immich-dark-primary hover:bg-immich-primary/75 hover:dark:bg-immich-dark-primary/80 text-white dark:text-immich-dark-gray',
};
$: colorClass = colorClasses[color];
$: mobileClass = hideMobile ? 'hidden sm:flex' : '';
</script>
<button
{title}
{type}
class="flex place-content-center place-items-center rounded-full {colorClass} p-{padding} transition-all hover:dark:text-immich-dark-gray {className} {mobileClass}"
on:click
>
<Icon path={icon} {size} ariaLabel={title} {viewBox} color="currentColor" />
</button>

View file

@ -2,7 +2,7 @@
import Button from '$lib/ui/Button.svelte';
import { Template } from '@storybook/addon-svelte-csf';
export const meta = {
title: 'Button',
title: 'Components/Buttons/Button',
component: Button,
};
</script>

View file

@ -0,0 +1,53 @@
<script context="module" lang="ts">
import CircleIconButton from '$lib/ui/CircleIconButton.svelte';
import { mdiDotsVertical, mdiInformation, mdiPartyPopper } from '@mdi/js';
export const meta = {
title: 'Components/Buttons/Circle Icon Button',
component: CircleIconButton,
argTypes: {
color: {
control: 'select',
options: ['transparent', 'light', 'dark', 'gray', 'primary', 'opaque'],
},
icon: {
options: {
mdiInformation,
mdiDotsVertical,
mdiPartyPopper,
},
control: 'select',
},
title: {
control: 'text',
},
type: {
control: 'select',
options: ['button', 'submit', 'reset'],
},
viewBox: {
control: 'text',
},
},
args: {
class: '',
hideMobile: false,
icon: mdiInformation,
padding: 3,
size: 24,
title: 'Information',
type: 'button',
},
};
</script>
<script>
import { Story, Template } from '@storybook/addon-svelte-csf';
</script>
<Template let:args>
<!--👇 'on:click' allows to forward event to addon-actions -->
<CircleIconButton {...args} on:click />
</Template>
<Story name="Primary" args={{ color: 'primary' }} />
<Story name="Transparent" args={{ color: 'transparent' }} />