daisy buttons

This commit is contained in:
Benjamin Palko 2024-12-17 23:29:43 -05:00
parent d839d9071a
commit 251c2b23e7
6 changed files with 82 additions and 54 deletions

View file

@ -11,20 +11,35 @@
onClick: fn()
},
argTypes: {
color: {
control: 'select',
options: [
'neutral',
'primary',
'secondary',
'accent',
'ghost',
'link',
'info',
'success',
'warning',
'error'
]
},
outline: {
control: 'boolean'
},
size: {
control: 'select',
options: ['small', 'normal', 'large'],
defaultValue: 'normal'
options: ['Default', 'xs', 'sm', 'lg'],
defaultValue: 'Default'
},
backgroundColor: {
control: 'color'
},
primary: {
control: 'boolean',
defaultValue: true
type: {
control: 'select',
options: ['button', 'reset', 'submit']
}
}
});
</script>
<Story name="Default" args={{ label: 'Button', size: 'normal', primary: true }} />
<Story name="Default" args={{ label: 'Button', color: 'primary' }} />

View file

@ -1,51 +1,54 @@
<script lang="ts">
import type { DaisyColor, DaisySize } from '$lib/types';
import type { HTMLButtonAttributes } from 'svelte/elements';
let {
type = 'button',
onClick,
label,
size = 'normal',
backgroundColor,
primary = false
}: {
type?: HTMLButtonAttributes['type'];
onClick?: () => void;
interface Props {
color?: DaisyColor;
glass?: boolean;
label: string;
size?: 'small' | 'normal' | 'large';
backgroundColor?: string;
primary?: boolean;
} = $props();
outline?: boolean;
onClick?: () => void;
responsive?: boolean;
size?: DaisySize;
type?: HTMLButtonAttributes['type'];
wide?: boolean;
}
let {
color,
glass = false,
label,
outline = false,
onClick,
responsive = false,
size,
type = 'button',
wide = false
}: Props = $props();
</script>
<button
{type}
onclick={onClick}
class={`button button--${size}`}
style:background-color={backgroundColor}
class:button--primary={primary}
class:button--secondary={!primary}
class:btn-outline={outline}
class:btn-wide={wide}
class:glass
class:btn-xs={size === 'xs'}
class:btn-sm={size === 'sm'}
class:btn-lg={size === 'lg'}
class:btn-neutral={color === 'neutral'}
class:btn-primary={color === 'primary'}
class:btn-secondary={color === 'secondary'}
class:btn-accent={color === 'accent'}
class:btn-ghost={color === 'ghost'}
class:btn-link={color === 'link'}
class:btn-info={color === 'info'}
class:btn-success={color === 'success'}
class:btn-warning={color === 'warning'}
class:btn-error={color === 'error'}
class={`btn ${responsive && 'btn-xs sm:btn-sm md:btn-md lg:btn-lg'}`}
>
{label}
</button>
<style>
.button {
@apply inline-block cursor-pointer rounded-lg border-0 font-semibold leading-none transition-colors hover:opacity-80 hover:shadow-lg;
}
.button--small {
@apply px-2 py-0.5 text-sm;
}
.button--normal {
@apply px-2 py-1 text-base;
}
.button--large {
@apply px-3 py-1.5 text-lg;
}
.button--primary {
@apply bg-red-600 text-white;
}
.button--secondary {
@apply bg-blue-600 text-white;
}
</style>
<style></style>

View file

@ -0,0 +1,12 @@
export type DaisyColor =
| 'default'
| 'neutral'
| 'primary'
| 'secondary'
| 'accent'
| 'ghost'
| 'link'
| 'info'
| 'success'
| 'warning'
| 'error';

View file

@ -0,0 +1 @@
export type DaisySize = 'xs' | 'sm' | 'lg';

2
src/lib/types/index.ts Normal file
View file

@ -0,0 +1,2 @@
export * from './daisy-colors';
export * from './daisy-sizes';

View file

@ -24,13 +24,8 @@
<TextInput label="Email" name="email" type="email" />
<TextInput label="Password" name="password" type="password" />
<div class="flex gap-2">
<Button
onClick={onViewToggle}
label={mode === 'login' ? 'Register' : 'Login'}
size="large"
primary
/>
<Button type="submit" label="Submit" size="large" />
<Button onClick={onViewToggle} label={mode === 'login' ? 'Register' : 'Login'} />
<Button type="submit" label="Submit" />
</div>
</form>
</div>