Skip to content

Commit d74b014

Browse files
authored
Merge pull request #493 from Harbour-Enterprises/har-9642_no-highlight
HAR-9642 Add no highlight option
2 parents f89003f + df33a6d commit d74b014

6 files changed

Lines changed: 63 additions & 18 deletions

File tree

packages/super-editor/src/components/toolbar/IconGrid.vue

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup>
22
import IconGridRow from './IconGridRow.vue';
3+
import DropIcon from '@harbour-enterprises/common/icons/droplet-slash.svg?raw';
34
45
const emit = defineEmits(['select', 'clickoutside']);
56
const props = defineProps({
@@ -15,6 +16,10 @@ const props = defineProps({
1516
type: Object,
1617
required: false,
1718
},
19+
hasNoneIcon: {
20+
type: Boolean,
21+
required: false,
22+
}
1823
});
1924
2025
const handleSelect = (option) => {
@@ -24,31 +29,58 @@ const handleSelect = (option) => {
2429
</script>
2530

2631
<template>
27-
<div class="option-grid-ctn">
28-
<IconGridRow
29-
:icons="icons"
30-
:active-color="activeColor"
31-
@select="handleSelect"
32-
/>
33-
34-
<template v-if="customIcons.flat().length">
35-
<span class="option-grid-ctn__subtitle">Custom colors</span>
36-
32+
<div class="options-grid-wrap">
33+
<div
34+
v-if="hasNoneIcon"
35+
class="none-option"
36+
@click="handleSelect('none')"
37+
>
38+
<span
39+
v-html="DropIcon"
40+
class="none-icon"
41+
></span>
42+
None
43+
</div>
44+
<div class="option-grid-ctn">
3745
<IconGridRow
38-
:icons="customIcons"
46+
:icons="icons"
3947
:active-color="activeColor"
4048
@select="handleSelect"
4149
/>
42-
</template>
50+
51+
<template v-if="customIcons.flat().length">
52+
<span class="option-grid-ctn__subtitle">Custom colors</span>
53+
54+
<IconGridRow
55+
:icons="customIcons"
56+
:active-color="activeColor"
57+
@select="handleSelect"
58+
/>
59+
</template>
60+
</div>
4361
</div>
4462
</template>
4563

4664
<style scoped>
65+
.options-grid-wrap {
66+
padding: 5px;
67+
border-radius: 5px;
68+
}
69+
.none-option {
70+
display: flex;
71+
align-items: center;
72+
gap: 4px;
73+
padding: 4px;
74+
&:hover {
75+
opacity: 0.65;
76+
}
77+
}
78+
.none-icon {
79+
width: 16px;
80+
}
4781
.option-grid-ctn {
4882
display: flex;
4983
flex-direction: column;
50-
padding: 5px;
51-
border-radius: 5px;
5284
background-color: #fff;
5385
z-index: 3;
5486
box-sizing: border-box;

packages/super-editor/src/components/toolbar/color-dropdown-helpers.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const makeColorOption = (color, label = null) => {
2020
};
2121
};
2222

23-
export const renderColorOptions = (superToolbar, button, customIcons = []) => {
23+
export const renderColorOptions = (superToolbar, button, customIcons = [], hasNoneIcon = false) => {
2424
const handleSelect = (e) => {
2525
button.iconColor.value = e;
2626
superToolbar.emitCommand({ item: button, argument: e });
@@ -32,6 +32,7 @@ export const renderColorOptions = (superToolbar, button, customIcons = []) => {
3232
icons,
3333
customIcons,
3434
activeColor: button.iconColor,
35+
hasNoneIcon,
3536
onSelect: handleSelect,
3637
}),
3738
]);

packages/super-editor/src/components/toolbar/defaultItems.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,13 @@ export const makeDefaultItems = (superToolbar, isDev = false, windowWidth, role,
218218
active: false,
219219
tooltip: 'Highlight color',
220220
command: 'setHighlight',
221+
noArgumentCommand: 'unsetHighlight',
221222
suppressActiveHighlight: true,
222223
options: [
223224
{
224225
key: 'color',
225226
type: 'render',
226-
render: () => renderColorOptions(superToolbar, highlight),
227+
render: () => renderColorOptions(superToolbar, highlight, [], true),
227228
},
228229
],
229230
onActivate: ({ color }) => {

packages/super-editor/src/components/toolbar/super-toolbar.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ export class SuperToolbar extends EventEmitter {
322322
const option = {
323323
key: 'color',
324324
type: 'render',
325-
render: () => renderColorOptions(this, highlightItem, result),
325+
render: () => renderColorOptions(this, highlightItem, result, true),
326326
}
327327

328328
highlightItem.nestedOptions.value = [option];
@@ -459,8 +459,16 @@ export class SuperToolbar extends EventEmitter {
459459

460460
#runCommandWithArgumentOnly({ item, argument }, callback) {
461461
if (!argument || !this.activeEditor) return;
462-
462+
463463
let command = item.command;
464+
const noArgumentCommand = item.noArgumentCommand;
465+
466+
if (argument === 'none' && noArgumentCommand in this.activeEditor?.commands) {
467+
this.activeEditor.commands[noArgumentCommand]();
468+
this.updateToolbarState();
469+
return;
470+
}
471+
464472
if (command in this.activeEditor?.commands) {
465473
this.activeEditor.commands[command](argument);
466474
if (typeof callback === 'function') callback(argument);

packages/super-editor/src/components/toolbar/use-toolbar-item.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const useToolbarItem = (options) => {
1919
const type = options.type;
2020
const name = ref(options.name);
2121
const command = options.command;
22+
const noArgumentCommand = options.noArgumentCommand;
2223
const icon = ref(options.icon);
2324
const group = ref(options.group || 'center');
2425
const allowWithoutEditor = ref(options.allowWithoutEditor);
@@ -112,6 +113,7 @@ export const useToolbarItem = (options) => {
112113
name,
113114
type,
114115
command,
116+
noArgumentCommand,
115117
icon,
116118
tooltip,
117119
group,
Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)