Skip to content

Commit

Permalink
feat(rule): add Spectrum rule pattern and apply to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Westbrook committed Apr 15, 2020
1 parent 33101a0 commit f4c52ae
Show file tree
Hide file tree
Showing 23 changed files with 625 additions and 64 deletions.
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ commands:
- restore_cache:
name: Restore Golden Images Cache
keys:
<<<<<<< HEAD
- v1-golden-images-<< parameters.regression_color >>-<< parameters.regression_scale >>-2f4e2d334e9b2dc2bd8b3415e3ab66022cbb7af0
=======
- v1-golden-images-<< parameters.regression_color >>-<< parameters.regression_scale >>-fc273cb7681bbcf9711b73279b1fe88e6308443b
>>>>>>> feat(rule): add Spectrum rule pattern and apply to docs
- v1-golden-images-master-<< parameters.regression_color >>-<< parameters.regression_scale >>-
- run: yarn test:visual:ci --color=<< parameters.regression_color >> --scale=<< parameters.regression_scale >>
- run:
Expand Down
12 changes: 8 additions & 4 deletions documentation/src/components/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import componentStyles from './markdown.css';
import homeStyles from './home.css';
import '@spectrum-web-components/button';
import '@spectrum-web-components/link';
import '@spectrum-web-components/rule';

class HomeElement extends RouteComponent {
public static get styles(): CSSResultArray {
Expand Down Expand Up @@ -75,10 +76,13 @@ class HomeElement extends RouteComponent {
</p>
</div>
</section>
<section id="example">
<h2 class="spectrum-Heading">
Sample element usage
</h2>
<section id="example" class="spectrum-Typography">
<div class="headerContainer">
<h2 class="spectrum-Heading2">
Sample element usage
</h2>
<sp-rule size="large"></sp-rule>
</div>
<code-example class="language-html">
&lt;sp-button variant='cta' href='components/button'&gt;Use
Spectrum Web Component buttons&lt;/sp-button&gt;
Expand Down
8 changes: 4 additions & 4 deletions documentation/src/components/markdown.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ governing permissions and limitations under the License.
margin-bottom: 28px;
}

hr.spectrum-Rule {
margin-bottom: 33px;
}

article {
margin-bottom: 3em;
}
Expand All @@ -51,3 +47,7 @@ article {
.spectrum-Table-body {
--spectrum-table-row-background-color: var(--spectrum-global-color-gray-75);
}

.headerContainer {
margin-bottom: var(--spectrum-global-dimension-size-400);
}
27 changes: 26 additions & 1 deletion documentation/src/utils/posthtml-spectrum-typography.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,32 @@ const transformations = [
},
{
selector: 'h2',
classes: ['spectrum-Heading2--quiet'],
fn: (node) => {
if (
node.attrs &&
node.attrs.class &&
/spectrum-Heading2/.test(node.attrs.class)
) {
return node;
}
return {
tag: 'div',
attrs: {
class: 'headerContainer',
},
content: [
{
tag: 'h1',
attrs: { class: 'spectrum-Heading2' },
content: node.content,
},
{
tag: 'sp-rule',
attrs: { size: 'large' },
},
],
};
},
},
{
selector: 'h3',
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,8 @@
"postcss-selector-parser": "^6.0.2",
"posthtml": "^0.12.0",
"posthtml-attrs-parser": "^0.1.1",
"posthtml-loader": "^1.0.1",
"posthtml-loader": "^1.0.2",
"posthtml-match-helper": "^1.0.1",
"posthtml-transform": "^1.0.6",
"prettier": "^2.0.2",
"pretty-quick": "^2.0.1",
"prismjs": "^1.15.0",
Expand Down
1 change: 1 addition & 0 deletions packages/bundle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"@spectrum-web-components/popover": "^0.3.6",
"@spectrum-web-components/radio": "^0.2.10",
"@spectrum-web-components/radio-group": "^0.1.16",
"@spectrum-web-components/rule": "^0.0.1",
"@spectrum-web-components/search": "^0.2.12",
"@spectrum-web-components/sidenav": "^0.3.6",
"@spectrum-web-components/slider": "^0.4.7",
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 @@ -35,6 +35,7 @@ export * from '@spectrum-web-components/overlay';
export * from '@spectrum-web-components/popover';
export * from '@spectrum-web-components/radio';
export * from '@spectrum-web-components/radio-group';
export * from '@spectrum-web-components/rule';
export * from '@spectrum-web-components/search';
export * from '@spectrum-web-components/sidenav';
export * from '@spectrum-web-components/slider';
Expand Down
1 change: 1 addition & 0 deletions packages/bundle/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
{ "path": "../overlay" },
{ "path": "../radio" },
{ "path": "../radio-group" },
{ "path": "../rule" },
{ "path": "../search" },
{ "path": "../sidenav" },
{ "path": "../slider" },
Expand Down
72 changes: 72 additions & 0 deletions packages/rule/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
## Description

`sp-rule` bring clarity to a layout by grouping and dividing content in close proximity. They can also be used to establish rhythm and hierarchy.

### Installation

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

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

## Examples

### Large

```html-live
<h2 class="spectrum-Heading--subtitle1">Large</h2>
<sp-rule size="large"></sp-rule>
<p class="spectrum-Body">Page or Section Titles.</p>
```

### Medium

```html-live
<h3 class="spectrum-Heading--subtitle2">Medium</h3>
<sp-rule size="medium"></sp-rule>
<p class="spectrum-Body">Divide subsections, or divide different groups of elements (between panels, rails, etc.)</p>
```

### Small

```html-live
<h4 class="spectrum-Heading--subtitle3">Small</h4>
<sp-rule size="small"></sp-rule>
<p class="spectrum-Body">Divide like-elements (tables, tool groups, elements within a panel, etc.)</p>
```

### Vertical, Small

When a vertical Rule is used inside of a flex container, use `align-self: stretch; height: auto;` on the Rule.

```html-live
<div style="height: 32px; display: flex;">
<sp-action-button quiet>
<sp-icon slot="icon" size="m" name="ui:Magnifier"></sp-icon>
</sp-action-button>
<sp-rule size="small" vertical></sp-rule>
<sp-action-button quiet>
<sp-icon slot="icon" size="m" name="ui:Magnifier"></sp-icon>
</sp-action-button>
</div>
```

### Vertical, Medium

```html-live
<div style="height: 32px; display: flex;">
<sp-action-button quiet>
<sp-icon slot="icon" size="m" name="ui:Magnifier"></sp-icon>
</sp-action-button>
<sp-rule size="medium" vertical></sp-rule>
<sp-action-button quiet>
<sp-icon slot="icon" size="m" name="ui:Magnifier"></sp-icon>
</sp-action-button>
</div>
```
46 changes: 46 additions & 0 deletions packages/rule/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "@spectrum-web-components/rule",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/adobe/spectrum-web-components.git",
"directory": "packages/rule"
},
"bugs": {
"url": "https://github.com/adobe/spectrum-web-components/issues"
},
"homepage": "https://adobe.github.io/spectrum-web-components/components/rule",
"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/rule": "^2.0.0"
},
"dependencies": {
"tslib": "^1.10.0"
}
}
26 changes: 26 additions & 0 deletions packages/rule/src/index.ts
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 './rule.js';

import { Rule } from './rule.js';

/* istanbul ignore else */
if (!customElements.get('sp-rule')) {
customElements.define('sp-rule', Rule);
}

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

:host {
display: block;
}

hr {
border: none;
margin: 0;
}
38 changes: 38 additions & 0 deletions packages/rule/src/rule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
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 './rule.css';

/**
* @element sp-rule
*/
export class Rule extends LitElement {
public static styles: CSSResultArray = [styles];

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

protected render(): TemplateResult {
if (this.vertical) return html``;
return html`
<hr />
`;
}
}
39 changes: 39 additions & 0 deletions packages/rule/src/spectrum-config.js
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.
*/

module.exports = {
spectrum: 'rule',
components: [
{
name: 'rule',
host: {
selector: '.spectrum-Rule',
},
attributes: [
{
selector: '.spectrum-Rule--vertical',
type: 'boolean',
name: 'vertical',
},
{
type: 'enum',
name: 'size',
values: [
'.spectrum-Rule--small',
'.spectrum-Rule--medium',
'.spectrum-Rule--large',
],
},
],
},
],
};
Loading

0 comments on commit f4c52ae

Please sign in to comment.