Material UI:非常強大的CSS框架
Material UI 是一款功能非常強大,界面卻十分清新簡潔的CSS框架,Material UI利用了Google的Material Design 全新設計語言,并且讓每一個UI組件都變得非常獨立,因此開發者使用Material UI也會比較簡單。和Bootstrap類似,Material UI提供了很多常用的UI組件,除了最基本的菜單、按鈕、滑動桿、進度條、單選框/復選框外,它還提供了一個非常有趣的日歷組件,另外還提供了一些很有趣的圖標。
Material UI 的特點
- 組件很豐富,每一個組件的風格比較一致。
- 提供了 npm 包的形式,使用起來相對比較方便。
- 這一切都是開源的,你可以任意使用這個開源的CSS框架。
Material UI 的應用實例
首先我們從最基本的看起。
菜單
下面是一個簡單的多級下拉菜單
代碼如下:
nestedMenuItems = [
{ type: mui.MenuItem.Types.NESTED, text: 'Reports', items: [
{ payload: '1', text: 'Nested Item 1' },
{ type: mui.MenuItem.Types.NESTED, text: 'Nested Item 2', items: [
{ payload: '1', text: 'Nested Item 2.1' },
{ type: mui.MenuItem.Types.NESTED, text: 'Nested Item 2.2', items: [
{ payload: '1', text: 'Nested Item 2.2.1' },
{ payload: '3', text: 'Nested Item 2.2.2' }
] },
{ payload: '3', text: 'Nested Item 2.3' }
] },
{ payload: '3', text: 'Nested Item 3' },
{ type: mui.MenuItem.Types.NESTED, text: 'Nested Item 4', items: [
{ payload: '1', text: 'Nested Item 4.1' },
{ type: mui.MenuItem.Types.NESTED, text: 'Nested Item 4.2', items: [
{ payload: '1', text: 'Nested Item 4.2.1', disabled: true },
{ payload: '3', text: 'Nested Item 4.2.2' }
] },
{ payload: '3', text: 'Nested Item 4.3' }
] },
{ payload: '4', text: 'Nested Item 5' }
] },
{ payload: '1', text: 'Audio Library'},
{ payload: '2', text: 'Settings'},
{ payload: '3', text: 'Logout', disabled: true}
];
<Menu menuItems={nestedMenuItems} autoWidth={false}/> 下面是一個帶圖標的垂直菜單
代碼如下:
//iconClassName is the classname for our icon that will get passed into mui.FontIcon
iconMenuItems = [
{ payload: '1', text: 'Live Answer', iconClassName: 'muidocs-icon-communication-phone', number: '10' },
{ payload: '2', text: 'Voicemail', iconClassName: 'muidocs-icon-communication-voicemail', number: '5' },
{ payload: '3', text: 'Starred', iconClassName: 'muidocs-icon-action-stars', number: '3' },
{ payload: '4', text: 'Shared', iconClassName: 'muidocs-icon-action-thumb-up', number: '12' }
];
<Menu menuItems={iconMenuItems} autoWidth={false}/> 按鈕
下面是簡單的彩色按鈕,點擊按鈕會出現波浪擴散的動畫效果。
代碼如下:
//Raised Buttons
<RaisedButton label="Default" />
<RaisedButton label="Primary" primary={true} />
<RaisedButton label="Secondary" secondary={true} />
<div style={styles.container}>
<RaisedButton primary={true} label="Choose an Image">
<input type="file" style={styles.exampleImageInput}></input>
</RaisedButton>
</div>
<div style={styles.container}>
<RaisedButton linkButton={true} secondary={true} label="Github">
<FontIcon style={styles.exampleButtonIcon} className="muidocs-icon-custom-github"/>
</RaisedButton>
</div>
<RaisedButton label="Disabled" disabled={true} /> 美化單選框復選框
下面是Material UI經過美化過的單選框和復選框
代碼如下:
<RadioButtonGroup name="shipSpeed" defaultSelected="not_light">
<RadioButton
value="light"
label="prepare for light speed"
style={{marginBottom:16}} />
<RadioButton
value="not_light"
label="light speed too slow"
style={{marginBottom:16}}/>
<RadioButton
value="ludicrous"
label="go to ludicrous speed"
style={{marginBottom:16}}
disabled={true}/>
</RadioButtonGroup> 日歷組件
這是個人覺得最漂亮的CSS日歷組件
代碼如下:
//Portrait Dialog
<DatePicker
hintText="Portrait Dialog"
//Landscape Dialog
<DatePicker
hintText="Landscape Dialog"
mode="landscape"/>
// Ranged Date Picker
<DatePicker
hintText="Ranged Date Picker"
autoOk={this.state.autoOk}
minDate={this.state.minDate}
maxDate={this.state.maxDate}
showYearSelector={this.state.showYearSelector} /> Material UI還有很多有用的CSS UI組件,你可以前往其官方網站下載及學習使用。
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!