Skip to content

Commit

Permalink
Redo approach to button active states
Browse files Browse the repository at this point in the history
This didn't actually work: it assumed that there were styles set on the
element with `style=""` (?) but the styling is actually done entirely
with CSS.

In some ways the setStyles approach is maybe more elegant? But it means
we can't use the CSS variables (?), and overall an "active" class just
seems simpler.
  • Loading branch information
dgmstuart committed Apr 22, 2024
1 parent e6ee863 commit 2337263
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
22 changes: 3 additions & 19 deletions src/components/ActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,15 @@ const ActionButton: React.FC<{
target.disabled = false;
};

const setStyles = function (
element: HTMLElement,
styles: React.CSSProperties,
) {
Object.assign(element.style, styles);
};

const buttonActive = function (element: HTMLButtonElement) {
const {
innerText,
style: { color, backgroundColor },
} = element;
const { innerText } = element;

setTimeout(() => {
setStyles(element, {
color: color,
backgroundColor: backgroundColor,
});
element.classList.remove("active");
element.innerText = innerText;
}, activeDuration);

setStyles(element, {
color: "#282c34",
backgroundColor: "white",
});
element.classList.add("active");
if (changeText) {
element.innerText = changeText;
}
Expand Down
5 changes: 5 additions & 0 deletions src/components/CardActions.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@
border-radius: 0.25rem;
background-color: transparent;
}

.CardActions button.active {
color: var(--dark);
background-color: var(--off-white);
}

0 comments on commit 2337263

Please sign in to comment.