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

breaking(Accordion): Refactor component #1375

Merged
merged 24 commits into from
Sep 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
40c9a5c
breaking(Accordion): Refactor component
Feb 23, 2017
2efecfe
Merge branch 'master' of https://github.com/Semantic-Org/Semantic-UI-…
Feb 27, 2017
a236263
breaking(Accordion): Refactor component
Feb 27, 2017
96c956f
breaking(Accordion): Refactor component
layershifter Feb 27, 2017
6f97ff5
Merge branches 'master' and 'refactor/accordion' of https://github.co…
Mar 3, 2017
2c27724
breaking(Accordion): Refactor component
Mar 3, 2017
18be878
breaking(Accordion): Refactor component
layershifter Mar 6, 2017
95433c0
breaking(Accordion): Refactor component
Mar 7, 2017
9fbb7ce
Merge branch 'master' of https://github.com/Semantic-Org/Semantic-UI-…
Apr 3, 2017
219a305
style(Accordion): update typings, use overrideProps, remove cruft
Apr 3, 2017
15f4d2c
style(Accordion): update docs and tests
Apr 4, 2017
4c8451a
style(Accordion): fix lint issues
Apr 4, 2017
615aeac
Merge branches 'master' and 'refactor/accordion' of https://github.co…
layershifter Apr 17, 2017
a2621c1
fix(AccordionAccordion): use prop-types
layershifter Apr 17, 2017
dcb1a5f
Merge branches 'master' and 'refactor/accordion' of https://github.co…
layershifter May 7, 2017
2d68511
test(Accordion): fix test and lint issues
layershifter May 7, 2017
b3d5697
Merge branch 'master' of https://github.com/Semantic-Org/Semantic-UI-…
Jun 26, 2017
de7540f
Merge branch 'master' of https://github.com/Semantic-Org/Semantic-UI-…
Jul 3, 2017
389935a
fix(Accordion): use getInitialState
Jul 3, 2017
f96ced4
Merge branch 'master' of https://github.com/Semantic-Org/Semantic-UI-…
layershifter Jul 9, 2017
370c8a8
Merge branch 'master' of https://github.com/Semantic-Org/Semantic-UI-…
Jul 17, 2017
f19a68e
fix(Accordion): fix types
Jul 17, 2017
4c9ce00
perf(docs): optimize ComponentProps
Aug 28, 2017
8cb2062
style(Accordion): fix lint errors
Aug 28, 2017
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,30 @@
import React from 'react'
import { Accordion, Button, Form, Segment } from 'semantic-ui-react'

const panels = [
{
title: 'Optional Details',
content: {
as: Form.Input,
key: 'content',
label: 'Maiden Name',
placeholder: 'Maiden Name',
},
},
]

const AccordionExampleForm = () => (
<Segment>
<Form>
<Form.Group widths={2}>
<Form.Input label='First Name' placeholder='First Name' />
<Form.Input label='First Name' placeholder='Last Name' />
</Form.Group>
<Accordion as={Form.Field} panels={panels} />

<Button secondary>Sign Up</Button>
</Form>
</Segment>
)
Copy link
Member

Choose a reason for hiding this comment

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

Not sure about the API here, this produces invalid SUI HTML with two nested fields:

<div class="field accordion ui">
  <div class="title">
    <i class="dropdown icon"></i>Optional Details
  </div>
  <div class="field content">
    <label>Maiden Name</label>
    <div class="ui input">
      <input type="text" placeholder="Maiden Name" />
    </div>
  </div>
</div>

The Form.Field creates a field, but the content as Form.Input also creates a field. I tried to correct this by making the Accordion render as a Form.Field with a label prop, and the content render as an Input with the placeholder, however, this does not work.

I think I see where this is trying to go by allowing any component to be the Accordion and any component to be the Content, however, the CSS doesn't allow for this. We're bound to hit issues merging them.

The ui accordion should only contain children, same as the title and content. It would be ideal to have a generic Accordion component that could take any component, however, I think it would have to be JS style based and not CSS className based.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will check this example tomorrow. @levithomason do you have another remarks to this PR? After it will be merged, it will be easiest place where we can get transitions 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, @levithomason it renders same as there except CSS classes order. Can you take a look? Did I miss something?

    <div class="ui accordion field">
      <div class="title">
        <i class="icon dropdown"></i>
        Optional Details
      </div>
      <div class="content field">
        <label>Maiden Name</label>
        <input placeholder="Maiden Name" type="text">
      </div>
    </div>

Copy link
Member

Choose a reason for hiding this comment

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

I'm saying I do not think the HTML is valid SUI markup. I see no supported examples of nested fields: field > field.

Copy link
Member Author

Choose a reason for hiding this comment

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

Take a look there

<div class="ui accordion field">
  <div class="content field active"></div>
</div>

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for straightening me out on that! Will manually test this to refresh my memory. Likely will merge.


export default AccordionExampleForm
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React, { Component } from 'react'
import { Accordion, Form, Menu } from 'semantic-ui-react'

const ColorForm = (
<Form>
<Form.Group grouped>
<Form.Checkbox label='Red' name='color' value='red' />
<Form.Checkbox label='Orange' name='color' value='orange' />
<Form.Checkbox label='Green' name='color' value='green' />
<Form.Checkbox label='Blue' name='color' value='blue' />
</Form.Group>
</Form>
)

const SizeForm = (
<Form>
<Form.Group grouped>
<Form.Radio label='Small' name='size' type='radio' value='small' />
<Form.Radio label='Medium' name='size' type='radio' value='medium' />
<Form.Radio label='Large' name='size' type='radio' value='large' />
<Form.Radio label='X-Large' name='size' type='radio' value='x-large' />
</Form.Group>
</Form>
)

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

handleClick = (e, titleProps) => {
const { index } = titleProps
const { activeIndex } = this.state
const newIndex = activeIndex === index ? -1 : index

this.setState({ activeIndex: newIndex })
}

render() {
const { activeIndex } = this.state

return (
<Accordion as={Menu} vertical>
<Menu.Item>
<Accordion.Title
active={activeIndex === 0}
content='Size'
index={0}
onClick={this.handleClick}
/>
<Accordion.Content active={activeIndex === 0} content={SizeForm} />
</Menu.Item>

<Menu.Item>
<Accordion.Title
active={activeIndex === 1}
content='Colors'
index={1}
onClick={this.handleClick}
/>
<Accordion.Content active={activeIndex === 1} content={ColorForm} />
</Menu.Item>
</Accordion>
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react'
import { Accordion } from 'semantic-ui-react'

const level1Panels = [
{ title: 'Level 1A', content: 'Level 1A Contents' },
{ title: 'Level 1B', content: 'Level 1B Contents' },
]

const Level1Content = (
<div>
Welcome to level 1
<Accordion.Accordion panels={level1Panels} />
</div>
)

const level2Panels = [
{ title: 'Level 2A', content: 'Level 2A Contents' },
{ title: 'Level 2B', content: 'Level 2B Contents' },
]

const Level2Content = (
<div>
Welcome to level 2
<Accordion.Accordion panels={level2Panels} />
</div>
)

const rootPanels = [
{ title: 'Level 1', content: { content: Level1Content, key: 'content-1' } },
{ title: 'Level 2', content: { content: Level2Content, key: 'content-2' } },
]

const AccordionExampleNested = () => (
<Accordion defaultActiveIndex={0} panels={rootPanels} styled />
)

export default AccordionExampleNested
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import faker from 'faker'
import _ from 'lodash'
import React from 'react'
import { Accordion, Label, Message } from 'semantic-ui-react'

const panels = _.times(3, i => ({
title: {
content: <Label color='blue' content={faker.lorem.sentence()} />,
key: `title-${i}`,
},
content: {
content: (
<Message
info
header={faker.lorem.sentence()}
content={faker.lorem.paragraph()}
/>
),
key: `content-${i}`,
},
}))

const AccordionExampleShorthand = () => (
<Accordion defaultActiveIndex={1} panels={panels} />
)

export default AccordionExampleShorthand
34 changes: 34 additions & 0 deletions docs/app/Examples/modules/Accordion/Advanced/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react'

import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample'
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection'

const AccordionAdvancedExamples = () => (
<ExampleSection title='Advanced'>
<ComponentExample
title='Nested Accordions'
description='An accordion can have multiple levels of nested content.'
examplePath='modules/Accordion/Advanced/AccordionExampleNested'
/>
<ComponentExample
title='Form Fields'
description={[
'An accordion can be used anywhere where content can be shown or hidden. For example, to show optional form',
'fields.',
].join(' ')}
examplePath='modules/Accordion/Advanced/AccordionExampleForm'
/>
<ComponentExample
title='Accordion Menu'
description='An accordion can be used to create content drawers inside a menu.'
examplePath='modules/Accordion/Advanced/AccordionExampleMenu'
/>
<ComponentExample
title='Shorthand'
description='Panels of Accordion can be rendered via shorthand prop.'
examplePath='modules/Accordion/Advanced/AccordionExampleShorthand'
/>
</ExampleSection>
)

export default AccordionAdvancedExamples

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,45 +1,59 @@
import React from 'react'
import React, { Component } from 'react'
import { Accordion, Icon } from 'semantic-ui-react'

const AccordionExampleStandard = () => (
<Accordion>
<Accordion.Title>
<Icon name='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 name='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 name='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>
)
export default class AccordionExampleStandard extends Component {
state = { activeIndex: 0 }

export default AccordionExampleStandard
handleClick = (e, titleProps) => {
const { index } = titleProps
const { activeIndex } = this.state
const newIndex = activeIndex === index ? -1 : index

this.setState({ activeIndex: newIndex })
}

render() {
const { activeIndex } = this.state

return (
<Accordion>
<Accordion.Title active={activeIndex === 0} index={0} onClick={this.handleClick}>
<Icon name='dropdown' />
What is a dog?
</Accordion.Title>
<Accordion.Content active={activeIndex === 0}>
<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 active={activeIndex === 1} index={1} onClick={this.handleClick}>
<Icon name='dropdown' />
What kinds of dogs are there?
</Accordion.Title>
<Accordion.Content active={activeIndex === 1}>
<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 active={activeIndex === 2} index={2} onClick={this.handleClick}>
<Icon name='dropdown' />
How do you acquire a dog?
</Accordion.Title>
<Accordion.Content active={activeIndex === 2}>
<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>
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react'
import { Accordion } from 'semantic-ui-react'

const panels = [
{
title: 'What is a dog?',
content: [
'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.',
].join(' '),
},
{
title: 'What kinds of dogs are there?',
content: [
'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.',
].join(' '),
},
{
title: 'How do you acquire a dog?',
content: {
content: (
<div>
<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>
</div>
),
key: 'content-dog',
},
},
]

const AccordionExampleStandardShorthand = () => (
<Accordion defaultActiveIndex={0} panels={panels} />
)

export default AccordionExampleStandardShorthand
Loading