Skip to content

Commit

Permalink
Fixed plus-minus button
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-locatelli committed Apr 17, 2024
1 parent 2dc28a6 commit ca450bc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
27 changes: 21 additions & 6 deletions src/components/ExpandButton.astro
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ const { buttonText, buttonLink, id } = Astro.props;

<div>
<div class="read-more">
<button class="plus-minus" id={"expand-button-" + id}>+</button><span
<button class="plus-minus" id={"expand-button-" + id}
><svg class="icon">
<use xlink:href="/assets/icons.svg#plus"></use>
</svg>
</button>
<span
><Button
text={buttonText}
link={buttonLink}
Expand All @@ -29,6 +34,7 @@ const { buttonText, buttonLink, id } = Astro.props;
<style>
.read-more {
display: flex;
align-items: center;
}

.more-text {
Expand All @@ -41,23 +47,32 @@ const { buttonText, buttonLink, id } = Astro.props;
}

.plus-minus {
background: none;
display: flex;
justify-content: center;
align-items: center;
width: 1.7rem;
height: 1.7rem;
font-size: 1.6rem;
background-color: var(--text-main);
color: var(--background-body);
border-radius: 50%;
aspect-ratio: 1/1;
height: 26px;
padding: 0;
margin-right: 1rem;
cursor: pointer;
border: 0;
}

.plus-minus:hover {
background-color: var(--background-body);
color: var(--text-main);
}

.icon {
height: 26px;
width: 26px;
fill: var(--background-body);
}

.icon:hover {
fill: var(--text-main);
}

@media (max-width: 1280px) {
Expand Down
7 changes: 5 additions & 2 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,16 @@ const posts = await getAllPosts();

textsExpandButtons.forEach((text, i) => {
const button = document.getElementById("expand-button-0" + (i + 1))!;
const svgElement = button.querySelector("svg");
const useElement = svgElement?.querySelector("use");

button.addEventListener("click", () => {
if (text.style.height === "max-content") {
text.style.height = "1px";
button.innerHTML = "+";
useElement?.setAttribute("xlink:href", "/assets/icons.svg#plus");
} else {
text.style.height = "max-content";
button.innerHTML = "−";
useElement?.setAttribute("xlink:href", "/assets/icons.svg#minus");
}
});
});
Expand Down

0 comments on commit ca450bc

Please sign in to comment.