This repository has been archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Radio): radio button base implementation (#100)
* radio button base implementation * updating the changelog * updating Radio variables * cleaning the code; moving the input inside of the label for behavior compatibility * removing typings from example * adding type as propType * small style tweaks * changelog
- Loading branch information
Showing
12 changed files
with
149 additions
and
1 deletion.
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
6 changes: 6 additions & 0 deletions
6
docs/src/examples/components/Radio/Types/RadioExample.shorthand.tsx
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,6 @@ | ||
import React from 'react' | ||
import { Radio } from '@stardust-ui/react' | ||
|
||
const RadioExample = () => <Radio label="Make your choice" /> | ||
|
||
export default RadioExample |
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,15 @@ | ||
import React from 'react' | ||
import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' | ||
import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' | ||
|
||
const Types = () => ( | ||
<ExampleSection title="Types"> | ||
<ComponentExample | ||
title="Radio" | ||
description="A radio for checking." | ||
examplePath="components/Radio/Types/RadioExample" | ||
/> | ||
</ExampleSection> | ||
) | ||
|
||
export default Types |
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,10 @@ | ||
import * as React from 'react' | ||
import Types from './Types' | ||
|
||
const RadioExamples = () => ( | ||
<div> | ||
<Types /> | ||
</div> | ||
) | ||
|
||
export default RadioExamples |
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,63 @@ | ||
import * as React from 'react' | ||
import * as PropTypes from 'prop-types' | ||
|
||
import { createHTMLInput, customPropTypes, UIComponent } from '../../lib' | ||
import Label from '../Label' | ||
|
||
/** | ||
* @accessibility | ||
* This is shown at the top. | ||
*/ | ||
class Radio extends UIComponent<any, any> { | ||
static displayName = 'Radio' | ||
|
||
static className = 'ui-radio' | ||
|
||
static propTypes = { | ||
as: customPropTypes.as, | ||
|
||
/** Child content * */ | ||
children: PropTypes.node, | ||
|
||
/** Additional classes. */ | ||
className: PropTypes.string, | ||
|
||
/** The label of the radio input. */ | ||
label: PropTypes.string, | ||
|
||
/** Custom styles to be applied for component. */ | ||
styles: PropTypes.oneOfType([PropTypes.object, PropTypes.func]), | ||
|
||
/** The HTML input type. */ | ||
type: PropTypes.string, | ||
|
||
/** Custom variables to be applied for component. */ | ||
variables: PropTypes.oneOfType([PropTypes.object, PropTypes.func]), | ||
} | ||
|
||
static handledProps = ['as', 'children', 'className', 'label', 'styles', 'type', 'variables'] | ||
|
||
static defaultProps = { | ||
as: 'div', | ||
type: 'radio', | ||
} | ||
|
||
renderComponent({ ElementType, classes, rest, styles }) { | ||
const { type, label } = this.props | ||
|
||
return ( | ||
<ElementType {...rest} className={classes.root}> | ||
<Label styles={{ root: styles.label }}> | ||
{createHTMLInput(type, { | ||
overrideProps: { | ||
className: classes.radio, | ||
}, | ||
})} | ||
{label} | ||
</Label> | ||
</ElementType> | ||
) | ||
} | ||
} | ||
|
||
export default Radio |
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 @@ | ||
export { default } from './Radio' |
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
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,29 @@ | ||
import { IComponentPartStylesInput, ICSSInJSStyle } from '../../../../../types/theme' | ||
|
||
const radioStyles: IComponentPartStylesInput = { | ||
root: ({ props, variables }): ICSSInJSStyle => { | ||
return { | ||
outline: 0, | ||
display: 'inline-block', | ||
} | ||
}, | ||
|
||
radio: ({ props, variables }): ICSSInJSStyle => { | ||
return { | ||
marginRight: variables.radioMargin, | ||
} | ||
}, | ||
|
||
label: ({ props, variables }): ICSSInJSStyle => { | ||
return { | ||
cursor: 'pointer', | ||
display: 'inline-flex', | ||
alignItems: 'baseline', | ||
fontWeight: variables.fontWeight, | ||
minHeight: '2.5rem', | ||
backgroundColor: 'transparent', | ||
} | ||
}, | ||
} | ||
|
||
export default radioStyles |
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,10 @@ | ||
import { pxToRem } from '../../../../lib' | ||
|
||
export default (siteVars: any) => { | ||
const vars: any = {} | ||
|
||
vars.fontWeight = 400 | ||
vars.radioMargin = `${pxToRem(10)}` | ||
|
||
return vars | ||
} |
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,7 @@ | ||
import { isConformant } from 'test/specs/commonTests' | ||
|
||
import Radio from 'src/components/Radio' | ||
|
||
describe('Radio', () => { | ||
isConformant(Radio) | ||
}) |