@nexus_js/ui 0.6.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/LICENSE +21 -0
- package/README.md +17 -0
- package/package.json +44 -0
- package/src/components/accordion.ts +22 -0
- package/src/components/modal.ts +26 -0
- package/src/components/progress-ring.ts +29 -0
- package/src/components/tabs.ts +30 -0
- package/src/components/tooltip.ts +14 -0
- package/src/index.ts +132 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nexus Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @nexus_js/ui
|
|
2
|
+
|
|
3
|
+
Nexus Zero-Bundle UI — CSS-only interactive components with 0.0KB of JavaScript.
|
|
4
|
+
|
|
5
|
+
## Documentation
|
|
6
|
+
|
|
7
|
+
All guides, API reference, and examples live on **[nexusjs.dev](https://nexusjs.dev)**.
|
|
8
|
+
|
|
9
|
+
## Links
|
|
10
|
+
|
|
11
|
+
- **Website:** [https://nexusjs.dev](https://nexusjs.dev)
|
|
12
|
+
- **Repository:** [github.com/bierfor/nexus](https://github.com/bierfor/nexus) (see `packages/ui/`)
|
|
13
|
+
- **Issues:** [github.com/bierfor/nexus/issues](https://github.com/bierfor/nexus/issues)
|
|
14
|
+
|
|
15
|
+
## License
|
|
16
|
+
|
|
17
|
+
MIT © Nexus contributors
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nexus_js/ui",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Nexus Zero-Bundle UI — CSS-only interactive components with 0.0KB of JavaScript",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.ts",
|
|
9
|
+
"./styles": "./src/styles.css"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"nexus",
|
|
13
|
+
"ui",
|
|
14
|
+
"zero-bundle",
|
|
15
|
+
"css",
|
|
16
|
+
"components",
|
|
17
|
+
"no-js",
|
|
18
|
+
"framework",
|
|
19
|
+
"full-stack",
|
|
20
|
+
"svelte",
|
|
21
|
+
"islands",
|
|
22
|
+
"ssr",
|
|
23
|
+
"vite",
|
|
24
|
+
"server-actions"
|
|
25
|
+
],
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"homepage": "https://nexusjs.dev",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/bierfor/nexus.git",
|
|
31
|
+
"directory": "packages/ui"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/bierfor/nexus/issues"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"src",
|
|
38
|
+
"README.md"
|
|
39
|
+
],
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public",
|
|
42
|
+
"registry": "https://registry.npmjs.org/"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** @zero-bundle */
|
|
2
|
+
export interface AccordionProps {
|
|
3
|
+
title: string;
|
|
4
|
+
children: string; // raw HTML content
|
|
5
|
+
open?: boolean;
|
|
6
|
+
id?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function renderAccordion(props: AccordionProps): string {
|
|
10
|
+
const { title, children, open = false, id } = props;
|
|
11
|
+
const detailsAttrs = [
|
|
12
|
+
open ? 'open' : '',
|
|
13
|
+
id ? `id="${id}"` : '',
|
|
14
|
+
].filter(Boolean).join(' ');
|
|
15
|
+
|
|
16
|
+
return `<div class="nx-accordion">
|
|
17
|
+
<details ${detailsAttrs}>
|
|
18
|
+
<summary>${title}</summary>
|
|
19
|
+
<div class="nx-accordion__body">${children}</div>
|
|
20
|
+
</details>
|
|
21
|
+
</div>`;
|
|
22
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zero-bundle — CSS :target modal. Zero JS.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* Trigger: <a href="#my-modal">Open</a>
|
|
6
|
+
* Close: <a href="#">Close</a>
|
|
7
|
+
*/
|
|
8
|
+
export interface ModalProps {
|
|
9
|
+
id: string;
|
|
10
|
+
title: string;
|
|
11
|
+
children: string; // raw HTML body
|
|
12
|
+
trigger?: string; // optional trigger button HTML to prepend
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function renderModal(props: ModalProps): string {
|
|
16
|
+
const { id, title, children, trigger } = props;
|
|
17
|
+
const triggerHtml = trigger ? `${trigger}\n` : '';
|
|
18
|
+
|
|
19
|
+
return `${triggerHtml}<div id="${id}" class="nx-modal-overlay" role="dialog" aria-modal="true" aria-labelledby="${id}-title">
|
|
20
|
+
<div class="nx-modal">
|
|
21
|
+
<a href="#" class="nx-modal__close" aria-label="Close">×</a>
|
|
22
|
+
<h2 class="nx-modal__title" id="${id}-title">${title}</h2>
|
|
23
|
+
${children}
|
|
24
|
+
</div>
|
|
25
|
+
</div>`;
|
|
26
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** @zero-bundle — Pure SVG progress ring. Zero JS. CSS animated. */
|
|
2
|
+
export interface ProgressRingProps {
|
|
3
|
+
value: number; // 0–100
|
|
4
|
+
size?: number; // px, default 64
|
|
5
|
+
stroke?: number; // stroke width, default 6
|
|
6
|
+
color?: string; // CSS color, default #6366f1
|
|
7
|
+
label?: string; // center text override (default: value%)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function renderProgressRing(props: ProgressRingProps): string {
|
|
11
|
+
const { value, size = 64, stroke = 6, color = '#6366f1', label } = props;
|
|
12
|
+
const clamp = Math.max(0, Math.min(100, value));
|
|
13
|
+
const r = (size - stroke * 2) / 2;
|
|
14
|
+
const circ = 2 * Math.PI * r;
|
|
15
|
+
const offset = circ - (clamp / 100) * circ;
|
|
16
|
+
const center = size / 2;
|
|
17
|
+
|
|
18
|
+
return `<div class="nx-ring" style="width:${size}px;height:${size}px" role="progressbar" aria-valuenow="${clamp}" aria-valuemin="0" aria-valuemax="100">
|
|
19
|
+
<svg class="nx-ring__svg" width="${size}" height="${size}" viewBox="0 0 ${size} ${size}">
|
|
20
|
+
<circle class="nx-ring__track" cx="${center}" cy="${center}" r="${r}" stroke-width="${stroke}" />
|
|
21
|
+
<circle class="nx-ring__fill" cx="${center}" cy="${center}" r="${r}" stroke-width="${stroke}"
|
|
22
|
+
stroke="${color}"
|
|
23
|
+
stroke-dasharray="${circ}"
|
|
24
|
+
stroke-dashoffset="${offset}"
|
|
25
|
+
/>
|
|
26
|
+
</svg>
|
|
27
|
+
<span class="nx-ring__label">${label ?? `${clamp}%`}</span>
|
|
28
|
+
</div>`;
|
|
29
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** @zero-bundle — Uses CSS :target for tab switching. Zero JS. */
|
|
2
|
+
export interface TabItem {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
content: string; // raw HTML
|
|
6
|
+
default?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface TabsProps {
|
|
10
|
+
tabs: TabItem[];
|
|
11
|
+
prefix: string; // unique prefix to avoid ID collisions on the page
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function renderTabs(props: TabsProps): string {
|
|
15
|
+
const { tabs, prefix } = props;
|
|
16
|
+
const nav = tabs
|
|
17
|
+
.map((t) => `<a href="#${prefix}-${t.id}" class="nx-tabs__tab">${t.label}</a>`)
|
|
18
|
+
.join('\n ');
|
|
19
|
+
|
|
20
|
+
const panels = tabs
|
|
21
|
+
.map((t) => `<div id="${prefix}-${t.id}" class="nx-tabs__panel${t.default ? ' nx-tabs__panel--default' : ''}">${t.content}</div>`)
|
|
22
|
+
.join('\n ');
|
|
23
|
+
|
|
24
|
+
return `<div class="nx-tabs">
|
|
25
|
+
<nav class="nx-tabs__nav">
|
|
26
|
+
${nav}
|
|
27
|
+
</nav>
|
|
28
|
+
${panels}
|
|
29
|
+
</div>`;
|
|
30
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** @zero-bundle — Pure CSS :hover tooltip. Zero JS. */
|
|
2
|
+
export interface TooltipProps {
|
|
3
|
+
text: string; // tooltip label
|
|
4
|
+
children: string; // trigger element (raw HTML)
|
|
5
|
+
position?: 'top' | 'bottom';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function renderTooltip(props: TooltipProps): string {
|
|
9
|
+
const { text, children } = props;
|
|
10
|
+
return `<span class="nx-tooltip" role="tooltip" aria-label="${text}">
|
|
11
|
+
${children}
|
|
12
|
+
<span class="nx-tooltip__content" aria-hidden="true">${text}</span>
|
|
13
|
+
</span>`;
|
|
14
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nexus_js/ui — Zero-Bundle Component Library
|
|
3
|
+
*
|
|
4
|
+
* Every component in this library generates pure HTML+CSS output.
|
|
5
|
+
* No JavaScript is shipped to the browser. The Nexus compiler detects
|
|
6
|
+
* the @zero-bundle annotation and replaces the component with its
|
|
7
|
+
* static HTML+CSS equivalent at build time.
|
|
8
|
+
*
|
|
9
|
+
* Components:
|
|
10
|
+
* - Accordion → <details>/<summary> with animation
|
|
11
|
+
* - Tabs → CSS :target pseudo-class trick
|
|
12
|
+
* - Toggle → <details> + CSS ::marker trick
|
|
13
|
+
* - Tooltip → CSS :hover + aria-label
|
|
14
|
+
* - Disclosure → <details> semantic variant
|
|
15
|
+
* - Modal → <dialog> native + :target fallback
|
|
16
|
+
* - ProgressRing → SVG-only animated ring
|
|
17
|
+
*
|
|
18
|
+
* Usage in .nx files:
|
|
19
|
+
*
|
|
20
|
+
* ```nx
|
|
21
|
+
* ---
|
|
22
|
+
* import { Accordion } from '@nexus_js/ui';
|
|
23
|
+
* ---
|
|
24
|
+
*
|
|
25
|
+
* <Accordion title="How does Nexus work?">
|
|
26
|
+
* It uses islands architecture...
|
|
27
|
+
* </Accordion>
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* The compiler replaces this with the CSS-only HTML at build time.
|
|
31
|
+
* Zero JS. Zero hydration. Works even with JavaScript disabled.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
export { renderAccordion, type AccordionProps } from './components/accordion.js';
|
|
35
|
+
export { renderTabs, type TabsProps } from './components/tabs.js';
|
|
36
|
+
export { renderTooltip, type TooltipProps } from './components/tooltip.js';
|
|
37
|
+
export { renderModal, type ModalProps } from './components/modal.js';
|
|
38
|
+
export { renderProgressRing, type ProgressRingProps } from './components/progress-ring.js';
|
|
39
|
+
|
|
40
|
+
/** @zero-bundle annotation marker — used by the Nexus compiler. */
|
|
41
|
+
export const ZERO_BUNDLE_MARKER = '__nexus_zero_bundle__';
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Injects the Zero-Bundle stylesheet into a page's <head>.
|
|
45
|
+
* Called automatically by the renderer when @nexus_js/ui components are detected.
|
|
46
|
+
*/
|
|
47
|
+
export function getZeroBundleCSS(): string {
|
|
48
|
+
return `
|
|
49
|
+
/* @nexus_js/ui — Zero-Bundle Component Styles */
|
|
50
|
+
@layer nexus.ui {
|
|
51
|
+
|
|
52
|
+
/* ── Accordion ── */
|
|
53
|
+
.nx-accordion { border: 1px solid #e2e8f0; border-radius: 8px; overflow: hidden; }
|
|
54
|
+
.nx-accordion + .nx-accordion { margin-top: -1px; border-radius: 0; }
|
|
55
|
+
.nx-accordion:first-child { border-radius: 8px 8px 0 0; }
|
|
56
|
+
.nx-accordion:last-child { border-radius: 0 0 8px 8px; }
|
|
57
|
+
.nx-accordion details { width: 100%; }
|
|
58
|
+
.nx-accordion summary {
|
|
59
|
+
list-style: none; display: flex; align-items: center; justify-content: space-between;
|
|
60
|
+
padding: .875rem 1rem; font-weight: 500; cursor: pointer; user-select: none;
|
|
61
|
+
background: #fafafa; transition: background .15s;
|
|
62
|
+
}
|
|
63
|
+
.nx-accordion summary:hover { background: #f1f5f9; }
|
|
64
|
+
.nx-accordion summary::after {
|
|
65
|
+
content: '+'; font-size: 1.25rem; font-weight: 300; color: #94a3b8;
|
|
66
|
+
transition: transform .2s; will-change: transform;
|
|
67
|
+
}
|
|
68
|
+
.nx-accordion details[open] summary::after { transform: rotate(45deg); }
|
|
69
|
+
.nx-accordion details[open] summary { background: #f8fafc; }
|
|
70
|
+
.nx-accordion__body {
|
|
71
|
+
padding: 1rem; border-top: 1px solid #e2e8f0;
|
|
72
|
+
animation: nx-slide-down .2s ease;
|
|
73
|
+
}
|
|
74
|
+
@keyframes nx-slide-down {
|
|
75
|
+
from { opacity: 0; transform: translateY(-4px); }
|
|
76
|
+
to { opacity: 1; transform: translateY(0); }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* ── Tabs ── */
|
|
80
|
+
.nx-tabs { }
|
|
81
|
+
.nx-tabs__nav { display: flex; border-bottom: 2px solid #e2e8f0; gap: .5rem; }
|
|
82
|
+
.nx-tabs__tab {
|
|
83
|
+
padding: .625rem 1rem; text-decoration: none; color: #64748b; border-radius: 6px 6px 0 0;
|
|
84
|
+
border: 2px solid transparent; border-bottom: none; font-weight: 500; font-size: .9rem;
|
|
85
|
+
transition: color .15s, background .15s;
|
|
86
|
+
}
|
|
87
|
+
.nx-tabs__tab:hover { color: #1e293b; background: #f8fafc; }
|
|
88
|
+
.nx-tabs__panel { display: none; padding: 1.25rem 0; animation: nx-fade-in .2s; }
|
|
89
|
+
.nx-tabs__panel:target { display: block; }
|
|
90
|
+
.nx-tabs__panel--default { display: block; }
|
|
91
|
+
.nx-tabs__panel:target ~ .nx-tabs__panel--default { display: none; }
|
|
92
|
+
.nx-tabs__tab--active,
|
|
93
|
+
.nx-tabs__nav a[href]:target-within { color: #6366f1; border-color: #6366f1; background: white; }
|
|
94
|
+
@keyframes nx-fade-in { from { opacity: 0; } to { opacity: 1; } }
|
|
95
|
+
|
|
96
|
+
/* ── Tooltip ── */
|
|
97
|
+
.nx-tooltip { position: relative; display: inline-block; }
|
|
98
|
+
.nx-tooltip__content {
|
|
99
|
+
position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
|
|
100
|
+
background: #1e293b; color: #f8fafc; padding: .4rem .75rem; border-radius: 6px;
|
|
101
|
+
font-size: .8rem; white-space: nowrap; pointer-events: none;
|
|
102
|
+
opacity: 0; visibility: hidden; transition: opacity .15s, visibility .15s;
|
|
103
|
+
}
|
|
104
|
+
.nx-tooltip__content::after {
|
|
105
|
+
content: ''; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
|
|
106
|
+
border: 5px solid transparent; border-top-color: #1e293b;
|
|
107
|
+
}
|
|
108
|
+
.nx-tooltip:hover .nx-tooltip__content,
|
|
109
|
+
.nx-tooltip:focus-within .nx-tooltip__content { opacity: 1; visibility: visible; }
|
|
110
|
+
|
|
111
|
+
/* ── Modal ── */
|
|
112
|
+
.nx-modal-overlay { display: none; }
|
|
113
|
+
.nx-modal-overlay:target { display: flex; position: fixed; inset: 0; background: rgba(0,0,0,.5); align-items: center; justify-content: center; z-index: 1000; animation: nx-fade-in .2s; }
|
|
114
|
+
.nx-modal {
|
|
115
|
+
background: white; border-radius: 12px; padding: 1.5rem 2rem; min-width: 320px;
|
|
116
|
+
max-width: min(90vw, 560px); box-shadow: 0 25px 50px -12px rgba(0,0,0,.25);
|
|
117
|
+
animation: nx-modal-up .25s ease;
|
|
118
|
+
}
|
|
119
|
+
.nx-modal__close { float: right; text-decoration: none; font-size: 1.25rem; color: #94a3b8; line-height: 1; margin: -.25rem -.5rem 0 0; }
|
|
120
|
+
.nx-modal__close:hover { color: #1e293b; }
|
|
121
|
+
.nx-modal__title { font-size: 1.125rem; font-weight: 600; margin-bottom: 1rem; }
|
|
122
|
+
@keyframes nx-modal-up { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
|
|
123
|
+
|
|
124
|
+
/* ── Progress Ring ── */
|
|
125
|
+
.nx-ring { display: inline-flex; align-items: center; justify-content: center; position: relative; }
|
|
126
|
+
.nx-ring__svg { transform: rotate(-90deg); }
|
|
127
|
+
.nx-ring__track { fill: none; stroke: #e2e8f0; }
|
|
128
|
+
.nx-ring__fill { fill: none; stroke: #6366f1; stroke-linecap: round; transition: stroke-dashoffset .6s ease; }
|
|
129
|
+
.nx-ring__label { position: absolute; font-weight: 700; font-size: .8rem; color: #1e293b; }
|
|
130
|
+
|
|
131
|
+
}`;
|
|
132
|
+
}
|