Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

editor: improve checklist styling Signed-off-by: 01zulfi <[email protected]>

01zulfib01d1fc87e76
diff --git a/packages/editor/src/extensions/check-list-item/check-list-item.ts b/packages/editor/src/extensions/check-list-item/check-list-item.ts
index 6f9b97a24..41fd001b7 100644
--- a/packages/editor/src/extensions/check-list-item/check-list-item.ts
+++ b/packages/editor/src/extensions/check-list-item/check-list-item.ts
@@ -98,32 +98,36 @@ export const CheckListItem = Node.create<CheckListItemOptions>({
addNodeView() {
return ({ node, getPos, editor }) => {
const listItem = document.createElement("li");
- const checkboxWrapper = document.createElement("label");
- const checkboxStyler = document.createElement("span");
- const checkbox = document.createElement("input");
+ const checkboxWrapper = document.createElement("div");
const content = document.createElement("div");
checkboxWrapper.contentEditable = "false";
- checkbox.type = "checkbox";
+ checkboxWrapper.className = "checkbox-wrapper";
+ checkboxWrapper.innerHTML = `
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
+ <path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/>
+ </svg>
+ `;
- checkbox.addEventListener("mousedown", (event) => {
+ content.className = "checklist-item-content";
+
+ checkboxWrapper.addEventListener("mousedown", (event) => {
if (globalThis.keyboardShown) {
event.preventDefault();
}
});
- checkbox.addEventListener("change", (event) => {
+ checkboxWrapper.addEventListener("click", (event) => {
event.preventDefault();
- // if the editor isn’t editable and we don't have a handler for
+
+ const isChecked = checkboxWrapper.classList.contains("checked");
+
+ // if the editor isn't editable and we don't have a handler for
// readonly checks we have to undo the latest change
if (!editor.isEditable && !this.options.onReadOnlyChecked) {
- checkbox.checked = !checkbox.checked;
-
return;
}
- const { checked } = event.target as any;
-
if (editor.isEditable && typeof getPos === "function") {
editor
.chain()
@@ -133,7 +137,7 @@ export const CheckListItem = Node.create<CheckListItemOptions>({
tr.setNodeMarkup(position, undefined, {
...currentNode?.attrs,
- checked
+ checked: !isChecked
});
return true;
@@ -142,17 +146,17 @@ export const CheckListItem = Node.create<CheckListItemOptions>({
}
if (!editor.isEditable && this.options.onReadOnlyChecked) {
// Reset state if onReadOnlyChecked returns false
- if (!this.options.onReadOnlyChecked(node, checked)) {
- checkbox.checked = !checkbox.checked;
+ if (!this.options.onReadOnlyChecked(node, !isChecked)) {
+ return;
}
}
});
if (node.attrs.checked) {
- checkbox.setAttribute("checked", "checked");
+ checkboxWrapper.classList.add("checked");
+ listItem.dataset.checked = node.attrs.checked;
}
- checkboxWrapper.append(checkbox, checkboxStyler);
listItem.append(checkboxWrapper, content);
return {
@@ -165,9 +169,9 @@ export const CheckListItem = Node.create<CheckListItemOptions>({
listItem.dataset.checked = updatedNode.attrs.checked;
if (updatedNode.attrs.checked) {
- checkbox.setAttribute("checked", "checked");
+ checkboxWrapper.classList.add("checked");
} else {
- checkbox.removeAttribute("checked");
+ checkboxWrapper.classList.remove("checked");
}
return true;
diff --git a/packages/editor/styles/styles.css b/packages/editor/styles/styles.css
index 3ff2ec936..f71f27118 100644
--- a/packages/editor/styles/styles.css
+++ b/packages/editor/styles/styles.css
@@ -643,24 +643,57 @@ p > *::selection {
/* Check list */
.ProseMirror ul.simple-checklist {
list-style: none;
- padding: 0;
+ margin-left: -25px;
}
.ProseMirror ul.simple-checklist > li {
display: flex;
+ align-items: center;
}
-.ProseMirror ul.simple-checklist > li input {
- flex: 0 0 auto;
- margin-right: 0.5rem;
- user-select: none;
- height: 1rem;
+.ProseMirror ul.simple-checklist > li > div.checklist-item-content {
+ flex: 1 1 auto;
+ display: flex;
+ justify-content: center;
+ flex-direction: column;
+}
+
+.ProseMirror ul.simple-checklist > li[data-checked="true"] > div.checklist-item-content {
+ opacity: 0.6;
+}
+
+.ProseMirror ul.simple-checklist > li > div.checkbox-wrapper {
+ border: 2px solid var(--icon);
+ width: 0.9rem;
+ height: 0.9rem;
+ border-radius: 4px;
+ margin-right: 7px;
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ cursor: pointer;
+ transition: all 250ms cubic-bezier(1, 0, .37, .91);
+ background-color: transparent;
+}
+
+.ProseMirror ul.simple-checklist > li > div.checkbox-wrapper:hover {
+ border-color: var(--accent);
+}
+
+.ProseMirror ul.simple-checklist > li > div.checkbox-wrapper.checked {
+ border-color: var(--accent);
+}
+
+.ProseMirror ul.simple-checklist > li > div.checkbox-wrapper svg {
width: 1rem;
- accent-color: var(--accent);
+ height: 1rem;
+ fill: var(--accent);
+ opacity: 0;
+ transition: opacity 250ms cubic-bezier(1, 0, .37, .91);
}
-.ProseMirror ul.simple-checklist > li > div {
- flex: 1 1 auto;
+.ProseMirror ul.simple-checklist > li > div.checkbox-wrapper.checked svg {
+ opacity: 1;
}
@media screen and (max-width: 480px) {