Changed snippet icon in menus based on snippet contents

no issue

- vary the snippet icon based on the snippet contents: text only, text and cards, cards only
This commit is contained in:
Kevin Ansfield 2020-10-23 10:55:46 +01:00
parent 0ab0100567
commit b392313df1
3 changed files with 21 additions and 2 deletions

View File

@ -1,5 +1,6 @@
import Component from '@ember/component';
import mobiledocParsers from 'mobiledoc-kit/parsers/mobiledoc';
import snippetIcon from '../utils/snippet-icon';
import {CARD_MENU} from '../options/cards';
import {computed} from '@ember/object';
import {htmlSafe} from '@ember/string';
@ -50,7 +51,7 @@ export default Component.extend({
snippets.forEach((snippet) => {
snippetsSection.items.push({
label: snippet.name,
icon: 'koenig/kg-card-type-snippet-text',
icon: snippetIcon(snippet),
type: 'snippet',
matches: [snippet.name.toLowerCase()]
});

View File

@ -1,5 +1,6 @@
import Component from '@glimmer/component';
import mobiledocParsers from 'mobiledoc-kit/parsers/mobiledoc';
import snippetIcon from '../utils/snippet-icon';
import {CARD_MENU} from '../options/cards';
import {action} from '@ember/object';
import {isEmpty} from '@ember/utils';
@ -69,7 +70,7 @@ export default class KoenigSlashMenuComponent extends Component {
snippets.forEach((snippet) => {
snippetsSection.items.push({
label: snippet.name,
icon: 'koenig/kg-card-type-snippet-text',
icon: snippetIcon(snippet),
type: 'snippet',
matches: [snippet.name.toLowerCase()]
});

View File

@ -0,0 +1,17 @@
export default function snippetIcon(snippet) {
let {mobiledoc} = snippet;
if (mobiledoc.cards.length === 0) {
return 'koenig/kg-card-type-snippet-text';
}
let hasRichText = mobiledoc.sections.some((section) => {
return section[0] !== 10;
});
if (hasRichText) {
return 'koenig/kg-card-type-snippet-combination';
}
return 'koenig/kg-card-type-snippet-block';
}