-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Section isolated mode #394
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
Section isolated mode #394
Conversation
Thanks! I’m trying to merge #389 but it still doesn’t work as it should and I’m not sure why ;-| |
{name && ( | ||
<Heading level={1} slug={slug} className={classes.heading}>{name}</Heading> | ||
)} | ||
<div className={classes.isolatedLink}> |
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.
Looks like it’s time to extract it to a separate component. We already have this pattern in two places I think.
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 created an IsolatedLink component that contains the markup and the CSS for it. I believe that the CSS rule that says "on hover of this element, reveal the IsolatedLink" should be inside the component (the component would just need the className for the element that will reveal the component once that element is hovered).
Do you agree with this approach?
Trying to implement this, I run into a problem with how to use this class inside the styles object. Following is the IsolateLinkRender where hoverClass is the class I'm getting from the parent component, and trying to use it in the styles object. Obviously the following doesn't work, since I don't know how to pass the hoverLink from the component to the styles object. Any help?
const styles = ({ font }) => ({
[hoverClass]: {
'&:hover $isolatedLink': {
isolate: false,
opacity: 1,
},
},
isolatedLink: {
position: 'absolute',
top: 0,
right: 0,
fontFamily: font,
fontSize: 14,
opacity: 0,
transition: 'opacity ease-in-out .15s .2s',
},
});
export function IsolatedLinkRenderer({ classes, hoverClass, isIsolated, link }) {
return (
<div className={classes.isolatedLink}>
{link && (
isIsolated ? (
<Link href="/">⇽ Back</Link>
) : (
<Link href={'#!/' + link}>Open isolated ⇢</Link>
)
)}
</div>
);
}
IsolatedLinkRenderer.propTypes = {
classes: PropTypes.object.isRequired,
hoverClass: PropTypes.string.isRequired,
isIsolated: PropTypes.bool,
link: PropTypes.string,
};
export default Styled(styles)(IsolatedLinkRenderer);
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 believe that the CSS rule that says "on hover of this element, reveal the IsolatedLink" should be inside the component
With this I agree.
the component would just need the className for the element that will reveal the component once that element is hovered
I think you need to put both of them into this component. Sou it’d be not IsolatedLink
but more like IsolatedContainer
:
<IsolatedContainer to="/foo">
this content will have a link in the corner
</IsolatedContainer>
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.
@sapegin I created the IsolatedContainer component. Since the CSS rule for "onHover" is inside the component, that means that on heading hover show the "Open Isolated" link (it used to be onHover of the whole component info area show the link). That seems fine by me, but theres a problem with the Isolated example which has no title. It used to be on hover of the code example area but now the only "hover" area is the link itself which is hidden.
Any ideas? Do you want me to update the PR to see the code?
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.
Yes please!
src/utils/utils.js
Outdated
@@ -148,22 +148,26 @@ export function filterComponentsInSectionsByExactName(sections, name) { | |||
return components; | |||
} | |||
|
|||
export function filterSections(sections, 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.
Please add JDoc here.
Cool, I will wait for the other PR to be merged first and then add the tests. In the mean time will fix the Changes Requested :) |
Awesome! 🍕 |
Tests in master should work now. |
@sapegin updated the PR. Let me know if you want me to clarify anything. Tests are still missing P.S. Also, after merging master in, everything has a purple border, not sure why. |
That’s what I’d do: https://gist.github.com/9d02a2603619daa8de7f1287490c894f |
I tried your proposed solution but that doesn't solve the problem that to open an isolated example you have to hover over the "opacity: 0" link. |
You never hover on links, only on containers. |
But probably you can hardcode these links back because of #426 ;-) |
I think we have a communication problem, and that's why I updated the PR with the changes you suggested. If you run the project with |
Works fine for me: But please take a look at #426, we’re probably trying to do something that would be removed soon. So if it‘s easier to revert, please revert it back, and sorry for inconsistent suggestions ;-) |
Ok, cool. Shall I revert back to this commit and then add the tests? |
Yep, thanks! 🍕 |
46ab135
to
de6dd2d
Compare
Codecov Report
@@ Coverage Diff @@
## master #394 +/- ##
==========================================
- Coverage 94.28% 94.06% -0.23%
==========================================
Files 82 82
Lines 1138 1145 +7
Branches 255 260 +5
==========================================
+ Hits 1073 1077 +4
- Misses 61 64 +3
Partials 4 4
Continue to review full report at Codecov.
|
@sapegin I reverted to the commit you suggested and tried to adjust the tests, but I'm not familiar with Jest and it's snapshots so I'm not sure if it's 100% ok. At least |
@@ -1,15 +1,30 @@ | |||
// Jest Snapshot v1, https://goo.gl/fbAQLP | |||
|
|||
exports[`render should not render title if name is not set 1`] = `<section />`; | |||
exports[`render should not render title if name is not set 1`] = ` | |||
<section> |
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.
These empty divs look strange but they most likely will go away after UI 2.0 ;-)
* @param {string} name The name to match | ||
* @return {object} The section found | ||
*/ | ||
export function filterSections(sections, 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.
Could you add a test for this function too? :-)
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 added tests for this function.
<div className={classes.isolatedLink}> | ||
{name && ( | ||
isolatedSection ? ( | ||
<Link href="/">⇽ Back</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.
And a test for back 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.
I tried to understand how to add tests for links, but I couldn't figure it out. Do you mind adding it?
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’s fine, we’re working on a new UI for these links anyway ;-)
Looks fine! There are two pieces not covered by any tests though. |
## New feature **Section isolated mode:** now you can open sections in isolated mode too. (#394 by @Knorcedger) ## Bug fixes * Fix React CodeMirror warning when opening code editor * Fix Create React App 1.0 support (#458) * Fix back button path for support pathname-relative paths (#447 by @stepancar) * Promise polyfill for IE11 because require.ensure requires it in webpack 2
This is the implementation of the section isolated mode.
I was not able to write tests for it because I couldn't run the tests. I think it's something with
react-addons-test-utils
moving toreact-dom/test-utils
. Is this fixed in the master branch, or can someone take a look so that I can run the tests and add tests for this too?