Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 46 additions & 14 deletions packages/super-editor/src/components/toolbar/IconGrid.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup>
import IconGridRow from './IconGridRow.vue';
import DropIcon from '@harbour-enterprises/common/icons/droplet-slash.svg?raw';

const emit = defineEmits(['select', 'clickoutside']);
const props = defineProps({
Expand All @@ -15,6 +16,10 @@ const props = defineProps({
type: Object,
required: false,
},
hasNoneIcon: {
type: Boolean,
required: false,
}
});

const handleSelect = (option) => {
Expand All @@ -24,31 +29,58 @@ const handleSelect = (option) => {
</script>

<template>
<div class="option-grid-ctn">
<IconGridRow
:icons="icons"
:active-color="activeColor"
@select="handleSelect"
/>

<template v-if="customIcons.flat().length">
<span class="option-grid-ctn__subtitle">Custom colors</span>

<div class="options-grid-wrap">
<div
v-if="hasNoneIcon"
class="none-option"
@click="handleSelect('none')"
>
<span
v-html="DropIcon"
class="none-icon"
></span>
None
</div>
<div class="option-grid-ctn">
<IconGridRow
:icons="customIcons"
:icons="icons"
:active-color="activeColor"
@select="handleSelect"
/>
</template>

<template v-if="customIcons.flat().length">
<span class="option-grid-ctn__subtitle">Custom colors</span>

<IconGridRow
:icons="customIcons"
:active-color="activeColor"
@select="handleSelect"
/>
</template>
</div>
</div>
</template>

<style scoped>
.options-grid-wrap {
padding: 5px;
border-radius: 5px;
}
.none-option {
display: flex;
align-items: center;
gap: 4px;
padding: 4px;
&:hover {
opacity: 0.65;
}
}
.none-icon {
width: 16px;
}
.option-grid-ctn {
display: flex;
flex-direction: column;
padding: 5px;
border-radius: 5px;
background-color: #fff;
z-index: 3;
box-sizing: border-box;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const makeColorOption = (color, label = null) => {
};
};

export const renderColorOptions = (superToolbar, button, customIcons = []) => {
export const renderColorOptions = (superToolbar, button, customIcons = [], hasNoneIcon = false) => {
const handleSelect = (e) => {
button.iconColor.value = e;
superToolbar.emitCommand({ item: button, argument: e });
Expand All @@ -32,6 +32,7 @@ export const renderColorOptions = (superToolbar, button, customIcons = []) => {
icons,
customIcons,
activeColor: button.iconColor,
hasNoneIcon,
onSelect: handleSelect,
}),
]);
Expand Down
3 changes: 2 additions & 1 deletion packages/super-editor/src/components/toolbar/defaultItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,13 @@ export const makeDefaultItems = (superToolbar, isDev = false, windowWidth, role,
active: false,
tooltip: 'Highlight color',
command: 'setHighlight',
noArgumentCommand: 'unsetHighlight',
suppressActiveHighlight: true,
options: [
{
key: 'color',
type: 'render',
render: () => renderColorOptions(superToolbar, highlight),
render: () => renderColorOptions(superToolbar, highlight, [], true),
},
],
onActivate: ({ color }) => {
Expand Down
12 changes: 10 additions & 2 deletions packages/super-editor/src/components/toolbar/super-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export class SuperToolbar extends EventEmitter {
const option = {
key: 'color',
type: 'render',
render: () => renderColorOptions(this, highlightItem, result),
render: () => renderColorOptions(this, highlightItem, result, true),
}

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

#runCommandWithArgumentOnly({ item, argument }, callback) {
if (!argument || !this.activeEditor) return;

let command = item.command;
const noArgumentCommand = item.noArgumentCommand;

if (argument === 'none' && noArgumentCommand in this.activeEditor?.commands) {
this.activeEditor.commands[noArgumentCommand]();
this.updateToolbarState();
return;
}

if (command in this.activeEditor?.commands) {
this.activeEditor.commands[command](argument);
if (typeof callback === 'function') callback(argument);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const useToolbarItem = (options) => {
const type = options.type;
const name = ref(options.name);
const command = options.command;
const noArgumentCommand = options.noArgumentCommand;
const icon = ref(options.icon);
const group = ref(options.group || 'center');
const allowWithoutEditor = ref(options.allowWithoutEditor);
Expand Down Expand Up @@ -112,6 +113,7 @@ export const useToolbarItem = (options) => {
name,
type,
command,
noArgumentCommand,
icon,
tooltip,
group,
Expand Down
1 change: 1 addition & 0 deletions shared/common/icons/droplet-slash.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading