Skip to content

Commit

Permalink
refactor(Accordion): use title and content sub components
Browse files Browse the repository at this point in the history
  • Loading branch information
levithomason committed Jul 4, 2016
1 parent 7d330f5 commit 75f34ff
Show file tree
Hide file tree
Showing 15 changed files with 462 additions and 164 deletions.
57 changes: 37 additions & 20 deletions docs/app/Examples/modules/Accordion/Types/Accordion.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
import React, { Component } from 'react'
import { Accordion } from 'stardust'
import { Accordion, Icon } from 'stardust'

export default class AccordionStyledExample extends Component {
render() {
return (
<Accordion>
<Accordion.Panel title='What is a dog?'>
A dog is a type of domesticated animal. Known for its loyalty and faithfulness,
{' '}it can be found as a welcome guest in many households across the world.
</Accordion.Panel>
<Accordion.Panel title='What kinds of dogs are there?'>
There are many breeds of dogs. Each breed varies in size and temperament.
{' '}Owners often select a breed of dog that they find to be compatible
with their own lifestyle and desires from a companion.
</Accordion.Panel>
<Accordion.Panel title='How do you acquire a dog?'>
Three common ways for a prospective owner to acquire a dog is from pet shops,
{' '}private owners, or shelters.
<br />
<br />
A pet shop may be the most convenient way to buy a dog.
{' '}Buying a dog from a private owner allows you to assess the pedigree and
{' '}upbringing of your dog before choosing to take it home. Lastly, finding your dog
{' '}from a shelter, helps give a good home to a dog who may not find one so readily.
</Accordion.Panel>
<Accordion.Title>
<Icon className='dropdown' />
What is a dog?
</Accordion.Title>
<Accordion.Content>
<p>
A dog is a type of domesticated animal. Known for its loyalty and faithfulness,
{' '}it can be found as a welcome guest in many households across the world.
</p>
</Accordion.Content>
<Accordion.Title>
<Icon className='dropdown' />
What kinds of dogs are there?
</Accordion.Title>
<Accordion.Content>
<p>
There are many breeds of dogs. Each breed varies in size and temperament.
{' '}Owners often select a breed of dog that they find to be compatible
with their own lifestyle and desires from a companion.
</p>
</Accordion.Content>
<Accordion.Title>
<Icon className='dropdown' />
How do you acquire a dog?
</Accordion.Title>
<Accordion.Content>
<p>
Three common ways for a prospective owner to acquire a dog is from pet shops,
{' '}private owners, or shelters.
</p>
<p> A pet shop may be the most convenient way to buy a dog.
{' '}Buying a dog from a private owner allows you to assess the pedigree and
{' '}upbringing of your dog before choosing to take it home. Lastly, finding your dog
{' '}from a shelter, helps give a good home to a dog who may not find one so readily.
</p>
</Accordion.Content>
</Accordion>
)
}
Expand Down
42 changes: 42 additions & 0 deletions docs/app/Examples/modules/Accordion/Types/ActiveIndex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import faker from 'faker'
import _ from 'lodash'
import React, { Component } from 'react'
import { Accordion } from 'stardust'

const panels = _.times(3, () => ({
title: faker.lorem.sentence(),
content: faker.lorem.paragraphs(),
}))

export default class AccordionActiveIndexExample extends Component {
state = { activeIndex: 0 }

handleSliderChange = (e) => this.setState({
activeIndex: Number(e.target.value),
})

handleTitleClick = (e, i) => this.setState({
activeIndex: this.state.activeIndex === i ? -1 : i,
})

render() {
const { activeIndex } = this.state
return (
<div>
<div>activeIndex: {activeIndex}</div>
<input
type='range'
min='-1'
max={panels.length - 1}
value={activeIndex}
onChange={this.handleSliderChange}
/>
<Accordion
activeIndex={activeIndex}
panels={panels}
onTitleClick={this.handleTitleClick}
/>
</div>
)
}
}
17 changes: 17 additions & 0 deletions docs/app/Examples/modules/Accordion/Types/PanelsProp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React, { Component } from 'react'
import { Accordion } from 'stardust'
import faker from 'faker'
import _ from 'lodash'

const panels = _.times(3, () => ({
title: faker.lorem.sentence(),
content: faker.lorem.paragraphs(),
}))

export default class AccordionPanelsPropExample extends Component {
render() {
return (
<Accordion panels={panels} />
)
}
}
29 changes: 8 additions & 21 deletions docs/app/Examples/modules/Accordion/Types/Styled.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
import _ from 'lodash'
import faker from 'faker'
import React, { Component } from 'react'
import { Accordion } from 'stardust'

const panels = _.times(3, () => ({
title: faker.lorem.sentence(),
content: faker.lorem.paragraphs(),
}))

export default class AccordionStyledExample extends Component {
render() {
return (
<Accordion styled>
<Accordion.Panel title='What is a dog?'>
A dog is a type of domesticated animal. Known for its loyalty and faithfulness,
{' '}it can be found as a welcome guest in many households across the world.
</Accordion.Panel>
<Accordion.Panel title='What kinds of dogs are there?'>
There are many breeds of dogs. Each breed varies in size and temperament.
{' '}Owners often select a breed of dog that they find to be compatible
with their own lifestyle and desires from a companion.
</Accordion.Panel>
<Accordion.Panel title='How do you acquire a dog?'>
Three common ways for a prospective owner to acquire a dog is from pet shops,
{' '}private owners, or shelters.
<br />
<br />
A pet shop may be the most convenient way to buy a dog.
{' '}Buying a dog from a private owner allows you to assess the pedigree and
{' '}upbringing of your dog before choosing to take it home. Lastly, finding your dog
{' '}from a shelter, helps give a good home to a dog who may not find one so readily.
</Accordion.Panel>
</Accordion>
<Accordion panels={panels} styled />
)
}
}
22 changes: 22 additions & 0 deletions docs/app/Examples/modules/Accordion/Types/Types.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ 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 AccordionTypesExamples extends Component {
render() {
return (
Expand All @@ -11,6 +13,26 @@ export default class AccordionTypesExamples extends Component {
description='A standard Accordion.'
examplePath='modules/Accordion/Types/Accordion'
/>
<ComponentExample
title='Panels Prop'
description='Accordion panels can be define using the `panels` prop.'
examplePath='modules/Accordion/Types/PanelsProp'
>
<Message className='info'>
Panel objects can also define an <code>active</code> key to open/close the panel.
</Message>
</ComponentExample>
<ComponentExample
title='Active Index'
description='The `activeIndex` prop controls which panel is open.'
examplePath='modules/Accordion/Types/ActiveIndex'
>
<Message className='info'>
An <code>active</code> prop on an
{' '}<code>&lt;Accordion.Title&gt;</code> or <code>&lt;Accordion.Content&gt;</code>
{' '}will override the <code>&lt;Accordion&gt;</code> <code>&lt;activeIndex&gt;</code> prop.
</Message>
</ComponentExample>
<ComponentExample
title='Styled'
description='A styled accordion adds basic formatting'
Expand Down
29 changes: 8 additions & 21 deletions docs/app/Examples/modules/Accordion/Variations/Fluid.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
import _ from 'lodash'
import faker from 'faker'
import React, { Component } from 'react'
import { Accordion } from 'stardust'

const panels = _.times(3, () => ({
title: faker.lorem.sentence(),
content: faker.lorem.paragraphs(),
}))

export default class AccordionFluidExample extends Component {
render() {
return (
<Accordion fluid>
<Accordion.Panel title='What is a dog?'>
A dog is a type of domesticated animal. Known for its loyalty and faithfulness,
{' '}it can be found as a welcome guest in many households across the world.
</Accordion.Panel>
<Accordion.Panel title='What kinds of dogs are there?'>
There are many breeds of dogs. Each breed varies in size and temperament.
{' '}Owners often select a breed of dog that they find to be compatible
with their own lifestyle and desires from a companion.
</Accordion.Panel>
<Accordion.Panel title='How do you acquire a dog?'>
Three common ways for a prospective owner to acquire a dog is from pet shops,
{' '}private owners, or shelters.
<br />
<br />
A pet shop may be the most convenient way to buy a dog.
{' '}Buying a dog from a private owner allows you to assess the pedigree and
{' '}upbringing of your dog before choosing to take it home. Lastly, finding your dog
{' '}from a shelter, helps give a good home to a dog who may not find one so readily.
</Accordion.Panel>
</Accordion>
<Accordion panels={panels} fluid />
)
}
}
33 changes: 11 additions & 22 deletions docs/app/Examples/modules/Accordion/Variations/Inverted.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
import _ from 'lodash'
import faker from 'faker'
import React, { Component } from 'react'
import { Accordion } from 'stardust'
import { Accordion, Segment } from 'stardust'

const panels = _.times(3, () => ({
title: faker.lorem.sentence(),
content: faker.lorem.paragraphs(),
}))

export default class AccordionInvertedExample extends Component {
render() {
return (
<Accordion inverted>
<Accordion.Panel title='What is a dog?'>
A dog is a type of domesticated animal. Known for its loyalty and faithfulness,
{' '}it can be found as a welcome guest in many households across the world.
</Accordion.Panel>
<Accordion.Panel title='What kinds of dogs are there?'>
There are many breeds of dogs. Each breed varies in size and temperament.
{' '}Owners often select a breed of dog that they find to be compatible
with their own lifestyle and desires from a companion.
</Accordion.Panel>
<Accordion.Panel title='How do you acquire a dog?'>
Three common ways for a prospective owner to acquire a dog is from pet shops,
{' '}private owners, or shelters.
<br />
<br />
A pet shop may be the most convenient way to buy a dog.
{' '}Buying a dog from a private owner allows you to assess the pedigree and
{' '}upbringing of your dog before choosing to take it home. Lastly, finding your dog
{' '}from a shelter, helps give a good home to a dog who may not find one so readily.
</Accordion.Panel>
</Accordion>
<Segment className='inverted'>
<Accordion panels={panels} inverted />
</Segment>
)
}
}
Loading

0 comments on commit 75f34ff

Please sign in to comment.