
Research
NPM targeted by malware campaign mimicking familiar library names
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
A functional TypeScript/JavaScript component library with composable architecture based on Material Design 3
Project Status: mtrl is in active development with TypeScript support! The core architecture and components are established, with more features on the roadmap. We welcome early adopters and contributors who want to help shape mtrl's future!
mtrl is a lightweight, composable TypeScript/JavaScript component library inspired by Material Design principles. Built with zero dependencies, mtrl provides a robust foundation for creating modern web interfaces with an emphasis on performance, type safety, and accessibility.
mtrl (pronounced "material") takes its inspiration from Material Design while providing a flexible, framework-agnostic implementation. The library's name is reflected in its component prefix mtrl-
, which you'll see used consistently throughout the codebase.
mtrl is built on several core principles:
mtrl provides a comprehensive set of components, each following Material Design principles:
import { createButton, createTextField } from 'mtrl'
// Create a material button with ripple effect
const button = createButton({
text: 'Submit',
variant: 'filled',
ripple: true,
class: 'custom-button'
})
// className will be: mtrl-button mtrl-button--filled custom-button
Each component follows the mtrl-
prefix convention:
mtrl-button
- Material buttons with ripple effectsmtrl-textfield
- Text input componentsmtrl-switch
- Toggle switchesmtrl-navigation
- Navigation componentsmtrl-list
- List components with selectionmtrl-snackbar
- Toast notificationsmtrl-container
- Layout containers# Using npm
npm install mtrl
# Using yarn
yarn add mtrl
# Using bun
bun add mtrl
Let's look at how mtrl components are constructed:
// Example of a button component creation
const button = createButton({
prefix: 'mtrl', // The library's prefix
componentName: 'button', // Component identifier
variant: 'filled', // Visual variant
text: 'Click me', // Button text
ripple: true // Enable ripple effect
})
mtrl uses a pipe-based composition system with full type safety for building components:
// Internal component creation
const createButton = (config: ButtonConfig): ButtonComponent => {
return pipe(
createBase, // Base component structure
withEvents(), // Event handling capability
withElement({ // DOM element creation
tag: 'button',
componentName: 'button',
prefix: 'mtrl'
}),
withVariant(config), // Visual variant support
withText(config), // Text content management
withIcon(config), // Icon support
withRipple(config) // Ripple animation
)(config)
}
mtrl provides comprehensive TypeScript definitions:
// Component interfaces for better developer experience
export interface ButtonComponent extends
BaseComponent,
ElementComponent,
TextComponent,
IconComponent,
DisabledComponent,
LifecycleComponent {
// Button-specific properties and methods
getValue: () => string;
setValue: (value: string) => ButtonComponent;
enable: () => ButtonComponent;
disable: () => ButtonComponent;
setText: (content: string) => ButtonComponent;
getText: () => string;
setIcon: (icon: string) => ButtonComponent;
getIcon: () => string;
destroy: () => void;
updateCircularStyle: () => void;
}
mtrl follows a consistent class naming convention:
.mtrl-component /* Base component class */
.mtrl-component--variant /* Variant modifier */
.mtrl-component--state /* State modifier (disabled, focused) */
.mtrl-component-element /* Child element */
mtrl provides several approaches to state management:
const textField = createTextField({
label: 'Username'
})
textField.on('input', ({ value }) => {
console.log('Current value:', value)
})
textField.setValue('New value')
For managing lists and datasets:
const collection = new Collection<User>({
transform: (item) => ({
...item,
displayName: `${item.firstName} ${item.lastName}`
})
})
collection.subscribe(({ event, data }) => {
console.log(`Collection ${event}:`, data)
})
mtrl provides adapters for different data sources:
// MongoDB adapter
const mongoAdapter = createMongoAdapter({
uri: 'mongodb://localhost:27017',
dbName: 'mtrl-app',
collection: 'users'
})
// Route adapter for REST APIs
const routeAdapter = createRouteAdapter({
base: '/api',
endpoints: {
list: '/users',
create: '/users'
}
})
Extend mtrl by creating custom components with full type safety:
interface CustomCardConfig {
title?: string;
class?: string;
}
interface CustomCardComponent extends ElementComponent {
setContent: (content: string) => CustomCardComponent;
}
const createCustomCard = (config: CustomCardConfig): CustomCardComponent => {
return pipe(
createBase,
withEvents(),
withElement({
tag: 'div',
componentName: 'card',
prefix: 'mtrl'
}),
// Add custom features
(component) => ({
...component,
setContent(content: string) {
component.element.innerHTML = content;
return this;
}
})
)(config);
}
mtrl components can be styled through CSS custom properties:
:root {
--mtrl-primary: #6200ee;
--mtrl-surface: #ffffff;
--mtrl-on-surface: #000000;
--mtrl-elevation-1: 0 2px 4px rgba(0,0,0,0.2);
}
mtrl is designed with performance in mind:
mtrl leverages TypeScript for better developer experience:
Built-in accessibility features include:
mtrl supports modern browsers:
We welcome contributions! Please see our Contributing Guide for details and our Migration Guide for TypeScript information.
mtrl is licensed under the MIT License - see the LICENSE file for details.
mtrl comes with a comprehensive test suite using Bun's test runner. The tests are written in TypeScript and use JSDOM for DOM testing.
# Run all tests
bun test
# Run tests in watch mode
bun test --watch
# Run tests with coverage report
bun test --coverage
# Run tests with UI
bun test --watch --ui
# Run a specific test file
bun test test/components/button.test.ts
For more details on writing and running tests, see our Testing Guide.
For detailed API documentation, examples, and guides, visit our documentation site.
This library is designed to provide a solid foundation for building modern web interfaces with TypeScript while maintaining flexibility for custom implementations. For questions, issues, or contributions, please visit our GitHub repository.
FAQs
A functional TypeScript/JavaScript component library with composable architecture based on Material Design 3
The npm package mtrl receives a total of 38 weekly downloads. As such, mtrl popularity was classified as not popular.
We found that mtrl demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
Research
Socket's research uncovers three dangerous Go modules that contain obfuscated disk-wiping malware, threatening complete data loss.
Research
Socket uncovers malicious packages on PyPI using Gmail's SMTP protocol for command and control (C2) to exfiltrate data and execute commands.