-
Notifications
You must be signed in to change notification settings - Fork 22
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
React: Add Standard Accordion Components to Mayflower React #85
React: Add Standard Accordion Components to Mayflower React #85
Conversation
This reverts commit 7b1bc7b.
<Collapse in={this.state.open} dimension="height"> | ||
<div className="ma__accordion-content__body"> | ||
{ React.Children.map(this.props.children, (child) => { | ||
if (allowedChildren.includes(child.type.name)) { |
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.
maybe should also check for React.isValidElement(child))
before child.type.name
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.
this could also be refactored into a utility function?
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.
added that to the wrapper - we can remove the child check if that is prefered here
<Collapse in={this.state.open} dimension="height"> | ||
<div className="ma__accordion-content__body"> | ||
{ React.Children.map(this.props.children, (child) => { | ||
if (allowedChildren.includes(child.type.name)) { |
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.
this could also be refactored into a utility function?
render() { | ||
const buttonClasses = this.state.open ? 'ma__accordion-header__button is-open' : 'ma__accordion-header__button'; | ||
const accordionClasses = this.props.border ? 'ma__accordion-item' : 'ma__accordion-item__borderless'; | ||
const allowedChildren = ['Paragraph', 'OrderedList', 'UnorderedList', 'Heading', 'Table']; |
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.
where does this list come from? also see this in patternlab --> https://mayflower.digital.mass.gov/?p=molecules-contact-us-collapsed-with-more-link
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.
we can remove any check for children type if that is a better approach here..
{this.props.icon} | ||
</div> | ||
)} | ||
<h2 className="ma__accordion-header__title">{this.props.title}</h2> |
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.
heading level should probably be passable
I think this is a good use of children to prevent prop drilling. I can see many organisms or higher components can be refactored to use children especially for those don't care what order of children are passed and don't need to carry any logic at the wrapper level. The react-transition-group can potentially solve all the animation problems we are running into, e.g. page scroll. For this specific case, since everything is purely css, maybe we could use ReactCSSTransitionGroup a higher level api to handle the animation. thoughts? |
comments about css files were mistaken
…assgov/mayflower into react-add-accordion-to-mayflower-react
} | ||
|
||
&__title { | ||
@include ma-h5; |
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.
why import both h4 and h5 styles?
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.
if you want to include the margin, I'd recommend only import h4 and manually set margin
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 think i took this from a pl scss - but i will pull it out
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.
see code comments
react/backstop/backstop.js
Outdated
@@ -10,15 +11,27 @@ let viewports; | |||
|
|||
// Scan for component names and set up viewports. | |||
const componentsPath = `${__dirname}/../src/components/`; | |||
components = listDirs(componentsPath) |
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 think we should keep the main backstop.js as free from distraction as possible (it's already got more than we probably want with my split of atoms/non-atoms)-- it shouldn't care about how to get the list of components, that's a storybook-specific thing.
Instead of looping over the results of the other call into fs here & doing more fs access, let's rename storyBookBackstop listDirs to something like listComponents & fold this logic in there.
react/backstop/backstop.js
Outdated
// Component directory names are capitalized. | ||
.filter((filePath) => (/^[A-Z]/.test(path.basename(filePath)))) | ||
// Only test atoms with this backstop configuration. | ||
.filter((filePath) => (filePath.indexOf('/atoms/') > -1)) | ||
// Skip table and media/Image, they need to be tested with larger viewports. | ||
.filter((filePath) => ((filePath.indexOf('table') === -1) && (path.basename(filePath) !== 'Image'))); | ||
.filter((filePath) => ((filePath.indexOf('table') === -1) && (path.basename(filePath) !== 'Image'))) | ||
// Do not test components without stories; |
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.
Did this comment go with a line of code somewhere else?
} | ||
|
||
function triggerBrowserReflow(node) { | ||
node.offsetHeight; // eslint-disable-line no-unused-expressions |
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.
Is this doing anything?
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.
yeah this causes the redraw so the animation can happen
@@ -8,7 +8,7 @@ import CalloutLink from './index'; | |||
import CalloutLinkDocs from './CalloutLink.md'; | |||
import calloutLinkOptions from './CalloutLink.knobs.options'; | |||
|
|||
storiesOf('molecules/CalloutLink', module).addDecorator(withKnobs) |
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.
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.
yeah this is so that backstop vr works correctly, it was getting the wrong stories before because of this nesting and that there is not a one to one relationship between src folder structure and storybook navigation - this was the simplest solution to solve this issue but we may want to refactor this in a followup
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.
Could we do what we discussed about using the add.("[ComponentName]")
in stories to create the reference url?
@@ -34,12 +34,14 @@ const getCommonPropsWithKnobs = () => ({ | |||
phone: null | |||
}); | |||
|
|||
storiesOf('molecules/ImagePromo', module).addDecorator(withKnobs) |
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.
see above comment
@@ -13,7 +13,7 @@ import SocialLinksLiveData from '../../molecules/SocialLinks/SocialLinksLive.jso | |||
import stateSeal from '../../../../../assets/images/stateseal.png'; | |||
|
|||
|
|||
storiesOf('organisms/Footer', module).addDecorator(withKnobs) | |||
storiesOf('organisms', module).addDecorator(withKnobs) |
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.
react/backstop/backstop.js
Outdated
@@ -1,4 +1,4 @@ | |||
const listDirs = require('./listDirs'); | |||
const listComponents = require('./listComponents'); | |||
const storyBookBackstop = require('./storyBookBackstop'); | |||
const path = require('path'); | |||
const fs = require('fs'); |
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.
this line can be removed
…ub.com/massgov/mayflower into react-add-accordion-to-mayflower-react
return( | ||
/* eslint-disable no-console */ | ||
console.log(`Warning! You cannot pass a ${child.type.name} child to AccordionWrapper`) | ||
/* eslint-disable no-console */ |
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 think this line was supposed to be eslint-enable
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.
why should this be enable
?
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.
That or line 20 was maybe supposed to be eslint-disable-next-line
instead of just disable
Description: This PR includes the addition of 4 new components that together create a standard accordion feature in Mayflower React. The design is pulled from Mayflower PL but were refactored in order to generate these new components. Also, in order to enable animations, this PR installs the react-transition-group library.
Question to Validate with React Team --> Is the approach to handling children in both accordion item and accordion wrapper appropriate here? Is the approach to animations here appropriate? Do we want to pull animation and focus scss in accordion item out to a higher level in the react library so it applies to all relevant components?
External Review Steps:
Updated Gifs