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 13 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// @flow

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

const styleSheet = createStyleSheet('ExclusiveToggleButton', {
Copy link
Member

Choose a reason for hiding this comment

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

You do no longer need to provide the sheet name. We have removed it from all our demo example. Please do the same here :)

root: {
width: '100%',
},
paper: {
padding: 30,
Copy link
Member

Choose a reason for hiding this comment

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

using a multiplier of theme.spacing.unit would be better.

},
});

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

function alignRight() {
Copy link
Member

Choose a reason for hiding this comment

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

Can't those functions be defined in the parent scope? The issue right not is that they are going to be created at each render.

document.getElementById('dummyDiv2').style.textAlign = 'right';
}

function alignCenter() {
document.getElementById('dummyDiv2').style.textAlign = 'center';
}

function alignLeft() {
document.getElementById('dummyDiv2').style.textAlign = 'left';
}

function alignReset() {
document.getElementById('dummyDiv2').style.textAlign = 'initial';
}

return (
<div className={classes.root}>
<ToggleButton exclusive className="toggle">
Copy link
Member

Choose a reason for hiding this comment

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

What's the className is for? I don't think that you need it.

Copy link
Author

Choose a reason for hiding this comment

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

It's so that the paper is full width, without it it's width only spans it's contents.

<Option
icon={<Icon className="material-icons">format_align_left</Icon>}
value="1"
onSelect={alignLeft}
onDeselect={alignReset}
/>
<Option
icon={<Icon className="material-icons">format_align_center</Icon>}
value="2"
onSelect={alignCenter}
onDeselect={alignReset}
/>
<Option
icon={<Icon className="material-icons">format_align_right</Icon>}
value="3"
onSelect={alignRight}
onDeselect={alignReset}
/>
</ToggleButton>

Copy link
Member

Choose a reason for hiding this comment

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

We almost never use blank line between the components.

<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(styleSheet)(ExclusiveToggleButton);
106 changes: 106 additions & 0 deletions docs/src/pages/component-demos/toggle-button/NormalToggleButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// @flow

import React from 'react';
import PropTypes from 'prop-types';
import { withStyles, createStyleSheet } from 'material-ui/styles';
import ToggleButton, { Option } 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 styleSheet = createStyleSheet('NormalToggleButton', {
root: {
width: '100%',
},
paper: {
padding: 30,
},
});

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

function changeColor(value) {
const div = document.getElementById('dummyDiv').style;
if (value === 4) {
div.background = '#F44336';
} else if (value === 5) {
div.background = '#2196F3';
} else if (value === 6) {
div.background = '#009688';
}
}

function colorReset() {
document.getElementById('dummyDiv').style.background = 'white';
}

function changeText(value) {
const text = document.getElementById('dummyText').style;
if (value === 1) {
text.fontWeight = 800;
} else if (value === 2) {
text.fontStyle = 'italic';
} else if (value === 3) {
text.textDecoration = 'underline';
}
}

function resetText(value) {
const text = document.getElementById('dummyText').style;
if (value === 1) {
text.fontWeight = 'normal';
} else if (value === 2) {
text.fontStyle = 'normal';
} else if (value === 3) {
text.textDecoration = 'none';
}
}

return (
<div className={classes.root}>
<ToggleButton>
<Option
icon={<Icon className="material-icons">format_bold</Icon>}
value={1}
onSelect={changeText}
onDeselect={resetText}
/>
<Option
icon={<Icon className="material-icons">format_italic</Icon>}
value={2}
onSelect={changeText}
onDeselect={resetText}
/>
<Option
icon={<Icon className="material-icons">format_underline</Icon>}
value={3}
onSelect={changeText}
onDeselect={resetText}
/>
<Option
icon={<Icon className="material-icons">format_color_fill</Icon>}
onSelect={changeColor}
onDeselect={colorReset}
>
<MenuItem value={4}>Red</MenuItem>
<MenuItem value={5}>Blue</MenuItem>
<MenuItem value={6}>Green</MenuItem>
</Option>
</ToggleButton>
Copy link
Member

@kgregory kgregory Jul 31, 2017

Choose a reason for hiding this comment

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

I don't think this should be part of the demo because it doesn't seem to be in the scope of a toggle button's user experience. I think this is more like a dropdown button.

It could work if this were a segmented dropdown button and the left segment could be used to toggle the selection.

Hopefully we can open a discussion on this.

Copy link
Author

Choose a reason for hiding this comment

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

Hopefully, based on the discussion for the previously raised query we can resolve this.


<Paper id="dummyDiv" className={classes.paper} elevation={4}>
Copy link
Member

Choose a reason for hiding this comment

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

I can we can find a better wording for #dummyDiv.

<Typography id="dummyText" type="headline" component="h3">
Text to be edited.
</Typography>
</Paper>
</div>
);
}

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

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

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

const styleSheet = createStyleSheet('NormalToggleButton', {
root: {
width: '100%',
},
});

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

return (
<div className={classes.root}>
<ToggleButton toggleIcons>
<Option icon={<Icon className="material-icons">mood</Icon>} value="1" />
<Option icon={<Icon className="material-icons">mood_bad</Icon>} value="1" />
<Option icon={<Icon className="material-icons">whatshot</Icon>} value="3" />
</ToggleButton>
</div>
);
}

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

export default withStyles(styleSheet)(ToggleIcon);
27 changes: 27 additions & 0 deletions docs/src/pages/component-demos/toggle-button/toggle-button.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
components: Option, 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/component-demos/toggle-button/NormalToggleButton.js'}}

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

{{demo='pages/component-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/component-demos/toggle-button/ToggleIcons.js'}}


Copy link
Member

Choose a reason for hiding this comment

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

Extra lines


Loading