mirror of
https://github.com/zadam/trilium.git
synced 2025-11-18 03:00:41 +01:00
client/note color picker menu item: add initial implementation
This commit is contained in:
15
apps/client/src/menus/custom-items/ColorPickerMenuItem.css
Normal file
15
apps/client/src/menus/custom-items/ColorPickerMenuItem.css
Normal file
@@ -0,0 +1,15 @@
|
||||
.color-picker-menu-item {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.color-picker-menu-item > .color-cell {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 4px;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.color-picker-menu-item > .color-cell.selected {
|
||||
outline: 2px solid royalblue;
|
||||
}
|
||||
@@ -1,9 +1,38 @@
|
||||
import FNote from "../../entities/fnote"
|
||||
import "./ColorPickerMenuItem.css";
|
||||
import { useState } from "preact/hooks";
|
||||
import attributes from "../../services/attributes";
|
||||
import FNote from "../../entities/fnote";
|
||||
|
||||
const COLORS = ["blue", "green", "cyan", "red", "magenta", "brown", "yellow", ""];
|
||||
|
||||
export interface ColorPickerMenuItemProps {
|
||||
note: FNote | null;
|
||||
}
|
||||
|
||||
export default function ColorPickerMenuItem(props: ColorPickerMenuItemProps) {
|
||||
return <span>Color Picker</span>
|
||||
const {note} = props;
|
||||
if (!note) return null;
|
||||
|
||||
const [currentColor, setCurrentColor] = useState(note.getLabel("color")?.value ?? "");
|
||||
|
||||
const onColorCellClicked = (color: string) => {
|
||||
attributes.setLabel(note.noteId, "color", color);
|
||||
setCurrentColor(color);
|
||||
}
|
||||
|
||||
return <div className="color-picker-menu-item">
|
||||
{COLORS.map((color) => (
|
||||
<ColorCell key={color}
|
||||
color={color}
|
||||
isSelected={(color === currentColor)}
|
||||
onClick={() => onColorCellClicked(color)} />
|
||||
))}
|
||||
</div>
|
||||
}
|
||||
|
||||
function ColorCell(props: {color: string, isSelected: boolean, onClick?: () => void}) {
|
||||
return <div class={`color-cell ${props.isSelected ? "selected" : ""}`}
|
||||
style={`background-color: ${props.color}`}
|
||||
onClick={props.onClick}>
|
||||
</div>;
|
||||
}
|
||||
Reference in New Issue
Block a user