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

[core] feat(Button): add "outlined" modifier #3947

Merged
merged 7 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/src/common/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const INTERACTIVE = `${NS}-interactive`;
export const LARGE = `${NS}-large`;
export const LOADING = `${NS}-loading`;
export const MINIMAL = `${NS}-minimal`;
export const OUTLINED = `${NS}-outlined`;
export const MULTILINE = `${NS}-multiline`;
export const ROUND = `${NS}-round`;
export const SMALL = `${NS}-small`;
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/components/button/_button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Markup:
.#{$ns}-intent-warning - Warning intent
.#{$ns}-intent-danger - Danger intent
.#{$ns}-minimal - More subtle appearance
.#{$ns}-outlined - Subtle yet structured appearance
.#{$ns}-large - Larger size
.#{$ns}-small - Smaller size
.#{$ns}-fill - Fill parent container
Expand Down Expand Up @@ -163,6 +164,12 @@ Styleguide button
&.#{$ns}-minimal {
@include pt-button-minimal();
}

// outline is based on the styles of minimal
&.#{$ns}-outlined {
@include pt-button-minimal();
@include pt-button-outlined();
}
}

a.#{$ns}-button {
Expand Down
57 changes: 57 additions & 0 deletions packages/core/src/components/button/_common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ $dark-minimal-button-background-color: none !default;
$dark-minimal-button-background-color-hover: rgba($gray3, 0.15) !default;
$dark-minimal-button-background-color-active: rgba($gray3, 0.3) !default;

$button-outlined-width: 1px !default;
$button-outlined-border-intent-opacity: 0.6 !default;
$button-outlined-border-disabled-intent-opacity: 0.2 !default;

// "intent": (default, hover, active colors)
$button-intents: (
"primary": ($pt-intent-primary, $blue2, $blue1),
Expand Down Expand Up @@ -448,3 +452,56 @@ $button-intents: (
}
}

@mixin pt-button-outlined() {
border: $button-outlined-width solid rgba($pt-text-color, 0.2);
box-sizing: border-box;

&:disabled,
&.#{$ns}-disabled,
&:disabled:hover,
&.#{$ns}-disabled:hover {
border-color: rgba($pt-text-color-disabled, 0.1);
}

.#{$ns}-dark & {
@include pt-dark-button-outlined();
}

@each $intent, $colors in $button-intents {
&.#{$ns}-intent-#{$intent} {
@include pt-button-outlined-intent(
map-get($pt-intent-text-colors, $intent),
map-get($pt-dark-intent-text-colors, $intent)
);
}
}
}

@mixin pt-dark-button-outlined() {
border-color: rgba($white, 0.4);

&:disabled,
&:disabled:hover,
&.#{$ns}-disabled,
&.#{$ns}-disabled:hover {
border-color: rgba($white, 0.2);
}
}

@mixin pt-button-outlined-intent($text-color, $dark-text-color) {
border-color: rgba($text-color, $button-outlined-border-intent-opacity);

&:disabled,
&.#{$ns}-disabled {
border-color: rgba($text-color, $button-outlined-border-disabled-intent-opacity);
}

.#{$ns}-dark & {
border-color: rgba($dark-text-color, $button-outlined-border-intent-opacity);

&:disabled,
&.#{$ns}-disabled {
border-color: rgba($dark-text-color, $button-outlined-border-disabled-intent-opacity);
}
}
}
6 changes: 5 additions & 1 deletion packages/core/src/components/button/abstractButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export interface IButtonProps extends IActionProps {
/** Whether this button should use minimal styles. */
minimal?: boolean;

/** Whether this button should use outlined styles. */
outlined?: boolean;

/** Name of a Blueprint UI icon (or an icon element) to render after the text. */
rightIcon?: IconName | MaybeElement;

Expand Down Expand Up @@ -96,7 +99,7 @@ export abstract class AbstractButton<H extends React.HTMLAttributes<any>> extend
public abstract render(): JSX.Element;

protected getCommonButtonProps() {
const { alignText, fill, large, loading, minimal, small, tabIndex } = this.props;
const { alignText, fill, large, loading, outlined, minimal, small, tabIndex } = this.props;
const disabled = this.props.disabled || loading;

const className = classNames(
Expand All @@ -108,6 +111,7 @@ export abstract class AbstractButton<H extends React.HTMLAttributes<any>> extend
[Classes.LARGE]: large,
[Classes.LOADING]: loading,
[Classes.MINIMAL]: minimal,
[Classes.OUTLINED]: outlined,
[Classes.SMALL]: small,
},
Classes.alignmentClass(alignText),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface IButtonsExampleState {
loading: boolean;
large: boolean;
minimal: boolean;
outlined: boolean;
wiggling: boolean;
}

Expand All @@ -41,6 +42,7 @@ export class ButtonsExample extends React.PureComponent<IExampleProps, IButtonsE
large: false,
loading: false,
minimal: false,
outlined: false,
wiggling: false,
};

Expand All @@ -50,6 +52,7 @@ export class ButtonsExample extends React.PureComponent<IExampleProps, IButtonsE
private handleLargeChange = handleBooleanChange(large => this.setState({ large }));
private handleLoadingChange = handleBooleanChange(loading => this.setState({ loading }));
private handleMinimalChange = handleBooleanChange(minimal => this.setState({ minimal }));
private handleOutlinedChange = handleBooleanChange(outlined => this.setState({ outlined }));
private handleIntentChange = handleStringChange((intent: Intent) => this.setState({ intent }));

private wiggleTimeoutId: number;
Expand All @@ -69,6 +72,7 @@ export class ButtonsExample extends React.PureComponent<IExampleProps, IButtonsE
<Switch label="Large" checked={this.state.large} onChange={this.handleLargeChange} />
<Switch label="Loading" checked={this.state.loading} onChange={this.handleLoadingChange} />
<Switch label="Minimal" checked={this.state.minimal} onChange={this.handleMinimalChange} />
<Switch label="Outlined" checked={this.state.outlined} onChange={this.handleOutlinedChange} />
<IntentSelect intent={this.state.intent} onChange={this.handleIntentChange} />
<H5>Example</H5>
<Switch label="Icons only" checked={this.state.iconOnly} onChange={this.handleIconOnlyChange} />
Expand Down