create-nativecore 0.1.1 → 0.2.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/README.md +6 -14
- package/bin/index.mjs +402 -431
- package/package.json +3 -2
- package/template/.env.example +28 -0
- package/template/.htmlhintrc +14 -0
- package/template/api/data/dashboard.json +11 -0
- package/template/api/data/users.json +18 -0
- package/template/api/mockApi.js +161 -0
- package/template/assets/icon.svg +13 -0
- package/template/assets/logo.svg +25 -0
- package/template/eslint.config.js +94 -0
- package/template/index.html +137 -0
- package/template/manifest.json +19 -0
- package/template/public/.well-known/security.txt +9 -0
- package/template/public/_headers +24 -0
- package/template/public/_redirects +14 -0
- package/template/public/assets/icon.svg +13 -0
- package/template/public/assets/logo.svg +25 -0
- package/template/public/manifest.json +19 -0
- package/template/public/robots.txt +13 -0
- package/template/public/sitemap.xml +27 -0
- package/template/scripts/build-for-bots.mjs +121 -0
- package/template/scripts/convert-to-ts.mjs +106 -0
- package/template/scripts/fix-encoding.mjs +38 -0
- package/template/scripts/fix-svg-paths.mjs +32 -0
- package/template/scripts/generate-cf-router.mjs +52 -0
- package/template/scripts/inject-dev-tools.mjs +41 -0
- package/template/scripts/inject-version.mjs +65 -0
- package/template/scripts/make-component.mjs +445 -0
- package/template/scripts/make-component.mjs.backup +432 -0
- package/template/scripts/make-controller.mjs +119 -0
- package/template/scripts/make-core-component.mjs +303 -0
- package/template/scripts/make-view.mjs +346 -0
- package/template/scripts/minify.mjs +71 -0
- package/template/scripts/prepare-static-assets.mjs +141 -0
- package/template/scripts/prompt-bot-build.mjs +223 -0
- package/template/scripts/remove-component.mjs +170 -0
- package/template/scripts/remove-core-component.mjs +156 -0
- package/template/scripts/remove-dev.mjs +13 -0
- package/template/scripts/remove-view.mjs +200 -0
- package/template/scripts/strip-dev-blocks.mjs +30 -0
- package/template/scripts/watch-compile.mjs +69 -0
- package/template/server.js +1066 -0
- package/template/src/app.ts +115 -0
- package/template/src/components/appRegistry.ts +8 -0
- package/template/src/components/core/app-footer.ts +27 -0
- package/template/src/components/core/app-header.ts +175 -0
- package/template/src/components/core/app-sidebar.ts +238 -0
- package/template/src/components/core/loading-spinner.ts +25 -0
- package/template/src/components/core/nc-a.ts +313 -0
- package/template/src/components/core/nc-accordion.ts +186 -0
- package/template/src/components/core/nc-alert.ts +153 -0
- package/template/src/components/core/nc-animation.ts +1150 -0
- package/template/src/components/core/nc-autocomplete.ts +271 -0
- package/template/src/components/core/nc-avatar-group.ts +113 -0
- package/template/src/components/core/nc-avatar.ts +148 -0
- package/template/src/components/core/nc-badge.ts +86 -0
- package/template/src/components/core/nc-bottom-nav.ts +214 -0
- package/template/src/components/core/nc-breadcrumb.ts +96 -0
- package/template/src/components/core/nc-button.ts +307 -0
- package/template/src/components/core/nc-card.ts +160 -0
- package/template/src/components/core/nc-checkbox.ts +282 -0
- package/template/src/components/core/nc-chip.ts +115 -0
- package/template/src/components/core/nc-code.ts +314 -0
- package/template/src/components/core/nc-collapsible.ts +154 -0
- package/template/src/components/core/nc-color-picker.ts +268 -0
- package/template/src/components/core/nc-copy-button.ts +119 -0
- package/template/src/components/core/nc-date-picker.ts +443 -0
- package/template/src/components/core/nc-div.ts +280 -0
- package/template/src/components/core/nc-divider.ts +81 -0
- package/template/src/components/core/nc-drawer.ts +230 -0
- package/template/src/components/core/nc-dropdown.ts +178 -0
- package/template/src/components/core/nc-empty-state.ts +134 -0
- package/template/src/components/core/nc-file-upload.ts +354 -0
- package/template/src/components/core/nc-form.ts +312 -0
- package/template/src/components/core/nc-image.ts +184 -0
- package/template/src/components/core/nc-input.ts +383 -0
- package/template/src/components/core/nc-kbd.ts +48 -0
- package/template/src/components/core/nc-menu-item.ts +193 -0
- package/template/src/components/core/nc-menu.ts +376 -0
- package/template/src/components/core/nc-modal.ts +238 -0
- package/template/src/components/core/nc-nav-item.ts +151 -0
- package/template/src/components/core/nc-number-input.ts +350 -0
- package/template/src/components/core/nc-otp-input.ts +235 -0
- package/template/src/components/core/nc-pagination.ts +178 -0
- package/template/src/components/core/nc-popover.ts +260 -0
- package/template/src/components/core/nc-progress-circular.ts +119 -0
- package/template/src/components/core/nc-progress.ts +134 -0
- package/template/src/components/core/nc-radio.ts +235 -0
- package/template/src/components/core/nc-rating.ts +266 -0
- package/template/src/components/core/nc-rich-text.ts +283 -0
- package/template/src/components/core/nc-scroll-top.ts +116 -0
- package/template/src/components/core/nc-select.ts +452 -0
- package/template/src/components/core/nc-skeleton.ts +107 -0
- package/template/src/components/core/nc-slider.ts +285 -0
- package/template/src/components/core/nc-snackbar.ts +230 -0
- package/template/src/components/core/nc-splash.ts +343 -0
- package/template/src/components/core/nc-stepper.ts +247 -0
- package/template/src/components/core/nc-switch.ts +281 -0
- package/template/src/components/core/nc-tab-item.ts +138 -0
- package/template/src/components/core/nc-table.ts +279 -0
- package/template/src/components/core/nc-tabs.ts +554 -0
- package/template/src/components/core/nc-tag-input.ts +279 -0
- package/template/src/components/core/nc-textarea.ts +216 -0
- package/template/src/components/core/nc-time-picker.ts +438 -0
- package/template/src/components/core/nc-timeline.ts +186 -0
- package/template/src/components/core/nc-tooltip.ts +143 -0
- package/template/src/components/frameworkRegistry.ts +68 -0
- package/template/src/components/preloadRegistry.ts +28 -0
- package/template/src/components/registry.ts +8 -0
- package/template/src/components/ui/dashboard-signal-lab.ts +284 -0
- package/template/src/constants/apiEndpoints.ts +27 -0
- package/template/src/constants/errorMessages.ts +23 -0
- package/template/src/constants/index.ts +8 -0
- package/template/src/constants/routePaths.ts +15 -0
- package/template/src/constants/storageKeys.ts +18 -0
- package/template/src/controllers/dashboard.controller.ts +200 -0
- package/template/src/controllers/home.controller.ts +21 -0
- package/template/src/controllers/index.ts +11 -0
- package/template/src/controllers/login.controller.ts +131 -0
- package/template/src/core/component.ts +354 -0
- package/template/src/core/errorHandler.ts +85 -0
- package/template/src/core/gpu-animation.ts +604 -0
- package/template/src/core/http.ts +173 -0
- package/template/src/core/lazyComponents.ts +90 -0
- package/template/src/core/router.ts +642 -0
- package/template/src/core/signals.ts +146 -0
- package/template/src/core/state.ts +248 -0
- package/template/src/dev/component-editor.ts +1363 -0
- package/template/src/dev/component-overlay.ts +278 -0
- package/template/src/dev/context-menu.ts +223 -0
- package/template/src/dev/denc-tools.ts +250 -0
- package/template/src/dev/hmr.ts +189 -0
- package/template/src/dev/nfbs.code-workspace +27 -0
- package/template/src/dev/outline-panel.ts +1247 -0
- package/template/src/middleware/auth.middleware.ts +23 -0
- package/template/src/routes/routes.ts +38 -0
- package/template/src/services/api.service.ts +394 -0
- package/template/src/services/auth.service.ts +176 -0
- package/template/src/services/index.ts +8 -0
- package/template/src/services/logger.service.ts +74 -0
- package/template/src/services/storage.service.ts +88 -0
- package/template/src/stores/appStore.ts +57 -0
- package/template/src/stores/uiStore.ts +36 -0
- package/template/src/styles/core-variables.css +219 -0
- package/template/src/styles/core.css +710 -0
- package/template/src/styles/main.css +3164 -0
- package/template/src/styles/variables.css +152 -0
- package/template/src/types/global.d.ts +47 -0
- package/template/src/utils/cacheBuster.ts +20 -0
- package/template/src/utils/dom.ts +149 -0
- package/template/src/utils/events.ts +203 -0
- package/template/src/utils/form.ts +176 -0
- package/template/src/utils/formatters.ts +169 -0
- package/template/src/utils/helpers.ts +195 -0
- package/template/src/utils/markdown.ts +307 -0
- package/template/src/utils/sidebar.ts +96 -0
- package/template/src/utils/smoothScroll.ts +85 -0
- package/template/src/utils/templates.ts +23 -0
- package/template/src/utils/validation.ts +73 -0
- package/template/src/views/protected/dashboard.html +293 -0
- package/template/src/views/public/home.html +150 -0
- package/template/src/views/public/login.html +102 -0
- package/template/tests/unit/component.test.ts +87 -0
- package/template/tests/unit/computed.test.ts +79 -0
- package/template/tests/unit/form.test.ts +68 -0
- package/template/tests/unit/formatters.test.ts +49 -0
- package/template/tests/unit/lazy-components.test.ts +59 -0
- package/template/tests/unit/markdown.test.ts +62 -0
- package/template/tests/unit/router.test.ts +112 -0
- package/template/tests/unit/signals.test.ts +54 -0
- package/template/tests/unit/validation.test.ts +50 -0
- package/template/tsconfig.build.json +21 -0
- package/template/tsconfig.json +51 -0
- package/template/vitest.config.ts +36 -0
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NativeCore Link/Button Component (nc-a)
|
|
3
|
+
*
|
|
4
|
+
* A semantic <a> element styled as a button. Handles SPA navigation
|
|
5
|
+
* internally so the router's light-DOM event delegation is not needed.
|
|
6
|
+
* External links open normally; internal paths use router.navigate().
|
|
7
|
+
*
|
|
8
|
+
* Attributes:
|
|
9
|
+
* href — Destination path or URL (required for navigation)
|
|
10
|
+
* variant — Visual style (default: 'primary')
|
|
11
|
+
* size — 'sm' | 'md' | 'lg' (default: 'md')
|
|
12
|
+
* disabled — Boolean. Prevents navigation and dims the element.
|
|
13
|
+
* target — '_blank' etc. Passed through to the inner <a>. External links
|
|
14
|
+
* are always handled by the browser (no SPA navigation).
|
|
15
|
+
*
|
|
16
|
+
* Variants:
|
|
17
|
+
* primary, secondary, success, danger, warning, info,
|
|
18
|
+
* outline, ghost, link,
|
|
19
|
+
* hero-primary, hero-ghost
|
|
20
|
+
*
|
|
21
|
+
* Slots:
|
|
22
|
+
* default — Link label / content.
|
|
23
|
+
*
|
|
24
|
+
* Events emitted:
|
|
25
|
+
* nc-navigate — { href } — fires before SPA navigation (cancelable).
|
|
26
|
+
*
|
|
27
|
+
* Usage:
|
|
28
|
+
* <nc-a href="/components" variant="primary">Explore Components</nc-a>
|
|
29
|
+
* <nc-a href="/login" variant="ghost" size="lg">Get Started</nc-a>
|
|
30
|
+
* <nc-a href="https://github.com" target="_blank" variant="link">GitHub</nc-a>
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
import { Component, defineComponent } from '@core/component.js';
|
|
34
|
+
import router from '@core/router.js';
|
|
35
|
+
import { html } from '@utils/templates.js';
|
|
36
|
+
|
|
37
|
+
export class NcA extends Component {
|
|
38
|
+
static useShadowDOM = true;
|
|
39
|
+
|
|
40
|
+
static attributeOptions = {
|
|
41
|
+
variant: [
|
|
42
|
+
'primary', 'secondary', 'success', 'danger', 'warning', 'info',
|
|
43
|
+
'outline', 'ghost', 'link',
|
|
44
|
+
'hero-primary', 'hero-ghost',
|
|
45
|
+
],
|
|
46
|
+
size: ['sm', 'md', 'lg'],
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
static get observedAttributes() {
|
|
50
|
+
return ['href', 'variant', 'size', 'disabled', 'target'];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private _onClick: ((e: Event) => void) | null = null;
|
|
54
|
+
|
|
55
|
+
template(): string {
|
|
56
|
+
const href = this.attr('href', '#');
|
|
57
|
+
const disabled = this.hasAttribute('disabled');
|
|
58
|
+
const target = this.attr('target', '');
|
|
59
|
+
|
|
60
|
+
const targetAttr = target ? `target="${target}" rel="noopener noreferrer"` : '';
|
|
61
|
+
|
|
62
|
+
return html`
|
|
63
|
+
<style>
|
|
64
|
+
:host {
|
|
65
|
+
display: inline-block;
|
|
66
|
+
width: var(--nc-a-host-width, auto);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
a {
|
|
70
|
+
display: inline-flex;
|
|
71
|
+
align-items: center;
|
|
72
|
+
justify-content: center;
|
|
73
|
+
gap: var(--nc-spacing-xs);
|
|
74
|
+
font-family: var(--nc-font-family);
|
|
75
|
+
font-weight: var(--nc-font-weight-semibold);
|
|
76
|
+
text-decoration: none;
|
|
77
|
+
border: none;
|
|
78
|
+
border-radius: var(--nc-radius-md);
|
|
79
|
+
cursor: pointer;
|
|
80
|
+
transition:
|
|
81
|
+
background var(--nc-transition-fast),
|
|
82
|
+
color var(--nc-transition-fast),
|
|
83
|
+
box-shadow var(--nc-transition-fast),
|
|
84
|
+
transform var(--nc-transition-fast),
|
|
85
|
+
border-color var(--nc-transition-fast);
|
|
86
|
+
white-space: nowrap;
|
|
87
|
+
user-select: none;
|
|
88
|
+
box-sizing: border-box;
|
|
89
|
+
outline: none;
|
|
90
|
+
width: var(--nc-a-width, auto);
|
|
91
|
+
|
|
92
|
+
/* default size: md */
|
|
93
|
+
padding: var(--nc-spacing-sm) var(--nc-spacing-xl);
|
|
94
|
+
font-size: var(--nc-font-size-base);
|
|
95
|
+
min-height: 40px;
|
|
96
|
+
|
|
97
|
+
/* default variant: primary */
|
|
98
|
+
background: var(--nc-primary);
|
|
99
|
+
color: var(--nc-white);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
a:focus-visible {
|
|
103
|
+
outline: 2px solid var(--nc-primary);
|
|
104
|
+
outline-offset: 2px;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/* ── Sizes ─────────────────────────────────────────────────── */
|
|
108
|
+
:host([size="sm"]) a {
|
|
109
|
+
padding: var(--nc-spacing-xs) var(--nc-spacing-lg);
|
|
110
|
+
font-size: var(--nc-font-size-sm);
|
|
111
|
+
min-height: 32px;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
:host([size="lg"]) a {
|
|
115
|
+
padding: var(--nc-spacing-md) var(--nc-spacing-2xl);
|
|
116
|
+
font-size: var(--nc-font-size-lg);
|
|
117
|
+
min-height: 48px;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* ── Variants ──────────────────────────────────────────────── */
|
|
121
|
+
:host([variant="primary"]) a {
|
|
122
|
+
background: var(--nc-primary);
|
|
123
|
+
color: var(--nc-white);
|
|
124
|
+
box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
|
|
125
|
+
}
|
|
126
|
+
:host([variant="primary"]) a:hover {
|
|
127
|
+
background: var(--nc-primary-dark);
|
|
128
|
+
transform: translateY(-1px);
|
|
129
|
+
box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
:host([variant="secondary"]) a {
|
|
133
|
+
background: var(--nc-gray-200);
|
|
134
|
+
color: var(--nc-text);
|
|
135
|
+
}
|
|
136
|
+
:host([variant="secondary"]) a:hover {
|
|
137
|
+
background: var(--nc-gray-300);
|
|
138
|
+
transform: translateY(-1px);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
:host([variant="success"]) a {
|
|
142
|
+
background: var(--nc-success);
|
|
143
|
+
color: var(--nc-white);
|
|
144
|
+
box-shadow: var(--nc-shadow-success);
|
|
145
|
+
}
|
|
146
|
+
:host([variant="success"]) a:hover {
|
|
147
|
+
background: var(--nc-success-dark);
|
|
148
|
+
transform: translateY(-1px);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
:host([variant="danger"]) a {
|
|
152
|
+
background: var(--nc-danger);
|
|
153
|
+
color: var(--nc-white);
|
|
154
|
+
box-shadow: var(--nc-shadow-danger);
|
|
155
|
+
}
|
|
156
|
+
:host([variant="danger"]) a:hover {
|
|
157
|
+
background: var(--nc-danger-dark);
|
|
158
|
+
transform: translateY(-1px);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
:host([variant="warning"]) a {
|
|
162
|
+
background: var(--nc-warning);
|
|
163
|
+
color: var(--nc-white);
|
|
164
|
+
}
|
|
165
|
+
:host([variant="warning"]) a:hover {
|
|
166
|
+
background: var(--nc-warning-dark);
|
|
167
|
+
transform: translateY(-1px);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
:host([variant="info"]) a {
|
|
171
|
+
background: var(--nc-info);
|
|
172
|
+
color: var(--nc-white);
|
|
173
|
+
}
|
|
174
|
+
:host([variant="info"]) a:hover {
|
|
175
|
+
background: var(--nc-info-dark);
|
|
176
|
+
transform: translateY(-1px);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
:host([variant="outline"]) a {
|
|
180
|
+
background: transparent;
|
|
181
|
+
color: var(--nc-primary);
|
|
182
|
+
border: 2px solid var(--nc-primary);
|
|
183
|
+
}
|
|
184
|
+
:host([variant="outline"]) a:hover {
|
|
185
|
+
background: var(--nc-primary);
|
|
186
|
+
color: var(--nc-white);
|
|
187
|
+
transform: translateY(-1px);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
:host([variant="ghost"]) a {
|
|
191
|
+
background: transparent;
|
|
192
|
+
color: var(--nc-text);
|
|
193
|
+
border: 2px solid var(--nc-border-dark);
|
|
194
|
+
}
|
|
195
|
+
:host([variant="ghost"]) a:hover {
|
|
196
|
+
background: var(--nc-bg-tertiary);
|
|
197
|
+
transform: translateY(-1px);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
:host([variant="link"]) a {
|
|
201
|
+
background: transparent;
|
|
202
|
+
color: var(--nc-primary);
|
|
203
|
+
padding-left: 0;
|
|
204
|
+
padding-right: 0;
|
|
205
|
+
min-height: unset;
|
|
206
|
+
text-decoration: underline;
|
|
207
|
+
text-underline-offset: 3px;
|
|
208
|
+
}
|
|
209
|
+
:host([variant="link"]) a:hover {
|
|
210
|
+
color: var(--nc-primary-dark);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/* ── Hero variants (landing page CTA style) ─────────────────── */
|
|
214
|
+
:host([variant="hero-primary"]) a {
|
|
215
|
+
background: var(--nc-primary);
|
|
216
|
+
color: var(--nc-white);
|
|
217
|
+
padding: var(--nc-spacing-md) var(--nc-spacing-2xl);
|
|
218
|
+
font-size: var(--nc-font-size-lg);
|
|
219
|
+
min-height: 52px;
|
|
220
|
+
border-radius: var(--nc-radius-full);
|
|
221
|
+
box-shadow: 0 4px 20px rgba(16, 185, 129, 0.4);
|
|
222
|
+
}
|
|
223
|
+
:host([variant="hero-primary"]) a:hover {
|
|
224
|
+
background: var(--nc-primary-dark);
|
|
225
|
+
transform: translateY(-2px);
|
|
226
|
+
box-shadow: 0 8px 28px rgba(16, 185, 129, 0.5);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
:host([variant="hero-ghost"]) a {
|
|
230
|
+
background: transparent;
|
|
231
|
+
color: var(--nc-white);
|
|
232
|
+
padding: var(--nc-spacing-md) var(--nc-spacing-2xl);
|
|
233
|
+
font-size: var(--nc-font-size-lg);
|
|
234
|
+
min-height: 52px;
|
|
235
|
+
border-radius: var(--nc-radius-full);
|
|
236
|
+
border: 2px solid rgba(255, 255, 255, 0.4);
|
|
237
|
+
}
|
|
238
|
+
:host([variant="hero-ghost"]) a:hover {
|
|
239
|
+
background: rgba(255, 255, 255, 0.1);
|
|
240
|
+
border-color: rgba(255, 255, 255, 0.7);
|
|
241
|
+
transform: translateY(-2px);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/* ── Disabled ────────────────────────────────────────────────── */
|
|
245
|
+
:host([disabled]) a {
|
|
246
|
+
opacity: 0.45;
|
|
247
|
+
cursor: not-allowed;
|
|
248
|
+
pointer-events: none;
|
|
249
|
+
transform: none !important;
|
|
250
|
+
box-shadow: none !important;
|
|
251
|
+
}
|
|
252
|
+
</style>
|
|
253
|
+
<a href="${href}" ${targetAttr} aria-disabled="${disabled}" role="link">
|
|
254
|
+
<slot></slot>
|
|
255
|
+
</a>
|
|
256
|
+
`;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
onMount(): void {
|
|
260
|
+
this._onClick = (e: Event) => {
|
|
261
|
+
if (this.hasAttribute('disabled')) {
|
|
262
|
+
e.preventDefault();
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const href = this.attr('href', '');
|
|
267
|
+
const target = this.attr('target', '');
|
|
268
|
+
|
|
269
|
+
if (!href) return;
|
|
270
|
+
|
|
271
|
+
// External links, hash links, or explicit target — let the browser handle
|
|
272
|
+
if (
|
|
273
|
+
href.startsWith('http://') ||
|
|
274
|
+
href.startsWith('https://') ||
|
|
275
|
+
href.startsWith('mailto:') ||
|
|
276
|
+
href.startsWith('tel:') ||
|
|
277
|
+
href.startsWith('#') ||
|
|
278
|
+
target === '_blank'
|
|
279
|
+
) {
|
|
280
|
+
return; // don't prevent default
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// SPA navigation
|
|
284
|
+
e.preventDefault();
|
|
285
|
+
|
|
286
|
+
const cancelled = !this.emitEvent('nc-navigate', { href }, { cancelable: true });
|
|
287
|
+
if (cancelled) return;
|
|
288
|
+
|
|
289
|
+
router.navigate(href);
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
this.shadowRoot!.addEventListener('click', this._onClick);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
onUnmount(): void {
|
|
296
|
+
if (this._onClick) {
|
|
297
|
+
this.shadowRoot?.removeEventListener('click', this._onClick);
|
|
298
|
+
this._onClick = null;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
attributeChangedCallback(
|
|
303
|
+
_name: string,
|
|
304
|
+
oldValue: string | null,
|
|
305
|
+
newValue: string | null
|
|
306
|
+
): void {
|
|
307
|
+
if (this._mounted && oldValue !== newValue) {
|
|
308
|
+
this.render();
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
defineComponent('nc-a', NcA);
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NcAccordion + NcAccordionItem Components
|
|
3
|
+
*
|
|
4
|
+
* nc-accordion:
|
|
5
|
+
* - multiple: boolean — allow multiple items open simultaneously
|
|
6
|
+
* - variant: 'default'|'bordered'|'flush' (default: 'default')
|
|
7
|
+
*
|
|
8
|
+
* nc-accordion-item:
|
|
9
|
+
* - header: string — header text (or use slot[name="header"])
|
|
10
|
+
* - open: boolean — expanded state
|
|
11
|
+
* - disabled: boolean
|
|
12
|
+
*
|
|
13
|
+
* Events (on nc-accordion-item):
|
|
14
|
+
* - toggle: CustomEvent<{ open: boolean }>
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* <nc-accordion>
|
|
18
|
+
* <nc-accordion-item header="Section 1" open>Content here</nc-accordion-item>
|
|
19
|
+
* <nc-accordion-item header="Section 2">More content</nc-accordion-item>
|
|
20
|
+
* </nc-accordion>
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { Component, defineComponent } from '@core/component.js';
|
|
24
|
+
|
|
25
|
+
// ── NcAccordionItem ──────────────────────────────────────────────────────────
|
|
26
|
+
|
|
27
|
+
export class NcAccordionItem extends Component {
|
|
28
|
+
static useShadowDOM = true;
|
|
29
|
+
|
|
30
|
+
static get observedAttributes() { return ['header', 'open', 'disabled']; }
|
|
31
|
+
|
|
32
|
+
template() {
|
|
33
|
+
const header = this.getAttribute('header') || '';
|
|
34
|
+
const open = this.hasAttribute('open');
|
|
35
|
+
const disabled = this.hasAttribute('disabled');
|
|
36
|
+
|
|
37
|
+
return `
|
|
38
|
+
<style>
|
|
39
|
+
:host { display: block; }
|
|
40
|
+
|
|
41
|
+
.item {
|
|
42
|
+
border-bottom: 1px solid var(--nc-border);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.trigger {
|
|
46
|
+
width: 100%;
|
|
47
|
+
display: flex;
|
|
48
|
+
align-items: center;
|
|
49
|
+
justify-content: space-between;
|
|
50
|
+
gap: var(--nc-spacing-sm);
|
|
51
|
+
padding: var(--nc-spacing-md) var(--nc-spacing-lg);
|
|
52
|
+
background: none;
|
|
53
|
+
border: none;
|
|
54
|
+
cursor: ${disabled ? 'not-allowed' : 'pointer'};
|
|
55
|
+
color: ${disabled ? 'var(--nc-text-muted)' : 'var(--nc-text)'};
|
|
56
|
+
font-family: var(--nc-font-family);
|
|
57
|
+
font-size: var(--nc-font-size-base);
|
|
58
|
+
font-weight: var(--nc-font-weight-medium);
|
|
59
|
+
text-align: left;
|
|
60
|
+
transition: background var(--nc-transition-fast), color var(--nc-transition-fast);
|
|
61
|
+
opacity: ${disabled ? '0.6' : '1'};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.trigger:hover:not([disabled]) { background: var(--nc-bg-secondary); }
|
|
65
|
+
.trigger:focus-visible { outline: 2px solid var(--nc-primary); outline-offset: -2px; }
|
|
66
|
+
|
|
67
|
+
.chevron {
|
|
68
|
+
flex-shrink: 0;
|
|
69
|
+
transition: transform var(--nc-transition-base);
|
|
70
|
+
transform: rotate(${open ? '180deg' : '0deg'});
|
|
71
|
+
color: var(--nc-text-muted);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.body {
|
|
75
|
+
display: ${open ? 'block' : 'none'};
|
|
76
|
+
padding: 0 var(--nc-spacing-lg) var(--nc-spacing-md);
|
|
77
|
+
font-size: var(--nc-font-size-sm);
|
|
78
|
+
color: var(--nc-text-secondary, var(--nc-text-muted));
|
|
79
|
+
line-height: var(--nc-line-height-relaxed, 1.7);
|
|
80
|
+
}
|
|
81
|
+
</style>
|
|
82
|
+
<div class="item">
|
|
83
|
+
<button
|
|
84
|
+
class="trigger"
|
|
85
|
+
type="button"
|
|
86
|
+
aria-expanded="${open}"
|
|
87
|
+
${disabled ? 'disabled' : ''}
|
|
88
|
+
>
|
|
89
|
+
<slot name="header">${header}</slot>
|
|
90
|
+
<svg class="chevron" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" width="16" height="16">
|
|
91
|
+
<path d="M3 6l5 5 5-5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
|
92
|
+
</svg>
|
|
93
|
+
</button>
|
|
94
|
+
<div class="body" role="region" aria-hidden="${!open}">
|
|
95
|
+
<slot></slot>
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
onMount() {
|
|
102
|
+
this.$<HTMLButtonElement>('.trigger')!.addEventListener('click', () => {
|
|
103
|
+
if (this.hasAttribute('disabled')) return;
|
|
104
|
+
const nowOpen = !this.hasAttribute('open');
|
|
105
|
+
if (nowOpen) {
|
|
106
|
+
this.setAttribute('open', '');
|
|
107
|
+
} else {
|
|
108
|
+
this.removeAttribute('open');
|
|
109
|
+
}
|
|
110
|
+
this.dispatchEvent(new CustomEvent('toggle', {
|
|
111
|
+
bubbles: true, composed: true,
|
|
112
|
+
detail: { open: nowOpen }
|
|
113
|
+
}));
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
attributeChangedCallback(name: string, oldValue: string, newValue: string) {
|
|
118
|
+
if (oldValue === newValue) return;
|
|
119
|
+
if (name === 'open' && this._mounted) {
|
|
120
|
+
const open = this.hasAttribute('open');
|
|
121
|
+
const body = this.$<HTMLElement>('.body');
|
|
122
|
+
const chevron = this.$<HTMLElement>('.chevron');
|
|
123
|
+
const trigger = this.$<HTMLButtonElement>('.trigger');
|
|
124
|
+
if (body) { body.style.display = open ? 'block' : 'none'; body.setAttribute('aria-hidden', String(!open)); }
|
|
125
|
+
if (chevron) chevron.style.transform = `rotate(${open ? 180 : 0}deg)`;
|
|
126
|
+
if (trigger) trigger.setAttribute('aria-expanded', String(open));
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (this._mounted) { this.render(); this.onMount(); }
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ── NcAccordion ──────────────────────────────────────────────────────────────
|
|
134
|
+
|
|
135
|
+
export class NcAccordion extends Component {
|
|
136
|
+
static useShadowDOM = true;
|
|
137
|
+
|
|
138
|
+
static get observedAttributes() { return ['multiple', 'variant']; }
|
|
139
|
+
|
|
140
|
+
template() {
|
|
141
|
+
return `
|
|
142
|
+
<style>
|
|
143
|
+
:host { display: block; }
|
|
144
|
+
|
|
145
|
+
.accordion {
|
|
146
|
+
border-radius: var(--nc-radius-md, 8px);
|
|
147
|
+
overflow: hidden;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
:host([variant="bordered"]) .accordion {
|
|
151
|
+
border: 1px solid var(--nc-border);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
:host([variant="flush"]) .accordion {
|
|
155
|
+
border-radius: 0;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
::slotted(nc-accordion-item:last-child) {
|
|
159
|
+
border-bottom: none !important;
|
|
160
|
+
}
|
|
161
|
+
</style>
|
|
162
|
+
<div class="accordion">
|
|
163
|
+
<slot></slot>
|
|
164
|
+
</div>
|
|
165
|
+
`;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
onMount() {
|
|
169
|
+
// Collapse siblings unless multiple is set
|
|
170
|
+
this.addEventListener('toggle', (e: Event) => {
|
|
171
|
+
if (this.hasAttribute('multiple')) return;
|
|
172
|
+
const opened = e.target as NcAccordionItem;
|
|
173
|
+
if (!(opened as any).hasAttribute('open')) return;
|
|
174
|
+
this.querySelectorAll<NcAccordionItem>('nc-accordion-item').forEach(item => {
|
|
175
|
+
if (item !== opened) item.removeAttribute('open');
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
attributeChangedCallback(name: string, oldValue: string, newValue: string) {
|
|
181
|
+
if (oldValue !== newValue && this._mounted) this.render();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
defineComponent('nc-accordion-item', NcAccordionItem);
|
|
186
|
+
defineComponent('nc-accordion', NcAccordion);
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NcAlert Component
|
|
3
|
+
*
|
|
4
|
+
* Attributes:
|
|
5
|
+
* - variant: 'info'|'success'|'warning'|'danger'|'neutral' (default: 'info')
|
|
6
|
+
* - title: string — optional bold heading
|
|
7
|
+
* - dismissible: boolean — show close button
|
|
8
|
+
* - duration: number — ms before auto-dismiss (0 = sticky)
|
|
9
|
+
* - icon: boolean — show variant icon (default: true)
|
|
10
|
+
* - open: boolean — visible state (default: true; remove to hide)
|
|
11
|
+
*
|
|
12
|
+
* Events:
|
|
13
|
+
* - dismiss: CustomEvent — fired when closed
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* <nc-alert variant="success" title="Saved!" dismissible>Your changes have been saved.</nc-alert>
|
|
17
|
+
* <nc-alert variant="warning">Your session expires in 5 minutes.</nc-alert>
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { Component, defineComponent } from '@core/component.js';
|
|
21
|
+
|
|
22
|
+
const ICONS: Record<string, string> = {
|
|
23
|
+
info: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" width="18" height="18"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"/></svg>`,
|
|
24
|
+
success: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" width="18" height="18"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/></svg>`,
|
|
25
|
+
warning: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" width="18" height="18"><path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd"/></svg>`,
|
|
26
|
+
danger: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" width="18" height="18"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"/></svg>`,
|
|
27
|
+
neutral: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" width="18" height="18"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"/></svg>`,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export class NcAlert extends Component {
|
|
31
|
+
static useShadowDOM = true;
|
|
32
|
+
|
|
33
|
+
static get observedAttributes() {
|
|
34
|
+
return ['variant', 'title', 'dismissible', 'duration', 'icon', 'open'];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private _dismissTimer: ReturnType<typeof setTimeout> | null = null;
|
|
38
|
+
|
|
39
|
+
template() {
|
|
40
|
+
const variant = this.getAttribute('variant') || 'info';
|
|
41
|
+
const title = this.getAttribute('title') || '';
|
|
42
|
+
const dismissible = this.hasAttribute('dismissible');
|
|
43
|
+
const showIcon = this.getAttribute('icon') !== 'false';
|
|
44
|
+
const open = !this.hasAttribute('open') || this.getAttribute('open') !== 'false';
|
|
45
|
+
|
|
46
|
+
return `
|
|
47
|
+
<style>
|
|
48
|
+
:host { display: block; font-family: var(--nc-font-family); }
|
|
49
|
+
|
|
50
|
+
.alert {
|
|
51
|
+
display: ${open ? 'flex' : 'none'};
|
|
52
|
+
align-items: flex-start;
|
|
53
|
+
gap: var(--nc-spacing-sm);
|
|
54
|
+
padding: var(--nc-spacing-md) var(--nc-spacing-lg);
|
|
55
|
+
border-radius: var(--nc-radius-md, 8px);
|
|
56
|
+
border: 1px solid transparent;
|
|
57
|
+
line-height: 1.5;
|
|
58
|
+
animation: nc-alert-in 0.2s ease;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@keyframes nc-alert-in {
|
|
62
|
+
from { opacity: 0; transform: translateY(-4px); }
|
|
63
|
+
to { opacity: 1; transform: translateY(0); }
|
|
64
|
+
}
|
|
65
|
+
.alert.out {
|
|
66
|
+
animation: nc-alert-out 0.18s ease forwards;
|
|
67
|
+
}
|
|
68
|
+
@keyframes nc-alert-out {
|
|
69
|
+
to { opacity: 0; transform: scale(0.97); }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.alert--info { background: #eff6ff; color: #1e40af; border-color: #93c5fd; }
|
|
73
|
+
.alert--success { background: #f0fdf4; color: #166534; border-color: #86efac; }
|
|
74
|
+
.alert--warning { background: #fffbeb; color: #92400e; border-color: #fcd34d; }
|
|
75
|
+
.alert--danger { background: #fef2f2; color: #991b1b; border-color: #fca5a5; }
|
|
76
|
+
.alert--neutral { background: var(--nc-bg-secondary); color: var(--nc-text); border-color: var(--nc-border); }
|
|
77
|
+
|
|
78
|
+
.alert__icon { flex-shrink: 0; margin-top: 1px; }
|
|
79
|
+
|
|
80
|
+
.alert__body { flex: 1; font-size: var(--nc-font-size-sm); }
|
|
81
|
+
|
|
82
|
+
.alert__title {
|
|
83
|
+
font-weight: var(--nc-font-weight-semibold);
|
|
84
|
+
font-size: var(--nc-font-size-base);
|
|
85
|
+
margin-bottom: 2px;
|
|
86
|
+
display: block;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.alert__close {
|
|
90
|
+
background: none;
|
|
91
|
+
border: none;
|
|
92
|
+
cursor: pointer;
|
|
93
|
+
flex-shrink: 0;
|
|
94
|
+
padding: 2px;
|
|
95
|
+
color: inherit;
|
|
96
|
+
opacity: 0.5;
|
|
97
|
+
transition: opacity var(--nc-transition-fast);
|
|
98
|
+
display: flex;
|
|
99
|
+
line-height: 1;
|
|
100
|
+
border-radius: var(--nc-radius-sm, 4px);
|
|
101
|
+
}
|
|
102
|
+
.alert__close:hover { opacity: 1; }
|
|
103
|
+
</style>
|
|
104
|
+
<div class="alert alert--${variant}" role="alert" aria-live="polite">
|
|
105
|
+
${showIcon ? `<span class="alert__icon">${ICONS[variant] ?? ICONS.info}</span>` : ''}
|
|
106
|
+
<div class="alert__body">
|
|
107
|
+
${title ? `<strong class="alert__title">${title}</strong>` : ''}
|
|
108
|
+
<slot></slot>
|
|
109
|
+
</div>
|
|
110
|
+
${dismissible ? `
|
|
111
|
+
<button class="alert__close" type="button" aria-label="Close alert">
|
|
112
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 14 14" fill="none" width="14" height="14">
|
|
113
|
+
<path d="M2 2l10 10M12 2L2 12" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
|
|
114
|
+
</svg>
|
|
115
|
+
</button>` : ''}
|
|
116
|
+
</div>
|
|
117
|
+
`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
onMount() {
|
|
121
|
+
const closeBtn = this.$<HTMLButtonElement>('.alert__close');
|
|
122
|
+
if (closeBtn) {
|
|
123
|
+
closeBtn.addEventListener('click', () => this._dismiss());
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const duration = Number(this.getAttribute('duration') || 0);
|
|
127
|
+
if (duration > 0) {
|
|
128
|
+
this._dismissTimer = setTimeout(() => this._dismiss(), duration);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
onUnmount() {
|
|
133
|
+
if (this._dismissTimer) clearTimeout(this._dismissTimer);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private _dismiss() {
|
|
137
|
+
if (this._dismissTimer) { clearTimeout(this._dismissTimer); this._dismissTimer = null; }
|
|
138
|
+
const alertEl = this.$<HTMLElement>('.alert');
|
|
139
|
+
if (alertEl) {
|
|
140
|
+
alertEl.classList.add('out');
|
|
141
|
+
alertEl.addEventListener('animationend', () => {
|
|
142
|
+
alertEl.style.display = 'none';
|
|
143
|
+
this.dispatchEvent(new CustomEvent('dismiss', { bubbles: true, composed: true }));
|
|
144
|
+
}, { once: true });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
attributeChangedCallback(name: string, oldValue: string, newValue: string) {
|
|
149
|
+
if (oldValue !== newValue && this._mounted) { this.render(); this.onMount(); }
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
defineComponent('nc-alert', NcAlert);
|