Skip to content

Commit ff31c5e

Browse files
authored
chore(ui): components styles bootstrap (#100)
* styles bootstrap * inject css * Update tsconfig.json
1 parent 8526781 commit ff31c5e

File tree

12 files changed

+1152
-24
lines changed

12 files changed

+1152
-24
lines changed

packages/ui/index.html

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<div id="editorjs"></div>
1+
<div class="page">
2+
<div id="editorjs"></div>
3+
</div>
24

35
<script type="module">
46
import Core from '@editorjs/core';
@@ -28,5 +30,16 @@
2830
body, html {
2931
background-color: #222;
3032
color: #fff;
33+
font-size: 16px;
34+
}
35+
36+
.page {
37+
max-width: 600px;
38+
margin: 0 auto;
39+
height: 100%;
40+
padding: 100px;
41+
display: flex;
42+
font-size: 2rem;
43+
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
3144
}
3245
</style>

packages/ui/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@
2626
"devDependencies": {
2727
"eslint": "^9.9.1",
2828
"eslint-config-codex": "^2.0.2",
29+
"postcss-apply": "^0.12.0",
30+
"postcss-preset-env": "^10.1.5",
2931
"typescript": "^5.5.4",
3032
"vite": "^5.1.3",
33+
"vite-plugin-css-injected-by-js": "^3.5.2",
3134
"vite-plugin-dts": "^3.7.3"
3235
},
3336
"dependencies": {

packages/ui/postcss.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* PostCSS configuration
3+
*/
4+
export default {
5+
plugins: {
6+
'postcss-preset-env': {},
7+
'postcss-apply': {},
8+
},
9+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.blocks {
2+
outline: none;
3+
}

packages/ui/src/Blocks/Blocks.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
CoreEventType,
88
UiComponentType
99
} from '@editorjs/core';
10+
import Style from './Blocks.module.pcss';
1011

1112
/**
1213
* Editor's main UI renderer for HTML environment
@@ -20,10 +21,12 @@ export class BlocksUI implements EditorjsPlugin {
2021
*/
2122
public static readonly type = UiComponentType.Blocks;
2223

24+
2325
/**
24-
* Editor holder element
26+
* Blocks holder element
2527
*/
26-
#holder: HTMLElement;
28+
#blocksHolder: HTMLElement;
29+
2730
/**
2831
* Elements of the blocks added to the editor
2932
*/
@@ -39,8 +42,8 @@ export class BlocksUI implements EditorjsPlugin {
3942
* @param params - Plugin parameters
4043
*/
4144
constructor(params: EditorjsPluginParams) {
42-
this.#holder = params.config.holder;
4345
this.#eventBus = params.eventBus;
46+
this.#blocksHolder = this.#prepareBlocksHolder(params.config.holder);
4447

4548
this.#eventBus.addEventListener(`core:${CoreEventType.BlockAdded}`, (event: BlockAddedCoreEvent<HTMLElement>) => {
4649
const { ui, index } = event.detail;
@@ -54,7 +57,7 @@ export class BlocksUI implements EditorjsPlugin {
5457
this.#removeBlock(index);
5558
});
5659

57-
this.#holder.addEventListener('keydown', (e) => {
60+
this.#blocksHolder.addEventListener('keydown', (e) => {
5861
if (e.code !== 'KeyZ') {
5962
return;
6063
}
@@ -72,24 +75,21 @@ export class BlocksUI implements EditorjsPlugin {
7275
this.#eventBus.dispatchEvent(new Event('core:undo'));
7376
});
7477

75-
this.#prepareBlocksHolder();
76-
}
77-
78-
/**
79-
* Renders the editor UI
80-
*/
81-
public render(): void {
8278
}
8379

8480
/**
8581
* Prepares blocks holder element
8682
*/
87-
#prepareBlocksHolder(): void {
83+
#prepareBlocksHolder(editorHolder: HTMLElement): HTMLElement {
8884
const blocksHolder = document.createElement('div');
8985

90-
blocksHolder.classList.add('ejs-blocks-holder');
86+
blocksHolder.classList.add(Style['blocks']);
87+
88+
blocksHolder.contentEditable = 'false';
89+
90+
editorHolder.appendChild(blocksHolder);
9191

92-
this.#holder.appendChild(blocksHolder);
92+
return blocksHolder;
9393
}
9494

9595
/**
@@ -104,7 +104,7 @@ export class BlocksUI implements EditorjsPlugin {
104104
this.#blocks[index].insertAdjacentElement('beforebegin', blockElement);
105105
this.#blocks.splice(index, 0, blockElement);
106106
} else {
107-
this.#holder.appendChild(blockElement);
107+
this.#blocksHolder.appendChild(blockElement);
108108
this.#blocks.push(blockElement);
109109
}
110110
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.inline-toolbar {
2+
background: var(--color-bg);
3+
transform: translateY(-100%);
4+
font-size: var(--font-size-ui);
5+
padding: var(--size-padding-toolbar);
6+
7+
button {
8+
cursor: pointer;
9+
10+
&:hover {
11+
opacity: 0.8;
12+
}
13+
}
14+
15+
button, input {
16+
font-size: inherit;
17+
background: var(--color-bg-secondary);
18+
border: none;
19+
outline: none;
20+
color: inherit;
21+
border-radius: var(--radius-control);
22+
}
23+
24+
input {
25+
padding: var(--size-padding-toolbar);
26+
}
27+
28+
}
29+
30+
.inline-toolbar-list {
31+
display: flex;
32+
flex-direction: row;
33+
gap: var(--size-padding-toolbar);
34+
}
35+
36+
.inline-toolbar-actions {
37+
margin-top: var(--size-padding-toolbar);
38+
}

packages/ui/src/InlineToolbar/InlineToolbar.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
} from '@editorjs/core';
1212
import type { InlineTool, InlineToolFormatData } from '@editorjs/sdk';
1313
import type { InlineFragment, InlineToolName, TextRange } from '@editorjs/model';
14+
import Style from './InlineToolbar.module.pcss';
15+
1416

1517
/**
1618
* Inline Toolbar UI module
@@ -95,18 +97,15 @@ export class InlineToolbarUI implements EditorjsPlugin {
9597
* Renders the Inline Toolbar UI HTML nodes
9698
*/
9799
#render(): void {
98-
this.#nodes.holder = make('div');
100+
this.#nodes.holder = make('div', Style['inline-toolbar']);
99101

100102
this.#nodes.holder.style.display = 'none';
101103
this.#nodes.holder.style.position = 'absolute';
102104

103-
this.#nodes.buttons = make('div');
104-
this.#nodes.buttons.style.display = 'flex';
105-
105+
this.#nodes.buttons = make('div', Style['inline-toolbar-list']);
106106
this.#nodes.holder.appendChild(this.#nodes.buttons);
107107

108-
this.#nodes.actions = make('div');
109-
108+
this.#nodes.actions = make('div', Style['inline-toolbar-actions']);
110109
this.#nodes.holder.appendChild(this.#nodes.actions);
111110

112111
this.#eventBus.dispatchEvent(new InlineToolbarRenderedUIEvent({ toolbar: this.#nodes.holder }));

packages/ui/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from '@editorjs/core';
88
import type { ToolboxRenderedUIEvent } from './Toolbox/ToolboxRenderedUIEvent.js';
99
import type { InlineToolbarRenderedUIEvent } from './InlineToolbar/InlineToolbarRenderedUIEvent.js';
10+
import Style from './main.module.pcss';
1011

1112
/**
1213
* EditorJS UI plugin
@@ -40,6 +41,8 @@ export class EditorjsUI implements EditorjsPlugin {
4041
this.#eventBus = params.eventBus;
4142
this.#holder = params.config.holder;
4243

44+
this.#holder.classList.add(Style['editor']);
45+
4346
this.#eventBus.addEventListener(`ui:toolbox:rendered`, (event: ToolboxRenderedUIEvent) => {
4447
this.#addToolbox(event.detail.toolbox);
4548
});

packages/ui/src/main.module.pcss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.editor {
2+
--color-bg: #202020;
3+
--color-bg-secondary:rgb(70, 70, 70);
4+
5+
--font-size-ui: 16px;
6+
--size-padding-toolbar: 4px;
7+
--radius-control: 4px;
8+
9+
width: 100%;
10+
}

packages/ui/src/types/css.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '*.pcss' {
2+
const content: { [className: string]: string };
3+
export default content;
4+
}

0 commit comments

Comments
 (0)