Skip to content

Commit

Permalink
Updated Types
Browse files Browse the repository at this point in the history
  • Loading branch information
hkbertoson committed Oct 22, 2024
1 parent 0bac5e9 commit db4602b
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 85 deletions.
4 changes: 2 additions & 2 deletions package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"./schema": "./src/schema.ts",
"./client": "./lib/client.ts",
"./server": "./lib/server.ts",
"./components/TurnstileWidget": "./lib/components/TurnstileWidget",
"./components/TurnstileForm": "./lib/components/TurnstileForm"
"./components/TurnstileWidget": "./lib/components/TurnstileWidget.astro",
"./components/TurnstileForm": "./lib/components/TurnstileForm.astro"
},
"scripts": {},
"type": "module",
Expand Down
4 changes: 2 additions & 2 deletions package/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ export const astroTurnstile = defineIntegration({
"virtual:astro-turnstile/config": `export default ${JSON.stringify(
options,
)}`,
"astro-turnstile:components/TurnstileWidget": `export * from '${name}/components';`,
"astro-turnstile:components/TurnstileForm": `export * from '${name}/components';`,
"astro-turnstile:components/TurnstileWidget": `import Widget from '${name}/components/TurnstileWidget'; export default Widget;`,
"astro-turnstile:components/TurnstileForm": `import Form from '${name}/components/TurnstileForm'; export default Form;`,
},
});

Expand Down
78 changes: 39 additions & 39 deletions package/src/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,45 +26,45 @@ components.addSingleLineNote(
);

// Add the module to the file
components.addModule("astro-turnstile:components", {
namedExports: [
{
name: "TurnstileWidget",
typeDef: `typeof import('${name}/components/TurnstileWidget.astro').TurnstileWidget`,
multiLineDescription: [
"# Turnstile Verification Widget",
"@description An [Astro](https://astro.build) component that is used to render a Turnstile verification widget. This widget is used to verify that a user is human.",
`@param {"auto"|"light"|"dark"} theme - The theme for the widget. (default: "auto")`,
`@param {"normal"|"compact"|"flexible"} size - The size for the widget. (default: "normal")`,
`@param {string} margin - The margin for the widget element. (default: '0.5rem')`,
"@example",
"```tsx",
"---",
`import { TurnstileWidget } from '${name}:components';`,
"---",
"<form action='/your/api/endpoint' method='POST'>",
"<TurnstileWidget theme='light' size='compact' margin='1rem' />",
"<button type='submit'>Submit</button>",
"</form>",
],
},
{
name: "TurnstileForm",
typeDef: `typeof import('${name}/components/TurnstileForm.astro').TurnstileForm`,
multiLineDescription: [
"# Turnstile Verification Form",
"@description An [Astro](https://astro.build) component that is used to render a Turnstile verification form. This form includes a Turnstile verification widget and a submit button.",
"@slot default - Any unassigned content will be placed here.",
"@slot header - `<div slot='header'>...</div>`",
"@slot buttons - `<div slot='buttons'>...</div>`",
"@slot footer - `<div slot='footer'>...</div>`",
`@param {"auto"|"light"|"dark"} theme - The theme for the widget. (default: "auto")`,
`@param {"normal"|"compact"|"flexible"} size - The size for the widget. (default: "normal")`,
`@param {string} margin - The margin for the widget element. (default: '0.5rem')`,
`@param {"multipart/form-data"|"application/x-www-form-urlencoded"|"submit"} enctype - The form enctype. (default: 'application/x-www-form-urlencoded')`,
],
},
],
components.addModule("astro-turnstile:components/TurnstileWidget", {
defaultExport: {
typeDef: `typeof import('${name}/components/TurnstileWidget.astro').TurnstileWidget`,
multiLineDescription: [
"# Turnstile Verification Widget",
"@description An [Astro](https://astro.build) component that is used to render a Turnstile verification widget. This widget is used to verify that a user is human.",
`@param {"auto"|"light"|"dark"} theme - The theme for the widget. (default: "auto")`,
`@param {"normal"|"compact"|"flexible"} size - The size for the widget. (default: "normal")`,
`@param {string} margin - The margin for the widget element. (default: '0.5rem')`,
"@example",
"```tsx",
"---",
`import TurnstileWidget from '${name}:components/TurnstileWidget';`,
"---",
"<form action='/your/api/endpoint' method='POST'>",
"<TurnstileWidget theme='light' size='compact' margin='1rem' />",
"<button type='submit'>Submit</button>",
"</form>",
],
},
});

// Add the module to the file
components.addModule("astro-turnstile:components/TurnstileForm", {
defaultExport: {
typeDef: `typeof import('${name}/components/TurnstileForm.astro').TurnstileForm`,
multiLineDescription: [
"# Turnstile Verification Form",
"@description An [Astro](https://astro.build) component that is used to render a Turnstile verification form. This form includes a Turnstile verification widget and a submit button.",
"@slot default - Any unassigned content will be placed here.",
"@slot header - `<div slot='header'>...</div>`",
"@slot buttons - `<div slot='buttons'>...</div>`",
"@slot footer - `<div slot='footer'>...</div>`",
`@param {"auto"|"light"|"dark"} theme - The theme for the widget. (default: "auto")`,
`@param {"normal"|"compact"|"flexible"} size - The size for the widget. (default: "normal")`,
`@param {string} margin - The margin for the widget element. (default: '0.5rem')`,
`@param {"multipart/form-data"|"application/x-www-form-urlencoded"|"submit"} enctype - The form enctype. (default: 'application/x-www-form-urlencoded')`,
],
},
});

// Export the DTS files
Expand Down
95 changes: 53 additions & 42 deletions playground/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,57 +1,68 @@
---
import TurnstileForm from "astro-turnstile/components/TurnstileForm";
import Layout from "../layouts/Layout.astro";
import TurnstileForm from 'astro-turnstile/components/TurnstileForm';
import Layout from '../layouts/Layout.astro';
import TurnstileWidget from 'astro-turnstile:components/TurnstileWidget';
if (Astro.request.method === "POST") {
console.log("success");
if (Astro.request.method === 'POST') {
console.log('success');
}
---

<Layout title="Welcome to Astro.">
<main>
<form>
<label>
Username:
<input type="text" name="username" required />
</label>
<button type="submit">Submit</button>
<TurnstileWidget />
</form>
<!-- <main>
<TurnstileForm action="/" method={'POST'} enctype={'submit'}>
<label>
Username:
<input type="text" name="username" required />
</label>
</TurnstileForm>
</main> -->
</main>
</Layout>

<style is:global>
main {
max-width: 600px;
margin: 0 auto;
padding: 20px;
}

form {
display: flex;
flex-direction: column;
}

label {
margin-bottom: 10px;
}

input[type='text'] {
padding: 8px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 4px;
}

button {
padding: 10px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}

button:hover {
background-color: #0056b3;
}
</style>
<style is:global>
main {
max-width: 600px;
margin: 0 auto;
padding: 20px;
}

form {
display: flex;
flex-direction: column;
}

label {
margin-bottom: 10px;
}

input[type='text'] {
padding: 8px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 4px;
}

button {
padding: 10px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}

button:hover {
background-color: #0056b3;
}
</style>
</Layout>

0 comments on commit db4602b

Please sign in to comment.