Skip to content

Commit bdf7341

Browse files
committed
Follow codebase conventions
1 parent 2e14f9d commit bdf7341

1 file changed

Lines changed: 44 additions & 33 deletions

File tree

  • contentcuration/contentcuration/frontend/shared/views/TipTapEditor/TipTapEditor/components

contentcuration/contentcuration/frontend/shared/views/TipTapEditor/TipTapEditor/components/EditorToolbar.vue

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44
ref="toolbarRef"
55
class="toolbar"
66
role="toolbar"
7+
:style="{
8+
backgroundColor: $themePalette.grey.v_50,
9+
borderBottom: `1px solid ${$themeTokens.fineLine}`,
10+
}"
711
:aria-label="textFormattingToolbar$()"
812
>
913
<!-- History buttons -->
1014
<div
1115
role="group"
16+
class="toolbar-group"
1217
:aria-label="historyActions$()"
1318
>
1419
<ToolbarButton
@@ -27,6 +32,7 @@
2732
<!-- Format dropdown -->
2833
<div
2934
role="group"
35+
class="toolbar-group"
3036
:aria-label="textFormattingOptions$()"
3137
>
3238
<FormatDropdown />
@@ -73,7 +79,17 @@
7379
</template>
7480

7581
<template #more="{ overflowItems }">
76-
<button class="more-button">
82+
<button
83+
class="more-button"
84+
:class="
85+
$computedClass({
86+
':is([aria-expanded=\'true\'])': {
87+
color: $themePalette.blue.v_600,
88+
background: $themePalette.blue.v_100,
89+
},
90+
})
91+
"
92+
>
7793
<span>{{ moreButtonText$() }}</span>
7894
<img
7995
:src="require('../../assets/icon-chevron-down.svg')"
@@ -87,7 +103,14 @@
87103
<template #option="{ option }">
88104
<div
89105
class="overflow-item"
90-
:class="{ active: option.isActive }"
106+
:style="
107+
option.isActive
108+
? {
109+
color: $themePalette.blue.v_600,
110+
backgroundColor: $themePalette.blue.v_100,
111+
}
112+
: null
113+
"
91114
>
92115
<img
93116
:src="option.icon"
@@ -103,6 +126,7 @@
103126
</KListWithOverflow>
104127

105128
<ToolbarButton
129+
class="minimize-button"
106130
:title="minimizeAction.title"
107131
:icon="minimizeAction.icon"
108132
@click="minimizeAction.handler"
@@ -114,8 +138,7 @@
114138

115139
<script>
116140
117-
import { defineComponent, ref, computed } from 'vue';
118-
import KListWithOverflow from 'kolibri-design-system/lib/KListWithOverflow.vue';
141+
import { ref, computed } from 'vue';
119142
import { useToolbarActions } from '../composables/useToolbarActions';
120143
import { getTipTapEditorStrings } from '../TipTapEditorStrings';
121144
import { useDropdowns } from '../composables/useDropdowns';
@@ -124,10 +147,9 @@
124147
import PasteDropdown from './toolbar/PasteDropdown.vue';
125148
import ToolbarDivider from './toolbar/ToolbarDivider.vue';
126149
127-
export default defineComponent({
150+
export default {
128151
name: 'EditorToolbar',
129152
components: {
130-
KListWithOverflow,
131153
ToolbarButton,
132154
FormatDropdown,
133155
PasteDropdown,
@@ -165,7 +187,7 @@
165187
moreButtonText$,
166188
} = getTipTapEditorStrings();
167189
168-
const onToolClick = (tool, event, { fromOverflow } = {}) => {
190+
const onInsertToolClick = (tool, event, { fromOverflow } = {}) => {
169191
const target = fromOverflow ? null : event.currentTarget;
170192
if (tool.name === 'image') {
171193
emit('insert-image', target);
@@ -180,15 +202,13 @@
180202
181203
// Toolbar groups in visual order (left-to-right).
182204
// KListWithOverflow will collapse items from the end first.
183-
// Note: Don't include dividers here - KListWithOverflow renders
184-
// them automatically via #divider slot.
185-
//
205+
// Note: Don't include dividers here - this will be the source of truth.
206+
186207
// Each group describes its actions via `groupActions`. A `label` makes
187208
// the wrapper a role="group"; omitting it renders a plain div (for
188209
// single-action groups that don't need grouping semantics).
189210
// Actions with a `component` key render that component instead of a
190-
// ToolbarButton (e.g. PasteDropdown). Actions with an `onClick` key
191-
// receive the click event; otherwise `handler()` is called.
211+
// ToolbarButton (e.g. PasteDropdown).
192212
const toolbarGroups = computed(() => [
193213
{
194214
name: 'textFormat',
@@ -254,7 +274,7 @@
254274
label: insertTools$(),
255275
groupActions: insertTools.value.map(tool => ({
256276
...tool,
257-
handler: (e, { fromOverflow } = {}) => onToolClick(tool, e, { fromOverflow }),
277+
handler: (e, { fromOverflow } = {}) => onInsertToolClick(tool, e, { fromOverflow }),
258278
})),
259279
},
260280
]);
@@ -290,6 +310,11 @@
290310
return options;
291311
};
292312
313+
/**
314+
* Place a divider element between toolbar groups in the overflow menu.
315+
* This is necessary to tell KListWithOverflow where to render dividers
316+
* between groups.
317+
*/
293318
const toolbarGroupsWithDividers = computed(() => {
294319
const groups = [];
295320
toolbarGroups.value.forEach((group, index) => {
@@ -305,6 +330,9 @@
305330
});
306331
307332
const onOverflowSelect = (option, event) => {
333+
// Stop propagation to avoid triggering RTE on outside click handler that
334+
// minimizes the editor because KDropdownMenu is attached to an overlay layer,
335+
// i.e. not a descendant of the editor.
308336
event.stopPropagation();
309337
option.handler(event, { fromOverflow: true });
310338
};
@@ -322,7 +350,7 @@
322350
moreButtonText$,
323351
};
324352
},
325-
});
353+
};
326354
327355
</script>
328356

@@ -335,21 +363,14 @@
335363
gap: 6px;
336364
align-items: center;
337365
padding: 8px;
338-
background: #f8f9fa;
339-
border-bottom: 1px solid #e1e5e9;
340366
border-radius: 8px 8px 0 0;
341367
}
342368
343-
.toolbar > :last-child {
369+
.minimize-button {
370+
/* Push the minimize button to the far right. */
344371
margin-left: auto;
345372
}
346373
347-
[role='group'] {
348-
display: flex;
349-
gap: 2px;
350-
align-items: center;
351-
}
352-
353374
.overflow-list {
354375
flex: 1;
355376
min-width: 0;
@@ -383,11 +404,6 @@
383404
outline: 2px solid #0097f2;
384405
}
385406
386-
.more-button[aria-expanded='true'] {
387-
color: #4368f5;
388-
background: #d9e1fd;
389-
}
390-
391407
.more-button-icon {
392408
width: 16px;
393409
height: 16px;
@@ -406,11 +422,6 @@
406422
padding: 8px 12px;
407423
font-size: 1.2rem;
408424
line-height: 140%;
409-
410-
&.active {
411-
color: #3730a3;
412-
background-color: #e0e7ff;
413-
}
414425
}
415426
416427
.list-with-overflow-divider {

0 commit comments

Comments
 (0)