@cpt-group/cpt-prime-react
v1.9.8
Published
PrimeReact components wrapped with CPT naming conventions and types for easy customization
Maintainers
Readme
CPT Prime React
PrimeReact components wrapped with CPT naming conventions and types for easy customization.
Overview
This package provides TypeScript React components that wrap PrimeReact components with CPT naming conventions. This abstraction layer allows you to:
- Use consistent CPT naming across your applications
- Easily customize components in the future without changing your codebase
- Maintain compatibility with PrimeReact's API while using your own component names
- Import themes easily with a single CSS import
Installation
Install the latest version:
npm install @cpt-group/cpt-prime-react
# or explicitly
npm install @cpt-group/cpt-prime-react@latestInstall a specific version:
npm install @cpt-group/[email protected]Install with version range:
npm install @cpt-group/cpt-prime-react@^1.9.7Peer Dependencies
This package requires the following peer dependencies:
Required:
react>= 16.8.0react-dom>= 16.8.0primereact>= 10.0.0
Optional (for specific components):
chart.js>= 4.0.0 (required forCPTChartcomponent)quill>= 2.0.0 (required forCPTEditorcomponent)lodash-es>= 4.17.0 (required byquill)
Make sure these are installed in your project:
# Required dependencies
npm install react react-dom primereact
# Optional dependencies (if using Chart or Editor components)
npm install chart.js quill lodash-esUsage
Basic Component Usage
Import components from the main package:
import { CPTButton, CPTInputText, CPTDataTable } from '@cpt-group/cpt-prime-react';
function MyComponent() {
return (
<div>
<CPTInputText value="Hello" onChange={(e) => console.log(e.target.value)} />
<CPTButton label="Click Me" />
<CPTDataTable value={data} />
</div>
);
}Component Props
All components maintain the same props interface as their PrimeReact counterparts, prefixed with CPT:
import { CPTButton, CPTButtonProps } from '@cpt-group/cpt-prime-react';
// CPTButtonProps is the same as ButtonProps from PrimeReact
const buttonProps: CPTButtonProps = {
label: 'Submit',
icon: 'pi pi-check',
onClick: () => console.log('Clicked'),
};TypeScript Types
All component props are exported with CPT prefix:
import type {
CPTButtonProps,
CPTInputTextProps,
CPTDataTableProps,
// ... all other component types
} from '@cpt-group/cpt-prime-react';Generic Components
Some components like CPTDataTable support generics:
import { CPTDataTable, CPTDataTableProps } from '@cpt-group/cpt-prime-react';
interface MyDataType {
id: number;
name: string;
}
const data: MyDataType[] = [{ id: 1, name: 'Item 1' }];
<CPTDataTable<MyDataType> value={data} />Components with Refs
Some components use forwardRef and can accept refs:
import { useRef } from 'react';
import { CPTToast } from '@cpt-group/cpt-prime-react';
import type { Toast } from 'primereact/toast';
function MyComponent() {
const toastRef = useRef<Toast>(null);
return (
<>
<CPTToast ref={toastRef} />
<button onClick={() => toastRef.current?.show({ severity: 'success', summary: 'Success' })}>
Show Toast
</button>
</>
);
}Theming
Available Themes
Available Themes
CPT PrimeReact provides two official themes:
| Theme | Description | Import Path |
|-------|-------------|-------------|
| cpt-light | Light theme with CPT styling | @cpt-group/cpt-prime-react/cpt/light-theme.css |
| cpt-dark | Dark theme with CPT styling | @cpt-group/cpt-prime-react/cpt/dark-theme.css |
Importing Themes
Important: Import the theme CSS ONCE at your application's root/layout level (not in individual components), just like standard PrimeReact themes. The theme will apply globally to all CPT components.
Import Paths
// CPT Light theme
import '@cpt-group/cpt-prime-react/cpt/light-theme.css';
// CPT Dark theme
import '@cpt-group/cpt-prime-react/cpt/dark-theme.css';Where to Import
React (Create React App / Vite):
// src/index.tsx or src/main.tsx
import '@cpt-group/cpt-prime-react/cpt/light-theme.css';
import { createRoot } from 'react-dom/client';
import App from './App';
createRoot(document.getElementById('root')!).render(<App />);Next.js:
// app/layout.tsx (App Router) or pages/_app.tsx (Pages Router)
import '@cpt-group/cpt-prime-react/cpt/light-theme.css';
import type { Metadata } from 'next';
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}React Router / Other Frameworks:
// Your root App component or layout component
import '@cpt-group/cpt-prime-react/cpt/light-theme.css';
import { BrowserRouter } from 'react-router-dom';
function App() {
return (
<BrowserRouter>
{/* Your routes */}
</BrowserRouter>
);
}Dynamic Theme Switching
Important: For dynamic theme switching (changing themes at runtime), the theme CSS files must be available in your public folder. This is required because PrimeReact's changeTheme function needs to swap the stylesheet link dynamically.
Setup for Theme Switching
- Copy theme files to your public folder:
# Copy from node_modules to your public folder
cp node_modules/@cpt-group/cpt-prime-react/dist/cpt/light-theme.css public/themes/
cp node_modules/@cpt-group/cpt-prime-react/dist/cpt/dark-theme.css public/themes/
cp -r node_modules/@cpt-group/cpt-prime-react/dist/cpt/fonts public/themes/- Add a link element in your HTML (or use Next.js Head component):
// In index.html or app/layout.tsx
<link id="theme-link" rel="stylesheet" href="/themes/light-theme.css" />- Use changeTheme in your components:
import { PrimeReactContext } from 'primereact/api';
import { useContext } from 'react';
function ThemeSwitcher() {
const { changeTheme } = useContext(PrimeReactContext);
const switchToDark = () => {
changeTheme('light-theme', 'dark-theme', 'theme-link');
};
const switchToLight = () => {
changeTheme('dark-theme', 'light-theme', 'theme-link');
};
return (
<div>
<button onClick={switchToLight}>Light Theme</button>
<button onClick={switchToDark}>Dark Theme</button>
</div>
);
}Note: If you're only using a single theme (not switching dynamically), you can import the CSS directly in your code as shown in the examples above. Theme switching requires the files to be in the public folder.
For comprehensive theming documentation, see docs/THEMING.md.
Theme Structure
Themes include:
- PrimeReact core styles
- PrimeIcons
- PrimeFlex utility classes
- Custom styling and variables
Using Themes
Basic Usage Example
Step 1: Import the theme once at your app root (e.g., src/index.tsx, app/layout.tsx, or pages/_app.tsx):
// src/index.tsx (or your root file)
import '@cpt-group/cpt-prime-react/cpt/light-theme.css';Step 2: Use components anywhere in your app - they'll automatically use the theme:
// src/components/MyComponent.tsx
import { CPTButton, CPTInputText, CPTCard, CPTPanel } from '@cpt-group/cpt-prime-react';
function MyComponent() {
return (
<div>
<CPTCard title="Welcome">
<p>This is using the CPT Light theme with American colors!</p>
<CPTButton label="Primary Button" />
<CPTButton label="Secondary Button" className="p-button-secondary" />
<CPTInputText placeholder="Enter text here" />
</CPTCard>
<CPTPanel header="Panel with Blue Gradient Header">
<p>Panels and cards feature blue gradient banners with American colors.</p>
</CPTPanel>
</div>
);
}Dark Theme Example
Import once at root:
// src/index.tsx
import '@cpt-group/cpt-prime-react/cpt/dark-theme.css';Use components anywhere:
// src/components/DataTableExample.tsx
import { CPTButton, CPTDataTable, CPTColumn } from '@cpt-group/cpt-prime-react';
function DataTableExample() {
const data = [
{ id: 1, name: 'Item 1', status: 'Active' },
{ id: 2, name: 'Item 2', status: 'Inactive' },
];
return (
<div>
<CPTButton label="Click Me" />
<CPTDataTable
value={data}
header="Data Table with Blue Gradient Header"
>
<CPTColumn field="name" header="Name" />
<CPTColumn field="status" header="Status" />
</CPTDataTable>
</div>
);
}Complete Example with Multiple Components
Theme import (once at root):
// src/index.tsx
import '@cpt-group/cpt-prime-react/cpt/light-theme.css';Component usage (anywhere in your app):
// src/components/Demo.tsx
import React, { useState } from 'react';
import {
CPTButton,
CPTInputText,
CPTCard,
CPTPanel,
CPTDataTable,
CPTColumn,
CPTDialog,
CPTToast,
CPTTabView,
CPTTabPanel,
} from '@cpt-group/cpt-prime-react';
function Demo() {
const [visible, setVisible] = useState(false);
const toast = React.useRef(null);
const showToast = () => {
toast.current?.show({
severity: 'info',
summary: 'Success',
detail: 'Theme is working perfectly!',
});
};
const data = [
{ id: 1, name: 'John Doe', email: '[email protected]' },
{ id: 2, name: 'Jane Smith', email: '[email protected]' },
];
return (
<div className="p-4">
<CPTCard title="CPT American Theme Demo">
<div className="flex flex-column gap-3">
<CPTButton
label="Primary Button (Blue Gradient)"
onClick={showToast}
/>
<CPTButton
label="Secondary Button (Heroic Red)"
className="p-button-secondary"
/>
<CPTInputText placeholder="Enter your name" />
<CPTButton
label="Open Dialog"
onClick={() => setVisible(true)}
/>
</div>
</CPTCard>
<CPTPanel header="Panel with Blue Gradient Banner" className="mt-4">
<p>This panel header features a beautiful blue gradient banner.</p>
</CPTPanel>
<CPTDataTable
value={data}
header="Data Table with Blue Gradient Header"
className="mt-4"
>
<CPTColumn field="name" header="Name" />
<CPTColumn field="email" header="Email" />
</CPTDataTable>
<CPTTabView className="mt-4">
<CPTTabPanel header="Tab 1">
<p>Active tabs have blue gradient backgrounds.</p>
</CPTTabPanel>
<CPTTabPanel header="Tab 2">
<p>Content for tab 2</p>
</CPTTabPanel>
</CPTTabView>
<CPTDialog
header="Dialog with Blue Gradient Header"
visible={visible}
onHide={() => setVisible(false)}
style={{ width: '50vw' }}
>
<p>Dialogs feature blue gradient headers matching the American theme.</p>
</CPTDialog>
<CPTToast ref={toast} />
</div>
);
}
export default Demo;Comprehensive Theming Guide
For detailed information about:
- Creating custom themes
- Dynamic theme switching
- CSS variables reference
- Theme customization
- Best practices
See the Complete Theming Guide.
Quick Start Example
Step 1: Import the theme once at your application root (e.g., src/index.tsx, app/layout.tsx):
// src/index.tsx (or your root file)
import '@cpt-group/cpt-prime-react/cpt/light-theme.css';Step 2: Import and use components anywhere in your app:
// src/components/MyComponent.tsx
import { CPTButton, CPTInputText } from '@cpt-group/cpt-prime-react';
function MyComponent() {
return (
<>
<CPTButton label="Click Me" />
<CPTInputText placeholder="Enter text" />
</>
);
}That's it! The theme automatically styles all CPT components globally with the American color scheme. You only need to import the theme once at the root level, just like standard PrimeReact themes.
Components
All major PrimeReact components are available with CPT naming:
Form Components
CPTInputText- Text inputCPTInputTextarea- TextareaCPTInputNumber- Number inputCPTInputMask- Masked inputCPTInputSwitch- Toggle switchCPTButton- ButtonCPTButtonGroup- Button groupCPTSplitButton- Split buttonCPTToggleButton- Toggle buttonCPTCheckbox- CheckboxCPTTriStateCheckbox- Tri-state checkboxCPTRadioButton- Radio buttonCPTDropdown- DropdownCPTMultiSelect- Multi-select dropdownCPTAutoComplete- AutocompleteCPTCalendar- Calendar/Date pickerCPTChips- Chips inputCPTColorPicker- Color pickerCPTEditor- Rich text editorCPTFileUpload- File uploadCPTKnob- Knob controlCPTPassword- Password inputCPTRating- RatingCPTSelectButton- Select buttonCPTSlider- SliderCPTTreeSelect- Tree select
Data Display
CPTDataTable- Data tableCPTDataView- Data viewCPTDataViewLayoutOptions- Data view layout optionsCPTTreeTable- Tree tableCPTColumn- Table columnCPTColumnGroup- Table column groupCPTChart- ChartCPTProgressBar- Progress barCPTProgressSpinner- Progress spinnerCPTSkeleton- Loading skeletonCPTTag- TagCPTChip- ChipCPTCard- CardCPTPanel- PanelCPTFieldset- FieldsetCPTDivider- DividerCPTAccordion- AccordionCPTAccordionTab- Accordion tabCPTTabView- Tab viewCPTTabPanel- Tab panelCPTTimeline- TimelineCPTOrganizationChart- Organization chart
Overlay Components
CPTDialog- Dialog/ModalCPTSidebar- SidebarCPTOverlayPanel- Overlay panelCPTConfirmDialog- Confirm dialogCPTConfirmPopup- Confirm popupCPTTooltip- TooltipCPTBlockUI- Block UI overlay
Menu Components
CPTMenu- Context menuCPTContextMenu- Context menuCPTTieredMenu- Tiered menuCPTSlideMenu- Slide menuCPTMegaMenu- Mega menuCPTMenubar- MenubarCPTPanelMenu- Panel menuCPTDock- Dock menu
Navigation
CPTBreadcrumb- BreadcrumbCPTSteps- Steps indicator
Media
CPTImage- ImageCPTGalleria- GalleryCPTCarousel- Carousel
Messages
CPTMessage- MessageCPTToast- Toast notifications
Misc
CPTTerminal- Terminal componentCPTSplitter- SplitterCPTSplitterPanel- Splitter panelCPTVirtualScroller- Virtual scrollerCPTSpeedDial- Speed dialCPTMeterGroup- Meter groupCPTInplace- Inplace editorCPTInplaceDisplay- Inplace displayCPTInplaceContent- Inplace content
Layout
CPTRow- RowCPTAvatar- AvatarCPTAvatarGroup- Avatar groupCPTSkeleton- Skeleton loader
PrimeReact Version Compatibility
This package is compatible with PrimeReact ^10.0.0. When updating PrimeReact, check the PrimeReact changelog for breaking changes.
Updating PrimeReact
Update PrimeReact in your project:
npm install primereact@latestTest your application thoroughly
Check this package's CHANGELOG for any component updates
Customization
Since all components are simple wrappers around PrimeReact components, you can customize them by:
- Modifying the component files in this package
- Extending components in your own codebase
- Using PrimeReact's theming system to customize styles
Development
Building the Package
npm run buildThis will:
- Clean the dist folder
- Build CommonJS output (
dist/cjs/) - Build ES Modules output (
dist/esm/) - Generate TypeScript declarations (
dist/types/)
Development Mode
Watch mode for development:
npm run watchType Checking
npm run typecheckContributing
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
License
MIT
Known Issues
Some components with nested parent-child relationships (like Accordion/AccordionTab and TabView/TabPanel) may not work correctly when wrapped. See KNOWN_ISSUES.md for details and workarounds.
Support
For issues, questions, or contributions, please open an issue on the GitHub repository.
