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

[UI Framework][K7]: Form components #13435

Merged
merged 20 commits into from
Aug 11, 2017
Merged

Conversation

snide
Copy link
Contributor

@snide snide commented Aug 9, 2017

Adds form components.

Todo before merge...

  • Need to flesh out the docs to show various configs.
  • Add in validation.

Todo after merge...

  • Make sizing system (I'd like these to be applied to containers, not the inputs themselves).
  • Related, but show how horizontal, grid based layouts work. Again, should be all container handled, not applied directly to the core elements.

Stuff that I need help from @cjcenizal...

  • Figuring out the actual KuiForm wrapper component.
  • Figuring out how / if we pass arrays into checkboxes / selects.
  • Replace icon usage with a background svg solution so they can work on naked inputs.
  • How to handle button/form submit.

Light version

Dark version


return (
<div>
{options.map(function (option, index) {
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 have no idea how this should really be handled, right now I use a simple array, but that doesn't allow for things like passing defaultChecked on the actual input. Figured @cjcenizal could help here. I can say that checkboxes should always be in multiple sets, because switches are the single use checkbox variant.

className={classes}
{...rest}
>
{options.map(function (option, index) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, dunno the best way to deal with this. Figure @cjcenizal can help here.

@snide snide requested a review from cjcenizal August 9, 2017 20:50
@@ -557,6 +557,284 @@ table {
.kuiCallOutHeader__title {
color: #0079a5; }

.kuiForm__textField {
Copy link
Contributor Author

@snide snide Aug 9, 2017

Choose a reason for hiding this comment

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

I ended up using a base class to style all the similar text fields (text, textarea, password, number...etc). I originally had this as a mixin, but figured having a base class saves us a lot of CSS.

You can see this class passed as a default class on top of every text based input... ex: <input type="password" className="kuiForm__textField kuiFormPassword" />.

I think that's the right way to do it.

@@ -0,0 +1,83 @@
// The following code is inspired by...
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 modified this quite a bit. It's small enough I didn't want to install it as a dependency, because the overwrites would have been just as large as the original source. Let me know if this is the proper way to credit stuff in our code.

@cjcenizal
Copy link
Contributor

Name suggestions:

  • KuiFormRow
  • KuiNumberInput
  • KuiPasswordInput
  • KuiSearchInput
  • KuiTextInput
  • KuiTextArea (capital A to form a pattern, e.g. TextInput/TextArea)
  • KuiRangeSlider
  • KuiSelect
  • KuiSwitch
  • KuiCheckbox

@cjcenizal cjcenizal mentioned this pull request Aug 10, 2017
51 tasks
@@ -0,0 +1,69 @@
import React, {
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll only need to pass id to <KuiFormRow> (and not to the child component), if we do this:

import React, {
  cloneElement,
  PropTypes,
} from 'react';
import classNames from 'classnames';
import { KuiIcon } from '../../../components';

export const KuiFormRow = ({ children, icon, helpText, invalid, errors, label, id, className, ...rest }) => {
  const classes = classNames(
    'kuiFormRow',
    className,
    {
      'kuiFormRow--withIcon' : icon,
      'kuiFormRow--invalid' : invalid,
    }
  );

  let optionalIcon = null;
  if (icon) {
    optionalIcon = <KuiIcon className="kuiFormRow__icon" type={icon} size="medium" />;
  }

  let optionalHelpText = null;
  if (helpText) {
    optionalHelpText = <div className="kuiFormRow__helpText">{helpText}</div>;
  }

  let optionalErrors = null;
  if (errors) {
    optionalErrors = (
      errors.map(function (error, index) {
        return <div  key={index} className="kuiFormRow__error">{error}</div>;
      })
    );
  }

  let optionalLabel = null;
  if (label) {
    optionalLabel = <label className="kuiFormRow__label" htmlFor={id}>{label}</label>;
  }

  let field;

  if (id) {
    field = cloneElement(children, {
      id,
    });
  } else {
    field = children;
  }

  return (
    <div
      className={classes}
      {...rest}
    >
      {/*
          Order is important here. The label needs to be UNDER the children.
          We rearrange the flex order in the CSS so the label ends up
          displaying above the children / input. This allows us to still
          use sibling selectors against the label that are tiggered by the
          focus state of the input.
      */}
      {field}
      {optionalLabel}
      {optionalErrors}
      {optionalHelpText}
      {optionalIcon}
    </div>
  );
};

KuiFormRow.propTypes = {
  label: PropTypes.string,
  id: PropTypes.string,
  icon: PropTypes.string,
  invalid: PropTypes.bool,
  errors: PropTypes.array,
  helpText: PropTypes.string,
};

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 worked and I applied it. The only negative is it won't register when the child has isRequired on the prop. I went ahead and removed is required from the child components.

@snide
Copy link
Contributor Author

snide commented Aug 11, 2017

OK @cjcenizal I think this is in a pretty good state. I ran tests but a couple of them fail because of required props. Might need a primer on that tomorrow.

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 beautiful! Great work @snide. Had a few comments but nothing major.

// to be more easily maintained / themable going forward.

.kuiRange {
-webkit-appearance: none;
Copy link
Contributor

Choose a reason for hiding this comment

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

How about just appearance: none here, and let PostCSS autoprefix it?

// Don't use this, make proper ids instead. This is just for the example.
function makeId() {
return Math.random().toString(36).substr(2, 5);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to self: port @BigFunger's ID generator over to the UI Framework.

id={makeId()}
label="Text field in a form row"
>
<KuiFieldText name="text_name_in_row" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to self: update examples with ARIA attributes.

}]}
>
<GuideText>
<p>
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need a <p> here btw.

<button>
Logstash
</button>
Logstash
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch!

$kuiRangeTrackHeight: 2px !default;
$kuiRangeTrackBorderWidth: 0 !default;
$kuiRangeTrackBorderColor: $kuiColorLightShade !default;
$kuiRangeTrackRadius: $kuiBorderRadius !default;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering, why are we marking these overrideable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no need. copy/pasta. ill remove

// MIT License

// It has been modified to fit the styling patterns of Kibana and
// to be more easily maintained / themable going forward.
Copy link
Contributor

Choose a reason for hiding this comment

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

This credit looks good to me, but I think "themable" is spelled "themeable", based on a quick Google search.

@include kuiFieldStyle;
}

.kuiSelect::-ms-expand {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be nested with & inside of .kuiSelect?





Copy link
Contributor

Choose a reason for hiding this comment

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

/**
* 1. The label is our main clickable area. It sits above the actual switch.
*/
.kuiSwitch__label {
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 unnest everything from this line down?

@cjcenizal cjcenizal added the Team:Platform-Design Team Label for Kibana Design Team. Support the Analyze group of plugins. label Aug 11, 2017
@snide
Copy link
Contributor Author

snide commented Aug 11, 2017

@cjcenizal Got everything but the nesting. Can do the tyography stuff in a different PR. Removed radio. I'll need to add that next week.

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!

@snide snide merged commit 97812a1 into elastic:k7-ui-framework Aug 11, 2017
@snide snide deleted the k7/forms branch August 11, 2017 19:02
snide added a commit to snide/kibana that referenced this pull request Aug 14, 2017
Adds form components and example documentation to KUI.
cjcenizal pushed a commit to cjcenizal/kibana that referenced this pull request Aug 16, 2017
Adds form components and example documentation to KUI.
cjcenizal pushed a commit to cjcenizal/kibana that referenced this pull request Aug 26, 2017
Adds form components and example documentation to KUI.
cjcenizal pushed a commit that referenced this pull request Sep 19, 2017
Adds form components and example documentation to KUI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Platform-Design Team Label for Kibana Design Team. Support the Analyze group of plugins.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants