Created
October 17, 2018 07:49
-
-
Save rhostem/2e19f048c4f4615da36a51a405cfb4a4 to your computer and use it in GitHub Desktop.
[React] radio group (text or input in label tag)
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
import React from 'react' | |
import styled from 'styled-components' | |
import { mixin } from 'styles' | |
const Wrap = styled.div` | |
${mixin.clearFix()}; | |
font-size: 14px; | |
&:not(:last-child) { | |
margin-right: 27px; | |
} | |
& > input { | |
display: none; | |
float: left; | |
} | |
& > input + label { | |
float: left; | |
display: inline-block; | |
position: relative; | |
padding-left: 30px; | |
margin-right: 20px; | |
min-width: 90px; | |
&:before { | |
${mixin.centeredY()}; | |
left: 0; | |
display: block; | |
width: 20px; | |
height: 20px; | |
content: ' '; | |
background: url('${ | |
process.env.REACT_APP_CDN_URL | |
}/admin/btn-radio-off.svg') no-repeat center; | |
background-size: contain; | |
} | |
&:hover { | |
cursor: pointer; | |
} | |
} | |
& > input:checked + label { | |
&:before { | |
background-image: url('${ | |
process.env.REACT_APP_CDN_URL | |
}/admin/btn-radio-on.svg'); | |
} | |
} | |
` | |
export default function RadioGroup({ children }) { | |
return <Wrap>{children}</Wrap> | |
} |
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
stories.add('RadioGroup', () => { | |
return ( | |
<div> | |
<h2>text</h2> | |
<RadioGroup> | |
<input id="1" type="radio" name="unique" value="1" /> | |
<label htmlFor="1">라벨1</label> | |
<input id="2" type="radio" name="unique" value="1" /> | |
<label htmlFor="2">라벨2</label> | |
</RadioGroup> | |
<h2>input</h2> | |
<RadioGroup> | |
<input id="input1" type="radio" name="radioInput" value="input1" /> | |
<label htmlFor="input1"> | |
<input type="text" /> | |
</label> | |
<input id="input2" type="radio" name="radioInput" value="input2" /> | |
<label htmlFor="input2" style={{ clear: 'left', marginTop: '10px' }}> | |
<input type="text" /> | |
</label> | |
</RadioGroup> | |
</div> | |
) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment