Skip to content

Commit

Permalink
refactor: moved all tag props typing to the JSXTE global namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
ncpa0cpl committed Sep 2, 2023
1 parent f75712b commit 38485c7
Show file tree
Hide file tree
Showing 50 changed files with 847 additions and 559 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ A JSX based html templating engine for browsers or Node environments.
7. [Express JS View Engine](#express-js-view-engine)
8. [Rendering to a string tag template](#rendering-to-a-string-tag-template)
1. [Example](#example-2)
9. [Monkey-Patching type definitions](#monkey-patching-type-definitions)
10. [Contributing](#contributing)

## Getting started

Expand Down Expand Up @@ -399,6 +401,52 @@ const result = renderToStringTemplateTag(
);
```

## Monkey-Patching type definitions

It is possible to monkey-patch type definition of all HTML tags and add new attributes to them.

#### Extend prop types of a specific tag

The following adds a new attribute to the `<div />` tag - `data-my-attr`:

```tsx
declare global {
namespace JSXTE {
interface DivTagProps {
"data-my-attr"?: string;
}
}
}
```

#### Extends prop of all html tags

The following adds a new attribute to all html tags - `hx-post`:

```tsx
declare global {
namespace JSXTE {
interface BaseHTMLTagProps {
"hx-post"?: string;
}
}
}
```

#### Change the accepted type for a specific attribute

The following adds a `Function` type to the `onclick` attribute of all html tags:

```tsx
declare global {
namespace JSXTE {
interface AttributeAcceptedTypes {
onclick?: Function;
}
}
}
```

## Contributing

If you want to contribute please See [CONTRIBUTING.md](./CONTRIBUTING.md)
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import "./utilities/array-flat-polyfill";

export * from "./express/index";
export * from "./jsx/jsx.types";
export * from "./jsx/prop-types/index";

export {
Interpolate,
Expand Down
Loading

0 comments on commit 38485c7

Please sign in to comment.