@nysds/mcp-server 1.16.0-alpha4 → 1.16.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 +114 -63
- package/data/guides/fonts.md +77 -0
- package/data/guides/form-validation.md +169 -0
- package/data/guides/frameworks/angular.md +71 -0
- package/data/guides/frameworks/dotnet.md +42 -0
- package/data/guides/frameworks/drupal.md +39 -0
- package/data/guides/frameworks/react.md +45 -0
- package/data/guides/frameworks/vanilla.md +45 -0
- package/data/guides/installation.md +73 -0
- package/data/guides/page-structure.md +160 -0
- package/data/guides/styles.md +48 -0
- package/dist/lib/cem-parser.d.ts +6 -0
- package/dist/lib/cem-parser.d.ts.map +1 -1
- package/dist/lib/cem-parser.js +18 -9
- package/dist/lib/format.d.ts +22 -0
- package/dist/lib/format.d.ts.map +1 -0
- package/dist/lib/format.js +33 -0
- package/dist/prompts/nysds-mode.d.ts.map +1 -1
- package/dist/prompts/nysds-mode.js +17 -8
- package/dist/resources/guides.d.ts.map +1 -1
- package/dist/resources/guides.js +22 -26
- package/dist/tools/component-tools.d.ts +3 -5
- package/dist/tools/component-tools.d.ts.map +1 -1
- package/dist/tools/component-tools.js +51 -85
- package/dist/tools/guide-tools.d.ts +9 -0
- package/dist/tools/guide-tools.d.ts.map +1 -0
- package/dist/tools/guide-tools.js +78 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +4 -0
- package/dist/tools/token-tools.d.ts +2 -5
- package/dist/tools/token-tools.d.ts.map +1 -1
- package/dist/tools/token-tools.js +88 -108
- package/dist/tools/utility-tools.d.ts +8 -0
- package/dist/tools/utility-tools.d.ts.map +1 -0
- package/dist/tools/utility-tools.js +282 -0
- package/dist/tools/validation-tools.d.ts +1 -2
- package/dist/tools/validation-tools.d.ts.map +1 -1
- package/dist/tools/validation-tools.js +1 -163
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -3,40 +3,50 @@
|
|
|
3
3
|
MCP (Model Context Protocol) server for the New York State Design System. Exposes NYSDS components, design tokens, and documentation to AI assistants.
|
|
4
4
|
|
|
5
5
|
> [!WARNING]
|
|
6
|
-
> This MCP server is a work-in-progress and the current results are
|
|
6
|
+
> This MCP server is a work-in-progress and the current tool results are being refined. The server is functional, but the quality of the output depends on the robustness of the underlying documentation, and we're enhancing component JSDoc with patterns, accessibility guidance, and usage rules based on guidance from ["Effective Writing for AI" by Benny Powers](https://bennypowers.dev/cem/docs/mcp/writing-descriptions/).
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Getting Started
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
> This package is not yet published to npm. You must clone the repository and build locally until it is.
|
|
10
|
+
No installation is required. The MCP server runs on-demand via `npx` — your AI assistant downloads and starts it automatically when you add the configuration below. You just need [Node.js](https://nodejs.org/) (v18 or later) installed on your machine.
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
Jump to the configuration for your assistant:
|
|
13
|
+
- [GitHub Copilot](#github-copilot)
|
|
14
|
+
- [Claude Desktop](#claude-desktop)
|
|
15
|
+
- [Claude Code](#claude-code)
|
|
16
|
+
- [Cursor](#cursor)
|
|
17
|
+
- [Gemini CLI](#gemini-cli)
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
### Using the Next Channel
|
|
20
|
+
|
|
21
|
+
To pull in the latest bleeding-edge changes before they hit the stable release, point to the `next` dist-tag by replacing `@nysds/mcp-server` with `@nysds/mcp-server@next` in any of the configurations below. For example:
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
"args": ["-y", "@nysds/mcp-server@next"]
|
|
25
|
+
```
|
|
19
26
|
|
|
20
|
-
|
|
21
|
-
git checkout feature/mcp-server
|
|
27
|
+
To go back to stable, just remove `@next`.
|
|
22
28
|
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
> [!NOTE]
|
|
30
|
+
> Next releases may include breaking changes, incomplete features, or components not fully supported. They're useful for previewing upcoming work, but stick with the stable channel for production use.
|
|
25
31
|
|
|
26
|
-
|
|
27
|
-
npm run build --workspace=packages/mcp-server
|
|
32
|
+
### Optional: Local Installation
|
|
28
33
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
If you prefer to install the server locally — for example, to use the [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector) or to pin a specific version — you can install it globally:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install -g @nysds/mcp-server
|
|
38
|
+
nysds-mcp
|
|
32
39
|
```
|
|
33
40
|
|
|
34
|
-
|
|
41
|
+
Or run it directly without installing:
|
|
35
42
|
|
|
36
|
-
|
|
43
|
+
```bash
|
|
44
|
+
npx -y @nysds/mcp-server
|
|
45
|
+
```
|
|
37
46
|
|
|
38
|
-
|
|
39
|
-
|
|
47
|
+
## Connecting to Your AI Assistant
|
|
48
|
+
|
|
49
|
+
Each assistant has its own configuration format, but they all follow the same pattern: tell the assistant how to start the server (via `npx`), and it handles the rest.
|
|
40
50
|
|
|
41
51
|
### GitHub Copilot
|
|
42
52
|
|
|
@@ -46,8 +56,8 @@ MCP support in GitHub Copilot is available in VS Code. Add to your VS Code setti
|
|
|
46
56
|
{
|
|
47
57
|
"servers": {
|
|
48
58
|
"nysds": {
|
|
49
|
-
"command": "
|
|
50
|
-
"args": ["
|
|
59
|
+
"command": "npx",
|
|
60
|
+
"args": ["-y", "@nysds/mcp-server"]
|
|
51
61
|
}
|
|
52
62
|
}
|
|
53
63
|
}
|
|
@@ -59,15 +69,15 @@ See the [Copilot MCP documentation](https://docs.github.com/en/copilot/using-git
|
|
|
59
69
|
|
|
60
70
|
Add to your Claude Desktop configuration:
|
|
61
71
|
|
|
62
|
-
- macOS:
|
|
63
|
-
- Windows:
|
|
72
|
+
- macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
73
|
+
- Windows: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
64
74
|
|
|
65
75
|
```json
|
|
66
76
|
{
|
|
67
77
|
"mcpServers": {
|
|
68
78
|
"nysds": {
|
|
69
|
-
"command": "
|
|
70
|
-
"args": ["
|
|
79
|
+
"command": "npx",
|
|
80
|
+
"args": ["-y", "@nysds/mcp-server"]
|
|
71
81
|
}
|
|
72
82
|
}
|
|
73
83
|
}
|
|
@@ -81,8 +91,8 @@ Add to your project's `.mcp.json`:
|
|
|
81
91
|
{
|
|
82
92
|
"mcpServers": {
|
|
83
93
|
"nysds": {
|
|
84
|
-
"command": "
|
|
85
|
-
"args": ["
|
|
94
|
+
"command": "npx",
|
|
95
|
+
"args": ["-y", "@nysds/mcp-server"]
|
|
86
96
|
}
|
|
87
97
|
}
|
|
88
98
|
}
|
|
@@ -98,32 +108,55 @@ Add to your Cursor MCP settings (`.cursor/mcp.json`):
|
|
|
98
108
|
{
|
|
99
109
|
"mcpServers": {
|
|
100
110
|
"nysds": {
|
|
101
|
-
"command": "
|
|
102
|
-
"args": ["
|
|
111
|
+
"command": "npx",
|
|
112
|
+
"args": ["-y", "@nysds/mcp-server"]
|
|
103
113
|
}
|
|
104
114
|
}
|
|
105
115
|
}
|
|
106
116
|
```
|
|
107
117
|
|
|
118
|
+
### Gemini CLI
|
|
119
|
+
|
|
120
|
+
Add to your Gemini CLI settings file (`~/.gemini/settings.json`) or your project's `.gemini/settings.json`:
|
|
121
|
+
|
|
122
|
+
```json
|
|
123
|
+
{
|
|
124
|
+
"mcpServers": {
|
|
125
|
+
"nysds": {
|
|
126
|
+
"command": "npx",
|
|
127
|
+
"args": ["-y", "@nysds/mcp-server"]
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
See the [Gemini CLI documentation](https://github.com/google-gemini/gemini-cli) for the latest setup instructions.
|
|
134
|
+
|
|
108
135
|
## Available Tools
|
|
109
136
|
|
|
110
|
-
###
|
|
137
|
+
### Components
|
|
138
|
+
|
|
139
|
+
| Tool | Description |
|
|
140
|
+
|------|-------------|
|
|
141
|
+
| `find_components` | Search for components by name/description, or list all (omit query) |
|
|
142
|
+
| `get_component` | Full documentation for a specific component. Use `includeExamples: true` for code examples. |
|
|
143
|
+
| `validate_component_api` | Validate that attributes/properties are valid for a component |
|
|
144
|
+
|
|
145
|
+
### Design Tokens
|
|
111
146
|
|
|
112
147
|
| Tool | Description |
|
|
113
148
|
|------|-------------|
|
|
114
|
-
| `
|
|
115
|
-
| `
|
|
116
|
-
| `
|
|
117
|
-
| `
|
|
118
|
-
| `get_usage_guide` | Installation and usage patterns |
|
|
149
|
+
| `get_tokens` | Get tokens, categories, or agency themes. Filter by category or layer. |
|
|
150
|
+
| `find_tokens` | Search tokens by CSS variable name, value, or description |
|
|
151
|
+
| `get_token_info` | Detailed info for a specific token with optional context validation |
|
|
152
|
+
| `get_token_graph` | Token dependency graph showing references and usage |
|
|
119
153
|
|
|
120
|
-
###
|
|
154
|
+
### Styles & Guides
|
|
121
155
|
|
|
122
156
|
| Tool | Description |
|
|
123
157
|
|------|-------------|
|
|
124
|
-
| `
|
|
125
|
-
| `
|
|
126
|
-
| `find_tokens` | Search tokens by name/value |
|
|
158
|
+
| `get_utility_classes` | Grid, flexbox, spacing, display, and typography utility classes |
|
|
159
|
+
| `get_guide` | Guides for installation, forms, styles, fonts, page structure, or framework setup (angular, react, dotnet, drupal, vanilla). Angular, React, .NET, and Drupal guides are currently untested. |
|
|
127
160
|
|
|
128
161
|
## Available Resources
|
|
129
162
|
|
|
@@ -131,7 +164,13 @@ Add to your Cursor MCP settings (`.cursor/mcp.json`):
|
|
|
131
164
|
|-----|-------------|
|
|
132
165
|
| `nysds://components` | Component overview list |
|
|
133
166
|
| `nysds://component/{tag}` | Individual component docs |
|
|
134
|
-
| `nysds://tokens` | All design tokens |
|
|
167
|
+
| `nysds://tokens` | All design tokens with CSS variables and descriptions |
|
|
168
|
+
| `nysds://tokens/css` | Raw tokens.css file content |
|
|
169
|
+
| `nysds://tokens/graph` | Token dependency graph with stats |
|
|
170
|
+
| `nysds://tokens/color` | Color tokens only |
|
|
171
|
+
| `nysds://tokens/font` | Typography tokens |
|
|
172
|
+
| `nysds://tokens/space` | Spacing tokens |
|
|
173
|
+
| `nysds://tokens/size` | Size tokens |
|
|
135
174
|
| `nysds://installation` | Installation guide |
|
|
136
175
|
|
|
137
176
|
## Prompts
|
|
@@ -142,28 +181,40 @@ Add to your Cursor MCP settings (`.cursor/mcp.json`):
|
|
|
142
181
|
|
|
143
182
|
## Example Prompts
|
|
144
183
|
|
|
145
|
-
Once configured, you can ask your AI assistant
|
|
184
|
+
Once configured, you can ask your AI assistant to help you build real applications with the design system.
|
|
185
|
+
|
|
186
|
+
**Building applications from requirements:**
|
|
187
|
+
|
|
188
|
+
> Read the PDF from this folder and create a PRD for a multi-step front end application. Use the NYS Design System. Build with Vite and TypeScript. Break up the tasks into a step-by-step list. Before you start, ask any clarifying questions to do this task well.
|
|
189
|
+
|
|
190
|
+
> Build out a newsletter signup form using the NYS Design System. Use existing DS components where possible. Where not, build new components using the same approach as existing components, and style with appropriate NYSDS design tokens and utility classes. Afterward, perform a gap analysis that documents everything not in the design system that was created.
|
|
191
|
+
|
|
192
|
+
**Scaffolding and setup:**
|
|
193
|
+
|
|
194
|
+
> Set up a new Vite project with TypeScript and install the NYS Design System. Configure it with the correct fonts, tokens, and page structure. Show me a working hello world page that follows the NYSDS page layout guide.
|
|
195
|
+
|
|
196
|
+
> I have an existing .NET Razor Pages app. Walk me through integrating NYSDS components into it step by step.
|
|
197
|
+
|
|
198
|
+
**Building pages and features:**
|
|
199
|
+
|
|
200
|
+
> Build a search results page with a text input, filters using checkboxes and selects, and a results list. Use NYSDS components for all form elements and follow the grid system for layout.
|
|
201
|
+
|
|
202
|
+
> Create an accessible multi-step wizard form for a permit application with validation on each step. Use NYSDS form components and show error states using the design system's error patterns.
|
|
203
|
+
|
|
204
|
+
**Working with design tokens and theming:**
|
|
205
|
+
|
|
206
|
+
> I'm building a page for the Department of Health. Show me how to apply their agency theme using NYSDS tokens, and build a dashboard header that uses the correct brand colors.
|
|
207
|
+
|
|
208
|
+
> Show me all the spacing tokens available and explain the scale. Then refactor this layout to use NYSDS spacing tokens instead of hardcoded values.
|
|
209
|
+
|
|
210
|
+
**Code review and validation:**
|
|
146
211
|
|
|
147
|
-
|
|
148
|
-
- "What NYSDS components are available for forms?"
|
|
149
|
-
- "Show me the documentation for the nys-button component"
|
|
150
|
-
- "What properties does nys-alert support?"
|
|
212
|
+
> Review this HTML page and identify everywhere I'm using NYSDS components incorrectly — wrong attributes, missing required properties, or deprecated patterns.
|
|
151
213
|
|
|
152
|
-
|
|
153
|
-
- "Create a contact form using NYSDS components with fields for name, email, and message"
|
|
154
|
-
- "Build a page header with the global header component and navigation"
|
|
155
|
-
- "Add form validation to this input using NYSDS error message components"
|
|
214
|
+
> Check if I'm using the right token layers. I want to make sure my component-level styles reference the correct semantic tokens instead of raw values.
|
|
156
215
|
|
|
157
|
-
**
|
|
158
|
-
- "What color tokens are available in NYSDS?"
|
|
159
|
-
- "Show me the spacing tokens I should use for consistent layouts"
|
|
160
|
-
- "What's the correct token for the primary brand color?"
|
|
216
|
+
**Exploring the system:**
|
|
161
217
|
|
|
162
|
-
|
|
163
|
-
- "How do I set up NYSDS components in my Angular project?"
|
|
164
|
-
- "Show me how to use nys-button in React"
|
|
165
|
-
- "What's the recommended way to integrate NYSDS with Vue?"
|
|
218
|
+
> What NYSDS components are available for forms? Show me the documentation for each one with code examples.
|
|
166
219
|
|
|
167
|
-
|
|
168
|
-
- "Is this the correct way to use the nys-select component?"
|
|
169
|
-
- "Check if I'm using valid attributes on this nys-checkbox"
|
|
220
|
+
> Show me the token dependency graph for the primary color. I want to understand how the base, semantic, and component layers connect.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# NYSDS Font Setup Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
NYSDS uses proprietary fonts that are licensed for New York State government use. These fonts are distributed through a private repository.
|
|
6
|
+
|
|
7
|
+
## Obtaining Fonts
|
|
8
|
+
|
|
9
|
+
The NYSDS font package is available through a private npm registry. Contact the NYSDS team for access:
|
|
10
|
+
|
|
11
|
+
1. Request access to the private font repository
|
|
12
|
+
2. Configure your npm to use the private registry
|
|
13
|
+
3. Install the font package
|
|
14
|
+
|
|
15
|
+
## Manual Installation
|
|
16
|
+
|
|
17
|
+
If you have the font files:
|
|
18
|
+
|
|
19
|
+
1. Place font files in your project (e.g., `/assets/fonts/`)
|
|
20
|
+
2. Include the font CSS in your stylesheet
|
|
21
|
+
3. The fonts will be loaded automatically when using NYSDS styles
|
|
22
|
+
|
|
23
|
+
### Directory Structure
|
|
24
|
+
```
|
|
25
|
+
/assets/fonts/
|
|
26
|
+
├── proxima-nova/
|
|
27
|
+
│ ├── proxima-nova-regular.woff2
|
|
28
|
+
│ ├── proxima-nova-medium.woff2
|
|
29
|
+
│ ├── proxima-nova-semibold.woff2
|
|
30
|
+
│ └── proxima-nova-bold.woff2
|
|
31
|
+
└── d-din/
|
|
32
|
+
├── d-din-regular.woff2
|
|
33
|
+
└── d-din-bold.woff2
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Font Tokens
|
|
37
|
+
|
|
38
|
+
NYSDS provides the following font family tokens:
|
|
39
|
+
|
|
40
|
+
| Token | Description | Usage |
|
|
41
|
+
|-------|-------------|-------|
|
|
42
|
+
| `--nys-font-body` | Body text font | Paragraphs, general content |
|
|
43
|
+
| `--nys-font-heading` | Heading font | h1-h6 elements |
|
|
44
|
+
| `--nys-font-ui` | UI font | Buttons, labels, form elements |
|
|
45
|
+
| `--nys-font-display` | Display font | Large headlines, hero text |
|
|
46
|
+
| `--nys-font-brand` | Brand font | Brand-specific usage |
|
|
47
|
+
| `--nys-font-alt` | Alternative font | Secondary content |
|
|
48
|
+
|
|
49
|
+
### Usage Example
|
|
50
|
+
```css
|
|
51
|
+
.custom-heading {
|
|
52
|
+
font-family: var(--nys-font-heading);
|
|
53
|
+
font-weight: 600;
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Font Preloading
|
|
58
|
+
|
|
59
|
+
For optimal performance, preload critical fonts in your HTML head:
|
|
60
|
+
|
|
61
|
+
```html
|
|
62
|
+
<link rel="preload" href="/assets/fonts/proxima-nova/proxima-nova-regular.woff2" as="font" type="font/woff2" crossorigin>
|
|
63
|
+
<link rel="preload" href="/assets/fonts/proxima-nova/proxima-nova-semibold.woff2" as="font" type="font/woff2" crossorigin>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Fallback Fonts
|
|
67
|
+
|
|
68
|
+
NYSDS includes system font fallbacks. If custom fonts are unavailable, the design system will gracefully degrade to:
|
|
69
|
+
|
|
70
|
+
- **Sans-serif:** -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial
|
|
71
|
+
- **Monospace:** "SF Mono", Consolas, "Liberation Mono", Menlo, monospace
|
|
72
|
+
|
|
73
|
+
## Getting Access
|
|
74
|
+
|
|
75
|
+
To request access to the NYSDS font package, contact the NYSDS team through:
|
|
76
|
+
- The NYS Digital Services team
|
|
77
|
+
- Your agency's designated NYSDS contact
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# NYSDS Form Validation Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
NYSDS form components include built-in validation support using the `showError` and `errorMessage` properties. All form components integrate with ElementInternals for native form validation.
|
|
6
|
+
|
|
7
|
+
## Error Display Properties
|
|
8
|
+
|
|
9
|
+
All NYSDS form components support these validation properties:
|
|
10
|
+
|
|
11
|
+
| Property | Type | Description |
|
|
12
|
+
|----------|------|-------------|
|
|
13
|
+
| `showError` | boolean | When true, displays the error state |
|
|
14
|
+
| `errorMessage` | string | The error message to display |
|
|
15
|
+
| `required` | boolean | Marks the field as required |
|
|
16
|
+
|
|
17
|
+
## Error Summary Pattern
|
|
18
|
+
|
|
19
|
+
Display an error summary at the top of forms with links to each field:
|
|
20
|
+
|
|
21
|
+
```html
|
|
22
|
+
<nys-alert type="danger" heading="Please correct the following errors">
|
|
23
|
+
<ul>
|
|
24
|
+
<li><a href="#email-field">Email address is required</a></li>
|
|
25
|
+
<li><a href="#phone-field">Phone number format is invalid</a></li>
|
|
26
|
+
</ul>
|
|
27
|
+
</nys-alert>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
This pattern:
|
|
31
|
+
- Appears at the top of the form after submission attempt
|
|
32
|
+
- Lists all errors with anchor links to the fields
|
|
33
|
+
- Helps users quickly navigate to problem areas
|
|
34
|
+
- Is essential for accessibility (screen reader users)
|
|
35
|
+
|
|
36
|
+
## Inline Error Pattern
|
|
37
|
+
|
|
38
|
+
Display errors directly on the form fields:
|
|
39
|
+
|
|
40
|
+
```html
|
|
41
|
+
<nys-textinput
|
|
42
|
+
id="email-field"
|
|
43
|
+
label="Email"
|
|
44
|
+
required
|
|
45
|
+
showError
|
|
46
|
+
errorMessage="Please enter a valid email address"
|
|
47
|
+
></nys-textinput>
|
|
48
|
+
|
|
49
|
+
<nys-select
|
|
50
|
+
id="state-field"
|
|
51
|
+
label="State"
|
|
52
|
+
required
|
|
53
|
+
showError
|
|
54
|
+
errorMessage="Please select a state"
|
|
55
|
+
></nys-select>
|
|
56
|
+
|
|
57
|
+
<nys-radiogroup
|
|
58
|
+
id="preference-field"
|
|
59
|
+
label="Contact Preference"
|
|
60
|
+
showError
|
|
61
|
+
errorMessage="Please select a contact preference"
|
|
62
|
+
>
|
|
63
|
+
<nys-radiobutton label="Email" value="email"></nys-radiobutton>
|
|
64
|
+
<nys-radiobutton label="Phone" value="phone"></nys-radiobutton>
|
|
65
|
+
</nys-radiogroup>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Complete Form Example
|
|
69
|
+
|
|
70
|
+
```html
|
|
71
|
+
<form id="contact-form" novalidate>
|
|
72
|
+
<!-- Error summary (hidden initially, shown on validation failure) -->
|
|
73
|
+
<nys-alert id="error-summary" type="danger" heading="Please correct the following errors" hidden>
|
|
74
|
+
<ul id="error-list"></ul>
|
|
75
|
+
</nys-alert>
|
|
76
|
+
|
|
77
|
+
<nys-textinput
|
|
78
|
+
id="name-field"
|
|
79
|
+
label="Full Name"
|
|
80
|
+
required
|
|
81
|
+
class="nys-margin-b-300"
|
|
82
|
+
></nys-textinput>
|
|
83
|
+
|
|
84
|
+
<nys-textinput
|
|
85
|
+
id="email-field"
|
|
86
|
+
label="Email Address"
|
|
87
|
+
type="email"
|
|
88
|
+
required
|
|
89
|
+
class="nys-margin-b-300"
|
|
90
|
+
></nys-textinput>
|
|
91
|
+
|
|
92
|
+
<nys-textarea
|
|
93
|
+
id="message-field"
|
|
94
|
+
label="Message"
|
|
95
|
+
required
|
|
96
|
+
class="nys-margin-b-400"
|
|
97
|
+
></nys-textarea>
|
|
98
|
+
|
|
99
|
+
<nys-button type="submit" label="Submit"></nys-button>
|
|
100
|
+
</form>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## JavaScript Validation Example
|
|
104
|
+
|
|
105
|
+
```javascript
|
|
106
|
+
const form = document.getElementById('contact-form');
|
|
107
|
+
const errorSummary = document.getElementById('error-summary');
|
|
108
|
+
const errorList = document.getElementById('error-list');
|
|
109
|
+
|
|
110
|
+
form.addEventListener('submit', (e) => {
|
|
111
|
+
e.preventDefault();
|
|
112
|
+
|
|
113
|
+
const errors = [];
|
|
114
|
+
|
|
115
|
+
// Validate each field
|
|
116
|
+
const nameField = document.getElementById('name-field');
|
|
117
|
+
if (!nameField.value) {
|
|
118
|
+
nameField.showError = true;
|
|
119
|
+
nameField.errorMessage = 'Full name is required';
|
|
120
|
+
errors.push({ id: 'name-field', message: 'Full name is required' });
|
|
121
|
+
} else {
|
|
122
|
+
nameField.showError = false;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const emailField = document.getElementById('email-field');
|
|
126
|
+
if (!emailField.value) {
|
|
127
|
+
emailField.showError = true;
|
|
128
|
+
emailField.errorMessage = 'Email address is required';
|
|
129
|
+
errors.push({ id: 'email-field', message: 'Email address is required' });
|
|
130
|
+
} else if (!isValidEmail(emailField.value)) {
|
|
131
|
+
emailField.showError = true;
|
|
132
|
+
emailField.errorMessage = 'Please enter a valid email address';
|
|
133
|
+
errors.push({ id: 'email-field', message: 'Please enter a valid email address' });
|
|
134
|
+
} else {
|
|
135
|
+
emailField.showError = false;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Show/hide error summary
|
|
139
|
+
if (errors.length > 0) {
|
|
140
|
+
errorList.innerHTML = errors
|
|
141
|
+
.map(err => `<li><a href="#${err.id}">${err.message}</a></li>`)
|
|
142
|
+
.join('');
|
|
143
|
+
errorSummary.hidden = false;
|
|
144
|
+
errorSummary.scrollIntoView({ behavior: 'smooth' });
|
|
145
|
+
} else {
|
|
146
|
+
errorSummary.hidden = true;
|
|
147
|
+
form.submit();
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Form Components with Validation Support
|
|
153
|
+
|
|
154
|
+
The following NYSDS components support `showError` and `errorMessage`:
|
|
155
|
+
|
|
156
|
+
- `nys-textinput` - Text input fields
|
|
157
|
+
- `nys-textarea` - Multi-line text areas
|
|
158
|
+
- `nys-select` - Dropdown selects
|
|
159
|
+
- `nys-radiogroup` - Radio button groups
|
|
160
|
+
- `nys-checkbox` - Checkboxes
|
|
161
|
+
- `nys-checkboxgroup` - Checkbox groups
|
|
162
|
+
- `nys-date` - Date pickers
|
|
163
|
+
|
|
164
|
+
## Accessibility Considerations
|
|
165
|
+
|
|
166
|
+
1. **Error summary links**: Include anchor links to fields for keyboard navigation
|
|
167
|
+
2. **Focus management**: Move focus to error summary or first error field on validation failure
|
|
168
|
+
3. **ARIA attributes**: NYSDS components automatically set `aria-invalid` and `aria-describedby`
|
|
169
|
+
4. **Clear error messages**: Use specific, actionable error text
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# NYSDS with Angular
|
|
2
|
+
|
|
3
|
+
> **Note:** Angular integration is currently untested. The guidance below is based on standard web component usage patterns and may require adjustments.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @nysds/components @nysds/styles
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Load styles
|
|
12
|
+
|
|
13
|
+
Add the NYSDS stylesheet to `angular.json`:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"projects": {
|
|
18
|
+
"your-app": {
|
|
19
|
+
"architect": {
|
|
20
|
+
"build": {
|
|
21
|
+
"options": {
|
|
22
|
+
"styles": [
|
|
23
|
+
"node_modules/@nysds/styles/dist/nysds-full.min.css",
|
|
24
|
+
"src/styles.css"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Use `nysds-full.min.css` for new projects (includes reset, typography, and utilities) or `nysds.min.css` for existing projects (CSS variables only).
|
|
35
|
+
|
|
36
|
+
## Configuration
|
|
37
|
+
|
|
38
|
+
Add `CUSTOM_ELEMENTS_SCHEMA` to your module so Angular allows custom element tags:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
|
|
42
|
+
|
|
43
|
+
@NgModule({
|
|
44
|
+
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
|
45
|
+
})
|
|
46
|
+
export class AppModule {}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
For standalone components:
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
|
53
|
+
|
|
54
|
+
@Component({
|
|
55
|
+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
|
56
|
+
template: `<nys-button label="Click me"></nys-button>`
|
|
57
|
+
})
|
|
58
|
+
export class MyComponent {}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
Import components in the component or module where they're used:
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import '@nysds/nys-button';
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
```html
|
|
70
|
+
<nys-button label="Click me"></nys-button>
|
|
71
|
+
```
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# NYSDS with .NET / Blazor
|
|
2
|
+
|
|
3
|
+
> **Note:** .NET / Blazor integration is currently untested. The guidance below is based on standard web component usage patterns and may require adjustments.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add the NYSDS scripts and styles to your layout file (e.g., `_Layout.cshtml` or `App.razor`).
|
|
8
|
+
|
|
9
|
+
Install via npm:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @nysds/components @nysds/styles
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Then reference in your layout:
|
|
16
|
+
|
|
17
|
+
```html
|
|
18
|
+
<head>
|
|
19
|
+
<!-- New project: includes reset, typography, and utility classes -->
|
|
20
|
+
<link rel="stylesheet" href="node_modules/@nysds/styles/dist/nysds-full.min.css" />
|
|
21
|
+
|
|
22
|
+
<!-- Existing project: CSS variables only -->
|
|
23
|
+
<!-- <link rel="stylesheet" href="node_modules/@nysds/styles/dist/nysds.min.css" /> -->
|
|
24
|
+
|
|
25
|
+
<script type="module" src="node_modules/@nysds/components/dist/nysds.es.js"></script>
|
|
26
|
+
</head>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage in Razor
|
|
30
|
+
|
|
31
|
+
```razor
|
|
32
|
+
<nys-button label="Click me"></nys-button>
|
|
33
|
+
<nys-alert type="info">This is an informational message.</nys-alert>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage in Blazor
|
|
37
|
+
|
|
38
|
+
Blazor treats unknown elements as custom elements by default. No additional configuration is needed:
|
|
39
|
+
|
|
40
|
+
```razor
|
|
41
|
+
<nys-button label="Submit" variant="filled"></nys-button>
|
|
42
|
+
```
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# NYSDS with Drupal
|
|
2
|
+
|
|
3
|
+
> **Note:** Drupal integration is currently untested. The guidance below is based on standard web component usage patterns and may require adjustments.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the packages:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @nysds/components @nysds/styles
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Add the NYSDS styles and scripts to your theme's `*.libraries.yml`:
|
|
14
|
+
|
|
15
|
+
```yaml
|
|
16
|
+
nysds:
|
|
17
|
+
css:
|
|
18
|
+
theme:
|
|
19
|
+
# New project: includes reset, typography, and utility classes
|
|
20
|
+
/node_modules/@nysds/styles/dist/nysds-full.min.css: { minified: true }
|
|
21
|
+
# Existing project: CSS variables only
|
|
22
|
+
# /node_modules/@nysds/styles/dist/nysds.min.css: { minified: true }
|
|
23
|
+
js:
|
|
24
|
+
/node_modules/@nysds/components/dist/nysds.es.js: { attributes: { type: module } }
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then attach the library in your theme's `.info.yml`:
|
|
28
|
+
|
|
29
|
+
```yaml
|
|
30
|
+
libraries:
|
|
31
|
+
- mytheme/nysds
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage in Twig
|
|
35
|
+
|
|
36
|
+
```twig
|
|
37
|
+
<nys-button label="{{ 'Click me'|t }}"></nys-button>
|
|
38
|
+
<nys-alert type="info">{{ 'This is an alert.'|t }}</nys-alert>
|
|
39
|
+
```
|