-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
117 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
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,84 @@ | ||
import cx from 'classnames' | ||
import React, { PropTypes } from 'react' | ||
|
||
import { | ||
AutoControlledComponent as Component, | ||
META, | ||
customPropTypes, | ||
getUnhandledProps, | ||
getElementType, | ||
useKeyOnly, | ||
} from '../../lib' | ||
|
||
const _meta = { | ||
name: 'Sidebar', | ||
type: META.TYPES.MODULE, | ||
props: { | ||
animation: ['overlay', 'push', 'scale down', 'uncover', 'slide out', 'slide along'], | ||
direction: ['top', 'right', 'bottom', 'left'], | ||
width: ['very thin', 'thin', 'wide', 'very wide'], | ||
}, | ||
} | ||
|
||
/** | ||
* A sidebar hides additional content beside a page. | ||
*/ | ||
class Sidebar extends Component { | ||
static _meta = _meta | ||
|
||
static propTypes = { | ||
/** An element type to render as (string or function). */ | ||
as: customPropTypes.as, | ||
|
||
/** Animation style. */ | ||
animation: PropTypes.oneOf(Sidebar._meta.props.animation), | ||
|
||
/** Primary content. */ | ||
children: PropTypes.node, | ||
|
||
/** Additional classes. */ | ||
className: PropTypes.string, | ||
|
||
/** Initial value of visible. */ | ||
defaultVisible: PropTypes.bool, | ||
|
||
/** Direction the sidebar should appear on */ | ||
direction: PropTypes.oneOf(Sidebar._meta.props.direction), | ||
|
||
/** Controls whether or not the sidebar is visible on the page. */ | ||
visible: PropTypes.bool, | ||
|
||
/** Sidebar width */ | ||
width: PropTypes.oneOf(Sidebar._meta.props.width), | ||
} | ||
|
||
static defaultProps = { | ||
direction: 'left', | ||
} | ||
|
||
static autoControlledProps = [ | ||
'visible', | ||
] | ||
|
||
render() { | ||
const { animation, className, children, direction, visible, width } = this.props | ||
|
||
const classes = cx( | ||
'ui', | ||
'sidebar', | ||
'animating', // should be dynamically set only when animating | ||
direction, | ||
width, | ||
animation, | ||
useKeyOnly(visible, 'visible'), | ||
className | ||
) | ||
|
||
const rest = getUnhandledProps(Sidebar, this.props) | ||
const ElementType = getElementType(Sidebar, this.props) | ||
|
||
return <ElementType {...rest} className={classes}>{children}</ElementType> | ||
} | ||
} | ||
|
||
export default Sidebar |
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 './Sidebar' |
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 React from 'react' | ||
import _ from 'lodash' | ||
|
||
import Sidebar from 'src/collections/Sidebar/Sidebar' | ||
import * as common from 'test/specs/commonTests' | ||
|
||
describe('Sidebar', () => { | ||
common.isConformant(Sidebar) | ||
common.rendersChildren(Sidebar) | ||
common.hasUIClassName(Sidebar) | ||
|
||
common.propKeyOnlyToClassName(Sidebar, 'visible') | ||
common.propValueOnlyToClassName(Sidebar, 'width') | ||
common.propValueOnlyToClassName(Sidebar, 'animation') | ||
|
||
it('renders a <div /> element', () => { | ||
shallow(<Sidebar />) | ||
.should.have.tagName('div') | ||
}) | ||
it('renders children of the sidebar', () => { | ||
const wrapper = mount(<Sidebar><span /></Sidebar>) | ||
wrapper.children().at(0).should.have.tagName('span') | ||
}) | ||
it('adds direction value to className', () => { | ||
_.each(_.get(Sidebar, '_meta.props.direction'), propValue => { | ||
shallow(<Sidebar direction={propValue} />).should.have.className(propValue) | ||
}) | ||
}) | ||
}) |