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

feat(toggle): add new component and msft styles #212

Merged
merged 16 commits into from
Apr 12, 2018

Conversation

nalogiudice
Copy link
Contributor

For details on formatting pull requests.

@@ -1,2 +1,3 @@
export * from "./button";
export * from "./toggle";
Copy link
Member

Choose a reason for hiding this comment

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

Likely should alphabetize

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 think the components should be together, and then the "other" stuff should be separate (managed-classes in this case)

Copy link
Member

Choose a reason for hiding this comment

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

In theory, Foundation is a component.

Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be part of the linter if we're going to nit on it. Chris, if you're passionate about this being alphabetical please file an issue against fast-tslint-rules

Copy link
Member

Choose a reason for hiding this comment

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

Sure - didn't feel like a nit. But I'll file and take care of the issue. It does feel like something that's going to make it extremely hard for people to find things if we aren't grouping in a logical progression. Especially with a flat structure in src. I'll file an issue.

Copy link
Member

Choose a reason for hiding this comment

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

Synced with @nicholasrice on this. In the index.ts files where we import all things in "src" we will alphabetize. This does not need to be the case in .tsx files for regular imports. Unfortunately, due to some weird configs with .ts lint, we'll need to enforce this by principle. Trying to enforce alphabetizing in these files using .tslint would create a massive hinderance to our dev experience and overall code readability

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it.

import * as React from "react";

export interface IToggleProps {
children?: React.ReactNode | React.ReactNode[];
Copy link
Member

Choose a reason for hiding this comment

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

Is this really a place where we want to support anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the label... sure why not? I don't think it needs to be text-only. If they want a glyph or hyperlink, they should be able to add one

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree - requiring a string seems unnecessarily restrictive.

/**
* Toggle base component
*/
/* tslint:disable-next-line */
Copy link
Member

Choose a reason for hiding this comment

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

I think we can remove this tslint rule

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok - it's in the base component you put up so it should be removed from there too

Copy link
Member

Choose a reason for hiding this comment

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

for sure

* Toggle base component
*/
/* tslint:disable-next-line */
class Toggle extends Foundation<IToggleProps & IManagedClasses<IToggleClassNameContract>, React.AllHTMLAttributes<HTMLElement>, IToggleState> {
Copy link
Member

Choose a reason for hiding this comment

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

We should try to be as specific as possible here. The reason that button supported All was due to the fact that there were serious conflicts when trying to allow HTMLAnchor | HTMLButton. Here though, I don't we lose the purpose of this if we tell the user they can pass an href.

@@ -10,4 +10,25 @@ const designSystemDefaults: IDesignSystem = {
brandColor: "#0078D4"
};

/**
* Returns RGBA from hex value with optional alpha
Copy link
Member

Choose a reason for hiding this comment

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

we should pull this into a utilities folder if we're going to use this one. We may also want to just interpolate the values below

Copy link
Member

Choose a reason for hiding this comment

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

Also - questions as to whether or not this should live here or another package - colors, jss-utiltites...likely a team convo. But I'd pull from the design system folder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We probably need to figure out the full color story or there is going to be a lot of redoing work. I could have simply added the rgba values, but this seems like something we would want anyway. I can move, but we should figure this out as a team.

Copy link
Member

Choose a reason for hiding this comment

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

Agree on syncing as a team here. Not saying it needs to land, but I think we can start categorizing in utils for now at the very least.

Copy link
Contributor

Choose a reason for hiding this comment

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

It would likely live in the color package - that already takes a dependency on chroma-js which probably has this functionality, so you might just use that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, I'll look into that @nicholasrice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok @nicholasrice, I see a function think I can use from chroma-js to accomplish this. Do I need to add chroma to the styles-msft repo to use?

}
};

export default styles;
Copy link
Member

Choose a reason for hiding this comment

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

I think you need a newline here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need our linter or whatever to yell about this.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it should be - not sure why it isn't

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 I fixed an issue in the linter with a PR, if it's not updating let me know and I'll see if I can repro on your branch. There was an issue with Mac not jumping into all files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool - will let you know.

@@ -0,0 +1,6 @@
import * as React from "react";
import { IFoundationProps, IToggleClassNameContract, IToggleProps, Toggle } from "@microsoft/fast-components-react-base";
Copy link
Member

Choose a reason for hiding this comment

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

can you remove the spacing between the brackets and the imports?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea the linter will fail this

Copy link
Member

Choose a reason for hiding this comment

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

UPDATE: Leave spacing here due to the linter not being able to lint this. It should now lint import and exports to include space. Within the ts files themselves, there should be no spaces.

unselectedString: "Off"
}
]
} as IGenericExample<IToggleProps>;
Copy link
Member

Choose a reason for hiding this comment

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

I think @nicholasrice added something that updates this to generate snapshots

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 Check out the button component

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep all updated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep done

@@ -2,6 +2,10 @@ import Button from "./button";
export {Button};
export * from "./button";

import Toggle from "./toggle";
Copy link
Member

Choose a reason for hiding this comment

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

Should alphabetize

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like above, I think we should have our components separate from our other stuff. If we vote otherwise, I'm fine with it though.

Copy link
Member

Choose a reason for hiding this comment

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

Foundation is technically a component. I think maintainability is key unless we are going to comment and denote the intentional difference in structure. I think alphabetizing keeps everything in easy to understand and intuitive, but we can discuss as a team.

@@ -1,2 +1,5 @@
import ButtonExamples from "../src/button/examples.data";
export {ButtonExamples};

import ToggleExamples from "../src/toggle/examples.data";
export {ToggleExamples};
Copy link
Member

Choose a reason for hiding this comment

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

Is this not yelling at you for a newline?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nah, I can add it back in though. I received maybe one or two warnings about this at different times, but it seems all over the place when it "cares"

Copy link
Contributor

Choose a reason for hiding this comment

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

The rule is never more than one newline I believe, so this would be valid.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This would get caught on CI as well.

Copy link
Contributor Author

@nalogiudice nalogiudice left a comment

Choose a reason for hiding this comment

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

Responded to some comments

@@ -2,6 +2,10 @@ import Button from "./button";
export {Button};
export * from "./button";

import Toggle from "./toggle";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like above, I think we should have our components separate from our other stuff. If we vote otherwise, I'm fine with it though.

@@ -1,2 +1,5 @@
import ButtonExamples from "../src/button/examples.data";
export {ButtonExamples};

import ToggleExamples from "../src/toggle/examples.data";
export {ToggleExamples};
Copy link
Contributor

Choose a reason for hiding this comment

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

The rule is never more than one newline I believe, so this would be valid.

import * as React from "react";

export interface IToggleProps {
children?: React.ReactNode | React.ReactNode[];
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree - requiring a string seems unnecessarily restrictive.

@@ -0,0 +1,13 @@
import * as React from "react";

export interface IToggleProps {
Copy link
Contributor

Choose a reason for hiding this comment

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

We've changed naming conventions for props slightly - can you align the prop names to the format button uses?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do

}

/**
* Generates global aria-disabled
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment doesn't really map to the function name - can you align the two?

or you could remove this method entirely - I think it makes sense when there is a bunch of conditional logic for rendering attributes, but if you're simply setting one attribute I think it is more readable to apply that in the render method directly.

<div
  aria-disabled={ this.props.disabled || null }
  //...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing


return toggleAttributes;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

same here - there doesn't seem to be much rhyme or reason why some attributes are applied here but others are applied in the render method- I'd just put all these in the render method and reduce some of the code-clutter that having an extra method creates.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing

/>
<span />
</div>
<span id={this.props.spanId}>
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we should call this statusLabel or something? spanId isn't a very semantic name.

Copy link
Contributor Author

@nalogiudice nalogiudice Apr 9, 2018

Choose a reason for hiding this comment

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

Changed to statusLabelId to match other naming

unselectedString: "Off"
}
]
} as IGenericExample<IToggleProps>;
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 Check out the button component

@@ -0,0 +1,6 @@
import * as React from "react";
import { IFoundationProps, IToggleClassNameContract, IToggleProps, Toggle } from "@microsoft/fast-components-react-base";
Copy link
Contributor

Choose a reason for hiding this comment

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

Yea the linter will fail this

@@ -10,4 +10,25 @@ const designSystemDefaults: IDesignSystem = {
brandColor: "#0078D4"
};

/**
* Returns RGBA from hex value with optional alpha
Copy link
Contributor

Choose a reason for hiding this comment

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

It would likely live in the color package - that already takes a dependency on chroma-js which probably has this functionality, so you might just use that


const styles: ComponentStyles<IToggleClassNameContract, IDesignSystem> = {
toggle: {
'& > label': {
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

We're going to be mapping more directly to BEM principles - meaning that the span that indicates the status of the toggle would have a class directly associated to it, such as toggle_status_indicator

@awentzel awentzel changed the title feat(toggle): adds toggle component and msft styles feat(toggle): add new component and msft styles Apr 5, 2018
@awentzel awentzel added feature A new feature type : feat and removed type : docs labels Apr 5, 2018
@nalogiudice nalogiudice force-pushed the users/nalogiudice/component-create-toggle branch 2 times, most recently from ddcc3dc to 03776d2 Compare April 11, 2018 09:09
@nalogiudice nalogiudice force-pushed the users/nalogiudice/component-create-toggle branch from 5ffd72e to d477813 Compare April 11, 2018 18:14
@nalogiudice nalogiudice force-pushed the users/nalogiudice/component-create-toggle branch from 8a815c8 to fc42419 Compare April 12, 2018 02:42
@nalogiudice nalogiudice force-pushed the users/nalogiudice/component-create-toggle branch from fc42419 to 39dbed8 Compare April 12, 2018 04:00
@nalogiudice nalogiudice force-pushed the users/nalogiudice/component-create-toggle branch from 37d507a to 84135dc Compare April 12, 2018 18:46
data: [
{
managedClasses: {
toggle: "toggle" },
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, formatting

@nalogiudice nalogiudice merged commit b9dd3e0 into master Apr 12, 2018
@nalogiudice nalogiudice deleted the users/nalogiudice/component-create-toggle branch April 12, 2018 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants