Skip to content

Instantly share code, notes, and snippets.

@olecksamdr
Created October 24, 2018 06:05
Show Gist options
  • Save olecksamdr/37bdf2cd36075b54153c78b3719cb1bd to your computer and use it in GitHub Desktop.
Save olecksamdr/37bdf2cd36075b54153c78b3719cb1bd to your computer and use it in GitHub Desktop.
Radio button which looks like button
import React from 'react';
import { string } from 'prop-types';
import styled from 'styled-components';
import { getThemeColor } from 'utils/theme';
const Label = styled.label`
padding: 12px 20px;
display:block;
cursor: pointer;
text-align: center;
border-radius: 4px;
background-color: ${getThemeColor(['cloudLight'])};
`;
const HiddenInput = styled.input.attrs({ type: 'radio' })`
position: absolute;
clip: rect(0,0,0,0);
pointer-events: none;
&:checked ~ ${Label} {
background-color: ${getThemeColor(['inkLighter'])};
color: ${getThemeColor(['white'])};
}
`;
const RadioButton = ({ label, id, ...props }) => (
<div>
<HiddenInput {...{ id }} {...props} />
<Label htmlFor={id}>{label}</Label>
</div>
);
RadioButton.propTypes = {
label: string.isRequired,
id: string.isRequired,
};
export default RadioButton;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment