Skip to content
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

Guidelines component #263

Merged
merged 15 commits into from
Jan 11, 2018
Merged

Guidelines component #263

merged 15 commits into from
Jan 11, 2018

Conversation

cchaos
Copy link
Contributor

@cchaos cchaos commented Jan 4, 2018

This creates a style guide specific component for writing out rows of guidelines.

Basic instance

Includes a top area for a heading and description and two examples (a "do" and a "dont"). Each example takes a type and a text string for a more verbose caption.

Leave the heading and description props blank if you do not needs these displayed.

screen shot 2018-01-05 at 15 11 11 pm

<GuideGuideline
  heading="Write in active voice"
  description="Active voice puts the focus on who or what is performing the action and makes the sentence easier to understand."
>

  <GuideGuidelineExample type="do" text="">
    <GuideGuidelineWriting>The Elasticsearch Query DSL builds filters.</GuideGuidelineWriting>
  </GuideGuidelineExample>
  <GuideGuidelineExample type="dont" text="">
    <GuideGuidelineWriting>Filters are built using the Elasticsearch Query DSL.</GuideGuidelineWriting>
  </GuideGuidelineExample>
</GuideGuideline>

For simple writing sample examples, use the GuideGuidelineWriting component

Complex example

If you don't want to encapsulate the whole example in panel-style container, add the prop panel={false}. Then you can use your own panel or any other component.

screen shot 2018-01-05 at 15 11 43 pm

<GuideGuideline
  heading="Avoid using &quot;Are you sure&quot;"
  description="Your text is more direct without it."
>
  <GuideGuidelineExample type="do" text="" panel={false}>
    <EuiPanel></EuiPanel>
  </GuideGuidelineExample>

  <GuideGuidelineExample type="dont" text="" panel={false}>
    <EuiPanel></EuiPanel>
  </GuideGuidelineExample>
</GuideGuideline>

Omitting columns

If you need to have an empty example column, use <EuiFlexItem /> in place of the GuideGuidelineExample.

screen shot 2018-01-05 at 15 18 22 pm

<GuideGuideline
  heading=""
  description=""
>
  <GuideGuidelineExample type="do" text=""></GuideGuidelineExample>

  <EuiFlexItem />
</GuideGuideline>

Section titles

There is also a GuideGuidelineTitle component that will create the correct title component and add the right amount of spacing.

<GuideGuidelineTitle>Style</GuideGuidelineTitle>

@cchaos cchaos added the documentation Issues or PRs that only affect documentation - will not need changelog entries label Jan 4, 2018
@cchaos cchaos requested review from snide and gchaps January 4, 2018 21:27
@snide
Copy link
Contributor

snide commented Jan 5, 2018

Gonna set up a quick review meeting for this one. I messed around with it for an hour and played around with throwing it into another page. Likely some easy wins we can do to make it a little more flexible. Easier to run through over a zoom.

@cchaos
Copy link
Contributor Author

cchaos commented Jan 5, 2018

PR has been updated based on the conversation with @elastic/kibana-design

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

Nice improvement! I had a few suggestions about code structure and style.

In terms of the presentation of the do's and don'ts how do you feel about either of these options?

image

image

I feel like first option is pretty strong. The benefit of doing either one of these is that our code will become much simpler because we won't need to add custom styles for adding borders to the panels.

@@ -0,0 +1,15 @@
.Guideline {
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 lowercase the first letter of all of the classes? e.g. guideline

Copy link
Contributor

Choose a reason for hiding this comment

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

I keep getting tripped up by the repetition of "guide" and "guideline". Can we use the word "rule" instead of "guideline" and add back the general "guide" prefix? So we'd end up with components such as:

  • GuideRule (with class guideRule)
  • GuideRuleDescription (with class guideRuleDescription)
  • GuideRuleTitle (with class guideRuleTitle)
  • And so on...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

.GuidelineExample__panel {
border-bottom-color: $euiColorSuccess;

+ small {
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 use a class instead of an element selector? This will be a little less brittle so the element can change without breaking anything. Also, I'm not sure small is the appropriate element here, semantically speaking. I think it should just be a regular <p>. I think it's typically used for small print like attribution, copyrights, and disclaimers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about using <figure> to wrap the whole thing and <figcaption> for the small text?

@@ -0,0 +1,3 @@
.euiGuideGuidelineWriting {

}
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 delete this since it's a no-op?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


if (description) {
descriptionNode = (
<GuideGuidelineDescription
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need a GuideGuidelineDescription component? I think it's OK to put <EuiText className="guidelineDescription"> and the other stuff in here instead.

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 left it separate because I think there may be cases where we would want to add the description without the examples.

className,
...rest,
}) => {
const classes = classNames('GuidelineWriting', className);
Copy link
Contributor

Choose a reason for hiding this comment

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

This class is a no-op, so can we remove this component and just use <EuiText><p>{children}</p></EuiText> in the examples?

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 see your point. My thinking was to just make it easy on those who just need a quick example of copywriting. Maybe it can be a helper function inside the writing guidelines instead of it's own component?

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

This is looking great! I just had a few last minute suggestions.

@@ -0,0 +1,67 @@
import React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this file needs to be renamed to guide_rule_example.js.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or can we just delete it? looks like guide_rule_example.js already exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, accidentally left that in

<EuiPanel className={panelClasses}>
{children}
</EuiPanel>
<small>{text || typeToSubtitleTextMap[type]}</small>
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 I'm OK with this or your figcaption suggestion as long as we're not using element selectors to style them! 😄

margin-top: $euiSizeXXL * -2;
}

.euiTitle + &.guideRule--hasHeading {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm this confuses me. What's the use case in which this selector applies? Can I see a screenshot?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh never mind, I see it now. Would it be possible to use EuiSpacer instead?

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But then you would have to know you need a space and have to know what spacer size.

This way, it always adds the tightens up space before the example row only if it directly follows a title.

I did forget to change the general .euiTitle selector to the GuideRule specific ones so the selector is now .guideRule__title + &.guideRule--hasHeading.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh good! That works too.

{children}
</div>
);
}
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 make this a little more efficient by conditionally assigning the component type instead of the entire component:

  const ChildrenComponent = panel ? EuiPanel : 'div';

  const childrenNode = (
    <ChildrenComponent className="guideRule__example__panel">
      {children}
    </ChildrenComponent>
  );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh yes!

Copy link
Contributor Author

@cchaos cchaos Jan 10, 2018

Choose a reason for hiding this comment

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

Could I take it further and just put the

<ChildrenComponent className="guideRule__example__panel">
  {children}
</ChildrenComponent>

directly in the return?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea!

EuiText,
} from '../../../../src/components';

export const GuideRuleWriting = ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it can be a helper function inside the writing guidelines instead of it's own component?

Sounds good!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there an example of one that has been created yet that I can look at?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I would just cut and paste the code into the top of guidelines/writing.js.

@cchaos
Copy link
Contributor Author

cchaos commented Jan 10, 2018

Ok, I think everything has been addressed now.

Again, this will probably be an evolving component as we start building out more doc pages.

@cchaos
Copy link
Contributor Author

cchaos commented Jan 10, 2018

Oh except that I am still getting the console error:

Warning: Failed prop type: Invalid prop `component` of value `figure` supplied to `EuiFlexItem`, expected one of ["div","span"].

by trying to use figure as a flex item. We can either let the error stand until #278 is resolved, or I can just add it to the approved list.

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

LGTM! I had one small note.

@@ -30,6 +29,23 @@ import {

import makeId from '../../../../src/components/form/form_row/make_id';

export const GuideRuleWriting = ({
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 remove the export here since it's only used in this example?


import {
GuideRuleDescription,
} from '../../components';
Copy link
Contributor

Choose a reason for hiding this comment

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

This causes a circular dependency because components/index.js also imports this file. So they end up depending on each other. To solve this we just need to change this path to point to the file containing GuideRuleDescription:

import {
   GuideRuleDescription,
} from './guide_rule_description';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah as soon as I hit comment, I saw it. 😩

@cchaos cchaos merged commit 6f03386 into elastic:master Jan 11, 2018
@cchaos cchaos deleted the writing_guidelines branch January 11, 2018 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Issues or PRs that only affect documentation - will not need changelog entries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants