-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add radio form elements, make checkbox ids required (#65)
* add radios, make id required in checkboxes, and adjust gitignore * adjust css to feedback
- Loading branch information
Showing
18 changed files
with
308 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ lib/ | |
package-lock.json | ||
npm-debug.log | ||
.eslintcache | ||
.yo-rc.json | ||
tmp/ |
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
.euiForm__error { | ||
@include euiFontSizeS; | ||
list-style: disc; | ||
margin-left: $euiSizeXL; | ||
} | ||
|
||
.euiForm__errors { | ||
|
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
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,2 @@ | ||
@import 'radio'; | ||
@import 'radio_group'; |
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,70 @@ | ||
.euiRadio { | ||
position: relative; | ||
height: $euiSizeL; | ||
|
||
/** | ||
* 1. Float above the visual radio and match its dimension, so that when users try to click it | ||
* they actually click this input. | ||
*/ | ||
.euiRadio__input { | ||
position: absolute; /* 1 */ | ||
opacity: 0; /* 1 */ | ||
height: $euiSizeL; /* 1 */ | ||
width: $euiSizeL; /* 1 */ | ||
z-index: 1; /* 1 */ | ||
margin: 0; /* 1 */ | ||
cursor: pointer; | ||
|
||
&:checked ~ .euiRadio__circle { | ||
.euiRadio__check { | ||
background-color: $euiTextColor; | ||
// This path is relative to ~/docs/postcss.config.js, which uses | ||
// the postcss-line-svg plugin. | ||
mask: svg-load('../src/components/icon/assets/check.svg') center center no-repeat; | ||
} | ||
} | ||
|
||
&:focus ~ .euiRadio__circle, | ||
&:active:not(:disabled) ~ .euiRadio__circle { | ||
background-color: $euiFocusBackgroundColor; | ||
border-color: $euiColorPrimary; | ||
} | ||
|
||
&:disabled { | ||
|
||
~ .euiRadio__circle { | ||
background-color: $euiColorLightestShade; | ||
} | ||
|
||
~ .euiRadio__label { | ||
cursor: not-allowed; | ||
} | ||
} | ||
} | ||
|
||
.euiRadio__circle { | ||
position: absolute; | ||
height: $euiSizeL; | ||
width: $euiSizeL; | ||
border-radius: 50%; | ||
border: $euiBorderThin; | ||
background: $euiFormBackgroundColor; | ||
z-index: 0; | ||
} | ||
|
||
.euiRadio__check { | ||
height: 100%; | ||
width: 100%; | ||
} | ||
|
||
.euiRadio__label { | ||
position: absolute; | ||
padding-left: $euiSizeXL; | ||
line-height: $euiSizeL; | ||
display: block; | ||
font-weight: $euiFontWeightRegular; | ||
z-index: 2; | ||
font-size: $euiFontSizeS; | ||
cursor: pointer; | ||
} | ||
} |
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,3 @@ | ||
.euiRadioGroup__item + .euiRadioGroup__item { | ||
margin-top: $euiSizeS; | ||
} |
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 @@ | ||
export { | ||
EuiRadio, | ||
} from './radio'; | ||
|
||
export { | ||
EuiRadioGroup, | ||
} from './radio_group'; |
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,67 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
|
||
export const EuiRadio = ({ | ||
className, | ||
id, | ||
checked, | ||
label, | ||
onChange, | ||
disabled, | ||
...rest, | ||
}) => { | ||
const classes = classNames( | ||
'euiRadio', | ||
className | ||
); | ||
|
||
let optionalLabel; | ||
|
||
if (label) { | ||
optionalLabel = ( | ||
<label | ||
className="euiRadio__label" | ||
htmlFor={id} | ||
> | ||
{label} | ||
</label> | ||
); | ||
} | ||
|
||
return ( | ||
<div | ||
className={classes} | ||
{...rest} | ||
> | ||
<input | ||
className="euiRadio__input" | ||
type="radio" | ||
id={id} | ||
checked={checked} | ||
onChange={onChange} | ||
disabled={disabled} | ||
/> | ||
|
||
<div className="euiRadio__circle"> | ||
<div className="euiRadio__check" /> | ||
</div> | ||
|
||
{optionalLabel} | ||
</div> | ||
); | ||
}; | ||
|
||
EuiRadio.propTypes = { | ||
className: PropTypes.string, | ||
id: PropTypes.string.isRequired, | ||
checked: PropTypes.bool.isRequired, | ||
label: PropTypes.string, | ||
onChange: PropTypes.func.isRequired, | ||
disabled: PropTypes.bool, | ||
}; | ||
|
||
EuiRadio.defaultProps = { | ||
checked: false, | ||
disabled: false, | ||
}; |
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,16 @@ | ||
import React from 'react'; | ||
import { render } from 'enzyme'; | ||
import { requiredProps } from '../../test/required_props'; | ||
|
||
import { EuiRadio } from './radio'; | ||
|
||
describe('EuiRadio', () => { | ||
test('is rendered', () => { | ||
const component = render( | ||
<EuiRadio {...requiredProps} /> | ||
); | ||
|
||
expect(component) | ||
.toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.