Build out components #45
3 changed files with 61 additions and 0 deletions
27
src/lib/components/Feedback/Tooltip.stories.svelte
Normal file
27
src/lib/components/Feedback/Tooltip.stories.svelte
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<script module lang="ts">
|
||||
import { defineMeta } from '@storybook/addon-svelte-csf';
|
||||
import Tooltip from './Tooltip.svelte';
|
||||
import { Button } from '../Actions';
|
||||
import type { ComponentProps } from 'svelte';
|
||||
|
||||
const { Story } = defineMeta({
|
||||
title: 'Feedback/Tooltip',
|
||||
component: Tooltip,
|
||||
argTypes: {
|
||||
color: {
|
||||
control: 'select',
|
||||
options: ['primary', 'secondary', 'accent', 'info', 'success', 'warning', 'error'],
|
||||
},
|
||||
open: { control: 'boolean' },
|
||||
position: { control: 'select', options: ['top', 'bottom', 'left', 'right'] },
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
{#snippet template(props: ComponentProps<typeof Tooltip>)}
|
||||
<Tooltip {...props}>
|
||||
<Button color="primary">Button</Button>
|
||||
</Tooltip>
|
||||
{/snippet}
|
||||
|
||||
<Story name="Default" args={{ tip: "It's a button" }} children={template} />
|
||||
33
src/lib/components/Feedback/Tooltip.svelte
Normal file
33
src/lib/components/Feedback/Tooltip.svelte
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<script lang="ts">
|
||||
import type { DaisyColor } from '$lib/types';
|
||||
import type { SvelteHTMLElements } from 'svelte/elements';
|
||||
import { twMerge } from 'tailwind-merge';
|
||||
|
||||
type Props = {
|
||||
color?: Exclude<DaisyColor, 'neutral' | 'ghost'>;
|
||||
open?: boolean;
|
||||
position?: 'top' | 'bottom' | 'left' | 'right';
|
||||
tip?: string;
|
||||
} & SvelteHTMLElements['div'];
|
||||
let { children, class: className, color, open, position, tip, ...props }: Props = $props();
|
||||
</script>
|
||||
|
||||
<div
|
||||
class={twMerge('tooltip', className)}
|
||||
class:tooltip-primary={color === 'primary'}
|
||||
class:tooltip-secondary={color === 'secondary'}
|
||||
class:tooltip-accent={color === 'accent'}
|
||||
class:tooltip-info={color === 'info'}
|
||||
class:tooltip-success={color === 'success'}
|
||||
class:tooltip-warning={color === 'warning'}
|
||||
class:tooltip-error={color === 'error'}
|
||||
class:tooltip-open={open}
|
||||
class:tooltip-top={position === 'top'}
|
||||
class:tooltip-bottom={position === 'bottom'}
|
||||
class:tooltip-left={position === 'left'}
|
||||
class:tooltip-right={position === 'right'}
|
||||
data-tip={tip}
|
||||
{...props}
|
||||
>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
|
|
@ -2,3 +2,4 @@ export { default as Alert } from './Alert.svelte';
|
|||
export { default as Loader } from './Loader.svelte';
|
||||
export { default as Loading } from './Loading.svelte';
|
||||
export { default as Progress } from './Progress.svelte';
|
||||
export { default as Tooltip } from './Tooltip.svelte';
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue