The Package Manager component provides a tabbed interface for displaying installation commands for different package managers (npm, pnpm, yarn, bun). It allows users to easily copy the correct installation command for their preferred package manager.
Metro UI Core
DOM library
Hooks (for ID generation)
See the Example by Serhii Pimenov on CodePen .
< div data-role = "package-manager" data-package = "metro4" ></ div >
< div data-role = "package-manager"
// Create a package manager component programmatically
const packageManager = Metro . makePlugin ( "#element" , "package-manager" , {
// Alternative jQuery-style creation
const packageManager = $ ( "<div>" ). packageManager ({
}). appendTo ( "#container" );
The Package Manager component accepts the following configuration options:
Parameter Type Default Description link
string "package-manager"
Name for the tabs link default
string "npm"
Default selected package manager (npm, pnpm, yarn, bun) deps
string ""
Dependency type: empty for regular dependencies, “dev” for dev dependencies, “peer” for peer dependencies package
string ""
Package name to install
Event Description onPackageManagerCreate
Triggered when the component is created
The Package Manager component provides the following methods:
Method Description destroy()
Removes the component from the DOM
const packageManager = Metro . getPlugin ( "#element" , "package-manager" );
packageManager . destroy ();
The component automatically formats the correct installation command for each package manager based on the dependency type:
Package Manager Command Format npm npm i <package>
pnpm pnpm add <package>
yarn yarn add <package>
bun bun add <package>
Package Manager Command Format npm npm i -D <package>
pnpm pnpm add -D <package>
yarn yarn add -D <package>
bun bun add -D <package>
Package Manager Command Format npm npm i <package>
(npm doesn’t have a specific flag for peer dependencies)pnpm pnpm add --save-peer <package>
yarn yarn add -P <package>
bun bun add --peer <package>
The Package Manager component uses the following CSS variables for styling:
Variable Default (Light) Dark Mode Description --code-background
Inherited from theme Inherited from theme Background color for code blocks and tabs --code-color
Inherited from theme Inherited from theme Text color for code blocks and icons
/* Custom styling for package manager */
.custom-package-manager {
--code-background : #f5f5f5 ;
.package-manager
- Base class for the component
.pm-command
- Container for each package manager command
.pm-command code
- Command text
.pm-command button
- Copy button
Tabbed Interface : Easily switch between different package managers
Copy to Clipboard : One-click copying of installation commands
Dependency Type Support : Configure for regular, development, or peer dependencies
Visual Icons : Each package manager has its own icon for easy identification
Responsive Design : Works well in different container sizes
Place the component near package information for easy discovery
Set a default package manager that matches your project’s recommended tooling
Specify the correct dependency type to ensure users install packages correctly
Consider adding additional context around the component to explain what the package does
For packages with complex installation requirements, consider providing additional instructions