Skip to content

Commit

Permalink
Merge pull request #135 from break-stuff/react-wrappers-fix-base-types
Browse files Browse the repository at this point in the history
React wrappers fix base types
  • Loading branch information
break-stuff authored Jun 25, 2024
2 parents 67701e5 + dc1e26e commit d67d172
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 9 deletions.
3 changes: 1 addition & 2 deletions demo/lit-app/custom-elements-manifest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ export default {
}),
customElementReactWrapperPlugin({
outdir: "./dist/react",
modulePath: (className, tagName) => `../${tagName}/${tagName}.js`,
reactProps: true,
modulePath: (className, tagName) => `../${tagName}/${className}.js`,
scopedTags: true,
ssrSafe: true
}),
Expand Down
2 changes: 2 additions & 0 deletions demo/lit-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"custom-elements-manifest-deprecator": "*",
"eslint": "^9.3.0",
"eslint-plugin-custom-element": "*",
"react": "^18.3.1",
"react-dom": "18.3.1",
"typescript": "^5.0.2",
"vite": "^4.4.5"
},
Expand Down
6 changes: 4 additions & 2 deletions package-lock.json

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

5 changes: 5 additions & 0 deletions packages/react-wrappers/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## 1.6.2

- Fix redundant base types
- Add docs to `ScopeProvider` component

## 1.6.1

- Fixed null scope error
Expand Down
2 changes: 1 addition & 1 deletion packages/react-wrappers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "custom-element-react-wrappers",
"version": "1.6.1",
"version": "1.6.2",
"description": "A tool for generating react-compatible wrappers for custom elements",
"main": "index.js",
"module": "index.js",
Expand Down
2 changes: 2 additions & 0 deletions packages/react-wrappers/src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,5 @@ export const BASE_PROPS = [
"onFocus",
"onBlur",
];

export const NON_ATTR_BASE_PROPS = ["exportparts", "key", "part", "ref"];
14 changes: 12 additions & 2 deletions packages/react-wrappers/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,18 @@ export function ScopeProvider({ prefix, suffix, children }) {
`;

const scopeProviderTypes = `
export type ScopeProps = { prefix?: string, suffix?: string, children?: ReactNode }
export type ScopeProps = {
/** Adds a prefix to the custom element tag name */
prefix?: string,
/** Adds a prefix to the custom element tag name */
suffix?: string,
children?: ReactNode
};
/**
* Provides a mechanism to add a custom prefix or suffix to to child components.
* This prevents tag name collisions with components from different versions of the same library.
*/
export function ScopeProvider(props: ScopeProps): JSX.Element;
`;

Expand Down
4 changes: 2 additions & 2 deletions packages/react-wrappers/src/wrapper-generator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BASE_PROPS, MAPPED_PROPS } from "./global.js";
import { BASE_PROPS, MAPPED_PROPS, NON_ATTR_BASE_PROPS } from "./global.js";
import {
EventName,
MappedAttribute,
Expand Down Expand Up @@ -440,7 +440,7 @@ function getExtendedProps() {
return config.reactProps === true
? "extends React.AllHTMLAttributes<HTMLElement>"
: `extends Pick<React.AllHTMLAttributes<HTMLElement>, ${[
...BASE_PROPS,
...BASE_PROPS.filter(x => !NON_ATTR_BASE_PROPS.includes(x)),
...(config.reactProps || []),
]
.map((x) => `'${x}'`)
Expand Down

0 comments on commit d67d172

Please sign in to comment.