@gecko-ui-kit/vue 0.0.0-stage → 0.1.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.
@@ -0,0 +1,6 @@
1
+ import type { Component, Plugin } from 'vue';
2
+ /** Every component of the package by name. */
3
+ export const components: Record<string, Component>;
4
+ /** app.use(GeckoUI) registers every component by name; app.use(GeckoUI, { prefix: 'G' }) → <GButton>… */
5
+ export const GeckoUI: Plugin<[{ prefix?: string }?]>;
6
+ export {};
package/src/plugin.js ADDED
@@ -0,0 +1,27 @@
1
+ /* app.use(GeckoUI): registers every component of this package by its name (<Button>, <Rating>, <Modal>…),
2
+ so templates can use them without importing each one. { prefix: 'G' } gives <GButton>, <GRating>… */
3
+ import * as core from './core.js';
4
+ import * as basics from './basics.js';
5
+ import * as controls from './controls.js';
6
+ import * as forms from './forms.js';
7
+ import * as data from './data.js';
8
+ import * as actions from './actions.js';
9
+ import * as charts from './charts.js';
10
+ import * as text from './text.js';
11
+ import * as motion from './motion.js';
12
+ import * as effects from './effects.js';
13
+ import * as overlays from './overlays.js';
14
+ import * as shell from './shell.js';
15
+
16
+ const groups = [core, basics, controls, forms, data, actions, charts, text, motion, effects, overlays, shell];
17
+ const isComponent = (v) => !!v && typeof v === 'object' && (typeof v.setup === 'function' || typeof v.render === 'function') && typeof v.name === 'string';
18
+
19
+ /** Every component of the package by name: { Button, Rating, Modal, … }. */
20
+ export const components = Object.fromEntries(groups.flatMap((m) => Object.entries(m).filter(([k, v]) => /^[A-Z]/.test(k) && isComponent(v))));
21
+
22
+ /** Vue plugin: app.use(GeckoUI) or app.use(GeckoUI, { prefix: 'G' }). */
23
+ export const GeckoUI = {
24
+ install(app, { prefix = '' } = {}) {
25
+ for (const [name, c] of Object.entries(components)) app.component(prefix + name, c);
26
+ },
27
+ };
package/src/shell.d.ts ADDED
@@ -0,0 +1,210 @@
1
+ import type { Component, VNodeChild } from 'vue';
2
+ import type { GeckoComponent, IconLike, ModelProps } from './core.js';
3
+
4
+ /** A sub-page: [id, label] or [id, label, href], or { id, label, href }. */
5
+ export type ShellSub = [id: string, label: string, href?: string] | { id: string; label: string; href?: string };
6
+ export interface ShellItem {
7
+ /** Route id: the address is `${base}/${id}` unless href is given. */
8
+ id: string;
9
+ /** Text in the menu, breadcrumbs, tab bar and palette. */
10
+ label: string;
11
+ /** An icon name from @gecko-ui-kit/icons, a component or a VNode. */
12
+ icon?: IconLike;
13
+ /** Its own address (e.g. '/' for the home page). */
14
+ href?: string;
15
+ /** A number badge (hidden at 0) or a function giving it; it flashes when it changes. */
16
+ count?: number | (() => number);
17
+ /** Sub-pages: unfold under the item when it is open, and become tabs in <PageHeader>. */
18
+ subs?: ShellSub[];
19
+ /** A short line in the rail flyout and the palette. */
20
+ blurb?: string;
21
+ /** false: no sub-page tabs in <PageHeader> for this item. */
22
+ tabs?: boolean;
23
+ }
24
+ export interface ShellGroup {
25
+ /** Small heading over the group (optional). */
26
+ label?: string;
27
+ items: ShellItem[];
28
+ }
29
+ /** An account-menu row: '-' a line, { section } a heading, else an action. */
30
+ export type ShellMenuItem = '-' | { section: string } | { label: string; icon?: string; kbd?: string; danger?: boolean; run?: (button: HTMLElement) => void };
31
+ export interface ShellUser {
32
+ name: string;
33
+ /** Initials in the avatar (default: from the name). */
34
+ ini?: string;
35
+ /** Avatar colour: indigo teal rose amber violet green slate sky. */
36
+ tone?: string;
37
+ /** Second line, e.g. 'Manager'. */
38
+ role?: string;
39
+ /** Green dot. Default true. */
40
+ online?: boolean;
41
+ /** Rows in the account menu. */
42
+ menu?: ShellMenuItem[];
43
+ }
44
+ export interface ShellBrand {
45
+ name: string;
46
+ sub?: string;
47
+ /** An icon name, or your logo as a component or VNode. Default 'logo'. */
48
+ icon?: IconLike;
49
+ /** Where the brand links to (default: the home item). */
50
+ href?: string;
51
+ }
52
+ /** Every text the shell shows (English defaults); pass the ones you want to change. */
53
+ export interface ShellWords {
54
+ sidebar?: string; main?: string; collapse?: string; expand?: string; collapseTip?: string; expandTip?: string; account?: string; open?: string;
55
+ menu?: string; breadcrumb?: string; search?: string; searchPlaceholder?: string; searchKey?: string; theme?: string; themeTip?: string;
56
+ bell?: string; primary?: string; tabs?: string; more?: string; sections?: string; shortcuts?: string; replay?: string; searchPages?: string;
57
+ goTo?: string; toggleRail?: string; thisList?: string; close?: string;
58
+ }
59
+ /** What every part needs to know about the menu and where we are. */
60
+ export interface ShellNavProps {
61
+ /** Groups of menu items. */
62
+ nav: ShellGroup[];
63
+ /** Items pinned to the bottom (settings, help). */
64
+ end?: ShellItem[];
65
+ /** The current path, e.g. useRoute().path. It picks the current item and sub-page. */
66
+ path?: string;
67
+ /** Prefix for item addresses (e.g. '/app'). Default ''. */
68
+ base?: string;
69
+ /** Id of the home item (brand link). Default: the first item. */
70
+ home?: string;
71
+ /** Called with the address on a plain click of any link, and from menus, the palette and keys (e.g. router.push / navigateTo). */
72
+ onNavigate?: (href: string) => void;
73
+ /** The component links are drawn with (e.g. NuxtLink or RouterLink; it gets `to`). Default a plain <a href>. */
74
+ link?: Component | string;
75
+ /** Texts. */
76
+ words?: ShellWords;
77
+ }
78
+
79
+ /** What a template ref on <Sidebar> gives you. */
80
+ export interface SidebarHandle {
81
+ /** Collapse (true) or expand (false) with the motion. Call it from an event handler. */
82
+ setRail(rail: boolean): void;
83
+ isRail(): boolean;
84
+ /** The <aside>. */
85
+ readonly el: HTMLElement | null;
86
+ }
87
+ export interface SidebarProps extends ShellNavProps {
88
+ /** Top of the sidebar. */
89
+ brand?: ShellBrand;
90
+ /** Account button at the bottom. */
91
+ user?: ShellUser | null;
92
+ /** Prefix for saved choices: '<key>:pinned'. Default 'gecko'. */
93
+ storageKey?: string;
94
+ /** With nothing saved, narrower windows start as a rail. Default 1280. */
95
+ railBreakpoint?: number;
96
+ /** Phone layout at this width and below. Default 760. */
97
+ mobile?: number;
98
+ }
99
+ /** The main menu with pill, sub-pages, rail + flyout. Template ref → SidebarHandle. */
100
+ export const Sidebar: GeckoComponent<SidebarProps>;
101
+
102
+ export interface TopbarProps extends ShellNavProps {
103
+ /** Text for the first breadcrumb. */
104
+ crumbsRoot?: string;
105
+ /** { placeholder, onOpen } or false to hide the search button. */
106
+ search?: false | { placeholder?: string; onOpen?: () => void };
107
+ /** false hides the theme switch. */
108
+ theme?: boolean;
109
+ /** A bell with a number badge: it wiggles when count goes up. */
110
+ bell?: { count?: number; onClick?: (button: HTMLElement) => void } | null;
111
+ /** The main button on the right (icon only on phones). */
112
+ primary?: { label?: string; icon?: IconLike; tip?: string; run?: (button: HTMLElement) => void } | null;
113
+ /** Called by the search button when search.onOpen is not given. */
114
+ onSearch?: () => void;
115
+ /** Prefix for the saved theme: '<key>:theme'. Default 'gecko'. */
116
+ storageKey?: string;
117
+ }
118
+ /** The bar above the page. Default slot: extra buttons before the theme switch. Template ref: .$el is the <header>. */
119
+ export const Topbar: GeckoComponent<TopbarProps, { default?: () => VNodeChild }>;
120
+
121
+ export interface MobileTabbarProps extends ShellNavProps {
122
+ /** Ids of the items that get a tab (default: the first four); the rest go under “More”. */
123
+ tabbar?: string[];
124
+ }
125
+ /** The phone tab bar (hidden on wider screens). Template ref: .$el is the <nav>. */
126
+ export const MobileTabbar: GeckoComponent<MobileTabbarProps>;
127
+
128
+ /** A tab: { id, label, count, href } or [id, label, count?, href?]. */
129
+ export type PageTab = { id: string; label: string; count?: number; href?: string } | [id: string, label: string, count?: number, href?: string];
130
+ export interface PageHeaderProps extends ModelProps<string> {
131
+ /** The big title (its letters roll up, again when it changes). */
132
+ title: string;
133
+ /** Small coloured line above it (or the #eyebrow slot). */
134
+ eyebrow?: string;
135
+ /** A line of text under it (or the #sub slot). */
136
+ sub?: string;
137
+ /** Buttons on the right: use the #actions slot (a text here is shown as is). */
138
+ actions?: string;
139
+ /** Tabs under it. Inside AppShell the current item's sub-pages are used by themselves; false hides them. */
140
+ tabs?: PageTab[] | false;
141
+ /** Called with the id when a button tab (one without href) is clicked (after v-model is set). */
142
+ onTabChange?: (id: string) => void;
143
+ /** Number badges on the tabs: { tabId: n }. */
144
+ counts?: Record<string, number>;
145
+ /** sections: the tabs' name for screen readers. */
146
+ words?: ShellWords;
147
+ }
148
+ /** What a template ref on <PageHeader> gives you. */
149
+ export interface PageHeaderHandle {
150
+ /** The <header>. */
151
+ readonly el: HTMLElement | null;
152
+ }
153
+ /** The top of a page. v-model = the chosen button tab. Template ref → PageHeaderHandle. */
154
+ export const PageHeader: GeckoComponent<PageHeaderProps, { eyebrow?: () => VNodeChild; sub?: () => VNodeChild; actions?: () => VNodeChild }>;
155
+
156
+ /** A key of your own: shown under ?, run with the shell. */
157
+ export interface ShellKey { key: string; label: string; run?: (shell: ShellApi) => void }
158
+ /** A group at the top of the ⌘K palette. */
159
+ export interface ShellSearchGroup { label: string; items: Array<{ title: string; sub?: string; icon?: string; run?: () => void }> }
160
+ export interface AppShellProps extends ShellNavProps {
161
+ brand?: ShellBrand;
162
+ user?: ShellUser | null;
163
+ /** Topbar parts: search, theme, bell, primary (extra buttons: the #extra slot). */
164
+ top?: { search?: TopbarProps['search']; theme?: boolean; bell?: TopbarProps['bell']; primary?: TopbarProps['primary'] };
165
+ /** Text for the first breadcrumb. */
166
+ crumbsRoot?: string;
167
+ /** Ids of the items in the phone tab bar (default: the first four). */
168
+ tabbar?: string[];
169
+ /** Sub-pages as tabs in <PageHeader> (item.tabs overrides). Default true. */
170
+ tabs?: boolean;
171
+ /** Sidebar and topbar play in on load. Default true. */
172
+ intro?: boolean;
173
+ /** The built-in keys: ⌘K and / search, [ rail, ? list, Esc close. Default true. */
174
+ shortcuts?: boolean;
175
+ /** Your own single-key shortcuts, also listed under ?. */
176
+ keys?: ShellKey[];
177
+ /** Extra groups at the top of the ⌘K palette: (q) → [{ label, items: [{ title, sub, icon, run }] }]. */
178
+ search?: (query: string) => ShellSearchGroup[];
179
+ /** Prefix for saved choices: '<key>:pinned', '<key>:theme'. Default 'gecko'. */
180
+ storageKey?: string;
181
+ /** With nothing saved, narrower windows start as a rail. Default 1280. */
182
+ railBreakpoint?: number;
183
+ /** Phone layout at this width and below (also sets the overlays' config.mobile). Default 760. */
184
+ mobile?: number;
185
+ }
186
+ /** What useShell() gives inside <AppShell>: a reactive object (route and path follow the current path). */
187
+ export interface ShellApi {
188
+ /** The current item id (null when no item matches) and sub-page id ('' when none). */
189
+ readonly route: { page: string | null; sub: string };
190
+ readonly path: string | undefined;
191
+ /** Go somewhere (onNavigate, else a normal page load). */
192
+ navigate(href: string): void;
193
+ /** Open search (top.search.onOpen or the palette). */
194
+ palette(): void;
195
+ /** Open the keyboard shortcuts list. */
196
+ shortcuts(): void;
197
+ /** Play the intro again. */
198
+ intro(): void;
199
+ /** Collapse / expand the sidebar (from an event handler). */
200
+ setRail(rail: boolean): void;
201
+ isRail(): boolean;
202
+ }
203
+ /** The whole app frame around your page (default slot); #extra: buttons in the topbar before the theme switch. */
204
+ export const AppShell: GeckoComponent<AppShellProps, { default?: () => VNodeChild; extra?: () => VNodeChild }>;
205
+ /** Inside <AppShell> (call it in setup()): the shell's state and actions; null outside. */
206
+ export function useShell(): ShellApi | null;
207
+ /** A script for <head> that sets the saved theme and rail before the first paint. */
208
+ export function shellBootScript(options?: { storageKey?: string; railBreakpoint?: number }): string;
209
+
210
+ export {};