@covalent/components 0.0.0-COVALENT

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 (264) hide show
  1. package/.babelrc +10 -0
  2. package/.eslintrc.json +18 -0
  3. package/.storybook/main.js +34 -0
  4. package/.storybook/manager-head.html +62 -0
  5. package/.storybook/manager.js +1 -0
  6. package/.storybook/preview-head.html +20 -0
  7. package/.storybook/preview.js +20 -0
  8. package/README.md +179 -0
  9. package/component-config.json +313 -0
  10. package/index.html +288 -0
  11. package/jest.config.js +18 -0
  12. package/package.json +315 -0
  13. package/project.json +104 -0
  14. package/public/index.scss +1 -0
  15. package/public/reset.css +128 -0
  16. package/src/action-ribbon/_action-ribbon.theme.scss +90 -0
  17. package/src/action-ribbon/action-ribbon-base.ts +164 -0
  18. package/src/action-ribbon/action-ribbon.scss +20 -0
  19. package/src/action-ribbon/action-ribbon.spec.ts +11 -0
  20. package/src/action-ribbon/action-ribbon.stories.js +78 -0
  21. package/src/action-ribbon/action-ribbon.ts +26 -0
  22. package/src/alert/_alert.theme.scss +116 -0
  23. package/src/alert/alert-base.ts +175 -0
  24. package/src/alert/alert.scss +55 -0
  25. package/src/alert/alert.spec.ts +26 -0
  26. package/src/alert/alert.stories.js +76 -0
  27. package/src/alert/alert.ts +26 -0
  28. package/src/app-shell/app-shell.scss +387 -0
  29. package/src/app-shell/app-shell.stories.js +323 -0
  30. package/src/app-shell/app-shell.ts +388 -0
  31. package/src/badge/badge.scss +60 -0
  32. package/src/badge/badge.spec.ts +40 -0
  33. package/src/badge/badge.stories.js +88 -0
  34. package/src/badge/badge.ts +122 -0
  35. package/src/button/Overview.mdx +160 -0
  36. package/src/button/button.scss +28 -0
  37. package/src/button/button.spec.ts +11 -0
  38. package/src/button/button.stories.js +102 -0
  39. package/src/button/button.ts +17 -0
  40. package/src/card/card-base.ts +69 -0
  41. package/src/card/card.scss +45 -0
  42. package/src/card/card.spec.ts +11 -0
  43. package/src/card/card.ts +21 -0
  44. package/src/card/cards.stories.js +40 -0
  45. package/src/checkbox/checkbox.scss +8 -0
  46. package/src/checkbox/checkbox.spec.ts +11 -0
  47. package/src/checkbox/checkbox.stories.js +61 -0
  48. package/src/checkbox/checkbox.ts +18 -0
  49. package/src/chips/chip-base.ts +276 -0
  50. package/src/chips/chip-set-base.ts +184 -0
  51. package/src/chips/chip-set.scss +15 -0
  52. package/src/chips/chip-set.spec.ts +11 -0
  53. package/src/chips/chip-set.ts +27 -0
  54. package/src/chips/chip.scss +40 -0
  55. package/src/chips/chip.spec.ts +11 -0
  56. package/src/chips/chip.ts +26 -0
  57. package/src/chips/chips.stories.js +81 -0
  58. package/src/circular-progress/circular-progress.spec.ts +11 -0
  59. package/src/circular-progress/circular-progress.stories.js +40 -0
  60. package/src/circular-progress/circular-progress.ts +16 -0
  61. package/src/code-editor/code-editor.scss +20 -0
  62. package/src/code-editor/code-editor.spec.ts +11 -0
  63. package/src/code-editor/code-editor.stories.js +44 -0
  64. package/src/code-editor/code-editor.theme.ts +199 -0
  65. package/src/code-editor/code-editor.ts +231 -0
  66. package/src/code-snippet/code-snippet.scss +126 -0
  67. package/src/code-snippet/code-snippet.spec.ts +11 -0
  68. package/src/code-snippet/code-snippet.stories.js +134 -0
  69. package/src/code-snippet/code-snippet.ts +93 -0
  70. package/src/data-table/_data-table.theme.scss +39 -0
  71. package/src/data-table/data-table.stories.js +24 -0
  72. package/src/data-table/data-table.stories.scss +11 -0
  73. package/src/dialog/Overview.mdx +39 -0
  74. package/src/dialog/dialog.scss +17 -0
  75. package/src/dialog/dialog.spec.ts +11 -0
  76. package/src/dialog/dialog.stories.js +89 -0
  77. package/src/dialog/dialog.ts +44 -0
  78. package/src/drawer/drawer.scss +4 -0
  79. package/src/drawer/drawer.spec.ts +11 -0
  80. package/src/drawer/drawer.ts +18 -0
  81. package/src/empty-state/_empty-state.theme.scss +0 -0
  82. package/src/empty-state/empty-state.scss +67 -0
  83. package/src/empty-state/empty-state.spec.ts +11 -0
  84. package/src/empty-state/empty-state.stories.js +117 -0
  85. package/src/empty-state/empty-state.ts +61 -0
  86. package/src/expansion-panel/Overview.mdx +108 -0
  87. package/src/expansion-panel/expansion-panel-incorrect-example.png +0 -0
  88. package/src/expansion-panel/expansion-panel-item.scss +243 -0
  89. package/src/expansion-panel/expansion-panel-item.ts +95 -0
  90. package/src/expansion-panel/expansion-panel.spec.ts +11 -0
  91. package/src/expansion-panel/expansion-panel.stories.js +76 -0
  92. package/src/expansion-panel/expansion-panel.ts +94 -0
  93. package/src/focused-page/focused-page.scss +113 -0
  94. package/src/focused-page/focused-page.spec.ts +11 -0
  95. package/src/focused-page/focused-page.stories.js +167 -0
  96. package/src/focused-page/focused-page.ts +201 -0
  97. package/src/formfield/formfield.scss +8 -0
  98. package/src/formfield/formfield.spec.ts +11 -0
  99. package/src/formfield/formfield.ts +24 -0
  100. package/src/full-screen-dialog/full-screen-dialog.scss +37 -0
  101. package/src/full-screen-dialog/full-screen-dialog.spec.ts +11 -0
  102. package/src/full-screen-dialog/full-screen-dialog.stories.js +172 -0
  103. package/src/full-screen-dialog/full-screen-dialog.ts +84 -0
  104. package/src/icon/_icon-list.ts +316 -0
  105. package/src/icon/icon-demo.scss +25 -0
  106. package/src/icon/icon-demo.ts +37 -0
  107. package/src/icon/icon.spec.ts +11 -0
  108. package/src/icon/icon.stories.js +55 -0
  109. package/src/icon/icon.ts +16 -0
  110. package/src/icon-button/_icon-button.theme.scss +9 -0
  111. package/src/icon-button/icon-button.scss +12 -0
  112. package/src/icon-button/icon-button.spec.ts +11 -0
  113. package/src/icon-button/icon-button.stories.js +24 -0
  114. package/src/icon-button/icon-button.ts +19 -0
  115. package/src/icon-button-toggle/icon-button-toggle.scss +19 -0
  116. package/src/icon-button-toggle/icon-button-toggle.spec.ts +11 -0
  117. package/src/icon-button-toggle/icon-button-toggle.stories.js +32 -0
  118. package/src/icon-button-toggle/icon-button-toggle.ts +50 -0
  119. package/src/icon-checkbox/icon-check-toggle.ts +64 -0
  120. package/src/icon-checkbox/icon-check.spec.ts +11 -0
  121. package/src/icon-checkbox/icon-checkbox.scss +95 -0
  122. package/src/icon-checkbox/icon-checkbox.stories.js +77 -0
  123. package/src/icon-lockup/icon-lockup.scss +47 -0
  124. package/src/icon-lockup/icon-lockup.spec.ts +11 -0
  125. package/src/icon-lockup/icon-lockup.stories.js +93 -0
  126. package/src/icon-lockup/icon-lockup.ts +125 -0
  127. package/src/icon-radio/icon-radio-toggle.ts +43 -0
  128. package/src/icon-radio/icon-radio.scss +63 -0
  129. package/src/icon-radio/icon-radio.spec.ts +11 -0
  130. package/src/icon-radio/icon-radio.stories.js +23 -0
  131. package/src/index.scss +1 -0
  132. package/src/index.ts +57 -0
  133. package/src/linear-progress/linear-progress.scss +4 -0
  134. package/src/linear-progress/linear-progress.spec.ts +11 -0
  135. package/src/linear-progress/linear-progress.stories.js +43 -0
  136. package/src/linear-progress/linear-progress.ts +18 -0
  137. package/src/list/Overview.mdx +91 -0
  138. package/src/list/_list.theme.scss +100 -0
  139. package/src/list/check-list-item.spec.ts +11 -0
  140. package/src/list/check-list-item.ts +25 -0
  141. package/src/list/list-item.scss +56 -0
  142. package/src/list/list-item.spec.ts +11 -0
  143. package/src/list/list-item.ts +31 -0
  144. package/src/list/list.scss +25 -0
  145. package/src/list/list.stories.js +120 -0
  146. package/src/list/list.ts +23 -0
  147. package/src/list/nav-list-item.scss +159 -0
  148. package/src/list/nav-list-item.ts +223 -0
  149. package/src/list/radio-list-item.ts +25 -0
  150. package/src/menu/menu.scss +3 -0
  151. package/src/menu/menu.spec.ts +11 -0
  152. package/src/menu/menu.stories.js +110 -0
  153. package/src/menu/menu.ts +23 -0
  154. package/src/notebook-cell/notebook-cell.scss +185 -0
  155. package/src/notebook-cell/notebook-cell.spec.ts +11 -0
  156. package/src/notebook-cell/notebook-cell.stories.js +87 -0
  157. package/src/notebook-cell/notebook-cell.ts +300 -0
  158. package/src/radio/radio.scss +3 -0
  159. package/src/radio/radio.spec.ts +11 -0
  160. package/src/radio/radio.stories.js +56 -0
  161. package/src/radio/radio.ts +18 -0
  162. package/src/select/select.scss +16 -0
  163. package/src/select/select.spec.ts +11 -0
  164. package/src/select/select.stories.js +57 -0
  165. package/src/select/select.ts +18 -0
  166. package/src/side-sheet/side-sheet.scss +49 -0
  167. package/src/side-sheet/side-sheet.spec.ts +11 -0
  168. package/src/side-sheet/side-sheet.stories.js +96 -0
  169. package/src/side-sheet/side-sheet.ts +37 -0
  170. package/src/skeleton/_skeleton.styles.scss +24 -0
  171. package/src/skeleton/skeleton.stories.js +77 -0
  172. package/src/slider/slider-range.ts +16 -0
  173. package/src/slider/slider.spec.ts +11 -0
  174. package/src/slider/slider.stories.js +54 -0
  175. package/src/slider/slider.ts +16 -0
  176. package/src/snackbar/snackbar.scss +8 -0
  177. package/src/snackbar/snackbar.spec.ts +11 -0
  178. package/src/snackbar/snackbar.stories.js +42 -0
  179. package/src/snackbar/snackbar.ts +18 -0
  180. package/src/status-dialog/status-dialog.scss +204 -0
  181. package/src/status-dialog/status-dialog.spec.ts +48 -0
  182. package/src/status-dialog/status-dialog.stories.js +136 -0
  183. package/src/status-dialog/status-dialog.ts +188 -0
  184. package/src/status-header/_status-header.theme.scss +79 -0
  185. package/src/status-header/status-header-base.ts +42 -0
  186. package/src/status-header/status-header-item.scss +17 -0
  187. package/src/status-header/status-header-item.spec.ts +11 -0
  188. package/src/status-header/status-header-item.ts +32 -0
  189. package/src/status-header/status-header.scss +57 -0
  190. package/src/status-header/status-header.spec.ts +11 -0
  191. package/src/status-header/status-header.stories.js +114 -0
  192. package/src/status-header/status-header.ts +26 -0
  193. package/src/switch/switch.scss +17 -0
  194. package/src/switch/switch.spec.ts +11 -0
  195. package/src/switch/switch.stories.js +41 -0
  196. package/src/switch/switch.ts +18 -0
  197. package/src/tab/Overview.mdx +38 -0
  198. package/src/tab/tab-bar.spec.ts +11 -0
  199. package/src/tab/tab-bar.ts +16 -0
  200. package/src/tab/tab.scss +10 -0
  201. package/src/tab/tab.spec.ts +11 -0
  202. package/src/tab/tab.stories.js +30 -0
  203. package/src/tab/tab.ts +18 -0
  204. package/src/text-lockup/text-lockup.scss +66 -0
  205. package/src/text-lockup/text-lockup.spec.ts +11 -0
  206. package/src/text-lockup/text-lockup.stories.js +67 -0
  207. package/src/text-lockup/text-lockup.ts +55 -0
  208. package/src/textarea/textarea.spec.ts +11 -0
  209. package/src/textarea/textarea.stories.js +39 -0
  210. package/src/textarea/textarea.ts +19 -0
  211. package/src/textfield/textfield.scss +34 -0
  212. package/src/textfield/textfield.spec.ts +11 -0
  213. package/src/textfield/textfield.stories.js +60 -0
  214. package/src/textfield/textfield.ts +25 -0
  215. package/src/theme/_index.scss +46 -0
  216. package/src/theme/prebuilt/dark-theme.scss +17 -0
  217. package/src/theme/prebuilt/light-theme.scss +17 -0
  218. package/src/toolbar/toolbar.scss +37 -0
  219. package/src/toolbar/toolbar.spec.ts +11 -0
  220. package/src/toolbar/toolbar.stories.js +66 -0
  221. package/src/toolbar/toolbar.ts +27 -0
  222. package/src/tooltip/tooltip.scss +16 -0
  223. package/src/tooltip/tooltip.spec.ts +11 -0
  224. package/src/tooltip/tooltip.stories.js +72 -0
  225. package/src/tooltip/tooltip.ts +185 -0
  226. package/src/top-app-bar/top-app-bar-fixed.ts +23 -0
  227. package/src/top-app-bar/top-app-bar.scss +14 -0
  228. package/src/top-app-bar/top-app-bar.spec.ts +11 -0
  229. package/src/top-app-bar/top-app-bar.stories.js +41 -0
  230. package/src/top-app-bar/top-app-bar.ts +23 -0
  231. package/src/tree-list/tree-list-item.scss +96 -0
  232. package/src/tree-list/tree-list-item.spec.ts +11 -0
  233. package/src/tree-list/tree-list-item.ts +87 -0
  234. package/src/tree-list/tree-list.scss +13 -0
  235. package/src/tree-list/tree-list.spec.ts +11 -0
  236. package/src/tree-list/tree-list.stories.js +151 -0
  237. package/src/tree-list/tree-list.ts +53 -0
  238. package/src/typography/typography.scss +45 -0
  239. package/src/typography/typography.spec.ts +11 -0
  240. package/src/typography/typography.stories.js +23 -0
  241. package/src/typography/typography.ts +27 -0
  242. package/stories/Introduction.mdx +47 -0
  243. package/stories/color-use.mdx +509 -0
  244. package/stories/demos/dialog.component.html +187 -0
  245. package/stories/demos/dialog.component.js +57 -0
  246. package/stories/demos/grid.content.html +99 -0
  247. package/stories/demos/lorem-ipsum.content.html +338 -0
  248. package/stories/demos/material-web.content.html +2125 -0
  249. package/stories/demos/table-column-sorting.content.html +92 -0
  250. package/stories/demos/table-pagination.content.html +139 -0
  251. package/stories/demos/table-progress-indicator.content.html +77 -0
  252. package/stories/demos/table-row-selection.content.html +219 -0
  253. package/stories/demos/table.content.html +64 -0
  254. package/stories/demos/top-app-bar.component.js +57 -0
  255. package/stories/guide-representing-state.mdx +282 -0
  256. package/stories/info-and-help.mdx +484 -0
  257. package/stories/item-detail-and-editing.mdx +529 -0
  258. package/stories/markdown-elements.mdx +194 -0
  259. package/stories/writing-and-naming.mdx +157 -0
  260. package/tsconfig.json +34 -0
  261. package/tsconfig.lib.json +17 -0
  262. package/tsconfig.spec.json +14 -0
  263. package/types.d.ts +15 -0
  264. package/vite.config.js +58 -0
@@ -0,0 +1,276 @@
1
+ import { addHasRemoveClass } from '@material/mwc-base';
2
+ import { MDCChipFoundation } from '@material/chips/chip/foundation';
3
+ import {
4
+ MDCChipAttributes,
5
+ MDCChipCssClasses,
6
+ MDCChipEvents,
7
+ MDCChipAnimation,
8
+ } from '@material/chips/chip/constants';
9
+ import { MDCChipAction, MDCChipActionEvents } from '@material/chips/action';
10
+ import {
11
+ MDCChipActionFocusBehavior,
12
+ MDCChipActionType,
13
+ } from '@material/chips/action/constants';
14
+ import { MDCChipAdapter } from '@material/chips/chip/adapter';
15
+ import { property, query } from 'lit/decorators.js';
16
+ import { html, LitElement } from 'lit';
17
+ import { classMap } from 'lit/directives/class-map.js';
18
+
19
+ let tdChipsId = 0;
20
+
21
+ export class ChipBase extends LitElement {
22
+ protected mdcFoundation?: MDCChipFoundation;
23
+ protected readonly mdcFoundationClass = MDCChipFoundation;
24
+ protected actions!: Map<MDCChipActionType, MDCChipAction>;
25
+ protected chipId!: number;
26
+
27
+ @query('.mdc-evolution-chip') protected mdcRoot!: HTMLElement;
28
+
29
+ /**
30
+ * The text label of the chip
31
+ */
32
+ @property()
33
+ label = '';
34
+
35
+ /**
36
+ * The icon name to use for primary or leading chip
37
+ */
38
+ @property({ type: String }) icon = '';
39
+
40
+ @property({ type: Boolean, reflect: true }) trailingIcon = false;
41
+
42
+ @property({ type: Boolean, reflect: true }) avatar = false;
43
+
44
+ /**
45
+ * The text label of the chip
46
+ */
47
+ @property({ type: Boolean, reflect: true }) disabled = false;
48
+
49
+ /**
50
+ * Set the filter chip varient
51
+ */
52
+ @property({ type: Boolean, reflect: true }) filter = false;
53
+
54
+ /**
55
+ * The state representation secondary|negative|positive|caution
56
+ */
57
+ @property()
58
+ state?: 'secondary' | 'negative' | 'positive' | 'caution';
59
+
60
+ constructor() {
61
+ super();
62
+ this.chipId = tdChipsId++;
63
+ }
64
+
65
+ protected override render() {
66
+ const classes = {
67
+ 'mdc-evolution-chip': true,
68
+ 'mdc-evolution-chip--disabled': this.disabled,
69
+ 'mdc-evolution-chip--with-trailing-action': this.trailingIcon,
70
+ 'mdc-evolution-chip--with-primary-graphic':
71
+ !this.trailingIcon && this.icon,
72
+ 'mdc-evolution-chip--with-primary-icon': this.icon && !this.filter,
73
+ 'mdc-evolution-chip--filter': this.filter,
74
+ 'mdc-evolution-chip--selectable': this.filter,
75
+ 'mdc-evolution-chip--with-avatar': this.avatar,
76
+ secondary: this.state === 'secondary',
77
+ positive: this.state === 'positive',
78
+ negative: this.state === 'negative',
79
+ caution: this.state === 'caution',
80
+ };
81
+ return html`
82
+ <span
83
+ class="${classMap(classes)}"
84
+ role="${this.filter ? 'presentation' : 'row'}"
85
+ id="cv-chip-${this.chipId}"
86
+ >
87
+ <span
88
+ class="mdc-evolution-chip__cell mdc-evolution-chip__cell--primary"
89
+ role="${this.filter ? 'presentation' : 'gridcell'}"
90
+ >
91
+ <button
92
+ class="mdc-evolution-chip__action mdc-evolution-chip__action--primary"
93
+ role="${this.filter ? 'option' : ''}"
94
+ type="button"
95
+ tabindex="-1"
96
+ >
97
+ <span
98
+ class="mdc-evolution-chip__ripple mdc-evolution-chip__ripple--primary"
99
+ ></span>
100
+ ${(!this.trailingIcon && this.icon) || this.filter
101
+ ? this.renderGraphic()
102
+ : ''}
103
+ <span class="mdc-evolution-chip__text-label">${this.label}</span>
104
+ </button>
105
+ </span>
106
+ ${this.trailingIcon ? this.renderTrailing() : ''}
107
+ </span>
108
+ `;
109
+ }
110
+
111
+ protected override async firstUpdated() {
112
+ if (this.mdcFoundation !== undefined) {
113
+ this.mdcFoundation.destroy();
114
+ }
115
+ this.mdcFoundation = new this.mdcFoundationClass(this.createAdapter());
116
+
117
+ this.actions = new Map();
118
+ const actionEls = this.mdcRoot.querySelectorAll(
119
+ '.mdc-evolution-chip__action'
120
+ );
121
+ for (let i = 0; i < actionEls.length; i++) {
122
+ const action = new MDCChipAction(actionEls[i] as HTMLElement);
123
+ this.actions.set(action.actionType(), action);
124
+ actionEls[i].addEventListener(
125
+ MDCChipActionEvents.INTERACTION,
126
+ (event) => {
127
+ this.mdcFoundation?.handleActionInteraction(event as any);
128
+ }
129
+ );
130
+ actionEls[i].addEventListener(MDCChipActionEvents.NAVIGATION, (event) => {
131
+ this.mdcFoundation?.handleActionNavigation(event as any);
132
+ });
133
+ }
134
+ }
135
+
136
+ protected renderGraphic() {
137
+ const graphicContent = this.filter
138
+ ? this.renderCheckMark()
139
+ : this.renderIcon();
140
+ return html`<span class="mdc-evolution-chip__graphic">
141
+ ${graphicContent}
142
+ </span>`;
143
+ }
144
+
145
+ protected renderCheckMark() {
146
+ return html` <span class="mdc-evolution-chip__checkmark">
147
+ <svg class="mdc-evolution-chip__checkmark-svg" viewBox="-2 -3 30 30">
148
+ <path
149
+ class="mdc-evolution-chip__checkmark-path"
150
+ fill="none"
151
+ d="M1.73,12.91 8.1,19.28 22.79,4.59"
152
+ />
153
+ </svg>
154
+ </span>`;
155
+ }
156
+
157
+ protected renderIcon(trailing = false) {
158
+ return html` <span
159
+ class="mdc-evolution-chip__icon mdc-evolution-chip__icon--${trailing
160
+ ? 'trailing'
161
+ : 'primary'}"
162
+ >
163
+ ${this.icon}
164
+ </span>`;
165
+ }
166
+
167
+ protected renderTrailing() {
168
+ return html` <span
169
+ class="mdc-evolution-chip__cell mdc-evolution-chip__cell--trailing"
170
+ role="gridcell"
171
+ >
172
+ <button
173
+ class="mdc-evolution-chip__action mdc-evolution-chip__action--trailing"
174
+ type="button"
175
+ tabindex="-1"
176
+ data-mdc-deletable="true"
177
+ aria-label="Remove ${this.label}"
178
+ >
179
+ <span
180
+ class="mdc-evolution-chip__ripple mdc-evolution-chip__ripple--trailing"
181
+ ></span>
182
+ ${this.renderIcon(true)}
183
+ </button>
184
+ </span>`;
185
+ }
186
+
187
+ protected createAdapter(): MDCChipAdapter {
188
+ return {
189
+ ...addHasRemoveClass(this.mdcRoot),
190
+ emitEvent: <D extends object>(eventName: MDCChipEvents, eventDetail: D) =>
191
+ this.dispatchEvent(
192
+ new CustomEvent(eventName, { bubbles: true, detail: eventDetail })
193
+ ),
194
+ /** Returns the child actions provided by the chip. */
195
+ getActions: () => {
196
+ const actions: MDCChipActionType[] = [];
197
+ for (const [key] of this.actions) {
198
+ actions.push(key);
199
+ }
200
+ return actions;
201
+ },
202
+ /** Returns the value for the given attribute, if it exists. */
203
+ getAttribute: (attrName: MDCChipAttributes) =>
204
+ this.mdcRoot.getAttribute(attrName),
205
+ /** Returns the ID of the root element. */
206
+ getElementID: () => this.mdcRoot.getAttribute('id') ?? '',
207
+ /** Returns the offset width of the root element. */
208
+ getOffsetWidth: () => this.mdcRoot.offsetWidth,
209
+ /** Returns true if the root element has the given class. */
210
+ hasClass: (className: MDCChipCssClasses) =>
211
+ this.mdcRoot.classList.contains(className),
212
+ /** Proxies to the MDCChipAction#isSelectable method. */
213
+ isActionSelectable: (action: MDCChipActionType) =>
214
+ this.actions.get(action)?.isSelectable() ?? true,
215
+ /** Proxies to the MDCChipAction#isSelected method. */
216
+ isActionSelected: (action: MDCChipActionType) =>
217
+ this.actions.get(action)?.isSelected() ?? false,
218
+ /** Proxies to the MDCChipAction#isFocusable method. */
219
+ isActionFocusable: (action: MDCChipActionType) =>
220
+ this.actions.get(action)?.isFocusable() ?? true,
221
+ /** Proxies to the MDCChipAction#isDisabled method. */
222
+ isActionDisabled: (action: MDCChipActionType) =>
223
+ this.actions.get(action)?.isDisabled() ?? false,
224
+ /** Returns true if the text direction is right-to-left. */
225
+ isRTL: () =>
226
+ window.getComputedStyle(this.mdcRoot).getPropertyValue('direction') ===
227
+ 'rtl',
228
+ /** Proxies to the MDCChipAction#setDisabled method. */
229
+ setActionDisabled: (action: MDCChipActionType, isDisabled: boolean) =>
230
+ this.actions.get(action)?.setDisabled(isDisabled),
231
+ /** Proxies to the MDCChipAction#setFocus method. */
232
+ setActionFocus: (
233
+ action: MDCChipActionType,
234
+ behavior: MDCChipActionFocusBehavior
235
+ ) => this.actions.get(action)?.setFocus(behavior),
236
+ /** Proxies to the MDCChipAction#setSelected method. */
237
+ setActionSelected: (action: MDCChipActionType, isSelected: boolean) =>
238
+ this.actions.get(action)?.setSelected(isSelected),
239
+ /** Sets the style property to the given value. */
240
+ setStyleProperty: (property: string, value: string) =>
241
+ this.mdcRoot.style.setProperty(property, value),
242
+ };
243
+ }
244
+
245
+ getActions() {
246
+ return this.mdcFoundation?.getActions() ?? [];
247
+ }
248
+
249
+ getElementID() {
250
+ return this.mdcFoundation?.getElementID() ?? '';
251
+ }
252
+
253
+ isActionFocusable(action: MDCChipActionType) {
254
+ return this.mdcFoundation?.isActionFocusable(action) ?? false;
255
+ }
256
+
257
+ isActionSelectable(action: MDCChipActionType) {
258
+ return this.mdcFoundation?.isActionSelectable(action) ?? false;
259
+ }
260
+
261
+ isActionSelected(action: MDCChipActionType) {
262
+ return this.mdcFoundation?.isActionSelected(action) ?? false;
263
+ }
264
+
265
+ setActionFocus(action: MDCChipActionType, focus: MDCChipActionFocusBehavior) {
266
+ return this.mdcFoundation?.setActionFocus(action, focus);
267
+ }
268
+
269
+ setActionSelected(actionType: MDCChipActionType, isSelected: boolean) {
270
+ return this.mdcFoundation?.setActionSelected(actionType, isSelected);
271
+ }
272
+
273
+ startAnimation(animation: MDCChipAnimation) {
274
+ return this.mdcFoundation?.startAnimation(animation);
275
+ }
276
+ }
@@ -0,0 +1,184 @@
1
+ import { MDCChipSetAdapter } from '@material/chips/chip-set/adapter';
2
+ import {
3
+ MDCChipSetAttributes,
4
+ MDCChipSetEvents,
5
+ } from '@material/chips/chip-set/constants';
6
+ import { MDCChipEvents } from '@material/chips/chip/constants';
7
+ import {
8
+ MDCChipActionType,
9
+ MDCChipActionFocusBehavior,
10
+ } from '@material/chips/action/constants';
11
+ import { MDCChipAnimation } from '@material/chips/chip/constants';
12
+ import {
13
+ ChipAnimationEvent,
14
+ ChipInteractionEvent,
15
+ ChipNavigationEvent,
16
+ } from '@material/chips/chip-set/types';
17
+ import { MDCChipSetFoundation } from '@material/chips/chip-set/foundation';
18
+ import { announce } from '@material/dom/announce';
19
+ import { property, query } from 'lit/decorators.js';
20
+ import { html, LitElement, PropertyValues } from 'lit';
21
+ import { CovalentChip } from './chip';
22
+
23
+ export class ChipSetBase extends LitElement {
24
+ protected mdcFoundation!: MDCChipSetFoundation;
25
+
26
+ @query('.mdc-evolution-chip-set') protected mdcRoot!: HTMLElement;
27
+
28
+ /**
29
+ * Set if the chips are selectable/actionable
30
+ */
31
+ @property({ type: Boolean, reflect: true }) selectable = false;
32
+
33
+ /**
34
+ * Set the chips are mulit-selectable
35
+ */
36
+ @property({ type: Boolean, reflect: true }) multi = false;
37
+
38
+ /**
39
+ * The arial label for the the chip set
40
+ */
41
+ @property()
42
+ label = '';
43
+
44
+ @property({ type: Number }) activeIndex = 0;
45
+
46
+ protected _previousActiveIndex = -1;
47
+
48
+ protected chips: CovalentChip[] = [];
49
+
50
+ override render() {
51
+ return html`<span
52
+ class="mdc-evolution-chip-set"
53
+ role="${this.selectable || this.multi ? 'listbox' : 'grid'}"
54
+ aria-label="${this.label}"
55
+ aria-multiselectable="${this.multi}"
56
+ >
57
+ <span class="mdc-evolution-chip-set__chips" role="presentation">
58
+ <slot></slot>
59
+ </span>
60
+ </span>`;
61
+ }
62
+
63
+ protected override async updated(changedProps: PropertyValues) {
64
+ super.updated(changedProps);
65
+ await this.updateComplete;
66
+ if (this.activeIndex != this._previousActiveIndex) {
67
+ this.mdcFoundation.setChipSelected(
68
+ this.activeIndex,
69
+ MDCChipActionType.PRIMARY,
70
+ true
71
+ );
72
+ }
73
+ }
74
+
75
+ protected override firstUpdated(changedProps: PropertyValues) {
76
+ super.firstUpdated(changedProps);
77
+ const slot = this.shadowRoot?.querySelector('slot');
78
+ const chipEls =
79
+ slot?.assignedElements().filter((node) => node instanceof CovalentChip) ??
80
+ [];
81
+
82
+ for (let i = 0; i < chipEls.length; i++) {
83
+ const chip = chipEls[i] as CovalentChip;
84
+ this.chips.push(chip);
85
+ }
86
+
87
+ if (this.mdcFoundation !== undefined) {
88
+ this.mdcFoundation.destroy();
89
+ }
90
+ this.mdcFoundation = new MDCChipSetFoundation(this.createAdapter());
91
+ this.mdcFoundation.init();
92
+ }
93
+
94
+ override connectedCallback(): void {
95
+ super.connectedCallback();
96
+ this.addEventListener(MDCChipEvents.ANIMATION, this._handleChipAnimation);
97
+ this.addEventListener(
98
+ MDCChipEvents.INTERACTION,
99
+ this._handleChipInteraction
100
+ );
101
+ this.addEventListener(MDCChipEvents.NAVIGATION, this._handleChipNavigation);
102
+ }
103
+
104
+ override disconnectedCallback(): void {
105
+ super.disconnectedCallback();
106
+ this.removeEventListener(
107
+ MDCChipEvents.ANIMATION,
108
+ this._handleChipAnimation
109
+ );
110
+ this.removeEventListener(
111
+ MDCChipEvents.INTERACTION,
112
+ this._handleChipInteraction
113
+ );
114
+ this.removeEventListener(
115
+ MDCChipEvents.NAVIGATION,
116
+ this._handleChipNavigation
117
+ );
118
+ }
119
+
120
+ protected createAdapter(): MDCChipSetAdapter {
121
+ return {
122
+ /** Announces the message via an aria-live region */
123
+ announceMessage: announce,
124
+ /** Emits the given event with the given detail. */
125
+ emitEvent: <D extends object>(
126
+ eventName: MDCChipSetEvents,
127
+ eventDetail: D
128
+ ) =>
129
+ this.dispatchEvent(
130
+ new CustomEvent(eventName, { bubbles: true, detail: eventDetail })
131
+ ),
132
+ /** Returns the value for the given attribute, if it exists. */
133
+ getAttribute: (attrName: MDCChipSetAttributes) =>
134
+ this.mdcRoot.getAttribute(attrName),
135
+ /** Returns the actions provided by the child chip at the given index. */
136
+ getChipActionsAtIndex: (index: number) => this.chips[index].getActions(),
137
+ /** Returns the number of child chips. */
138
+ getChipCount: () => this.chips.length,
139
+ /** Returns the ID of the chip at the given index. */
140
+ getChipIdAtIndex: (index: number) => this.chips[index].getElementID(),
141
+ /** Returns the index of the child chip with the matching ID. */
142
+ getChipIndexById: (chipID: string) =>
143
+ this.chips.findIndex((chip) => chip.getElementID() === chipID),
144
+ /** Proxies to the MDCChip#isActionFocusable method. */
145
+ isChipFocusableAtIndex: (index: number, actionType: MDCChipActionType) =>
146
+ this.chips[index].isActionFocusable(actionType),
147
+ /** Proxies to the MDCChip#isActionSelectable method. */
148
+ isChipSelectableAtIndex: (index: number, actionType: MDCChipActionType) =>
149
+ this.chips[index].isActionSelectable(actionType),
150
+ /** Proxies to the MDCChip#isActionSelected method. */
151
+ isChipSelectedAtIndex: (index: number, actionType: MDCChipActionType) =>
152
+ this.chips[index].isActionSelected(actionType),
153
+ /** Removes the chip at the given index. */
154
+ removeChipAtIndex: (index: number) => this.chips[index].remove(),
155
+ /** Proxies to the MDCChip#setActionFocus method. */
156
+ setChipFocusAtIndex: (
157
+ index: number,
158
+ action: MDCChipActionType,
159
+ focus: MDCChipActionFocusBehavior
160
+ ) => this.chips[index].setActionFocus(action, focus),
161
+ /** Proxies to the MDCChip#setActionSelected method. */
162
+ setChipSelectedAtIndex: (
163
+ index: number,
164
+ actionType: MDCChipActionType,
165
+ isSelected: boolean
166
+ ) => this.chips[index].setActionSelected(actionType, isSelected),
167
+ /** Starts the chip animation at the given index. */
168
+ startChipAnimationAtIndex: (index: number, animation: MDCChipAnimation) =>
169
+ this.chips[index].startAnimation(animation),
170
+ };
171
+ }
172
+
173
+ private _handleChipAnimation(event: Event): void {
174
+ this.mdcFoundation.handleChipAnimation(event as ChipAnimationEvent);
175
+ }
176
+
177
+ private _handleChipInteraction(event: Event): void {
178
+ this.mdcFoundation.handleChipInteraction(event as ChipInteractionEvent);
179
+ }
180
+
181
+ private _handleChipNavigation(event: Event): void {
182
+ this.mdcFoundation.handleChipNavigation(event as ChipNavigationEvent);
183
+ }
184
+ }
@@ -0,0 +1,15 @@
1
+ @use 'sass:math';
2
+ @use '@material/chips/chip-set';
3
+ @use '@material/chips/chip-set-theme';
4
+ @use '@material/rtl/rtl';
5
+
6
+ @include chip-set.core-styles();
7
+
8
+ $space: chip-set-theme.$space-between-chips;
9
+
10
+ ::slotted(cv-chip) {
11
+ @include rtl.reflexive-property(margin, $space, 0);
12
+
13
+ margin-top: math.div($space, 2);
14
+ margin-bottom: math.div($space, 2);
15
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @vitest-environment jsdom
3
+ */
4
+ import { it, describe, expect } from 'vitest';
5
+ import { CovalentChipSet } from './chip-set';
6
+
7
+ describe('Chip set', () => {
8
+ it('should work', () => {
9
+ expect(new CovalentChipSet()).toBeDefined();
10
+ });
11
+ });
@@ -0,0 +1,27 @@
1
+ import { css, unsafeCSS } from 'lit';
2
+ import { customElement } from 'lit/decorators.js';
3
+ import { ChipSetBase } from './chip-set-base';
4
+ import styles from './chip-set.scss?inline';
5
+
6
+ /**
7
+ * Action ribbon
8
+ *
9
+ * @slot - This element has a slot
10
+ */
11
+ @customElement('cv-chip-set')
12
+ export class CovalentChipSet extends ChipSetBase {
13
+ static override styles = [
14
+ css`
15
+ ${unsafeCSS(styles)}
16
+ `,
17
+ ];
18
+ }
19
+
20
+ declare global {
21
+ interface HTMLElementTagNameMap {
22
+ 'cv-chip-set': CovalentChipSet;
23
+ }
24
+ }
25
+
26
+
27
+ export default CovalentChipSet;
@@ -0,0 +1,40 @@
1
+ @use '@material/chips/chip';
2
+
3
+ @include chip.core-styles();
4
+
5
+ .mdc-evolution-chip {
6
+ background-color: var(--cv-theme-surface-container);
7
+
8
+ .mdc-evolution-chip__text-label {
9
+ color: var(--cv-theme-on-surface-container);
10
+ }
11
+
12
+ .mdc-evolution-chip__icon {
13
+ font-family: var(--mdc-icon-font, 'Material Symbols Rounded');
14
+ color: var(--mdc-theme-text-icon-on-background);
15
+ }
16
+
17
+ .mdc-evolution-chip__checkmark-path {
18
+ stroke: var(--mdc-theme-text-icon-on-background);
19
+ }
20
+
21
+ &.mdc-evolution-chip--selected {
22
+ background-color: var(--mdc-theme-surface-primary);
23
+ }
24
+
25
+ &.positive {
26
+ background-color: var(--cv-theme-surface-positive);
27
+ }
28
+
29
+ &.negative {
30
+ background-color: var(--mdc-theme-surface-negative);
31
+ }
32
+
33
+ &.caution {
34
+ background-color: var(--mdc-theme-surface-caution);
35
+ }
36
+
37
+ &.secondary {
38
+ background-color: var(--mdc-theme-surface-secondary);
39
+ }
40
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @vitest-environment jsdom
3
+ */
4
+ import { it, describe, expect } from 'vitest';
5
+ import { CovalentChip } from './chip';
6
+
7
+ describe('Chip', () => {
8
+ it('should work', () => {
9
+ expect(new CovalentChip()).toBeDefined();
10
+ });
11
+ });
@@ -0,0 +1,26 @@
1
+ import { css, unsafeCSS } from 'lit';
2
+ import { customElement } from 'lit/decorators.js';
3
+ import { ChipBase } from './chip-base';
4
+ import styles from './chip.scss?inline';
5
+
6
+ /**
7
+ * Action ribbon
8
+ *
9
+ * @slot - This element has a slot
10
+ */
11
+ @customElement('cv-chip')
12
+ export class CovalentChip extends ChipBase {
13
+ static override styles = [
14
+ css`
15
+ ${unsafeCSS(styles)}
16
+ `,
17
+ ];
18
+ }
19
+
20
+ declare global {
21
+ interface HTMLElementTagNameMap {
22
+ 'cv-chip': CovalentChip;
23
+ }
24
+ }
25
+
26
+ export default CovalentChip;
@@ -0,0 +1,81 @@
1
+ import './chip';
2
+ import './chip-set';
3
+
4
+ export default {
5
+ title: 'Components/Chips',
6
+ args: {
7
+ label: 'Chip',
8
+ icon: 'houseboat',
9
+ showIcon: false,
10
+ trailingIcon: false,
11
+ disabled: false,
12
+ avatar: false,
13
+ },
14
+ };
15
+
16
+ const Template = ({
17
+ avatar,
18
+ label,
19
+ disabled,
20
+ icon,
21
+ showIcon,
22
+ state,
23
+ trailingIcon,
24
+ }) => {
25
+ return `<cv-chip-set label="test chips">
26
+ <cv-chip
27
+ label="${label}"
28
+ ${showIcon ? `icon="${icon}"` : ''}
29
+ ${showIcon && trailingIcon ? `trailingIcon` : ''}
30
+ ${avatar ? 'avatar' : ''}
31
+ ${state ? `state="${state}"` : ''}
32
+ ${disabled ? 'disabled' : ''} ></cv-chip>
33
+ </cv-chip-set>`;
34
+ };
35
+
36
+ const SelectableTemplate = ({ multiSelectable, label, disabled, state }) => {
37
+ return `<cv-chip-set
38
+ label="test chips"
39
+ selectable
40
+ activeIndex="0"
41
+ ${multiSelectable ? 'multi' : ''}>
42
+ <cv-chip
43
+ label="${label}"
44
+ filter
45
+ ${state ? `state="${state}"` : ''}
46
+ ${disabled ? 'disabled' : ''} ></cv-chip>
47
+ <cv-chip
48
+ label="${label} 2"
49
+ filter
50
+ ${state ? `state="${state}"` : ''}
51
+ ${disabled ? 'disabled' : ''} ></cv-chip>
52
+ </cv-chip-set>`;
53
+ };
54
+
55
+ export const Basic = Template.bind({});
56
+
57
+ export const Secondary = Template.bind({});
58
+ Secondary.args = {
59
+ state: 'secondary',
60
+ };
61
+
62
+ export const Caution = Template.bind({});
63
+ Caution.args = {
64
+ state: 'caution',
65
+ };
66
+
67
+ export const Positive = Template.bind({});
68
+ Positive.args = {
69
+ state: 'positive',
70
+ };
71
+
72
+ export const Negative = Template.bind({});
73
+ Negative.args = {
74
+ state: 'negative',
75
+ };
76
+
77
+ export const Selectable = SelectableTemplate.bind({});
78
+ Selectable.args = {
79
+ showIcon: true,
80
+ multiSelectable: false,
81
+ };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @vitest-environment jsdom
3
+ */
4
+ import { it, describe, expect } from 'vitest';
5
+ import { CovalentCircularProgress } from './circular-progress';
6
+
7
+ describe('Circular progress', () => {
8
+ it('should work', () => {
9
+ expect(new CovalentCircularProgress()).toBeDefined();
10
+ });
11
+ });