-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4c00eb
commit ec95f95
Showing
3 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components/macro'; | ||
|
||
interface Props { | ||
id: string; | ||
label: string; | ||
className?: string; | ||
|
||
// TODO: extend RadioInputProps automatically | ||
onChange(e: any): void; | ||
name: string; | ||
value: string; | ||
} | ||
|
||
export default function Radio({ id, label, className, ...restOf }: Props) { | ||
return ( | ||
<Wrapper className={className}> | ||
<RadioInput id={id} {...restOf} /> | ||
<label htmlFor={id}>{label}</label> | ||
</Wrapper> | ||
); | ||
} | ||
|
||
const Wrapper = styled.div``; | ||
|
||
const RadioInput = styled.input.attrs({ type: 'radio' })` | ||
margin: 0; | ||
opacity: 0; | ||
width: 0; | ||
height: 0; | ||
padding: 0; | ||
+ label { | ||
margin: 0; | ||
display: inline-block; | ||
padding-left: 1.375rem; | ||
padding-top: 0.0625rem; | ||
position: relative; | ||
cursor: pointer; | ||
font-size: 0.875rem; | ||
a { | ||
color: ${p => p.theme.text}; | ||
text-decoration: none; | ||
} | ||
&::before { | ||
position: absolute; | ||
top: 0.25rem; | ||
left: 0; | ||
display: inline-block; | ||
width: 1rem; | ||
height: 1rem; | ||
border-radius: 50%; | ||
background-color: ${p => p.theme.background}; | ||
content: ''; | ||
border: 2px solid ${p => p.theme.border}; | ||
transition: all 0.1s; | ||
} | ||
&::after { | ||
display: none; | ||
content: ''; | ||
position: absolute; | ||
display: inline-block; | ||
width: 0.375rem; | ||
height: 0.375rem; | ||
border-radius: 50%; | ||
top: 0.5625rem; | ||
left: 0.3125rem; | ||
background-color: ${p => p.theme.background}; | ||
} | ||
&:hover { | ||
&::before { | ||
border-color: ${p => p.theme.primary}; | ||
} | ||
} | ||
} | ||
&:disabled { | ||
+ label { | ||
opacity: 0.6; | ||
cursor: auto; | ||
&:hover { | ||
&::before { | ||
border-color: ${p => p.theme.border}; | ||
} | ||
} | ||
} | ||
} | ||
&:focus { | ||
+ label { | ||
&::before { | ||
box-shadow: 0 0 0 3px | ||
${p => | ||
p.theme.primary.replace( | ||
/rgba?(\(\s*\d+\s*,\s*\d+\s*,\s*\d+)(?:\s*,.+?)?\)/, | ||
'rgba$1,0.2)', | ||
)}; | ||
} | ||
} | ||
} | ||
&:checked { | ||
+ label { | ||
&::before { | ||
background-color: ${p => p.theme.primary}; | ||
border-color: ${p => p.theme.primary}; | ||
} | ||
&::after { | ||
display: inline-block; | ||
} | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from 'react'; | ||
import FormLabel from 'components/FormLabel'; | ||
import Radio from 'components/Radio'; | ||
import styled from 'styled-components/macro'; | ||
|
||
export default function ThemeSwitch() { | ||
const handleThemeChange = (e: any) => { | ||
console.log(e.target.value); | ||
}; | ||
return ( | ||
<Wrapper> | ||
<FormLabel>Select Theme</FormLabel> | ||
<Themes> | ||
<Radio | ||
id="default" | ||
label="Default" | ||
className="radio" | ||
name="theme" | ||
onChange={handleThemeChange} | ||
value="default" | ||
/> | ||
<Radio | ||
id="light" | ||
label="Light" | ||
className="radio" | ||
name="theme" | ||
onChange={handleThemeChange} | ||
value="light" | ||
/> | ||
<Radio | ||
id="dark" | ||
label="Dark" | ||
className="radio" | ||
name="theme" | ||
onChange={handleThemeChange} | ||
value="dark" | ||
/> | ||
</Themes> | ||
</Wrapper> | ||
); | ||
} | ||
|
||
const Wrapper = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
${FormLabel} { | ||
margin-bottom: 0.625rem; | ||
} | ||
`; | ||
const Themes = styled.div` | ||
display: flex; | ||
.radio { | ||
margin-right: 1.5rem; | ||
} | ||
`; |