Skip to content

Commit 1883de8

Browse files
committed
feat: add date picker into modal form
1 parent 20360d7 commit 1883de8

File tree

4 files changed

+96
-2
lines changed

4 files changed

+96
-2
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
import type { HTMLAttributes } from "astro/types";
3+
import classnames from "classnames";
4+
5+
type Props = {
6+
labelProps?: HTMLAttributes<"label">;
7+
label?: string;
8+
errorText?: string;
9+
classNames?: string;
10+
onDark?: boolean;
11+
inputProps: HTMLAttributes<"input"> & { type?: "date" | string };
12+
};
13+
14+
const { classNames, labelProps, label = "", onDark } = Astro.props;
15+
---
16+
17+
<div
18+
data-field
19+
class={classnames(
20+
`group relative z-[2] flex min-h-[74px] overflow-hidden pt-6
21+
rounded-[6px]
22+
after:absolute after:top-6 after:ml-[1px] after:h-[46px]
23+
after:w-[calc(100%-2px)] after:rounded-[6px] after:bg-[#F6FCFD]`,
24+
classNames,
25+
)}
26+
>
27+
<input
28+
{...Astro.props.inputProps}
29+
type="date"
30+
id="date-picker"
31+
class="peer/input text-transparent relative z-[4] ml-[1px] h-[46px] w-[calc(100%-2px)]
32+
rounded-[6px] border border-transparent bg-transparent px-4 py-2.5
33+
focus:border-transparent focus:outline-0 focus:ring-0
34+
focus:text-secondary valid:text-secondary"
35+
/>
36+
37+
<label
38+
{...labelProps}
39+
class={classnames(
40+
`
41+
text-xs
42+
min-[375px]:text-sm
43+
absolute
44+
top-0
45+
translate-y-[37px]
46+
transition-transform
47+
translate-x-[17px]
48+
z-[3]
49+
peer-focus/input:translate-y-0
50+
peer-focus/input:translate-x-0
51+
peer-valid/input:translate-0
52+
`,
53+
{ "text-secondary": !onDark, "text-neutral-50": onDark },
54+
)}
55+
>
56+
<span>{label}</span>
57+
</label>
58+
59+
<div
60+
class={classnames(
61+
`
62+
absolute top-[23px] flex h-[48px] w-full items-center justify-center overflow-hidden rounded-[6px]
63+
bg-[#424c6d50]
64+
after:h-5 after:w-5 after:scale-0 after:rounded-full after:transition-transform after:duration-[400ms]
65+
peer-focus/input:after:scale-[25]
66+
peer-[&:not(:focus):invalid]/input:data-[has-value=true]:bg-red-500
67+
`,
68+
{ "after:bg-[#67a807]": !onDark, "after:bg-neutral-50": onDark },
69+
)}
70+
>
71+
</div>
72+
</div>
73+
74+
<script>
75+
76+
</script>

apps/website/src/components/Field.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const { classNames, labelProps, label, errorText, onDark } = Astro.props;
121121
<div
122122
class={classnames(
123123
`absolute
124-
w-full
124+
w-full
125125
rounded-[6px]
126126
bg-[#424c6d50]
127127
flex

apps/website/src/components/GetYourPlanForm.astro

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const enableModalForm = import.meta.env.PUBLIC_ENABLE_MODAL_FORM === "true";
1919
onDark
2020
inputProps={{
2121
name: "form-full-name",
22+
id: "form-full-name",
2223
maxlength: "100",
2324
placeholder: formContent.frontmatter.fullname,
2425
required: true,
@@ -36,6 +37,7 @@ const enableModalForm = import.meta.env.PUBLIC_ENABLE_MODAL_FORM === "true";
3637
onDark
3738
inputProps={{
3839
name: "form-email",
40+
id: "form-email",
3941
maxlength: "100",
4042
placeholder: formContent.frontmatter.email,
4143
type: "email",
@@ -127,7 +129,7 @@ const enableModalForm = import.meta.env.PUBLIC_ENABLE_MODAL_FORM === "true";
127129
const modalFormLoader =
128130
modalFormSubmitBtn?.querySelector("#modal-form-loader");
129131

130-
const handleModalSoftDismiss = (e: PointerEvent) => {
132+
const handleModalSoftDismiss = (e: MouseEvent) => {
131133
if (!e.currentTarget) return;
132134

133135
const dialogElem = e.currentTarget as HTMLDialogElement;
@@ -181,6 +183,7 @@ const enableModalForm = import.meta.env.PUBLIC_ENABLE_MODAL_FORM === "true";
181183
const consent = formData.get("form-consent");
182184
const companyName = formData.get("form-company");
183185
const mainChallenge = formData.get("form-challenge");
186+
const startDate = formData.get("form-start-date");
184187

185188
if (!name || !email || !consent) {
186189
return;
@@ -202,6 +205,7 @@ const enableModalForm = import.meta.env.PUBLIC_ENABLE_MODAL_FORM === "true";
202205
hasConsent: consent ? true : false,
203206
companyName: companyName || "",
204207
mainChallenge: mainChallenge || "",
208+
startDate: startDate || "",
205209
}),
206210
},
207211
);

apps/website/src/components/GetYourPlanModal.astro

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Field from "./Field.astro";
33
import Modal from "./Modal.astro";
44
import * as formContent from "../content/contact/get-your-plan-form.md";
55
import Select from "./Select.astro";
6+
import DatePicker from "./DatePicker.astro";
67
---
78

89
<Modal id="get-plan-modal" classNames="w-[calc(100%-16px)] max-w-[500px]">
@@ -17,6 +18,7 @@ import Select from "./Select.astro";
1718
isTextArea={false}
1819
inputProps={{
1920
name: "form-company",
21+
id: "form-company",
2022
maxlength: "100",
2123
placeholder: formContent.frontmatter.companyName,
2224
}}
@@ -41,6 +43,17 @@ import Select from "./Select.astro";
4143
content: c,
4244
}))}
4345
/>
46+
<DatePicker
47+
label={formContent.frontmatter.expectedStartDate}
48+
inputProps={{
49+
id: "form-start-date",
50+
name: "form-start-date",
51+
min: new Date(Date.now()).toISOString().split("T")[0] }}
52+
labelProps={{
53+
for: "form-start-date",
54+
"aria-hidden": false,
55+
}}
56+
/>
4457
<button
4558
type="submit"
4659
id="modal-form-submit-button"
@@ -56,6 +69,7 @@ import Select from "./Select.astro";
5669
group-invalid/contact-us:focus-visible:bg-[#85a32a]
5770
group-invalid/contact-us:focus-visible:outline-transparent
5871
group-invalid/contact-us:focus:bg-[#85a32a]
72+
group-valid/contact-us:cursor-pointer
5973
bg-crocoder-yellow
6074
hover:bg-crocoder-yellow/90
6175
focus:bg-crocoder-yellow/90

0 commit comments

Comments
 (0)