-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
flex menu item #2075
flex menu item #2075
Changes from 7 commits
7f6fca4
6f8f630
bea2501
29047cf
633d513
ae5e44c
9f3f5e6
c268f85
1752e03
dd2a6da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2018 Palantir Technologies, Inc. All rights reserved. | ||
// Licensed under the terms of the LICENSE file distributed with this project. | ||
|
||
// this element becomes a flex container in the given direction. | ||
// supply `$margin` to put space between each child. | ||
// supply `$inline: inline` to use `display: flex-inline`. | ||
// customize `flex: 1 1` child selector with $fill. | ||
@mixin pt-flex-container($direction: row, $margin: none, $inline: none, $fill: ".pt-fill") { | ||
@if $inline == inline or $inline == true { | ||
display: inline-flex; | ||
} @else { | ||
display: flex; | ||
} | ||
flex-direction: $direction; | ||
|
||
> * { | ||
flex: 0 0 auto; | ||
} | ||
|
||
> #{$fill} { | ||
flex: 1 1 auto; | ||
} | ||
|
||
@if $margin != none { | ||
@include pt-flex-margin($direction, $margin); | ||
} | ||
} | ||
|
||
// applies margin along axis of direction between every direct child, with no margins on either end. | ||
// $direction: row | column | ||
// $margin: margin[-right|-bottom] value | ||
@mixin pt-flex-margin($direction, $margin) { | ||
// CSS API support | ||
&::before, | ||
> :not(:last-child) { | ||
@if $direction == row { | ||
margin-right: $margin; | ||
} @else { | ||
margin-bottom: $margin; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,13 @@ export interface IMenuItemProps extends IActionProps, ILinkProps { | |
*/ | ||
label?: string | JSX.Element; | ||
|
||
/** | ||
* Whether the text should be allowed to wrap to multiple lines. | ||
* If `false`, text will be truncated with an ellipsis when it reaches `max-width`. | ||
* @default false | ||
*/ | ||
multiline?: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎩 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @llorca thoughts on the centered icon alignment when multiline? (see your screenshot in comment below) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good call, actually aligned at the top would be better in this case |
||
|
||
/** Props to spread to `Popover`. Note that `content` and `minimal` cannot be changed. */ | ||
popoverProps?: Partial<IPopoverProps>; | ||
|
||
|
@@ -45,6 +52,7 @@ export interface IMenuItemProps extends IActionProps, ILinkProps { | |
export class MenuItem extends AbstractPureComponent<IMenuItemProps> { | ||
public static defaultProps: IMenuItemProps = { | ||
disabled: false, | ||
multiline: false, | ||
popoverProps: {}, | ||
shouldDismissPopover: true, | ||
text: "", | ||
|
@@ -66,6 +74,7 @@ export class MenuItem extends AbstractPureComponent<IMenuItemProps> { | |
}, | ||
this.props.className, | ||
); | ||
const textClasses = classNames(Classes.FILL, { [Classes.TEXT_OVERFLOW_ELLIPSIS]: !this.props.multiline }); | ||
|
||
const target = ( | ||
<a | ||
|
@@ -76,8 +85,9 @@ export class MenuItem extends AbstractPureComponent<IMenuItemProps> { | |
target={this.props.target} | ||
> | ||
<Icon iconName={this.props.iconName} /> | ||
<span className={textClasses}>{this.props.text}</span> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. back to the topic of our public CSS API! this is very similar to what I had a few months ago--it was considered breaking then, so it's technically breaking now since you're adding a span. if you remove the span from this current PR, this is what it looks like: reiterating that it's quite annoying, this sort of internal refactor should not be considered breaking, and we should be able to do these outside of major versions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this implementation is not an API break, though! i added an element but only inside the React component. you can of course easily break the appearance by mucking in the console--that doesn't mean it's an API break. you'll notice, most importantly, that all the CSS markup examples still look perfect, like before. I made no external changes to the CSS or React APIs. folks who use only |
||
{label && <span className={Classes.MENU_ITEM_LABEL}>{label}</span>} | ||
{this.props.text} | ||
{hasSubmenu && <Icon iconName="caret-right" />} | ||
</a> | ||
); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,5 +29,5 @@ | |
} | ||
|
||
.docs-releases-menu .pt-menu { | ||
width: 320px; | ||
min-width: 270px; | ||
} |
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.
align-items
is much better at alignment than humans, so this shouldn't be necessary. keep an eye out for SVG icons mixed with text to ensure they're centered.