-
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
textClassName property for Button component #4460
Comments
Thanks for the kind words about Blueprint. I'd like to avoid adding this prop unless absolutely necessary. I think you can work around this with CSS. If not, can you please create a code sandbox demonstrating the lack of customizability? |
Of course you can work around with CSS (this is why I love working with the blueprint components), but the CSS would have to be "aware" of the .bp3-* classes hierarchy, which I try to avoid as much as possible... Let's see a pseudo-code import { Button } from '@blueprintjs/core';
import { Component } from 'react';
export default class ClickableOrNot extends Component<{ clickable: boolean; className?: string }> {
render() {
const { clickable, className } = this.props;
return clickable ? (
<Button className={className}>{this.props.children}</Button>
) : (
<span className={className}>{this.props.children}</span>
);
}
}
<ClickableOrNot clickable={true} className="clickable-or-not-text">Text content</ClickableOrNot> The CSS to have the same visual feedback would be .clickable-or-not-text, .bp3-button.clickable-or-not-text > .bp3-button-text
color: red Wouldn't be more "elegant" to have ? render() {
const { clickable, className } = this.props;
return clickable ? (
<Button textClassName={className}>{this.props.children}</Button>
) : (
<span className={className}>{this.props.children}</span>
);
} .clickable-or-not-text
color: red |
What happens if you change the color of the whole button? Why do you need to target the text span specifically? |
Yeah, the color might be a bad example, but still significant if you use text/svg in your I'm thinking more about paddings, borders, etc... |
I'm inclined to decline this request for now. In general we guarantee backwards compatibility for the DOM structure rendered by Blueprint components, especially fundamental ones like buttons. So you should feel safe applying custom styling with |
I get it. Thanks for answering ;-) |
Revisiting this old issue, I think should add a // in a CSS module
@use "@blueprintjs/core/lib/scss/variables" as bp;
.my-button {
:global(.#{bp.$ns}-button-text) {
overflow: hidden;
text-wrap: nowrap;
text-overflow: ellipsis;
}
} Whereas it would be nicer if users could do this: <Button textClassName={Classes.TEXT_OVERFLOW_ELLIPSIS} /> N.B. it might be even nicer if Buttons had a prop for text overflow styling, but that's out of scope for this issue. |
Note that <Button className={Classes.TEXT_MUTED} /> because this class loses on CSS specificity to some See #6516 |
Environment
Feature request
Would it be a good idea to add a 'textClassName' to the Button props, which would be added to the text span?
Examples
I'm currently creating a zone which can (or cannot) be a button, kinda
<Zone className='text-or-button' clickable={true}>Zone content</Zone>
The component is returning a
<Button />
(with no margin, padding, background or border) or<span />
depending on the clickable prop.The idea is to allow to customize the zone via CSS just by defining , without having to use .bp3-button-text
What do you think?
PS: Well done Palantir guys, Blueprint is a huge component set, very well designed and coded. And I love the highly customizable output thanks to CSS.
The text was updated successfully, but these errors were encountered: