@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,40 @@
1
+ import './circular-progress';
2
+
3
+ export default {
4
+ title: 'Components/Circular Progress',
5
+ argTypes: {
6
+ progress: {
7
+ control: { type: 'range', max: 1, min: 0, step: 0.1 },
8
+ },
9
+ density: {
10
+ control: { type: 'range', min: -8, max: 50 },
11
+ },
12
+ },
13
+ args: {
14
+ density: 0,
15
+ },
16
+ };
17
+
18
+ const Template = ({ density = 0, indeterminate, progress }) => {
19
+ const progressBar = document.createElement('cv-circular-progress');
20
+ progressBar.density = density;
21
+ progressBar.indeterminate = indeterminate;
22
+ progressBar.progress = progress;
23
+ progressBar.ariaLabel = 'Example progress bar';
24
+
25
+ return progressBar;
26
+ };
27
+
28
+ export const Indeterminate = Template.bind({});
29
+ Indeterminate.parameters = {
30
+ // disables Chromatic's snapshotting on a story level
31
+ chromatic: { disableSnapshot: true },
32
+ };
33
+ Indeterminate.args = {
34
+ indeterminate: true,
35
+ };
36
+
37
+ export const Determinate = Template.bind({});
38
+ Determinate.args = {
39
+ progress: 0.5,
40
+ };
@@ -0,0 +1,16 @@
1
+ import { CircularProgressBase } from '@material/mwc-circular-progress/mwc-circular-progress-base';
2
+ import { styles } from '@material/mwc-circular-progress/mwc-circular-progress.css';
3
+ import { customElement } from 'lit/decorators.js';
4
+
5
+ declare global {
6
+ interface HTMLElementTagNameMap {
7
+ 'cv-circular-progress': CovalentCircularProgress;
8
+ }
9
+ }
10
+
11
+ @customElement('cv-circular-progress')
12
+ export class CovalentCircularProgress extends CircularProgressBase {
13
+ static override styles = [styles];
14
+ }
15
+
16
+ export default CovalentCircularProgress;
@@ -0,0 +1,20 @@
1
+ :host {
2
+ --cv-editor-width: 100%;
3
+ --cv-editor-height: 100%;
4
+
5
+ box-sizing: border-box;
6
+
7
+ .monaco-editor {
8
+ .lines-content.monaco-editor-background {
9
+ height: var(--cv-editor-height);
10
+ width: var(--cv-editor-width);
11
+ }
12
+ }
13
+ }
14
+
15
+ .editor {
16
+ height: var(--cv-editor-height);
17
+ min-height: var(--cv-editor-height);
18
+ max-width: calc(var(--cv-editor-width) - 2px);
19
+ width: var(--cv-editor-width);
20
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @vitest-environment jsdom
3
+ */
4
+ import { it, describe, expect } from 'vitest';
5
+ import { CovalentCodeEditor } from './code-editor';
6
+
7
+ describe('Code editor', () => {
8
+ it('should work', () => {
9
+ expect(new CovalentCodeEditor()).toBeDefined();
10
+ });
11
+ });
@@ -0,0 +1,44 @@
1
+ import './code-editor';
2
+
3
+ const sqlContent = `
4
+ SELECT * FROM load_to_teradata (
5
+ ON (
6
+ SELECT 'class' AS class_col,
7
+ 'variable' AS variable_col,
8
+ 'type' AS type_col,
9
+ category,
10
+ cnt,
11
+ 'sum' AS sum_col,
12
+ 'sumSq',
13
+ 'totalCnt'
14
+ FROM aster_nb_modelSC
15
+ )
16
+ tdpid ('sdt12432.labs.teradata.com')
17
+ username ('sample_user')
18
+ password ('sample_user')
19
+ target_table ('td_nb_modelSC')
20
+ );
21
+ `;
22
+
23
+ export default {
24
+ title: 'Components/Code Editor',
25
+ args: {
26
+ theme: 'cv-light',
27
+ code: sqlContent,
28
+ language: 'sql',
29
+ disableScroll: false,
30
+ },
31
+ };
32
+
33
+ const Template = ({ theme, language, code, disableScroll }) => {
34
+ return `
35
+ <div style="width: 800px; height: 100%">
36
+ <cv-code-editor language="${language}" theme="${theme}" code="${code}" ${
37
+ disableScroll ? 'disableScroll' : ''
38
+ }>
39
+ </cv-code-editor>
40
+ </div>
41
+ `;
42
+ };
43
+
44
+ export const Basic = Template.bind();
@@ -0,0 +1,199 @@
1
+ import * as tokens from '@covalent/tokens';
2
+
3
+ const getTheme = (theme: 'Light' | 'Dark') => {
4
+ return {
5
+ base: theme === 'Light' ? 'vs' : 'vs-dark',
6
+ inherit: true,
7
+ rules: [
8
+ {
9
+ token: '',
10
+ foreground: tokens[`Cv${theme}CodeSnippetColor`],
11
+ background: tokens[`Cv${theme}Surface`],
12
+ },
13
+ {
14
+ token: 'arbitration-variable',
15
+ foreground: tokens[`Cv${theme}CodeSnippetVariable`],
16
+ },
17
+ {
18
+ token: 'arbitration-variable.invalid',
19
+ foreground: tokens[`Cv${theme}Negative`],
20
+ },
21
+ {
22
+ token: 'attribute.name',
23
+ foreground: tokens[`Cv${theme}CodeSnippetVariable`],
24
+ },
25
+ {
26
+ token: 'attribute.value',
27
+ foreground: tokens[`Cv${theme}CodeSnippetVariable`],
28
+ },
29
+ {
30
+ token: 'attribute.value.number',
31
+ foreground: tokens[`Cv${theme}CodeSnippetVariable`],
32
+ },
33
+ {
34
+ token: 'attribute.value.unit',
35
+ foreground: tokens[`Cv${theme}CodeSnippetVariable`],
36
+ },
37
+ {
38
+ token: 'attribute.value.html',
39
+ foreground: tokens[`Cv${theme}CodeSnippetString`],
40
+ },
41
+ {
42
+ token: 'attribute.value.xml',
43
+ foreground: tokens[`Cv${theme}CodeSnippetLiteral`],
44
+ },
45
+ {
46
+ token: 'builtins',
47
+ foreground: tokens[`Cv${theme}CodeSnippetClass`],
48
+ },
49
+ {
50
+ token: 'class',
51
+ foreground: tokens[`Cv${theme}CodeSnippetClass`],
52
+ },
53
+ {
54
+ token: 'comment',
55
+ foreground: tokens[`Cv${theme}CodeSnippetComment`],
56
+ fontStyle: 'italic',
57
+ },
58
+ {
59
+ token: 'constant',
60
+ foreground: tokens[`Cv${theme}CodeSnippetLiteral`],
61
+ },
62
+ {
63
+ token: 'delimiter',
64
+ foreground: tokens[`CvTheme${theme}ColorsOnSurface`],
65
+ },
66
+ {
67
+ token: 'delimiter.html',
68
+ foreground: tokens[`Cv${theme}CodeSnippetSelector`],
69
+ },
70
+ {
71
+ token: 'delimiter.xml',
72
+ foreground: tokens[`Cv${theme}CodeSnippetSelector`],
73
+ },
74
+ {
75
+ token: 'doctag',
76
+ foreground: tokens[`Cv${theme}CodeSnippetKeyword`],
77
+ },
78
+ {
79
+ token: 'emphasis',
80
+ fontStyle: 'italic',
81
+ },
82
+ {
83
+ token: 'formula',
84
+ foreground: tokens[`Cv${theme}CodeSnippetKeyword`],
85
+ },
86
+ {
87
+ token: 'function',
88
+ foreground: tokens[`Cv${theme}CodeSnippetTitle`],
89
+ },
90
+ {
91
+ token: 'invalid',
92
+ foreground: tokens[`Cv${theme}Negative`],
93
+ },
94
+ { token: 'key', foreground: tokens[`Cv${theme}CodeSnippetString`] },
95
+ {
96
+ token: 'keyword',
97
+ foreground: tokens[`Cv${theme}CodeSnippetKeyword`],
98
+ },
99
+ {
100
+ token: 'keyword.json',
101
+ foreground: tokens[`Cv${theme}CodeSnippetTitle`],
102
+ fontStyle: 'bold italic',
103
+ },
104
+ {
105
+ token: 'link',
106
+ foreground: tokens[`Cv${theme}CodeSnippetTitle`],
107
+ fontStyle: 'underline',
108
+ },
109
+ {
110
+ token: 'literal',
111
+ foreground: tokens[`Cv${theme}CodeSnippetLiteral`],
112
+ },
113
+ {
114
+ token: 'meta',
115
+ foreground: tokens[`Cv${theme}CodeSnippetTitle`],
116
+ },
117
+ {
118
+ token: 'number',
119
+ foreground: tokens[`Cv${theme}CodeSnippetVariable`],
120
+ },
121
+ {
122
+ token: 'operator',
123
+ foreground: tokens[`Cv${theme}CodeSnippetLiteral`],
124
+ },
125
+ { token: 'predefined', foreground: tokens[`Cv${theme}CodeSnippetTitle`] },
126
+ {
127
+ token: 'predefined.sql',
128
+ foreground: tokens[`Cv${theme}CodeSnippetTitle`],
129
+ },
130
+ {
131
+ token: 'predefined.python',
132
+ foreground: tokens[`Cv${theme}CodeSnippetClass`],
133
+ },
134
+ {
135
+ token: 'punctuation',
136
+ foreground: tokens[`Cv${theme}CodeSnippetColor`],
137
+ },
138
+ {
139
+ token: 'string',
140
+ foreground: tokens[`Cv${theme}CodeSnippetString`],
141
+ },
142
+ {
143
+ token: 'string.sql',
144
+ foreground: tokens[`Cv${theme}CodeSnippetString`],
145
+ },
146
+ {
147
+ token: 'string.key.json',
148
+ foreground: tokens[`Cv${theme}CodeSnippetString`],
149
+ },
150
+ {
151
+ token: 'string.value.json',
152
+ foreground: tokens[`Cv${theme}CodeSnippetString`],
153
+ },
154
+ {
155
+ token: 'strong',
156
+ fontStyle: 'bold',
157
+ },
158
+ {
159
+ token: 'tag',
160
+ foreground: tokens[`Cv${theme}CodeSnippetSelector`],
161
+ },
162
+ {
163
+ token: 'tag.id.jade',
164
+ foreground: tokens[`Cv${theme}CodeSnippetClass`],
165
+ },
166
+ {
167
+ token: 'tag.class.jade',
168
+ foreground: tokens[`Cv${theme}CodeSnippetClass`],
169
+ },
170
+ {
171
+ token: 'type',
172
+ foreground: tokens[`Cv${theme}CodeSnippetClass`],
173
+ },
174
+ {
175
+ token: 'variable',
176
+ foreground: tokens[`Cv${theme}CodeSnippetVariable`],
177
+ },
178
+ ],
179
+ colors: {
180
+ comment: tokens[`Cv${theme}CodeSnippetComment`],
181
+ 'editor.background': tokens[`Cv${theme}Surface`],
182
+ 'editor.foreground': tokens[`CvTheme${theme}ColorsOnSurface`],
183
+ 'editorCursor.foreground': tokens[`Cv${theme}TextSecondaryOnBackground`],
184
+ 'editorLineNumber.activeForeground':
185
+ tokens[`CvTheme${theme}ColorsOnSurface74`],
186
+ 'editorLineNumber.foreground': tokens[`CvTheme${theme}ColorsOnSurface38`],
187
+ 'editor.lineHighlightBackground':
188
+ tokens[`CvTheme${theme}ColorsSurfaceContainerLow`],
189
+ 'inputValidation.errorBackground': tokens[`Cv${theme}Negative`],
190
+ 'inputValidation.errorBorder':
191
+ tokens[`CvTheme${theme}PalettesNegative95`],
192
+ },
193
+ };
194
+ };
195
+
196
+ // Any changes to these themes should also be reflected in the angular-code-editor theme.
197
+ export const cvEditorDarkTheme = getTheme('Dark');
198
+
199
+ export const cvEditorLightTheme = getTheme('Light');
@@ -0,0 +1,231 @@
1
+ import { css, html, LitElement, PropertyValues, unsafeCSS } from 'lit';
2
+ import { customElement, property } from 'lit/decorators.js';
3
+ import { createRef, Ref, ref } from 'lit/directives/ref.js';
4
+
5
+ import { cvEditorDarkTheme, cvEditorLightTheme } from './code-editor.theme';
6
+ import styles from './code-editor.scss?inline';
7
+
8
+ // -- Monaco Editor Imports --
9
+ import { editor } from 'monaco-editor/esm/vs/editor/editor.api.js';
10
+ import baseStyles from 'monaco-editor/min/vs/editor/editor.main.css?inline';
11
+
12
+ // Register all language contributions
13
+ import 'monaco-editor/esm/vs/basic-languages/html/html.contribution';
14
+ import 'monaco-editor/esm/vs/basic-languages/css/css.contribution';
15
+ import 'monaco-editor/esm/vs/basic-languages/javascript/javascript.contribution';
16
+ import 'monaco-editor/esm/vs/basic-languages/typescript/typescript.contribution';
17
+ import 'monaco-editor/esm/vs/basic-languages/python/python.contribution';
18
+ import 'monaco-editor/esm/vs/basic-languages/sql/sql.contribution';
19
+ import 'monaco-editor/esm/vs/basic-languages/markdown/markdown.contribution';
20
+ import 'monaco-editor/esm/vs/basic-languages/r/r.contribution';
21
+
22
+ @customElement('cv-code-editor')
23
+ export class CovalentCodeEditor extends LitElement {
24
+ /**
25
+ * The container where editor will be created
26
+ */
27
+ private container: Ref<HTMLElement> = createRef();
28
+ /**
29
+ * Editor instance
30
+ */
31
+ editor?: editor.IStandaloneCodeEditor;
32
+ /**
33
+ * Theme of the editor
34
+ */
35
+ @property({ type: String }) theme?: string;
36
+ /**
37
+ * Language of th editor instance
38
+ */
39
+ @property() language?: string;
40
+ /**
41
+ * Code entered into the editor
42
+ */
43
+ @property() code?: string;
44
+ /**
45
+ * Disable scroll bar and set the editor height based on content
46
+ */
47
+ @property({ type: Boolean, reflect: true }) disableScroll?: boolean = false;
48
+ /**
49
+ * Options that can be set for the editor
50
+ */
51
+ @property({ type: Object }) options?: editor.IEditorOptions &
52
+ editor.IGlobalEditorOptions;
53
+
54
+ static styles = [
55
+ css`
56
+ ${unsafeCSS(baseStyles)} ${unsafeCSS(styles)}
57
+ `,
58
+ ];
59
+
60
+ private getFile() {
61
+ if (this.children.length > 0) return this.children[0];
62
+ return null;
63
+ }
64
+
65
+ private getCode() {
66
+ if (this.code) return this.code;
67
+ const file = this.getFile();
68
+ if (!file) return;
69
+ return file.innerHTML.trim() || '';
70
+ }
71
+
72
+ private getLang() {
73
+ if (this.language) return this.language;
74
+ const file = this.getFile();
75
+ if (!file) return;
76
+ const type = file.getAttribute('type');
77
+ return type?.split('/').pop();
78
+ }
79
+
80
+ private getTheme() {
81
+ if (this.theme) return this.theme;
82
+ return 'cv-light';
83
+ }
84
+
85
+ private setTheme = () => {
86
+ editor.setTheme(this.getTheme());
87
+ };
88
+
89
+ adjustHeight() {
90
+ if (this.editor && this.container.value) {
91
+ const contentHeight = this.editor.getContentHeight();
92
+ this.container.value.style.height = `${contentHeight}px`;
93
+ this.editor.layout();
94
+ }
95
+ }
96
+
97
+ createEditor(container: HTMLElement) {
98
+ // uses covalent light colors
99
+ editor.defineTheme(
100
+ 'cv-light',
101
+ cvEditorLightTheme as editor.IStandaloneThemeData
102
+ );
103
+
104
+ // uses covalent dark colors
105
+ editor.defineTheme(
106
+ 'cv-dark',
107
+ cvEditorDarkTheme as editor.IStandaloneThemeData
108
+ );
109
+
110
+ this.editor = editor.create(container, {
111
+ ...this.options,
112
+ fontLigatures: '',
113
+ value: this.getCode(),
114
+ language: this.getLang(),
115
+ theme: this.getTheme(),
116
+ automaticLayout: true,
117
+ scrollBeyondLastLine: false,
118
+ });
119
+
120
+ // Notify when the editor instance is created/ready
121
+ this.dispatchEvent(
122
+ new CustomEvent('editor-ready', {
123
+ detail: { editor: this.editor },
124
+ bubbles: false,
125
+ composed: true,
126
+ })
127
+ );
128
+ }
129
+
130
+ override disconnectedCallback(): void {
131
+ this.editor?.dispose();
132
+ window.removeEventListener('change', this.setTheme);
133
+ super.disconnectedCallback();
134
+ }
135
+
136
+ firstUpdated() {
137
+ if (this.container.value) {
138
+ this.createEditor(this.container.value);
139
+
140
+ this.onModelChange();
141
+
142
+ // Dispatch event when editor is focused
143
+ this.editor?.onDidFocusEditorText(() => {
144
+ this.dispatchEvent(
145
+ new CustomEvent('editor-focus', {
146
+ bubbles: false,
147
+ composed: true,
148
+ })
149
+ );
150
+ });
151
+
152
+ // Dispatch event when editor is blurred
153
+ this.editor?.onDidBlurEditorText(() => {
154
+ this.dispatchEvent(
155
+ new CustomEvent('editor-blur', {
156
+ bubbles: false,
157
+ composed: true,
158
+ })
159
+ );
160
+ });
161
+
162
+ if (this.disableScroll) {
163
+ // Adjust the height of the editor when content changes, to avoid vertical scroll bar
164
+ this.editor?.onDidContentSizeChange(() => {
165
+ this.adjustHeight();
166
+ });
167
+ }
168
+
169
+ this.adjustHeight();
170
+
171
+ window
172
+ .matchMedia('(prefers-color-scheme: dark)')
173
+ .addEventListener('change', this.setTheme);
174
+ }
175
+ }
176
+
177
+ getEditorInstance() {
178
+ return this.editor;
179
+ }
180
+
181
+ getValue() {
182
+ const value = this.editor?.getValue();
183
+ return value;
184
+ }
185
+
186
+ onModelChange() {
187
+ this.editor?.onDidChangeModelContent(() => {
188
+ this.code = this.getValue();
189
+ // Dispatch event when code in the editor is changed
190
+ this.dispatchEvent(
191
+ new CustomEvent('code-change', {
192
+ detail: { code: this.code },
193
+ bubbles: true,
194
+ composed: true,
195
+ })
196
+ );
197
+ });
198
+ }
199
+
200
+ render() {
201
+ return html` <main ${ref(this.container)} class="editor"></main> `;
202
+ }
203
+
204
+ setValue(value: string) {
205
+ this.editor?.setValue(value);
206
+ }
207
+
208
+ updated(changedProperties: PropertyValues) {
209
+ if (changedProperties.has('code') && this.editor) {
210
+ const currentCode = this.editor.getValue();
211
+ if (this.code !== currentCode) {
212
+ this.editor.setValue(this.code || '');
213
+ }
214
+ }
215
+ if (changedProperties.has('language') && this.editor) {
216
+ // Update monaco editor language when language prop is changed
217
+ editor.setModelLanguage(
218
+ this.editor.getModel() as editor.ITextModel,
219
+ this.language || ''
220
+ );
221
+ }
222
+ }
223
+ }
224
+
225
+ declare global {
226
+ interface HTMLElementTagNameMap {
227
+ 'cv-code-editor': CovalentCodeEditor;
228
+ }
229
+ }
230
+
231
+ export default CovalentCodeEditor;
@@ -0,0 +1,126 @@
1
+ :host {
2
+ background-color: var(--mdc-theme-surface-canvas);
3
+ border-radius: var(--mdc-shape-medium);
4
+ display: block;
5
+ position: relative;
6
+
7
+ /* For max height */
8
+ overflow: hidden;
9
+
10
+ .code-slot {
11
+ display: none;
12
+ }
13
+
14
+ pre {
15
+ margin: 0;
16
+ overflow: auto;
17
+
18
+ code.hljs.cv-code-snippet {
19
+ padding: 16px;
20
+ display: block;
21
+ overflow-x: auto;
22
+ font-family: var(--cv-theme-code-font-family);
23
+ font-size: var(--cv-theme-code-font-size);
24
+ font-weight: var(--cv-theme-code-font-weight);
25
+ line-height: var(--cv-theme-code-line-height);
26
+ }
27
+ }
28
+
29
+ .hljs {
30
+ color: var(--cv-theme-code-snippet-color, #abb2bf);
31
+ }
32
+
33
+ .hljs-comment,
34
+ .hljs-quote {
35
+ color: var(--cv-theme-code-snippet-comment, #5c6370);
36
+ font-style: italic;
37
+ }
38
+
39
+ .hljs-doctag,
40
+ .hljs-formula,
41
+ .hljs-keyword {
42
+ color: var(--cv-theme-code-snippet-keyword, #c678dd);
43
+ }
44
+
45
+ .hljs-deletion,
46
+ .hljs-name,
47
+ .hljs-section,
48
+ .hljs-selector-tag,
49
+ .hljs-subst {
50
+ color: var(--cv-theme-code-snippet-selector, #e06c75);
51
+ }
52
+
53
+ .hljs-literal {
54
+ color: var(--cv-theme-code-snippet-literal, #56b6c2);
55
+ }
56
+
57
+ .hljs-addition,
58
+ .hljs-attribute,
59
+ .hljs-meta .hljs-string,
60
+ .hljs-regexp,
61
+ .hljs-string {
62
+ color: var(--cv-theme-code-snippet-string, #98c379);
63
+ }
64
+
65
+ .hljs-attr,
66
+ .hljs-number,
67
+ .hljs-selector-attr,
68
+ .hljs-selector-class,
69
+ .hljs-selector-pseudo,
70
+ .hljs-template-variable,
71
+ .hljs-type,
72
+ .hljs-variable {
73
+ color: var(--cv-theme-code-snippet-variable, #d19a66);
74
+ }
75
+
76
+ .hljs-bullet,
77
+ .hljs-link,
78
+ .hljs-meta,
79
+ .hljs-selector-id,
80
+ .hljs-symbol,
81
+ .hljs-title {
82
+ color: var(--cv-theme-code-snippet-title, #61aeee);
83
+ }
84
+
85
+ .hljs-built_in,
86
+ .hljs-class .hljs-title,
87
+ .hljs-title.class_ {
88
+ color: var(--cv-theme-code-snippet-class, #e6c07b);
89
+ }
90
+
91
+ .hljs-emphasis {
92
+ font-style: italic;
93
+ }
94
+
95
+ .hljs-strong {
96
+ font-weight: 700;
97
+ }
98
+
99
+ .hljs-link {
100
+ text-decoration: underline;
101
+ }
102
+ }
103
+
104
+ :host([inline]) {
105
+ border-radius: 0;
106
+ }
107
+
108
+ .header {
109
+ border-bottom: 1px solid var(--mdc-theme-border);
110
+ position: sticky;
111
+ top: -8px;
112
+ background-color: var(--mdc-theme-surface-canvas);
113
+ display: flex;
114
+ justify-content: space-between;
115
+ padding: 4px 8px 4px 16px;
116
+ align-items: center;
117
+ border-radius: var(--mdc-shape-medium) var(--mdc-shape-medium) 0 0;
118
+ }
119
+
120
+ .title {
121
+ font-family: var(--mdc-typography-subtitle2-font-family);
122
+ font-size: var(--mdc-typography-subtitle2-font-size);
123
+ font-weight: var(--mdc-typography-subtitle2-font-weight);
124
+ line-height: var(--mdc-typography-subtitle2-line-height);
125
+ padding-right: 16px;
126
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @vitest-environment jsdom
3
+ */
4
+ import { it, describe, expect } from 'vitest';
5
+ import { CovalentCodeSnippet } from './code-snippet';
6
+
7
+ describe('Code snippet', () => {
8
+ it('should work', () => {
9
+ expect(new CovalentCodeSnippet()).toBeDefined();
10
+ });
11
+ });