Skip to content

feat(split button): adds split button #207

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

Merged
merged 9 commits into from
Jul 8, 2024
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
5 changes: 5 additions & 0 deletions .changeset/perfect-yaks-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@crowdstrike/glide-core': patch
---

Adds `glide-core-split-container`, `glide-core-split-button`, and `glide-core-split-link`.
2 changes: 1 addition & 1 deletion packages/components/src/button.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default [
.component {
align-items: center;
border-color: transparent;
border-radius: var(--glide-core-spacing-sm);
border-radius: 0.75rem;
border-style: solid;
border-width: 1px;
cursor: pointer;
Expand Down
241 changes: 241 additions & 0 deletions packages/components/src/split-button.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
import './icons/storybook.js';
import './menu.button.js';
import './menu.link.js';
import './split-button.js';
import './split-container.js';
import './split-link.js';

import { html, nothing } from 'lit';
import type { Meta, StoryObj } from '@storybook/web-components';

const meta: Meta = {
title: 'Split Button',
tags: ['autodocs'],
decorators: [
(story) =>
html`<div
style="height: 13rem; display: flex; align-items: center; justify-content: center;"
>
${story()}
</div>`,
],
parameters: {
docs: {
description: {
component:
'A split button provides a primary action and a menu of alternate actions.',
},
},
},
render: (arguments_) => html`
<glide-core-split-container
?open=${arguments_.open || nothing}
size=${arguments_.size}
variant=${arguments_.variant}
?disabled=${arguments_.disabled || nothing}
menu-label=${arguments_['menu-label']}
menu-placement=${arguments_['menu-placement']}
>
<glide-core-split-button slot="primary-action"
>Button</glide-core-split-button
>
<glide-core-menu-link label="One" url="/one"></glide-core-menu-link>
<glide-core-menu-link label="Two" url="/two"></glide-core-menu-link>
<glide-core-menu-button label="Three"></glide-core-menu-button>
</glide-core-split-container>
`,
args: {
open: false,
size: 'large',
variant: 'primary',
disabled: false,
'menu-label': 'Button menu',
'menu-placement': 'bottom-end',
'slot="primary-action"': '',
},
argTypes: {
variant: {
control: { type: 'radio' },
options: ['primary', 'secondary'],
table: {
defaultValue: {
summary: '"primary"',
},
type: { summary: '"primary" | "secondary"' },
},
},
size: {
control: { type: 'radio' },
options: ['large', 'small'],
table: {
defaultValue: {
summary: '"large"',
},
type: { summary: '"large" | "small"' },
},
},
'menu-label': {
control: { type: 'text' },
type: { name: 'string', required: true },
table: {
type: { summary: 'string', detail: 'The menu button`s aria-label.' },
},
},
'menu-placement': {
control: { type: 'select' },
options: [
'bottom',
'left',
'right',
'top',
'bottom-start',
'bottom-end',
'left-start',
'left-end',
'right-start',
'right-end',
'top-start',
'top-end',
],
table: {
defaultValue: { summary: '"bottom-end"' },
type: {
summary:
'"bottom" | "left" | "right" | "top" | "bottom-start" | "bottom-end" | "left-start" | "left-end" | "right-start" | "right-end" | "top-start"| "top-end"',
},
},
},
'slot="primary-action"': {
table: {
type: { summary: 'GlideCoreSplitButton | GlideCoreSplitLink' },
},
type: { name: 'function', required: true },
},
},
};

export default meta;

export const Primary: StoryObj = {};

export const PrimaryWithPrefixIcon: StoryObj = {
render: (arguments_) => html`
<glide-core-split-container
?open=${arguments_.open || nothing}
size=${arguments_.size}
variant=${arguments_.variant}
?disabled=${arguments_.disabled || nothing}
menu-label=${arguments_['menu-label']}
menu-placement=${arguments_['menu-placement']}
>
<glide-core-split-button slot="primary-action">
<glide-core-example-icon
slot="prefix"
name="info"
></glide-core-example-icon>
Button
</glide-core-split-button>
<glide-core-menu-link label="One" url="/one"></glide-core-menu-link>
<glide-core-menu-link label="Two" url="/two"></glide-core-menu-link>
<glide-core-menu-button label="Three"></glide-core-menu-button>
</glide-core-split-container>
`,
};

export const PrimaryWithSizeSmall: StoryObj = {
args: {
variant: 'primary',
size: 'small',
},
};

export const PrimaryWithLink: StoryObj = {
render: (arguments_) => html`
<glide-core-split-container
?open=${arguments_.open || nothing}
size=${arguments_.size}
variant=${arguments_.variant}
?disabled=${arguments_.disabled || nothing}
menu-label=${arguments_['menu-label']}
menu-placement=${arguments_['menu-placement']}
>
<glide-core-split-link slot="primary-action" url="/">
<glide-core-example-icon
slot="prefix"
name="info"
></glide-core-example-icon>
Button
</glide-core-split-link>
<glide-core-menu-link label="One" url="/one"></glide-core-menu-link>
<glide-core-menu-link label="Two" url="/two"></glide-core-menu-link>
<glide-core-menu-button label="Three"></glide-core-menu-button>
</glide-core-split-container>
`,
};

export const Secondary: StoryObj = {
args: {
variant: 'secondary',
},
};

export const SecondaryWithPrefixIcon: StoryObj = {
args: {
variant: 'secondary',
},
render: (arguments_) => html`
<glide-core-split-container
?open=${arguments_.open || nothing}
size=${arguments_.size}
variant=${arguments_.variant}
?disabled=${arguments_.disabled || nothing}
menu-label=${arguments_['menu-label']}
menu-placement=${arguments_['menu-placement']}
>
<glide-core-split-button slot="primary-action">
<glide-core-example-icon
slot="prefix"
name="info"
></glide-core-example-icon>
Button
</glide-core-split-button>
<glide-core-menu-link label="One" url="/one"></glide-core-menu-link>
<glide-core-menu-link label="Two" url="/two"></glide-core-menu-link>
<glide-core-menu-button label="Three"></glide-core-menu-button>
</glide-core-split-container>
`,
};

export const SecondaryWithSizeSmall: StoryObj = {
args: {
variant: 'secondary',
size: 'small',
},
};

export const SecondaryWithLink: StoryObj = {
args: {
variant: 'secondary',
},
render: (arguments_) => html`
<glide-core-split-container
?open=${arguments_.open || nothing}
size=${arguments_.size}
variant=${arguments_.variant}
?disabled=${arguments_.disabled || nothing}
menu-label=${arguments_['menu-label']}
menu-placement=${arguments_['menu-placement']}
>
<glide-core-split-link slot="primary-action" url="/">
<glide-core-example-icon
slot="prefix"
name="info"
></glide-core-example-icon>
Button
</glide-core-split-link>
<glide-core-menu-link label="One" url="/one"></glide-core-menu-link>
<glide-core-menu-link label="Two" url="/two"></glide-core-menu-link>
<glide-core-menu-button label="Three"></glide-core-menu-button>
</glide-core-split-container>
`,
};
109 changes: 109 additions & 0 deletions packages/components/src/split-button.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { css } from 'lit';
import focusOutline from './styles/focus-outline.js';

// These styles are shared between `glide-core-split-button` and `glide-core-split-link`.
export default [
css`
.component {
align-items: center;
border-color: transparent;
border-radius: 0.75rem 0 0 0.75rem;
border-style: solid;
border-width: 1px 0 1px 1px;
cursor: pointer;
display: inline-flex;
font-family: var(--glide-core-heading-xxs-font-family);
font-style: var(--glide-core-heading-xxs-font-style);
font-weight: var(--glide-core-heading-xxs-font-weight);
gap: 0.625rem;
justify-content: center;
padding-block: var(--glide-core-spacing-xs);
padding-inline: var(--glide-core-spacing-md);
padding-inline-end: var(--glide-core-spacing-xs);
text-decoration: none;
transition-duration: 150ms;
transition-property: color, background-color, border-color, fill, stroke;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
user-select: none;

&:focus {
outline: none;
}

&:focus-visible {
${focusOutline};
}

&.disabled {
cursor: default;
opacity: 1;
pointer-events: none;
}

&.primary {
background-color: var(--glide-core-surface-primary);
border-color: transparent;
color: var(--glide-core-text-selected);

/* Since the "disabled" styles are shared between a link and a button, we use a disabled class and not a pseudo-class */
&.disabled {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could be good to add a comment on why this uses .disabled versus :disabled (because of the shared usage of buttons and links) for future travelers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The comment is just above on line 37, but I can move it down.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

background-color: var(--glide-core-surface-disabled);
border-color: transparent;
color: var(--glide-core-text-tertiary-disabled);
}

&:not(.disabled):active {
background-color: var(--glide-core-surface-selected-hover);
border-color: transparent;
color: var(--glide-core-text-selected);
}

&:not(:active):hover:not(.disabled) {
background-color: var(--glide-core-surface-hover);
border-color: transparent;
box-shadow: var(--glide-core-glow-sm);
color: var(--glide-core-text-primary);
}
}

&.secondary {
background-color: transparent;
border-color: var(--glide-core-border-primary);
color: var(--glide-core-text-primary);

&.disabled {
background-color: var(--glide-core-surface-disabled);
border-color: transparent;
color: var(--glide-core-text-tertiary-disabled);
}

&:not(.disabled):active {
background-color: var(--glide-core-surface-selected-hover);
border-color: transparent;
color: var(--glide-core-text-selected);
}

&:not(:active):hover:not(.disabled) {
background-color: var(--glide-core-surface-hover);
border-color: transparent;
box-shadow: var(--glide-core-glow-sm);
color: var(--glide-core-text-primary);
}
}

&.small {
block-size: 1.75rem;
box-sizing: border-box;
font-size: var(--glide-core-body-xs-font-size);
line-height: 1rem;
}

&.large {
block-size: 2.125rem;
box-sizing: border-box;
font-size: var(--glide-core-body-xxs-font-size);
line-height: 1.5rem;
}
}
`,
];
Loading