Skip to content

Commit c806586

Browse files
committed
add an example on how to add new attributes to elements
1 parent 1195fa8 commit c806586

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

js/jsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"compilerOptions": {
33
"strict": true,
4+
"checkJs": true,
45
"target": "ESNext",
56
"module": "ESNext",
67
"moduleResolution": "NodeNext",
78
"allowSyntheticDefaultImports": true,
89
"esModuleInterop": true,
910
"jsx": "preserve",
1011
"jsxImportSource": "pota",
11-
"types": ["vite/client", "pota"],
12+
"types": ["vite/client", "pota", "./types.ts"],
1213
"noEmit": true,
1314
"isolatedModules": true
1415
}

js/src/index.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Router } from 'pota/web'
33

44
import logo from './assets/logo.svg'
55
import styles from './index.module.css'
6+
import 'pota/plugin/clickOutside'
67

78
function App() {
89
return (
@@ -11,7 +12,13 @@ function App() {
1112
<img src={logo} alt="logo" />
1213
</header>
1314
<p>
14-
<a alt="pota comes from potable" href="https://pota.quack.uy">
15+
<a
16+
clickOutside={(event, node) =>
17+
console.log('clickOutside demo', event, node)
18+
}
19+
title="pota comes from potable"
20+
href="https://pota.quack.uy"
21+
>
1522
https://pota.quack.uy
1623
</a>
1724
</p>

js/types.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { JSX } from 'pota/jsx-runtime'
2+
3+
declare module 'pota/jsx-runtime' {
4+
namespace JSX {
5+
/** Adds an attribute to all HTML elements */
6+
interface IntrinsicHTMLAttributes {
7+
clickOutside?: (event: Event, node: HTMLElement) => void
8+
}
9+
10+
/** Adds an attribute to all SVG elements */
11+
interface IntrinsicSVGAttributes {
12+
clickOutside?: (event: Event, node: HTMLElement) => void
13+
}
14+
15+
/** Adds an attribute to all MathML elements */
16+
interface IntrinsicMathMLAttributes {
17+
clickOutside?: (event: Event, node: HTMLElement) => void
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)