Skip to content

Commit 70c76be

Browse files
authored
feat: add Button.Nav (#77)
* feat: add Button.Nav * chore: format * chore: sort imports * update: remove unused snippet and add missing props * feat: stick to fragment definition * update: documentation * fix: stories * chore: sort imports
1 parent dddf491 commit 70c76be

File tree

8 files changed

+108
-27
lines changed

8 files changed

+108
-27
lines changed

infrastructure/eid-wallet/src/lib/fragments/SettingsNavigationBtn/SettingsNavigationBtn.stories.snippet.svelte

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
import type { Snippet } from "svelte";
2-
import { icon } from "./SettingsNavigationBtn.stories.snippet.svelte";
1+
import { LanguageSquareIcon } from "@hugeicons/core-free-icons";
2+
import type { ComponentProps } from "svelte";
33
import SettingsNavigationBtn from "./SettingsNavigationBtn.svelte";
44

55
export default {
66
title: "Fragments/SettingsNavigationBtn",
77
component: SettingsNavigationBtn,
88
tags: ["autodocs"],
9-
render: (args: { icon: Snippet; label: string; onClick: () => void }) => ({
9+
render: (args: {
10+
Component: SettingsNavigationBtn;
11+
props: ComponentProps<typeof SettingsNavigationBtn>;
12+
}) => ({
1013
Component: SettingsNavigationBtn,
1114
props: args,
1215
}),
1316
};
1417

1518
export const Primary = {
1619
args: {
17-
icon: icon,
20+
icon: LanguageSquareIcon,
1821
label: "Language",
19-
onClick: () => alert("asdf"),
22+
href: "#",
2023
},
2124
};
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
<script lang="ts">
2+
import * as Button from "$lib/ui/Button";
23
import { cn } from "$lib/utils";
34
import { ArrowRight01Icon } from "@hugeicons/core-free-icons";
4-
import { HugeiconsIcon } from "@hugeicons/svelte";
5-
import type { Snippet } from "svelte";
5+
import { HugeiconsIcon, type IconSvgElement } from "@hugeicons/svelte";
66
import type { HTMLAttributes } from "svelte/elements";
77
88
interface ISettingsNavigationBtn extends HTMLAttributes<HTMLElement> {
9-
icon: Snippet;
9+
icon: IconSvgElement;
1010
label: string;
11-
onClick: () => void;
11+
href: string;
1212
}
1313
14-
let { icon, label, onClick, ...restProps }: ISettingsNavigationBtn = $props();
14+
const { icon, label, href, ...restProps }: ISettingsNavigationBtn = $props();
1515
</script>
1616

17-
<div {...restProps} class={cn('flex items-center justify-between px-3 py-2', restProps.class)} onclick={onClick}>
17+
<Button.Nav {href} {...restProps} class={cn('flex items-center justify-between px-3 py-2', restProps.class)}>
1818
<div class="flex items-center gap-2">
19-
<div class="p-3 bg-gray max-w-max rounded-4xl object-cover flex items-center" >
20-
{@render icon?.()}
19+
<div class="p-3 bg-gray max-w-max rounded-full object-cover flex items-center" >
20+
<HugeiconsIcon {icon} size={30} color="var(--color-black-500)" />
2121
</div>
2222
<p class="font-medium!">{label}</p>
2323
</div>
2424
<HugeiconsIcon size={30} color="var(--color-black-500)" icon={ArrowRight01Icon} />
25-
</div>
25+
</Button.Nav>
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
<script context="module">
2-
export { ButtonText };
2+
import { ArrowRight01Icon, SettingsIcon } from "@hugeicons/core-free-icons";
3+
import { HugeiconsIcon } from "@hugeicons/svelte";
4+
5+
export { ButtonText, ButtonNavText, ButtonNavSettings };
36
</script>
47

58
{#snippet ButtonText()}
69
Button
710
{/snippet}
11+
12+
{#snippet ButtonNavText()}
13+
Nav Button
14+
{/snippet}
15+
16+
{#snippet ButtonNavSettings()}
17+
<div class="flex items-center gap-2">
18+
<div class="p-3 bg-gray max-w-max rounded-full object-cover flex items-center" >
19+
<HugeiconsIcon icon={SettingsIcon} size={30} color="var(--color-black-500)" />
20+
</div>
21+
<h1>Settings</h1>
22+
</div>
23+
<HugeiconsIcon size={30} color="var(--color-black-500)" icon={ArrowRight01Icon} />
24+
{/snippet}

infrastructure/eid-wallet/src/lib/ui/Button/ButtonIcon.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ const {
2727
icon,
2828
iconSize = undefined,
2929
isActive = false,
30-
children = undefined,
3130
...restProps
3231
}: IButtonProps = $props();
3332
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { ComponentProps } from "svelte";
2+
import {
3+
ButtonNavSettings,
4+
ButtonNavText,
5+
} from "./Button.stories.snippet.svelte";
6+
import ButtonNav from "./ButtonNav.svelte";
7+
8+
export default {
9+
title: "UI/ButtonNav",
10+
component: ButtonNav,
11+
tags: ["autodocs"],
12+
render: (args: {
13+
Component: ButtonNav;
14+
props: ComponentProps<typeof ButtonNav>;
15+
}) => ({
16+
Component: ButtonNav,
17+
props: args,
18+
}),
19+
};
20+
21+
export const Default = {
22+
args: { href: "#", children: ButtonNavText },
23+
};
24+
25+
export const ForSettings = {
26+
args: {
27+
href: "#",
28+
children: ButtonNavSettings,
29+
class: "flex items-center justify-between px-3 py-2",
30+
},
31+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<script lang="ts">
2+
import { cn } from "$lib/utils";
3+
import type { Snippet } from "svelte";
4+
import type { HTMLAnchorAttributes } from "svelte/elements";
5+
6+
interface IButtonNav extends HTMLAnchorAttributes {
7+
href: string;
8+
children: Snippet;
9+
}
10+
11+
const { href, children, ...restProps }: IButtonNav = $props();
12+
</script>
13+
14+
<a {href} {...restProps} class={cn(restProps.class)}>
15+
{@render children()}
16+
</a>
17+
18+
<!--
19+
@component
20+
export default ButtonNav;
21+
@description
22+
This component is a wrapper for a button that navigates to a different page.
23+
24+
@props
25+
- href: The URL of the page to navigate to.
26+
- children: The content of the button.
27+
- ...restProps: Any other props that can be passed to an anchor element.
28+
29+
@usage
30+
```html
31+
<script lang="ts">
32+
import * as Button from '$lib/ui/Button'
33+
import { SettingsIcon, ArrowRight01Icon } from "@hugeicons/core-free-icons";
34+
</script>
35+
36+
<Button.Nav href="/settings">
37+
// The content of the button
38+
</Button.Nav>
39+
```
40+
-->
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Action from "./ButtonAction.svelte";
22
import Icon from "./ButtonIcon.svelte";
3+
import Nav from "./ButtonNav.svelte";
34

4-
export { Action, Icon };
5+
export { Action, Icon, Nav };

0 commit comments

Comments
 (0)