@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.
- package/.babelrc +10 -0
- package/.eslintrc.json +18 -0
- package/.storybook/main.js +34 -0
- package/.storybook/manager-head.html +62 -0
- package/.storybook/manager.js +1 -0
- package/.storybook/preview-head.html +20 -0
- package/.storybook/preview.js +20 -0
- package/README.md +179 -0
- package/component-config.json +313 -0
- package/index.html +288 -0
- package/jest.config.js +18 -0
- package/package.json +315 -0
- package/project.json +104 -0
- package/public/index.scss +1 -0
- package/public/reset.css +128 -0
- package/src/action-ribbon/_action-ribbon.theme.scss +90 -0
- package/src/action-ribbon/action-ribbon-base.ts +164 -0
- package/src/action-ribbon/action-ribbon.scss +20 -0
- package/src/action-ribbon/action-ribbon.spec.ts +11 -0
- package/src/action-ribbon/action-ribbon.stories.js +78 -0
- package/src/action-ribbon/action-ribbon.ts +26 -0
- package/src/alert/_alert.theme.scss +116 -0
- package/src/alert/alert-base.ts +175 -0
- package/src/alert/alert.scss +55 -0
- package/src/alert/alert.spec.ts +26 -0
- package/src/alert/alert.stories.js +76 -0
- package/src/alert/alert.ts +26 -0
- package/src/app-shell/app-shell.scss +387 -0
- package/src/app-shell/app-shell.stories.js +323 -0
- package/src/app-shell/app-shell.ts +388 -0
- package/src/badge/badge.scss +60 -0
- package/src/badge/badge.spec.ts +40 -0
- package/src/badge/badge.stories.js +88 -0
- package/src/badge/badge.ts +122 -0
- package/src/button/Overview.mdx +160 -0
- package/src/button/button.scss +28 -0
- package/src/button/button.spec.ts +11 -0
- package/src/button/button.stories.js +102 -0
- package/src/button/button.ts +17 -0
- package/src/card/card-base.ts +69 -0
- package/src/card/card.scss +45 -0
- package/src/card/card.spec.ts +11 -0
- package/src/card/card.ts +21 -0
- package/src/card/cards.stories.js +40 -0
- package/src/checkbox/checkbox.scss +8 -0
- package/src/checkbox/checkbox.spec.ts +11 -0
- package/src/checkbox/checkbox.stories.js +61 -0
- package/src/checkbox/checkbox.ts +18 -0
- package/src/chips/chip-base.ts +276 -0
- package/src/chips/chip-set-base.ts +184 -0
- package/src/chips/chip-set.scss +15 -0
- package/src/chips/chip-set.spec.ts +11 -0
- package/src/chips/chip-set.ts +27 -0
- package/src/chips/chip.scss +40 -0
- package/src/chips/chip.spec.ts +11 -0
- package/src/chips/chip.ts +26 -0
- package/src/chips/chips.stories.js +81 -0
- package/src/circular-progress/circular-progress.spec.ts +11 -0
- package/src/circular-progress/circular-progress.stories.js +40 -0
- package/src/circular-progress/circular-progress.ts +16 -0
- package/src/code-editor/code-editor.scss +20 -0
- package/src/code-editor/code-editor.spec.ts +11 -0
- package/src/code-editor/code-editor.stories.js +44 -0
- package/src/code-editor/code-editor.theme.ts +199 -0
- package/src/code-editor/code-editor.ts +231 -0
- package/src/code-snippet/code-snippet.scss +126 -0
- package/src/code-snippet/code-snippet.spec.ts +11 -0
- package/src/code-snippet/code-snippet.stories.js +134 -0
- package/src/code-snippet/code-snippet.ts +93 -0
- package/src/data-table/_data-table.theme.scss +39 -0
- package/src/data-table/data-table.stories.js +24 -0
- package/src/data-table/data-table.stories.scss +11 -0
- package/src/dialog/Overview.mdx +39 -0
- package/src/dialog/dialog.scss +17 -0
- package/src/dialog/dialog.spec.ts +11 -0
- package/src/dialog/dialog.stories.js +89 -0
- package/src/dialog/dialog.ts +44 -0
- package/src/drawer/drawer.scss +4 -0
- package/src/drawer/drawer.spec.ts +11 -0
- package/src/drawer/drawer.ts +18 -0
- package/src/empty-state/_empty-state.theme.scss +0 -0
- package/src/empty-state/empty-state.scss +67 -0
- package/src/empty-state/empty-state.spec.ts +11 -0
- package/src/empty-state/empty-state.stories.js +117 -0
- package/src/empty-state/empty-state.ts +61 -0
- package/src/expansion-panel/Overview.mdx +108 -0
- package/src/expansion-panel/expansion-panel-incorrect-example.png +0 -0
- package/src/expansion-panel/expansion-panel-item.scss +243 -0
- package/src/expansion-panel/expansion-panel-item.ts +95 -0
- package/src/expansion-panel/expansion-panel.spec.ts +11 -0
- package/src/expansion-panel/expansion-panel.stories.js +76 -0
- package/src/expansion-panel/expansion-panel.ts +94 -0
- package/src/focused-page/focused-page.scss +113 -0
- package/src/focused-page/focused-page.spec.ts +11 -0
- package/src/focused-page/focused-page.stories.js +167 -0
- package/src/focused-page/focused-page.ts +201 -0
- package/src/formfield/formfield.scss +8 -0
- package/src/formfield/formfield.spec.ts +11 -0
- package/src/formfield/formfield.ts +24 -0
- package/src/full-screen-dialog/full-screen-dialog.scss +37 -0
- package/src/full-screen-dialog/full-screen-dialog.spec.ts +11 -0
- package/src/full-screen-dialog/full-screen-dialog.stories.js +172 -0
- package/src/full-screen-dialog/full-screen-dialog.ts +84 -0
- package/src/icon/_icon-list.ts +316 -0
- package/src/icon/icon-demo.scss +25 -0
- package/src/icon/icon-demo.ts +37 -0
- package/src/icon/icon.spec.ts +11 -0
- package/src/icon/icon.stories.js +55 -0
- package/src/icon/icon.ts +16 -0
- package/src/icon-button/_icon-button.theme.scss +9 -0
- package/src/icon-button/icon-button.scss +12 -0
- package/src/icon-button/icon-button.spec.ts +11 -0
- package/src/icon-button/icon-button.stories.js +24 -0
- package/src/icon-button/icon-button.ts +19 -0
- package/src/icon-button-toggle/icon-button-toggle.scss +19 -0
- package/src/icon-button-toggle/icon-button-toggle.spec.ts +11 -0
- package/src/icon-button-toggle/icon-button-toggle.stories.js +32 -0
- package/src/icon-button-toggle/icon-button-toggle.ts +50 -0
- package/src/icon-checkbox/icon-check-toggle.ts +64 -0
- package/src/icon-checkbox/icon-check.spec.ts +11 -0
- package/src/icon-checkbox/icon-checkbox.scss +95 -0
- package/src/icon-checkbox/icon-checkbox.stories.js +77 -0
- package/src/icon-lockup/icon-lockup.scss +47 -0
- package/src/icon-lockup/icon-lockup.spec.ts +11 -0
- package/src/icon-lockup/icon-lockup.stories.js +93 -0
- package/src/icon-lockup/icon-lockup.ts +125 -0
- package/src/icon-radio/icon-radio-toggle.ts +43 -0
- package/src/icon-radio/icon-radio.scss +63 -0
- package/src/icon-radio/icon-radio.spec.ts +11 -0
- package/src/icon-radio/icon-radio.stories.js +23 -0
- package/src/index.scss +1 -0
- package/src/index.ts +57 -0
- package/src/linear-progress/linear-progress.scss +4 -0
- package/src/linear-progress/linear-progress.spec.ts +11 -0
- package/src/linear-progress/linear-progress.stories.js +43 -0
- package/src/linear-progress/linear-progress.ts +18 -0
- package/src/list/Overview.mdx +91 -0
- package/src/list/_list.theme.scss +100 -0
- package/src/list/check-list-item.spec.ts +11 -0
- package/src/list/check-list-item.ts +25 -0
- package/src/list/list-item.scss +56 -0
- package/src/list/list-item.spec.ts +11 -0
- package/src/list/list-item.ts +31 -0
- package/src/list/list.scss +25 -0
- package/src/list/list.stories.js +120 -0
- package/src/list/list.ts +23 -0
- package/src/list/nav-list-item.scss +159 -0
- package/src/list/nav-list-item.ts +223 -0
- package/src/list/radio-list-item.ts +25 -0
- package/src/menu/menu.scss +3 -0
- package/src/menu/menu.spec.ts +11 -0
- package/src/menu/menu.stories.js +110 -0
- package/src/menu/menu.ts +23 -0
- package/src/notebook-cell/notebook-cell.scss +185 -0
- package/src/notebook-cell/notebook-cell.spec.ts +11 -0
- package/src/notebook-cell/notebook-cell.stories.js +87 -0
- package/src/notebook-cell/notebook-cell.ts +300 -0
- package/src/radio/radio.scss +3 -0
- package/src/radio/radio.spec.ts +11 -0
- package/src/radio/radio.stories.js +56 -0
- package/src/radio/radio.ts +18 -0
- package/src/select/select.scss +16 -0
- package/src/select/select.spec.ts +11 -0
- package/src/select/select.stories.js +57 -0
- package/src/select/select.ts +18 -0
- package/src/side-sheet/side-sheet.scss +49 -0
- package/src/side-sheet/side-sheet.spec.ts +11 -0
- package/src/side-sheet/side-sheet.stories.js +96 -0
- package/src/side-sheet/side-sheet.ts +37 -0
- package/src/skeleton/_skeleton.styles.scss +24 -0
- package/src/skeleton/skeleton.stories.js +77 -0
- package/src/slider/slider-range.ts +16 -0
- package/src/slider/slider.spec.ts +11 -0
- package/src/slider/slider.stories.js +54 -0
- package/src/slider/slider.ts +16 -0
- package/src/snackbar/snackbar.scss +8 -0
- package/src/snackbar/snackbar.spec.ts +11 -0
- package/src/snackbar/snackbar.stories.js +42 -0
- package/src/snackbar/snackbar.ts +18 -0
- package/src/status-dialog/status-dialog.scss +204 -0
- package/src/status-dialog/status-dialog.spec.ts +48 -0
- package/src/status-dialog/status-dialog.stories.js +136 -0
- package/src/status-dialog/status-dialog.ts +188 -0
- package/src/status-header/_status-header.theme.scss +79 -0
- package/src/status-header/status-header-base.ts +42 -0
- package/src/status-header/status-header-item.scss +17 -0
- package/src/status-header/status-header-item.spec.ts +11 -0
- package/src/status-header/status-header-item.ts +32 -0
- package/src/status-header/status-header.scss +57 -0
- package/src/status-header/status-header.spec.ts +11 -0
- package/src/status-header/status-header.stories.js +114 -0
- package/src/status-header/status-header.ts +26 -0
- package/src/switch/switch.scss +17 -0
- package/src/switch/switch.spec.ts +11 -0
- package/src/switch/switch.stories.js +41 -0
- package/src/switch/switch.ts +18 -0
- package/src/tab/Overview.mdx +38 -0
- package/src/tab/tab-bar.spec.ts +11 -0
- package/src/tab/tab-bar.ts +16 -0
- package/src/tab/tab.scss +10 -0
- package/src/tab/tab.spec.ts +11 -0
- package/src/tab/tab.stories.js +30 -0
- package/src/tab/tab.ts +18 -0
- package/src/text-lockup/text-lockup.scss +66 -0
- package/src/text-lockup/text-lockup.spec.ts +11 -0
- package/src/text-lockup/text-lockup.stories.js +67 -0
- package/src/text-lockup/text-lockup.ts +55 -0
- package/src/textarea/textarea.spec.ts +11 -0
- package/src/textarea/textarea.stories.js +39 -0
- package/src/textarea/textarea.ts +19 -0
- package/src/textfield/textfield.scss +34 -0
- package/src/textfield/textfield.spec.ts +11 -0
- package/src/textfield/textfield.stories.js +60 -0
- package/src/textfield/textfield.ts +25 -0
- package/src/theme/_index.scss +46 -0
- package/src/theme/prebuilt/dark-theme.scss +17 -0
- package/src/theme/prebuilt/light-theme.scss +17 -0
- package/src/toolbar/toolbar.scss +37 -0
- package/src/toolbar/toolbar.spec.ts +11 -0
- package/src/toolbar/toolbar.stories.js +66 -0
- package/src/toolbar/toolbar.ts +27 -0
- package/src/tooltip/tooltip.scss +16 -0
- package/src/tooltip/tooltip.spec.ts +11 -0
- package/src/tooltip/tooltip.stories.js +72 -0
- package/src/tooltip/tooltip.ts +185 -0
- package/src/top-app-bar/top-app-bar-fixed.ts +23 -0
- package/src/top-app-bar/top-app-bar.scss +14 -0
- package/src/top-app-bar/top-app-bar.spec.ts +11 -0
- package/src/top-app-bar/top-app-bar.stories.js +41 -0
- package/src/top-app-bar/top-app-bar.ts +23 -0
- package/src/tree-list/tree-list-item.scss +96 -0
- package/src/tree-list/tree-list-item.spec.ts +11 -0
- package/src/tree-list/tree-list-item.ts +87 -0
- package/src/tree-list/tree-list.scss +13 -0
- package/src/tree-list/tree-list.spec.ts +11 -0
- package/src/tree-list/tree-list.stories.js +151 -0
- package/src/tree-list/tree-list.ts +53 -0
- package/src/typography/typography.scss +45 -0
- package/src/typography/typography.spec.ts +11 -0
- package/src/typography/typography.stories.js +23 -0
- package/src/typography/typography.ts +27 -0
- package/stories/Introduction.mdx +47 -0
- package/stories/color-use.mdx +509 -0
- package/stories/demos/dialog.component.html +187 -0
- package/stories/demos/dialog.component.js +57 -0
- package/stories/demos/grid.content.html +99 -0
- package/stories/demos/lorem-ipsum.content.html +338 -0
- package/stories/demos/material-web.content.html +2125 -0
- package/stories/demos/table-column-sorting.content.html +92 -0
- package/stories/demos/table-pagination.content.html +139 -0
- package/stories/demos/table-progress-indicator.content.html +77 -0
- package/stories/demos/table-row-selection.content.html +219 -0
- package/stories/demos/table.content.html +64 -0
- package/stories/demos/top-app-bar.component.js +57 -0
- package/stories/guide-representing-state.mdx +282 -0
- package/stories/info-and-help.mdx +484 -0
- package/stories/item-detail-and-editing.mdx +529 -0
- package/stories/markdown-elements.mdx +194 -0
- package/stories/writing-and-naming.mdx +157 -0
- package/tsconfig.json +34 -0
- package/tsconfig.lib.json +17 -0
- package/tsconfig.spec.json +14 -0
- package/types.d.ts +15 -0
- 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
|
+
});
|