feat: storybook cases and mocks

This commit is contained in:
Ilia Mashkov
2026-02-19 13:58:12 +03:00
parent 9d1f59d819
commit da79dd2e35
22 changed files with 3047 additions and 45 deletions

View File

@@ -0,0 +1,41 @@
<!--
Component: MockIcon
Wrapper component for Lucide icons to properly handle className in Storybook.
Lucide Svelte icons from @lucide/svelte/icons/* don't properly handle
the className prop directly. This wrapper ensures the class is applied
correctly via the HTML element's class attribute.
-->
<script lang="ts">
import { cn } from '$shared/shadcn/utils/shadcn-utils';
import type {
Component,
Snippet,
} from 'svelte';
interface Props {
/**
* The Lucide icon component
*/
icon: Component;
/**
* CSS classes to apply to the icon
*/
class?: string;
/**
* Additional icon-specific attributes
*/
attrs?: Record<string, unknown>;
}
let { icon: Icon, class: className, attrs = {} }: Props = $props();
</script>
{#if Icon}
{@const __iconClass__ = cn('size-4', className)}
<!-- Render icon component dynamically with class prop -->
<Icon
class={__iconClass__}
{...attrs}
/>
{/if}

View File

@@ -0,0 +1,64 @@
<!--
Component: Providers
Storybook wrapper that provides required contexts for components.
Provides:
- responsive: ResponsiveManager context for breakpoint tracking
- tooltip: Tooltip.Provider context for shadcn Tooltip components
- Additional Radix UI providers can be added here as needed
-->
<script lang="ts">
import { createResponsiveManager } from '$shared/lib';
import type { ResponsiveManager } from '$shared/lib';
import { Provider as TooltipProvider } from '$shared/shadcn/ui/tooltip';
import { setContext } from 'svelte';
import type { Snippet } from 'svelte';
interface Props {
children: Snippet;
/**
* Initial viewport width for the responsive context (default: 1280)
*/
initialWidth?: number;
/**
* Initial viewport height for the responsive context (default: 720)
*/
initialHeight?: number;
/**
* Tooltip provider options
*/
tooltipDelayDuration?: number;
/**
* Tooltip skip delay duration
*/
tooltipSkipDelayDuration?: number;
}
let {
children,
initialWidth = 1280,
initialHeight = 720,
tooltipDelayDuration = 200,
tooltipSkipDelayDuration = 300,
}: Props = $props();
// Create a responsive manager with default breakpoints
const responsiveManager = createResponsiveManager();
// Initialize the responsive manager to set up resize listeners
$effect(() => {
return responsiveManager.init();
});
// Provide the responsive context
setContext<ResponsiveManager>('responsive', responsiveManager);
</script>
<div class="storybook-providers" style:width="100%" style:height="100%">
<TooltipProvider
delayDuration={tooltipDelayDuration}
skipDelayDuration={tooltipSkipDelayDuration}
>
{@render children()}
</TooltipProvider>
</div>

View File

@@ -0,0 +1,24 @@
/**
* ============================================================================
* STORYBOOK HELPERS
* ============================================================================
*
* Helper components and utilities for Storybook stories.
*
* ## Usage
*
* ```svelte
* <script lang="ts">
* import { Providers, MockIcon } from '$shared/lib/storybook';
* </script>
*
* <Providers>
* <YourComponent />
* </Providers>
* ```
*
* @module
*/
export { default as MockIcon } from './MockIcon.svelte';
export { default as Providers } from './Providers.svelte';