Skip to content

Commit

Permalink
feat: move Strikethrough into More Formatting drop down
Browse files Browse the repository at this point in the history
  • Loading branch information
umaranis committed May 12, 2024
1 parent cc6f742 commit e0411cb
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
6 changes: 5 additions & 1 deletion demos/playground/src/ToolbarPlayground.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
DropDownAlign,
InsertHRDropDownItem,
InsertImageDropDownItem,
MoreStylesDropDown,
StrikethroughDropDownItem,
} from 'svelte-lexical';
import InsertImageDialog from './InsertImageDialog.svelte';
Expand Down Expand Up @@ -60,9 +62,11 @@
<BoldButton />
<ItalicButton />
<UnderlineButton />
<StrikethroughButton />
<FormatCodeButton />
<InsertLink />
<MoreStylesDropDown>
<StrikethroughDropDownItem />
</MoreStylesDropDown>
<Divider />
<InsertDropDown>
<InsertHRDropDownItem />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
let className: string;
export {className as class};
export let title: string | undefined = undefined;
export let ariaLabel: string | undefined = undefined;
let ref: HTMLButtonElement;
Expand All @@ -19,6 +20,12 @@
});
</script>

<button class={className} on:click bind:this={ref} {title} type="button">
<button
class={className}
on:click
bind:this={ref}
{title}
type="button"
aria-label={ariaLabel}>
<slot />
</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script lang="ts">
import {getIsEditable} from '$lib/core/composerContext.js';
import DropDown from '$lib/components/generic/dropdown/DropDown.svelte';
const isEditable = getIsEditable();
</script>

<DropDown
disabled={!$isEditable}
buttonClassName="toolbar-item spaced"
buttonLabel=""
buttonAriaLabel="Formatting options for additional text styles"
buttonIconClassName="icon dropdown-more">
<slot />
</DropDown>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script lang="ts">
import DropDownItem from '$lib/components/generic/dropdown/DropDownItem.svelte';
import {getActiveEditor} from '$lib/core/composerContext.js';
import {FORMAT_TEXT_COMMAND} from 'lexical';
import {getContext} from 'svelte';
import type {Writable} from 'svelte/store';
const activeEditor = getActiveEditor();
const isStrikethrough: Writable<boolean> = getContext('isStrikethrough');
</script>

<DropDownItem
on:click={() => {
$activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, 'strikethrough');
}}
class={'item ' + ($isStrikethrough ? 'active dropdown-item-active' : '')}
title="Strikethrough"
ariaLabel="Format text with a strikethrough">
<i class="icon strikethrough" />
<span class="text">Strikethrough</span>
</DropDownItem>
2 changes: 2 additions & 0 deletions packages/svelte-lexical/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export {default as FontSizeDropDown} from './components/toolbar/FontSizeDropDown
export {default as FontSizeEntry} from './components/toolbar/FontSizeEntry.svelte';
export {default as InsertLink} from './components/toolbar/InsertLink.svelte';
export {default as CodeLanguageDropDown} from './components/toolbar/CodeLanguageDropDown.svelte';
export {default as MoreStylesDropDown} from './components/toolbar/MoreStylesDropDown/MoreStylesDropDown.svelte';
export {default as StrikethroughDropDownItem} from './components/toolbar/MoreStylesDropDown/StrikethroughDropDownItem.svelte';
// dialogs
export {default as InsertImageDialog} from './components/toolbar/dialogs/InsertImageDialog.svelte';
export {default as InsertImageUploadedDialogBody} from './components/toolbar/dialogs/InsertImageUploadedDialogBody.svelte';
Expand Down

0 comments on commit e0411cb

Please sign in to comment.