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

Collapse borders between buttons in outlined ButtonGroup #7005

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
9 changes: 9 additions & 0 deletions packages/core/src/components/button/_button-group.scss
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,20 @@ Styleguide button-group
}

&.#{$ns}-outlined {
> .#{$ns}-popover-target > .#{$ns}-button,
> .#{$ns}-button {
@include pt-button-outlined();
}

&.#{$ns}-vertical {
> .#{$ns}-popover-target:not(:last-child) .#{$ns}-button,
> .#{$ns}-button:not(:last-child) {
border-bottom: none;
}
}

&:not(.#{$ns}-vertical) {
> .#{$ns}-popover-target:not(:last-child) > .#{$ns}-button,
> .#{$ns}-button:not(:last-child) {
border-right: none;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes to this file include a subset of the same changes originally applied in #6966, but scoped only to the outlined ButtonGroup.

Expand Down
28 changes: 15 additions & 13 deletions packages/core/src/components/button/button-group.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@# Button group

__ButtonGroup__ arranges multiple buttons in a horizontal or vertical group.
**ButtonGroup** arranges multiple buttons in a horizontal or vertical group.

@reactExample ButtonGroupExample

@## Usage

Most of __ButtonGroup__'s props are also supported by __Button__ directly; setting these props on __ButtonGroup__ will
Most of **ButtonGroup**'s props are also supported by **Button** directly; setting these props on **ButtonGroup** will
Copy link
Contributor Author

@ggdouglas ggdouglas Oct 1, 2024

Choose a reason for hiding this comment

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

Formatting changes were added here by prettier on editor save.

apply the same value to all buttons in the group. Note that most modifiers, once enabled on the group, cannot be
overridden on child buttons (due to the cascading nature of CSS).

Expand All @@ -26,32 +26,33 @@ The component also supports all HTML `<div>` props.

@## Usage with popovers

__Button__ elements inside a __ButtonGroup__ can trivially be wrapped with a [__Popover__](#core/components/popover) to
create complex toolbars.
**Button** elements inside a **ButtonGroup** can be wrapped with a [**Popover**](#core/components/popover) to create
complex toolbars or to provide split button functionality, allowing the action of a **Button** to be changed.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think "split button" is the unique thing to call out here in the use with popovers section, maybe "menu button"?

Also not sure about allowing the action of a **Button** to be changed - pretty much anything could be done inside the popover so it feels weird to call out a specific case here. I think it would be weird if the popover just contained options that would change the wrapped button's behavior (implying it needs to be clicked again?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, fair! I originally modeled this after GitHub's own merge options button, which I've seen as a pretty common dropdown use pattern in other places. Totally fine with omitting this and leaving the docs as is if the example isn't adding value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted 7776357


@reactExample ButtonGroupPopoverExample

@## Flex layout

__ButtonGroup__ renders a CSS inline flex row (or column if vertical) and provides some modifer props for common
**ButtonGroup** renders a CSS inline flex row (or column if vertical) and provides some modifer props for common
flexbox patterns:

- Enable the `fill` prop on a button group to make all buttons expand equally to
fill the available space.
- Buttons will expand horizontally by default, or vertically if the `vertical` prop is enabled.
- Add the class `Classes.FIXED` to individual buttons to revert them to their initial sizes.
- Enable the `fill` prop on a button group to make all buttons expand equally to
fill the available space.

- Alternatively, enable the `fill` prop on specific buttons (instead of on the
group) to expand them equally to fill the available space while other
buttons retain their original sizes.
- Buttons will expand horizontally by default, or vertically if the `vertical` prop is enabled.
- Add the class `Classes.FIXED` to individual buttons to revert them to their initial sizes.

- Alternatively, enable the `fill` prop on specific buttons (instead of on the
group) to expand them equally to fill the available space while other
buttons retain their original sizes.

You can adjust the specific size of a button with the `flex-basis` or `width` CSS properties.

@## Vertical layout

Buttons in a vertical group all have the same width as the widest button in the group.

Use the `alignText` prop to control icon and text alignment in the buttons. Set this prop on __ButtonGroup__ to affect
Use the `alignText` prop to control icon and text alignment in the buttons. Set this prop on **ButtonGroup** to affect
all buttons in the group, or set the prop on individual buttons directly.

@## CSS API
Expand All @@ -60,6 +61,7 @@ all buttons in the group, or set the prop on individual buttons directly.
<h5 class="@ns-heading">

Deprecated API: use [`<ButtonGroup>`](#core/components/button-group)

</h5>

CSS APIs for Blueprint components are considered deprecated, as they are verbose, error-prone, and they
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import * as React from "react";

import { Alignment, Button, ButtonGroup, H5, type IconName, Popover, Switch } from "@blueprintjs/core";
import { Alignment, Button, ButtonGroup, H5, type IconName, Menu, MenuItem, Popover, Switch } from "@blueprintjs/core";
import { Example, type ExampleProps, handleBooleanChange } from "@blueprintjs/docs-theme";

import { AlignmentSelect } from "./common/alignmentSelect";
Expand Down Expand Up @@ -70,6 +70,7 @@ export class ButtonGroupPopoverExample extends React.PureComponent<ExampleProps,
{this.renderButton("Edit", "edit")}
{this.renderButton("View", "eye-open")}
</ButtonGroup>
<SplitButtonExample {...this.state} />
</Example>
);
}
Expand All @@ -86,3 +87,32 @@ export class ButtonGroupPopoverExample extends React.PureComponent<ExampleProps,

private handleAlignChange = (alignText: Alignment) => this.setState({ alignText });
}

const mergeOptions = ["Create a merge commit", "Squash and merge", "Rebase and merge"];

function SplitButtonExample(props: ButtonGroupPopoverExampleState) {
const [selectedIndex, setSelectedIndex] = React.useState(0);
return (
<ButtonGroup {...props} aria-label="Button group with menu">
<Button text={mergeOptions[selectedIndex]} />
<Popover
content={
<Menu>
{mergeOptions.map((option, i) => (
<MenuItem
key={option}
text={option}
onClick={() => setSelectedIndex(i)}
active={i === selectedIndex}
/>
))}
</Menu>
}
minimal={true}
position="bottom-right"
>
<Button icon="caret-down" aria-label="Select merge method" />
</Popover>
</ButtonGroup>
);
}
7 changes: 7 additions & 0 deletions packages/docs-app/src/styles/_examples.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@
}
}

#{example("ButtonGroupPopover")} {
.docs-example {
flex-direction: column;
gap: $pt-grid-size * 3;
}
}

#{example("CardList")} {
.docs-example > div {
flex-grow: 1;
Expand Down