@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,110 @@
1
+ import './menu';
2
+ import '../button/button';
3
+ import '../list/list-item';
4
+ import '../select/select';
5
+
6
+ export default {
7
+ title: 'Components/Menu',
8
+ component: 'cv-menu',
9
+ parameters: {
10
+ layout: 'padded',
11
+ },
12
+ args: {
13
+ corner: 'BOTTOM_START',
14
+ defaultFocus: 'NONE',
15
+ fixed: true,
16
+ activatable: true,
17
+ },
18
+ argTypes: {
19
+ corner: {
20
+ options: ['TOP_START', 'TOP_END', 'BOTTOM_START', 'BOTTOM_END'],
21
+ control: {
22
+ type: 'select',
23
+ },
24
+ },
25
+ defaultFocus: {
26
+ options: ['NONE', 'LIST_ROOT', 'FIRST_ITEM', 'LAST_ITEM'],
27
+ control: {
28
+ type: 'select',
29
+ },
30
+ },
31
+ x: {
32
+ control: {
33
+ type: 'number',
34
+ },
35
+ },
36
+ y: {
37
+ control: {
38
+ type: 'number',
39
+ },
40
+ },
41
+ absolute: {
42
+ control: {
43
+ type: 'boolean',
44
+ },
45
+ },
46
+ },
47
+ };
48
+
49
+ export const Basic = (args) => {
50
+ document.addEventListener('DOMContentLoaded', () => {
51
+ window.basicMenu.anchor = window.basicButton;
52
+
53
+ window.basicButton.addEventListener('click', function () {
54
+ window.basicMenu.open = !window.basicMenu.open;
55
+ });
56
+ });
57
+
58
+ let menuProps = '';
59
+
60
+ for (const [key, value] of Object.entries(args))
61
+ menuProps += `${key}="${value}" `;
62
+
63
+ return `
64
+ <cv-button id="basicButton" raised label="Open menu"></cv-button>
65
+ <cv-menu
66
+ id="basicMenu"
67
+ ${menuProps}
68
+ >
69
+ <cv-list-item>one</cv-list-item>
70
+ <cv-list-item>two</cv-list-item>
71
+ <cv-list-item>three</cv-list-item>
72
+ <cv-list-item disabled><div>four</div></cv-list-item>
73
+ <li divider></li>
74
+ <cv-list-item>aaa</cv-list-item>
75
+ <cv-list-item>bbb</cv-list-item>
76
+ </cv-menu>
77
+ `;
78
+ };
79
+
80
+ export const absolute = Basic.bind({});
81
+ absolute.args = {
82
+ absolute: true,
83
+ x: 100,
84
+ y: 100,
85
+ };
86
+
87
+ export const quickOpen = Basic.bind({});
88
+ quickOpen.args = {
89
+ quick: true,
90
+ };
91
+
92
+ export const fullwidth = Basic.bind({});
93
+ fullwidth.args = {
94
+ fullwidth: true,
95
+ };
96
+
97
+ export const stayOpenOnBodyClick = Basic.bind({});
98
+ stayOpenOnBodyClick.args = {
99
+ stayOpenonBodyClick: true,
100
+ };
101
+
102
+ export const corner = Basic.bind({});
103
+ corner.args = {
104
+ corner: 'TOP_END',
105
+ };
106
+
107
+ export const defaultFocus = Basic.bind({});
108
+ defaultFocus.args = {
109
+ defaultFocus: 'LAST_ITEM',
110
+ };
@@ -0,0 +1,23 @@
1
+ import { MenuBase } from '@material/mwc-menu/mwc-menu-base';
2
+ import { styles as baseStyles } from '@material/mwc-menu/mwc-menu.css';
3
+ import styles from './menu.scss?inline';
4
+ import { customElement } from 'lit/decorators.js';
5
+ import { css, unsafeCSS } from 'lit';
6
+
7
+ declare global {
8
+ interface HTMLElementTagNameMap {
9
+ 'cv-menu': CovalentMenu;
10
+ }
11
+ }
12
+
13
+ @customElement('cv-menu')
14
+ export class CovalentMenu extends MenuBase {
15
+ static override styles = [
16
+ baseStyles,
17
+ css`
18
+ ${unsafeCSS(styles)}
19
+ `,
20
+ ];
21
+ }
22
+
23
+ export default CovalentMenu;
@@ -0,0 +1,185 @@
1
+ :host {
2
+ --mdc-icon-button-size: 2rem;
3
+
4
+ font-family: var(--mdc-typography-body1-font-family);
5
+ width: 100%;
6
+ }
7
+
8
+ cv-code-snippet {
9
+ background-color: var(--cv-theme-surface);
10
+ border-radius: 0;
11
+ box-sizing: border-box;
12
+ }
13
+
14
+ cv-code-snippet::part(code) {
15
+ font-size: var(--mdc-typography-body2-font-size);
16
+ line-height: var(--mdc-typography-body2-line-height);
17
+ padding: 0;
18
+ white-space: pre-wrap;
19
+ }
20
+
21
+ cv-code-editor {
22
+ margin-top: -1px;
23
+ }
24
+
25
+ .selectionIndicator {
26
+ background-color: var(--cv-theme-primary);
27
+ border-radius: 2px;
28
+ height: 100%;
29
+ visibility: hidden;
30
+ }
31
+
32
+ .selectionIndicatorWrapper {
33
+ min-width: 8px;
34
+
35
+ &:hover {
36
+ .selectionIndicator {
37
+ visibility: visible;
38
+ }
39
+ }
40
+ }
41
+
42
+ .status {
43
+ padding: 0 1px;
44
+ position: relative;
45
+ }
46
+
47
+ .loading {
48
+ top: 2.5px;
49
+ }
50
+
51
+ .timesExecuted {
52
+ --cv-icon-button-cursor: grab;
53
+
54
+ align-items: center;
55
+ box-sizing: border-box;
56
+ color: var(--cv-theme-on-surface-38);
57
+ display: flex;
58
+ font-family: var(--cv-typography-subtitle2-font-family);
59
+ font-size: var(--cv-typography-subtitle2-font-size);
60
+ gap: 0.5rem;
61
+ height: 56px;
62
+ line-height: var(--cv-typography-headline6-line-height);
63
+
64
+ .executionCount {
65
+ padding-right: 1rem;
66
+ overflow: hidden;
67
+ text-align: right;
68
+ text-overflow: ellipsis;
69
+ user-select: none;
70
+ white-space: nowrap;
71
+ width: 52px;
72
+ }
73
+
74
+ .dragHandle {
75
+ color: var(--cv-theme-on-surface-variant);
76
+ cursor: grab;
77
+ padding-left: 0.5rem;
78
+ transition: visibility 0.3s ease;
79
+ visibility: hidden;
80
+
81
+ &:active {
82
+ --cv-icon-button-cursor: grabbing;
83
+ }
84
+ }
85
+ }
86
+
87
+ .timesExecutedWrapper {
88
+ cursor: grab;
89
+
90
+ &:active {
91
+ cursor: grabbing;
92
+ }
93
+
94
+ &:hover {
95
+ .dragHandle {
96
+ visibility: visible;
97
+ }
98
+ }
99
+ }
100
+
101
+ .cell {
102
+ box-sizing: border-box;
103
+ cursor: pointer;
104
+ display: flex;
105
+ justify-content: space-between;
106
+ position: relative;
107
+ transition: background-color 0.2s ease;
108
+ user-select: auto;
109
+
110
+ &.focused,
111
+ &.selected {
112
+ .selectionIndicator {
113
+ visibility: visible;
114
+ }
115
+ }
116
+
117
+ &:hover {
118
+ background-color: var(--cv-theme-secondary-4);
119
+
120
+ .selectionIndicator {
121
+ visibility: visible;
122
+ background-color: var(--cv-theme-on-secondary-container-38);
123
+ }
124
+ }
125
+
126
+ &:active {
127
+ background-color: var(--cv-theme-secondary-12);
128
+
129
+ .selectionIndicator {
130
+ visibility: visible;
131
+ background-color: var(--cv-theme-on-secondary-container-74);
132
+ }
133
+ }
134
+ }
135
+
136
+ .cellWrapper {
137
+ display: flex;
138
+ flex-direction: column;
139
+ width: 100%;
140
+ }
141
+
142
+ .cellOutputWrapper {
143
+ display: flex;
144
+ flex-direction: column;
145
+ max-width: calc(100% - 130px);
146
+ flex: 1;
147
+ }
148
+
149
+ .contextMenu {
150
+ background-color: var(--cv-theme-surface-canvas);
151
+ border-radius: 8px;
152
+ box-shadow: 0 8px 12px 6px rgba(0, 0, 0, 15%), 0 4px 4px 0 rgba(0, 0, 0, 30%);
153
+ display: flex;
154
+ flex-direction: column;
155
+ position: fixed;
156
+ visibility: hidden;
157
+ z-index: 1000;
158
+ }
159
+
160
+ .contextMenuContent {
161
+ border-radius: 4px;
162
+ flex-grow: 1;
163
+ max-height: 100%;
164
+ overflow: auto;
165
+ }
166
+
167
+ .contextMenu.open {
168
+ visibility: visible;
169
+ }
170
+
171
+ .editorContainer {
172
+ box-sizing: border-box;
173
+ background-color: var(--cv-theme-surface);
174
+ border: 1px solid var(--cv-theme-outline-variant);
175
+ border-radius: var(--cv-editor-border-radius, 4px);
176
+ min-height: 56px;
177
+ overflow: hidden;
178
+ padding: 1rem;
179
+ }
180
+
181
+ .errors,
182
+ .output {
183
+ max-width: 100%;
184
+ width: 100%;
185
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @vitest-environment jsdom
3
+ */
4
+ import { it, describe, expect } from 'vitest';
5
+ import { CovalentNotebookCell } from './notebook-cell';
6
+
7
+ describe('Notebook cell', () => {
8
+ it('should work', () => {
9
+ expect(new CovalentNotebookCell()).toBeDefined();
10
+ });
11
+ });
@@ -0,0 +1,87 @@
1
+ import './notebook-cell';
2
+ import '../alert/alert';
3
+ import '../icon/icon';
4
+ import '../typography/typography';
5
+ import '../list/list';
6
+ import '../list/list-item';
7
+
8
+ export default {
9
+ title: 'Components/Notebook Cell',
10
+ args: {
11
+ code: 'Select * from DBC.UserInfo;',
12
+ index: 0,
13
+ language: 'sql',
14
+ loading: false,
15
+ selected: true,
16
+ hideCount: false,
17
+ hideEditor: false,
18
+ editorTheme: 'cv-light',
19
+ timesExecuted: 2,
20
+ },
21
+ };
22
+
23
+ const Template = ({
24
+ code,
25
+ index,
26
+ language,
27
+ loading,
28
+ selected,
29
+ hideCount,
30
+ hideEditor,
31
+ editorTheme,
32
+ timesExecuted,
33
+ error,
34
+ output,
35
+ }) => {
36
+ return `<div style="width: 60vw;">
37
+ <cv-notebook-cell code="${code}" index="${index}" language="${language}" timesExecuted="${timesExecuted}" editorTheme="${editorTheme}" ${
38
+ hideEditor ? 'hideEditor' : ''
39
+ } ${selected ? 'selected' : ''} ${loading ? 'loading' : ''} ${
40
+ hideCount ? 'hideCount' : ''
41
+ }>
42
+ ${
43
+ error &&
44
+ `<div slot="error" style="margin-top: 1rem;">
45
+ <cv-alert
46
+ descriptionText="Could not load data!"
47
+ state="negative"
48
+ icon="error"
49
+ iconAriaLabel="error"
50
+ >
51
+ </cv-alert>
52
+ </div>`
53
+ }
54
+ ${
55
+ output &&
56
+ `<div slot="output">
57
+ <cv-typography scale="headline4" style="margin:1rem 0;">Create and Populate Tables</cv-typography>
58
+ <cv-typography scale="body1">Tables are created and populated using SQL</cv-typography>
59
+ </div>`
60
+ }
61
+ <cv-icon-button slot="drag-handle" icon="drag_indicator"></cv-icon-button>
62
+ <div slot="context-menu">
63
+ <cv-list activatable>
64
+ <cv-list-item>Cut</cv-list-item>
65
+ <cv-list-item>Copy</cv-list-item>
66
+ <cv-list-item>Paste</cv-list-item>
67
+ <cv-list-item disabled><div>Delete</div></cv-list-item>
68
+ <li divider></li>
69
+ <cv-list-item>Clear outputs</cv-list-item>
70
+ <cv-list-item>Restart</cv-list-item>
71
+ </cv-list>
72
+ </div>
73
+ </cv-notebook-cell>
74
+ </div>`;
75
+ };
76
+
77
+ export const Basic = Template.bind({});
78
+
79
+ export const Error = Template.bind({});
80
+ Error.args = {
81
+ error: true,
82
+ };
83
+
84
+ export const WithOutput = Template.bind({});
85
+ WithOutput.args = {
86
+ output: true,
87
+ };
@@ -0,0 +1,300 @@
1
+ import { css, html, LitElement, PropertyValues, unsafeCSS } from 'lit';
2
+ import { customElement, property, state } from 'lit/decorators.js';
3
+ import styles from './notebook-cell.scss?inline';
4
+ import { classMap } from 'lit/directives/class-map.js';
5
+ import { KeyCode, editor } from 'monaco-editor/esm/vs/editor/editor.api.js';
6
+
7
+ import '../code-editor/code-editor';
8
+ import '../code-snippet/code-snippet';
9
+ import '../icon-button/icon-button';
10
+ import '../typography/typography';
11
+
12
+ declare global {
13
+ interface HTMLElementTagNameMap {
14
+ 'cv-notebook-cell': CovalentNotebookCell;
15
+ }
16
+ }
17
+
18
+ /**
19
+ * Notebook cell
20
+ *
21
+ * @slot - This element has a slot
22
+ */
23
+ @customElement('cv-notebook-cell')
24
+ export class CovalentNotebookCell extends LitElement {
25
+ /**
26
+ * The index of the cell in a notebook
27
+ */
28
+ @property({ type: Number })
29
+ index?: number;
30
+
31
+ /**
32
+ * Code written in the cell
33
+ */
34
+ @property({ type: String })
35
+ code = '';
36
+
37
+ /**
38
+ * Language of the code
39
+ */
40
+ @property({ type: String })
41
+ language = '';
42
+
43
+ /**
44
+ * Whether the cell is loading
45
+ */
46
+ @property({ type: Boolean, reflect: true })
47
+ loading = false;
48
+
49
+ /**
50
+ * Whether the cell is selected
51
+ */
52
+ @property({ type: Boolean, reflect: true })
53
+ selected = false;
54
+
55
+ /**
56
+ * Number of times the cell was exceuted
57
+ */
58
+ @property({ type: Number })
59
+ timesExecuted = 0;
60
+
61
+ /**
62
+ * Whether the editor is shown
63
+ */
64
+ @property({ type: Boolean, reflect: true })
65
+ hideEditor = false;
66
+
67
+ /**
68
+ * Whether the execution count is shown
69
+ */
70
+ @property({ type: Boolean, reflect: true })
71
+ hideCount = false;
72
+
73
+ /**
74
+ * Theme for the code editor
75
+ */
76
+ @property({ type: String })
77
+ editorTheme = '';
78
+
79
+ private _editor!: editor.IStandaloneCodeEditor;
80
+
81
+ private _editorFocused = false;
82
+
83
+ @state()
84
+ private _isMenuOpen = false;
85
+
86
+ private _menuMaxHeight = 'auto';
87
+
88
+ private _menuPosition = { top: 0, left: 0 };
89
+
90
+ editorOptions = {
91
+ minimap: { enabled: false }, // Disable minimap to save space
92
+ wordWrap: 'on', // Enable word wrap to avoid horizontal scroll
93
+ fontSize: '14px',
94
+ glyphMargin: false,
95
+ folding: false,
96
+ lineHeight: 20,
97
+ lineNumbers: 'off',
98
+ lineDecorationsWidth: 0,
99
+ lineNumbersMinChars: 0,
100
+ renderIndentGuides: false,
101
+ renderLineHighlight: 'none',
102
+ overviewRulerLanes: 0,
103
+ hideCursorInOverviewRuler: true,
104
+ scrollbar: {
105
+ alwaysConsumeMouseWheel: false,
106
+ vertical: 'hidden',
107
+ },
108
+ };
109
+
110
+ static override styles = [
111
+ css`
112
+ ${unsafeCSS(styles)}
113
+ `,
114
+ ];
115
+
116
+ constructor() {
117
+ super();
118
+ this.closeContextMenu = this.closeContextMenu.bind(this);
119
+ this.showContextMenu = this.showContextMenu.bind(this);
120
+ }
121
+
122
+ closeContextMenu(): void {
123
+ this._isMenuOpen = false;
124
+ }
125
+
126
+ connectedCallback(): void {
127
+ super.connectedCallback();
128
+ document.addEventListener('click', this.closeContextMenu);
129
+ }
130
+
131
+ disconnectedCallback(): void {
132
+ super.disconnectedCallback();
133
+ document.removeEventListener('click', this.closeContextMenu);
134
+ }
135
+
136
+ handleCodeChange(e: CustomEvent) {
137
+ this.code = e.detail.code;
138
+ }
139
+
140
+ setEditorFocus(e: CustomEvent, setFocus: boolean) {
141
+ e.stopImmediatePropagation();
142
+ this._editorFocused = setFocus;
143
+ this.requestUpdate();
144
+ }
145
+
146
+ setEditorInstance(e: CustomEvent) {
147
+ e.stopImmediatePropagation();
148
+ this._editor = e.detail.editor;
149
+ this._editor.onKeyDown((e) => {
150
+ if (e.shiftKey && e.keyCode === KeyCode.Enter) {
151
+ e.preventDefault(); // Prevents adding a new line
152
+ // The event will still propagate and can be capture with an event listener
153
+ }
154
+ });
155
+ }
156
+
157
+ showContextMenu(e: MouseEvent) {
158
+ e.preventDefault();
159
+ const cells = document.querySelectorAll('cv-notebook-cell');
160
+ cells?.forEach((cell) => {
161
+ cell.closeContextMenu();
162
+ });
163
+
164
+ const menu = this.shadowRoot?.querySelector(
165
+ '.contextMenu'
166
+ ) as HTMLDivElement;
167
+ const menuHeight = menu?.offsetHeight;
168
+
169
+ // Determine if there is enough space below the click position
170
+ const viewportHeight = window.innerHeight;
171
+ const spaceBelow = viewportHeight - e.clientY;
172
+ const spaceAbove = e.clientY;
173
+
174
+ // Determine if there is enough space below, otherwise open upwards
175
+ if (spaceBelow >= menuHeight) {
176
+ // Enough space below, open normally
177
+ this._menuPosition = { top: e.clientY, left: e.clientX };
178
+ this._menuMaxHeight = `${spaceBelow}px`;
179
+ } else if (spaceAbove >= menuHeight) {
180
+ // Enough space above, open upwards fully
181
+ this._menuPosition = { top: e.clientY - menuHeight, left: e.clientX };
182
+ this._menuMaxHeight = `${menuHeight}px`;
183
+ } else {
184
+ // Not enough space either way, open upwards with adjusted height
185
+ this._menuPosition = { top: e.clientY - spaceAbove, left: e.clientX };
186
+ this._menuMaxHeight = `${spaceAbove}px`;
187
+ }
188
+ this._isMenuOpen = true;
189
+ }
190
+
191
+ protected updated(changedProperties: PropertyValues) {
192
+ const editor = this.shadowRoot?.querySelector('cv-code-editor');
193
+ if (changedProperties.has('code') || changedProperties.has('language')) {
194
+ // Update the editor instance's code and language properties
195
+ if (editor) {
196
+ editor.code = this.code;
197
+ editor.language = this.language;
198
+ } else {
199
+ // Update the code in code-snippet component
200
+ const codeSnippet = this.shadowRoot?.querySelector('cv-code-snippet');
201
+ if (codeSnippet && !this.selected) {
202
+ codeSnippet.highlight();
203
+ }
204
+ }
205
+ }
206
+ super.updated(changedProperties);
207
+ }
208
+
209
+ getEditorBgColor(): string {
210
+ const editorContainer = this.shadowRoot?.querySelector('.editorContainer');
211
+ if (!editorContainer) {
212
+ return '';
213
+ }
214
+ const styles = window.getComputedStyle(editorContainer);
215
+ return styles.getPropertyValue('background-color');
216
+ }
217
+
218
+ renderEditor() {
219
+ // Show editor when the cell is selected and show code snippet otherwise
220
+ const editor = this.selected
221
+ ? html`<cv-code-editor
222
+ @code-change="${this.handleCodeChange}"
223
+ @editor-ready="${this.setEditorInstance}"
224
+ @editor-focus="${(e: CustomEvent) => this.setEditorFocus(e, true)}"
225
+ @editor-blur="${(e: CustomEvent) => this.setEditorFocus(e, false)}"
226
+ .code="${this.code}"
227
+ .language="${this.language}"
228
+ .options="${this.editorOptions}"
229
+ .theme="${this.editorTheme}"
230
+ disableScroll
231
+ ></cv-code-editor>`
232
+ : html`<cv-code-snippet hideHeader .language="${this.language}"
233
+ >${this.code}</cv-code-snippet
234
+ >`;
235
+ return html`${this.hideEditor
236
+ ? ''
237
+ : html`<div class="editorContainer">${editor}</div>`}`;
238
+ }
239
+
240
+ renderOutput() {
241
+ const output = html` <div class="errors"><slot name="error"></slot></div>
242
+ <div class="output">
243
+ <slot name="output"></slot>
244
+ <slot name="input"></slot>
245
+ </div>`;
246
+ return html`${output}`;
247
+ }
248
+
249
+ renderExecutionCount() {
250
+ if (this.hideCount) {
251
+ return html`&nbsp;`;
252
+ }
253
+ const loadingClass = {
254
+ status: true,
255
+ loading: this.loading,
256
+ };
257
+ return html`[<span class="${classMap(loadingClass)}"
258
+ >${this.loading ? '*' : this.timesExecuted || ' '}</span
259
+ >] :`;
260
+ }
261
+
262
+ protected render() {
263
+ const classes = {
264
+ cell: true,
265
+ selected: this.selected,
266
+ focused: this._editorFocused,
267
+ };
268
+ return html`
269
+ <div class="${classMap(classes)}" @contextmenu=${this.showContextMenu}>
270
+ <div class="selectionIndicatorWrapper">
271
+ <div class="selectionIndicator"></div>
272
+ </div>
273
+
274
+ <div class="timesExecutedWrapper">
275
+ <div class="timesExecuted">
276
+ <div class="dragHandle">
277
+ <slot name="drag-handle"></slot>
278
+ </div>
279
+ <div class="executionCount">${this.renderExecutionCount()}</div>
280
+ </div>
281
+ </div>
282
+
283
+ <div class="cellOutputWrapper">
284
+ ${this.renderEditor()} ${this.renderOutput()}
285
+ </div>
286
+ </div>
287
+ <div
288
+ class="contextMenu ${this._isMenuOpen ? 'open' : ''}"
289
+ style="left: ${this._menuPosition.left}px; top: ${this._menuPosition
290
+ .top}px; max-height: ${this._menuMaxHeight}"
291
+ >
292
+ <div class="contextMenuContent">
293
+ <slot name="context-menu"></slot>
294
+ </div>
295
+ </div>
296
+ `;
297
+ }
298
+ }
299
+
300
+ export default CovalentNotebookCell;