Skip to content

Commit b5dd826

Browse files
author
Josh Habdas
committed
Nested Segments Example
1 parent 3569ae1 commit b5dd826

3 files changed

Lines changed: 35 additions & 7 deletions

File tree

docs/app/Examples/elements/Segment/Groups/SegmentGroupsExamples.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ export default class SegmentGroupsExamples extends Component {
1111
description='A group of segments can be formatted to appear together.'
1212
examplePath='elements/Segment/Groups/SegmentSegmentsExample'
1313
/>
14+
<ComponentExample
15+
title='Nested Segments'
16+
description='A group of segments can be nested in another group of segments.'
17+
examplePath='elements/Segment/Groups/SegmentNestedSegmentsExample'
18+
/>
1419
</ExampleSection>
1520
);
1621
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React, {Component} from 'react';
2+
import {Segment, Segments} from 'stardust';
3+
4+
export default class SegmentNestedSegmentsExample extends Component {
5+
render() {
6+
return (
7+
<Segments>
8+
<Segment>Top</Segment>
9+
<Segments>
10+
<Segment>Nested Top</Segment>
11+
<Segment>Nested Middle</Segment>
12+
<Segment>Nested Bottom</Segment>
13+
</Segments>
14+
<Segments className='horizontal'>
15+
<Segment>Top</Segment>
16+
<Segment>Middle</Segment>
17+
<Segment>Bottom</Segment>
18+
</Segments>
19+
<Segment>Bottom</Segment>
20+
</Segments>
21+
);
22+
}
23+
}

src/utils/customPropTypes.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import _ from 'lodash';
33

44
const customPropTypes = {
55
/*
6-
* Ensures children are of a certain type
6+
* Ensures children are of a set of types
77
* Similar to `oneOfType` built-in validator
8-
* @param {Array<string>} allowedTypes Collection of allowed types
8+
* @param {Array<string>} allowedTypes Collection of allowed Stardust component types
99
* @returns {Array} containing children of the specified type
1010
*/
1111
childrenOfTypesOnly: (allowedTypes) => {
@@ -15,22 +15,22 @@ const customPropTypes = {
1515
return _.includes(allowedTypes, _.get(child, 'type._meta.name')) ? null : child;
1616
});
1717
if (disallowed && disallowed.length !== 0) {
18-
throw new Error(
18+
return new Error(
1919
`\`${componentName}\` should only have children of type \`${allowedTypes}\`.`);
2020
}
2121
};
2222
},
2323
/*
24-
* Verifies exclusivity of a given prop type
25-
* @param {string} exclusives property used in exclusivity check
26-
* @throws {Error} if props not mutually exclusive
24+
* Verifies exclusivity of a given prop
25+
* @param {string} exclusives property used for exclusivity check
26+
* @throws {Error} if named prop not mutually exclusive
2727
* @returns no-op
2828
*/
2929
mutuallyExclusive: exclusives => {
3030
return (props, propName, componentName) => {
3131
_.forEach(exclusives, exclusiveProp => {
3232
if (props[propName] && props[exclusiveProp]) {
33-
throw new Error(
33+
return new Error(
3434
`\`${componentName}\` should only have one of type \`${propName}\` or \`${exclusiveProp}\` not both.`
3535
);
3636
}

0 commit comments

Comments
 (0)