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

[Badge] Port Badge Component #6043

Merged
merged 7 commits into from
Feb 7, 2017
Merged

[Badge] Port Badge Component #6043

merged 7 commits into from
Feb 7, 2017

Conversation

stunaz
Copy link
Contributor

@stunaz stunaz commented Jan 31, 2017

  • PR has tests / docs demo, and is linted.
  • Commit and PR titles begin with [ComponentName], and are in imperative form: "[Component] Fix leaky abstraction".
  • Description explains the issue / use-case resolved, and auto-closes the related issue(s) (http://tr.im/vFqem).

For #4784

badge

@muibot muibot added PR: Needs Review PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI and removed PR: Needs Review labels Jan 31, 2017
@oliviertassinari oliviertassinari added component: badge This is the name of the generic UI component, not the React module! next labels Jan 31, 2017
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

That looks pretty cool so far. Thanks for contributing to the next effort!
I couldn't review it in detail. Will do it later.
It would be awesome if you could add a visual regression test.


assert.strictEqual(wrapper.contains(testChildren), true, 'should contain the children');
assert.strictEqual(wrapper.node.props.style.backgroundColor, style.backgroundColor,
'should overwrite badge backgroundColor');
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 that our convention is the following one:

assert.strictEqual(wrapper.node.props.style.backgroundColor, style.backgroundColor,
  'should overwrite badge backgroundColor');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean the spaces? if so I will change that.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it's about the spacing.

badgeContent,
className: classNameProp,
children,
primary, // eslint-disable-line no-unused-vars
Copy link
Member

Choose a reason for hiding this comment

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

no need for // eslint-disable-line no-unused-vars

className: classNameProp,
children,
primary, // eslint-disable-line no-unused-vars
accent, // eslint-disable-line no-unused-vars
Copy link
Member

Choose a reason for hiding this comment

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

no need for // eslint-disable-line no-unused-vars

import customPropTypes from '../utils/customPropTypes';

const radius = 12;
const radius2x = Math.floor(2 * radius);
Copy link
Member

Choose a reason for hiding this comment

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

Math.floor(?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't really know, took it from the master branch

Copy link
Member

Choose a reason for hiding this comment

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

@stunaz It rounds down to the nearest integer, which doesn't make much sense for integer multiplication. 😄

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 get that, so I just write const radius2x = 2 * radius;, will that be ok?

Copy link
Member

Choose a reason for hiding this comment

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

@stunaz Sounds good.

/**
* The badge will be added relativelty to this node.
*/
children: PropTypes.node,
Copy link
Member

Choose a reason for hiding this comment

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

Should children be required? Not sure a badge makes much sense without...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

indeed, makes sense. I will mark it as required.

@mbrookes
Copy link
Member

mbrookes commented Feb 1, 2017

@stunaz thanks for picking up the migration of this component - Tooltip has your name all over it for the next one! 😆

While we have the opportunity though, I think it would be worth discussing what a badge should do and look like. I've never liked the large separation between the badge and its child, so I went back to the source (Material Design spec), and discovered that, at least as far as is searchable, there is none. The only reference to badge is in FAB, saying not to add one. (If there are examples in the spec, so much the better - I didn't browse every page looking for one).

As a next-best-thing, here's what MDL have done:

screen shot 2017-02-01 at 1 02 52 am

screen shot 2017-02-01 at 1 03 30 am

That overlap with the child component seems quintessential for a badge.

Secondly, I'd question the validity of some of our current examples:

Should a badge be applied to an icon that is smaller than the badge itself?
Should a badge be an IconButton?
Should a badge be used as a substitute for superscript? ( (c) symbol example. )

Lets see if we can improve this as part of the migration, otherwise it's likely to be left for the forseeable.

- set children as required prop
- remove useless lint comment
@@ -11,7 +11,7 @@ Props
| accent | bool | false | If true, the badge will use the accent badge colors. |
| badgeClassName | string | | The CSS class name of the badge element. |
| <span style="color: #31a148">badgeContent *</span> | node | | This is the content rendered within the badge. |
| children | node | | The badge will be added relativelty to this node. |
| <span style="color: #31a148">children *</span> | node | | The badge will be added relativelty to this node. |
Copy link
Member

Choose a reason for hiding this comment

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

Typo in relatively, but it should probably be relative, and even then the sentence is awkward.

How about simply "The node that the badge will be applied to."

@stunaz
Copy link
Contributor Author

stunaz commented Feb 1, 2017

@mbrookes Tooltip 😃 , I can certainly try, but I think it is a big one as it involves a lot of things like performance for starter.

I surely can work on the applied styles and improve the examples.

Should a badge be applied to an icon that is smaller than the badge itself?

Maybe this dicision should be on the userland ?

Should a badge be an IconButton?

Interesting ... I tried, it works, but it can look ugly if primary or accent are applied to the badge

Should a badge be used as a substitute for superscript? ( (c) symbol example. )

I don't see why not

@mbrookes
Copy link
Member

mbrookes commented Feb 1, 2017

it involves a lot of things like performance

Mm, right I'd forgotten about that concern.

Maybe this dicision should be on the userland ?

Yes, but we shouldn't really be demonstrating an example of poor usage.

it works

Yes, but again I don't think it represents good practice, so shouldn't be a docs example.

I don't see why not

Because there is already a semantically valid way of achieving that? It's another questionable example IMHO.

Appreciate you inherited these issues from master!

@stunaz
Copy link
Contributor Author

stunaz commented Feb 1, 2017

Maybe we drop the further example, and show only the simple example ?
What about something like this:
badge2

@stunaz
Copy link
Contributor Author

stunaz commented Feb 1, 2017

@oliviertassinari @mbrookes Can you please point me how to make visual regression test ?

@mbrookes
Copy link
Member

mbrookes commented Feb 1, 2017

What about something like this

Much better! Perhaps an appropriate color / shade of grey for the main icons rather than black?

@oliviertassinari oliviertassinari force-pushed the next branch 6 times, most recently from cd92911 to 2f73c43 Compare February 2, 2017 19:59
@oliviertassinari
Copy link
Member

@stunaz Do you need any help? I'm not sure what's preventing us from moving forward.

@stunaz
Copy link
Contributor Author

stunaz commented Feb 2, 2017

@oliviertassinari I will try and add a visual regression test tonight. @mbrookes had concerrn about what the examples that should be shown. What do you want me to do about that?

@stunaz
Copy link
Contributor Author

stunaz commented Feb 3, 2017

I couldnt make it work, looks like I have an env issue :
Running the docker, I kind of have an error at the end:
screen shot 2017-02-03 at 8 03 07 am

Running the test regressions, I got:
screen shot 2017-02-03 at 8 03 24 am

apart from the visual regression test, is there something else that I can do?

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

I agree with @mbrookes, the examples of material-design-lite are just great. I think that we can keep a single Simple examples demo following mdl.
Regarding the visual regressions, do you have any error message?

import NotificationIcon from 'material-ui/svg-icons/notification';

const styleSheet = createStyleSheet('SimpleBadge', () => ({
badge: {
Copy link
Member

Choose a reason for hiding this comment

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

Two points here:

  1. That style doesn't have enough specificity to be applied. It's a dead style
    You need to add the badge component into the MUI_SHEET_ORDER.
  2. Users shouldn't have to add that style. It should be handled by the badge.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmmm @oliviertassinari , I didn't get that.

  1. I am not sure what MUI_SHEET_ORDER is for? You mean adding it in docs/site/src/components/App?
  2. That style is not needed, it is just for the demo. I have updated the example code, have a look

root: {
position: 'relative',
display: 'inline-block',
padding: `${radius2x}px ${radius2x}px ${radius}px ${radius}px`,
Copy link
Member

Choose a reason for hiding this comment

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

I agree with @mbrookes. I don't think that the badge should impact the layout of the element.
What about removing that padding property?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree too. done

alignContent: 'center',
alignItems: 'center',
position: 'absolute',
top: 0,
Copy link
Member

Choose a reason for hiding this comment

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

What about?

top: -radius,

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

alignItems: 'center',
position: 'absolute',
top: 0,
right: 0,
Copy link
Member

Choose a reason for hiding this comment

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

What about?

right: -radius,

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

@stunaz
Copy link
Contributor Author

stunaz commented Feb 6, 2017

@oliviertassinari I have done some modification, here is the new look of the page:
screen shot 2017-02-05 at 8 28 40 pm

Regarding the visual regression test it is not working, here is the logs that I think explain the issue:
Are you guys working on windows ? ( I am on mac)
screen shot 2017-02-05 at 8 35 58 pm

@oliviertassinari oliviertassinari dismissed their stale review February 6, 2017 23:09

Looks good :)

);

assert.strictEqual(wrapper.contains(testChildren), true, 'should contain the children');
assert.strictEqual(wrapper.node.props.style.backgroundColor, style.backgroundColor,
Copy link
Member

Choose a reason for hiding this comment

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

assert.strictEqual(wrapper.props().style.backgroundColor, style.backgroundColor,

@oliviertassinari
Copy link
Member

oliviertassinari commented Feb 6, 2017

Regarding the visual regression test it is not working, here is the logs that I think explain the issue:
Are you guys working on windows ? ( I am on mac)

We are on a Mac too. I have the same issues on my docker logs. I don't think that the issue is on that end. I can take care of generating the visual diff this time :). Could you just fix the linting issue?

@stunaz
Copy link
Contributor Author

stunaz commented Feb 7, 2017

there are no more linting issue, the ci because fails because of the image missing, I can remove the regression test

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

@stunaz I'm gonna do a second iteration on this PR to fix the build. Thanks a lot!

@oliviertassinari oliviertassinari added PR: Review Accepted and removed PR: Needs Review PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Feb 7, 2017
@oliviertassinari oliviertassinari merged commit 9a50136 into mui:next Feb 7, 2017
@muibot muibot added the PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI label Feb 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: badge This is the name of the generic UI component, not the React module! PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants