@govtechsg/sgds-web-component 1.2.2 → 1.3.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.
Files changed (53) hide show
  1. package/Masthead/index.js +2 -2
  2. package/README.md +60 -74
  3. package/base/sgds-element.cjs2.js +1 -1
  4. package/base/sgds-element2.js +1 -1
  5. package/components/Accordion/index.umd.js +9 -4
  6. package/components/Accordion/index.umd.js.map +1 -1
  7. package/components/Accordion/sgds-accordion-item.cjs2.js +1 -1
  8. package/components/Accordion/sgds-accordion-item2.js +1 -1
  9. package/components/Accordion/sgds-accordion.cjs.js +5 -1
  10. package/components/Accordion/sgds-accordion.cjs.js.map +1 -1
  11. package/components/Accordion/sgds-accordion.cjs2.js +10 -0
  12. package/components/Accordion/sgds-accordion.cjs2.js.map +1 -0
  13. package/components/Accordion/sgds-accordion.d.ts +3 -0
  14. package/components/Accordion/sgds-accordion.js +5 -1
  15. package/components/Accordion/sgds-accordion.js.map +1 -1
  16. package/components/Accordion/sgds-accordion2.js +6 -0
  17. package/components/Accordion/sgds-accordion2.js.map +1 -0
  18. package/components/ActionCard/index.umd.js +1 -1
  19. package/components/Alert/index.umd.js +1 -1
  20. package/components/Badge/index.umd.js +1 -1
  21. package/components/Breadcrumb/index.umd.js +1 -1
  22. package/components/Button/index.umd.js +1 -1
  23. package/components/Card/index.umd.js +1 -1
  24. package/components/Checkbox/index.umd.js +1 -1
  25. package/components/ComboBox/index.umd.js +1 -1
  26. package/components/Datepicker/index.umd.js +1 -1
  27. package/components/Drawer/index.umd.js +1 -1
  28. package/components/Dropdown/index.umd.js +1 -1
  29. package/components/FileUpload/index.umd.js +1 -1
  30. package/components/Footer/index.umd.js +1 -1
  31. package/components/Input/index.umd.js +1 -1
  32. package/components/Mainnav/index.umd.js +1 -1
  33. package/components/Masthead/index.umd.js +2 -2
  34. package/components/Masthead/sgds-masthead.cjs2.js +1 -1
  35. package/components/Masthead/sgds-masthead2.js +1 -1
  36. package/components/Modal/index.umd.js +1 -1
  37. package/components/Pagination/index.umd.js +1 -1
  38. package/components/Progress/index.umd.js +1 -1
  39. package/components/QuantityToggle/index.umd.js +1 -1
  40. package/components/Radio/index.umd.js +1 -1
  41. package/components/Sidenav/index.umd.js +1 -1
  42. package/components/Spinner/index.umd.js +1 -1
  43. package/components/Stepper/index.umd.js +1 -1
  44. package/components/Tab/index.umd.js +1 -1
  45. package/components/Table/index.umd.js +1 -1
  46. package/components/Textarea/index.umd.js +1 -1
  47. package/components/Toast/index.umd.js +1 -1
  48. package/components/Tooltip/index.umd.js +1 -1
  49. package/components/index.umd.js +10 -5
  50. package/components/index.umd.js.map +1 -1
  51. package/index.umd.js +10 -5
  52. package/index.umd.js.map +1 -1
  53. package/package.json +2 -2
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
- <img src="https://img.shields.io/badge/lit-324FFF?style=for-the-badge&logo=lit&logoColor=white" /> &nbsp;
2
- <img src="https://img.shields.io/badge/Sass-CC6699?style=for-the-badge&logo=sass&logoColor=white" /> &nbsp;
3
- <img src="https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white" />&nbsp;
1
+ <img src="https://img.shields.io/badge/lit-324FFF?style=for-the-badge&logo=lit&logoColor=white" /> &nbsp;
2
+ <img src="https://img.shields.io/badge/Sass-CC6699?style=for-the-badge&logo=sass&logoColor=white" /> &nbsp;
3
+ <img src="https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white" />&nbsp;
4
4
 
5
5
  # sgds-web-component
6
6
 
7
7
  # Installation Guide
8
8
 
9
- You can load SGDS's web components via CDN or by installing it locally. The library depends on [scoped custom elements registry](https://open-wc.org/docs/development/scoped-elements/) and in certain cases, it is required to import the `@webcomponents/scoped-custom-element-registry` polyfill before the web components.
9
+ You can load SGDS's web components via CDN or by installing it locally. The library depends on [scoped custom elements registry](https://open-wc.org/docs/development/scoped-elements/) and in certain cases, it is required to import the `@webcomponents/scoped-custom-element-registry` polyfill before the web components.
10
10
 
11
11
  Refer to [open-wc's directive on scoped-elements](https://open-wc.org/docs/development/scoped-elements/#:~:text=load%20the%20polyfill%20if%20you%20need%20scoping) for more details to know when to use the polyfill.
12
12
 
@@ -14,12 +14,11 @@ Refer to [open-wc's directive on scoped-elements](https://open-wc.org/docs/devel
14
14
 
15
15
  The CDN loader registers all SGDS elements up front. Depending on your usage, you may or may not need to load the polyfill.
16
16
 
17
- > When using CDN, it is recommended to version control. On initial usage, pick the latest version of the library. See list of available npm versions [here](https://www.npmjs.com/package/@govtechsg/sgds-web-component?activeTab=versions)
17
+ > When using CDN, it is recommended to version control. On initial usage, pick the latest version of the library. See list of available npm versions [here](https://www.npmjs.com/package/@govtechsg/sgds-web-component?activeTab=versions)
18
18
 
19
19
  > Stick to the version that works for you and make intentional updates on your end when you need the latest library updates. Versions are immutable and thus, stable.
20
20
 
21
- > By not specifying the version, you are using the latest version and subjected to changes made by the library that are not tested on your end. While we do our best to ensure backward compatibility between patches and minor version updates, we cannot guarantee that we have covered all of our user's edge cases.
22
-
21
+ > By not specifying the version, you are using the latest version and subjected to changes made by the library that are not tested on your end. While we do our best to ensure backward compatibility between patches and minor version updates, we cannot guarantee that we have covered all of our user's edge cases.
23
22
 
24
23
  ```js
25
24
  // load scoped custom element registry polyfill first (optional, depends on use case)
@@ -41,16 +40,15 @@ You can also install SGDS web components locally with the following command
41
40
  npm install @govtechsg/sgds-web-component @webcomponents/scoped-custom-element-registry
42
41
 
43
42
  ```
44
- import the polyfill and library once in you entry point and use the web components throughout your project. Note that the scoped custom element registry polyfill has to be imported before any custom element registration happens.
43
+
44
+ import the polyfill and library once in you entry point and use the web components throughout your project. Note that the scoped custom element registry polyfill has to be imported before any custom element registration happens.
45
45
 
46
46
  ```js
47
47
  // import polyfill first (optional, depends on use case), follow by the web components
48
- import "@webcomponents/scoped-custom-element-registry"
48
+ import "@webcomponents/scoped-custom-element-registry";
49
49
  import "@govtechsg/sgds-web-component";
50
-
51
50
  ```
52
51
 
53
-
54
52
  # Imports
55
53
 
56
54
  ## Using the custom elements
@@ -60,7 +58,7 @@ Once imported, the custom elements can be used throughout the project.
60
58
  ```js
61
59
  // import all custom elements at once
62
60
  import "@govtechsg/sgds-web-component";
63
- // or import individual custom elements
61
+ // or import individual custom elements
64
62
  import "@govtechsg/sgds-web-component/components/Button";
65
63
 
66
64
  //usage
@@ -69,46 +67,41 @@ import "@govtechsg/sgds-web-component/components/Button";
69
67
 
70
68
  ## Using the component's class object
71
69
 
72
- When writing with Typescript, you might be required to type the components in certain cases. Import the component class like so.
70
+ When writing with Typescript, you might be required to type the components in certain cases. Import the component class like so.
73
71
  Each component's Class is exported via named exports, prefixed with `Sgds`.
74
72
 
75
73
  ```js
76
-
77
74
  import { SgdsButton, SgdsMainnav } from "@govtechsg/sgds-web-component/components";
78
75
  // or
79
76
  import { SgdsButton } from "@govtechsg/sgds-web-component/components/Button/sgds-button";
80
77
  import { SgdsMainnav } from "@govtechsg/sgds-web-component/components/Mainnav/sgds-mainnav";
81
-
82
78
  ```
79
+
83
80
  # Attributes and Properties
84
81
 
85
82
  ## String
86
83
 
87
- 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
88
-
89
- ```html
84
+ 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
90
85
 
86
+ ```html
91
87
  <sgds-button variant="secondary"></sgds-button>
92
-
93
88
  ```
94
89
 
95
- ## Boolean
90
+ ## Boolean
96
91
 
97
- Boolean properties are usually false by default. To set it to true, add it as an attribute with no value on the custom element
92
+ Boolean properties are usually false by default. To set it to true, add it as an attribute with no value on the custom element
98
93
 
99
94
  ```html
100
-
101
95
  <sgds-accordion allowMultiple>
102
96
  ...
103
97
  </sgds-accordion>
104
98
 
105
99
  <sgds-input disabled></sgds-input>
106
-
107
100
  ```
108
101
 
109
102
  ## Objects, Arrays and Functions
110
103
 
111
- 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.
104
+ 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.
112
105
 
113
106
  ```html
114
107
  //via JSON string
@@ -116,44 +109,42 @@ Functions have to be passed in via javascript. For attributes that accepts Objec
116
109
 
117
110
  // via Javascript
118
111
  <script>
119
- const table = document.querySelector('sgds-table');
120
- table.tableHeaders = ['Name', 'Birthdate'];
112
+ const table = document.querySelector("sgds-table");
113
+ table.tableHeaders = ["Name", "Birthdate"];
121
114
  </script>
122
115
  ```
116
+
123
117
  # Events
124
118
 
125
119
  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.
126
120
 
127
- 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.
121
+ 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.
128
122
 
129
123
  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.
130
124
 
131
125
  ```html
132
-
133
126
  <sgds-checkbox>Check me</sgds-checkbox>
134
127
 
135
128
  <script>
136
- const checkbox = document.querySelector('sgds-checkbox');
137
- checkbox.addEventListener('sgds-change', event => {
138
- console.log(event.target.checked ? 'checked' : 'not checked');
129
+ const checkbox = document.querySelector("sgds-checkbox");
130
+ checkbox.addEventListener("sgds-change", event => {
131
+ console.log(event.target.checked ? "checked" : "not checked");
139
132
  });
140
133
  </script>
141
-
142
134
  ```
135
+
143
136
  # Slots
144
137
 
145
138
  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.
146
139
 
147
140
  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.
148
141
 
149
- Handle the usage of the default slot and named slot as below
142
+ Handle the usage of the default slot and named slot as below
150
143
 
151
144
  1. default slot : `<slot></slot>`
152
145
 
153
146
  ```html
154
-
155
147
  <sgds-button><span>Hello World</span></sgds-button>
156
-
157
148
  ```
158
149
 
159
150
  "Hello World" span element is placed in the default slot
@@ -161,12 +152,10 @@ There are two kinds of slots: default and named slots. In the storybook document
161
152
  2. named slot : `<slot name="icon"></slot>`
162
153
 
163
154
  ```html
164
-
165
155
  <sgds-button>
166
156
  <span>Hello World</span>
167
157
  <svg slot="icon"></svg>
168
158
  </sgds-button>
169
-
170
159
  ```
171
160
 
172
161
  The svg element with attribute `slot=icon` is placed in the named slot
@@ -177,15 +166,15 @@ There are two kinds of slots: default and named slots. In the storybook document
177
166
 
178
167
  The following css custom variable are exposed to enable users to make modifications across all web components in our library
179
168
 
180
- | css custom variable name | description |
181
- | ------------------------ | ----------------------------------------- |
182
- | --sgds-body-font-family | Set the font family of the web components |
183
- | --sgds-body-font-size | Set the font size of the web components |
184
- | --sgds-body-font-weight | Set the font weight of the web components |
185
- | --sgds-body-line-height | Set the line height of the web components |
186
- | --sgds-{stateColor}-rgb | State colors in red,green,blue value |
187
- | --sgds-{stateColor} | State colors in hexadecimal value |
188
- | --sgds-{stateColor} | State colors in hexadecimal value |
169
+ | css custom variable name | description |
170
+ | ---------------------------- | ---------------------------------------------------------- |
171
+ | --sgds-body-font-family | Set the font family of the web components |
172
+ | --sgds-body-font-size | Set the font size of the web components |
173
+ | --sgds-body-font-weight | Set the font weight of the web components |
174
+ | --sgds-body-line-height | Set the line height of the web components |
175
+ | --sgds-{stateColor}-rgb | State colors in red,green,blue value |
176
+ | --sgds-{stateColor} | State colors in hexadecimal value |
177
+ | --sgds-{stateColor} | State colors in hexadecimal value |
189
178
  | --sgds-{stateColor}-{weight} | State colors with different weightage in hexadecimal value |
190
179
  | --sgds-gray-{weight} | Gray colors with different weightage in hexadecimal value |
191
180
 
@@ -194,16 +183,14 @@ The following css custom variable are exposed to enable users to make modificati
194
183
  > `{weight}` are color weightage in hundreds starting from `100` up to `900`
195
184
 
196
185
  ```css
197
-
198
186
  :root {
199
- --sgds-body-font-family: Helvetica;
187
+ --sgds-body-font-family: "Inter";
200
188
  --sgds-body-font-size: 5rem;
201
- --sgds-primary-rgb : 89,37,220;
202
- --sgds-secondary : #1f69ff;
203
- --sgds-success-500 : #3bb346;
204
- --sgds-gray-500 : #667085;
189
+ --sgds-primary-rgb: 89, 37, 220;
190
+ --sgds-secondary: #1f69ff;
191
+ --sgds-success-500: #3bb346;
192
+ --sgds-gray-500: #667085;
205
193
  }
206
-
207
194
  ```
208
195
 
209
196
  ## Component Styles
@@ -256,9 +243,10 @@ Any external stylings done on our web components like positioning needs to be do
256
243
 
257
244
  Web components are [fully supported in Angular](https://custom-elements-everywhere.com/#angular) and can be used directly.
258
245
 
259
- ## Demo app
246
+ ## Demo app
247
+
248
+ Refer to this [stackblitz demo app](https://stackblitz.com/github/clukhei/angular-stepper?file=README.md) on the usage example
260
249
 
261
- Refer to this [stackblitz demo app](https://stackblitz.com/github/clukhei/angular-stepper?file=README.md) on the usage example
262
250
  ## Installation
263
251
 
264
252
  Locally install the library or use CDN by adding the script tag to entry point of the Angular application (i.e. index.html). Follow instructions in `Installation` and `Imports` documentation section
@@ -303,6 +291,7 @@ import "@govtechsg/sgds-web-component";
303
291
  })
304
292
  export class AppModule {}
305
293
  ```
294
+
306
295
  ## Referencing sgds-web-components in Angular
307
296
 
308
297
  ```typescript
@@ -339,9 +328,9 @@ Web components are [not fully supported in React](https://custom-elements-everyw
339
328
 
340
329
  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.
341
330
 
342
- ## Demo app
331
+ ## Demo app
343
332
 
344
- Refer to this [stackblitz demo app](https://stackblitz.com/edit/vitejs-vite-gebvf5) on the usage example
333
+ Refer to this [stackblitz demo app](https://stackblitz.com/edit/vitejs-vite-gebvf5) on the usage example
345
334
 
346
335
  ## Importing the library
347
336
 
@@ -349,12 +338,10 @@ Follow instructions in `Installation` documentation section.
349
338
  Our components are exported via named exports. Import the components like so
350
339
 
351
340
  ```js
352
-
353
341
  import { SgdsButton, SgdsTooltip } from "@govtechsg/sgds-web-component/react";
354
342
  // or
355
343
  import { SgdsButton } from "@govtechsg/sgds-web-component/react/button";
356
344
  import { SgdsTooltip } from "@govtechsg/sgds-web-component/react/tooltip";
357
-
358
345
  ```
359
346
 
360
347
  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.
@@ -389,34 +376,33 @@ For example:
389
376
  | sgds-after-show | onSgdsAfterShow |
390
377
  | sgds-after-hide | onSgdsAfterHide |
391
378
 
392
- If you are using Typescript, note that `event.target` refers to the underlying custom element.
379
+ If you are using Typescript, note that `event.target` refers to the underlying custom element.
393
380
 
394
381
  ```tsx
395
- import { useState } from 'react';
396
- import { SgdsInput } from '@govtechsg/sgds-web-component/react';
397
- import type { SgdsInput as SgdsInputElement } from '@govtechsg/sgds-web-component';
382
+ import { useState } from "react";
383
+ import { SgdsInput } from "@govtechsg/sgds-web-component/react";
384
+ import type { SgdsInput as SgdsInputElement } from "@govtechsg/sgds-web-component";
398
385
 
399
386
  function MyComponent() {
400
- const [value, setValue] = useState('');
387
+ const [value, setValue] = useState("");
401
388
 
402
389
  return <SgdsInput value={value} onSgdsInput={event => setValue((event.target as SgdsInputElement).value)} />;
403
390
  }
404
391
 
405
392
  export default MyComponent;
406
-
407
393
  ```
408
394
 
409
395
  ## NextJs
410
396
 
411
- The support for NextJS and server side rendering is WIP.
397
+ The support for NextJS and server side rendering is WIP.
412
398
 
413
399
  # Vue
414
400
 
415
401
  Web components are [fully supported in Vue](https://custom-elements-everywhere.com/#vue) and can be used directly.
416
402
 
417
- ## Demo app
403
+ ## Demo app
418
404
 
419
- Refer to this [stackblitz demo app](https://stackblitz.com/github/clukhei/web-components-with-vue?file=README.md) on the usage example
405
+ Refer to this [stackblitz demo app](https://stackblitz.com/github/clukhei/web-components-with-vue?file=README.md) on the usage example
420
406
 
421
407
  ## Installation
422
408
 
@@ -690,10 +676,9 @@ export default {
690
676
  </sgds-sidenav>
691
677
  ```
692
678
 
693
- # Extending sgds-web-component
694
-
695
- For users who are leveraging on sgds-web-component as a building block to build and export your own web component library with Lit, you will have to adopt the scoped elements approach to prevent any foreseeable clash of registries between sgds-web-component and your web component library in the case where your users are importing both libraries.
679
+ # Extending sgds-web-component
696
680
 
681
+ For users who are leveraging on sgds-web-component as a building block to build and export your own web component library with Lit, you will have to adopt the scoped elements approach to prevent any foreseeable clash of registries between sgds-web-component and your web component library in the case where your users are importing both libraries.
697
682
 
698
683
  ## Scoped Elements
699
684
 
@@ -703,10 +688,11 @@ Whenever a sgds component uses composition (meaning it uses another sgds compone
703
688
 
704
689
  For users who are using sgds component directly for builing application, use the custom elements directly by [importing the custom elements](#using-the-custom-elements)
705
690
 
706
- For users who are building component libraries on top of sgds-web-component, please adopt OpenWC's scoped elements to prevent exporting our registered custom elements.
691
+ For users who are building component libraries on top of sgds-web-component, please adopt OpenWC's scoped elements to prevent exporting our registered custom elements.
692
+
693
+ Things to note:
707
694
 
708
- Things to note:
709
- 1. Import component class from `@govtechsg/sgds-web-component/components`. Here the components are not registered in the custom element registry
695
+ 1. Import component class from `@govtechsg/sgds-web-component/components`. Here the components are not registered in the custom element registry
710
696
  2. Define the tagName you want to assign to the component's class
711
697
 
712
698
  Example below