Top Related Projects
Modular and customizable Material Design UI components for the web
🐉 Vue Component Framework
Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
Component infrastructure and Material Design components for Angular
Next Generation Vue UI Component Library
Materialize, a CSS Framework based on Material Design
Quick Overview
Svelte Material UI is a comprehensive Svelte component library that implements Google's Material Design. It provides a wide range of pre-built, customizable UI components that adhere to Material Design principles, allowing developers to create modern and visually appealing web applications using Svelte.
Pros
- Extensive collection of Material Design components
- Seamless integration with Svelte's reactive paradigm
- Customizable themes and styles
- Active development and community support
Cons
- Learning curve for developers new to Material Design
- Potential performance overhead for complex applications
- Limited documentation compared to some other UI libraries
- Dependency on Google's Material Design specifications
Code Examples
- Creating a simple button:
<script>
import Button from '@smui/button';
</script>
<Button on:click={() => alert('Clicked!')}>
Click me
</Button>
- Implementing a text field with a label:
<script>
import Textfield from '@smui/textfield';
</script>
<Textfield label="Username" />
- Using a dialog component:
<script>
import Dialog, { Title, Content, Actions } from '@smui/dialog';
import Button from '@smui/button';
let open = false;
</script>
<Button on:click={() => (open = true)}>Open Dialog</Button>
<Dialog bind:open>
<Title>Dialog Title</Title>
<Content>This is the dialog content.</Content>
<Actions>
<Button on:click={() => (open = false)}>Close</Button>
</Actions>
</Dialog>
Getting Started
- Install Svelte Material UI:
npm install --save-dev svelte-material-ui
- Import and use components in your Svelte file:
<script>
import Button from '@smui/button';
</script>
<Button on:click={() => console.log('Button clicked')}>
Click me
</Button>
- Add the Material Icons font and SMUI CSS (in your HTML file):
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel="stylesheet" href="smui.css" />
Note: For a complete setup, refer to the official documentation for more detailed instructions on theming and configuration.
Competitor Comparisons
Modular and customizable Material Design UI components for the web
Pros of Material Components Web
- Official implementation by Google, ensuring adherence to Material Design guidelines
- Broader ecosystem support and integration with other Google products
- More comprehensive documentation and examples
Cons of Material Components Web
- Not specifically designed for Svelte, requiring additional integration work
- Potentially larger bundle size due to its framework-agnostic nature
- May have a steeper learning curve for Svelte developers
Code Comparison
Material Components Web:
import {MDCRipple} from '@material/ripple';
const buttonRipple = new MDCRipple(document.querySelector('.mdc-button'));
Svelte Material UI:
<script>
import Button from '@smui/button';
</script>
<Button>Click me</Button>
Summary
Material Components Web offers an official implementation with broader support, while Svelte Material UI provides a more Svelte-friendly approach. The choice between them depends on project requirements, team expertise, and desired integration level with the Svelte ecosystem.
🐉 Vue Component Framework
Pros of Vuetify
- Larger community and ecosystem, with more resources and third-party integrations
- More comprehensive set of pre-built components and features
- Better documentation and official support
Cons of Vuetify
- Heavier bundle size, which may impact performance for smaller applications
- Steeper learning curve due to its extensive API and configuration options
- Less flexibility in customizing individual components without overriding styles
Code Comparison
Vuetify (Vue.js):
<template>
<v-btn color="primary" @click="handleClick">
Click me
</v-btn>
</template>
<script>
export default {
methods: {
handleClick() {
console.log('Button clicked')
}
}
}
</script>
Svelte Material UI (Svelte):
<script>
import Button from '@smui/button'
function handleClick() {
console.log('Button clicked')
}
</script>
<Button on:click={handleClick} variant="raised">
Click me
</Button>
Both libraries provide Material Design components, but Vuetify is more established in the Vue.js ecosystem, while Svelte Material UI caters to the growing Svelte community. Vuetify offers a more comprehensive set of features and components, but may be overkill for smaller projects. Svelte Material UI, being lighter and more flexible, might be preferable for developers seeking a simpler integration or working on smaller applications.
Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
Pros of Material-UI
- Larger community and ecosystem, with more third-party components and resources
- More comprehensive documentation and examples
- Better TypeScript support and type definitions
Cons of Material-UI
- Steeper learning curve, especially for developers new to React
- Larger bundle size, which may impact initial load times
- More complex theming system, requiring more setup for customization
Code Comparison
Material-UI (React):
import React from 'react';
import Button from '@mui/material/Button';
function App() {
return <Button variant="contained">Hello World</Button>;
}
Svelte Material UI:
<script>
import Button from '@smui/button';
</script>
<Button variant="raised">
<Label>Hello World</Label>
</Button>
Summary
Material-UI is a more established and feature-rich library for React applications, offering a wider range of components and better documentation. However, it comes with a steeper learning curve and larger bundle size. Svelte Material UI, while less mature, provides a simpler API and potentially better performance due to Svelte's compilation process. The choice between the two largely depends on the project's requirements, team expertise, and preferred framework (React vs. Svelte).
Component infrastructure and Material Design components for Angular
Pros of Angular Material
- Extensive documentation and community support
- Seamless integration with Angular framework
- Comprehensive set of pre-built components and themes
Cons of Angular Material
- Steeper learning curve for developers new to Angular
- Larger bundle size compared to Svelte Material UI
- More opinionated structure, potentially limiting flexibility
Code Comparison
Angular Material:
import { MatButtonModule } from '@angular/material/button';
@NgModule({
imports: [MatButtonModule],
// ...
})
export class AppModule { }
Svelte Material UI:
<script>
import Button from '@smui/button';
</script>
<Button on:click={handleClick}>Click me</Button>
The Angular Material example shows the module-based approach, requiring imports and configuration at the module level. Svelte Material UI demonstrates a more straightforward component import and usage, aligning with Svelte's component-based architecture.
Both libraries offer Material Design components, but their implementation and usage differ based on their respective frameworks. Angular Material provides a more comprehensive ecosystem, while Svelte Material UI offers a lighter-weight alternative with Svelte's reactive approach.
Next Generation Vue UI Component Library
Pros of PrimeVue
- More comprehensive component library with a wider range of UI elements
- Better documentation and examples, making it easier for developers to implement
- Active development and frequent updates, ensuring compatibility with the latest Vue versions
Cons of PrimeVue
- Larger bundle size, which may impact initial load times for applications
- Less customizable styling options compared to Svelte Material UI's SASS-based approach
- Steeper learning curve due to the extensive component library and API
Code Comparison
PrimeVue:
<template>
<Button label="Click me" @click="handleClick" />
</template>
<script>
import Button from 'primevue/button';
export default {
components: { Button },
methods: {
handleClick() {
// Handle click event
}
}
}
</script>
Svelte Material UI:
<script>
import Button from '@smui/button';
function handleClick() {
// Handle click event
}
</script>
<Button on:click={handleClick}>Click me</Button>
Both libraries offer easy-to-use component implementations, but PrimeVue requires more boilerplate code due to Vue's component structure. Svelte Material UI's syntax is more concise, leveraging Svelte's built-in event handling.
Materialize, a CSS Framework based on Material Design
Pros of Materialize
- Standalone CSS framework, usable with any JavaScript framework or vanilla JS
- Larger community and ecosystem, with more third-party resources and extensions
- More comprehensive set of UI components and utilities out-of-the-box
Cons of Materialize
- Not specifically designed for Svelte, requiring more manual integration
- Less frequent updates and maintenance compared to Svelte Material UI
- Heavier file size due to its standalone nature and broader feature set
Code Comparison
Materialize (using vanilla JS):
<div class="input-field">
<input id="email" type="email" class="validate">
<label for="email">Email</label>
</div>
Svelte Material UI:
<script>
import Textfield from '@smui/textfield';
</script>
<Textfield label="Email" type="email" />
Materialize focuses on providing CSS classes and minimal JavaScript for functionality, while Svelte Material UI offers more tightly integrated Svelte components. This results in cleaner, more idiomatic Svelte code when using Svelte Material UI, but potentially less flexibility compared to Materialize's class-based approach.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
A library of Svelte Material UI components, based on Material Design Components - Web.
Demos, Code Samples, and Guides
Features
Here are some unique features that help SMUI stand out:
- Full TypeScript support, including HTML attributes.
- You can add arbitrary attributes to all of the components and many of the elements within them.
- You can add actions to the components with
use={[Action1, [Action2, action2Props], Action3]}
. - You can add props to lower components and elements with "$" props, like
input$maxlength="15"
. - All events are forwarded. This includes DOM events, SMUI events, and custom events.
- You can add event modifiers with the
on:click$preventDefault$capture={handler}
syntax.- You have to use "$" instead of "|" like in native Svelte. (The extra S inside the | stands for SMUI.)
- Supported modifiers are:
- passive
- nonpassive
- capture
- once
- preventDefault
- stopPropagation
- stopImmediatePropagation
- self
- trusted
- You can add event modifiers with the
- SMUI supports RTL languages.
Installation
To get started, check out the installation docs or the SvelteKit docs.
Need Help?
If you need help installing or using SMUI, join the Discord server.
Svelte 5
SMUI v7 works with Svelte 4 only, due to the way it handles events.
SMUI v8 is in development, and works with Svelte 5 (and not Svelte 4). You can view the readme on the v8 branch.
You can install SMUI v8 by specifying the alpha tag when you install, like npm i -D @smui/button@alpha
.
Migration
Upgrading from an old version? Be sure to read the migration doc.
Upgrading from v6? You need Svelte 4. No more elemental components; you can now use the "tag" prop to change the element. No more "ComponentDev" types; components can now be used as their type. Check out the upgrade instructions.
Upgrading from v5? If you're still using the advanced styling method, it's really time to switch to the easy styling method. '/styled' endpoints are no longer provided. Check out the upgrade instructions.
Upgrading from v4? SMUI v5 requires the TypeScript preprocessor. SMUI v6 does not though, so if you upgrade straight to v6, don't worry. Check out the upgrade instructions.
Upgrading from v3? SMUI's styling method has been simplified. Check out the upgrade instructions.
Upgrading from v2? There are lots of changes listed in the upgrade instructions.
Old Docs
You can find older versions of the docs on their respective branch:
Icons
You can include icons in a number of ways, but the easiest is the Material Icon Font. This will give you the standard set of Material Icons, available with the CSS class "material-icons".
<link
href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet"
/>
However, there are two downsides. First is that all icons are downloaded, no matter which ones you use, so the size over the wire will almost certainly be more than necessary. Second is that it only includes the Material Icons from Google.
Another option is the Material Design Icons library. See the "Using SVGs" demo on the Icon Button demo page for instructions to use icons from the @mdi/js
package (or any other SVG icons).
You can even use them in data URLs:
To get a data URL for the icon:
- Find your icon and click "View SVG" under the code menu.
- Click the "SVG File" tab and copy the full SVG document.
- Base64 encode the document.
- Format the URL like this
data:image/svg+xml;base64,encodedcontent
, replacing "encodedcontent" with the Base64 results. - Now you have an image URL you can use in an "img" tag src attribute or anywhere else you put an image URL (like
background-image: url();
).
Components
Click a component/package below to go to the documentation. (Note that this documentation is a work in progress. The demo code should be your main source of truth for how something works.)
- Accordionâ¡
- Action Buttons
- App Bars
- Badgeâ¡
- Banner
- Card
- Common
- Data Table
- Dialog
- Drawer
- Elevationâ
- Image List
- Inputs and Controls
- Layout Grid
- List
- Menu Surface
- Menu
- Paperâ¡
- Progress Indicators
- Ripple
- Snackbar
- Kitchenâ¡
- Tabs
- Tooltip
- Touch Target
- Typographyâ
â This is Sass based, and therefore doesn't require Svelte components. I've included a demo showing how you can use it.
â¡ This is not an MDC-Web component (upstream library). It is an addition that SMUI provides.
- Labels and icons are named exports in the components that use them, or you can use the 'Label' and 'Icon' exports from '@smui/common'. (Except for chips labels and icons, textfield icons, and select icons, because they are special snowflakes.)
License
Copyright 2019-2024 Hunter Perrin
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Top Related Projects
Modular and customizable Material Design UI components for the web
🐉 Vue Component Framework
Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
Component infrastructure and Material Design components for Angular
Next Generation Vue UI Component Library
Materialize, a CSS Framework based on Material Design
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot