@govtechsg/sgds-web-component 0.0.13 → 0.0.14
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 +571 -41
- package/base/card-element.d.ts +4 -4
- package/base/dropdown-element.d.ts +13 -16
- package/base/link-element.d.ts +2 -0
- package/components/Accordion/index.d.ts +2 -2
- package/components/ActionCard/index.d.ts +1 -1
- package/components/ActionCard/sgds-action-card.d.ts +38 -10
- package/components/Alert/index.d.ts +1 -1
- package/components/Badge/index.d.ts +1 -1
- package/components/Button/index.d.ts +1 -1
- package/components/Card/index.d.ts +1 -0
- package/components/Card/sgds-card.d.ts +24 -0
- package/components/Checkbox/index.d.ts +1 -1
- package/components/Checkbox/sgds-checkbox.d.ts +3 -3
- package/components/Dropdown/index.d.ts +2 -3
- package/components/Dropdown/sgds-dropdown-item.d.ts +6 -2
- package/components/Dropdown/sgds-dropdown.d.ts +19 -0
- package/components/FileUpload/index.d.ts +1 -1
- package/components/FileUpload/sgds-file-upload.d.ts +44 -0
- package/components/Footer/index.d.ts +1 -1
- package/components/Input/index.d.ts +1 -1
- package/components/Input/sgds-input.d.ts +2 -2
- package/components/Mainnav/index.d.ts +3 -3
- package/components/Mainnav/sgds-mainnav-dropdown.d.ts +4 -0
- package/components/Mainnav/sgds-mainnav.d.ts +1 -2
- package/components/Masthead/index.d.ts +1 -1
- package/components/Modal/index.d.ts +1 -1
- package/components/Modal/sgds-modal.d.ts +45 -0
- package/components/QuantityToggle/index.d.ts +1 -1
- package/components/QuantityToggle/sgds-quantity-toggle.d.ts +39 -14
- package/components/Radio/index.d.ts +2 -2
- package/components/Radio/sgds-radio-group.d.ts +3 -3
- package/components/Radio/sgds-radio.d.ts +4 -3
- package/components/Sidenav/index.d.ts +3 -3
- package/components/Sidenav/sgds-sidenav-item.d.ts +7 -7
- package/components/Sidenav/sgds-sidenav-link.d.ts +1 -1
- package/components/Sidenav/sgds-sidenav.d.ts +5 -2
- package/components/Spinner/index.d.ts +1 -1
- package/components/Stepper/sgds-stepper.d.ts +31 -7
- package/components/Tab/index.d.ts +3 -3
- package/components/Textarea/index.d.ts +1 -1
- package/components/Textarea/sgds-textarea.d.ts +2 -2
- package/components/Toast/index.d.ts +1 -1
- package/components/Tooltip/index.d.ts +1 -1
- package/index.d.ts +1 -0
- package/index.js +832 -570
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/react/action-card/index.d.ts +3 -1
- package/react/{fileupload → card}/index.d.ts +1 -1
- package/react/cjs/index.js +936 -645
- package/react/cjs/index.js.map +1 -1
- package/react/dropdown/index.d.ts +2 -2
- package/react/file-upload/index.d.ts +5 -0
- package/react/index.d.ts +2 -1
- package/react/index.js +928 -638
- package/react/index.js.map +1 -1
- package/react/mainnav-dropdown/index.d.ts +2 -2
- package/react/modal/index.d.ts +7 -1
- package/react/quantity-toggle/index.d.ts +4 -1
- package/react/stepper/index.d.ts +8 -1
- package/umd/index.js +781 -590
- package/umd/index.js.map +1 -1
- package/components/FileUpload/sgds-fileupload.d.ts +0 -22
package/README.md
CHANGED
|
@@ -19,10 +19,6 @@ The CDN loader registers all SGDS elements up front. Note that, if you're only u
|
|
|
19
19
|
|
|
20
20
|
<script type="module" src="https://cdn.jsdelivr.net/npm/@govtechsg/sgds-web-component"></script>
|
|
21
21
|
|
|
22
|
-
//cherry picked
|
|
23
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/@govtechsg/sgds-web-component/${Component}/index.js"></script>
|
|
24
|
-
|
|
25
|
-
|
|
26
22
|
```
|
|
27
23
|
|
|
28
24
|
## Local Installation
|
|
@@ -35,7 +31,7 @@ npm install @govtechsg/sgds-web-component
|
|
|
35
31
|
|
|
36
32
|
```
|
|
37
33
|
|
|
38
|
-
and import the library once in your entry point
|
|
34
|
+
and import the library once in your entry point and use it globally throughout your project
|
|
39
35
|
|
|
40
36
|
```js
|
|
41
37
|
|
|
@@ -44,70 +40,604 @@ import "@govtechsg/sgds-web-component";
|
|
|
44
40
|
```
|
|
45
41
|
|
|
46
42
|
|
|
47
|
-
#
|
|
43
|
+
# Imports
|
|
48
44
|
|
|
49
|
-
##
|
|
45
|
+
## Using the custom elements
|
|
46
|
+
Once imported, the custom elements can be used throughout the project.
|
|
50
47
|
|
|
51
|
-
|
|
48
|
+
```js
|
|
52
49
|
|
|
53
|
-
|
|
50
|
+
import "@govtechsg/sgds-web-component"
|
|
51
|
+
|
|
52
|
+
```
|
|
54
53
|
|
|
55
|
-
|
|
56
|
-
//cdn way
|
|
57
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/@govtechsg/sgds-web-component/Button/index.js"></script>
|
|
54
|
+
## Using the component's class
|
|
58
55
|
|
|
56
|
+
Each component's Class is exported via named exports, prefixed with `Sgds`
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
|
|
60
|
+
import { SgdsButton, SgdsMainnav } from "@govtechsg/sgds-web-component"
|
|
59
61
|
|
|
60
62
|
```
|
|
63
|
+
# Attributes and Properties
|
|
61
64
|
|
|
62
|
-
##
|
|
65
|
+
## String
|
|
63
66
|
|
|
64
|
-
|
|
65
|
-
For such components, you will have to import all of its dependency. The component's dependency will be specified in the Component documentation under Dependency section
|
|
67
|
+
The web components uses attributes to set the properties. For example, the variant attribute is used to set the variant property of the button and in turn alters its class and changes its color
|
|
66
68
|
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
import "@govtechsg/sgds-web-component/Button";
|
|
69
|
+
```html
|
|
70
|
+
|
|
71
|
+
<sgds-button variant="secondary"></sgds-button>
|
|
71
72
|
|
|
72
73
|
```
|
|
73
74
|
|
|
74
|
-
|
|
75
|
+
## Boolean
|
|
75
76
|
|
|
76
|
-
|
|
77
|
+
Boolean properties are usually false by default. To set it to true, add it as an attribute with no value on the custom element
|
|
77
78
|
|
|
78
|
-
|
|
79
|
-
// data-shoelace attribute points to the assets folder, where the bootstrap icons are located. If you are copying out the assets folder to your own directory, change the value of data-shoelace to your assets folder
|
|
80
|
-
<script type="module" data-shoelace="node_modules/@shoelace-style/shoelace/dist">
|
|
81
|
-
import '@shoelace-style/shoelace/dist/components/icon/icon.js';
|
|
82
|
-
//<sl-icon> is ready to use!
|
|
83
|
-
</script>
|
|
79
|
+
```html
|
|
84
80
|
|
|
85
|
-
|
|
81
|
+
<sgds-accordion allowMultiple>
|
|
82
|
+
...
|
|
83
|
+
</sgds-accordion>
|
|
86
84
|
|
|
87
|
-
|
|
85
|
+
<sgds-input disabled></sgds-input>
|
|
88
86
|
|
|
89
|
-
```
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Objects, Arrays and Functions
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
// Set the base path to the folder you copied Shoelace's assets
|
|
93
|
-
setBasePath('/path/to/shoelace/dist');
|
|
91
|
+
Functions have to be passed in via javascript. For attributes that accepts Objects or Arrays, you can pass in as a JSON string or via javascript.
|
|
94
92
|
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
```html
|
|
94
|
+
//via JSON string
|
|
95
|
+
<sgds-table tableHeaders='["Name", "BirthDate"]'></sgds-table>
|
|
97
96
|
|
|
97
|
+
// via Javascript
|
|
98
|
+
<script>
|
|
99
|
+
const table = document.querySelector('sgds-table');
|
|
100
|
+
table.tableHeaders = ['Name', 'Birthdate'];
|
|
101
|
+
</script>
|
|
98
102
|
```
|
|
103
|
+
# Events
|
|
104
|
+
|
|
105
|
+
While you can listen for common HTML events like onclick, onmouseover etc., it is not recommended to do so. This is because the events emitted within a component's shadow root are retargeted to look like they've come from the host element rather than internal elements to the Shadow DOM. There are also [certain events](https://web.dev/shadowdom-301/#events-that-are-always-stopped) that will never cross the shadow boundary. See [DOM spec](https://dom.spec.whatwg.org/#retarget) and [Shadow Dom 301](https://web.dev/shadowdom-301/#event-model) for better illustration.
|
|
106
|
+
|
|
107
|
+
Tl;Dr: This may result in, for example, multiple click handlers executing even if the user clicks just once or no events emitted for certain events.
|
|
108
|
+
|
|
109
|
+
As such, we recommend you to listen for custom events emitted by SGDS web components over the native HTML events. The emitted custom events, if present, are specified for each component under API table.
|
|
110
|
+
|
|
111
|
+
```html
|
|
99
112
|
|
|
100
|
-
|
|
113
|
+
<sgds-checkbox>Check me</sgds-checkbox>
|
|
114
|
+
|
|
115
|
+
<script>
|
|
116
|
+
const checkbox = document.querySelector('sgds-checkbox');
|
|
117
|
+
checkbox.addEventListener('sgds-change', event => {
|
|
118
|
+
console.log(event.target.checked ? 'checked' : 'not checked');
|
|
119
|
+
});
|
|
120
|
+
</script>
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
# Slots
|
|
124
|
+
|
|
125
|
+
The [HTMl slot elements](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/slot) are placeholders inside the web components that you can fill up with your own HTML markups.
|
|
126
|
+
|
|
127
|
+
There are two kinds of slots: default and named slots. In the storybook documentation, slots are found under the API table with their names. If the name of a slot is <bold>default</bold>, it means that it is a default slot. For all other names, they are named slots.
|
|
128
|
+
|
|
129
|
+
Handle the usage of the default slot and named slot as below
|
|
130
|
+
|
|
131
|
+
1. default slot : `<slot></slot>`
|
|
132
|
+
|
|
133
|
+
```html
|
|
134
|
+
|
|
135
|
+
<sgds-button><span>Hello World</span></sgds-button>
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
"Hello World" span element is placed in the default slot
|
|
140
|
+
|
|
141
|
+
2. named slot : `<slot name="icon"></slot>`
|
|
142
|
+
|
|
143
|
+
```html
|
|
144
|
+
|
|
145
|
+
<sgds-button>
|
|
146
|
+
<span>Hello World</span>
|
|
147
|
+
<svg slot="icon"></svg>
|
|
148
|
+
</sgds-button>
|
|
149
|
+
|
|
150
|
+
```
|
|
101
151
|
|
|
102
|
-
|
|
152
|
+
The svg element with attribute `slot=icon` is placed in the named slot
|
|
103
153
|
|
|
104
|
-
|
|
154
|
+
# Stylings
|
|
105
155
|
|
|
106
|
-
|
|
156
|
+
## Global Styles
|
|
157
|
+
|
|
158
|
+
The following css custom variable are exposed to enable users to make modifications across all web components in our library
|
|
159
|
+
|
|
160
|
+
| css custom variable name | description |
|
|
161
|
+
| ------------------------ | ----------------------------------------- |
|
|
162
|
+
| --sgds-body-font-family | Set the font family of the web components |
|
|
163
|
+
| --sgds-body-font-size | Set the font size of the web components |
|
|
164
|
+
| --sgds-body-font-weight | Set the font weight of the web components |
|
|
165
|
+
| --sgds-body-line-height | Set the line height of the web components |
|
|
166
|
+
|
|
167
|
+
```css
|
|
168
|
+
|
|
169
|
+
:root {
|
|
170
|
+
--sgds-body-font-family: Helvetica;
|
|
171
|
+
--sgds-body-font-size: 5rem;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Component Styles
|
|
177
|
+
|
|
178
|
+
SGDS web component library is shipped with SGDS v2 stylings and does not require you to configure or install any other styling files.
|
|
107
179
|
The styles of components are built in and can be modified via props, cssparts and css custom properties whenever we specify for such styling modificiations. This information will be specified under API section for each component
|
|
108
180
|
|
|
109
181
|
You will require some knowledge of web components and css to do so and the information can be readily available online like mdn web docs for [web components](https://developer.mozilla.org/en-US/docs/Web/Web_Components) and [css](https://developer.mozilla.org/en-US/docs/Web/CSS)
|
|
110
182
|
|
|
111
|
-
###
|
|
183
|
+
### classes prop
|
|
184
|
+
|
|
185
|
+
Some components exposes a class-like attribute, usually named "classes" prefix with the element's name e.g. buttonClasses.
|
|
186
|
+
SGDS web component library is shipped with our v2 design library, a spin-off from Bootstrap v5. As such, the css tokens are applicable to use and exposed to the shadow DOM.
|
|
187
|
+
|
|
188
|
+
For example, you can pass "btn-lg" and "me-2" to `buttonClasses` prop as another way to customise the stylings of your button.
|
|
189
|
+
|
|
190
|
+
```html
|
|
191
|
+
<sgds-button buttonClasses="btn-lg me-2">Hello world</sgds-button>
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**NOTE** Do not use `class` attribute to attempt to style the shadow tree of the host. We did not the forward of `class` attribute to the shadow DOM so that users are able to style the light dom with it. Use `class` attribute when you need to style the light DOM.
|
|
195
|
+
|
|
196
|
+
### cssparts
|
|
197
|
+
|
|
198
|
+
Some components expose cssparts on selected elements of the shadow DOM. See the API table for each component on the css parts exposed.
|
|
199
|
+
|
|
200
|
+
```css
|
|
201
|
+
sgds-footer::part(footer-bottom) {
|
|
202
|
+
background-color: grey;
|
|
203
|
+
font-family: "Times New Roman", Times, serif;
|
|
204
|
+
border: 10px dotted red;
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### css custom variable
|
|
209
|
+
|
|
210
|
+
Some components have defined css custom variable for styling of selected aspects of the element in the shadow DOM. See the API table for the available css custom variables
|
|
211
|
+
|
|
212
|
+
```css
|
|
213
|
+
sgds-sidenav {
|
|
214
|
+
--sidenav-theme-color: pink;
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## External stylings
|
|
219
|
+
|
|
220
|
+
Any external stylings done on our web components like positioning needs to be done on your end. You can use [SGDS v2 library](https://designsystem.tech.gov.sg/get-started/)to leverage on the position stylings we provide e.g. ms-auto, flexbox, grids
|
|
221
|
+
|
|
222
|
+
# Angular
|
|
223
|
+
|
|
224
|
+
Web components are [fully supported in Angular](https://custom-elements-everywhere.com/#angular) and can be used directly.
|
|
225
|
+
|
|
226
|
+
## Installation
|
|
227
|
+
|
|
228
|
+
Locally install the library or use CDN by adding the script tag to entry point of the Angular application (i.e. index.html)
|
|
229
|
+
|
|
230
|
+
## Configuration
|
|
231
|
+
|
|
232
|
+
Apply CUSTOM_ELEMENTS_SCHEMA as shown below
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
//app.module.ts
|
|
236
|
+
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
|
|
237
|
+
import { BrowserModule } from "@angular/platform-browser";
|
|
238
|
+
import { AppComponent } from "./app.component";
|
|
239
|
+
|
|
240
|
+
@NgModule({
|
|
241
|
+
declarations: [AppComponent],
|
|
242
|
+
imports: [BrowserModule],
|
|
243
|
+
providers: [],
|
|
244
|
+
bootstrap: [AppComponent],
|
|
245
|
+
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
|
246
|
+
})
|
|
247
|
+
export class AppModule {}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Importing the library
|
|
251
|
+
|
|
252
|
+
When using a several of our components it can be more convenient to import the entire library once in App Module and use it throughout the application
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
//app.module.ts
|
|
256
|
+
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
|
|
257
|
+
import { BrowserModule } from "@angular/platform-browser";
|
|
258
|
+
import { AppComponent } from "./app.component";
|
|
259
|
+
import "@govtechsg/sgds-web-component";
|
|
260
|
+
|
|
261
|
+
@NgModule({
|
|
262
|
+
declarations: [AppComponent],
|
|
263
|
+
imports: [BrowserModule],
|
|
264
|
+
providers: [],
|
|
265
|
+
bootstrap: [AppComponent],
|
|
266
|
+
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
|
267
|
+
})
|
|
268
|
+
export class AppModule {}
|
|
269
|
+
```
|
|
270
|
+
## Referencing sgds-web-components in Angular
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
//alert.component.ts
|
|
274
|
+
import { Component, ElementRef, ViewChild } from '@angular/core';
|
|
275
|
+
import { SgdsAlert } from '@govtechsg/sgds-web-component';
|
|
276
|
+
|
|
277
|
+
@Component({
|
|
278
|
+
selector: 'app-alert',
|
|
279
|
+
templateUrl: './alert.component.html',
|
|
280
|
+
styleUrls: ['./alert.component.css']
|
|
281
|
+
})
|
|
282
|
+
export class AlertComponent {
|
|
283
|
+
|
|
284
|
+
@ViewChild('alert')
|
|
285
|
+
alert? : ElementRef<SgdsAlert>
|
|
286
|
+
|
|
287
|
+
showAlert() {
|
|
288
|
+
this.alert?.nativeElement.show()
|
|
289
|
+
}
|
|
290
|
+
alertShowState?: boolean = false
|
|
291
|
+
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
//alert.component.html
|
|
295
|
+
<sgds-button (click)="showAlert()">{{buttonText}}</sgds-button>
|
|
296
|
+
<sgds-alert #alert [show]="alertShowState">Alerting</sgds-alert>
|
|
297
|
+
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
# React
|
|
301
|
+
|
|
302
|
+
Web components are [not fully supported in React](https://custom-elements-everywhere.com/#react) and should only be used directly when no rich data is required to be passed into the web components and your use case does not require any events handling.
|
|
303
|
+
|
|
304
|
+
Instead, our library outputs the React version of each of our web components. You can choose to use either the React components or the web components. This React instruction page mainly focuses on how to use the React version.
|
|
305
|
+
|
|
306
|
+
## Importing the library
|
|
307
|
+
|
|
308
|
+
Our components are exported via named exports. Import the components like so
|
|
309
|
+
|
|
310
|
+
```js
|
|
311
|
+
|
|
312
|
+
import { SgdsButton } from "@govtechsg/sgds-web-component/react";
|
|
313
|
+
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
The components follow React naming convention, using pascal case as the component name. See the example table below for the web components tagname and its corresponding React name.
|
|
317
|
+
|
|
318
|
+
| Web Components | React |
|
|
319
|
+
| ----------------- | --------------- |
|
|
320
|
+
| sgds-button | SgdsButton |
|
|
321
|
+
| sgds-mainnav | SgdsMainnav |
|
|
322
|
+
| sgds-mainnav-item | SgdsMainnavItem |
|
|
323
|
+
| sgds-textarea | SgdsTextarea |
|
|
324
|
+
|
|
325
|
+
```jsx
|
|
326
|
+
//Button.ts
|
|
327
|
+
import { SgdsButton } from "@govtechsg/sgds-web-component/react";
|
|
328
|
+
|
|
329
|
+
const ButtonWc = () => {
|
|
330
|
+
return <SgdsButton>Button</SgdsButton>;
|
|
331
|
+
};
|
|
332
|
+
export default ButtonWc;
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
## Event Handling
|
|
336
|
+
|
|
337
|
+
We follow the React convention for events name, each custom event emitted by the web component is prefixed with a `on` and converted to camel case. Native events still applies to the components.
|
|
338
|
+
|
|
339
|
+
For example:
|
|
340
|
+
|
|
341
|
+
| Web Components | React |
|
|
342
|
+
| --------------- | --------------- |
|
|
343
|
+
| sgds-change | onSgdsChange |
|
|
344
|
+
| sgds-toggle | onSgdsToggle |
|
|
345
|
+
| sgds-after-show | onSgdsAfterShow |
|
|
346
|
+
| sgds-after-hide | onSgdsAfterHide |
|
|
112
347
|
|
|
113
|
-
|
|
348
|
+
If you are using Typescript, note that `event.target` refers to the underlying custom element.
|
|
349
|
+
|
|
350
|
+
```tsx
|
|
351
|
+
import { useState } from 'react';
|
|
352
|
+
import { SgdsInput } from '@govtechsg/sgds-web-component/react';
|
|
353
|
+
import type { SgdsInput as SgdsInputElement } from '@govtechsg/sgds-web-component';
|
|
354
|
+
|
|
355
|
+
function MyComponent() {
|
|
356
|
+
const [value, setValue] = useState('');
|
|
357
|
+
|
|
358
|
+
return <SgdsInput value={value} onSgdsInput={event => setValue((event.target as SgdsInputElement).value)} />;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
export default MyComponent;
|
|
362
|
+
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
## NextJs
|
|
366
|
+
|
|
367
|
+
The support for NextJS and server side rendering is WIP.
|
|
368
|
+
|
|
369
|
+
# Vue
|
|
370
|
+
|
|
371
|
+
Web components are [fully supported in Vue](https://custom-elements-everywhere.com/#vue) and can be used directly.
|
|
372
|
+
|
|
373
|
+
## Installation
|
|
374
|
+
|
|
375
|
+
Locally install the library or use CDN by adding the script tag to entry point of the Vue application.
|
|
376
|
+
|
|
377
|
+
## Configuration
|
|
378
|
+
|
|
379
|
+
Tell Vue to ignore sgds web components and skip component resolution.
|
|
380
|
+
|
|
381
|
+
### Vite config example
|
|
382
|
+
|
|
383
|
+
```typescript
|
|
384
|
+
// vite.config.js
|
|
385
|
+
import vue from "@vitejs/plugin-vue";
|
|
386
|
+
|
|
387
|
+
export default {
|
|
388
|
+
plugins: [
|
|
389
|
+
vue({
|
|
390
|
+
template: {
|
|
391
|
+
compilerOptions: {
|
|
392
|
+
// treat all tags that starts with sgds as custom elements
|
|
393
|
+
isCustomElement: tag => tag.includes("sgds-")
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
})
|
|
397
|
+
]
|
|
398
|
+
};
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
### Vue CLI config example
|
|
402
|
+
|
|
403
|
+
```typescript
|
|
404
|
+
// vue.config.js
|
|
405
|
+
module.exports = {
|
|
406
|
+
chainWebpack: config => {
|
|
407
|
+
config.module
|
|
408
|
+
.rule("vue")
|
|
409
|
+
.use("vue-loader")
|
|
410
|
+
.tap(options => ({
|
|
411
|
+
...options,
|
|
412
|
+
compilerOptions: {
|
|
413
|
+
// treat any tag that starts with sgds- as custom elements
|
|
414
|
+
isCustomElement: tag => tag.startsWith("sgds-")
|
|
415
|
+
}
|
|
416
|
+
}));
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
## Importing the library
|
|
422
|
+
|
|
423
|
+
Import the library once in your entry point and use it throughout your application.
|
|
424
|
+
|
|
425
|
+
```typescript
|
|
426
|
+
//App.vue
|
|
427
|
+
<script>
|
|
428
|
+
import "@govtechsg/sgds-web-component"
|
|
429
|
+
|
|
430
|
+
export default {
|
|
431
|
+
name: "app",
|
|
432
|
+
components: {
|
|
433
|
+
...
|
|
434
|
+
},
|
|
435
|
+
};
|
|
436
|
+
</script>
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
## Usage
|
|
440
|
+
|
|
441
|
+
See Vue's documentation on usage with [custom elements](https://vuejs.org/guide/extras/web-components.html#building-custom-elements-with-vue)
|
|
442
|
+
|
|
443
|
+
```typescript
|
|
444
|
+
// e.g. Attribute binding with footer
|
|
445
|
+
<template>
|
|
446
|
+
<div>
|
|
447
|
+
<sgds-footer :title="footerAttr.title" :description="footerAttr.description" :lastUpdatedDate="footerAttr.date" .:links="footerAttr.links"></sgds-footer>
|
|
448
|
+
</div>
|
|
449
|
+
</template>
|
|
450
|
+
|
|
451
|
+
<script lang='ts'>
|
|
452
|
+
import { ref, computed } from "vue";
|
|
453
|
+
|
|
454
|
+
export default {
|
|
455
|
+
setup() {
|
|
456
|
+
const footerAttr = computed(() => ({
|
|
457
|
+
title: "Singapore Design System",
|
|
458
|
+
description: "this is a description",
|
|
459
|
+
date: new Date().toDateString(),
|
|
460
|
+
links : [
|
|
461
|
+
{
|
|
462
|
+
"title": "Column 1",
|
|
463
|
+
"links" : [
|
|
464
|
+
{
|
|
465
|
+
"href": "#1",
|
|
466
|
+
"label": "About Us"
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
"href": "#2",
|
|
470
|
+
"label": "This is a super long link"
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
"href": "#3",
|
|
474
|
+
"label": "Test"
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
"href": "#4",
|
|
478
|
+
"label": "Test"
|
|
479
|
+
}
|
|
480
|
+
]
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
"title": "Column 2",
|
|
484
|
+
"links" : [
|
|
485
|
+
{
|
|
486
|
+
"href": "#1",
|
|
487
|
+
"label": "About Us"
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
"href": "#2",
|
|
491
|
+
"label": "This is a super long link"
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
"href": "#3",
|
|
495
|
+
"label": "Test"
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
"href": "#4",
|
|
499
|
+
"label": "Test"
|
|
500
|
+
}
|
|
501
|
+
]
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
"title": "Column 3",
|
|
505
|
+
"links" : [
|
|
506
|
+
{
|
|
507
|
+
"href": "#1",
|
|
508
|
+
"label": "About Us"
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
"href": "#2",
|
|
512
|
+
"label": "This is a super long link"
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
"href": "#3",
|
|
516
|
+
"label": "Test"
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
"href": "#4",
|
|
520
|
+
"label": "Test"
|
|
521
|
+
}
|
|
522
|
+
]
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
"title": "Column 4",
|
|
526
|
+
"links" : [
|
|
527
|
+
{
|
|
528
|
+
"href": "#1",
|
|
529
|
+
"label": "About Us"
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
"href": "#2",
|
|
533
|
+
"label": "This is a super long link"
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
"href": "#3",
|
|
537
|
+
"label": "Test"
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
"href": "#4",
|
|
541
|
+
"label": "Test"
|
|
542
|
+
}
|
|
543
|
+
]
|
|
544
|
+
},
|
|
545
|
+
{
|
|
546
|
+
"title": "Column 5",
|
|
547
|
+
"links" : [
|
|
548
|
+
{
|
|
549
|
+
"href": "#1",
|
|
550
|
+
"label": "About Us"
|
|
551
|
+
},
|
|
552
|
+
{
|
|
553
|
+
"href": "#2",
|
|
554
|
+
"label": "This is a super long link"
|
|
555
|
+
},
|
|
556
|
+
{
|
|
557
|
+
"href": "#3",
|
|
558
|
+
"label": "Test"
|
|
559
|
+
},
|
|
560
|
+
{
|
|
561
|
+
"href": "#4",
|
|
562
|
+
"label": "Test"
|
|
563
|
+
}
|
|
564
|
+
]
|
|
565
|
+
},
|
|
566
|
+
{
|
|
567
|
+
"title": "Column 6",
|
|
568
|
+
"links" : [
|
|
569
|
+
{
|
|
570
|
+
"href": "#1",
|
|
571
|
+
"label": "About Us"
|
|
572
|
+
},
|
|
573
|
+
{
|
|
574
|
+
"href": "#2",
|
|
575
|
+
"label": "This is a super long link"
|
|
576
|
+
},
|
|
577
|
+
{
|
|
578
|
+
"href": "#3",
|
|
579
|
+
"label": "Test"
|
|
580
|
+
},
|
|
581
|
+
{
|
|
582
|
+
"href": "#4",
|
|
583
|
+
"label": "Test"
|
|
584
|
+
}
|
|
585
|
+
]
|
|
586
|
+
}
|
|
587
|
+
]
|
|
588
|
+
}))
|
|
589
|
+
return { footerAttr };
|
|
590
|
+
},
|
|
591
|
+
};
|
|
592
|
+
</script>
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
```typescript
|
|
596
|
+
// e.g. of v-model usage on sgds web components
|
|
597
|
+
// e.g. using sgds events for callbacks usage
|
|
598
|
+
<template>
|
|
599
|
+
<form>
|
|
600
|
+
<sgds-input @sgds-input="onInput" v-model="inputValue" placeholder="Enter your name">
|
|
601
|
+
</sgds-input>
|
|
602
|
+
<div>Name: {{inputValue}} </div>
|
|
603
|
+
</form>
|
|
604
|
+
</template>
|
|
605
|
+
|
|
606
|
+
<script lang='ts'>
|
|
607
|
+
import { ref, computed } from "vue";
|
|
608
|
+
|
|
609
|
+
export default {
|
|
610
|
+
setup() {
|
|
611
|
+
const inputValue = ref("defaultValue")
|
|
612
|
+
const onInput = () => {
|
|
613
|
+
console.log("inputting")
|
|
614
|
+
}
|
|
615
|
+
return { onInput, inputValue };
|
|
616
|
+
},
|
|
617
|
+
};
|
|
618
|
+
</script>
|
|
619
|
+
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
```typescript
|
|
623
|
+
// e.g. using slots in vue
|
|
624
|
+
<sgds-sidenav>
|
|
625
|
+
<sgds-sidenav-item>
|
|
626
|
+
<span slot="title"> SideNav Item #1 (control by Argstable) </span>
|
|
627
|
+
<sgds-sidenav-link>sgds-sidenav-link (control by Argstable)</sgds-sidenav-link>
|
|
628
|
+
<sgds-sidenav-link href="#" disabled="">
|
|
629
|
+
sgds-sidenav-link
|
|
630
|
+
</sgds-sidenav-link>
|
|
631
|
+
<sgds-sidenav-link href="#">sgds-sidenav-link</sgds-sidenav-link>
|
|
632
|
+
</sgds-sidenav-item>
|
|
633
|
+
<sgds-sidenav-item>
|
|
634
|
+
<span slot="title">SideNav Item #2</span>
|
|
635
|
+
<sgds-sidenav-link href="#">sgds-sidenav-link</sgds-sidenav-link>
|
|
636
|
+
<sgds-sidenav-link href="#">sgds-sidenav-link</sgds-sidenav-link>
|
|
637
|
+
<sgds-sidenav-link href="#">sgds-sidenav-link</sgds-sidenav-link>
|
|
638
|
+
</sgds-sidenav-item>
|
|
639
|
+
<sgds-sidenav-item href="#">
|
|
640
|
+
<span slot="title">SideNav Item #3</span>
|
|
641
|
+
</sgds-sidenav-item>
|
|
642
|
+
</sgds-sidenav>
|
|
643
|
+
```
|
package/base/card-element.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ export type CardBorderVariant = "primary" | "secondary" | "success" | "danger" |
|
|
|
3
3
|
export type CardTextVariant = "primary" | "secondary" | "success" | "danger" | "warning" | "info" | "dark" | "light" | "white" | "muted";
|
|
4
4
|
export declare class CardElement extends SgdsElement {
|
|
5
5
|
static styles: import("lit").CSSResultGroup;
|
|
6
|
-
|
|
6
|
+
/** The border's variant. */
|
|
7
|
+
borderColor: CardBorderVariant;
|
|
7
8
|
/** The bg's variant. */
|
|
8
|
-
bgColor
|
|
9
|
+
bgColor: CardBorderVariant;
|
|
9
10
|
/** The text's variant. */
|
|
10
|
-
textColor
|
|
11
|
-
disabled: boolean;
|
|
11
|
+
textColor: CardTextVariant;
|
|
12
12
|
}
|