@gsa-tts/graymatter-ui 0.3.2 → 0.3.4

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 CHANGED
@@ -1,16 +1,18 @@
1
1
  # @gsa-tts/graymatter-ui
2
2
 
3
+ A comprehensive UI component library built with Svelte 5, providing reusable components, layouts, and utilities for modern web applications.
4
+
3
5
  ## Package Responsibilities
4
6
 
5
- The GrayMatter UI package (`@gsa-tts/graymatter-ui`) is a UI component library. It provides reusable UI components, layouts, styles, and utilities.
7
+ The GrayMatter UI package (`@gsa-tts/graymatter-ui`) is a UI component library that provides:
6
8
 
7
9
  ### Primary Responsibilities:
8
10
 
9
- - Provide a comprehensive set of reusable UI components
10
- - Implement the design system using the tokens from `@gsa-tts/graymatter-style-tokens`
11
- - Provide layouts for consistent page structures
12
- - Offer utility functions for UI-related operations
13
- - Export components as both Svelte components and web components
11
+ - **Reusable UI Components** - A comprehensive set of accessible, customizable components
12
+ - **Design System Implementation** - Built using tokens from `@gsa-tts/graymatter-style-tokens`
13
+ - **Layout Components** - Consistent page structures and navigation patterns
14
+ - **Utility Functions** - Helper functions for UI-related operations
15
+ - **Cross-Framework Support** - Components available as both Svelte components and web components
14
16
 
15
17
  ### Package Boundaries:
16
18
 
@@ -21,91 +23,188 @@ The GrayMatter UI package (`@gsa-tts/graymatter-ui`) is a UI component library.
21
23
  - **SHOULD NOT** contain data fetching or API integration code
22
24
  - **SHOULD NOT** depend on application-specific packages
23
25
 
26
+ ## Installation
27
+
28
+ ```bash
29
+ npm install @gsa-tts/graymatter-ui @gsa-tts/graymatter-style-tokens
30
+ ```
31
+
32
+ **Note:** The `@gsa-tts/graymatter-style-tokens` package is required for proper styling and design tokens.
33
+
24
34
  ## Usage
25
35
 
26
36
  The UI package can be used in two ways:
27
37
 
28
- 1. As Svelte components (for Svelte/Astro applications)
29
- 2. As web components (for any framework or vanilla JS)
38
+ ### 1. Svelte Components (for Svelte/Astro applications)
30
39
 
31
- ## Component Documentation
40
+ ```svelte
41
+ <script>
42
+ import { DesktopSideNav, ProfileMenu } from '@gsa-tts/graymatter-ui';
43
+ </script>
44
+
45
+ <DesktopSideNav showAppIcons={true} ssrSelectedItem="api">
46
+ <!-- Sub navigation content -->
47
+ </DesktopSideNav>
48
+ ```
49
+
50
+ ### 2. Web Components (for any framework or vanilla JS)
51
+
52
+ ```html
53
+ <graymatter-desktop-side-nav show-app-icons="true" ssr-selected-item="api">
54
+ <!-- Sub navigation content -->
55
+ </graymatter-desktop-side-nav>
56
+ ```
57
+
58
+ ## Navigation URL Configuration
59
+
60
+ Navigation components (`DesktopSideNav`, `MobileBottomNav`) support flexible URL configuration:
61
+
62
+ ### Option 1: Environment Variables (Recommended)
63
+ ```bash
64
+ # .env
65
+ PUBLIC_CHAT_URL=https://your-chat-app.com
66
+ PUBLIC_CONSOLE_URL=https://your-console-app.com
67
+ PUBLIC_API_URL=https://your-api-app.com
68
+ PUBLIC_DISCOVER_URL=https://your-discover-page.com
69
+ ```
32
70
 
33
- ### ProfileMenu Component - Event-Driven Architecture
34
-
35
- The ProfileMenu component uses a custom event system to handle menu item actions, avoiding issues with function serialization in Astro apps.
36
-
37
- ### Usage
38
-
39
- #### 1. Define Menu Items with Action Strings
40
-
41
- ```typescript
42
- const profileMenuData = {
43
- userMeta: {
44
- initials: 'ZW',
45
- },
46
- menuItems: [
47
- {
48
- label: 'Settings',
49
- icon: '/path/to/icon.svg',
50
- action: 'settings', // String identifier
51
- },
52
- {
53
- label: 'Log out',
54
- icon: '/path/to/icon.svg',
55
- action: 'logout', // String identifier
56
- },
57
- ],
58
- };
71
+ ### Option 2: Component Props (Override Environment)
72
+ ```svelte
73
+ <DesktopSideNav
74
+ showAppIcons={true}
75
+ apiUrl="https://custom-api.com"
76
+ chatUrl="https://custom-chat.com"
77
+ consoleUrl="https://custom-console.com"
78
+ discoverUrl="https://custom-discover.com"
79
+ >
80
+ <!-- Sub navigation content -->
81
+ </DesktopSideNav>
59
82
  ```
60
83
 
61
- #### 2. Listen for Profile Menu Actions
84
+ ### Option 3: Mixed Approach
85
+ ```svelte
86
+ <DesktopSideNav
87
+ showAppIcons={true}
88
+ apiUrl="https://custom-api.com"
89
+ <!-- chatUrl, consoleUrl, discoverUrl will use environment variables -->
90
+ >
91
+ <!-- Sub navigation content -->
92
+ </DesktopSideNav>
93
+ ```
94
+
95
+ **Priority Order:** Component props → Environment variables → Fallback (`#`)
96
+
97
+ ## Available Components
98
+
99
+ ### Web Components (Universal - Any Framework)
100
+
101
+ All components with `.webcomponent.svelte` extension are available as web components:
62
102
 
63
- ```typescript
64
- // In your app's main layout or component
65
- window.addEventListener('profileMenuAction', (event) => {
66
- const { action, userMeta, timestamp } = event.detail;
103
+ - `graymatter-desktop-side-nav` - Desktop sidebar navigation
104
+ - `graymatter-mobile-top-nav` - Mobile header navigation
105
+ - `graymatter-mobile-bottom-nav` - Mobile bottom navigation bar
106
+ - `graymatter-mobile-side-menu` - Mobile slide-out navigation menu
107
+ - `graymatter-desktop-header` - Desktop header component
108
+ - `graymatter-button` - Accessible button component
109
+ - `graymatter-logo` - Brand logo component
110
+
111
+ ### Svelte 5 Components
112
+
113
+ Available for Svelte, SvelteKit, and Astro applications:
114
+
115
+ ```javascript
116
+ import {
117
+ // Navigation Components
118
+ DesktopSideNav,
119
+ MobileTopNav,
120
+ MobileBottomNav,
121
+ MobileSideMenu,
122
+ DesktopHeader,
123
+
124
+ // UI Components
125
+ Button,
126
+ Logo,
127
+ ProfileMenu,
128
+
129
+ // Utility Components
130
+ UsaBanner,
131
+ UsaSkipNav,
132
+ NavigationInitializer,
67
133
 
68
- switch (action) {
69
- case 'settings':
70
- // Handle settings action
71
- console.log('Settings clicked for user:', userMeta);
72
- break;
73
- case 'logout':
74
- // Handle logout action
75
- console.log('Logout clicked for user:', userMeta);
76
- break;
77
- default:
78
- console.warn('Unknown profile menu action:', action);
79
- }
80
- });
134
+ // Icon Components
135
+ // (all icons from ./icons/index.js)
136
+ } from '@gsa-tts/graymatter-ui/components';
81
137
  ```
82
138
 
83
- ### Event Details
139
+ ### Astro Components
140
+
141
+ Available for Astro applications:
142
+
143
+ ```javascript
144
+ import {
145
+ Head,
146
+ BaseLayout,
147
+ GlobalAppLayout
148
+ } from '@gsa-tts/graymatter-ui/layouts';
149
+ ```
150
+
151
+ ## Component Categories
152
+
153
+ ### Navigation Components
154
+ - **DesktopSideNav** - Desktop sidebar navigation with external control support
155
+ - **MobileTopNav** - Mobile header navigation
156
+ - **MobileBottomNav** - Mobile bottom navigation bar
157
+ - **MobileSideMenu** - Mobile slide-out navigation menu
84
158
 
85
- The `profileMenuAction` event includes:
159
+ ### Layout Components
160
+ - **GlobalAppLayout** - Main application layout wrapper
161
+ - **BaseLayout** - Base page layout structure
86
162
 
87
- - **action**: String identifier for the menu item action
88
- - **userMeta**: User metadata object
89
- - **timestamp**: When the action was triggered
163
+ ### UI Components
164
+ - **ProfileMenu** - User profile dropdown menu with event-driven actions
165
+ - **Button** - Accessible button component with multiple variants
166
+ - **Logo** - Brand logo component
167
+
168
+ ### Utility Components
169
+ - **UsaBanner** - Government banner component
170
+ - **UsaSkipNav** - Skip navigation link for accessibility
171
+
172
+ ## Key Features
173
+
174
+ ### Event-Driven Architecture
175
+ Many components use custom events for external control and communication:
176
+
177
+ - **DesktopSideNav** - External control via `graymatter-desktop-nav-control` events
178
+ - **ProfileMenu** - Action handling via `profileMenuAction` events
179
+
180
+ ### Cross-App Communication
181
+ Components support communication between different applications:
182
+
183
+ - **Navigation Control** - Control desktop navigation from external apps
184
+ - **Event Bubbling** - Events work across Shadow DOM boundaries
185
+
186
+ ### Accessibility
187
+ - **WCAG 2.1 AA Compliant** - Built with accessibility in mind
188
+ - **Keyboard Navigation** - Full keyboard support
189
+ - **Screen Reader Support** - Proper ARIA labels and roles
190
+
191
+ ## Component Documentation
90
192
 
91
- ### Benefits
193
+ ### Navigation Control
194
+ - **[DesktopSideNav External Control](./NAVIGATION_CONTROL.md)** - Event-based control system for desktop navigation
92
195
 
93
- - ✅ **No serialization issues** - Works with both Astro and Svelte apps
94
- - **Type safe** - No runtime function evaluation
95
- - ✅ **Secure** - No `new Function()` usage
96
- - ✅ **Debuggable** - Clear event flow
97
- - ✅ **Flexible** - Each app can handle actions differently
98
- - ✅ **Shadow DOM compatible** - Events bubble through web component boundaries
196
+ ### Component-Specific Documentation
197
+ - **[ProfileMenu Component](./PROFILE_MENU.md)** - Event-driven profile menu with action handling
99
198
 
100
- ### Shadow DOM & Web Component Support
199
+ ## Framework Support
101
200
 
102
- The ProfileMenu component is designed to work in both regular DOM and Shadow DOM contexts:
201
+ - **Svelte 5** - Native Svelte components
202
+ - **Astro** - Full support with client-side hydration
203
+ - **React/Vue/Angular** - Via web components
204
+ - **Vanilla JavaScript** - Via web components
103
205
 
104
- - **Regular DOM**: Events bubble up to `window` as expected
105
- - **Shadow DOM**: Events are configured with `bubbles: true` and `composed: true` to cross Shadow DOM boundaries
106
- - **Web Components**: Events are dispatched from the component element to ensure proper bubbling
206
+ ## Browser Support
107
207
 
108
- This makes the component compatible with:
109
- - Astro apps using the component directly
110
- - Svelte apps using the web component version
111
- - Any other framework using the web component
208
+ - **Modern Browsers** - Chrome, Firefox, Safari, Edge (latest 2 versions)
209
+ - **Web Components** - Native support or polyfill required
210
+ - **Custom Events** - Native support in all modern browsers