Skip to content

Commit

Permalink
Fix: ToolbarPlugin paste error with start, end format (#5019)
Browse files Browse the repository at this point in the history
  • Loading branch information
khsily authored Sep 28, 2023
1 parent 9a272fa commit 0e5671a
Showing 1 changed file with 53 additions and 3 deletions.
56 changes: 53 additions & 3 deletions packages/lexical-playground/src/plugins/ToolbarPlugin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,42 @@ const FONT_SIZE_OPTIONS: [string, string][] = [
];

const ELEMENT_FORMAT_OPTIONS: {
[key: string]: {icon: string; name: string};
[key in Exclude<ElementFormatType, ''>]: {
icon: string;
iconRTL: string;
name: string;
};
} = {
center: {
icon: 'center-align',
iconRTL: 'right-align',
name: 'Center Align',
},
end: {
icon: 'right-align',
iconRTL: 'left-align',
name: 'End Align',
},
justify: {
icon: 'justify-align',
iconRTL: 'justify-align',
name: 'Justify Align',
},
left: {
icon: 'left-align',
iconRTL: 'left-align',
name: 'Left Align',
},
right: {
icon: 'right-align',
iconRTL: 'left-align',
name: 'Right Align',
},
start: {
icon: 'left-align',
iconRTL: 'right-align',
name: 'Start Align',
},
};

function dropDownActiveClass(active: boolean) {
Expand Down Expand Up @@ -415,11 +433,15 @@ function ElementFormatDropdown({
isRTL: boolean;
disabled: boolean;
}) {
const formatOption = ELEMENT_FORMAT_OPTIONS[value || 'left'];

return (
<DropDown
disabled={disabled}
buttonLabel={ELEMENT_FORMAT_OPTIONS[value].name}
buttonIconClassName={`icon ${ELEMENT_FORMAT_OPTIONS[value].icon}`}
buttonLabel={formatOption.name}
buttonIconClassName={`icon ${
isRTL ? formatOption.iconRTL : formatOption.icon
}`}
buttonClassName="toolbar-item spaced alignment"
buttonAriaLabel="Formatting options for text alignment">
<DropDownItem
Expand Down Expand Up @@ -454,6 +476,34 @@ function ElementFormatDropdown({
<i className="icon justify-align" />
<span className="text">Justify Align</span>
</DropDownItem>
<DropDownItem
onClick={() => {
editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'start');
}}
className="item">
<i
className={`icon ${
isRTL
? ELEMENT_FORMAT_OPTIONS.start.iconRTL
: ELEMENT_FORMAT_OPTIONS.start.icon
}`}
/>
<span className="text">Start Align</span>
</DropDownItem>
<DropDownItem
onClick={() => {
editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'end');
}}
className="item">
<i
className={`icon ${
isRTL
? ELEMENT_FORMAT_OPTIONS.end.iconRTL
: ELEMENT_FORMAT_OPTIONS.end.icon
}`}
/>
<span className="text">End Align</span>
</DropDownItem>
<Divider />
<DropDownItem
onClick={() => {
Expand Down

1 comment on commit 0e5671a

@vercel
Copy link

@vercel vercel bot commented on 0e5671a Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lexical – ./packages/lexical-website

lexical-fbopensource.vercel.app
lexical.dev
lexicaljs.com
lexical-git-main-fbopensource.vercel.app
www.lexical.dev
lexicaljs.org

Please sign in to comment.