Skip to content
This repository has been archived by the owner on Jul 26, 2021. It is now read-only.

Add css tab to example loader #281

Merged
merged 33 commits into from
Jul 17, 2020
Merged

Add css tab to example loader #281

merged 33 commits into from
Jul 17, 2020

Conversation

DMcginn
Copy link
Contributor

@DMcginn DMcginn commented Jul 1, 2020

Summary

Replaced the toggle background tab with a CSS tab that displays any css files imported by the example.

Closes #247

Deployment Link

https://terra-dev-si-add-css-ta-f2ejya.herokuapp.com/

Testing

There have been added WDIO tests to cover the same functionality as the existing <code> tab tests.

Additional Details

In the case that the example doesn't import a css file is the tab isn't displayed. The <code> and css tabs have both also been themed, the colors were based on the button-group selected and highlight colors.

Thank you for contributing to Terra.
@cerner/terra

@DMcginn DMcginn added this to the Backlog milestone Jul 1, 2020
@DMcginn DMcginn self-assigned this Jul 1, 2020
@mjhenkes mjhenkes temporarily deployed to terra-dev-si-add-css-ta-f2ejya July 1, 2020 15:16 Inactive
@@ -1,3 +1,4 @@
/* eslint-disable jsx-a11y/role-supports-aria-props */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This disable line is to deal with an aria-haspopup is not supported by the role link linting error.

Copy link
Contributor

Choose a reason for hiding this comment

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

this should be address here: #279

@emilyrohrbough
Copy link
Contributor

Does this handle themed examples that import themed files? Here's a link of an issue of missing vars: cerner/terra-core#3046

The changes to fix this issue would be very similar to how our components import and do theming. This would be nice to be 'face-up' if we can.

@@ -49,6 +50,21 @@
display: flex;
outline: none;
padding: 0.625rem;

&.is-selected {
--terra-dev-site-example-template-chevron-color: --terra-dev-site-example-template-selected-code-toggle-color;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally it was so that the chevrons matched the text color when the button was selected or highlighted, but I think the better option would be to just remove the color specification for the chevrons all together.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed chevron coloring: f086e80.

@mjhenkes mjhenkes temporarily deployed to terra-dev-si-add-css-ta-f2ejya July 16, 2020 04:19 Inactive

if (m !== null) {
m.forEach((match, groupIndex) => {
if (groupIndex === 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

would the first match index be 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The first match is the entire import line ex: var _ActionHeaderDocCommon =_interopRequireDefault(require("./ActionHeaderDocCommon.scss", I'll look into making this shorter since there's really no reason to run through both matches.

@@ -1,34 +1,65 @@
const path = require('path');
const startCase = require('lodash.startcase');
const findCss = require('./devSiteCssFinder');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const findCss = require('./devSiteCssFinder');
const findCssFileName = require('./devSiteCssFinder');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated name here: d830ef0.

}

.chevron {
color: var(--terra-dev-site-example-template-chevron-color, #000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this stay?

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 removed this originally so that the chevron could would always match the text color in the case of the tab being highlighted or selected, re-adding it and making a different text variable for it would be very simple if that's more appropriate? It would add quite a few more variables though.

<IconChevronRight className={cx('chevron')} />
</button>
</div>
{renderExamples()}
Copy link
Contributor

Choose a reason for hiding this comment

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

based on the naming, this should be moved to the main code snippet after render buttons

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 took renderExamples out of the renderButtons function and moved it after renderButtons: 4984d2d.

Comment on lines 102 to 105
const renderButtons = () => (
<div>
{exampleSrc
&& (
Copy link
Contributor

Choose a reason for hiding this comment

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

we can simplify this so it's a bit easier to read

Suggested change
const renderButtons = () => (
<div>
{exampleSrc
&& (
const renderButtons = () => (
if (! exampleSrc) {
return null;
}
return (

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored renderButtons here: 4984d2d.

The Example loader will take the passed in file, add it to an example template then location the source for the file in the src folder and render the example output.
The file must be a return a react component that has no required props to render.
The Example loader will take the passed in file, add it to an example template then locate the source for the file in the src folder and render the example output.
The file must be a return a react component that has no required props to render. The Example loader will also look for a css file import and render the example
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The file must be a return a react component that has no required props to render. The Example loader will also look for a css file import and render the example
The file must be a react component that requires no additional props to render. The Example loader will also look for the first css file import and also provide the scss snippet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated here: d830ef0.

expect(example).toMatchSnapshot();
});

it('returns undefined if there is no .css or .scss file declaration', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add some tests for css.moudle.scss?

Also can we add a few tests where multiple css imports are passes in to ensure the first path is resolved?

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 a test to make sure it picked up the whole file name for css.module.scss and a second to ensure that the first import path is the one that is loaded d830ef0.
I can add more for css.module.scss if you had something different in mind?

@mjhenkes mjhenkes temporarily deployed to terra-dev-si-add-css-ta-f2ejya July 16, 2020 16:17 Inactive
@DMcginn
Copy link
Contributor Author

DMcginn commented Jul 16, 2020

I removed the jest tests for devSiteExample due to an issue with the this.resolve() function being undefined during testing, @emilyrohrbough logged a ticket for the issue here: webpack/loader-runner#42.

CHANGELOG.md Outdated Show resolved Hide resolved
@mjhenkes mjhenkes temporarily deployed to terra-dev-si-add-css-ta-f2ejya July 16, 2020 16:46 Inactive
@mjhenkes mjhenkes temporarily deployed to terra-dev-si-add-css-ta-f2ejya July 16, 2020 19:48 Inactive
Copy link
Contributor

@mjhenkes mjhenkes left a comment

Choose a reason for hiding this comment

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

Good work @DMcginn !

@mjhenkes mjhenkes temporarily deployed to terra-dev-si-add-css-ta-f2ejya July 17, 2020 16:43 Inactive
Copy link
Contributor

@emilyrohrbough emilyrohrbough left a comment

Choose a reason for hiding this comment

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

Nice job! I'm super excited for this new feature!! I think this will be helpful for our consumers as well 😄

@mjhenkes mjhenkes merged commit a4694b3 into main Jul 17, 2020
@mjhenkes mjhenkes deleted the add-css-tab-to-example-loader branch July 17, 2020 17:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Terra Roadmap
Awaiting triage
Development

Successfully merging this pull request may close these issues.

Add a css tab to the example loader
5 participants