Skip to content

Commit

Permalink
feat(field-group): add field-group pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Westbrook committed Nov 24, 2020
1 parent 94952a5 commit b027f27
Show file tree
Hide file tree
Showing 25 changed files with 462 additions and 48 deletions.
1 change: 1 addition & 0 deletions packages/bundle/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import '@spectrum-web-components/dialog/sp-dialog.js';
import '@spectrum-web-components/dialog/sp-dialog-wrapper.js';
import '@spectrum-web-components/dropdown/sp-dropdown.js';
import '@spectrum-web-components/dropzone/sp-dropzone.js';
import '@spectrum-web-components/field-group/sp-field-group.js';
import '@spectrum-web-components/icon/sp-icon.js';
import '@spectrum-web-components/icons/sp-icons-large.js';
import '@spectrum-web-components/icons/sp-icons-medium.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 @@ -65,6 +65,7 @@
"@spectrum-web-components/dialog": "^0.3.4",
"@spectrum-web-components/dropdown": "^0.8.5",
"@spectrum-web-components/dropzone": "^0.4.4",
"@spectrum-web-components/field-group": "^0.0.1",
"@spectrum-web-components/icon": "^0.6.3",
"@spectrum-web-components/icons": "^0.4.5",
"@spectrum-web-components/icons-workflow": "^0.3.6",
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 @@ -26,6 +26,7 @@ export * from '@spectrum-web-components/coachmark';
export * from '@spectrum-web-components/dialog';
export * from '@spectrum-web-components/dropdown';
export * from '@spectrum-web-components/dropzone';
export * from '@spectrum-web-components/field-group';
export * from '@spectrum-web-components/icon';
export * from '@spectrum-web-components/icons';
import * as UIIcons from '@spectrum-web-components/icons-ui';
Expand Down
1 change: 1 addition & 0 deletions packages/bundle/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
{ "path": "../dialog" },
{ "path": "../dropdown" },
{ "path": "../dropzone" },
{ "path": "../field-group" },
{ "path": "../icon" },
{ "path": "../icons" },
{ "path": "../icons-ui" },
Expand Down
3 changes: 2 additions & 1 deletion packages/checkbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"author": "",
"license": "Apache-2.0",
"devDependencies": {
"@spectrum-css/checkbox": "^3.0.0-beta.4"
"@spectrum-css/checkbox": "^3.0.0-beta.4",
"@spectrum-web-components/field-group": "^0.0.1"
},
"dependencies": {
"@spectrum-web-components/base": "^0.1.3",
Expand Down
11 changes: 0 additions & 11 deletions packages/checkbox/src/checkbox.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,3 @@ governing permissions and limitations under the License.
);
}
/* stylelint-enable no-descending-specificity */

/**
* Partial work around until FieldGroup is implemented
*/
:host([dir='ltr']:not(:first-of-type)) {
margin: 0 0 0 var(--spectrum-global-dimension-size-200);
}

:host([dir='rtl']:not(:first-of-type)) {
margin: 0 var(--spectrum-global-dimension-size-200) 0 0;
}
27 changes: 19 additions & 8 deletions packages/checkbox/stories/checkbox.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ governing permissions and limitations under the License.
*/
import { html, action } from '@open-wc/demoing-storybook';

import '../';
import '../sp-checkbox.js';
import '@spectrum-web-components/field-group/sp-field-group.js';
import { TemplateResult } from '@spectrum-web-components/base';

export default {
Expand Down Expand Up @@ -157,14 +158,24 @@ export const quietDisabledIndeterminate = (): TemplateResult => {

export const tabIndexExample = (): TemplateResult => {
return html`
<sp-checkbox tabindex="0">Checkbox 0</sp-checkbox>
<sp-checkbox disabled tabindex="3">Checkbox 3</sp-checkbox>
<sp-checkbox tabindex="4">Checkbox 4</sp-checkbox>
<sp-checkbox tabindex="2" autofocus>Checkbox 2</sp-checkbox>
<sp-checkbox tabindex="1">Checkbox 1</sp-checkbox>
<sp-field-group horizontal>
<sp-checkbox tabindex="0">Checkbox 0</sp-checkbox>
<sp-checkbox disabled tabindex="3">Checkbox 3</sp-checkbox>
<sp-checkbox tabindex="4">Checkbox 4</sp-checkbox>
<sp-checkbox tabindex="2" autofocus>Checkbox 2</sp-checkbox>
<sp-checkbox tabindex="1">Checkbox 1</sp-checkbox>
</sp-field-group>
`;
};

tabIndexExample.story = {
name: 'Tab index example',
export const verticalTabIndexExample = (): TemplateResult => {
return html`
<sp-field-group vertical>
<sp-checkbox tabindex="0">Checkbox 0</sp-checkbox>
<sp-checkbox disabled tabindex="3">Checkbox 3</sp-checkbox>
<sp-checkbox tabindex="4">Checkbox 4</sp-checkbox>
<sp-checkbox tabindex="2" autofocus>Checkbox 2</sp-checkbox>
<sp-checkbox tabindex="1">Checkbox 1</sp-checkbox>
</sp-field-group>
`;
};
48 changes: 48 additions & 0 deletions packages/field-group/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## Description

An `<sp-field-group>` element is used to layout a group of fields, usually `<sp-checkbox>` elements. It can be leveraged for `vertical` or `horizontal` organization of the fields that are supplied as its children.

### Usage

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

```
yarn add @spectrum-web-components/field-group
```

Import the side effectful registration of `<sp-field-group>` via:

```
import '@spectrum-web-components/field-group/sp-field-group.js';
```

When looking to leverage the `FieldGroup` base class as a type and/or for extension purposes, do so via:

```
import { FieldGroup } from '@spectrum-web-components/field-group';
```

## Example

```html
<sp-field-group horizontal>
<sp-checkbox>Checkbox 1</sp-checkbox>
<sp-checkbox>Checkbox 2</sp-checkbox>
<sp-checkbox checked>Checkbox 3</sp-checkbox>
<sp-checkbox>Checkbox 4</sp-checkbox>
<sp-checkbox>Checkbox 5</sp-checkbox>
</sp-field-group>
```

### Vertical

```html
<sp-field-group vertical>
<sp-checkbox>Checkbox 1</sp-checkbox>
<sp-checkbox>Checkbox 2</sp-checkbox>
<sp-checkbox>Checkbox 3</sp-checkbox>
<sp-checkbox>Checkbox 4</sp-checkbox>
<sp-checkbox checked>Checkbox 5</sp-checkbox>
</sp-field-group>
```
59 changes: 59 additions & 0 deletions packages/field-group/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "@spectrum-web-components/field-group",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/adobe/spectrum-web-components.git",
"directory": "packages/field-group"
},
"bugs": {
"url": "https://github.com/adobe/spectrum-web-components/issues"
},
"homepage": "https://adobe.github.io/spectrum-web-components/components/field-group",
"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/index.js",
"./src/": "./src/",
"./custom-elements.json": "./custom-elements.json",
"./package.json": "./package.json",
"./sp-field-group": "./sp-field-group.js",
"./sp-field-group.js": "./sp-field-group.js"
},
"files": [
"custom-elements.json",
"*.d.ts",
"*.js",
"*.js.map",
"/src/"
],
"sideEffects": [
"./sp-*.js",
"./sp-*.ts"
],
"scripts": {
"test": "echo \"Error: run tests from mono-repo root.\" && exit 1"
},
"author": "",
"license": "Apache-2.0",
"devDependencies": {
"@spectrum-css/fieldgroup": "^3.0.0-beta.4",
"@spectrum-web-components/checkbox": "^0.5.2",
"@spectrum-web-components/radio": "^0.4.4"
},
"dependencies": {
"@spectrum-web-components/base": "^0.1.3",
"tslib": "^2.0.0"
}
}
21 changes: 21 additions & 0 deletions packages/field-group/sp-field-group.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 { FieldGroup } from './src/FieldGroup.js';

customElements.define('sp-field-group', FieldGroup);

declare global {
interface HTMLElementTagNameMap {
'sp-field-group': FieldGroup;
}
}
42 changes: 42 additions & 0 deletions packages/field-group/src/FieldGroup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
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 './field-group.css.js';

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

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

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

protected render(): TemplateResult {
return html`
<slot></slot>
`;
}
}
25 changes: 25 additions & 0 deletions packages/field-group/src/field-group.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
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-field-group.css';

:host([horizontal][dir='rtl']) ::slotted(*:not(:last-child)),
:host([dir='rtl']:not([vertical])) ::slotted(*:not(:last-child)) {
/* .spectrum-FieldGroup--horizontal .spectrum-FieldGroup-item+.spectrum-FieldGroup-item */
margin: 0 0 0 var(--spectrum-global-dimension-size-200);
}

:host([horizontal][dir='ltr']) ::slotted(*:not(:last-child)),
:host([dir='ltr']:not([vertical])) ::slotted(*:not(:last-child)) {
/* .spectrum-FieldGroup--horizontal .spectrum-FieldGroup-item+.spectrum-FieldGroup-item */
margin: 0 var(--spectrum-global-dimension-size-200) 0 0;
}
13 changes: 13 additions & 0 deletions packages/field-group/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 './FieldGroup.js';
44 changes: 44 additions & 0 deletions packages/field-group/src/spectrum-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
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.
*/

const config = {
spectrum: 'fieldgroup',
components: [
{
name: 'field-group',
host: {
selector: '.spectrum-FieldGroup',
},
attributes: [
{
type: 'boolean',
selector: '.spectrum-FieldGroup--horizontal',
name: 'horizontal',
},
{
type: 'boolean',
selector: '.spectrum-FieldGroup--vertical',
name: 'vertical',
},
],
complexSelectors: [
{
replacement: '::slotted(:not(:last-child))',
selector:
'.spectrum-FieldGroup-item+.spectrum-FieldGroup-item',
},
],
},
],
};

export default config;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/* 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
Expand All @@ -8,24 +8,20 @@ Unless required by applicable law or agreed to in writing, software distributed
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-FieldGroup */
display: flex;
flex-direction: row;
vertical-align: top;
flex-wrap: wrap;
}

:host([column]) {
flex-direction: column;
}

/**
* Partial work around until FieldGroup is implemented
*/
:host([dir='ltr']:not([column])) ::slotted(:not(:first-child)) {
:host([horizontal]) ::slotted(:not(:last-child)) {
/* .spectrum-FieldGroup--horizontal .spectrum-FieldGroup-item+.spectrum-FieldGroup-item */
margin: 0 0 0 var(--spectrum-global-dimension-size-200);
}

:host([dir='rtl']:not([column])) ::slotted(:not(:first-child)) {
margin: 0 var(--spectrum-global-dimension-size-200) 0 0;
:host([vertical]) {
/* .spectrum-FieldGroup--vertical */
display: inline-flex;
flex-direction: column;
}
Loading

0 comments on commit b027f27

Please sign in to comment.