Skip to content

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

Merged
merged 4 commits into from
May 11, 2017
Merged

Conversation

Knorcedger
Copy link
Contributor

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 to react-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?

@sapegin
Copy link
Member

sapegin commented Apr 13, 2017

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}>
Copy link
Member

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.

Copy link
Contributor Author

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);

Copy link
Member

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>

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

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

Yes please!

@@ -148,22 +148,26 @@ export function filterComponentsInSectionsByExactName(sections, name) {
return components;
}

export function filterSections(sections, name) {
Copy link
Member

Choose a reason for hiding this comment

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

Please add JDoc here.

@Knorcedger
Copy link
Contributor Author

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 :)

@sapegin
Copy link
Member

sapegin commented Apr 13, 2017

Awesome! 🍕

@sapegin
Copy link
Member

sapegin commented Apr 14, 2017

Tests in master should work now.

@Knorcedger
Copy link
Contributor Author

Knorcedger commented Apr 25, 2017

@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.

@sapegin
Copy link
Member

sapegin commented Apr 25, 2017

@Knorcedger
Copy link
Contributor Author

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.

@sapegin
Copy link
Member

sapegin commented May 3, 2017

You never hover on links, only on containers.

@sapegin
Copy link
Member

sapegin commented May 3, 2017

But probably you can hardcode these links back because of #426 ;-)

@Knorcedger
Copy link
Contributor Author

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 npm run start:sections and go to the first Button example that says 'Push Me' the 'Open Isolated' but has opacity 0, and the only way to reveal it, it to hover over the actual invisible button, and not the whole container. That was the initial problem and I don't know how to fix.

@sapegin
Copy link
Member

sapegin commented May 3, 2017

Works fine for me:

image 2017-05-03 at 6 37 53 pm

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 ;-)

@Knorcedger
Copy link
Contributor Author

Ok, cool. Shall I revert back to this commit and then add the tests?

@sapegin
Copy link
Member

sapegin commented May 4, 2017

Yep, thanks! 🍕

@Knorcedger Knorcedger force-pushed the section-isolated-mode branch from 46ab135 to de6dd2d Compare May 9, 2017 15:22
@codecov-io
Copy link

codecov-io commented May 9, 2017

Codecov Report

Merging #394 into master will decrease coverage by 0.22%.
The diff coverage is 76.92%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/rsg-components/StyleGuide/StyleGuide.js 100% <ø> (ø) ⬆️
src/rsg-components/Section/Section.js 100% <100%> (ø) ⬆️
src/utils/utils.js 93.93% <50%> (-2.94%) ⬇️
src/rsg-components/Section/SectionRenderer.js 90% <85.71%> (-10%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update feaa6b8...f2ddd58. Read the comment docs.

@Knorcedger
Copy link
Contributor Author

@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 npm test was reporting no errors locally :)

@@ -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>
Copy link
Member

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) {
Copy link
Member

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? :-)

Copy link
Contributor Author

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>
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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 ;-)

@sapegin
Copy link
Member

sapegin commented May 9, 2017

Looks fine! There are two pieces not covered by any tests though.

@sapegin sapegin merged commit 4de939d into styleguidist:master May 11, 2017
sapegin pushed a commit that referenced this pull request May 12, 2017
sapegin added a commit that referenced this pull request May 30, 2017
## 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants