-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Container Component updated to v1 API #277
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
Changes from 18 commits
27dc01c
a5441e5
7631a91
d64f2b2
84f9f53
9e2d9b4
06fde8b
724759a
bd4b8de
241a022
f420da9
a083fd5
bd628e3
77b4bb5
0d50e12
edf673a
9bb4509
f31fe72
ad81023
6330ca0
f2781cd
2366b67
8863f6d
28f6d7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React, { Component } from 'react' | ||
import ContainerTypesExamples from './Types/ContainerTypesExamples' | ||
import ContainerVariationsExamples from './Variations/ContainerVariationsExamples' | ||
|
||
export default class ContainerExamples extends Component { | ||
render() { | ||
return ( | ||
<div> | ||
<ContainerTypesExamples /> | ||
<ContainerVariationsExamples /> | ||
</div> | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* eslint-disable max-len */ | ||
|
||
import React, { Component } from 'react' | ||
import { Container } from 'stardust' | ||
|
||
export default class ContainerContainerExample extends Component { | ||
render() { | ||
return ( | ||
<Container> | ||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa strong. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede link mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi.</p> | ||
</Container> | ||
) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* eslint-disable max-len */ | ||
|
||
import React, { Component } from 'react' | ||
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample' | ||
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection' | ||
import { Message } from 'stardust' | ||
|
||
export default class ContainerTypesExamples extends Component { | ||
render() { | ||
return ( | ||
<ExampleSection title='Types'> | ||
<ComponentExample | ||
title='Container' | ||
description='A standard container' | ||
examplePath='elements/Container/Types/ContainerContainerExample' | ||
/> | ||
<ComponentExample | ||
title='Text Container' | ||
description='A container can reduce its maximum width to more naturally accomodate a single column of text' | ||
examplePath='elements/Container/Types/ContainerTextExample' | ||
> | ||
<Message className='info'> | ||
<p>A text container is a simpler markup alternative to using a grid with a single column, and is designed to have a reasonable maximum width for displaying flowing text</p> | ||
</Message> | ||
</ComponentExample> | ||
</ExampleSection> | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* eslint-disable max-len */ | ||
|
||
import React, { Component } from 'react' | ||
import { Container, Divider } from 'stardust' | ||
|
||
export default class ContainerAlignmentExample extends Component { | ||
render() { | ||
return ( | ||
<div> | ||
<Container aligned='left'> | ||
Left Aligned | ||
</Container> | ||
<Container aligned='center'> | ||
Center Aligned | ||
</Container> | ||
<Container aligned='right'> | ||
Right Aligned | ||
</Container> | ||
<Container aligned='justified'> | ||
<b>Justified</b> | ||
<Divider /> | ||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa strong. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede link mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi.</p> | ||
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa strong. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede link mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi.</p> | ||
</Container> | ||
</div> | ||
|
||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* eslint-disable max-len */ | ||
|
||
import React, { Component } from 'react' | ||
import { Container, Header } from 'stardust' | ||
|
||
export default class ContainerFluidExample extends Component { | ||
render() { | ||
return ( | ||
<div> | ||
<Container fluid> | ||
<Header.H2>Dogs Roles with Humans</Header.H2> | ||
<p>Domestic dogs inherited complex behaviors, such as bite inhibition, from their wolf ancestors, which would have been pack hunters with complex body language. These sophisticated forms of social cognition and communication may account for their trainability, playfulness, and ability to fit into human households and social situations, and these attributes have given dogs a relationship with humans that has enabled them to become one of the most successful species on the planet today.</p> | ||
<p>The dogs' value to early human hunter-gatherers led to them quickly becoming ubiquitous across world cultures. Dogs perform many roles for people, such as hunting, herding, pulling loads, protection, assisting police and military, companionship, and, more recently, aiding handicapped individuals. This impact on human society has given them the nickname "man's best friend" in the Western world. In some cultures, however, dogs are also a source of meat.</p> | ||
</Container> | ||
</div> | ||
|
||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* eslint-disable max-len */ | ||
|
||
import React, { Component } from 'react' | ||
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample' | ||
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection' | ||
import { Message } from 'stardust' | ||
|
||
export default class ContainerVariationsExamples extends Component { | ||
render() { | ||
return ( | ||
<ExampleSection title='Variations'> | ||
<ComponentExample | ||
title='Text Alignment' | ||
description='A container can specify its text alignment' | ||
examplePath='elements/Container/Variations/ContainerAlignmentExample' | ||
/> | ||
<ComponentExample | ||
title='Fluid' | ||
description='A fluid container has no maximum width' | ||
examplePath='elements/Container/Variations/ContainerFluidExample' | ||
> | ||
<Message className='info'> | ||
Fluid containers are useful for setting text alignment, or other variations on unstyled content | ||
</Message> | ||
</ComponentExample> | ||
</ExampleSection> | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,62 @@ | ||
import React, { Component, PropTypes } from 'react' | ||
import classNames from 'classnames' | ||
import META from '../../utils/Meta' | ||
import cx from 'classnames' | ||
import React, { PropTypes } from 'react' | ||
import META from '../../utils/Meta'; | ||
import { | ||
getUnhandledProps, | ||
useValueAndKey, | ||
useKeyOnly, | ||
} from '../../utils/propUtils' | ||
|
||
/** | ||
* A container that gives your content some side padding. | ||
* A container limits content to a maximum width | ||
*/ | ||
export default class Container extends Component { | ||
static propTypes = { | ||
children: PropTypes.node, | ||
className: PropTypes.string, | ||
} | ||
|
||
static _meta = { | ||
library: META.library.semanticUI, | ||
name: 'Container', | ||
type: META.type.element, | ||
} | ||
|
||
render() { | ||
const classes = classNames( | ||
'sd-container', | ||
'ui', | ||
this.props.className, | ||
'container', | ||
) | ||
return ( | ||
<div {...this.props} className={classes}> | ||
{this.props.children} | ||
</div> | ||
) | ||
} | ||
function Container(props) { | ||
const { | ||
text, aligned, fluid, | ||
children, className, | ||
} = props | ||
|
||
const classes = cx('sd-container ui', | ||
useKeyOnly(text, 'text'), | ||
aligned === 'justified' ? 'justified' : useValueAndKey(aligned, 'aligned'), | ||
useKeyOnly(fluid, 'fluid'), | ||
'container', | ||
className | ||
) | ||
|
||
const rest = getUnhandledProps(Container, props) | ||
|
||
return ( | ||
<div className={classes} {...rest}> | ||
{children} | ||
</div> | ||
) | ||
} | ||
|
||
Container._meta = { | ||
library: META.library.semanticUI, | ||
name: 'Container', | ||
type: META.type.element, | ||
props: { | ||
aligned: ['left', 'center', 'right', 'justified'], | ||
}, | ||
} | ||
|
||
Container.propTypes = { | ||
/** Primary content of the Container */ | ||
children: PropTypes.node, | ||
|
||
/** Classes to add to the container className. */ | ||
className: PropTypes.string, | ||
|
||
/** Reduce maximum width to more naturally accomodate text */ | ||
text: PropTypes.bool, | ||
|
||
/** Align container content to left */ | ||
aligned: PropTypes.oneOf(Container._meta.props.aligned), | ||
|
||
/** Container has no maximum with */ | ||
fluid: PropTypes.bool, | ||
} | ||
|
||
export default Container |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react' | ||
|
||
import Container from 'src/elements/Container/Container' | ||
import * as common from 'test/specs/commonTests' | ||
|
||
describe('Container', () => { | ||
common.isConformant(Container) | ||
common.rendersChildren(Container) | ||
common.hasUIClassName(Container) | ||
|
||
common.propKeyOnlyToClassName(Container, 'text') | ||
common.propKeyAndValueToClassName(Container, 'aligned') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the test that is failing. This test will ensure that the component has the classNames:
I'm merging a new propUtil to handle the className logic. I'm also merging a new common test to ensure the Once merged, we'll be able to do this in cx(
useAlignedProp(aligned),
) And this in tests: common.implementsAlignedProp(Container) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have now merged #285 which adds The util and test account for the special handling of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. implemented |
||
common.propKeyOnlyToClassName(Container, 'fluid') | ||
|
||
it('renders a <div /> element', () => { | ||
shallow(<Container />) | ||
.should.have.tagName('div') | ||
}) | ||
|
||
it('does not have aligned class when justified', () => { | ||
shallow(<Container aligned='justified' />) | ||
.should.not.have.className('aligned') | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is automated as part of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the common.propKeyOnlyToClassName are still required, but not the 2
Sent from Postbox There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, should've been more explicit. You can keep all tests in this file, just remove this one: it('adds the Container class', ... All components must include a class that matches the component name. A The conformance tests use the component's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After updating this PR and getting the new tools merged in #285, remove this test: - it('does not have aligned class when justified', () => {
- shallow(<Container aligned='justified' />)
- .should.not.have.className('aligned')
- }) Then, replace line 12 above: -common.propKeyAndValueToClassName(Container, 'aligned')
+common.implementsAlignedProp(Container) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
}) |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After updating this PR and getting the new tools merged in #285, replace line 21 here with:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done