Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: code toggle for alert examples #42

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"publint": "^0.2.0",
"svelte": "^5.0.0",
"svelte-check": "^4.0.0",
"svelte-highlight": "^7.8.0",
"tailwindcss": "^3.4.9",
"typescript": "^5.0.0",
"typescript-eslint": "^8.15.0",
Expand Down
55 changes: 55 additions & 0 deletions src/docs/components/ExampleCard.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<script lang="ts">
import type { Theme } from '$docs/constants.js';
import { Button, Card, CardBody, CardHeader, CardTitle, HStack, Icon } from '@immich/ui';
import { mdiEye, mdiXml } from '@mdi/js';
import type { Component as SvelteComponent } from 'svelte';
import { HighlightSvelte, LineNumbers } from 'svelte-highlight';
import atomOneDark from 'svelte-highlight/styles/atom-one-dark';

type Props = {
title: string;
example: string;
component: SvelteComponent;
theme: Theme;
};

const { title, component: Component, example }: Props = $props();

let viewMode = $state<'code' | 'example'>('example');

const handleToggle = () => {
viewMode = viewMode === 'code' ? 'example' : 'code';
};
</script>

<svelte:head>
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
{@html atomOneDark}
</svelte:head>

<Card>
<CardHeader>
<div class="flex justify-between">
<CardTitle>{title}</CardTitle>
<HStack gap={1}>
<Button disabled={viewMode === 'example'} onclick={handleToggle} size="small">
<Icon icon={mdiEye} size="1.5em" />
<span>Preview</span>
</Button>
<Button disabled={viewMode === 'code'} onclick={handleToggle} size="small">
<Icon icon={mdiXml} size="1.5em" />
<span>Code</span>
</Button>
</HStack>
</div>
</CardHeader>
<CardBody class={viewMode === 'code' ? 'p-0 pt-4' : ''}>
{#if viewMode === 'example'}
<Component />
{:else}
<HighlightSvelte code={example.trim()} let:highlighted>
<LineNumbers {highlighted} hideBorder wrapLines />
</HighlightSvelte>
{/if}
</CardBody>
</Card>
74 changes: 16 additions & 58 deletions src/routes/examples/alert/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,65 +1,23 @@
<script lang="ts">
import DualThemeLayout from '$docs/components/DualThemeLayout.svelte';
import Lorem from '$docs/components/Lorem.svelte';
import { colors } from '$docs/constants.js';
import { Alert, Card, CardBody, CardHeader, CardTitle, Stack } from '@immich/ui';
import { mdiHelpCircleOutline } from '@mdi/js';
import ExampleCard from '$docs/components/ExampleCard.svelte';
import BasicExample from './BasicExample.svelte';
import basicExample from './BasicExample.svelte?raw';
import ColorExample from './ColorExample.svelte';
import colorExample from './ColorExample.svelte?raw';
import CustomIconExample from './CustomIconExample.svelte';
import customIconExample from './CustomIconExample.svelte?raw';
</script>

<DualThemeLayout name="Alert">
{#snippet component()}
<Card>
<CardHeader>
<CardTitle>Basic</CardTitle>
</CardHeader>
<CardBody>
<Stack>
{#each colors as color}
<Alert {color} title="This is an alert" />
{/each}
</Stack>
</CardBody>
</Card>

<Card>
<CardHeader>
<CardTitle>Colors</CardTitle>
</CardHeader>
<CardBody>
<Stack>
{#each colors as color}
<Alert {color} title="This is an alert">
<Lorem />
</Alert>
{/each}
</Stack>
</CardBody>
</Card>

<Card>
<CardHeader>
<CardTitle>Custom icon</CardTitle>
</CardHeader>
<CardBody>
<Alert icon={mdiHelpCircleOutline} title="This is an alert">
<Lorem />
</Alert>
</CardBody>
</Card>

<Card>
<CardHeader>
<CardTitle>Colors</CardTitle>
</CardHeader>
<CardBody>
<Stack>
{#each colors as color}
<Alert {color} title="This is an alert">
<Lorem />
</Alert>
{/each}
</Stack>
</CardBody>
</Card>
{#snippet component({ theme })}
<ExampleCard {theme} title="Basic" example={basicExample} component={BasicExample} />
<ExampleCard {theme} title="Colors" example={colorExample} component={ColorExample} />
<ExampleCard
{theme}
title="Custom Icon"
example={customIconExample}
component={CustomIconExample}
/>
{/snippet}
</DualThemeLayout>
12 changes: 12 additions & 0 deletions src/routes/examples/alert/BasicExample.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script lang="ts">
import { Alert, Stack } from '@immich/ui';
</script>

<Stack>
<Alert color="primary" title="This is an alert" />
<Alert color="secondary" title="This is an alert" />
<Alert color="success" title="This is an alert" />
<Alert color="info" title="This is an alert" />
<Alert color="warning" title="This is an alert" />
<Alert color="danger" title="This is an alert" />
</Stack>
25 changes: 25 additions & 0 deletions src/routes/examples/alert/ColorExample.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script lang="ts">
import Lorem from '$docs/components/Lorem.svelte';
import { Alert, Stack } from '@immich/ui';
</script>

<Stack>
<Alert color="primary" title="This is a primary alert">
<Lorem />
</Alert>
<Alert color="secondary" title="This is a secondary alert">
<Lorem />
</Alert>
<Alert color="success" title="This is a success alert">
<Lorem />
</Alert>
<Alert color="info" title="This is an info alert">
<Lorem />
</Alert>
<Alert color="warning" title="This is a warning alert">
<Lorem />
</Alert>
<Alert color="danger" title="This is a danger alert">
<Lorem />
</Alert>
</Stack>
9 changes: 9 additions & 0 deletions src/routes/examples/alert/CustomIconExample.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script lang="ts">
import Lorem from '$docs/components/Lorem.svelte';
import { Alert } from '@immich/ui';
import { mdiHelpCircleOutline } from '@mdi/js';
</script>

<Alert icon={mdiHelpCircleOutline} title="This is an alert">
<Lorem />
</Alert>
Loading