Skip to content

Commit

Permalink
feat(quick-actions): add quick-actions pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Westbrook Johnson authored and Westbrook committed Aug 29, 2020
1 parent 4f99209 commit 3664b51
Show file tree
Hide file tree
Showing 16 changed files with 495 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/bundle/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import '@spectrum-web-components/menu/sp-menu-item.js';
import '@spectrum-web-components/overlay/active-overlay.js';
import '@spectrum-web-components/overlay/overlay-trigger.js';
import '@spectrum-web-components/popover/sp-popover.js';
import '@spectrum-web-components/quick-actions/sp-quick-actions.js';
import '@spectrum-web-components/radio/sp-radio.js';
import '@spectrum-web-components/radio/sp-radio-group.js';
import '@spectrum-web-components/rule/sp-rule.js';
Expand Down
1 change: 1 addition & 0 deletions packages/bundle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"@spectrum-web-components/menu": "^0.3.2",
"@spectrum-web-components/overlay": "^0.5.2",
"@spectrum-web-components/popover": "^0.4.6",
"@spectrum-web-components/quick-actions": "^0.0.1",
"@spectrum-web-components/radio": "^0.3.3",
"@spectrum-web-components/rule": "^0.2.1",
"@spectrum-web-components/search": "^0.4.4",
Expand Down
1 change: 1 addition & 0 deletions packages/bundle/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export * from '@spectrum-web-components/link';
export * from '@spectrum-web-components/menu';
export * from '@spectrum-web-components/overlay';
export * from '@spectrum-web-components/popover';
export * from '@spectrum-web-components/quick-actions';
export * from '@spectrum-web-components/radio';
export * from '@spectrum-web-components/rule';
export * from '@spectrum-web-components/search';
Expand Down
1 change: 1 addition & 0 deletions packages/bundle/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
{ "path": "../menu" },
{ "path": "../popover" },
{ "path": "../overlay" },
{ "path": "../quick-actions" },
{ "path": "../radio" },
{ "path": "../rule" },
{ "path": "../search" },
Expand Down
54 changes: 54 additions & 0 deletions packages/quick-actions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
## Description

`<sp-quick-actions>` allow users to perform contextual actions when hovering or focusing on a specific component. They're shortcuts meant to make workflows more efficient. Spectrum guidelines suggest a `<sp-quick-action>` element feature only text buttons OR only icon buttons, and never both.

### Installation

[![See it on NPM!](https://img.shields.io/npm/v/@spectrum-web-components/quick-actions?style=for-the-badge)](https://www.npmjs.com/package/@spectrum-web-components/quick-actions)
[![How big is this package in your project?](https://img.shields.io/bundlephobia/minzip/@spectrum-web-components/quick-actions?style=for-the-badge)](https://bundlephobia.com/result?p=@spectrum-web-components/quick-actions)

```
npm install @spectrum-web-components/quick-actions
# or
yarn add @spectrum-web-components/quick-actions
```

## Example

<sp-icons-medium></sp-icons-medium>

```html
<div
style="padding: 2em; background-color: var(--spectrum-quickactions-overlay-color, var(--spectrum-alias-background-color-quickactions-overlay));"
>
<sp-quick-actions opened>
<sp-action-button quiet label="Info">
<sp-icon slot="icon" size="s" name="ui:InfoMedium"></sp-icon>
</sp-action-button>
<sp-action-button quiet label="Magnify">
<sp-icon slot="icon" size="s" name="ui:Magnifier"></sp-icon>
</sp-action-button>
<sp-action-button quiet label="Star">
<sp-icon slot="icon" size="s" name="ui:Star"></sp-icon>
</sp-action-button>
</sp-quick-actions>
</div>
```

### Text Only

When the buttons have text only, be sure to include the `text-only` attribute to ensure correct layout of your actions.

```html
<div
style="padding: 2em; background-color: var(--spectrum-quickactions-overlay-color, var(--spectrum-alias-background-color-quickactions-overlay));"
>
<sp-quick-actions opened text-only>
<sp-action-button quiet>Edit</sp-action-button>
<sp-action-button quiet>Copy</sp-action-button>
<sp-action-button quiet>Delete</sp-action-button>
</sp-quick-actions>
</div>
```
56 changes: 56 additions & 0 deletions packages/quick-actions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "@spectrum-web-components/quick-actions",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/adobe/spectrum-web-components.git",
"directory": "packages/quick-actions"
},
"bugs": {
"url": "https://github.com/adobe/spectrum-web-components/issues"
},
"homepage": "https://adobe.github.io/spectrum-web-components/components/quick-actions",
"keywords": [
"spectrum css",
"web components",
"lit-element",
"lit-html"
],
"version": "0.0.1",
"description": "",
"main": "src/index.js",
"module": "src/index.js",
"type": "module",
"exports": {
"./src/": "./src/",
"./custom-elements.json": "./custom-elements.json",
"./package.json": "./package.json",
"./sp-quick-actions": "./sp-quick-actions.js",
"./sp-quick-actions.js": "./sp-quick-actions.js"
},
"files": [
"custom-elements.json",
"*.d.ts",
"*.js",
"*.js.map",
"/src/"
],
"sideEffects": [
"./sp-quick-actions.js",
"./sp-quick-actions.ts"
],
"scripts": {
"test": "karma start --coverage"
},
"author": "",
"license": "Apache-2.0",
"devDependencies": {
"@spectrum-css/quickaction": "^3.0.0-beta.3"
},
"dependencies": {
"@spectrum-web-components/base": "^0.0.1",
"tslib": "^2.0.0"
}
}
21 changes: 21 additions & 0 deletions packages/quick-actions/sp-quick-actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
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 { QuickActions } from './src/QuickActions.js';

customElements.define('sp-quick-actions', QuickActions);

declare global {
interface HTMLElementTagNameMap {
'sp-quick-actions': QuickActions;
}
}
48 changes: 48 additions & 0 deletions packages/quick-actions/src/QuickActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
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,
SpectrumElement,
CSSResultArray,
TemplateResult,
property,
} from '@spectrum-web-components/base';

import styles from './quick-actions.css.js';

/**
* @element sp-quick-actions
*/
export class QuickActions extends SpectrumElement {
public static get styles(): CSSResultArray {
return [styles];
}

@property({ type: Boolean, reflect: true })
public opened = false;

@property({
type: Boolean,
attribute: 'text-only',
hasChanged() {
return false;
},
})
public textOnly = false;

protected render(): TemplateResult {
return html`
<slot></slot>
`;
}
}
13 changes: 13 additions & 0 deletions packages/quick-actions/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
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 './QuickActions.js';
13 changes: 13 additions & 0 deletions packages/quick-actions/src/quick-actions.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
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-quick-actions.css';
55 changes: 55 additions & 0 deletions packages/quick-actions/src/spectrum-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
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.
*/

module.exports = {
spectrum: 'quickaction',
components: [
{
name: 'quick-actions',
host: {
selector: '.spectrum-QuickActions',
},
attributes: [
{
type: 'boolean',
selector: '.spectrum-QuickActions--textOnly',
name: 'text-only',
},
{
type: 'boolean',
selector: '.is-open',
name: 'opened',
},
{
type: 'enum',
name: 'enter-from',
values: [
'.spectrum-QuickActions--left',
'.spectrum-QuickActions--right',
],
},
],
ids: [
{
selector: '.spectrum-QuickActions-overlay',
name: 'overlay',
},
],
slots: [
{
selector: '.spectrum-ActionButton',
name: 'action',
},
],
},
],
};
Loading

0 comments on commit 3664b51

Please sign in to comment.