From 95cfe48fa5a455a008a9dc13d9699c7d8456d50d Mon Sep 17 00:00:00 2001 From: Alexander Fedyashov Date: Tue, 12 Jul 2016 18:21:52 +0300 Subject: [PATCH] (feat) Rail #181 --- src/elements/Rail/Rail.js | 73 +++++++++++++++++++++++++++ src/index.js | 1 + test/specs/elements/Rail/Rail-test.js | 21 ++++++++ 3 files changed, 95 insertions(+) create mode 100644 src/elements/Rail/Rail.js create mode 100644 test/specs/elements/Rail/Rail-test.js diff --git a/src/elements/Rail/Rail.js b/src/elements/Rail/Rail.js new file mode 100644 index 0000000000..44f8960ba0 --- /dev/null +++ b/src/elements/Rail/Rail.js @@ -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
{ children }
+} + +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 + diff --git a/src/index.js b/src/index.js index b8168ab3f8..f7670c001a 100644 --- a/src/index.js +++ b/src/index.js @@ -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 diff --git a/test/specs/elements/Rail/Rail-test.js b/test/specs/elements/Rail/Rail-test.js new file mode 100644 index 0000000000..96061feca0 --- /dev/null +++ b/test/specs/elements/Rail/Rail-test.js @@ -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() + .should.have.tagName('div') + }) +})