Skip to content

Add props to customize on/off colors #4

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ node_js:
- '4'

before_install:
- npm install -g npm
- npm --version

after_success:
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ console.log(this.toggleSwitch.checked);
<td>'lg'</td>
<td></td>
</tr>
<tr>
<td>onColor</td>
<td>string / hex</td>
<td>'#ff0000'</td>
<td>Color when state is ON</td>
</tr>
<tr>
<td>offColor</td>
<td>string / hex</td>
<td>'#009000'</td>
<td>Color when state is OFF</td>
</tr>
</tbody>
</table>

Expand Down
53 changes: 53 additions & 0 deletions examples/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,59 @@ class App extends React.Component {
</div>
</div>
</div>
<div className="row">
<div className="col-sm-6">
<div className="panel panel-default">
<div className="panel-heading">
<div className="panel-title">
Colored
</div>
</div>
<div className="panel-body">
<div className="container-fluid">
<div className="row">
<div className="col-sm-6" style={{ minHeight: 40, padding: '8px 0' }}>
<ToggleSwitch
onColor="green"
checked
size="lg"
/>
ON Green
</div>
<div className="col-sm-6" style={{ minHeight: 40, padding: '8px 0' }}>
<ToggleSwitch
onColor="green"
disabled
checked
size="lg"
/>
ON Green (Disabled)
</div>
</div>
<div className="row">
<div className="col-sm-6" style={{ minHeight: 40, padding: '8px 0' }}>
<ToggleSwitch
offColor="red"
checked={false}
size="lg"
/>
OFF Red
</div>
<div className="col-sm-6" style={{ minHeight: 40, padding: '8px 0' }}>
<ToggleSwitch
onColor="green"
offColor="red"
checked
size="lg"
/>
ON / OFF (Red / Green)
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@trendmicro/react-toggle-switch",
"version": "0.5.7",
"version": "0.5.8",
"description": "Trend Micro Components: React Toggle Switch",
"main": "lib/index.js",
"files": [
Expand Down
5 changes: 5 additions & 0 deletions src/ToggleSwitch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ class ToggleSwitch extends PureComponent {
className,
disabled,
size,
onColor,
offColor,
...props
} = this.props;

delete props.checked;
delete props.onChange;

const color = this.state.checked ? onColor : offColor;

return (
<Anchor
{...props}
Expand All @@ -79,6 +83,7 @@ class ToggleSwitch extends PureComponent {
styles.round,
{ [styles.disabled]: disabled }
)}
style={{ backgroundColor: color, borderColor: color }}
/>
</Anchor>
);
Expand Down