U2Component is a cross-framework component library inspired by the Material Design 3 design system, based on web component. The project is being refactored.
U2Component is a component library based on web component. You can change the color of all components at once by replacing the CSS file "token.css", all component colors and fonts use design tokens.
- Please make sure that you use this component library for development on mainstream browsers.
- Make sure you set
font-size: 1remon html. Some styles use rem and em units.
Color tokens
The css files in ""/style" folder are generated by or Figma plugin Material Theme Builder. Choose "Export" - "Web(CSS)", just replace the token.css.
Material-Theme-Builder web: as they have updated this tool, it will not generated token.css now.
I am trying to design a repository that can generate the token required for U2Component theme, stay tuned.
Icon (TODO)
The previous icon library used material-symbols, which has now been removed and will be supported in the future.
setp 1
npm install u2-componentsetp 2
For Vite (vue)
// vite.config.js
export default defineConfig({
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: (tag) => tag.startsWith('u2-'),
},
},
}),
],
});For Vue CLI / Webpack (vue)
// vue.config.js
module.exports = {
chainWebpack: config => {
config.module
.rule('vue')
.use('vue-loader')
.tap(options => {
options.compilerOptions = {
isCustomElement: (tag) => tag.startsWith('u2-')
};
return options;
});
}
};final setp For vue
// main.ts
import U2Component from 'u2-component'
import 'u2-component/style' // import style
import { createApp } from 'vue'
const app = createApp(App)
app.use(U2Component) // install
app.mount('#app')For react (in progress)
You can download the github repository file and import it directly.
1. Import style The style file contains various tokens, such as light and dark themes.
<link rel="stylesheet" type="text/css" href="../style/theme.css">2. Import component Just import it into the HTML file (there are many parameters that can be adjusted):
<script src="../components/TextField.js" type="module"></script>| name | state | the name when using |
|---|---|---|
| text field | stable | u2-field |
| textarea | stable | u2-textarea |
| select | may change | u2-Select |
| filled button | stable | u2-button variant="filled" |
| outlined button | stable | u2-button variant="outlined" |
| text button | stable | u2-button |
| segmented button | may change | segmented-button |
| form | may change | u2-form |
| form item | may change | u2-form-item |
Basic use. it will auto add a placeholder attribute to itself.
<u2-field variant="filled"></u2-field>
<u2-field variant="outlined"></u2-field>There are two types of text field: filled and outlined. variant attribute is required.
<u2-field
variant="filled"
label="username"
autocomplete="name"
width="240">
</u2-field>
<u2-field
variant="outlined"
placeholder="verify code"
type="password">
</u2-field>parameter: (*) means required
- variant(*) : The style type of the text input box. In Material 3, this component has two style variants: filled and outlined.
- value : Set default input.
- placeholder : The placeholder text to be displayed in the initial state when the user has not input anything.
- label : A label may float to top when user focus on text field. You can't set both of label and placeholder.
- width : The default unit is px, and percentage units are not supported. You can specify the width of the component, and the width of the component will no longer fill the width of the parent element. (TextField has a maximum width of 112 px in M3 Doc, but I designed a property to help you remove this limitation.)
- fullWidth : Here it comes. The component will fill the container width.
- type :
Set
type="password"to let input be invisible. - disabled :
Set
disabledto make it uninputable.
<u2-textarea
variant="filled"
label="note"
height="200">
</u2-textarea>parameter: (*) means required
- variant(*) : This component has two style variants: filled and outlined.
- value :
- placeholder
- label
- width
- height
Same as the native web select, put option element in it.
<u2-select
variant="filled"
label="type selector">
<option value="1">inner option 1</option>
<option value="2">inner option 2</option>
</u2-select>parameter: (*) means required
- variant(*) : This component has two style variants: filled and outlined.
- label(*)
- disabled
<u2-button>text button</u2-button>
<u2-button variant="filled">filled button</u2-button>
<u2-button variant="outlined">outlined button</u2-button>
<u2-button disabled>disabled state</u2-button>parameter: (*) means required
- variant : This component has three style variants: text, filled and outlined. If you don't set this attribute, it will fallback to default text type.
- disabled
<segmented-button>
<u2-button>option 1</u2-button>
<u2-button>option 2</u2-button>
<u2-button>option 3</u2-button>
</segmented-button>no parameter is needed.
For validation usage.
<u2-form>
<u2-form-item prop="age">
<u2-field
variant="filled"
label="age"
fullWidth>
</u2-field>
</u2-form-item>
</u2-form>When setting rules for form, the inner element form item must have a prop attribute.
const FORM = document.getElementsByTagName("U2-FORM")[0];
const rules = {
age: [
{
required: true,
trigger: "change",
},
]
}
FORM.rules = rules; // (*)When using it in vue or react, you also need to get form first and set the rules configuration of form. (Pass it like (*) line)
The configuration requirements of the rules are the same as Element Plus.
See upper case. Put form item into u2-form component.





