Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Font Icons] Google material icons support #1024

Merged
merged 1 commit into from
Jul 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions docs/src/app/components/pages/components/icon-buttons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class IconButtonsPage extends React.Component {
'<IconButton tooltip="Sort" disabled={true}>\n' +
' <FontIcon className="muidocs-icon-custom-sort"/>\n' +
'</IconButton>\n\n' +
'//Adding tooltipPosition to Icon Button\n' +
'<IconButton iconClassName="muidocs-icon-custom-github" tooltip="bottom-right"\n' +
' tooltipPosition="bottom-right"/>\n';
'//Method 4: Using Google material-icons\n' +
' <IconButton className="material-icons" tooltipAlignment="bottom-center" \n' +
' tooltip="Sky">settings_system_daydream</IconButton>';

let desc = (
<p>
Expand All @@ -50,6 +50,10 @@ class IconButtonsPage extends React.Component {
similiar to how the iconClassName prop from method 1 is
handled.
</li>
<li>
Google Material Icons: Now also supported for iconButtons by passing "material-icons" in
iconClassName prop.
</li>
</ol>
</p>
);
Expand Down Expand Up @@ -168,6 +172,9 @@ class IconButtonsPage extends React.Component {
<IconButton tooltip="Sort" disabled={true}>
<FontIcon className="muidocs-icon-custom-sort"/>
</IconButton>
<br/><br/><br/>

<IconButton iconClassName="material-icons" tooltip="Sky">settings_system_daydream</IconButton>
</ComponentDoc>
);

Expand Down
17 changes: 4 additions & 13 deletions src/icon-button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,6 @@ let IconButton = React.createClass({
};
},

componentDidMount() {
if (process.env.NODE_ENV !== 'production') {
if (this.props.iconClassName && this.props.children) {
let warning = 'You have set both an iconClassName and a child icon. ' +
'It is recommended you use only one method when adding ' +
'icons to IconButtons.';
console.warn(warning);
}
}
},

getStyles() {
let spacing = this.context.muiTheme.spacing;
let palette = this.context.muiTheme.palette;
Expand All @@ -71,7 +60,8 @@ let IconButton = React.createClass({
transition: Transitions.easeOut(),
padding: spacing.iconSize / 2,
width: spacing.iconSize*2,
height: spacing.iconSize*2
height: spacing.iconSize*2,
fontSize: 0
},
tooltip: {
boxSizing: 'border-box',
Expand Down Expand Up @@ -133,7 +123,8 @@ let IconButton = React.createClass({
styles.icon,
disabled ? styles.disabled : {},
iconStyleFontIcon
)}/>
)}>
{this.props.children}</FontIcon>
);
}

Expand Down
17 changes: 9 additions & 8 deletions src/utils/children.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ module.exports = {

extend(children, extendedProps, extendedChildren) {

return React.Children.map(children, (child) => {
return React.isValidElement(children) ?
React.Children.map(children, (child) => {

let newProps = typeof(extendedProps) === 'function' ?
extendedProps(child) : extendedProps;
let newProps = typeof(extendedProps) === 'function' ?
extendedProps(child) : extendedProps;

let newChildren = typeof(extendedChildren) === 'function' ?
extendedChildren(child) : extendedChildren ?
extendedChildren : child.props.children;
let newChildren = typeof(extendedChildren) === 'function' ?
extendedChildren(child) : extendedChildren ?
extendedChildren : child.props.children;

return React.cloneElement(child, newProps, newChildren);
});
return React.cloneElement(child, newProps, newChildren);
}) : children;
}

};