Skip to content

Commit

Permalink
(feat) Rail Semantic-Org#181
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Fedyashov committed Jul 12, 2016
1 parent 9beb4a9 commit 95cfe48
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/elements/Rail/Rail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import _ from 'lodash'
import React, { PropTypes } from 'react'
import cx from 'classnames'

import * as sui from '../../utils/semanticUtils'
import { customPropTypes, getUnhandledProps, useKeyOnly, useKeyOrValueAndKey } from '../../utils/propUtils'
import META from '../../utils/Meta'

function Rail(props) {
const { attached, className, close, children, dividing, internal, position, size } = props
const classes = cx(
'ui',
position,
useKeyOnly(attached, 'attached'),
useKeyOrValueAndKey(close, 'close'),
useKeyOnly(dividing, 'dividing'),
useKeyOnly(internal, 'internal'),
size,
className,
'rail',
)
const rest = getUnhandledProps(Rail, props)

return <div className={classes} {...rest}>{ children }</div>
}

Rail._meta = {
library: META.library.semanticUI,
name: 'Rail',
type: META.type.element,
props: {
close: ['very'],
position: sui.floats,
size: _.without(sui.sizes, 'mini', 'small', 'medium', 'big'),
},
}

Rail.propTypes = {
/** Show that the Rail is attached. */
attached: PropTypes.bool,

/** Classes that will be added to the Rail className. */
className: PropTypes.string,

/** Show that the Rail is close. */
close: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.oneOf(Rail._meta.props.close),
]),

/** Primary content of the Rail. */
children: customPropTypes.ofComponentTypes([
'Segment',
]),

/** Show that the Rail is dividing. */
dividing: PropTypes.bool,

/** Show that the Rail is internal. */
internal: PropTypes.bool,

/** Show that the Rail is inverted. */
inverted: PropTypes.bool,

/** Shows Rail's position. */
position: PropTypes.oneOf(Rail._meta.props.position).isRequired,

/** Size of the Rail. */
size: PropTypes.oneOf(Rail._meta.props.size),
}

export default Rail

1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const ListItem = deprecateComponent('ListItem', 'Use "List.Item" instead.

export Segment from './elements/Segment/Segment'
export Segments from './elements/Segment/SegmentSegments'
export Rail from './elements/Rail/Rail'

// ----------------------------------------
// Modules
Expand Down
21 changes: 21 additions & 0 deletions test/specs/elements/Rail/Rail-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react'

import Rail from 'src/elements/Rail/Rail'
import * as common from 'test/specs/commonTests'

describe('Rail', () => {
common.isConformant(Rail)
common.hasUIClassName(Rail)
common.propValueOnlyToClassName(Rail, 'position')
common.propKeyOnlyToClassName(Rail, 'attached')
common.propKeyOrValueToClassName(Rail, 'close')
common.propKeyOnlyToClassName(Rail, 'dividing')
common.propKeyOnlyToClassName(Rail, 'internal')
common.propValueOnlyToClassName(Rail, 'size')
common.rendersChildren(Rail)

it('renders an div element', () => {
shallow(<Rail />)
.should.have.tagName('div')
})
})

0 comments on commit 95cfe48

Please sign in to comment.