Skip to content

Commit a8b9cdf

Browse files
Merge pull request #41 from WebDevSimplified/css-calc-size
Add CSS Calc Article And Fix Slots
2 parents 7793381 + b8f46de commit a8b9cdf

File tree

13 files changed

+236
-73
lines changed

13 files changed

+236
-73
lines changed

.github/workflows/scheduleMerge.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ jobs:
1010
merge_schedule:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: gr2m/merge-schedule-action@v1
13+
- uses: gr2m/merge-schedule-action@v2
1414
with:
15-
time_zone: "America/Chicago"
15+
time_zone: "America/Chicago"
1616
env:
17-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
const {
3+
isCalcSize,
4+
body = "Lorem ipsum dolor sit amet consectetur adipisicing elit. Impedit in libero odit, dignissimos corrupti dolore voluptatibus praesentium sapiente corporis nam aspernatur consequuntur reprehenderit dolorem voluptate! Soluta, perferendis nam quibusdam sunt culpa eius id voluptate iste dolor eaque odio, recusandae velit nemo corrupti reprehenderit? Ex deleniti deserunt fugiat velit repellat corporis. Ex deleniti deserunt fugiat velit repellat corporis.",
5+
header = isCalcSize ? "Using calc-size()" : "Normal expansion",
6+
buttonText = isCalcSize ? "Expand calc-size()" : "Expand normal",
7+
} = Astro.props
8+
---
9+
10+
<div class="container">
11+
<button data-css-calc-accordion-btn class="btn">{buttonText}</button>
12+
<div class="card">
13+
<div class="card-header">{header}</div>
14+
<div class={`card-body ${isCalcSize ? "calc-size" : ""}`}>{body}</div>
15+
</div>
16+
</div>
17+
18+
<style>
19+
.btn {
20+
border: none;
21+
border-radius: 0.25em;
22+
padding: 0.5em 0.75em;
23+
font-size: inherit;
24+
background: var(--theme-purple);
25+
cursor: pointer;
26+
}
27+
28+
.btn:hover {
29+
background: var(--theme-purple-hover);
30+
}
31+
32+
.card {
33+
border: 1px solid var(--theme-text);
34+
border-radius: 0.5rem;
35+
margin-top: 1rem;
36+
padding: 1rem;
37+
}
38+
39+
.card-body {
40+
height: 0;
41+
font-size: 0.85rem;
42+
overflow: hidden;
43+
transition: height 0.3s ease-in-out;
44+
}
45+
46+
.card-body.expand {
47+
height: auto;
48+
}
49+
50+
.card-body.expand.calc-size {
51+
height: var(--height);
52+
height: calc-size(auto);
53+
}
54+
</style>
55+
56+
<script>
57+
const buttons = document.querySelectorAll("[data-css-calc-accordion-btn]")
58+
59+
buttons.forEach(button => {
60+
button.addEventListener("click", () => {
61+
const body = button.closest(".container").querySelector(".card-body")
62+
63+
if (body.classList.contains("calc-size")) {
64+
;(body as HTMLElement).style.setProperty(
65+
"--height",
66+
body.scrollHeight + "px"
67+
)
68+
}
69+
70+
body.classList.toggle("expand")
71+
})
72+
})
73+
74+
window.addEventListener("resize", () => {
75+
const bodies = document.querySelectorAll(".card-body.calc-size")
76+
77+
bodies.forEach(body => {
78+
;(body as HTMLElement).style.setProperty("--height", "auto")
79+
;(body as HTMLElement).style.setProperty(
80+
"--height",
81+
body.scrollHeight + "px"
82+
)
83+
})
84+
})
85+
</script>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
import CalcSizeAccordion from "./CalcSizeAccordion.astro"
3+
---
4+
5+
<div class="container">
6+
<CalcSizeAccordion />
7+
<CalcSizeAccordion isCalcSize />
8+
</div>
9+
10+
<style>
11+
.container {
12+
display: grid;
13+
grid-template-columns: 1fr 1fr;
14+
grid-gap: 2rem;
15+
padding: 1rem 0;
16+
17+
@media (max-width: 40em) {
18+
grid-template-columns: 1fr;
19+
grid-gap: 1rem;
20+
}
21+
}
22+
</style>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
<p class="first-letter">
1+
<div class="first-letter">
22
<slot />
3-
</p>
3+
</div>
44

55
<style>
66
.first-letter::first-letter {
77
font-size: 2em;
88
color: var(--theme-red);
99
font-weight: bold;
1010
}
11-
</style>
11+
</style>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<p class="first-line">
1+
<div class="first-line">
22
<slot />
3-
</p>
3+
</div>
44

55
<style>
66
.first-line::first-line {
77
color: var(--theme-red);
88
}
9-
</style>
9+
</style>
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<p class="selection">
1+
<div class="selection" data-pseudo-element-page>
22
<slot />
3-
</p>
3+
</div>
44

5-
<style>
6-
.selection::selection {
5+
<style is:global>
6+
[data-pseudo-element-page].selection ::selection {
77
background-color: var(--theme-red);
88
color: white;
99
}
10-
</style>
10+
</style>

src/blogComponents/cssPseudoElements/firstLetter.astro

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/blogComponents/cssPseudoElements/firstLine.astro

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/blogComponents/cssPseudoElements/selection.astro

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/blogComponents/cssPseudoElements/tooltip.astro

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)