-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Conversation
There was a problem hiding this 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.
src/Badge/Badge.spec.js
Outdated
|
||
assert.strictEqual(wrapper.contains(testChildren), true, 'should contain the children'); | ||
assert.strictEqual(wrapper.node.props.style.backgroundColor, style.backgroundColor, | ||
'should overwrite badge backgroundColor'); |
There was a problem hiding this comment.
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');
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/Badge/Badge.js
Outdated
badgeContent, | ||
className: classNameProp, | ||
children, | ||
primary, // eslint-disable-line no-unused-vars |
There was a problem hiding this comment.
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
src/Badge/Badge.js
Outdated
className: classNameProp, | ||
children, | ||
primary, // eslint-disable-line no-unused-vars | ||
accent, // eslint-disable-line no-unused-vars |
There was a problem hiding this comment.
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
src/Badge/Badge.js
Outdated
import customPropTypes from '../utils/customPropTypes'; | ||
|
||
const radius = 12; | ||
const radius2x = Math.floor(2 * radius); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Math.floor(
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. 😄
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stunaz Sounds good.
src/Badge/Badge.js
Outdated
/** | ||
* The badge will be added relativelty to this node. | ||
*/ | ||
children: PropTypes.node, |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
@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: 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? 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
docs/api/Badge/Badge.md
Outdated
@@ -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. | |
There was a problem hiding this comment.
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."
@mbrookes I surely can work on the applied styles and improve the examples.
Maybe this dicision should be on the userland ?
Interesting ... I tried, it works, but it can look ugly if
I don't see why not |
Mm, right I'd forgotten about that concern.
Yes, but we shouldn't really be demonstrating an example of poor usage.
Yes, but again I don't think it represents good practice, so shouldn't be a docs example.
Because there is already a semantically valid way of achieving that? It's another questionable example IMHO. Appreciate you inherited these issues from master! |
@oliviertassinari @mbrookes Can you please point me how to make visual regression test ? |
Much better! Perhaps an appropriate color / shade of grey for the main icons rather than black? |
cd92911
to
2f73c43
Compare
@stunaz Do you need any help? I'm not sure what's preventing us from moving forward. |
@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? |
There was a problem hiding this 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: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two points here:
- That style doesn't have enough specificity to be applied. It's a dead style
You need to add the badge component into theMUI_SHEET_ORDER
. - Users shouldn't have to add that style. It should be handled by the badge.
There was a problem hiding this comment.
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.
- I am not sure what
MUI_SHEET_ORDER
is for? You mean adding it indocs/site/src/components/App
? - That style is not needed, it is just for the demo. I have updated the example code, have a look
src/Badge/Badge.js
Outdated
root: { | ||
position: 'relative', | ||
display: 'inline-block', | ||
padding: `${radius2x}px ${radius2x}px ${radius}px ${radius}px`, |
There was a problem hiding this 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. I don't think that the badge should impact the layout of the element.
What about removing that padding
property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree too. done
src/Badge/Badge.js
Outdated
alignContent: 'center', | ||
alignItems: 'center', | ||
position: 'absolute', | ||
top: 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about?
top: -radius,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/Badge/Badge.js
Outdated
alignItems: 'center', | ||
position: 'absolute', | ||
top: 0, | ||
right: 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about?
right: -radius,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@oliviertassinari I have done some modification, here is the new look of the page: Regarding the visual regression test it is not working, here is the logs that I think explain the issue: |
); | ||
|
||
assert.strictEqual(wrapper.contains(testChildren), true, 'should contain the children'); | ||
assert.strictEqual(wrapper.node.props.style.backgroundColor, style.backgroundColor, |
There was a problem hiding this comment.
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,
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? |
there are no more linting issue, the |
There was a problem hiding this 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!
For #4784