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

[Button] Add extended FAB variant #11941

Merged
merged 7 commits into from
Jun 22, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 12 additions & 0 deletions docs/src/pages/demos/buttons/FloatingActionButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ import Button from '@material-ui/core/Button';
import AddIcon from '@material-ui/icons/Add';
import Icon from '@material-ui/core/Icon';
import DeleteIcon from '@material-ui/icons/Delete';
import NavigationIcon from '@material-ui/icons/Navigation';

const styles = theme => ({
button: {
margin: theme.spacing.unit,
},
extendedIcon: {
marginLeft: theme.spacing.unit,
marginRight: theme.spacing.unit,
},
extendedLabel: {
marginRight: 12,
},
});

function FloatingActionButtons(props) {
Expand All @@ -22,6 +30,10 @@ function FloatingActionButtons(props) {
<Button variant="fab" color="secondary" aria-label="edit" className={classes.button}>
<Icon>edit_icon</Icon>
</Button>
<Button variant="extended-fab" aria-label="delete" className={classes.button}>
<NavigationIcon className={classes.extendedIcon} />
<span className={classes.extendedLabel}>Extended</span>
</Button>
<Button variant="fab" disabled aria-label="delete" className={classes.button}>
<DeleteIcon />
</Button>
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Button/Button.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface ButtonProps extends StandardProps<ButtonBaseProps, ButtonClassK
mini?: boolean;
size?: 'small' | 'medium' | 'large';
type?: string;
variant?: 'text' | 'flat' | 'outlined' | 'contained' | 'raised' | 'fab';
variant?: 'text' | 'flat' | 'outlined' | 'contained' | 'raised' | 'fab' | 'extended-fab';
}

export type ButtonClassKey =
Expand Down
23 changes: 19 additions & 4 deletions packages/material-ui/src/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const styles = theme => ({
},
},
label: {
width: '100%',
display: 'inherit',
alignItems: 'inherit',
justifyContent: 'inherit',
Expand Down Expand Up @@ -131,13 +130,19 @@ export const styles = theme => ({
padding: 0,
minWidth: 0,
width: 56,
fontSize: 24,
height: 56,
boxShadow: theme.shadows[6],
'&:active': {
boxShadow: theme.shadows[12],
},
},
extended: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is off:

  • property name: extended-fab
  • class name: extended

Maybe using extendedFab? for the variant name?

borderRadius: 24,
padding: 8,
width: 'initial',
minWidth: 48,
height: 48,
},
mini: {
width: 40,
height: 40,
Expand Down Expand Up @@ -175,14 +180,16 @@ function Button(props) {
...other
} = props;

const fab = variant === 'fab';
const extended = variant === 'extended-fab';
const fab = variant === 'fab' || extended;
const contained = variant === 'contained' || variant === 'raised';
const text = !contained && !fab;
const className = classNames(
classes.root,
{
[classes.contained]: contained || fab,
[classes.fab]: fab,
[classes.extended]: extended,
[classes.mini]: fab && mini,
[classes.colorInherit]: color === 'inherit',
[classes.textPrimary]: text && color === 'primary',
Expand Down Expand Up @@ -282,7 +289,15 @@ Button.propTypes = {
/**
* The type of button.
*/
variant: PropTypes.oneOf(['text', 'flat', 'outlined', 'contained', 'raised', 'fab']),
variant: PropTypes.oneOf([
'text',
'flat',
'outlined',
'contained',
'raised',
'fab',
'extended-fab',
]),
};

Button.defaultProps = {
Expand Down
28 changes: 28 additions & 0 deletions packages/material-ui/src/Button/Button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,34 @@ describe('<Button />', () => {
'should have the contained class',
);
assert.strictEqual(wrapper.hasClass(classes.fab), true, 'should have the fab class');
assert.strictEqual(
wrapper.hasClass(classes.extended),
false,
'should not have the extended class',
);
assert.strictEqual(wrapper.hasClass(classes.flat), false, 'should not have the flat class');
assert.strictEqual(
wrapper.hasClass(classes.textPrimary),
false,
'should not have the textPrimary class',
);
assert.strictEqual(
wrapper.hasClass(classes.textSecondary),
false,
'should not have the textSecondary class',
);
});

it('should render an extended floating action button', () => {
const wrapper = shallow(<Button variant="extended-fab">Hello World</Button>);
assert.strictEqual(wrapper.hasClass(classes.root), true, 'should have the root class');
assert.strictEqual(
wrapper.hasClass(classes.contained),
true,
'should have the contained class',
);
assert.strictEqual(wrapper.hasClass(classes.fab), true, 'should have the fab class');
assert.strictEqual(wrapper.hasClass(classes.extended), true, 'should have the extended class');
assert.strictEqual(wrapper.hasClass(classes.flat), false, 'should not have the flat class');
assert.strictEqual(
wrapper.hasClass(classes.textPrimary),
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/styles/MuiThemeProvider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('<MuiThemeProvider />', () => {
assert.notStrictEqual(markup.match('Hello World'), null);
assert.strictEqual(sheetsRegistry.registry.length, 3);
assert.strictEqual(sheetsRegistry.toString().length > 4000, true);
assert.strictEqual(sheetsRegistry.registry[0].classes.root, 'MuiTouchRipple-root-26');
assert.strictEqual(sheetsRegistry.registry[0].classes.root, 'MuiTouchRipple-root-27');
assert.deepEqual(
sheetsRegistry.registry[1].classes,
{
Expand Down
3 changes: 2 additions & 1 deletion pages/api/button.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ filename: /packages/material-ui/src/Button/Button.js
| <span class="prop-name">href</span> | <span class="prop-type">string |   | The URL to link to when the button is clicked. If defined, an `a` element will be used as the root node. |
| <span class="prop-name">mini</span> | <span class="prop-type">bool | <span class="prop-default">false</span> | If `true`, and `variant` is `'fab'`, will use mini floating action button styling. |
| <span class="prop-name">size</span> | <span class="prop-type">enum:&nbsp;'small'&nbsp;&#124;<br>&nbsp;'medium'&nbsp;&#124;<br>&nbsp;'large'<br> | <span class="prop-default">'medium'</span> | The size of the button. `small` is equivalent to the dense button styling. |
| <span class="prop-name">variant</span> | <span class="prop-type">enum:&nbsp;'text', 'flat', 'outlined', 'contained', 'raised', 'fab'<br> | <span class="prop-default">'text'</span> | The type of button. |
| <span class="prop-name">variant</span> | <span class="prop-type">enum:&nbsp;'text', 'flat', 'outlined', 'contained', 'raised', 'fab', 'extended-fab'<br> | <span class="prop-default">'text'</span> | The type of button. |

Any other properties supplied will be spread to the root element ([ButtonBase](/api/button-base)).

Expand All @@ -49,6 +49,7 @@ This property accepts the following keys:
- `focusVisible`
- `disabled`
- `fab`
- `extended`
- `mini`
- `sizeSmall`
- `sizeLarge`
Expand Down