Skip to content

Commit

Permalink
refactor: build button component more like existing components
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbert committed Aug 7, 2023
1 parent 94072a3 commit 6b9081f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/components-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@babel/preset-react": "7.18.6",
"@babel/preset-typescript": "7.21.5",
"@babel/runtime": "7.21.5",
"@example/components-css": "workspace:*",
"@rollup/plugin-babel": "6.0.3",
"@rollup/plugin-commonjs": "24.1.0",
"@rollup/plugin-node-resolve": "15.0.2",
Expand Down
6 changes: 5 additions & 1 deletion packages/components-react/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { readFileSync } from "fs";
import filesize from "rollup-plugin-filesize";
import nodeExternal from "rollup-plugin-node-externals";
import nodePolyfills from "rollup-plugin-node-polyfills";
import postcss from "rollup-plugin-postcss";
import peerDepsExternal from "rollup-plugin-peer-deps-external";
import typescript from "rollup-plugin-typescript2";

Expand Down Expand Up @@ -46,7 +47,10 @@ export default [
include: /node_modules/,
}),
nodePolyfills(),
// del({ targets: ['dist/*', 'pages/*'] }),
postcss({
extensions: [".css", ".scss"],
minimize: true,
}),
typescript({ includeDependencies: false }),
babel({
presets: ["@babel/preset-react"],
Expand Down
13 changes: 10 additions & 3 deletions packages/components-react/src/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { ForwardedRef, forwardRef, PropsWithChildren } from 'react';
import clsx from 'clsx';
import { ButtonHTMLAttributes, ForwardedRef, forwardRef, PropsWithChildren } from 'react';
import '@example/components-css/button/index.scss';

export type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement>;

export const Button = forwardRef(
({ children, className, ...restProps }: PropsWithChildren<any>, ref: ForwardedRef<HTMLButtonElement>) => {
(
{ children, className, type, ...restProps }: PropsWithChildren<ButtonProps>,
ref: ForwardedRef<HTMLButtonElement>,
) => {
return (
<button ref={ref} className={className} type={'button'} {...restProps}>
<button ref={ref} className={clsx('example-button', className)} type={type ?? 'button'} {...restProps}>
{children}
</button>
);
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit 6b9081f

Please sign in to comment.