Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom header level icons #526

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions app/src/assets/header-level-icons/h1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/src/assets/header-level-icons/h2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions app/src/assets/header-level-icons/h3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/src/assets/header-level-icons/h4.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/src/assets/header-level-icons/h5.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions app/src/assets/header-level-icons/h6.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 22 additions & 1 deletion app/src/routes/editor/LayersPanel/Tree/NodeIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Link2Icon,
ListBulletIcon,
Pencil2Icon,
PilcrowIcon,
SectionIcon,
TextIcon,
VideoIcon,
Expand All @@ -16,6 +17,12 @@ import {
ViewVerticalIcon,
} from '@radix-ui/react-icons';
import { LayerNode } from '/common/models/element/layers';
import H1Icon from '/src/assets/header-level-icons/h1.svg';
import H2Icon from '/src/assets/header-level-icons/h2.svg';
import H3Icon from '/src/assets/header-level-icons/h3.svg';
import H4Icon from '/src/assets/header-level-icons/h4.svg';
import H5Icon from '/src/assets/header-level-icons/h5.svg';
import H6Icon from '/src/assets/header-level-icons/h6.svg';

interface NodeIconProps {
iconClass: string;
Expand All @@ -28,7 +35,21 @@ const NodeIcon = ({ iconClass, node }: NodeIconProps) => {
}

const tagName = node.tagName.toUpperCase();
if (['H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'P', 'STRONG', 'EM', 'SPAN', 'I'].includes(tagName)) {
if (tagName === 'H1') {
return <img src={H1Icon} className={iconClass} alt="H1" />;
} else if (tagName === 'H2') {
return <img src={H2Icon} className={iconClass} alt="H2" />;
} else if (tagName === 'H3') {
return <img src={H3Icon} className={iconClass} alt="H3" />;
} else if (tagName === 'H4') {
return <img src={H4Icon} className={iconClass} alt="H4" />;
} else if (tagName === 'H5') {
return <img src={H5Icon} className={iconClass} alt="H5" />;
} else if (tagName === 'H6') {
return <img src={H6Icon} className={iconClass} alt="H6" />;
} else if (tagName === 'P') {
return <PilcrowIcon className={iconClass} />;
} else if (['STRONG', 'EM', 'SPAN', 'I'].includes(tagName)) {
return <TextIcon className={iconClass} />;
} else if (tagName === 'A') {
return <Link2Icon className={iconClass} />;
Expand Down
4 changes: 4 additions & 0 deletions app/src/routes/editor/LayersPanel/Tree/TreeNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ const TreeNode = observer(
>
{instance?.component
? instance.component
: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p'].includes(
node.data.tagName.toLowerCase(),
)
? ''
: node.data.tagName.toLowerCase()}
{' ' + node.data.textContent}
</span>
Expand Down