Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Segment): add size prop #569

Merged
merged 2 commits into from
Sep 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react'
import { Segment } from 'stardust'

const SegmentGroupSizesExample = () => {
const sizes = ['mini', 'tiny', 'small', 'large', 'big', 'huge', 'massive']

return (
<div>
{sizes.map(size => (
<Segment.Group key={size} size={size}>
<Segment>
It's a {size} segment
</Segment>
<Segment>
And it's a {size} segment, too
</Segment>
</Segment.Group>
))}
</div>
)
}

export default SegmentGroupSizesExample
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react'
import { Segment } from 'stardust'

const SegmentSizesExample = () => {
const sizes = ['mini', 'tiny', 'small', 'large', 'big', 'huge', 'massive']

return (
<div>
{sizes.map(size => (
<Segment key={size} size={size}>
It's a {size} segment
</Segment>
))}
</div>
)
}

export default SegmentSizesExample
9 changes: 9 additions & 0 deletions docs/app/Examples/elements/Segment/Variations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ const SegmentVariationsExamples = () => (
description='A basic segment has no special formatting.'
examplePath='elements/Segment/Variations/SegmentBasicExample'
/>
<ComponentExample
title='Sizes'
description='A segment can have different sizes.'
examplePath='elements/Segment/Variations/SegmentSizesExample'
/>
<ComponentExample
description='A group of segments can have different sizes.'
examplePath='elements/Segment/Variations/SegmentGroupSizesExample'
/>
</ExampleSection>
)

Expand Down
11 changes: 9 additions & 2 deletions src/elements/Segment/Segment.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'lodash'
import cx from 'classnames'
import React, { PropTypes } from 'react'

Expand Down Expand Up @@ -35,6 +36,7 @@ function Segment(props) {
piled,
raised,
secondary,
size,
stacked,
tertiary,
textAlign,
Expand All @@ -44,6 +46,7 @@ function Segment(props) {
const classes = cx(
'ui',
color,
size,
useKeyOrValueAndKey(attached, 'attached'),
useKeyOnly(basic, 'basic'),
useKeyOnly(circular, 'circular'),
Expand Down Expand Up @@ -78,10 +81,11 @@ Segment._meta = {
type: META.TYPES.ELEMENT,
props: {
attached: ['top', 'bottom'],
color: SUI.COLORS,
floated: SUI.FLOATS,
textAlign: SUI.TEXT_ALIGNMENTS,
padded: ['very'],
color: SUI.COLORS,
size: _.without(SUI.SIZES, 'medium'),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no medium size.

textAlign: SUI.TEXT_ALIGNMENTS,
},
}

Expand Down Expand Up @@ -143,6 +147,9 @@ Segment.propTypes = {
/** A segment can be formatted to appear less noticeable */
secondary: PropTypes.bool,

/** A segment can have different sizes. */
size: PropTypes.oneOf(Segment._meta.props.size),

/** Formatted to show it contains multiple pages. */
stacked: PropTypes.bool,

Expand Down
12 changes: 11 additions & 1 deletion src/elements/Segment/SegmentGroup.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import _ from 'lodash'
import cx from 'classnames'
import React, { PropTypes } from 'react'

import {
customPropTypes,
getElementType,
getUnhandledProps,
META,
SUI,
useKeyOnly,
} from '../../lib'

/**
* A group of segments can be formatted to appear together.
*/
function SegmentGroup(props) {
const { children, className, compact, horizontal, raised, stacked, piled } = props
const { children, className, compact, horizontal, piled, raised, size, stacked } = props
const classes = cx(
'ui',
size,
useKeyOnly(horizontal, 'horizontal'),
useKeyOnly(compact, 'compact'),
useKeyOnly(piled, 'piled'),
Expand All @@ -34,6 +38,9 @@ SegmentGroup._meta = {
name: 'SegmentGroup',
parent: 'Segment',
type: META.TYPES.ELEMENT,
props: {
size: _.without(SUI.SIZES, 'medium'),
},
}

SegmentGroup.propTypes = {
Expand All @@ -58,6 +65,9 @@ SegmentGroup.propTypes = {
/** A segment group may be formatted to raise above the page. */
raised: PropTypes.bool,

/** A segment group can have different sizes. */
size: PropTypes.oneOf(SegmentGroup._meta.props.size),

/** Formatted to show it contains multiple pages. */
stacked: PropTypes.bool,
}
Expand Down
1 change: 1 addition & 0 deletions test/specs/elements/Segment/Segment-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('Segment', () => {
common.implementsTextAlignProp(Segment)

common.propValueOnlyToClassName(Segment, 'color')
common.propValueOnlyToClassName(Segment, 'size')

common.propKeyOnlyToClassName(Segment, 'basic')
common.propKeyOnlyToClassName(Segment, 'circular')
Expand Down
2 changes: 2 additions & 0 deletions test/specs/elements/Segment/SegmentGroup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ describe('SegmentGroup', () => {
common.hasUIClassName(SegmentGroup)
common.rendersChildren(SegmentGroup)

common.propValueOnlyToClassName(SegmentGroup, 'size')

common.propKeyOnlyToClassName(SegmentGroup, 'compact')
common.propKeyOnlyToClassName(SegmentGroup, 'horizontal')
common.propKeyOnlyToClassName(SegmentGroup, 'piled')
Expand Down