-
Notifications
You must be signed in to change notification settings - Fork 0
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
M1466 alternative toggle #22
Changes from all commits
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 |
---|---|---|
@@ -1,31 +1,54 @@ | ||
import React, { useState } from 'react' | ||
import Switch from 'react-switch' | ||
import PropTypes from 'prop-types' | ||
import raw from 'raw.macro' | ||
import React from 'react' | ||
import styled from 'styled-components/macro' | ||
import Toggle from 'react-toggle' | ||
|
||
/** | ||
* Describe your component | ||
*/ | ||
const ToggleCss = raw('react-toggle/style.css') | ||
|
||
const OfflineToggle = () => { | ||
const [checked, setChecked] = useState(false) | ||
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. Im thinking controlled input state can come later and will probably be in a parent component who owns offline status, or some custom hook instance. 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 agree, I'm thinking to store in a global state with context or redux. |
||
const ToggleWrapper = styled.div` | ||
${ToggleCss} | ||
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. dump the expected third party css in a styled component wrapper and override it with library classnames. |
||
& .react-toggle-track { | ||
height: 16px; | ||
width: 32px; | ||
} | ||
.react-toggle-thumb { | ||
top: 0px; | ||
left: 0px; | ||
height: 16px; | ||
width: 16px; | ||
} | ||
.react-toggle--checked .react-toggle-track { | ||
background-color: red; | ||
} | ||
.react-toggle--checked .react-toggle-thumb { | ||
left: 16px; | ||
border-color: red; | ||
} | ||
.react-toggle--checked:hover:not(.react-toggle--disabled) | ||
.react-toggle-track { | ||
background-color: darkred; | ||
} | ||
` | ||
|
||
const handleChange = (value) => setChecked(value) | ||
const OfflineToggle = ({ onChange }) => { | ||
const handleChange = (event) => { | ||
onChange(event.target.checked) | ||
} | ||
|
||
return ( | ||
<Switch | ||
id="offline-toggle-switch" | ||
aria-label="offline-toggle-switch" | ||
onChange={handleChange} | ||
checked={checked} | ||
onColor="#CC0A00" | ||
height={16} | ||
width={32} | ||
boxShadow="0px 1px 5px rgba(0, 0, 0, 0.6)" | ||
activeBoxShadow="0px 0px 1px 10px rgba(0, 0, 0, 0.2)" | ||
uncheckedIcon={false} | ||
/> | ||
<ToggleWrapper> | ||
<Toggle | ||
id="offline-toggle-switch" | ||
aria-label="offline-toggle-switch" | ||
onChange={handleChange} | ||
icons={false} | ||
/> | ||
</ToggleWrapper> | ||
) | ||
} | ||
|
||
OfflineToggle.propTypes = {} | ||
OfflineToggle.propTypes = { onChange: PropTypes.func } | ||
OfflineToggle.defaultProps = { onChange: () => {} } | ||
|
||
export default OfflineToggle |
This file was deleted.
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.
hack to get css without having it added globally. facebook/create-react-app#3722 (comment)
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.
this is cool