Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modal component #35

Merged
merged 14 commits into from
Mar 18, 2024
2 changes: 2 additions & 0 deletions .github/workflows/firebase-hosting-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ jobs:
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_MMP_SITE_B1C9B }}'
channelId: live
projectId: mmp-site-b1c9b
env:
FIREBASE_CLI_EXPERIMENTS: webframeworks
2 changes: 2 additions & 0 deletions .github/workflows/firebase-hosting-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ jobs:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_MMP_SITE_B1C9B }}'
projectId: mmp-site-b1c9b
env:
FIREBASE_CLI_EXPERIMENTS: webframeworks
hetd54 marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ pnpm-debug.log*
# macOS-specific files
.DS_Store
.idea
*.log
*.log
*.cache
13 changes: 7 additions & 6 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { defineConfig } from 'astro/config';
import mdx from '@astrojs/mdx';
import sitemap from '@astrojs/sitemap';

import { defineConfig } from "astro/config";
import mdx from "@astrojs/mdx";
import sitemap from "@astrojs/sitemap";
import tailwind from "@astrojs/tailwind";

import react from "@astrojs/react";

// https://astro.build/config
export default defineConfig({
site: 'https://example.com',
integrations: [mdx(), sitemap(), tailwind()]
site: "https://example.com",
integrations: [mdx(), sitemap(), tailwind(), react()]
});
2 changes: 1 addition & 1 deletion firebase.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"hosting": {
"public": "public",
"source": ".",
"ignore": [
"firebase.json",
"**/.*",
Expand Down
142 changes: 139 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@
"dependencies": {
"@astrojs/check": "^0.5.3",
"@astrojs/mdx": "^2.1.1",
"@astrojs/react": "^3.1.0",
"@astrojs/rss": "^4.0.5",
"@astrojs/sitemap": "^3.0.5",
"@astrojs/tailwind": "^5.1.0",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-icons": "^1.3.0",
"@staticcms/core": "^4.1.2",
"@staticcms/proxy-server": "^4.0.4",
"@types/react": "^18.2.64",
"@types/react-dom": "^18.2.21",
Comment on lines +23 to +24
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be dev dependencies? Or does astro want this stuff installed as a regular dependency?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added these using "astro add" -- "Astro includes an astro add command to automate the setup of official integrations. "

They seem to want them as dependencies, although we could manually install them as dev dep if needed?

The docs: https://docs.astro.build/en/guides/integrations-guide/react/

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not fight astro then. I guess if astro is building everything keeping things as dependencies doesn't really matter

"astro": "^4.3.6",
"i": "^0.3.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tailwindcss": "^3.4.1",
"typescript": "^5.3.3"
},
Expand Down
20 changes: 20 additions & 0 deletions src/components/CustomInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from "react"

interface CustomInputProps {
label: string
placeholder: string
}

export const CustomInput: React.FC<CustomInputProps> = ({ label, placeholder }) => {
return (
<>
<input
name={label}
id={label}
className="text-gray-400 text-sm font-medium outline-none border-b-2 py-2 w-full my-4 mx-2"
placeholder={placeholder}
required
/>
</>
)
}
19 changes: 19 additions & 0 deletions src/components/CustomTextarea.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react"

interface CustomTextareaProps {
label: string
placeholder: string
}

export const CustomTextarea: React.FC<CustomTextareaProps> = ({ label, placeholder }) => {
return (
<>
<textarea
rows={4}
id={label}
className="text-gray-400 text-sm font-medium outline-none border-b-2 py-2 w-full my-4 mx-2"
placeholder={placeholder}
/>
</>
)
}
59 changes: 59 additions & 0 deletions src/components/DownloadModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from "react"
import * as Dialog from "@radix-ui/react-dialog"
import { Cross2Icon, DownloadIcon, PlusIcon } from "@radix-ui/react-icons"
import { CustomInput } from "./CustomInput.tsx"
import { CustomTextarea } from "./CustomTextarea.tsx"

const DownloadModal = () => {
const [isOpen, setIsOpen] = React.useState(false)

return (
<Dialog.Root open={isOpen} onOpenChange={setIsOpen}>
<Dialog.Trigger asChild>
hetd54 marked this conversation as resolved.
Show resolved Hide resolved
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asChild is crazy!

<button className="sm:inline-flex items-center justify-center w-8 h-8 rounded-lg text-sm text-gray-500 hover:bg-gray-100 focus:outline-none focus:ring-4 focus:ring-gray-200">
<DownloadIcon />
<span className="sr-only">Download data</span>
</button>
</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Overlay
className="fixed top-0 left-0 right-0 bottom-0 bg-gray-500 bg-opacity-75 transition-opacity z-10 w-screen overflow-y-auto"
onClick={() => setIsOpen(false)}
/>
<Dialog.Overlay className="fixed top-0 left-0 right-0 bottom-0 grid place-items-center z-10 w-screen overflow-y-auto">
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need the double overlay? Why are there two overlay siblings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to have a scrollable overlay, radix recommends moving the modal content within the overlay. I still wanted to be able to click on the overlay to be able to close the modal, which is where the first one on line 19 comes in.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and you can't use the onClick handler on the overlay on 23?

<Dialog.Content className="rounded-lg text-left shadow-xl max-h-fit transition-all bg-white px-4 pb-4 pt-5 sm:p-6 sm:pb-4 sm:my-8 sm:w-full sm:max-w-lg">
<div className="flex justify-end">
<Dialog.Close className="text-gray-400 bg-transparent rounded-lg text-sm w-8 h-8 inline-flex justify-center items-center hover:bg-gray-200 hover:text-gray-900">
<Cross2Icon />
<span className="sr-only">Close</span>
</Dialog.Close>
</div>
<Dialog.Title>Download Data</Dialog.Title>
<form className="p-4 md:p-5">
<div className="flex flex-col justify-center mb-4">
<CustomInput label={"name"} placeholder={"Your name"} />
<CustomInput label={"institution"} placeholder={"Your institution"} />
<CustomInput label={"email"} placeholder={"Your email"} />
<CustomTextarea label={"description"} placeholder={"Why you need this file"} />
</div>
<div className="flex flex-row gap-2">
<button className="flex items-center gap-2 rounded-lg px-5 py-2.5 bg-black text-white text-sm text-center font-medium hover:bg-gray-500 focus:ring-4 focus:outline-none focus:ring-gray-500">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last thing, and this doesn't matter a lot until we have designs, but global styles like button styles should go in a global stylesheet so you're not repeating styles.

<PlusIcon />
<span className="pt-1">Validate Email</span>
</button>
<button
type="submit"
disabled
className="flex items-center gap-2 rounded-lg px-5 py-2.5 bg-black text-white text-sm text-center font-medium hover:bg-gray-500 focus:ring-4 focus:outline-none focus:ring-gray-500 disabled:bg-gray-400"
>
Download File
</button>
</div>
</form>
</Dialog.Content>
</Dialog.Overlay>
</Dialog.Portal>
</Dialog.Root>
)
}
export default DownloadModal
Loading
Loading