forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UI Framework] Reactify kuiCollapseButton (elastic#12225)
* add KuiCollapseButton * Export DIRECTIONS in collapse_button.js and use it in its test
- Loading branch information
1 parent
45e966b
commit 49f37e6
Showing
9 changed files
with
172 additions
and
31 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
ui_framework/components/collapse_button/__snapshots__/collapse_button.test.js.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,53 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`KuiCollapseButton Props direction down renders the down class 1`] = ` | ||
<button | ||
aria-label="aria-label" | ||
class="kuiCollapseButton testClass1 testClass2" | ||
data-test-subj="test subject string" | ||
type="button" | ||
> | ||
<div | ||
class="kuiIcon fa-chevron-circle-down" | ||
/> | ||
</button> | ||
`; | ||
|
||
exports[`KuiCollapseButton Props direction left renders the left class 1`] = ` | ||
<button | ||
aria-label="aria-label" | ||
class="kuiCollapseButton testClass1 testClass2" | ||
data-test-subj="test subject string" | ||
type="button" | ||
> | ||
<div | ||
class="kuiIcon fa-chevron-circle-left" | ||
/> | ||
</button> | ||
`; | ||
|
||
exports[`KuiCollapseButton Props direction right renders the right class 1`] = ` | ||
<button | ||
aria-label="aria-label" | ||
class="kuiCollapseButton testClass1 testClass2" | ||
data-test-subj="test subject string" | ||
type="button" | ||
> | ||
<div | ||
class="kuiIcon fa-chevron-circle-right" | ||
/> | ||
</button> | ||
`; | ||
|
||
exports[`KuiCollapseButton Props direction up renders the up class 1`] = ` | ||
<button | ||
aria-label="aria-label" | ||
class="kuiCollapseButton testClass1 testClass2" | ||
data-test-subj="test subject string" | ||
type="button" | ||
> | ||
<div | ||
class="kuiIcon fa-chevron-circle-up" | ||
/> | ||
</button> | ||
`; |
41 changes: 41 additions & 0 deletions
41
ui_framework/components/collapse_button/collapse_button.js
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,41 @@ | ||
import React, { | ||
PropTypes, | ||
} from 'react'; | ||
import classNames from 'classnames'; | ||
|
||
const DIRECTIONS = [ | ||
'down', | ||
'up', | ||
'left', | ||
'right' | ||
]; | ||
|
||
const directionToClassNameMap = { | ||
down: 'fa-chevron-circle-down', | ||
up: 'fa-chevron-circle-up', | ||
left: 'fa-chevron-circle-left', | ||
right: 'fa-chevron-circle-right', | ||
}; | ||
|
||
const KuiCollapseButton = ({ className, direction, ...rest }) => { | ||
const classes = classNames('kuiCollapseButton', className); | ||
const childClasses = classNames('kuiIcon', directionToClassNameMap[direction]); | ||
|
||
return (<button | ||
type="button" | ||
className={classes} | ||
{...rest} | ||
> | ||
<div className={childClasses}/> | ||
</button>); | ||
}; | ||
|
||
KuiCollapseButton.propTypes = { | ||
className: PropTypes.string, | ||
direction: PropTypes.oneOf(DIRECTIONS).isRequired | ||
}; | ||
|
||
export { | ||
DIRECTIONS, | ||
KuiCollapseButton | ||
}; |
48 changes: 48 additions & 0 deletions
48
ui_framework/components/collapse_button/collapse_button.test.js
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,48 @@ | ||
import React from 'react'; | ||
import { render,shallow } from 'enzyme'; | ||
import { requiredProps } from '../../test/required_props'; | ||
import sinon from 'sinon'; | ||
|
||
import { | ||
DIRECTIONS, | ||
KuiCollapseButton, | ||
} from './collapse_button'; | ||
|
||
describe('KuiCollapseButton', () => { | ||
describe('Props', () => { | ||
describe('direction', () => { | ||
DIRECTIONS.forEach(direction => { | ||
describe(direction, () => { | ||
test(`renders the ${direction} class`, () => { | ||
const component = <KuiCollapseButton direction={direction} { ...requiredProps }/>; | ||
expect(render(component)).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('onClick', () => { | ||
test(`isn't called upon instantiation`, () => { | ||
const onClickHandler = sinon.stub(); | ||
|
||
shallow( | ||
<KuiCollapseButton direction='left' onClick={onClickHandler} /> | ||
); | ||
|
||
sinon.assert.notCalled(onClickHandler); | ||
}); | ||
|
||
test('is called when the button is clicked', () => { | ||
const onClickHandler = sinon.stub(); | ||
|
||
const $button = shallow( | ||
<KuiCollapseButton direction='left' onClick={onClickHandler} /> | ||
); | ||
|
||
$button.simulate('click'); | ||
|
||
sinon.assert.calledOnce(onClickHandler); | ||
}); | ||
}); | ||
}); | ||
}); |
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 { KuiCollapseButton } from './collapse_button'; |
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
27 changes: 0 additions & 27 deletions
27
ui_framework/doc_site/src/views/collapse_button/collapse_button.html
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
ui_framework/doc_site/src/views/collapse_button/collapse_button.js
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,14 @@ | ||
import React from 'react'; | ||
|
||
import { | ||
KuiCollapseButton | ||
} from '../../../../components'; | ||
|
||
export default () => ( | ||
<div> | ||
<KuiCollapseButton direction='down'/> | ||
<KuiCollapseButton direction='up'/> | ||
<KuiCollapseButton direction='left'/> | ||
<KuiCollapseButton direction='right'/> | ||
</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