@trimble-oss/moduswebcomponents-mcp 1.0.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/dist/index.d.ts +2 -0
- package/dist/index.js +337 -0
- package/package.json +39 -0
- package/versions/1.0.0/component-docs/_all_components.json +56 -0
- package/versions/1.0.0/component-docs/modus-wc-autocomplete.json +415 -0
- package/versions/1.0.0/component-docs/modus-wc-date.json +227 -0
- package/versions/1.0.0/component-docs/modus-wc-dropdown-menu.json +164 -0
- package/versions/1.0.0/component-docs/modus-wc-logo.json +61 -0
- package/versions/1.0.0/component-docs/modus-wc-menu-item.json +165 -0
- package/versions/1.0.0/component-docs/modus-wc-menu.json +106 -0
- package/versions/1.0.0/component-docs/modus-wc-navbar.json +290 -0
- package/versions/1.0.0/component-docs/modus-wc-profile-menu.json +64 -0
- package/versions/1.0.0/component-docs/modus-wc-side-navigation.json +102 -0
- package/versions/1.0.0/component-docs/modus-wc-table.json +202 -0
- package/versions/1.0.0/component-docs/modus-wc-tooltip.json +94 -0
- package/versions/1.0.0/component-docs/modus-wc-typography.json +78 -0
- package/versions/1.0.0/docs/_all_docs.json +15 -0
- package/versions/1.0.0/docs/angular.mdx +374 -0
- package/versions/1.0.0/docs/getting-started.mdx +131 -0
- package/versions/1.0.7/component-docs/_all_components.json +55 -0
- package/versions/1.0.7/component-docs/modus-wc-autocomplete.json +405 -0
- package/versions/1.0.7/component-docs/modus-wc-table.json +202 -0
- package/versions/1.0.7/component-docs/modus-wc-tooltip.json +94 -0
- package/versions/1.0.7/docs/_all_docs.json +15 -0
- package/versions/1.0.7/docs/angular.mdx +374 -0
- package/versions/1.1.0/component-docs/_all_components.json +56 -0
- package/versions/1.1.0/component-docs/modus-wc-autocomplete.json +405 -0
- package/versions/1.1.0/component-docs/modus-wc-navbar.json +290 -0
- package/versions/1.1.0/component-docs/modus-wc-profile-menu.json +64 -0
- package/versions/1.1.0/component-docs/modus-wc-side-navigation.json +102 -0
- package/versions/1.1.0/component-docs/modus-wc-table.json +202 -0
- package/versions/1.1.0/component-docs/modus-wc-tooltip.json +94 -0
- package/versions/1.1.0/component-docs/modus-wc-typography.json +78 -0
- package/versions/1.1.0/docs/_all_docs.json +15 -0
- package/versions/1.1.0/docs/angular.mdx +374 -0
- package/versions/1.1.0/docs/getting-started.mdx +131 -0
- package/versions/1.1.1/component-docs/_all_components.json +56 -0
- package/versions/1.1.1/component-docs/modus-wc-autocomplete.json +405 -0
- package/versions/1.1.1/component-docs/modus-wc-navbar.json +290 -0
- package/versions/1.1.1/component-docs/modus-wc-profile-menu.json +64 -0
- package/versions/1.1.1/component-docs/modus-wc-side-navigation.json +102 -0
- package/versions/1.1.1/component-docs/modus-wc-table.json +202 -0
- package/versions/1.1.1/component-docs/modus-wc-tooltip.json +94 -0
- package/versions/1.1.1/component-docs/modus-wc-typography.json +78 -0
- package/versions/1.1.1/docs/_all_docs.json +15 -0
- package/versions/1.1.1/docs/angular.mdx +374 -0
- package/versions/1.1.1/docs/getting-started.mdx +131 -0
- package/versions/base/component-docs/_all_components.json +55 -0
- package/versions/base/component-docs/modus-wc-accordion.json +48 -0
- package/versions/base/component-docs/modus-wc-alert.json +112 -0
- package/versions/base/component-docs/modus-wc-autocomplete.json +397 -0
- package/versions/base/component-docs/modus-wc-avatar.json +83 -0
- package/versions/base/component-docs/modus-wc-badge.json +68 -0
- package/versions/base/component-docs/modus-wc-breadcrumbs.json +63 -0
- package/versions/base/component-docs/modus-wc-button-group.json +100 -0
- package/versions/base/component-docs/modus-wc-button.json +130 -0
- package/versions/base/component-docs/modus-wc-card.json +98 -0
- package/versions/base/component-docs/modus-wc-checkbox.json +149 -0
- package/versions/base/component-docs/modus-wc-chip.json +132 -0
- package/versions/base/component-docs/modus-wc-collapse.json +90 -0
- package/versions/base/component-docs/modus-wc-date.json +227 -0
- package/versions/base/component-docs/modus-wc-divider.json +85 -0
- package/versions/base/component-docs/modus-wc-dropdown-menu.json +154 -0
- package/versions/base/component-docs/modus-wc-file-dropzone.json +155 -0
- package/versions/base/component-docs/modus-wc-handle.json +135 -0
- package/versions/base/component-docs/modus-wc-icon.json +722 -0
- package/versions/base/component-docs/modus-wc-input-feedback.json +71 -0
- package/versions/base/component-docs/modus-wc-input-label.json +84 -0
- package/versions/base/component-docs/modus-wc-loader.json +65 -0
- package/versions/base/component-docs/modus-wc-logo.json +61 -0
- package/versions/base/component-docs/modus-wc-menu-item.json +173 -0
- package/versions/base/component-docs/modus-wc-menu.json +86 -0
- package/versions/base/component-docs/modus-wc-modal.json +108 -0
- package/versions/base/component-docs/modus-wc-navbar.json +280 -0
- package/versions/base/component-docs/modus-wc-number-input.json +219 -0
- package/versions/base/component-docs/modus-wc-pagination.json +103 -0
- package/versions/base/component-docs/modus-wc-panel.json +76 -0
- package/versions/base/component-docs/modus-wc-progress.json +86 -0
- package/versions/base/component-docs/modus-wc-radio.json +139 -0
- package/versions/base/component-docs/modus-wc-rating.json +117 -0
- package/versions/base/component-docs/modus-wc-select.json +159 -0
- package/versions/base/component-docs/modus-wc-side-navigation.json +102 -0
- package/versions/base/component-docs/modus-wc-skeleton.json +65 -0
- package/versions/base/component-docs/modus-wc-slider.json +163 -0
- package/versions/base/component-docs/modus-wc-stepper.json +47 -0
- package/versions/base/component-docs/modus-wc-switch.json +149 -0
- package/versions/base/component-docs/modus-wc-table.json +202 -0
- package/versions/base/component-docs/modus-wc-tabs.json +86 -0
- package/versions/base/component-docs/modus-wc-text-input.json +278 -0
- package/versions/base/component-docs/modus-wc-textarea.json +215 -0
- package/versions/base/component-docs/modus-wc-theme-switcher.json +49 -0
- package/versions/base/component-docs/modus-wc-time-input.json +211 -0
- package/versions/base/component-docs/modus-wc-toast.json +56 -0
- package/versions/base/component-docs/modus-wc-toolbar.json +44 -0
- package/versions/base/component-docs/modus-wc-tooltip.json +94 -0
- package/versions/base/component-docs/modus-wc-typography.json +73 -0
- package/versions/base/component-docs/modus-wc-utility-panel.json +86 -0
- package/versions/base/docs/_all_docs.json +15 -0
- package/versions/base/docs/accessibility.mdx +32 -0
- package/versions/base/docs/angular.mdx +346 -0
- package/versions/base/docs/form-inputs.mdx +86 -0
- package/versions/base/docs/getting-started.mdx +91 -0
- package/versions/base/docs/modus-figma-mcp-integration-guide.mdx +254 -0
- package/versions/base/docs/modus-icon-usage.mdx +210 -0
- package/versions/base/docs/react.mdx +129 -0
- package/versions/base/docs/styling.mdx +107 -0
- package/versions/base/docs/testing.mdx +18 -0
- package/versions/base/docs/vue.mdx +159 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Meta } from '@storybook/blocks';
|
|
2
|
+
|
|
3
|
+
<Meta title="Documentation/Accessibility" />
|
|
4
|
+
|
|
5
|
+
# Accessibility
|
|
6
|
+
|
|
7
|
+
The Modus Web Components package is designed to be accessible by default. This means that the components are built with accessibility in mind and are tested to ensure they meet the [Web Content Accessibility Guidelines (WCAG)](https://www.w3.org/WAI/standards-guidelines/wcag/).
|
|
8
|
+
|
|
9
|
+
Features:
|
|
10
|
+
|
|
11
|
+
- Meet [minimum contrast requirements (Level AA)](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html).
|
|
12
|
+
- Keyboard navigable where applicable.
|
|
13
|
+
- Screen reader accessible.
|
|
14
|
+
- Supports the [prefers-reduced-motion media query](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion) to minimize the amount of non-essential motion.
|
|
15
|
+
|
|
16
|
+
Found an accessibility issue? Please [report it at GitHub](https://github.com/trimble-oss/modus-wc-2.0/issues/new?assignees=&labels=accessibility&template=accessibility-issue-report.md&title=).
|
|
17
|
+
|
|
18
|
+
## For contributors
|
|
19
|
+
|
|
20
|
+
The Storybook site has an Accessibility tab that can be used to test the components for accessibility issues. If you are contributing to the Modus Web Components package please ensure that your changes do not introduce accessibility issues. If there are any violations please address them before submitting your changes. If you are unsure, please reach out to the team for guidance.
|
|
21
|
+
|
|
22
|
+
## Useful tools for testing your sites
|
|
23
|
+
|
|
24
|
+
### Browser extensions
|
|
25
|
+
|
|
26
|
+
- [axe DevTools](https://chromewebstore.google.com/detail/axe-devtools-web-accessib/lhdoppojpmngadmnindnejefpokejbdd)
|
|
27
|
+
- [Lighthouse](https://chromewebstore.google.com/detail/lighthouse/blipmdconlkpinefehnmjammfjpmpbjk)
|
|
28
|
+
- [Microsoft Accessibility Insights](https://accessibilityinsights.io/downloads/)
|
|
29
|
+
|
|
30
|
+
## Further Reading
|
|
31
|
+
|
|
32
|
+
You can find more information on accessibility on the [Modus website](https://modus.trimble.com/foundations/accessibility/).
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { Meta } from '@storybook/blocks';
|
|
2
|
+
|
|
3
|
+
<Meta title="Documentation/Frameworks/Angular" />
|
|
4
|
+
|
|
5
|
+
# Angular Framework Integration
|
|
6
|
+
|
|
7
|
+
This guide will help you get started with consuming the Modus Angular Web Component library in your Angular project.
|
|
8
|
+
|
|
9
|
+
We highly recommend using the Modus Angular Components library for Angular based projects.
|
|
10
|
+
These components are automatically generated using the Stencil Angular Framework Integration.
|
|
11
|
+
|
|
12
|
+
Follow the steps outlined below to integrate and use Modus Angular Web Components effectively.
|
|
13
|
+
|
|
14
|
+
Please refer to the [official stencil documentation](https://stenciljs.com/docs/angular#consumer-usage) for more information on how to integrate with your Angular project.
|
|
15
|
+
|
|
16
|
+
## Angular with modules
|
|
17
|
+
|
|
18
|
+
Modus Angular Components have a peer dependency with Modus Web Components and require the
|
|
19
|
+
installation of both packages.
|
|
20
|
+
|
|
21
|
+
### 1. Install both `modus-wc` and `modus-wc-angular` dependencies:
|
|
22
|
+
|
|
23
|
+
Ensure that you specify the target version of Angular for the `modus-wc-angular` package (e.g., `ng18` for Angular 18).
|
|
24
|
+
|
|
25
|
+
<b>
|
|
26
|
+
Lock the installed package versions to avoid unintended breakages on future
|
|
27
|
+
npm installs.
|
|
28
|
+
</b>
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install @trimble-oss/moduswebcomponents @trimble-oss/moduswebcomponents-angular@<latest-version>-ng<target-version>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### 2. Set up the styling:
|
|
35
|
+
|
|
36
|
+
You will need to import our styling in your main JavaScript or CSS file:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
import '@trimble-oss/moduswebcomponents/modus-wc-styles.css';
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 3. Import Modus Angular Web Components library into your Angular app's module:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
// app.module.ts
|
|
46
|
+
import { ModusAngularComponentsModule } from '@trimble-oss/moduswebcomponents-angular';
|
|
47
|
+
|
|
48
|
+
@NgModule({
|
|
49
|
+
...
|
|
50
|
+
imports: [ComponentLibraryModule],
|
|
51
|
+
...
|
|
52
|
+
})
|
|
53
|
+
export class AppModule {}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 4. Use Modus Angular Web Components while leveraging Angular template binding syntax:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
// app.component.html
|
|
60
|
+
<modus-wc-button label="Click Me" />
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Angular with standalone components
|
|
64
|
+
|
|
65
|
+
Modus Angular Components have a peer dependency with Modus Web Components and require the
|
|
66
|
+
installation of both packages.
|
|
67
|
+
|
|
68
|
+
### 1. Install both `modus-wc` and `modus-wc-angular` dependencies:
|
|
69
|
+
|
|
70
|
+
Ensure that you specify the target version of Angular for the `modus-wc-angular` package (e.g., `ng18` for Angular 18).
|
|
71
|
+
|
|
72
|
+
<b>
|
|
73
|
+
Lock the installed package versions to avoid unintended breakages on future
|
|
74
|
+
npm installs.
|
|
75
|
+
</b>
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npm install @trimble-oss/moduswebcomponents @trimble-oss/moduswebcomponents-angular@<latest-version>-ng<target-version>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 2. Set up the styling:
|
|
82
|
+
|
|
83
|
+
You will need to import our styling in your main JavaScript or CSS file:
|
|
84
|
+
|
|
85
|
+
```js
|
|
86
|
+
import '@trimble-oss/moduswebcomponents/modus-wc-styles.css';
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 3. Import your component library into your component.
|
|
90
|
+
|
|
91
|
+
You must distribute your components through a primary `NgModule` to use your components in a standalone component.
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
// app.component.ts
|
|
95
|
+
import { Component } from '@angular/core';
|
|
96
|
+
import { ModusAngularComponentsModule } from '@trimble-oss/moduswebcomponents-angular';
|
|
97
|
+
|
|
98
|
+
@Component({
|
|
99
|
+
selector: 'app-root',
|
|
100
|
+
standalone: true,
|
|
101
|
+
imports: [ModusAngularComponentsModule],
|
|
102
|
+
templateUrl: './app.component.html',
|
|
103
|
+
})
|
|
104
|
+
export class AppComponent {}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### 4. Use Modus Angular Web Components while leveraging Angular template binding syntax:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
// app.component.html
|
|
111
|
+
<modus-wc-button label="Click Me" />
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Custom Elements Schema
|
|
115
|
+
|
|
116
|
+
In the `app.module.ts` file, you need to tell angular that you are using custom element schemas
|
|
117
|
+
so that it does not throw errors when unknown element names are used in the markup.
|
|
118
|
+
|
|
119
|
+
Import `CUSTOM_ELEMENTS_SCHEMA` and add it to your `@NgModule`'s schemas:
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
|
|
123
|
+
|
|
124
|
+
@NgModule({
|
|
125
|
+
...
|
|
126
|
+
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
|
127
|
+
...
|
|
128
|
+
})
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Wrapping Components
|
|
132
|
+
|
|
133
|
+
When using Modus Web Components directly, it is recommended to wrap it in corresponding Angular components within your application. This will abstract away from the library dependency, allowing more flexibility for you and your application in the future. Each part of the component is able to be abstracted, leaving you with an Angular-native component.
|
|
134
|
+
|
|
135
|
+
Notice Angular allows `[]` and `()` markup syntax for the web component's inputs and outputs, respectively.
|
|
136
|
+
|
|
137
|
+
Wrapped Modus Button Example:
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
|
141
|
+
|
|
142
|
+
@Component({
|
|
143
|
+
selector: 'button-component',
|
|
144
|
+
template: `
|
|
145
|
+
<modus-wc-button
|
|
146
|
+
[buttonStyle]="buttonStyle"
|
|
147
|
+
[color]="color"
|
|
148
|
+
[disabled]="disabled"
|
|
149
|
+
[size]="size"
|
|
150
|
+
(buttonClick)="onButtonClick.emit()"
|
|
151
|
+
>
|
|
152
|
+
<ng-content></ng-content>
|
|
153
|
+
</modus-wc-button>
|
|
154
|
+
`,
|
|
155
|
+
})
|
|
156
|
+
export class ButtonComponent {
|
|
157
|
+
@Input() buttonStyle: 'borderless' | 'fill' | 'outline' = 'fill';
|
|
158
|
+
@Input() color: 'danger' | 'default' | 'primary' | 'secondary' | 'warning' =
|
|
159
|
+
'default';
|
|
160
|
+
@Input() disabled: boolean;
|
|
161
|
+
@Input() size: 'small' | 'medium' | 'large' = 'medium';
|
|
162
|
+
|
|
163
|
+
@Output() onButtonClick = new EventEmitter();
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Reactive Forms
|
|
168
|
+
|
|
169
|
+
Working with a web component's inputs/outputs works great but these components do not integrate with Angular's reactive forms quite as easily. Since web components do not know about Angular's form APIs, we must extend form-compatible components' behavior with simple directives. These directives are applied to the web component selectors, giving the components Angular form functionality.
|
|
170
|
+
|
|
171
|
+
Let's take a look at a directive implementation for a Modus Select's form functionality.
|
|
172
|
+
|
|
173
|
+
#### Wrapper
|
|
174
|
+
|
|
175
|
+
You'll notice the `modus-select` in the markup is taking extra inputs, such as `formControl` and `optionsDisplayProp`, these inputs are provided by the directive below. Here is what our wrapper looks like:
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
|
179
|
+
import { FormControl } from '@angular/forms';
|
|
180
|
+
|
|
181
|
+
@Component({
|
|
182
|
+
selector: 'select-component',
|
|
183
|
+
template: `
|
|
184
|
+
<modus-wc-select
|
|
185
|
+
#select
|
|
186
|
+
[disabled]="disabled"
|
|
187
|
+
[errorText]="errorText"
|
|
188
|
+
[formControl]="formControl"
|
|
189
|
+
[helperText]="helperText"
|
|
190
|
+
[label]="label"
|
|
191
|
+
[options]="options"
|
|
192
|
+
[optionsDisplayProp]="optionsDisplayProp"
|
|
193
|
+
[required]="required"
|
|
194
|
+
[selectValue]="value"
|
|
195
|
+
[size]="size"
|
|
196
|
+
[validText]="validText"
|
|
197
|
+
(valueChange)="onSelectValueChange.emit(select.value)"
|
|
198
|
+
>
|
|
199
|
+
</modus-wc-select>
|
|
200
|
+
`,
|
|
201
|
+
})
|
|
202
|
+
export class SelectComponent {
|
|
203
|
+
@Input() disabled: boolean;
|
|
204
|
+
@Input() errorText: string;
|
|
205
|
+
@Input() formControl: FormControl;
|
|
206
|
+
@Input() helperText: string;
|
|
207
|
+
@Input() label: string;
|
|
208
|
+
@Input() options: unknown[] = [];
|
|
209
|
+
@Input() optionsDisplayProp: string;
|
|
210
|
+
@Input() required: boolean;
|
|
211
|
+
@Input() size: 'medium' | 'large' = 'medium';
|
|
212
|
+
@Input() validText: string;
|
|
213
|
+
@Input() value: unknown;
|
|
214
|
+
|
|
215
|
+
@Output() onSelectValueChange = new EventEmitter<unknown>();
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
#### Directive
|
|
220
|
+
|
|
221
|
+
Moving onto the directive, there are a few things to keep in mind.
|
|
222
|
+
|
|
223
|
+
- The directive's selector is set to the web component's tag, not the wrapper's.
|
|
224
|
+
- Implementing the `ControlValueAccessor` interface helps Angular understand when the form control has been updated or changed.
|
|
225
|
+
- When the value is set, `onChange()` notifies that the control has been updated.
|
|
226
|
+
- Calling `onTouched()` lets Angular know the component has been touched, which is needed for form validation.
|
|
227
|
+
- The `get value()`, and `set value()` are used by Angular's form control.
|
|
228
|
+
- Using the `@HostListener` decorator lets you listen to events from the web component, and execute appropriate logic.
|
|
229
|
+
|
|
230
|
+
Here is what our directive looks like:
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
import {
|
|
234
|
+
Directive,
|
|
235
|
+
forwardRef,
|
|
236
|
+
ElementRef,
|
|
237
|
+
HostListener,
|
|
238
|
+
Input,
|
|
239
|
+
OnInit,
|
|
240
|
+
Output,
|
|
241
|
+
EventEmitter,
|
|
242
|
+
} from '@angular/core';
|
|
243
|
+
import {
|
|
244
|
+
ControlValueAccessor,
|
|
245
|
+
FormControl,
|
|
246
|
+
NG_VALUE_ACCESSOR,
|
|
247
|
+
} from '@angular/forms';
|
|
248
|
+
|
|
249
|
+
@Directive({
|
|
250
|
+
selector: 'modus-wc-select',
|
|
251
|
+
providers: [
|
|
252
|
+
{
|
|
253
|
+
provide: NG_VALUE_ACCESSOR,
|
|
254
|
+
useExisting: forwardRef(() => ModusSelectDirective),
|
|
255
|
+
multi: true,
|
|
256
|
+
},
|
|
257
|
+
],
|
|
258
|
+
})
|
|
259
|
+
export class ModusSelectDirective implements ControlValueAccessor, OnInit {
|
|
260
|
+
@Input() disabled: boolean;
|
|
261
|
+
@Input() errorText: string;
|
|
262
|
+
@Input() formControl: FormControl;
|
|
263
|
+
@Input() helperText: string;
|
|
264
|
+
@Input() label: string;
|
|
265
|
+
@Input() options: unknown[];
|
|
266
|
+
@Input() optionsDisplayProp: string;
|
|
267
|
+
@Input() required: boolean;
|
|
268
|
+
@Input() selectValue: unknown;
|
|
269
|
+
@Input() size: 'medium' | 'large';
|
|
270
|
+
@Input() validText: string;
|
|
271
|
+
|
|
272
|
+
@Output() valueChange = new EventEmitter<string>();
|
|
273
|
+
|
|
274
|
+
onChange: any = () => {};
|
|
275
|
+
onTouched: any = () => {};
|
|
276
|
+
|
|
277
|
+
private _value: string;
|
|
278
|
+
|
|
279
|
+
get value() {
|
|
280
|
+
return this._value;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
set value(value) {
|
|
284
|
+
if (value !== this._value) {
|
|
285
|
+
this._value = value;
|
|
286
|
+
this.onChange(this._value);
|
|
287
|
+
this.onTouched();
|
|
288
|
+
this.elementRef.nativeElement.value = value;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
constructor(private elementRef: ElementRef) {}
|
|
293
|
+
|
|
294
|
+
ngOnInit(): void {
|
|
295
|
+
const modusSelect = this.elementRef.nativeElement as HTMLModusSelectElement;
|
|
296
|
+
modusSelect.disabled = this.disabled;
|
|
297
|
+
modusSelect.errorText = this.errorText;
|
|
298
|
+
modusSelect.helperText = this.helperText;
|
|
299
|
+
modusSelect.label = this.label;
|
|
300
|
+
modusSelect.options = this.options;
|
|
301
|
+
modusSelect.optionsDisplayProp = this.optionsDisplayProp;
|
|
302
|
+
modusSelect.required = this.required;
|
|
303
|
+
modusSelect.size = this.size;
|
|
304
|
+
modusSelect.validText = this.validText;
|
|
305
|
+
modusSelect.value = this.selectValue;
|
|
306
|
+
|
|
307
|
+
if (!this.formControl) {
|
|
308
|
+
this.formControl = new FormControl(null);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
@HostListener('valueChange', ['$event.detail'])
|
|
313
|
+
listenForValueChange(value: string): void {
|
|
314
|
+
this.value = value;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
registerOnChange(fn: Function): void {
|
|
318
|
+
this.onChange = fn;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
registerOnTouched(fn: Function): void {
|
|
322
|
+
this.onTouched = fn;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
setDisabledState(isDisabled: boolean): void {
|
|
326
|
+
this.disabled = isDisabled;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
writeValue(value: string): void {
|
|
330
|
+
if (value) {
|
|
331
|
+
this.value = value;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
Now adding the Modus Select as a form control is as easy as:
|
|
338
|
+
|
|
339
|
+
```ts
|
|
340
|
+
<select-component
|
|
341
|
+
[formControl]="$any(form).controls['select1']"
|
|
342
|
+
[label]="'Select Form Demo'"
|
|
343
|
+
[options]="options"
|
|
344
|
+
[optionsDisplayProp]="'display'">
|
|
345
|
+
</select-component>
|
|
346
|
+
```
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Meta } from '@storybook/blocks';
|
|
2
|
+
|
|
3
|
+
<Meta title="Documentation/Form Inputs" />
|
|
4
|
+
|
|
5
|
+
# Form Inputs
|
|
6
|
+
|
|
7
|
+
## Controlled Input Pattern
|
|
8
|
+
|
|
9
|
+
The controlled input pattern is a design pattern where the form element's value is controlled by the application state rather than the DOM element itself. This pattern offers several benefits:
|
|
10
|
+
|
|
11
|
+
- Single source of truth for input values
|
|
12
|
+
- Ability to validate and transform input data in real-time
|
|
13
|
+
- Simplified form state management
|
|
14
|
+
- Improved testability and debugging
|
|
15
|
+
|
|
16
|
+
### Angular
|
|
17
|
+
|
|
18
|
+
Angular uses two-way data binding with ngModel to implement the controlled input pattern efficiently.
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { Component } from '@angular/core';
|
|
22
|
+
|
|
23
|
+
@Component({
|
|
24
|
+
selector: 'controlled-text-input',
|
|
25
|
+
template: `
|
|
26
|
+
<modus-wc-text-input
|
|
27
|
+
(inputChange)="onInputChange($event)"
|
|
28
|
+
[value]="inputValue"
|
|
29
|
+
>
|
|
30
|
+
</modus-wc-text-input>
|
|
31
|
+
`,
|
|
32
|
+
})
|
|
33
|
+
export class ControlledTextInput {
|
|
34
|
+
inputValue: string = '';
|
|
35
|
+
|
|
36
|
+
onInputChange(event: CustomEvent) {
|
|
37
|
+
this.inputValue = event.detail.target.value;
|
|
38
|
+
|
|
39
|
+
// You can add validation or transformation logic here
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### React
|
|
45
|
+
|
|
46
|
+
React's controlled input pattern binds form elements to state values and handlers, making React a natural fit for controlled inputs.
|
|
47
|
+
|
|
48
|
+
```typescript jsx
|
|
49
|
+
import { useState } from 'react';
|
|
50
|
+
|
|
51
|
+
function ControlledTextInput() {
|
|
52
|
+
const [value, setValue] = useState('');
|
|
53
|
+
|
|
54
|
+
// Handle input changes
|
|
55
|
+
const handleChange = (event: CustomEvent) => {
|
|
56
|
+
setValue(event.detail.target.value);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return <ModusWcTextInput onInputChange={handleChange} value={value} />;
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Web Components
|
|
64
|
+
|
|
65
|
+
Web Components can implement the controlled input pattern by exposing properties and events that allow parent applications to manage state externally.
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
// Example of using the Modus Text Input as a controlled component
|
|
69
|
+
const textInput = document.getElementById('first-name');
|
|
70
|
+
let inputValue = ''; // State lives in the parent application
|
|
71
|
+
|
|
72
|
+
// Set initial value
|
|
73
|
+
textInput.value = inputValue;
|
|
74
|
+
|
|
75
|
+
// Listen for changes
|
|
76
|
+
textInput.addEventListener('inputChange', (event) => {
|
|
77
|
+
// Update our state
|
|
78
|
+
inputValue = event.detail.target.value;
|
|
79
|
+
|
|
80
|
+
// You can perform validation or transformations here
|
|
81
|
+
|
|
82
|
+
// Update the input to reflect the new state
|
|
83
|
+
// This step is only needed if you transform the value
|
|
84
|
+
textInput.value = inputValue;
|
|
85
|
+
});
|
|
86
|
+
```
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Meta } from '@storybook/blocks';
|
|
2
|
+
|
|
3
|
+
<Meta title="Documentation/Getting Started" />
|
|
4
|
+
|
|
5
|
+
# Getting Started
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
<b>
|
|
10
|
+
Lock the installed package version to avoid unintended breakages on future npm
|
|
11
|
+
installs.
|
|
12
|
+
</b>
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @trimble-oss/moduswebcomponents
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### 1. Set up the styling:
|
|
21
|
+
|
|
22
|
+
You will need to import our styling in your main JavaScript or CSS file:
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import '@trimble-oss/moduswebcomponents/modus-wc-styles.css';
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 2. Set the theme:
|
|
29
|
+
|
|
30
|
+
The theme can be set manually or by using the `ThemeSwitcher` component. See the "Use a Theme" section of [Styling](/docs/documentation-styling--docs) for guidance.
|
|
31
|
+
|
|
32
|
+
Available themes are:
|
|
33
|
+
|
|
34
|
+
- `modus-classic-light`
|
|
35
|
+
- `modus-classic-dark`
|
|
36
|
+
- `modus-modern-light` (default)
|
|
37
|
+
- `modus-modern-dark`
|
|
38
|
+
|
|
39
|
+
### 3. Register custom elements:
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
import { defineCustomElements } from '@trimble-oss/moduswebcomponents/loader';
|
|
43
|
+
|
|
44
|
+
// Call during the initial loading of your application
|
|
45
|
+
const Root = () => {
|
|
46
|
+
defineCustomElements();
|
|
47
|
+
|
|
48
|
+
return <App />;
|
|
49
|
+
};
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 4. Use the components:
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
// Use in HTML
|
|
56
|
+
<modus-wc-button variant="primary">Click me</modus-wc-button>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Types
|
|
60
|
+
|
|
61
|
+
Types are a crucial part of our component library, providing robust type safety and enhanced developer experience through comprehensive TypeScript definitions for all components.
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
import { ISelectOption, ModusWcSelectCustomEvent } from '@trimble-oss/moduswebcomponents';
|
|
65
|
+
|
|
66
|
+
const options: ISelectOption[] = [
|
|
67
|
+
{
|
|
68
|
+
label: 'Option 1',
|
|
69
|
+
value: '1',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
label: 'Option 2',
|
|
73
|
+
value: '2',
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
const handleEvent = (e: ModusWcSelectCustomEvent<ISelectOption>) => {}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Framework Integrations
|
|
81
|
+
|
|
82
|
+
- ### [Angular](?path=/docs/documentation-frameworks-angular--docs)
|
|
83
|
+
|
|
84
|
+
- ### [React](?path=/docs/documentation-frameworks-react--docs)
|
|
85
|
+
|
|
86
|
+
- ### [Vue](?path=/docs/documentation-frameworks-vue--docs)
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
Need help? Check out our [GitHub repository](https://github.com/trimble-oss/modus-wc-2.0)
|
|
91
|
+
or [raise an issue](https://github.com/trimble-oss/modus-wc-2.0/issues).
|