@abydahana/aksara-ui 1.0.1 → 1.1.1

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.
@@ -0,0 +1,81 @@
1
+ export interface SidebarNavItemProps {
2
+ /** Unique ID (used for tab panel targeting) */
3
+ id?: string;
4
+ /** Label text */
5
+ label: string;
6
+ /** Icon HTML string */
7
+ icon?: string;
8
+ /** Badge text or count */
9
+ badge?: string;
10
+ /** Active state */
11
+ active?: boolean;
12
+ /** Disabled state */
13
+ disabled?: boolean;
14
+ /** Link mode: render as <a href="..."> */
15
+ href?: string;
16
+ /** Tab mode: render as <button data-tabs="#panelId"> */
17
+ panelTarget?: string;
18
+ className?: string;
19
+ attributes?: Record<string, unknown>;
20
+ }
21
+ export interface SidebarNavProps {
22
+ items: SidebarNavItemProps[];
23
+ /** Brand section title at the top */
24
+ title?: string;
25
+ /** Brand section subtitle */
26
+ subtitle?: string;
27
+ /** Brand icon HTML */
28
+ brandIcon?: string;
29
+ className?: string;
30
+ attributes?: Record<string, unknown>;
31
+ }
32
+ /**
33
+ * Sidebar navigation that supports two modes:
34
+ *
35
+ * - **Tab mode** (`panelTarget` prop): renders `<button data-tabs="#panelId">` —
36
+ * integrates with Aksara's tab JS to show/hide content panels.
37
+ * - **Link mode** (`href` prop): renders `<a href="...">` — plain navigation links.
38
+ *
39
+ * @example Tab mode
40
+ * SidebarNav({
41
+ * title: "Settings",
42
+ * items: [
43
+ * { label: "Privacy", icon: '<span class="mdi mdi-lock-outline">', panelTarget: "#panel-privacy", active: true },
44
+ * { label: "Notifications", icon: '<span class="mdi mdi-bell-outline">', panelTarget: "#panel-notif" },
45
+ * ]
46
+ * })
47
+ *
48
+ * @example Link mode
49
+ * SidebarNav({
50
+ * items: [
51
+ * { label: "Dashboard", icon: '<span class="mdi mdi-home-outline">', href: "/dashboard", active: true },
52
+ * { label: "Settings", icon: '<span class="mdi mdi-cog-outline">', href: "/settings" },
53
+ * ]
54
+ * })
55
+ */
56
+ export declare function SidebarNav(props: SidebarNavProps): string;
57
+ export declare const sidebarNav: typeof SidebarNav;
58
+ export interface SidebarNavHeaderProps {
59
+ label: string;
60
+ className?: string;
61
+ }
62
+ /** A group header label inside a SidebarNav */
63
+ export declare function SidebarNavHeader(props: SidebarNavHeaderProps): string;
64
+ export declare const sidebarNavHeader: typeof SidebarNavHeader;
65
+ export interface SidebarLayoutProps {
66
+ sidebar: string;
67
+ content: string;
68
+ className?: string;
69
+ attributes?: Record<string, unknown>;
70
+ }
71
+ /**
72
+ * Two-column layout wrapper: sidebar pane on the left, content area on the right.
73
+ *
74
+ * @example
75
+ * SidebarLayout({
76
+ * sidebar: SidebarNav({ ... }),
77
+ * content: '<div class="p-5">Panel content here</div>'
78
+ * })
79
+ */
80
+ export declare function SidebarLayout(props: SidebarLayoutProps): string;
81
+ export declare const sidebarLayout: typeof SidebarLayout;
@@ -0,0 +1,82 @@
1
+ import { classNames, escapeHtml, toAttributes } from "../utils";
2
+ /**
3
+ * Sidebar navigation that supports two modes:
4
+ *
5
+ * - **Tab mode** (`panelTarget` prop): renders `<button data-tabs="#panelId">` —
6
+ * integrates with Aksara's tab JS to show/hide content panels.
7
+ * - **Link mode** (`href` prop): renders `<a href="...">` — plain navigation links.
8
+ *
9
+ * @example Tab mode
10
+ * SidebarNav({
11
+ * title: "Settings",
12
+ * items: [
13
+ * { label: "Privacy", icon: '<span class="mdi mdi-lock-outline">', panelTarget: "#panel-privacy", active: true },
14
+ * { label: "Notifications", icon: '<span class="mdi mdi-bell-outline">', panelTarget: "#panel-notif" },
15
+ * ]
16
+ * })
17
+ *
18
+ * @example Link mode
19
+ * SidebarNav({
20
+ * items: [
21
+ * { label: "Dashboard", icon: '<span class="mdi mdi-home-outline">', href: "/dashboard", active: true },
22
+ * { label: "Settings", icon: '<span class="mdi mdi-cog-outline">', href: "/settings" },
23
+ * ]
24
+ * })
25
+ */
26
+ export function SidebarNav(props) {
27
+ const { items = [], title = "", subtitle = "", brandIcon = "", className = "", attributes } = props;
28
+ const baseAttrs = toAttributes(attributes);
29
+ // Brand section
30
+ const brandHtml = title
31
+ ? `<div class="sidebar-nav-brand">${brandIcon ? `<span class="sidebar-nav-icon">${brandIcon}</span>` : ""}<div><span class="sidebar-nav-brand-title">${escapeHtml(title)}</span>${subtitle ? `<span class="sidebar-nav-brand-subtitle">${escapeHtml(subtitle)}</span>` : ""}</div></div>`
32
+ : "";
33
+ // Items
34
+ const itemsHtml = items
35
+ .map((item) => {
36
+ const isLink = Boolean(item.href);
37
+ const isTab = Boolean(item.panelTarget) && !isLink;
38
+ const Tag = isLink ? "a" : "button";
39
+ const itemClasses = classNames("sidebar-nav-item", item.active && "active", item.disabled && "disabled", item.className);
40
+ const itemAttrs = toAttributes({
41
+ href: isLink ? item.href : undefined,
42
+ type: !isLink ? "button" : undefined,
43
+ "data-tabs": isTab ? item.panelTarget : undefined,
44
+ role: isTab ? "tab" : undefined,
45
+ "aria-selected": isTab ? (item.active ? "true" : "false") : undefined,
46
+ tabindex: isTab ? (item.active ? "0" : "-1") : undefined,
47
+ id: isTab && item.id ? `sidebar-tab-${item.id}` : item.id,
48
+ "aria-controls": isTab && item.id ? item.id : undefined,
49
+ disabled: !isLink && item.disabled ? true : undefined,
50
+ "aria-disabled": item.disabled ? "true" : undefined,
51
+ "aria-current": isLink && item.active ? "page" : undefined,
52
+ ...item.attributes
53
+ });
54
+ const iconHtml = item.icon ? `<span class="sidebar-nav-icon" aria-hidden="true">${item.icon}</span>` : "";
55
+ const badgeHtml = item.badge ? `<span class="sidebar-nav-badge">${escapeHtml(item.badge)}</span>` : "";
56
+ return `<${Tag} class="${itemClasses}"${itemAttrs}>${iconHtml}<span class="sidebar-nav-label">${escapeHtml(item.label)}</span>${badgeHtml}</${Tag}>`;
57
+ })
58
+ .join("");
59
+ return `<nav class="${classNames("sidebar-nav", className)}"${baseAttrs}>${brandHtml}${itemsHtml}</nav>`.trim();
60
+ }
61
+ export const sidebarNav = SidebarNav;
62
+ /** A group header label inside a SidebarNav */
63
+ export function SidebarNavHeader(props) {
64
+ const { label, className = "" } = props;
65
+ return `<span class="${classNames("sidebar-nav-header", className)}">${escapeHtml(label)}</span>`;
66
+ }
67
+ export const sidebarNavHeader = SidebarNavHeader;
68
+ /**
69
+ * Two-column layout wrapper: sidebar pane on the left, content area on the right.
70
+ *
71
+ * @example
72
+ * SidebarLayout({
73
+ * sidebar: SidebarNav({ ... }),
74
+ * content: '<div class="p-5">Panel content here</div>'
75
+ * })
76
+ */
77
+ export function SidebarLayout(props) {
78
+ const { sidebar, content, className = "", attributes } = props;
79
+ const baseAttrs = toAttributes(attributes);
80
+ return `<div class="${classNames("sidebar-layout", className)}"${baseAttrs}><div class="sidebar-pane">${sidebar}</div><div class="sidebar-content">${content}</div></div>`.trim();
81
+ }
82
+ export const sidebarLayout = SidebarLayout;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abydahana/aksara-ui",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -73,13 +73,16 @@
73
73
  "LICENSE"
74
74
  ],
75
75
  "scripts": {
76
+ "dev": "node --import tsx src/generator/dev.ts",
76
77
  "build": "node --import tsx src/generator/build.ts",
77
78
  "test": "node --import tsx src/tests/run.ts",
78
79
  "check": "tsc --noEmit",
79
- "lint": "eslint src eslint.config.js",
80
- "lint:fix": "eslint src eslint.config.js --fix",
81
- "format": "prettier --write . && eslint src eslint.config.js --fix",
82
- "format:check": "prettier --check . && eslint src eslint.config.js",
80
+ "lint": "eslint src eslint.config.ts",
81
+ "lint:fix": "eslint src eslint.config.ts --fix",
82
+ "format": "prettier --write . && eslint src eslint.config.ts --fix",
83
+ "format:check": "prettier --check . && eslint src eslint.config.ts",
84
+ "validate": "npm run check && npm run format:check && npm run test && npm run build",
85
+ "setup:hooks": "git config core.hooksPath .githooks && chmod +x .githooks/pre-commit",
83
86
  "prepare": "npm run build",
84
87
  "all": "npm run format && npm run lint && npm run test && npm run build",
85
88
  "prepublishOnly": "npm run all"
@@ -102,6 +105,7 @@
102
105
  "eslint": "^10.9.1",
103
106
  "eslint-config-prettier": "^10.1.8",
104
107
  "eslint-plugin-unicorn": "^65.0.1",
108
+ "jiti": "^2.7.0",
105
109
  "prettier": "^3.9.6",
106
110
  "tsx": "^4.19.3",
107
111
  "typescript": "^5.9.3",