forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Avatar] Support children, change default colors
- Loading branch information
Showing
25 changed files
with
737 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Chip | ||
==== | ||
|
||
Chips represent complex entities in small blocks, such as a contact. | ||
|
||
```jsx | ||
<Chip avatar={<Avatar>} label="Label text" /> | ||
``` | ||
|
||
Props | ||
----- | ||
|
||
| Name | Type | Default | Description | | ||
|:-----|:-----|:--------|:------------| | ||
| avatar | node | | Avatar element. | | ||
| className | string | | CSS `className` of the root element. | | ||
| deleteIconClassName | string | | CSS `className` of the delete icon element. | | ||
| label | string | | Label | | ||
| labelClassName | string | | CSS `className` of the label. | | ||
| onClick | function | | Callback function fired when the `Chip` element is clicked. If set, the chip will by styled for hover focus and active states.<br><br>**Signature:**<br>`function(event: object) => void`<br>*event:* `onClick` event targeting the root element. | | ||
| onRequestDelete | function | | Callback function fired when the delete icon is clicked. If set, the delete icon will be shown.<br><br>**Signature:**<br>`function(event: object) => void`<br>*event:* `onClick` event targeting the delete icon element. | | ||
|
||
Any other properties supplied will be spread to the root element. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// @flow weak | ||
|
||
import React, { PropTypes } from 'react'; | ||
import { createStyleSheet } from 'jss-theme-reactor'; | ||
import Avatar from 'material-ui/Avatar'; | ||
import Chip from 'material-ui/Chip'; | ||
import Face from 'material-ui/svg-icons/face'; | ||
import { grey } from 'material-ui/styles/colors'; | ||
import avatarImage from 'docs/site/assets/images/uxceo-128.jpg'; | ||
|
||
const styleSheet = createStyleSheet('Chips', () => ({ | ||
chip: { | ||
margin: '0 8px', | ||
}, | ||
svgIcon: { | ||
color: grey[800], | ||
}, | ||
row: { | ||
display: 'flex', | ||
justifyContent: 'center', | ||
}, | ||
})); | ||
|
||
function handleRequestDelete() { | ||
alert('You clicked the delete icon.'); // eslint-ignore-line no-alert | ||
} | ||
|
||
function handleClick() { | ||
alert('You clicked the Chip.'); // eslint-ignore-line no-alert | ||
} | ||
|
||
export default function Chips(props, context) { | ||
const classes = context.styleManager.render(styleSheet); | ||
return ( | ||
<div className={classes.row}> | ||
<Chip | ||
label="Basic Chip" | ||
className={classes.chip} | ||
/> | ||
<Chip | ||
avatar={<Avatar>MB</Avatar>} | ||
label="Clickable Chip" | ||
onClick={handleClick} | ||
className={classes.chip} | ||
/> | ||
<Chip | ||
avatar={<Avatar src={avatarImage} />} | ||
label="Deletable Chip" | ||
onRequestDelete={handleRequestDelete} | ||
className={classes.chip} | ||
/> | ||
<Chip | ||
avatar={<Avatar><Face className={classes.svgIcon} /></Avatar>} | ||
label="Clickable Deletable Chip" | ||
onClick={handleClick} | ||
onRequestDelete={handleRequestDelete} | ||
className={classes.chip} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
Chips.contextTypes = { | ||
styleManager: PropTypes.object.isRequired, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// @flow weak | ||
|
||
import React, { Component, PropTypes } from 'react'; | ||
import { createStyleSheet } from 'jss-theme-reactor'; | ||
import Chip from 'material-ui/Chip'; | ||
|
||
|
||
const styleSheet = createStyleSheet('ChipsArray', () => ({ | ||
chip: { | ||
margin: '0 4px', | ||
}, | ||
row: { | ||
display: 'flex', | ||
justifyContent: 'center', | ||
}, | ||
})); | ||
|
||
export default class ChipsArray extends Component { | ||
static contextTypes = { | ||
styleManager: PropTypes.object.isRequired, | ||
}; | ||
|
||
state = { chipData: [ | ||
{ key: 0, label: 'Angular' }, | ||
{ key: 1, label: 'JQuery' }, | ||
{ key: 2, label: 'Polymer' }, | ||
{ key: 3, label: 'ReactJS' }, | ||
{ key: 4, label: 'Vue.js' }, | ||
] }; | ||
|
||
styles = { | ||
chip: { | ||
margin: 4, | ||
}, | ||
wrapper: { | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
}, | ||
}; | ||
|
||
handleRequestDelete = (key) => { | ||
if (key === 3) { | ||
alert('Why would you want to delete React?! :)'); // eslint-ignore-line no-alert | ||
return; | ||
} | ||
|
||
const chipData = [...this.state.chipData]; | ||
const chipToDelete = chipData.indexOf(chipData.find((chip) => chip.key === key)); | ||
chipData.splice(chipToDelete, 1); | ||
this.setState({ chipData }); | ||
}; | ||
|
||
render() { | ||
const classes = this.context.styleManager.render(styleSheet); | ||
|
||
const renderChip = (data) => { | ||
return ( | ||
<Chip | ||
label={data.label} | ||
key={data.key} | ||
onRequestDelete={() => this.handleRequestDelete(data.key)} | ||
className={classes.chip} | ||
/> | ||
); | ||
}; | ||
|
||
return ( | ||
<div className={classes.row}> | ||
{this.state.chipData.map(renderChip, this)} | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Chips | ||
|
||
[Chips](https://www.google.com/design/spec/components/chips.html) | ||
represent complex entities in small blocks, such as a contact. | ||
|
||
While included here as a standalone component, the most common use will | ||
be in some form of input, so some of the behaviour demonstrated here is | ||
not shown in context. | ||
|
||
## Chip | ||
|
||
Examples of Chips, using an image Avatar, SVG Icon Avatar, "Letter" | ||
and (string) Avatar. | ||
Chips with the `onClick` property defined change appearance on focus, | ||
hover, and click. | ||
|
||
Chips with the `onRequestDelete` property defined will display a delete | ||
icon which changes appearance on hover. | ||
|
||
{{demo='demos/chips/Chips.js'}} | ||
|
||
## Chip array | ||
An example of rendering multiple Chips from an array of values. | ||
Deleting a chip removes it from the array. Note that since no | ||
`onClick` property is defined, the Chip can be focused, but does not | ||
gain depth while clicked or touched. | ||
|
||
{{demo='demos/chips/ChipsArray.js'}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.