-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Changes from 13 commits
dfccc2c
a47b717
c511a2c
5550823
fe95337
cc815c6
6f8c560
eaf0058
ee1186a
1240848
2b15588
4ab6bc5
4b82ec5
f56d640
c16be7e
954d72f
880dda1
b744e73
d20a80f
ccbb003
53b3bf7
2ca2eff
bebf2b2
f4ed522
314be62
ad4108b
afaa431
e6125ee
ddbf62f
ddf82fa
a81cace
2e1d25b
1d89a19
f00bbf3
3325cb8
e3af98b
8e3208d
49a07fa
956d4ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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', { | ||
root: { | ||
width: '100%', | ||
}, | ||
paper: { | ||
padding: 30, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using a multiplier of |
||
}, | ||
}); | ||
|
||
function ExclusiveToggleButton(props) { | ||
const classes = props.classes; | ||
|
||
function alignRight() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); |
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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can we can find a better wording for |
||
<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); |
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); |
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'}} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra lines |
||
|
There was a problem hiding this comment.
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 :)