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

component: Note #31

Merged
merged 6 commits into from
Jul 30, 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
3 changes: 3 additions & 0 deletions src/lib/assets/icons/check-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion src/lib/assets/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import BrandAssets from './brand-assets.svg?component';
import ChartBarMiddle from './chart-bar-middle.svg?component';
import ChartBarPeak from './chart-bar-peak.svg?component';
import ChartTrendingDown from './chart-trending-down.svg?component';
import CheckCircle from './check-circle.svg?component';
import Check from './check.svg?component';
import ChevronLeft from './chevron-left.svg?component';
import ChevronRightSmall from './chevron-right-small.svg?component';
Expand All @@ -29,6 +30,7 @@ import GitBranch from './git-branch.svg?component';
import Globe from './globe.svg?component';
import GridSquare from './grid-square.svg?component';
import Inbox from './inbox.svg?component';
import Information from './information.svg?component';
import Key from './key.svg?component';
import Link from './link.svg?component';
import LoaderCircle from './loader-circle.svg?component';
Expand Down Expand Up @@ -56,6 +58,7 @@ import Tabs from './tabs.svg?component';
import ThemeSwitchDark from './theme-switch-dark.svg?component';
import ThemeSwitchLight from './theme-switch-light.svg?component';
import ThemeSwitchSystem from './theme-switch-system.svg?component';
import Warning from './warning.svg?component';

export const Icons = {
Accessibility,
Expand All @@ -69,6 +72,7 @@ export const Icons = {
ChartBarMiddle,
ChartBarPeak,
ChartTrendingDown,
CheckCircle,
Check,
ChevronLeft,
ChevronRightSmall,
Expand All @@ -89,6 +93,7 @@ export const Icons = {
Globe,
GridSquare,
Inbox,
Information,
Key,
Link,
LoaderCircle,
Expand All @@ -115,5 +120,6 @@ export const Icons = {
Tabs,
ThemeSwitchDark,
ThemeSwitchLight,
ThemeSwitchSystem
ThemeSwitchSystem,
Warning
};
3 changes: 3 additions & 0 deletions src/lib/assets/icons/information.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/lib/assets/icons/warning.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions src/lib/components/ui/note/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { type VariantProps, tv } from 'tailwind-variants';

export { default as Note } from './note.svelte';

export const note_variants = tv({
base: 'flex grow flex-wrap items-center justify-between gap-3 text-pretty rounded-md border data-[disabled=true]:border-gray-alpha-200 data-[disabled=true]:bg-transparent data-[disabled=true]:text-gray-700 sm:flex-nowrap hover:[&>div>div>a]:underline [&>div>div>a]:data-[disabled=true]:text-gray-900',
variants: {
variant: {
secondary: 'bg-transparent text-gray-900 selection:bg-gray-700 [&>div>div>a]:text-gray-1000',
success: 'border-blue-400 text-blue-900 selection:bg-blue-700 [&>div>div>a]:text-blue-1000',
error: 'border-red-400 text-red-900 selection:bg-red-700 [&>div>div>a]:text-red-1000',
warning:
'border-amber-400 text-amber-900 selection:bg-amber-700 [&>div>div>a]:text-amber-1000',
violet:
'border-purple-400 text-purple-900 selection:bg-purple-700 [&>div>div>a]:text-purple-1000',
cyan: 'border-teal-400 text-teal-900 selection:bg-teal-700 [&>div>div>a]:text-teal-1000'
},
size: {
sm: 'min-h-[34px] px-2 py-1.5 text-[13px] leading-6',
md: 'min-h-10 px-3 py-2 text-[14px] leading-6',
lg: 'min-h-12 px-3 py-[11px] text-base'
},
fill: { true: true, false: false }
},
compoundVariants: [
{ variant: 'secondary', fill: true, class: 'bg-gray-200' },
{ variant: 'success', fill: true, class: 'bg-blue-200' },
{ variant: 'error', fill: true, class: 'bg-red-200' },
{ variant: 'warning', fill: true, class: 'bg-amber-200' },
{ variant: 'violet', fill: true, class: 'bg-purple-200' },
{ variant: 'cyan', fill: true, class: 'bg-teal-200' }
],
defaultVariants: {
variant: 'secondary',
size: 'md',
fill: false
}
});

type Variant = VariantProps<typeof note_variants>['variant'];
type Size = VariantProps<typeof note_variants>['size'];
type Fill = VariantProps<typeof note_variants>['fill'];

export type Props = {
variant?: Variant;
size?: Size;
fill?: Fill;
disabled?: boolean;
label?: string | boolean;
};
43 changes: 43 additions & 0 deletions src/lib/components/ui/note/note.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<script lang="ts">
import { Icons } from '$lib/assets/icons/index.js';
import { cn } from '$lib/utils.js';
import { type Props, note_variants } from './index.js';

type $$Props = Props;

let class_name: string | undefined | null = undefined;
export let variant: $$Props['variant'] = 'secondary';
export let size: $$Props['size'] = 'md';
export let fill: $$Props['fill'] = false;
export let disabled: $$Props['disabled'] = false;
export let label: $$Props['label'] = undefined;
export { class_name as class };
</script>

<div
data-disabled={disabled}
class={cn(note_variants({ variant, size, className: class_name, fill }))}
{...$$restProps}
>
<div class="flex items-center gap-2">
{#if label}
<span class="font-semibold">{label}:</span>
{:else if label !== false}
<span class="h-4">
{#if variant === 'secondary' || variant === 'violet' || variant === 'cyan'}
<Icons.Information aria-hidden="true" class="size-4" />
{:else if variant === 'success'}
<Icons.CheckCircle aria-hidden="true" class="size-4" />
{:else if variant === 'error'}
<Icons.Stop aria-hidden="true" class="size-4" />
{:else if variant === 'warning'}
<Icons.Warning aria-hidden="true" class="size-4" />
{/if}
</span>
{/if}
<div>
<slot />
</div>
</div>
<slot name="action" {disabled}></slot>
</div>
2 changes: 1 addition & 1 deletion src/lib/config/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const aside_items: Aside = {
{
title: 'Note',
href: '/note',
status: 'soon'
status: 'draft'
},
{
title: 'Pagination',
Expand Down
69 changes: 68 additions & 1 deletion src/routes/note/+page.svelte
Original file line number Diff line number Diff line change
@@ -1 +1,68 @@
<h1>note</h1>
<script lang="ts">
import Demo from '$lib/components/shared/demo.svelte';
import PageWrapper from '$lib/components/shared/page-wrapper.svelte';
import Action from './action.svelte';
import action_code from './action.svelte?raw';
import Cyan from './cyan.svelte';
import cyan_code from './cyan.svelte?raw';
import Default from './default.svelte';
import default_code from './default.svelte?raw';
import Disabled from './disabled.svelte';
import disabled_code from './disabled.svelte?raw';
import Error from './error.svelte';
import error_code from './error.svelte?raw';
import Labels from './labels.svelte';
import labels_code from './labels.svelte?raw';
import Secondary from './secondary.svelte';
import secondary_code from './secondary.svelte?raw';
import Success from './success.svelte';
import success_code from './success.svelte?raw';
import Violet from './violet.svelte';
import violet_code from './violet.svelte?raw';
import Warning from './warning.svelte';
import warning_code from './warning.svelte?raw';

export let data;
</script>

<PageWrapper title={data.title} description={data.description}>
<Demo id="default" code={default_code}>
<Default />
</Demo>

<Demo id="action" code={action_code}>
<Action />
</Demo>

<Demo id="success" code={success_code}>
<Success />
</Demo>

<Demo id="error" code={error_code}>
<Error />
</Demo>

<Demo id="warning" code={warning_code}>
<Warning />
</Demo>

<Demo id="secondary" code={secondary_code}>
<Secondary />
</Demo>

<Demo id="violet" code={violet_code}>
<Violet />
</Demo>

<Demo id="cyan" code={cyan_code}>
<Cyan />
</Demo>

<Demo id="disabled" code={disabled_code}>
<Disabled />
</Demo>

<Demo id="labels" code={labels_code}>
<Labels />
</Demo>
</PageWrapper>
21 changes: 21 additions & 0 deletions src/routes/note/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { MetaTagsProps } from 'svelte-meta-tags';

export function load() {
const title = 'Note';
const description = 'Display text that requires attention or provides additional information.';

const pageMetaTags = Object.freeze({
title,
description,
openGraph: {
title,
description
}
}) satisfies MetaTagsProps;

return {
pageMetaTags,
title,
description
};
}
16 changes: 16 additions & 0 deletions src/routes/note/action.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script lang="ts">
import { Button } from '$lib/components/ui/button';
import { Note } from '$lib/components/ui/note';
</script>

<div class="grid place-items-start gap-6">
<Note>
This note details some information.
<Button slot="action" size="sm">Upgrade</Button>
</Note>
<Note>
This note details a large amount information that could potentially wrap into two or more lines,
forcing the height of the Note to be larger.
<Button slot="action" size="sm">Upgrade</Button>
</Note>
</div>
28 changes: 28 additions & 0 deletions src/routes/note/cyan.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script lang="ts">
import { Button } from '$lib/components/ui/button';
import { Link } from '$lib/components/ui/link';
import { Note } from '$lib/components/ui/note';
</script>

<div class="grid gap-6">
<Note variant="cyan">This note details some cyan information.</Note>
<Note variant="cyan">
This note details some cyan information.
<Button slot="action" size="sm">Upgrade</Button>
</Note>
<Note variant="cyan">
This note details some cyan information. Check <Link href="/#">the documentation</Link> to learn
more.
<Button slot="action" size="sm">Upgrade</Button>
</Note>
<Note fill variant="cyan">This filled note details some cyan information.</Note>
<Note fill variant="cyan">
This filled note details some cyan information.
<Button slot="action" size="sm">Upgrade</Button>
</Note>
<Note fill variant="cyan">
This filled note details some cyan information. Check
<Link href="/#">the documentation</Link> to learn more.
<Button slot="action" size="sm">Upgrade</Button>
</Note>
</div>
9 changes: 9 additions & 0 deletions src/routes/note/default.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script lang="ts">
import { Note } from '$lib/components/ui/note';
</script>

<div class="flex items-start gap-6">
<Note size="sm">A small note.</Note>
<Note>A default note.</Note>
<Note size="lg">A large note.</Note>
</div>
17 changes: 17 additions & 0 deletions src/routes/note/disabled.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script lang="ts">
import { Button } from '$lib/components/ui/button';
import { Link } from '$lib/components/ui/link';
import { Note } from '$lib/components/ui/note';
</script>

<div class="grid gap-6">
<Note disabled fill variant="warning">
This note details a warning.
<Button slot="action" size="sm" let:disabled {disabled}>Upgrade</Button>
</Note>
<Note disabled fill variant="warning">
This filled note details some success information. Check
<Link href="/#">the documentation</Link> to learn more.
<Button slot="action" size="sm" let:disabled {disabled}>Upgrade</Button>
</Note>
</div>
28 changes: 28 additions & 0 deletions src/routes/note/error.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script lang="ts">
import { Button } from '$lib/components/ui/button';
import { Link } from '$lib/components/ui/link';
import { Note } from '$lib/components/ui/note';
</script>

<div class="grid gap-6">
<Note variant="error">This note details some error information.</Note>
<Note variant="error">
This note details some error information.
<Button slot="action" size="sm">Upgrade</Button>
</Note>
<Note variant="error">
This note details some error information. Check <Link href="/#">the documentation</Link> to learn
more.
<Button slot="action" size="sm">Upgrade</Button>
</Note>
<Note fill variant="error">This filled note details some error information.</Note>
<Note fill variant="error">
This filled note details some error information.
<Button slot="action" size="sm">Upgrade</Button>
</Note>
<Note fill variant="error">
This filled note details some error information. Check
<Link href="/#">the documentation</Link> to learn more.
<Button slot="action" size="sm">Upgrade</Button>
</Note>
</div>
Loading