Skip to content

Build your personal knowledge base with Trilium Notes

text editor/checkboxes: style checkboxes

Adorian Doran53c8b1c8eb0c
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.css
index 26e4316041..3ecfde6710 100644
--- a/apps/client/src/stylesheets/style.css
+++ b/apps/client/src/stylesheets/style.css
@@ -1285,10 +1285,6 @@ body.mobile .modal-content-with-sidebar > .modal-main > .modal-header > .modal-t
line-height: 1.5;
}
-.ck-content .todo-list .todo-list__label > input:before {
- border: 1px solid var(--muted-text-color) !important;
-}
-
.ck-link-actions .ck-tooltip {
/* force hide the tooltip since it shows misleading "open link in new tab */
display: none !important;
@@ -2545,18 +2541,6 @@ footer.webview-footer button {
opacity: 0.6;
}
-.ck-content ul.todo-list > li[data-task-state="doing"] {
- background-color: rgba(255, 200, 100, 0.25);
-}
-
-.ck-content ul.todo-list > li[data-task-state="cancelled"] {
- background-color: rgba(180, 180, 180, 0.25);
-}
-
-.ck-content ul.todo-list > li[data-task-state="maybe"] {
- background-color: rgba(200, 150, 240, 0.25);
-}
-
.chat-options-container {
display: flex;
margin: 5px 0;
@@ -2749,3 +2733,63 @@ iframe.print-iframe {
.ck-content pre code {
tab-size: var(--code-block-tab-width, 4);
}
+
+/* Task states in CK Editor */
+
+:root {
+ --task-checkbox-background: rgb(213, 213, 213);
+ --task-checkbox-done-color: green;
+ --task-checkbox-color: white;
+ --task-checkbox-border-radius: 4px;
+ --task-checkbox-padding: 2.5px;
+}
+
+:root .tn-task-checkbox {
+ position: relative;
+ width: 18px;
+ height: 18px;
+ font-size: 18px;
+}
+
+/* Default checked state */
+.ck-content li input[type="checkbox"]:checked,
+.tn-task-checkbox[data-task-state="done"] {
+ --task-state-color: var(--task-checkbox-done-color);
+ --task-state-glyph: "";
+ --task-state-glyph-font-family: boxicons;
+}
+
+:root .ck.ck.ck-content li span.todo-list__label input[type="checkbox"],
+:root .note-detail-readonly-text-content.ck-content ul.todo-list li .todo-list__label input[type="checkbox"],
+.tn-task-checkbox {
+ /* Checkbox body */
+ &::before {
+ all: unset;
+
+ content: "";
+ position: absolute;
+ inset: 0;
+ border-radius: var(--task-checkbox-border-radius);
+ background: var(--task-state-color, var(--task-checkbox-background));
+ }
+
+ /* Checkbox tick */
+ &::after {
+ all: unset;
+
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ position: absolute;
+ inset: var(--task-checkbox-padding);
+ content: var(--task-state-glyph);
+ font-family: var(--task-state-glyph-font-family, inherit);
+ font-size: calc(100% - var(--task-checkbox-padding) * 2);
+ color: var(--task-checkbox-color);
+ }
+
+ &:disabled {
+ opacity: 1;
+ cursor: not-allowed;
+ }
+}
\ No newline at end of file
diff --git a/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_ui.ts b/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_ui.ts
index 3e81440187..97f1287325 100644
--- a/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_ui.ts
+++ b/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_ui.ts
@@ -1,4 +1,4 @@
-import { ButtonView, Plugin } from "ckeditor5";
+import { ButtonView, Plugin, View } from "ckeditor5";
import TodoListMultistateEditing, { getConfiguredTaskStates } from "./todo_list_multistate_editing.js";
export default class TodoListMultistateUI extends Plugin {
@@ -18,13 +18,21 @@ export default class TodoListMultistateUI extends Plugin {
label: state.title || state.name,
withText: false,
tooltip: true,
- class: `ck-task-state-button ck-task-state-${state.name}${state.icon ? ` ${state.icon}` : ""}`
+ class: "ck-task-state-button"
});
- if (state.color) {
- button.extendTemplate({
- attributes: {style: `--task-state-color:${state.color}`}
- });
- }
+
+ // A checkbox preview inside the button, styled by the same
+ // `[data-task-state]` CSS that decorates the real checkboxes.
+ const preview = new View(locale);
+ preview.setTemplate({
+ tag: "div",
+ attributes: {
+ class: "tn-task-checkbox ck-reset_all-excluded",
+ "data-task-state": state.name
+ }
+ });
+ button.children.add(preview);
+
button.bind("isOn").to(command, "value", (value) => value === state.name);
button.bind("isEnabled").to(command, "isEnabled");
button.on("execute", () => {
diff --git a/packages/share-theme/src/styles/base.css b/packages/share-theme/src/styles/base.css
index 155f720eac..dca816c922 100644
--- a/packages/share-theme/src/styles/base.css
+++ b/packages/share-theme/src/styles/base.css
@@ -146,16 +146,4 @@ iframe.pdf-view {
.ck-content .todo-list .todo-list__label > input:before {
background-color: var(--background-primary);
border-color: var(--text-primary) !important;
-}
-
-.ck-content ul.todo-list > li[data-task-state="doing"] {
- background-color: rgba(255, 200, 100, 0.25);
-}
-
-.ck-content ul.todo-list > li[data-task-state="cancelled"] {
- background-color: rgba(180, 180, 180, 0.25);
-}
-
-.ck-content ul.todo-list > li[data-task-state="maybe"] {
- background-color: rgba(200, 150, 240, 0.25);
-}
+}
\ No newline at end of file
diff --git a/packages/trilium-core/src/services/task_states.ts b/packages/trilium-core/src/services/task_states.ts
index 63bd105152..b29a5c8869 100644
--- a/packages/trilium-core/src/services/task_states.ts
+++ b/packages/trilium-core/src/services/task_states.ts
@@ -150,7 +150,7 @@ export function generateTaskStateCss(): string {
if (!resolved) {
continue;
}
- const selector = `li[data-task-state="${escapeCssString(state.name)}"]`;
+ const selector = `li[data-task-state="${escapeCssString(state.name)}"], .tn-task-checkbox[data-task-state="${escapeCssString(state.name)}"]`;
rules.push(`${selector} {
--task-state-glyph: "${resolved.glyph}";
--task-state-glyph-font-family: "${resolved.fontFamily}";