1.0.0 • Published 5 months ago
@cognam/app-button v1.0.0
AppButton Component
A reusable Material-UI Button component wrapper for React applications.
Installation
npm install @cognam/app-buttonUsage
import AppButton from '@cognam/app-button';
// or
import { AppButton } from '@cognam/app-button';
function MyComponent() {
return (
<AppButton
variant="contained"
color="primary"
onClick={() => console.log('Clicked!')}
>
Click Me
</AppButton>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| size | string | - | Button size (small, medium, large) |
| style | object | - | Custom styles |
| variant | string | - | Button variant (text, outlined, contained) |
| className | string | - | CSS class name |
| color | string | "primary" | Button color |
| disabled | boolean | false | Whether button is disabled |
| onClick | function | - | Click handler |
| children | node | - | Button content |
Requirements
- React 17+ or 18+
- Material-UI 5+
- Emotion (React and Styled)
## Step 7: Build and Publish
1. **Install dependencies:**
```bash
npm install- Build the package:
npm run build- Test locally (optional):
npm linkThen in your test project:
npm link @cognam/app-button- Publish to NPM:
npm login
npm publish --access publicStep 8: Using in Your New Project
In your new project, install the package:
npm install @cognam/app-buttonThen use it:
import AppButton from '@cognam/app-button';
function MyApp() {
return (
<div>
<AppButton variant="contained" color="primary">
My Button
</AppButton>
</div>
);
}Key Benefits of This Approach:
- Peer Dependencies: Material-UI and React are peer dependencies, so they won't be bundled
- Tree Shaking: ESM build supports tree shaking
- Multiple Formats: Both CommonJS and ESM builds
- Optimized: Direct imports for Material-UI components
- Reusable: Can be used across multiple projects
This setup will create a professional NPM package that you can reuse across all your projects while maintaining the same Material-UI and React versions.
1.0.0
5 months ago