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

[Toggle Button] Implemented new component for v1-beta (Issue #2863) #7551

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
dfccc2c
[ToggleButton] Added Toggle Button Component
xsh2047 Jun 22, 2017
a47b717
[ToggleButton] Added Toggle Button Component
xsh2047 Jun 22, 2017
c511a2c
[Toggle Button] Style changes as well as state bug fix
xsh2047 Jun 23, 2017
5550823
Updated with next branch
xsh2047 Jun 23, 2017
fe95337
[Docs] Added Documentation for Toggle Button
xsh2047 Jun 26, 2017
cc815c6
Merge branch 'v1-alpha' of https://github.com/callemall/material-ui i…
xsh2047 Jul 1, 2017
6f8c560
Merge branch 'v1-alpha' of https://github.com/callemall/material-ui i…
xsh2047 Jul 20, 2017
eaf0058
[Toggle Button] Changed color references
xsh2047 Jul 20, 2017
ee1186a
Merge branch 'v1-beta' of https://github.com/callemall/material-ui in…
xsh2047 Jul 25, 2017
1240848
[Toggle Button] Refactored for v1-beta branch
xsh2047 Jul 25, 2017
2b15588
[lint] Fixed various linting errors
xsh2047 Jul 26, 2017
4ab6bc5
Merge branch 'v1-beta' of https://github.com/callemall/material-ui in…
xsh2047 Jul 26, 2017
4b82ec5
[lint] Fixed various linting errors
xsh2047 Jul 26, 2017
f56d640
[ToggleButton] Renamed Option to ToggleButtonOption
xsh2047 Aug 5, 2017
c16be7e
[ToggleButton] Changed toggle icon behaviour to fit the Material UI S…
xsh2047 Aug 5, 2017
954d72f
[ToggleButton] Changed noBackground prop to toggle
xsh2047 Aug 5, 2017
880dda1
[ToggleButton] Added Support for Disabling a ToggleButtonOption with …
xsh2047 Aug 5, 2017
b744e73
[ToggleButton] Adjusted the issuing of keys to be done at the ToggleB…
xsh2047 Aug 5, 2017
d20a80f
[ToggleButton] Fixed lint errors
xsh2047 Aug 5, 2017
ccbb003
[ToggleButton] Up to date with v1-beta branch
xsh2047 Aug 6, 2017
53b3bf7
[ToggleButton] Generated yarn.lock files
xsh2047 Aug 6, 2017
2ca2eff
[ToggleButton] Made changes to Demos based on Pull Request Revision
xsh2047 Aug 6, 2017
bebf2b2
[ToggleButton] Made additional changes based on PR Revision
xsh2047 Aug 6, 2017
f4ed522
[ToggleButton] Updates SwitchBase.js to match the one on v1-beta
xsh2047 Aug 6, 2017
314be62
[ToggleButton] Replaced calls to React.createElement with JSX syntax
xsh2047 Aug 6, 2017
ad4108b
[ToggleButton] Merged functions onSelect and onDeselect into onChange
xsh2047 Aug 6, 2017
afaa431
[ToggleButton] Made alterations according to PR Revision and fixed li…
xsh2047 Aug 6, 2017
e6125ee
[ToggleButton] Removed duplicate calls in demo
xsh2047 Aug 6, 2017
ddbf62f
[ToggleButton] Fixed bug with Demo
xsh2047 Aug 6, 2017
ddf82fa
[ToggleButtons] Changed Toggle Icons color selection to match that of…
xsh2047 Aug 23, 2017
a81cace
[ToggleButtons] Fixed extra width added after mutiple items selected …
xsh2047 Aug 23, 2017
2e1d25b
[ToggleButton] Fixed lint and flow errors and wrote tests
xsh2047 Aug 24, 2017
1d89a19
[ToggleButton] Made changes according to feedback from PR and increas…
xsh2047 Aug 27, 2017
f00bbf3
[ToggleButton] Rebase with v1-beta branch
xsh2047 Aug 28, 2017
3325cb8
Merge branch 'v1-beta' of https://github.com/callemall/material-ui in…
xsh2047 Aug 28, 2017
e3af98b
[ToggleButton] Up-to-date with v1-beta branch
xsh2047 Aug 28, 2017
8e3208d
Merge branch 'v1-beta' of https://github.com/callemall/material-ui in…
xsh2047 Aug 28, 2017
49a07fa
[ToggleButton] Made adjustments to test case
xsh2047 Aug 28, 2017
956d4ec
[ToggleButton] Fixed lint errors
xsh2047 Aug 28, 2017
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
80 changes: 80 additions & 0 deletions docs/src/pages/demos/toggle-button/ExclusiveToggleButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// @flow

import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from 'material-ui/styles';
import ToggleButton, { ToggleButtonOption } from 'material-ui/ToggleButton';
import Icon from 'material-ui/Icon';
import Paper from 'material-ui/Paper';
import Typography from 'material-ui/Typography';

const styles = theme => ({
root: {
width: '100%',
},
paper: {
padding: theme.spacing.unit * 4,
'margin-top': theme.spacing.unit,
},
});

function alterText(value, selected) {
const div = document.getElementById('dummyDiv2');
if (selected && div !== null) {
switch (value) {
case '1':
div.style.textAlign = 'left';
break;
case '2':
div.style.textAlign = 'center';
break;
case '3':
div.style.textAlign = 'right';
break;
default:
break;
}
} else if (div !== null) {
div.style.textAlign = 'initial';
}
}

function ExclusiveToggleButton(props) {
const classes = props.classes;

return (
<div className={classes.root}>
<ToggleButton exclusive className="toggle">
<ToggleButtonOption
key="1"
icon={<Icon className="material-icons">format_align_left</Icon>}
value="1"
onChange={alterText}
/>
<ToggleButtonOption
key="2"
icon={<Icon className="material-icons">format_align_center</Icon>}
value="2"
onChange={alterText}
/>
<ToggleButtonOption
key="3"
icon={<Icon className="material-icons">format_align_right</Icon>}
value="3"
onChange={alterText}
/>
</ToggleButton>
<Paper id="dummyDiv2" className={classes.paper} elevation={4}>
<Typography type="headline" component="h3">
This text is gonna move.
</Typography>
</Paper>
</div>
);
}

ExclusiveToggleButton.propTypes = {
classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(ExclusiveToggleButton);
123 changes: 123 additions & 0 deletions docs/src/pages/demos/toggle-button/NormalToggleButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// @flow

import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from 'material-ui/styles';
import ToggleButton, { ToggleButtonOption } from 'material-ui/ToggleButton';
import Icon from 'material-ui/Icon';
import { MenuItem } from 'material-ui/Menu';
import Paper from 'material-ui/Paper';
import Typography from 'material-ui/Typography';

const styles = theme => ({
root: {
width: '100%',
},
paper: {
padding: theme.spacing.unit * 4,
'margin-top': theme.spacing.unit,
},
});

function alterText(value, selected) {
const text = document.getElementById('dummyText');
if (selected && text !== null) {
switch (value) {
case 1:
text.style.fontWeight = '800';
break;
case 2:
text.style.fontStyle = 'italic';
break;
case 3:
text.style.textDecoration = 'underline';
break;
default:
break;
}
} else if (text !== null) {
switch (value) {
case 1:
text.style.fontWeight = 'normal';
break;
case 2:
text.style.fontStyle = 'normal';
break;
case 3:
text.style.textDecoration = 'none';
break;
default:
break;
}
}
}

function alterColor(value, selected) {
const div = document.getElementById('dummyDiv');
if (selected && div !== null) {
if (value === 4) {
div.style.background = '#F44336';
} else if (value === 5) {
div.style.background = '#2196F3';
} else if (value === 6) {
div.style.background = '#009688';
}
} else if (div !== null) {
div.style.background = 'white';
}
}

function NormalToggleButton(props) {
const classes = props.classes;

return (
<div className={classes.root}>
<ToggleButton>
<ToggleButtonOption
key="1"
icon={<Icon className="material-icons">format_bold</Icon>}
value={1}
onChange={alterText}
/>
<ToggleButtonOption
key="2"
icon={<Icon className="material-icons">format_italic</Icon>}
value={2}
onChange={alterText}
/>
<ToggleButtonOption
key="3"
icon={<Icon className="material-icons">format_underline</Icon>}
value={3}
onChange={alterText}
/>
<ToggleButtonOption
key="4"
icon={<Icon className="material-icons">format_color_fill</Icon>}
onChange={alterColor}
>
<MenuItem key="1" value={4}>
Red
</MenuItem>
<MenuItem key="2" value={5}>
Blue
</MenuItem>
<MenuItem key="3cl" value={6}>
Green
</MenuItem>
</ToggleButtonOption>
</ToggleButton>
<Paper id="dummyDiv" className={classes.paper} elevation={4}>
<Typography id="dummyText" type="headline" component="h3">
Text to be edited.
</Typography>
</Paper>
</div>
);
}

NormalToggleButton.propTypes = {
classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(NormalToggleButton);
56 changes: 56 additions & 0 deletions docs/src/pages/demos/toggle-button/ToggleIcons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// @flow

import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from 'material-ui/styles';
import ToggleButton, { ToggleButtonOption } from 'material-ui/ToggleButton';
import Icon from 'material-ui/Icon';

const styles = {
root: {
background: 'lightgrey',
padding: 20,
},
};

function ToggleIcon(props) {
const classes = props.classes;

return (
<div className={classes.root}>
<ToggleButton toggleIcons>
<ToggleButtonOption key="1" icon={<Icon className="material-icons">mood</Icon>} value="1" />
<ToggleButtonOption
key="2"
icon={<Icon className="material-icons">mood_bad</Icon>}
value="1"
color="primary"
/>
<ToggleButtonOption
key="3"
icon={<Icon className="material-icons">whatshot</Icon>}
value="3"
color="contrast"
/>
<ToggleButtonOption
key="4"
icon={<Icon className="material-icons">favorite</Icon>}
value="4"
color="accent"
/>
<ToggleButtonOption
key="5"
icon={<Icon className="material-icons">grade</Icon>}
value="5"
disabled
/>
</ToggleButton>
</div>
);
}

ToggleIcon.propTypes = {
classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(ToggleIcon);
24 changes: 24 additions & 0 deletions docs/src/pages/demos/toggle-button/toggle-button.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
components: ToggleButtonOption, ToggleButton
---

# Toggle Buttons

[Toggle Buttons](https://material.io/guidelines/components/buttons.html#buttons-toggle-buttons) may be used to group related options.
Each option may be toggled on or off upon a user's click.

## Toggle Buttons Examples

Normal toggle button declared with no additional properties.

{{demo='pages/demos/toggle-button/NormalToggleButton.js'}}

Exclusive toggle button allowing only one option to be selected at a time.

{{demo='pages/demos/toggle-button/ExclusiveToggleButton.js'}}

## Toggle Icons

Icons are appropriate for toggle buttons that allow a single choice to be selected or deselected, such as adding or removing a star to an item.

{{demo='pages/demos/toggle-button/ToggleIcons.js'}}
6 changes: 1 addition & 5 deletions pages/api/app-bar.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## Props
| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| children | Element | | The content of the component. |
| children | Node | | The content of the component. |
| classes | Object | | Useful to extend the style applied to components. |
| color | union:&nbsp;'inherit'<br>&nbsp;'primary'<br>&nbsp;'accent'<br>&nbsp;'default'<br> | 'primary' | The color of the component. It's using the theme palette when that makes sense. |
| position | union:&nbsp;'static'<br>&nbsp;'fixed'<br>&nbsp;'absolute'<br> | 'fixed' | The positioning type. |
Expand Down Expand Up @@ -37,7 +37,3 @@ you need to use the following style sheet name: `MuiAppBar`.

The properties of the [&lt;Paper /&gt;](/api/paper) component are also available.

## Demos

- [App Bar](/demos/app-bar)

6 changes: 1 addition & 5 deletions pages/api/avatar.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
| alt | string | | Used in combination with `src` or `srcSet` to provide an alt attribute for the rendered `img` element. |
| children | Element | | Used to render icon or text elements inside the Avatar. `src` and `alt` props will not be used and no `img` will be rendered by default.<br>This can be an element, or just a string. |
| classes | Object | | Useful to extend the style applied to components. |
| component | union:&nbsp;string<br>&nbsp;Function<br> | 'div' | The component used for the root node. Either a string to use a DOM element or a component. |
| component | union:&nbsp;string<br>&nbsp;ComponentType<*><br> | 'div' | The component used for the root node. Either a string to use a DOM element or a component. |
| imgProps | Object | | Properties applied to the `img` element when the component is used to display an image. |
| sizes | string | | The `sizes` attribute for the `img` element. |
| src | string | | The `src` attribute for the `img` element. |
Expand All @@ -33,7 +33,3 @@ If using the `overrides` key of the theme as documented
[here](/customization/themes#customizing-all-instances-of-a-component-type),
you need to use the following style sheet name: `MuiAvatar`.

## Demos

- [Avatars](/demos/avatars)

4 changes: 0 additions & 4 deletions pages/api/badge.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,3 @@ If using the `overrides` key of the theme as documented
[here](/customization/themes#customizing-all-instances-of-a-component-type),
you need to use the following style sheet name: `MuiBadge`.

## Demos

- [Badges](/demos/badges)

9 changes: 0 additions & 9 deletions pages/api/bottom-navigation-button.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
## Props
| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| classes | object | | Useful to extend the style applied to components. |
| icon | node | | The icon element. If a string is provided, it will be used as a font ligature. |
| label | node | | The label element. |
| showLabel | bool | | If `true`, the BottomNavigationButton will show its label. |
| value | any | | You can provide your own value. Otherwise, we fallback to the child position index. |

Any other properties supplied will be spread to the root element.

Expand All @@ -38,7 +33,3 @@ you need to use the following style sheet name: `MuiBottomNavigationButton`.

The properties of the [&lt;ButtonBase /&gt;](/api/button-base) component are also available.

## Demos

- [Bottom Navigation](/demos/bottom-navigation)

4 changes: 0 additions & 4 deletions pages/api/bottom-navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,3 @@ If using the `overrides` key of the theme as documented
[here](/customization/themes#customizing-all-instances-of-a-component-type),
you need to use the following style sheet name: `MuiBottomNavigation`.

## Demos

- [Bottom Navigation](/demos/bottom-navigation)

20 changes: 7 additions & 13 deletions pages/api/button-base.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
## Props
| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| centerRipple | boolean | false | If `true`, the ripples will be centered. They won't start at the cursor interaction position. |
| children | Element | | The content of the component. |
| classes | Object | {} | Useful to extend the style applied to components. |
| component | union:&nbsp;string<br>&nbsp;Function<br> | | The component used for the root node. Either a string to use a DOM element or a component. The default value is a `button`. |
| disableRipple | boolean | false | If `true`, the ripple effect will be disabled. |
| disabled | boolean | | If `true`, the base button will be disabled. |
| focusRipple | boolean | false | If `true`, the base button will have a keyboard focus ripple. `disableRipple` must also be `false`. |
| keyboardFocusedClassName | string | | The CSS class applied while the component is keyboard focused. |
| onKeyboardFocus | Function | | Callback fired when the component is focused with a keyboard. We trigger a `onFocus` callback too.<br><br>**Signature:**<br>`function(event: object) => void`<br>*event:* The event source of the callback |
| centerRipple | | false | |
| classes | | {} | |
| disableRipple | | false | |
| focusRipple | | false | |
| <span style="color: #31a148">keyboardFocused *</span> | boolean | | |
| tabIndex | | '0' | |
| type | | 'button' | |

Any other properties supplied will be spread to the root element.

Expand All @@ -33,7 +31,3 @@ If using the `overrides` key of the theme as documented
[here](/customization/themes#customizing-all-instances-of-a-component-type),
you need to use the following style sheet name: `MuiButtonBase`.

## Demos

- [Buttons](/demos/buttons)

Loading