@dorsk/tsumikit 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/layouts/NavItem.svelte +67 -8
- package/dist/components/layouts/NavItem.svelte.d.ts +6 -0
- package/dist/components/layouts/NavSection.svelte +71 -0
- package/dist/components/layouts/NavSection.svelte.d.ts +11 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
// Sidebar navigation item: icon + label
|
|
3
|
-
//
|
|
4
|
-
// resizable sidebar down to a rail)
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
2
|
+
// Sidebar navigation item: icon + label, with an optional trailing count
|
|
3
|
+
// `badge`. When the surrounding `sidebar` query container gets narrow
|
|
4
|
+
// (≤ 8rem — e.g. the user drags AppShell's resizable sidebar down to a rail)
|
|
5
|
+
// the label hides and the icon centers, purely in CSS; a non-empty badge then
|
|
6
|
+
// collapses to a small dot indicator so the count cue survives the rail.
|
|
7
|
+
// `title`/`aria-label` carry the name so the icon-only state stays accessible
|
|
8
|
+
// and shows a tooltip. Renders an <a> when `href` is set, else a <button>.
|
|
8
9
|
import type { Snippet } from 'svelte';
|
|
9
10
|
import Icon from '../atoms/Icon.svelte';
|
|
10
11
|
import type { IconName } from '../atoms/Icon.svelte';
|
|
12
|
+
import Badge from '../atoms/Badge.svelte';
|
|
13
|
+
|
|
14
|
+
type BadgeTone = 'neutral' | 'ok' | 'warn' | 'danger' | 'info';
|
|
11
15
|
|
|
12
16
|
let {
|
|
13
17
|
icon,
|
|
@@ -15,6 +19,8 @@
|
|
|
15
19
|
href,
|
|
16
20
|
active = false,
|
|
17
21
|
onclick,
|
|
22
|
+
badge,
|
|
23
|
+
badgeTone = 'neutral',
|
|
18
24
|
children,
|
|
19
25
|
...rest
|
|
20
26
|
}: {
|
|
@@ -23,9 +29,17 @@
|
|
|
23
29
|
href?: string;
|
|
24
30
|
active?: boolean;
|
|
25
31
|
onclick?: (e: MouseEvent) => void;
|
|
32
|
+
/** Optional trailing count pill (e.g. unread / missing items). When the
|
|
33
|
+
* item is `active` it adopts the accent fill; otherwise it uses `badgeTone`. */
|
|
34
|
+
badge?: string | number;
|
|
35
|
+
/** Tone for the trailing badge when the item is not active. */
|
|
36
|
+
badgeTone?: BadgeTone;
|
|
26
37
|
children?: Snippet;
|
|
27
38
|
[key: string]: unknown;
|
|
28
39
|
} = $props();
|
|
40
|
+
|
|
41
|
+
// Treat 0 / '' as "no badge" so callers can pass a raw count without guarding.
|
|
42
|
+
const hasBadge = $derived(badge !== undefined && badge !== null && badge !== '' && badge !== 0);
|
|
29
43
|
</script>
|
|
30
44
|
|
|
31
45
|
<svelte:element
|
|
@@ -42,11 +56,21 @@
|
|
|
42
56
|
>
|
|
43
57
|
<Icon name={icon} size={18} />
|
|
44
58
|
<span class="nav-label">{label}</span>
|
|
45
|
-
{#if
|
|
59
|
+
{#if hasBadge}
|
|
60
|
+
<span class="nav-trail">
|
|
61
|
+
<Badge size="sm" tone={active ? 'neutral' : badgeTone} active={active}>{badge}</Badge>
|
|
62
|
+
</span>
|
|
63
|
+
<!-- Rail fallback: the pill is hidden by the container query below, this dot
|
|
64
|
+
takes over so the "has items" cue still reads in the icon rail. -->
|
|
65
|
+
<span class="nav-dot" class:active aria-hidden="true"></span>
|
|
66
|
+
{:else if children}
|
|
67
|
+
<span class="nav-trail">{@render children()}</span>
|
|
68
|
+
{/if}
|
|
46
69
|
</svelte:element>
|
|
47
70
|
|
|
48
71
|
<style>
|
|
49
72
|
.nav-item {
|
|
73
|
+
position: relative;
|
|
50
74
|
display: flex;
|
|
51
75
|
align-items: center;
|
|
52
76
|
gap: var(--sp-2);
|
|
@@ -74,14 +98,36 @@
|
|
|
74
98
|
background: color-mix(in srgb, var(--accent) 14%, transparent);
|
|
75
99
|
color: var(--accent);
|
|
76
100
|
}
|
|
101
|
+
/* Active-route accent inset: a left rail marker that survives the icon-rail
|
|
102
|
+
collapse (the tint background does too, but the marker reads at a glance). */
|
|
103
|
+
.nav-item.active::before {
|
|
104
|
+
content: '';
|
|
105
|
+
position: absolute;
|
|
106
|
+
left: 0;
|
|
107
|
+
top: 50%;
|
|
108
|
+
transform: translateY(-50%);
|
|
109
|
+
width: 3px;
|
|
110
|
+
height: 60%;
|
|
111
|
+
border-radius: var(--r-pill);
|
|
112
|
+
background: var(--accent);
|
|
113
|
+
}
|
|
77
114
|
.nav-label {
|
|
78
115
|
flex: 1;
|
|
79
116
|
min-width: 0; /* allow the label to shrink/ellipsis instead of overflowing */
|
|
80
117
|
overflow: hidden;
|
|
81
118
|
text-overflow: ellipsis;
|
|
82
119
|
}
|
|
120
|
+
.nav-trail {
|
|
121
|
+
flex: none;
|
|
122
|
+
}
|
|
123
|
+
/* Dot is the rail-width stand-in for the badge: hidden at full width. */
|
|
124
|
+
.nav-dot {
|
|
125
|
+
display: none;
|
|
126
|
+
}
|
|
127
|
+
|
|
83
128
|
/* Icon-rail: when the sidebar container is narrow, drop the label + trailing
|
|
84
|
-
|
|
129
|
+
pill and center the icon. Driven by the sidebar's width, not the viewport.
|
|
130
|
+
A badge collapses to a dot pinned to the icon's top-right corner. */
|
|
85
131
|
@container sidebar (max-width: 8rem) {
|
|
86
132
|
.nav-item {
|
|
87
133
|
justify-content: center;
|
|
@@ -91,5 +137,18 @@
|
|
|
91
137
|
.nav-trail {
|
|
92
138
|
display: none;
|
|
93
139
|
}
|
|
140
|
+
.nav-dot {
|
|
141
|
+
display: block;
|
|
142
|
+
position: absolute;
|
|
143
|
+
top: 0.4rem;
|
|
144
|
+
right: 0.9rem;
|
|
145
|
+
width: 6px;
|
|
146
|
+
height: 6px;
|
|
147
|
+
border-radius: 50%;
|
|
148
|
+
background: var(--warn);
|
|
149
|
+
}
|
|
150
|
+
.nav-dot.active {
|
|
151
|
+
background: var(--accent);
|
|
152
|
+
}
|
|
94
153
|
}
|
|
95
154
|
</style>
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { IconName } from '../atoms/Icon.svelte';
|
|
3
|
+
type BadgeTone = 'neutral' | 'ok' | 'warn' | 'danger' | 'info';
|
|
3
4
|
type $$ComponentProps = {
|
|
4
5
|
icon: IconName;
|
|
5
6
|
label: string;
|
|
6
7
|
href?: string;
|
|
7
8
|
active?: boolean;
|
|
8
9
|
onclick?: (e: MouseEvent) => void;
|
|
10
|
+
/** Optional trailing count pill (e.g. unread / missing items). When the
|
|
11
|
+
* item is `active` it adopts the accent fill; otherwise it uses `badgeTone`. */
|
|
12
|
+
badge?: string | number;
|
|
13
|
+
/** Tone for the trailing badge when the item is not active. */
|
|
14
|
+
badgeTone?: BadgeTone;
|
|
9
15
|
children?: Snippet;
|
|
10
16
|
[key: string]: unknown;
|
|
11
17
|
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// A grouped block of sidebar nav items: an optional uppercase mono section
|
|
3
|
+
// `label` (eyebrow) plus consistent tight spacing between the NavItems passed
|
|
4
|
+
// as children. Saves consumers from re-implementing the label + gap inline for
|
|
5
|
+
// every group. At icon-rail width (sidebar container ≤ 8rem) the label hides
|
|
6
|
+
// and the group spacing tightens so the rail stays compact; a thin top divider
|
|
7
|
+
// then stands in for the dropped label to keep the groups visually separated.
|
|
8
|
+
import type { Snippet } from 'svelte';
|
|
9
|
+
|
|
10
|
+
let {
|
|
11
|
+
label,
|
|
12
|
+
children,
|
|
13
|
+
...rest
|
|
14
|
+
}: {
|
|
15
|
+
/** Optional section heading; rendered uppercase + mono. Omit for an
|
|
16
|
+
* unlabeled group (still gets the group spacing + rail divider). */
|
|
17
|
+
label?: string;
|
|
18
|
+
children?: Snippet;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
} = $props();
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<div class="nav-section" {...rest}>
|
|
24
|
+
{#if label}
|
|
25
|
+
<div class="nav-section-label">{label}</div>
|
|
26
|
+
{/if}
|
|
27
|
+
<div class="nav-section-items">
|
|
28
|
+
{@render children?.()}
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
<style>
|
|
33
|
+
.nav-section {
|
|
34
|
+
display: flex;
|
|
35
|
+
flex-direction: column;
|
|
36
|
+
gap: var(--sp-1);
|
|
37
|
+
}
|
|
38
|
+
/* Groups separate themselves with breathing room; the first one sits flush. */
|
|
39
|
+
.nav-section + :global(.nav-section),
|
|
40
|
+
.nav-section:not(:first-child) {
|
|
41
|
+
margin-top: var(--sp-3);
|
|
42
|
+
}
|
|
43
|
+
.nav-section-label {
|
|
44
|
+
padding: 0 var(--sp-3);
|
|
45
|
+
margin-bottom: var(--sp-1);
|
|
46
|
+
color: var(--text-faint);
|
|
47
|
+
font-family: var(--font-mono);
|
|
48
|
+
font-size: var(--fs-xs);
|
|
49
|
+
font-weight: var(--fw-semibold);
|
|
50
|
+
text-transform: uppercase;
|
|
51
|
+
letter-spacing: 0.06em;
|
|
52
|
+
}
|
|
53
|
+
.nav-section-items {
|
|
54
|
+
display: flex;
|
|
55
|
+
flex-direction: column;
|
|
56
|
+
gap: 2px;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* Icon-rail: drop the textual label and use a hairline divider to keep groups
|
|
60
|
+
distinct when the sidebar collapses to a rail. */
|
|
61
|
+
@container sidebar (max-width: 8rem) {
|
|
62
|
+
.nav-section-label {
|
|
63
|
+
display: none;
|
|
64
|
+
}
|
|
65
|
+
.nav-section:not(:first-child) {
|
|
66
|
+
margin-top: var(--sp-2);
|
|
67
|
+
padding-top: var(--sp-2);
|
|
68
|
+
border-top: 1px solid var(--border);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
/** Optional section heading; rendered uppercase + mono. Omit for an
|
|
4
|
+
* unlabeled group (still gets the group spacing + rail divider). */
|
|
5
|
+
label?: string;
|
|
6
|
+
children?: Snippet;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
};
|
|
9
|
+
declare const NavSection: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
10
|
+
type NavSection = ReturnType<typeof NavSection>;
|
|
11
|
+
export default NavSection;
|
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export { default as AutoGrid } from './components/layouts/AutoGrid.svelte';
|
|
|
21
21
|
export { default as Cluster } from './components/layouts/Cluster.svelte';
|
|
22
22
|
export { default as Container } from './components/layouts/Container.svelte';
|
|
23
23
|
export { default as NavItem } from './components/layouts/NavItem.svelte';
|
|
24
|
+
export { default as NavSection } from './components/layouts/NavSection.svelte';
|
|
24
25
|
export { default as Stack } from './components/layouts/Stack.svelte';
|
|
25
26
|
export { type AccordionItem, default as Accordion, } from './components/molecules/Accordion.svelte';
|
|
26
27
|
export { default as CodeBlock } from './components/molecules/CodeBlock.svelte';
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,7 @@ export { default as AutoGrid } from './components/layouts/AutoGrid.svelte';
|
|
|
28
28
|
export { default as Cluster } from './components/layouts/Cluster.svelte';
|
|
29
29
|
export { default as Container } from './components/layouts/Container.svelte';
|
|
30
30
|
export { default as NavItem } from './components/layouts/NavItem.svelte';
|
|
31
|
+
export { default as NavSection } from './components/layouts/NavSection.svelte';
|
|
31
32
|
export { default as Stack } from './components/layouts/Stack.svelte';
|
|
32
33
|
export { default as Accordion, } from './components/molecules/Accordion.svelte';
|
|
33
34
|
export { default as CodeBlock } from './components/molecules/CodeBlock.svelte';
|
package/package.json
CHANGED