Skip to content

Commit

Permalink
fix(community-toggle-switch): design changes and refactoring
Browse files Browse the repository at this point in the history
BREAKING CHANGE: add styled-components to peerDependencies
BREAKING CHANGE: default style changes
  • Loading branch information
nicmak authored and jraff committed Sep 30, 2019
1 parent bb20e07 commit f813eeb
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 112 deletions.
24 changes: 9 additions & 15 deletions packages/ToggleSwitch/ToggleSwitch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@ import Box from '@tds/core-box'
import Tooltip from '@tds/core-tooltip'
import Spinner from '@tds/core-spinner'
import FlexGrid from '@tds/core-flex-grid'
import {
HiddenInput,
Slider,
Switch,
InputSwitchWrapper,
SwitchWrapper,
SpinnerWrapper,
} from './styles'
import { Button, Slider, Switch, InputSwitchWrapper, SpinnerWrapper } from './styles'

/**
* ToggleSwitch is an alternative to using a checkbox, and maintains a similar component interface to [@tds/core-checkbox](https://tds.telus.com/components/index.html#checkbox).
Expand All @@ -38,7 +31,6 @@ class ToggleSwitch extends Component {

onChange = event => {
const { onChange } = this.props

if (onChange) {
event.persist()
onChange(event)
Expand Down Expand Up @@ -98,20 +90,22 @@ class ToggleSwitch extends Component {
</FlexGrid.Col>
<FlexGrid.Col xs={1} xsOffset={2} mdOffset={3} lgOffset={3} xlOffset={4}>
<InputSwitchWrapper>
<HiddenInput
<Button
{...safeRest(rest)}
id={id}
type="checkbox"
role="switch"
aria-checked={this.state.checked}
name={name}
value={value}
checked={this.state.checked}
isLoading={isLoading}
disabled={disabled}
aria-labelledby={labelledById}
onChange={this.onChange}
data-testid={`${id}-switch`}
onClick={this.onChange}
onFocus={this.onFocus}
onBlur={this.onBlur}
/>
<SwitchWrapper>
>
<Switch
data-testid={`${id}-switch`}
aria-checked={this.state.checked}
Expand All @@ -124,7 +118,7 @@ class ToggleSwitch extends Component {
<SpinnerWrapper switchOn={this.state.checked && isLoading}>
<Spinner tag="span" spinning size="small" />
</SpinnerWrapper>
</SwitchWrapper>
</Button>
</InputSwitchWrapper>
</FlexGrid.Col>
</FlexGrid.Row>
Expand Down
6 changes: 3 additions & 3 deletions packages/ToggleSwitch/__tests__/ToggleSwitch.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('ToggleSwitch', () => {
const toggleSwitch = mount(<ToggleSwitch {...defaultProps} />)
expect(
toggleSwitch
.find(`styles__HiddenInput#${defaultProps.id}`)
.find(`styles__Button#${defaultProps.id}`)
.children(0)
.prop('checked')
).toEqual(false)
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('ToggleSwitch', () => {
toggleSwitch
.find(`#${defaultProps.id}`)
.at(0)
.simulate('change')
.simulate('click')

expect(
toggleSwitch
Expand All @@ -113,7 +113,7 @@ describe('ToggleSwitch', () => {
toggleSwitch
.find(`#${defaultProps.id}`)
.at(0)
.simulate('change', mockEvent)
.simulate('click', mockEvent)

// Checked state should remain false instead of toggling
expect(
Expand Down
Loading

0 comments on commit f813eeb

Please sign in to comment.