mirror of
https://github.com/vran-dev/obsidian-contribution-graph.git
synced 2026-07-22 09:20:23 +00:00
feat: support reset background color to default
This commit is contained in:
parent
4a5078d83d
commit
c30d428780
3 changed files with 46 additions and 1 deletions
|
|
@ -13,7 +13,9 @@ import { useState } from "react";
|
|||
|
||||
export function ColorPicker(props: {
|
||||
color?: string;
|
||||
onChange: (color: string) => void;
|
||||
defaultColor?: string;
|
||||
onChange: (color?: string) => void;
|
||||
onReset?: (color?: string) => void;
|
||||
}): JSX.Element {
|
||||
const [showColorPicker, setShowColorPicker] = useState(false);
|
||||
const { refs, floatingStyles, context } = useFloating({
|
||||
|
|
@ -35,6 +37,20 @@ export function ColorPicker(props: {
|
|||
}}
|
||||
onClick={() => setShowColorPicker(!showColorPicker)}
|
||||
></span>
|
||||
{props.color && (
|
||||
<div className="color-label">
|
||||
<span>{props.color ?? ""}</span>
|
||||
<span className="color-reset-button" onClick={() => {
|
||||
if (props.onReset) {
|
||||
props.onReset(props.defaultColor);
|
||||
} else {
|
||||
props.onChange(props.defaultColor);
|
||||
}
|
||||
}}>
|
||||
x
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{showColorPicker ? (
|
||||
<div
|
||||
ref={refs.setFloating}
|
||||
|
|
|
|||
|
|
@ -440,6 +440,16 @@ export function GraphForm(props: {
|
|||
}
|
||||
);
|
||||
}}
|
||||
onReset={(color) => {
|
||||
changeFormData(
|
||||
"mainContainerStyle",
|
||||
{
|
||||
...formData.mainContainerStyle,
|
||||
backgroundColor:
|
||||
color,
|
||||
}
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
19
styles.css
19
styles.css
|
|
@ -288,6 +288,25 @@
|
|||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.color-label {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
background-color: hsl(var(--interactive-accent-hsl), 0.2);
|
||||
color: hsl(var(--interactive-accent-hsl), 0.8);
|
||||
align-items: center;
|
||||
border-radius: 6px;
|
||||
padding: 4px 8px;
|
||||
}
|
||||
|
||||
.color-label:hover {
|
||||
background-color: hsl(var(--interactive-accent-hsl), 0.8);
|
||||
color: var(--text-on-accent);
|
||||
}
|
||||
|
||||
.color-reset-button:hover {
|
||||
color: var(--text-normal);
|
||||
}
|
||||
|
||||
/* default cell rule indicator */
|
||||
.contribution-graph .cell-rule-indicator-container {
|
||||
position: relative;
|
||||
|
|
|
|||
Loading…
Reference in a new issue