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

Feat(web): Introduce SplitButton component #DS-1605 #1919

Merged
merged 2 commits into from
Feb 13, 2025
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
18 changes: 12 additions & 6 deletions packages/web/src/scss/components/Button/_Button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
border-width: theme.$border-width;
border-style: theme.$border-style;
border-color: var(--#{tokens.$css-variable-prefix}button-border-color);
border-radius: theme.$border-radius;
border-start-start-radius: var(
--#{tokens.$css-variable-prefix}button-border-start-start-radius,
theme.$border-radius
);
border-start-end-radius: var(--#{tokens.$css-variable-prefix}button-border-start-end-radius, theme.$border-radius);
border-end-start-radius: var(--#{tokens.$css-variable-prefix}button-border-end-start-radius, theme.$border-radius);
border-end-end-radius: var(--#{tokens.$css-variable-prefix}button-border-end-end-radius, theme.$border-radius);
background-color: var(--#{tokens.$css-variable-prefix}button-background-color);
user-select: none;
cursor: cursors.$buttons;
Expand Down Expand Up @@ -71,15 +77,15 @@
}

.Button:is(:disabled, .is-disabled, .Button--disabled):not(.Button--loading) {
color: theme.$disabled-color;
border-color: theme.$disabled-border-color;
background-color: theme.$disabled-background-color;
--#{tokens.$css-variable-prefix}button-color: #{theme.$disabled-color};
--#{tokens.$css-variable-prefix}button-border-color: #{theme.$disabled-border-color};
--#{tokens.$css-variable-prefix}button-background-color: #{theme.$disabled-background-color};
}

// We need to override the default disabled styles for plain buttons, because we want them to be still plain.
.Button--plain:is(:disabled, .is-disabled, .Button--disabled):not(.Button--loading) {
border-color: transparent;
background-color: transparent;
--#{tokens.$css-variable-prefix}button-border-color: transparent;
--#{tokens.$css-variable-prefix}button-background-color: transparent;
}

.Button.Button--loading {
Expand Down
84 changes: 84 additions & 0 deletions packages/web/src/scss/components/SplitButton/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Split Button

The Split Button component groups multiple related actions a user can take, combining a button with additional options like a dropdown menu or tooltips for better usability.

⚠️ It is recommended to always use the same button colors for all buttons inside a Split Button.

Learn more about the [Button][readme-button] component in its documentation.

Simple variant:

```html
<div class="SplitButton">
<button type="button" class="Button Button--medium Button--primary">Button</button>
<button type="button" class="Button Button--medium Button--primary">Button</button>
</div>
```

## Variant with Dropdown

You can add a Dropdown component inside a Split Button to provide additional actions.

Learn more about the [Dropdown][readme-dropdown] component in its documentation.

```html
<div class="SplitButton">
<button type="button" class="Button Button--medium Button--primary">Button</button>
<div class="Dropdown">
<button
type="button"
class="Button Button--medium Button--primary"
data-spirit-toggle="dropdown"
data-spirit-target="#dropdown-1"
aria-expanded="false"
aria-controls="dropdown-1"
data-spirit-autoclose="true"
>
More
<svg width="24" height="24" aria-hidden="true" class="ml-400">
<use xlink:href="/assets/icons/svg/sprite.svg#chevron-down" />
</svg>
</button>
<div class="DropdownPopover" data-spirit-placement="bottom-start" id="dropdown-1">Dropdown content</div>
</div>
</div>
```

## Variant with Tooltip

You can also add a tooltip to buttons, which is especially useful for buttons that contain only icons.

Learn more about the [Tooltip][readme-tooltip] component in its documentation.

```html
<div class="SplitButton">
<button type="button" class="Button Button--medium Button--primary">Button</button>
<div class="Tooltip" data-spirit-element="tooltip">
<button
type="button"
class="Button Button--medium Button--primary Button--symmetrical"
data-spirit-toggle="tooltip"
data-spirit-target="#tooltip-1"
aria-labelledby="tooltip-1"
>
pavelklibani marked this conversation as resolved.
Show resolved Hide resolved
<svg width="24" height="24" aria-hidden="true" class="mx-800">
<use xlink:href="/assets/icons/svg/sprite.svg#download" />
</svg>
</button>
<div
id="tooltip-1"
class="TooltipPopover is-hidden"
data-spirit-placement="bottom-start"
data-spirit-flip-fallback-placements="bottom"
data-spirit-trigger="hover"
>
Download
<span class="TooltipPopover__arrow" data-spirit-element="arrow"></span>
</div>
</div>
</div>
```

[readme-button]: https://github.com/lmc-eu/spirit-design-system/blob/main/packages/web/src/scss/components/Button/README.md
[readme-dropdown]: https://github.com/lmc-eu/spirit-design-system/blob/main/packages/web/src/scss/components/Dropdown/README.md
[readme-tooltip]: https://github.com/lmc-eu/spirit-design-system/blob/main/packages/web/src/scss/components/Tooltip/README.md
34 changes: 34 additions & 0 deletions packages/web/src/scss/components/SplitButton/_SplitButton.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 1. Non-zero values work only when the default Button border radius is a bit smaller than its height. In other words, it doesn't work when Buttons use the full radius.

@use 'sass:map';
@use '@tokens' as tokens;
@use 'theme';

.SplitButton {
--#{tokens.$css-variable-prefix}split-button-gap: #{-1 * theme.$border-width};
--#{tokens.$css-variable-prefix}split-button-inner-border-radius: #{theme.$inner-border-radius}; // 1.

display: flex;
}

.SplitButton > :not(:first-child):is(a, button),
.SplitButton > :not(:first-child) > :is(a, button) {
--#{tokens.$css-variable-prefix}button-border-start-start-radius: var(
--#{tokens.$css-variable-prefix}split-button-inner-border-radius
);
--#{tokens.$css-variable-prefix}button-border-end-start-radius: var(
--#{tokens.$css-variable-prefix}split-button-inner-border-radius
);

margin-inline-start: var(--#{tokens.$css-variable-prefix}split-button-gap);
}

.SplitButton > :not(:last-child):is(a, button),
.SplitButton > :not(:last-child) > :is(a, button) {
--#{tokens.$css-variable-prefix}button-border-start-end-radius: var(
--#{tokens.$css-variable-prefix}split-button-inner-border-radius
);
--#{tokens.$css-variable-prefix}button-border-end-end-radius: var(
--#{tokens.$css-variable-prefix}split-button-inner-border-radius
);
}
Loading
Loading