-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
40c9a5c
breaking(Accordion): Refactor component
2efecfe
Merge branch 'master' of https://github.com/Semantic-Org/Semantic-UI-…
a236263
breaking(Accordion): Refactor component
96c956f
breaking(Accordion): Refactor component
layershifter 6f97ff5
Merge branches 'master' and 'refactor/accordion' of https://github.co…
2c27724
breaking(Accordion): Refactor component
18be878
breaking(Accordion): Refactor component
layershifter 95433c0
breaking(Accordion): Refactor component
9fbb7ce
Merge branch 'master' of https://github.com/Semantic-Org/Semantic-UI-…
219a305
style(Accordion): update typings, use overrideProps, remove cruft
15f4d2c
style(Accordion): update docs and tests
4c8451a
style(Accordion): fix lint issues
615aeac
Merge branches 'master' and 'refactor/accordion' of https://github.co…
layershifter a2621c1
fix(AccordionAccordion): use prop-types
layershifter dcb1a5f
Merge branches 'master' and 'refactor/accordion' of https://github.co…
layershifter 2d68511
test(Accordion): fix test and lint issues
layershifter b3d5697
Merge branch 'master' of https://github.com/Semantic-Org/Semantic-UI-…
de7540f
Merge branch 'master' of https://github.com/Semantic-Org/Semantic-UI-…
389935a
fix(Accordion): use getInitialState
f96ced4
Merge branch 'master' of https://github.com/Semantic-Org/Semantic-UI-…
layershifter 370c8a8
Merge branch 'master' of https://github.com/Semantic-Org/Semantic-UI-…
f19a68e
fix(Accordion): fix types
4c9ce00
perf(docs): optimize ComponentProps
8cb2062
style(Accordion): fix lint errors
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
docs/app/Examples/modules/Accordion/Advanced/AccordionExampleForm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
|
||
export default AccordionExampleForm |
64 changes: 64 additions & 0 deletions
64
docs/app/Examples/modules/Accordion/Advanced/AccordionExampleMenu.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
docs/app/Examples/modules/Accordion/Advanced/AccordionExampleNested.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
27 changes: 27 additions & 0 deletions
27
docs/app/Examples/modules/Accordion/Advanced/AccordionExampleShorthand.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
15 changes: 0 additions & 15 deletions
15
docs/app/Examples/modules/Accordion/Types/AccordionExamplePanelsProp.js
This file was deleted.
Oops, something went wrong.
98 changes: 56 additions & 42 deletions
98
docs/app/Examples/modules/Accordion/Types/AccordionExampleStandard.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
docs/app/Examples/modules/Accordion/Types/AccordionExampleStandardShorthand.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not sure about the API here, this produces invalid SUI HTML with two nested fields:
The
Form.Field
creates a field, but the content asForm.Input
also creates a field. I tried to correct this by making the Accordion renderas
aForm.Field
with alabel
prop, and the content renderas
anInput
with theplaceholder
, 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 thetitle
andcontent
. 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.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.
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 😄
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.
Hm, @levithomason it renders same as there except CSS classes order. Can you take a look? Did I miss something?
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.
I'm saying I do not think the HTML is valid SUI markup. I see no supported examples of nested fields:
field > field
.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.
Take a look there
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.
Thanks for straightening me out on that! Will manually test this to refresh my memory. Likely will merge.