Skip to content

Commit 6694f52

Browse files
author
ComputelessComputer
committed
add contact
1 parent 64ce93c commit 6694f52

2 files changed

Lines changed: 91 additions & 12 deletions

File tree

src/pages/cal.astro

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
const url = new URL("https://cal.com/john.jeong/yo");
3+
const name = Astro.url.searchParams.get("name");
4+
const email = Astro.url.searchParams.get("email");
5+
6+
if (name) url.searchParams.set("name", name);
7+
if (email) url.searchParams.set("email", email);
8+
9+
return Astro.redirect(url.toString());
10+
---

src/pages/index.astro

Lines changed: 81 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ import Gallery from "../components/Gallery.astro";
2727
</a>
2828
</div>
2929

30-
<a href="/cal" class="contact-btn">Contact</a>
30+
<div class="contact-section">
31+
<p>
32+
hey i'm <input type="text" id="contact-name" placeholder="steve jobs" size="1" /> and my email is <input type="email" id="contact-email" placeholder="sjobs@apple.com" size="1" />. i'd love to <a href="/cal" id="chat-btn" class="btn">chat</a> !
33+
</p>
34+
</div>
3135

3236
<Gallery />
3337
</Base>
@@ -45,17 +49,82 @@ import Gallery from "../components/Gallery.astro";
4549
.social a:hover {
4650
color: #1a1a1a;
4751
}
48-
.contact-btn {
49-
display: inline-block;
50-
margin-top: 1rem;
51-
padding: 0.5rem 1rem;
52-
background: #1a1a1a;
53-
color: #fff;
54-
border-radius: 4px;
55-
text-decoration: none;
56-
transition: background 0.2s;
52+
.contact-section {
53+
margin-top: 1.5rem;
54+
padding-top: 1.5rem;
55+
border-top: 1px solid #eee;
56+
}
57+
.contact-section p {
58+
margin: 0;
59+
line-height: 2;
60+
}
61+
.contact-section input {
62+
border: none;
63+
border-bottom: 1px solid #ccc;
64+
padding: 0;
65+
font-size: inherit;
66+
font-family: inherit;
67+
font-weight: 500;
68+
background: transparent;
69+
}
70+
.contact-section .btn {
71+
padding: 0.1rem 0.35rem;
72+
font-size: 0.85rem;
73+
vertical-align: middle;
74+
line-height: 1.2;
75+
position: relative;
76+
top: -2px;
5777
}
58-
.contact-btn:hover {
59-
background: #333;
78+
.contact-section input:focus {
79+
outline: none;
80+
}
81+
.contact-section input::placeholder {
82+
color: #999;
6083
}
6184
</style>
85+
86+
<script>
87+
const nameInput = document.getElementById('contact-name') as HTMLInputElement;
88+
const emailInput = document.getElementById('contact-email') as HTMLInputElement;
89+
const chatBtn = document.getElementById('chat-btn') as HTMLAnchorElement;
90+
91+
function updateChatLink() {
92+
const params = new URLSearchParams();
93+
if (nameInput.value) params.set('name', nameInput.value);
94+
if (emailInput.value) params.set('email', emailInput.value);
95+
const query = params.toString();
96+
chatBtn.href = '/cal' + (query ? '?' + query : '');
97+
}
98+
99+
function measureText(text: string, font: string) {
100+
const span = document.createElement('span');
101+
span.style.visibility = 'hidden';
102+
span.style.position = 'absolute';
103+
span.style.whiteSpace = 'pre';
104+
span.style.font = font;
105+
span.textContent = text;
106+
document.body.appendChild(span);
107+
const width = span.offsetWidth;
108+
document.body.removeChild(span);
109+
return width;
110+
}
111+
112+
function resizeInput(input: HTMLInputElement) {
113+
const font = getComputedStyle(input).font;
114+
const placeholderWidth = measureText(input.placeholder, font);
115+
const valueWidth = input.value ? measureText(input.value, font) : 0;
116+
input.style.width = Math.max(placeholderWidth, valueWidth) + 2 + 'px';
117+
}
118+
119+
function handleInput(input: HTMLInputElement) {
120+
resizeInput(input);
121+
updateChatLink();
122+
}
123+
124+
nameInput?.addEventListener('input', () => handleInput(nameInput));
125+
emailInput?.addEventListener('input', () => handleInput(emailInput));
126+
127+
// Initial resize
128+
resizeInput(nameInput);
129+
resizeInput(emailInput);
130+
</script>

0 commit comments

Comments
 (0)