Skip to content

Commit

Permalink
add web component button and update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
nhistory committed Dec 27, 2024
1 parent 8d37e8a commit 3bafd31
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</head>
<body>
<div id="root"></div>
<wc-button children="Click Me"></wc-button>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"prepare": "panda codegen"
},
"dependencies": {
"@r2wc/react-to-web-component": "^2.0.4",
"axe-playwright": "^2.0.3",
"chromatic": "^11.20.2",
"react": "^18.3.1",
Expand Down
14 changes: 13 additions & 1 deletion src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import r2wc from "@r2wc/react-to-web-component";
import { css } from "../../../styled-system/css";

export interface ButtonProps {
Expand Down Expand Up @@ -46,10 +47,21 @@ export const Button = ({
"&:disabled": { opacity: 0.5 },
})}
type={type}
onClick={onClick}
onClick={() => {
console.log("Button clicked!");
onClick?.();
}}
{...rest}
>
{children}
</button>
);
};

const WcButton = r2wc(Button, {
props: {
children: "string",
},
});

customElements.define("wc-button", WcButton);

0 comments on commit 3bafd31

Please sign in to comment.