|
1 | 1 | <script lang="ts"> |
2 | | - import { type Component } from "svelte"; |
3 | 2 | import { Banner, banner, Button, Skeleton, ImagePlaceholder, Label, Radio, type BannerProps, uiHelpers } from "$lib"; |
4 | 3 | import { BullhornOutline } from "flowbite-svelte-icons"; |
5 | 4 | import { blur, fly, slide, scale } from "svelte/transition"; |
|
10 | 9 | import CodeWrapper from "../../utils/CodeWrapper.svelte"; |
11 | 10 | import H1 from "../../utils/H1.svelte"; |
12 | 11 | import H2 from "../../utils/H2.svelte"; |
13 | | - import { isGeneratedCodeOverflow, isSvelteOverflow, getExampleFileName } from "../../utils/helpers"; |
| 12 | + import { isGeneratedCodeOverflow } from "../../utils/helpers"; |
14 | 13 | // for Props table |
15 | 14 | import CompoAttributesViewer from "../../utils/CompoAttributesViewer.svelte"; |
16 | 15 | const dirName = "banner"; |
|
23 | 22 | eager: true |
24 | 23 | }) as Record<string, string>; |
25 | 24 |
|
26 | | - const exampleArr = [ |
27 | | - { name: "Newsletter signup banner", component: ExampleComponents.NewsletterSignupBanner }, |
28 | | - { name: "Information banner", component: ExampleComponents.InformationBanner } |
29 | | - ]; |
30 | | - let selectedExample: string | number = $state(exampleArr[0].name); |
31 | | - let svelteCode = $derived(getExampleFileName(selectedExample, exampleArr)); |
32 | | -
|
33 | | - function findObject(arr: { name: string; component: Component }[], name: string) { |
34 | | - const matchingObject = arr.find((obj) => obj.name === name); |
35 | | - return matchingObject ? matchingObject.component : null; |
36 | | - } |
37 | | - const SelectedComponent = $derived(findObject(exampleArr, selectedExample)); |
38 | | - // end of dynamic svelte component |
39 | | -
|
40 | 25 | // interactive example |
41 | 26 | // position, bannerType, color, class:divClass |
42 | 27 | const colors = Object.keys(banner.variants.color); |
|
125 | 110 | }; |
126 | 111 | // for DynamicCodeBlock setup for examples section. dynamically adjust the height of the code block based on the svelteCode content. |
127 | 112 |
|
128 | | - // for examples DynamicCodeBlockHighlight |
129 | | - let codeBlock = uiHelpers(); |
130 | | - let exampleExpand = $state(false); |
131 | | - let showExpandButton = $derived(isSvelteOverflow(svelteCode, exampleModules)); |
132 | | - const handleExpandClick = () => { |
133 | | - exampleExpand = !exampleExpand; |
134 | | - }; |
135 | 113 | // end of DynamicCodeBlock setup |
136 | 114 | $effect(() => { |
137 | | - exampleExpand = codeBlock.isOpen; |
138 | 115 | builderExpand = builder.isOpen; |
139 | 116 | }); |
140 | 117 | </script> |
|
190 | 167 | {/snippet} |
191 | 168 | </CodeWrapper> |
192 | 169 |
|
193 | | -<H2>Examples</H2> |
| 170 | +<H2>Newletter signup banner</H2> |
| 171 | +<CodeWrapper> |
| 172 | + <ExampleComponents.NewsletterSignupBanner /> |
| 173 | + {#snippet codeblock()} |
| 174 | + <HighlightCompo codeLang="ts" code={exampleModules["./examples/NewsletterSignupBanner.svelte"] as string} /> |
| 175 | + {/snippet} |
| 176 | +</CodeWrapper> |
194 | 177 |
|
195 | | -<CodeWrapper innerClass="p-0"> |
196 | | - <div class="mb-4 flex flex-wrap p-6"> |
197 | | - <Label class="mb-4 w-full font-bold">Example</Label> |
198 | | - {#each exampleArr as style} |
199 | | - <Radio labelClass="w-64 my-1" onclick={() => (exampleExpand = false)} name="block_style" bind:group={selectedExample} value={style.name}>{style.name}</Radio> |
200 | | - {/each} |
201 | | - </div> |
202 | | - <SelectedComponent /> |
| 178 | +<H2>Information banner</H2> |
| 179 | +<CodeWrapper> |
| 180 | + <ExampleComponents.InformationBanner /> |
203 | 181 | {#snippet codeblock()} |
204 | | - <DynamicCodeBlockHighlight replaceLib {handleExpandClick} expand={exampleExpand} {showExpandButton} code={exampleModules[`./examples/${svelteCode}`] as string} /> |
| 182 | + <HighlightCompo codeLang="ts" code={exampleModules["./examples/InformationBanner.svelte"] as string} /> |
205 | 183 | {/snippet} |
206 | 184 | </CodeWrapper> |
207 | 185 |
|
|
0 commit comments