-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(button-group): add ButtonGroup pattern
- Loading branch information
Showing
19 changed files
with
694 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
## Description | ||
|
||
`sp-button-group` delivers a set of buttons in horizontal or vertical orientation while ensuring the appropriate spacing between those buttons. | ||
|
||
### Installation | ||
|
||
[![See it on NPM!](https://img.shields.io/npm/v/@spectrum-web-components/button-group?style=for-the-badge)](https://www.npmjs.com/package/@spectrum-web-components/button-group) | ||
[![How big is this package in your project?](https://img.shields.io/bundlephobia/minzip/@spectrum-web-components/button-group?style=for-the-badge)](https://bundlephobia.com/result?p=@spectrum-web-components/button-group) | ||
|
||
``` | ||
npm install @spectrum-web-components/button-group | ||
# or | ||
yarn add @spectrum-web-components/button-group | ||
``` | ||
|
||
## Horizontal | ||
|
||
<sp-icons-medium></sp-icons-medium> | ||
|
||
```html | ||
<sp-button-group> | ||
<sp-button>Button 1</sp-button> | ||
<sp-button>Longer Button 2</sp-button> | ||
<sp-button>Short 3</sp-button> | ||
</sp-button-group> | ||
<br /> | ||
<sp-button-group> | ||
<sp-action-button>Button 1</sp-action-button> | ||
<sp-action-button>Longer Button 2</sp-action-button> | ||
<sp-action-button>Short 3</sp-action-button> | ||
</sp-button-group> | ||
<br /> | ||
<sp-button-group> | ||
<sp-action-button> | ||
<sp-icon slot="icon" size="xs" name="ui:Magnifier"></sp-icon> | ||
Button 1 | ||
</sp-action-button> | ||
<sp-action-button> | ||
<sp-icon slot="icon" size="xs" name="ui:Magnifier"></sp-icon> | ||
Longer Button 2 | ||
</sp-action-button> | ||
<sp-action-button> | ||
<sp-icon slot="icon" size="xs" name="ui:Magnifier"></sp-icon> | ||
Short 3 | ||
</sp-action-button> | ||
</sp-button-group> | ||
<br /> | ||
<sp-button-group> | ||
<sp-action-button quiet> | ||
<sp-icon slot="icon" size="xs" name="ui:Magnifier"></sp-icon> | ||
</sp-action-button> | ||
<sp-action-button quiet> | ||
<sp-icon slot="icon" size="xs" name="ui:Magnifier"></sp-icon> | ||
</sp-action-button> | ||
<sp-action-button quiet> | ||
<sp-icon slot="icon" size="xs" name="ui:Magnifier"></sp-icon> | ||
</sp-action-button> | ||
</sp-button-group> | ||
``` | ||
|
||
## Vertical | ||
|
||
```html | ||
<div | ||
style="display: flex; justify-content: space-between; width: 100%; max-width: 500px;" | ||
> | ||
<sp-button-group vertical> | ||
<sp-button>Button 1</sp-button> | ||
<sp-button>Longer Button 2</sp-button> | ||
<sp-button>Short 3</sp-button> | ||
</sp-button-group> | ||
|
||
<sp-button-group vertical> | ||
<sp-action-button>Button 1</sp-action-button> | ||
<sp-action-button>Longer Button 2</sp-action-button> | ||
<sp-action-button>Short 3</sp-action-button> | ||
</sp-button-group> | ||
|
||
<sp-button-group vertical> | ||
<sp-action-button> | ||
<sp-icon slot="icon" size="xs" name="ui:Magnifier"></sp-icon> | ||
Button 1 | ||
</sp-action-button> | ||
<sp-action-button> | ||
<sp-icon slot="icon" size="xs" name="ui:Magnifier"></sp-icon> | ||
Longer Button 2 | ||
</sp-action-button> | ||
<sp-action-button> | ||
<sp-icon slot="icon" size="xs" name="ui:Magnifier"></sp-icon> | ||
Short 3 | ||
</sp-action-button> | ||
</sp-button-group> | ||
|
||
<sp-button-group vertical> | ||
<sp-action-button quiet> | ||
<sp-icon slot="icon" size="xs" name="ui:Magnifier"></sp-icon> | ||
</sp-action-button> | ||
<sp-action-button quiet> | ||
<sp-icon slot="icon" size="xs" name="ui:Magnifier"></sp-icon> | ||
</sp-action-button> | ||
<sp-action-button quiet> | ||
<sp-icon slot="icon" size="xs" name="ui:Magnifier"></sp-icon> | ||
</sp-action-button> | ||
</sp-button-group> | ||
</div> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "@spectrum-web-components/button-group", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/adobe/spectrum-web-components.git", | ||
"directory": "packages/button-group" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/adobe/spectrum-web-components/issues" | ||
}, | ||
"homepage": "https://adobe.github.io/spectrum-web-components/components/button-group", | ||
"keywords": [ | ||
"spectrum css", | ||
"web components", | ||
"lit-element", | ||
"lit-html" | ||
], | ||
"version": "0.0.1", | ||
"description": "", | ||
"main": "lib/index.js", | ||
"module": "lib/index.js", | ||
"type": "module", | ||
"files": [ | ||
"custom-elements.json", | ||
"/lib/", | ||
"/src/" | ||
], | ||
"scripts": { | ||
"test": "karma start --coverage" | ||
}, | ||
"author": "", | ||
"license": "Apache-2.0", | ||
"peerDependencies": { | ||
"lit-element": "^2.1.0", | ||
"lit-html": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@spectrum-css/buttongroup": "^2.0.0", | ||
"@spectrum-web-components/button": "^0.6.0" | ||
}, | ||
"dependencies": { | ||
"tslib": "^2.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
Copyright 2020 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
@import './spectrum-button-group.css'; | ||
|
||
:host([vertical]) ::slotted(sp-action-button) { | ||
--spectrum-actionbutton-label-flex-grow: 1; | ||
--spectrum-actionbutton-label-text-align: left; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
Copyright 2020 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
import { | ||
html, | ||
LitElement, | ||
CSSResultArray, | ||
TemplateResult, | ||
property, | ||
} from 'lit-element'; | ||
|
||
import styles from './button-group.css.js'; | ||
|
||
/** | ||
* @element sp-button-group | ||
*/ | ||
export class ButtonGroup extends LitElement { | ||
public static get styles(): CSSResultArray { | ||
return [styles]; | ||
} | ||
|
||
@property({ type: Boolean, reflect: true }) | ||
public vertical = false; | ||
|
||
protected render(): TemplateResult { | ||
return html` | ||
<slot></slot> | ||
`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Copyright 2020 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
export * from './button-group.js'; | ||
|
||
import { ButtonGroup } from './button-group.js'; | ||
|
||
/* istanbul ignore else */ | ||
if (!customElements.get('sp-button-group')) { | ||
customElements.define('sp-button-group', ButtonGroup); | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'sp-button-group': ButtonGroup; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* stylelint-disable */ /* | ||
Copyright 2020 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
THIS FILE IS MACHINE GENERATED. DO NOT EDIT */ | ||
:host { | ||
/* .spectrum-ButtonGroup */ | ||
display: flex; | ||
} | ||
::slotted(sp-action-button), | ||
::slotted(sp-button), | ||
::slotted(sp-tool) { | ||
/* .spectrum-ButtonGroup .spectrum-ActionButton, | ||
* .spectrum-ButtonGroup .spectrum-Button, | ||
* .spectrum-ButtonGroup .spectrum-Tool */ | ||
flex-shrink: 0; | ||
} | ||
:host > ::slotted(sp-rule[vertical]) { | ||
/* .spectrum-ButtonGroup>.spectrum-Rule--vertical */ | ||
height: auto; | ||
align-self: stretch; | ||
} | ||
::slotted(sp-button:not(:first-of-type)) { | ||
/* .spectrum-ButtonGroup .spectrum-Button+.spectrum-Button */ | ||
margin-left: var( | ||
--spectrum-buttongroup-button-gap-x, | ||
var(--spectrum-global-dimension-static-size-200) | ||
); | ||
} | ||
::slotted(sp-action-button:not(:first-of-type)) { | ||
/* .spectrum-ButtonGroup .spectrum-ActionButton+.spectrum-ActionButton */ | ||
margin-left: var( | ||
--spectrum-actionbuttongroup-text-button-gap-x, | ||
var(--spectrum-global-dimension-size-100) | ||
); | ||
} | ||
::slotted(sp-tool:not(:first-of-type)) { | ||
/* .spectrum-ButtonGroup .spectrum-Tool+.spectrum-Tool */ | ||
margin-left: var( | ||
--spectrum-toolgroup-text-button-gap-x, | ||
var(--spectrum-global-dimension-size-100) | ||
); | ||
} | ||
:host([vertical]) { | ||
/* .spectrum-ButtonGroup--vertical */ | ||
display: inline-flex; | ||
flex-direction: column; | ||
} | ||
:host([vertical]) ::slotted(sp-button:not(:first-of-type)) { | ||
/* .spectrum-ButtonGroup--vertical .spectrum-Button+.spectrum-Button */ | ||
margin-top: var( | ||
--spectrum-buttongroup-button-gap-y, | ||
var(--spectrum-global-dimension-static-size-200) | ||
); | ||
margin-left: 0; | ||
} | ||
:host([vertical]) ::slotted(sp-action-button:not(:first-of-type)) { | ||
/* .spectrum-ButtonGroup--vertical .spectrum-ActionButton+.spectrum-ActionButton */ | ||
margin-top: var( | ||
--spectrum-actionbuttongroup-text-button-gap-y, | ||
var(--spectrum-global-dimension-size-100) | ||
); | ||
margin-left: 0; | ||
} | ||
:host([vertical]) ::slotted(sp-tool:not(:first-of-type)) { | ||
/* .spectrum-ButtonGroup--vertical .spectrum-Tool+.spectrum-Tool */ | ||
margin-top: var( | ||
--spectrum-toolgroup-text-button-gap-y, | ||
var(--spectrum-global-dimension-size-100) | ||
); | ||
margin-left: 0; | ||
} |
Oops, something went wrong.