-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add CheckablePanel and type Checkbox and CheckboxGroup * Add changelog entry * Fix responsiveness * Update package.json Co-Authored-By: Chandler Prall <[email protected]> * Update src/components/form/checkbox/checkbox.tsx Co-Authored-By: Chandler Prall <[email protected]> * Update src/components/form/checkbox/checkbox.tsx Co-Authored-By: Chandler Prall <[email protected]> * Update src/components/form/checkbox/checkbox.tsx Co-Authored-By: Chandler Prall <[email protected]> * Update src/components/form/checkbox/checkbox.tsx Co-Authored-By: Chandler Prall <[email protected]> * Update src/components/form/checkbox/checkbox_group.tsx Co-Authored-By: Chandler Prall <[email protected]> * Update src/components/form/checkbox/checkbox_group.tsx Co-Authored-By: Chandler Prall <[email protected]> * Update src/components/form/checkbox/checkbox_group.tsx Co-Authored-By: Chandler Prall <[email protected]> * Address PR feedback * Cleanup * Moved example to Card page * Renamed `EuiCheckablePanel` -> `EuiCheckableCard` And moved to `card` folder * Simplify elements and styles * A11y checks and fixes * Somewhat unrelated style changes - Selectable EuiCard title needed underline on hover - Unified spacing between radio and checkbox items (https://share.getcloudapp.com/YEudqoYp) * Update CHANGELOG.md Co-Authored-By: Caroline Horn <[email protected]> * Remove orphaned package * Address PR feedback
- Loading branch information
Showing
26 changed files
with
499 additions
and
145 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,101 @@ | ||
import React, { Component, Fragment } from 'react'; | ||
|
||
import { | ||
EuiCheckableCard, | ||
EuiSpacer, | ||
EuiRadioGroup, | ||
EuiTitle, | ||
} from '../../../../src/components'; | ||
|
||
import makeId from '../../../../src/components/form/form_row/make_id'; | ||
|
||
export default class extends Component { | ||
state = { | ||
radioName: makeId(), | ||
radio: 'radio2', | ||
nestedRadio: 'nestedRadio1', | ||
checkbox: false, | ||
}; | ||
|
||
render() { | ||
const { radioName } = this.state; | ||
|
||
const nestedRadios = [ | ||
{ | ||
id: 'nestedRadio1', | ||
label: 'Nested option one', | ||
}, | ||
{ | ||
id: 'nestedRadio2', | ||
label: 'Nested option two', | ||
}, | ||
{ | ||
id: 'nestedRadio3', | ||
label: 'Nested option three', | ||
}, | ||
]; | ||
|
||
return ( | ||
<Fragment> | ||
<fieldset> | ||
<legend> | ||
<EuiTitle size="xs"> | ||
<span>Checkable card radio group with legend</span> | ||
</EuiTitle> | ||
</legend> | ||
|
||
<EuiSpacer size="m" /> | ||
|
||
<EuiCheckableCard | ||
id={makeId()} | ||
label="Option one" | ||
name={radioName} | ||
value="radio1" | ||
checked={this.state.radio === 'radio1'} | ||
onChange={() => this.setState({ radio: 'radio1' })} | ||
/> | ||
|
||
<EuiSpacer size="m" /> | ||
|
||
<EuiCheckableCard | ||
id={makeId()} | ||
label="Option two" | ||
name={radioName} | ||
value="radio2" | ||
checked={this.state.radio === 'radio2'} | ||
onChange={() => this.setState({ radio: 'radio2' })}> | ||
<EuiRadioGroup | ||
options={nestedRadios} | ||
idSelected={this.state.nestedRadio} | ||
onChange={nestedRadio => this.setState({ nestedRadio })} | ||
disabled={this.state.radio !== 'radio2'} | ||
/> | ||
</EuiCheckableCard> | ||
|
||
<EuiSpacer size="m" /> | ||
|
||
<EuiCheckableCard | ||
id={makeId()} | ||
label="Option three (disabled)" | ||
name={radioName} | ||
value="radio3" | ||
checked={this.state.radio === 'radio3'} | ||
onChange={() => this.setState({ radio: 'radio3' })} | ||
disabled | ||
/> | ||
</fieldset> | ||
|
||
<EuiSpacer size="xl" /> | ||
|
||
<EuiCheckableCard | ||
id={makeId()} | ||
label="I am a checkbox" | ||
checkableType="checkbox" | ||
value="checkbox1" | ||
checked={this.state.checkbox} | ||
onChange={() => this.setState({ checkbox: !this.state.checkbox })} | ||
/> | ||
</Fragment> | ||
); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
@import 'mixins'; | ||
@import 'card'; | ||
@import 'card_select'; | ||
@import 'checkable_card/index'; |
71 changes: 71 additions & 0 deletions
71
src/components/card/checkable_card/__snapshots__/checkable_card.test.tsx.snap
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,71 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`EuiCheckableCard is rendered 1`] = ` | ||
<div | ||
class="euiCheckableCard testClass1 testClass2" | ||
> | ||
<div | ||
class="euiCheckableCard__row" | ||
> | ||
<div | ||
class="euiCheckableCard__control" | ||
> | ||
<div | ||
aria-label="aria-label" | ||
class="euiRadio euiRadio--noLabel" | ||
data-test-subj="test subject string" | ||
> | ||
<input | ||
class="euiRadio__input" | ||
id="id" | ||
type="radio" | ||
/> | ||
<div | ||
class="euiRadio__circle" | ||
/> | ||
</div> | ||
</div> | ||
<label | ||
class="euiCheckableCard__label" | ||
for="id" | ||
> | ||
Label | ||
</label> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`EuiCheckableCard renders a checkbox when specified 1`] = ` | ||
<div | ||
class="euiCheckableCard testClass1 testClass2" | ||
> | ||
<div | ||
class="euiCheckableCard__row" | ||
> | ||
<div | ||
class="euiCheckableCard__control" | ||
> | ||
<div | ||
class="euiCheckbox euiCheckbox--noLabel" | ||
> | ||
<input | ||
aria-label="aria-label" | ||
class="euiCheckbox__input" | ||
data-test-subj="test subject string" | ||
id="id" | ||
type="checkbox" | ||
/> | ||
<div | ||
class="euiCheckbox__square" | ||
/> | ||
</div> | ||
</div> | ||
<label | ||
class="euiCheckableCard__label" | ||
for="id" | ||
> | ||
Label | ||
</label> | ||
</div> | ||
</div> | ||
`; |
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,55 @@ | ||
@import '../../panel/mixins'; | ||
|
||
@include euiPanel('euiCheckableCard'); | ||
|
||
.euiCheckableCard { | ||
transition: border-color $euiAnimSpeedNormal ease-in; | ||
overflow: hidden; // Hides background color inside panel rounded corners | ||
|
||
&:not(.euiCheckableCard-isDisabled) { | ||
&:focus-within { | ||
@include euiFocusRing; | ||
} | ||
} | ||
} | ||
|
||
.euiCheckableCard-isChecked { | ||
border-color: $euiColorPrimary; | ||
} | ||
|
||
|
||
|
||
.euiCheckableCard__row { | ||
display: flex; | ||
align-items: stretch; | ||
} | ||
|
||
.euiCheckableCard__control { | ||
display: flex; | ||
flex: 0 0 $euiSizeXXL; | ||
justify-content: center; | ||
align-items: center; | ||
background-color: map-get($euiCardSelectButtonBackgrounds, 'text'); | ||
transition: background-color $euiAnimSpeedNormal ease-in; | ||
|
||
.euiCheckableCard-isChecked & { | ||
background-color: map-get($euiCardSelectButtonBackgrounds, 'primary'); | ||
} | ||
} | ||
|
||
.euiCheckableCard__label { | ||
flex-grow: 1; | ||
font-size: $euiFontSize; | ||
line-height: $euiSizeL; | ||
padding: $euiSizeS $euiSizeS $euiSizeS $euiSize; | ||
cursor: pointer; | ||
} | ||
|
||
.euiCheckableCard__label-isDisabled { | ||
color: $euiFormControlDisabledColor; | ||
cursor: not-allowed; | ||
} | ||
|
||
.euiCheckableCard__children { | ||
padding: 0 $euiSizeS $euiSizeS $euiSize; | ||
} |
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 @@ | ||
@import 'checkable_card'; |
33 changes: 33 additions & 0 deletions
33
src/components/card/checkable_card/checkable_card.test.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,33 @@ | ||
import React from 'react'; | ||
import { render } from 'enzyme'; | ||
import { requiredProps } from '../../../test/required_props'; | ||
|
||
import { EuiCheckableCard } from './checkable_card'; | ||
|
||
const checkablePanelRequiredProps = { | ||
label: 'Label', | ||
id: 'id', | ||
onChange: () => {}, | ||
}; | ||
|
||
describe('EuiCheckableCard', () => { | ||
test('is rendered', () => { | ||
const component = render( | ||
<EuiCheckableCard {...requiredProps} {...checkablePanelRequiredProps} /> | ||
); | ||
|
||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
test('renders a checkbox when specified', () => { | ||
const component = render( | ||
<EuiCheckableCard | ||
{...requiredProps} | ||
{...checkablePanelRequiredProps} | ||
checkableType="checkbox" | ||
/> | ||
); | ||
|
||
expect(component).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.