Skip to content

Commit d19b5c3

Browse files
authored
Merge pull request #16 from ether/feat/theme-system
feat: theme system and tabs
2 parents 8ba70a0 + 862743f commit d19b5c3

21 files changed

Lines changed: 1052 additions & 134 deletions

‎README.md‎

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Because they are standard custom elements, the components work in any page or fr
1313
## Install
1414

1515
```bash
16-
pnpm add etherpad-webcomponents
17-
# or: npm install etherpad-webcomponents
16+
pnpm add @samtv12345/etherpad-webcomponents
17+
# or: npm install @samtv12345/etherpad-webcomponents
1818
```
1919

2020
## Usage
@@ -23,10 +23,10 @@ Import the whole library, or just the components you need (each is individually
2323

2424
```js
2525
// everything
26-
import 'etherpad-webcomponents';
26+
import '@samtv12345/etherpad-webcomponents';
2727

2828
// or a single component
29-
import 'etherpad-webcomponents/EpButton.js';
29+
import '@samtv12345/etherpad-webcomponents/EpButton.js';
3030
```
3131

3232
```html
@@ -42,7 +42,7 @@ import 'etherpad-webcomponents/EpButton.js';
4242
The named exports (classes) are also available for programmatic use:
4343

4444
```js
45-
import { EpButton, EpTheme, themes } from 'etherpad-webcomponents';
45+
import { EpButton, EpTheme, themes } from '@samtv12345/etherpad-webcomponents';
4646
```
4747

4848
---
@@ -64,18 +64,49 @@ import { EpButton, EpTheme, themes } from 'etherpad-webcomponents';
6464
| `<ep-toast-container>` / `<ep-toast-item>` | `EpToastContainer` / `EpToastItem` | `position`, `type`, `message`, `duration` | — |
6565
| `<ep-toolbar-select>` | `EpToolbarSelect` | `options[]`, `value`, `icon-class`, `label`, `placeholder` | `ep-toolbar-select:change` |
6666
| `<ep-user-badge>` | `EpUserBadge` | `name`, `color`, `size`, `online` | — |
67-
| `<ep-theme>` | `EpTheme` | `name` — applies a token set to its subtree | — |
67+
| `<ep-tabs>` / `<ep-tab>` | `EpTabs` / `EpTab` | `value`, `variant` (`underline`/`pills`); tab: `value`, `label`, `disabled` | `ep-tab-change` |
68+
| `<ep-theme>` | `EpTheme` | `name` (incl. `auto`), `light`, `dark`, `.tokens` — applies a token set to its subtree | `ep-theme-change` |
6869
| `<ep-editor>` | `EpEditor` | `content`, `readonly`, `wrap`, `author-id` | `ready`, `content-changed`, `selection-changed` |
6970

7071
### Theming
7172

72-
Components read CSS custom properties (`--text-color`, `--primary-color`, `--bg-soft-color`, …). Wrap a subtree in `<ep-theme name="…">` to apply a token set. Built-in themes: **`colibris`** (default, matches Etherpad's skin), **`colibris-dark`**, **`high-contrast`**, and **`warm`**. Register your own at runtime:
73+
Components only read CSS custom properties, so every colour, radius and shadow can be changed without touching the components. Built-in themes: **`colibris`** (default, Etherpad's light-green skin), **`colibris-dark`**, **`high-contrast`** and **`warm`**.
74+
75+
| Token | Used for |
76+
| --- | --- |
77+
| `--bg-color`, `--bg-soft-color`, `--light-color`, `--super-light-color` | surfaces |
78+
| `--text-color`, `--text-soft-color`, `--dark-color`, `--super-dark-color` | text, icons |
79+
| `--middle-color` | borders |
80+
| `--primary-color`, `--primary-text-color` | accent and text on the accent |
81+
| `--danger-color`, `--success-color`, `--warning-color` | states |
82+
| `--focus-color` | focus ring |
83+
| `--radius`, `--radius-large`, `--shadow` | shape and elevation |
84+
| `--main-font-family` | font |
85+
86+
A theme only needs to state what differs from its base:
7387

7488
```js
75-
import { EpTheme } from 'etherpad-webcomponents';
76-
EpTheme.registerTheme('brand', { '--primary-color': '#ff5722', /* …all ThemeTokens */ });
89+
import { defineTheme } from '@samtv12345/etherpad-webcomponents';
90+
91+
defineTheme('acme', { '--primary-color': '#7c3aed' }); // based on colibris
92+
defineTheme('acme-dark', { '--primary-color': '#a78bfa' }, 'colibris-dark');
93+
```
94+
95+
```html
96+
<!-- fixed theme -->
97+
<ep-theme name="acme">…</ep-theme>
98+
99+
<!-- follow the operating system -->
100+
<ep-theme name="auto" light="acme" dark="acme-dark">…</ep-theme>
77101
```
78102

103+
`<ep-theme>` sets `data-scheme="light|dark"` on itself, fires `ep-theme-change` and updates live when a theme is redefined. Single tokens can be overridden per element with the `tokens` property. Without the element:
104+
105+
- `applyTheme(document.documentElement, 'acme')` sets the tokens on any element (and removes tokens of the previous call that the new set lacks),
106+
- `themeToCss('acme', ':root')` returns the tokens as a CSS rule, e.g. for rendering them server-side.
107+
108+
`@samtv12345/etherpad-webcomponents/themes.js` contains only these functions and the token sets, without any custom element.
109+
79110
### The editor (`<ep-editor>`)
80111

81112
`<ep-editor>` embeds Etherpad's Ace editor engine (under `src/editor/`: `Changeset`, `AttributePool`, `changesettracker`, content collector, op assemblers, etc.) as a self-contained element. It supports bold/italic/underline/strikethrough, ordered & unordered lists, indentation, undo/redo, and changeset-based collaboration.
@@ -99,7 +130,7 @@ const pending = ed.prepareUserChangeset(); // { changeset, apool } to send to
99130
The lower-level engine pieces are also exported for advanced use:
100131

101132
```js
102-
import { AceEditor, AttributePool, makeChangesetTracker } from 'etherpad-webcomponents';
133+
import { AceEditor, AttributePool, makeChangesetTracker } from '@samtv12345/etherpad-webcomponents';
103134
```
104135

105136
---

‎package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
"./EpToolbarSelect.js": "./dist/EpToolbarSelect.js",
2424
"./EpSelect.js": "./dist/EpSelect.js",
2525
"./EpUserBadge.js": "./dist/EpUserBadge.js",
26+
"./EpTabs.js": "./dist/EpTabs.js",
2627
"./EpTheme.js": "./dist/EpTheme.js",
28+
"./themes.js": "./dist/themes.js",
2729
"./EpEditor.js": "./dist/EpEditor.js",
2830
"./editor/AceEditor.js": "./dist/editor/AceEditor.js",
2931
"./editor/AttributePool.js": "./dist/editor/AttributePool.js",

‎src/EpButton.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class EpButton extends LitElement {
1212
button {
1313
font-family: var(--ep-font);
1414
padding: 5px 20px;
15-
border-radius: 4px;
15+
border-radius: var(--radius, 4px);
1616
font-size: 14px;
1717
font-weight: 700;
1818
cursor: pointer;
@@ -34,7 +34,7 @@ export class EpButton extends LitElement {
3434
}
3535
3636
button:focus-visible {
37-
outline: 2px solid var(--dark-color, #576273);
37+
outline: 2px solid var(--focus-color, var(--dark-color, #576273));
3838
outline-offset: 2px;
3939
}
4040
@@ -59,7 +59,7 @@ export class EpButton extends LitElement {
5959
background with bg-coloured (white) text. */
6060
:host([variant="primary"]) button {
6161
background: var(--primary-color, #64d29b);
62-
color: var(--bg-color, #ffffff);
62+
color: var(--primary-text-color, var(--bg-color, #ffffff));
6363
border: none;
6464
transition: filter 0.15s ease, opacity 0.15s ease;
6565
}
@@ -90,7 +90,7 @@ export class EpButton extends LitElement {
9090
color: var(--text-color, #485365);
9191
border: none;
9292
padding: 4px;
93-
border-radius: 3px;
93+
border-radius: calc(var(--radius, 4px) - 1px);
9494
min-width: 28px;
9595
min-height: 28px;
9696
justify-content: center;

‎src/EpCard.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export class EpCard extends LitElement {
1414
1515
.card {
1616
background: var(--bg-color, white);
17-
border-radius: 5px;
18-
box-shadow: 0 0 0 1px rgba(99, 114, 130, 0.16), 0 8px 16px rgba(27, 39, 51, 0.08);
17+
border-radius: var(--radius-large, 5px);
18+
box-shadow: var(--shadow, 0 0 0 1px rgba(99, 114, 130, 0.16), 0 8px 16px rgba(27, 39, 51, 0.08));
1919
overflow: hidden;
2020
}
2121

‎src/EpCheckbox.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class EpCheckbox extends LitElement {
9393
}
9494
9595
:host(:focus-within) .track {
96-
outline: 2px solid var(--dark-color, #576273);
96+
outline: 2px solid var(--focus-color, var(--dark-color, #576273));
9797
outline-offset: 2px;
9898
}
9999
@@ -112,7 +112,7 @@ export class EpCheckbox extends LitElement {
112112
<div class="track" @click="${this._toggle}">
113113
<div class="thumb"></div>
114114
</div>
115-
<input type="checkbox"
115+
<input type="checkbox" role="switch"
116116
.checked="${this.checked}"
117117
?disabled="${this.disabled}"
118118
@change="${this._toggle}"

‎src/EpColorPicker.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class EpColorPicker extends LitElement {
5252
background: var(--bg-color, white);
5353
border: 1px solid var(--middle-color, #d2d2d2);
5454
border-radius: 5px;
55-
box-shadow: 0 0 0 1px rgba(99, 114, 130, 0.16), 0 8px 16px rgba(27, 39, 51, 0.08);
55+
box-shadow: var(--shadow, 0 0 0 1px rgba(99, 114, 130, 0.16), 0 8px 16px rgba(27, 39, 51, 0.08));
5656
}
5757
5858
.swatch {
@@ -74,7 +74,7 @@ export class EpColorPicker extends LitElement {
7474
.swatch:hover { transform: scale(1.1); }
7575
7676
.swatch:focus-visible {
77-
outline: 2px solid var(--dark-color, #576273);
77+
outline: 2px solid var(--focus-color, var(--dark-color, #576273));
7878
outline-offset: 2px;
7979
}
8080

‎src/EpDropdown.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export class EpDropdown extends LitElement {
2727
overflow-y: auto;
2828
background: var(--bg-color, white);
2929
border: 1px solid var(--middle-color, #d2d2d2);
30-
border-radius: 5px;
31-
box-shadow: 0 0 0 1px rgba(99, 114, 130, 0.16), 0 8px 16px rgba(27, 39, 51, 0.08);
30+
border-radius: var(--radius-large, 5px);
31+
box-shadow: var(--shadow, 0 0 0 1px rgba(99, 114, 130, 0.16), 0 8px 16px rgba(27, 39, 51, 0.08));
3232
z-index: 9999;
3333
padding: 4px 0;
3434
opacity: 0;

‎src/EpDropdownItem.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class EpDropdownItem extends LitElement {
3636
3737
.item:focus-visible {
3838
background: var(--bg-soft-color, #f2f3f4);
39-
outline: 2px solid var(--dark-color, #576273);
39+
outline: 2px solid var(--focus-color, var(--dark-color, #576273));
4040
outline-offset: -2px;
4141
}
4242

‎src/EpInput.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class EpInput extends LitElement {
3030
margin: 0;
3131
padding: 8px 10px;
3232
border: 1px solid var(--middle-color, #d2d2d2);
33-
border-radius: 3px;
33+
border-radius: calc(var(--radius, 4px) - 1px);
3434
font-size: 14px;
3535
background: var(--bg-soft-color, #f2f3f4);
3636
color: var(--text-color, #485365);
@@ -65,13 +65,13 @@ export class EpInput extends LitElement {
6565
6666
:host([error]) input,
6767
:host([error]) textarea {
68-
border-color: #d1242f;
68+
border-color: var(--danger-color, #d1242f);
6969
}
7070
7171
.error-text {
7272
font-family: var(--ep-font);
7373
font-size: 12px;
74-
color: #d1242f;
74+
color: var(--danger-color, #d1242f);
7575
margin-top: 4px;
7676
}
7777
`;

‎src/EpModal.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export class EpModal extends LitElement {
4343
.dialog {
4444
position: relative; z-index: 1;
4545
background: var(--bg-color, white);
46-
border-radius: 5px;
47-
box-shadow: 0 0 0 1px rgba(99, 114, 130, 0.16), 0 8px 16px rgba(27, 39, 51, 0.08);
46+
border-radius: var(--radius-large, 5px);
47+
box-shadow: var(--shadow, 0 0 0 1px rgba(99, 114, 130, 0.16), 0 8px 16px rgba(27, 39, 51, 0.08));
4848
max-width: 480px; width: calc(100vw - 32px);
4949
max-height: calc(100vh - 64px); overflow: auto;
5050
animation: ep-modal-scale-in 0.2s ease; outline: none;
@@ -58,14 +58,14 @@ export class EpModal extends LitElement {
5858
background: none; border: none; cursor: pointer; padding: 4px;
5959
margin: -4px -4px 0 8px; color: var(--text-soft-color, #576273);
6060
opacity: 0.5; transition: opacity 0.15s ease; font-size: 18px; line-height: 1;
61-
display: flex; align-items: center; justify-content: center; border-radius: 4px;
61+
display: flex; align-items: center; justify-content: center; border-radius: var(--radius, 4px);
6262
}
6363
.close-btn:hover, .close-btn:focus-visible { opacity: 1; }
6464
.close-btn:focus-visible { outline: 2px solid var(--primary-color, #64d29b); outline-offset: 2px; }
6565
.body { padding: 20px 25px; line-height: 1.6; }
6666
.actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 0 25px 20px; }
6767
.actions ::slotted(button), .actions button {
68-
padding: 5px 20px; border-radius: 4px; font-size: 14px; font-weight: 700;
68+
padding: 5px 20px; border-radius: var(--radius, 4px); font-size: 14px; font-weight: 700;
6969
text-transform: uppercase; cursor: pointer;
7070
transition: background 0.15s ease, border-color 0.15s ease;
7171
font-family: inherit; line-height: 1.5;
@@ -76,7 +76,7 @@ export class EpModal extends LitElement {
7676
.btn-confirm:hover { background: var(--dark-color, #576273); }
7777
.prompt-input {
7878
width: 100%; box-sizing: border-box; padding: 8px 10px;
79-
border: 1px solid var(--middle-color, #d2d2d2); border-radius: 3px;
79+
border: 1px solid var(--middle-color, #d2d2d2); border-radius: calc(var(--radius, 4px) - 1px);
8080
font-size: 14px; font-family: inherit;
8181
background: var(--bg-soft-color, #f2f3f4); color: var(--text-color, #485365);
8282
margin-top: 12px; outline: none; transition: border-color 0.15s ease;
@@ -207,7 +207,7 @@ export class EpModal extends LitElement {
207207
const input = document.createElement('input');
208208
input.type = 'text';
209209
input.placeholder = options.placeholder ?? '';
210-
input.style.cssText = 'width:100%;box-sizing:border-box;padding:8px 10px;border:1px solid var(--middle-color,#d2d2d2);border-radius:3px;font-size:14px;margin-top:12px;outline:none;background:var(--bg-soft-color,#f2f3f4);color:var(--text-color,#485365);';
210+
input.style.cssText = 'width:100%;box-sizing:border-box;padding:8px 10px;border:1px solid var(--middle-color,#d2d2d2);border-radius:calc(var(--radius, 4px) - 1px);font-size:14px;margin-top:12px;outline:none;background:var(--bg-soft-color,#f2f3f4);color:var(--text-color,#485365);';
211211
container.append(msg, input);
212212
modal.appendChild(container);
213213
const actions = document.createElement('div');

0 commit comments

Comments
 (0)