Skip to content

Commit

Permalink
feat: apply sizedMixin for t-shirt sizing
Browse files Browse the repository at this point in the history
  • Loading branch information
Westbrook committed Jan 8, 2021
1 parent f3c0ec5 commit d7b63fb
Show file tree
Hide file tree
Showing 27 changed files with 679 additions and 83 deletions.
20 changes: 20 additions & 0 deletions documentation/src/components/component.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,23 @@ governing permissions and limitations under the License.
.docExample {
margin: 1.2em 0 1.5em 0;
}

[class^='tabs--'] {
display: none;
}

sp-tabs[selected='s'] ~ .tabs--s {
display: block;
}

sp-tabs[selected='m'] ~ .tabs--m {
display: block;
}

sp-tabs[selected='l'] ~ .tabs--l {
display: block;
}

sp-tabs[selected='xl'] ~ .tabs--xl {
display: block;
}
5 changes: 3 additions & 2 deletions documentation/src/components/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import '@spectrum-web-components/icons-workflow/icons/sp-icon-alert.js';
import '@spectrum-web-components/icons-workflow/icons/sp-icon-edit.js';
import '@spectrum-web-components/icons-workflow/icons/sp-icon-more.js';
import { RouteComponent } from './route-component.js';
import componentStyles from './markdown.css';
import markdownStyles from './markdown.css';
import componentStyles from './component.css';
import { AppRouter } from '../router.js';
import '@spectrum-web-components/tabs/sp-tab.js';
import '@spectrum-web-components/tabs/sp-tabs.js';
Expand Down Expand Up @@ -128,7 +129,7 @@ class ComponentElement extends RouteComponent {
private docsLoaded = false;

public static get styles(): CSSResultArray {
return [componentStyles];
return [markdownStyles, componentStyles];
}

public get componentName(): string {
Expand Down
4 changes: 2 additions & 2 deletions documentation/src/utils/posthtml-spectrum-typography.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const transformations = [
},
{
tag: 'sp-rule',
attrs: { size: 'large' },
attrs: { size: 'l' },
},
],
};
Expand Down Expand Up @@ -104,7 +104,7 @@ const transformations = [
},
{
tag: 'sp-rule',
attrs: { size: 'medium' },
attrs: { size: 'm' },
},
],
};
Expand Down
73 changes: 69 additions & 4 deletions packages/action-button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,87 @@ When looking to leverage the `ActionButton` base class as a type and/or for exte
import { ActionButton } from '@spectrum-web-components/action-button';
```

## Example
## Sizes

<sp-tabs selected="m">
<sp-tab value="s">Small</sp-tab>
<sp-tab value="m">Medium</sp-tab>
<sp-tab value="l">Large</sp-tab>
<sp-tab value="xl">Extra Large</sp-tab>
</sp-tabs>

<div class="tabs--s">

```html demo
<sp-button-group>
<sp-action-button size="s">
Do action
</sp-action-button>
<sp-action-button size="s" selected>
Do action
</sp-action-button>
<sp-action-button size="s" disabled>
Do action
</sp-action-button>
</sp-button-group>
```

</div>

<div class="tabs--m">

```html demo
<sp-button-group>
<sp-action-button size="m">
Do action
</sp-action-button>
<sp-action-button size="m" selected>
Do action
</sp-action-button>
<sp-action-button size="m" disabled>
Do action
</sp-action-button>
</sp-button-group>
```

</div>

<div class="tabs--l">

```html demo
<sp-button-group>
<sp-action-button>
<sp-action-button size="l">
Do action
</sp-action-button>
<sp-action-button selected>
<sp-action-button size="l" selected>
Do action
</sp-action-button>
<sp-action-button disabled>
<sp-action-button size="l" disabled>
Do action
</sp-action-button>
</sp-button-group>
```

</div>

<div class="tabs--xl">

```html demo
<sp-button-group>
<sp-action-button size="xl">
Do action
</sp-action-button>
<sp-action-button size="xl" selected>
Do action
</sp-action-button>
<sp-action-button size="xl" disabled>
Do action
</sp-action-button>
</sp-button-group>
```

</div>

## Variants

### Action button with icon
Expand Down
6 changes: 2 additions & 4 deletions packages/action-button/src/ActionButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
property,
PropertyValues,
TemplateResult,
SizedMixin,
} from '@spectrum-web-components/base';
import { ButtonBase } from '@spectrum-web-components/button';
import buttonStyles from './action-button.css.js';
Expand All @@ -28,7 +29,7 @@ import { CornerTriangle300Icon } from '@spectrum-web-components/icons-ui';
*
* @fires change - Announces a change in the `selected` property of an action button
*/
export class ActionButton extends ButtonBase {
export class ActionButton extends SizedMixin(ButtonBase) {
public static get styles(): CSSResultArray {
return [buttonStyles, cornerTriangleStyles];
}
Expand Down Expand Up @@ -65,9 +66,6 @@ export class ActionButton extends ButtonBase {
}
private _value = '';

@property({ type: String, reflect: true })
public size = 'm';

/**
* @private
*/
Expand Down
69 changes: 65 additions & 4 deletions packages/bar-loader/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,81 @@ When looking to leverage the `BarLoader` base class as a type and/or for extensi
import { BarLoader } from '@spectrum-web-components/bar-loader';
```

## Variants
## Sizes

<sp-tabs selected="m">
<sp-tab value="s">Small</sp-tab>
<sp-tab value="m">Medium</sp-tab>
<sp-tab value="l">Large</sp-tab>
<sp-tab value="xl">Extra Large</sp-tab>
</sp-tabs>

<div class="tabs--s">

```html
<div
style="width: var(--spectrum-global-dimension-size-3000); height: var(--spectrum-global-dimension-size-2000); display: flex; flex-direction: column; align-items: center; justify-content: space-around;"
>
<sp-bar-loader
size="s"
label="Loaded a little"
progress="22"
></sp-bar-loader>
</div>
```

### Default
</div>

An `<sp-bar-loader>` is used to visually show the progression of a system operation such as downloading, uploading, processing, etc.
<div class="tabs--m">

```html
<div
style="width: var(--spectrum-global-dimension-size-3000); height: var(--spectrum-global-dimension-size-2000); display: flex; flex-direction: column; align-items: center; justify-content: space-around;"
>
<sp-bar-loader label="Loaded a little" progress="22"></sp-bar-loader>
<sp-bar-loader
size="m"
label="Loaded a little"
progress="22"
></sp-bar-loader>
</div>
```

</div>

<div class="tabs--l">

```html
<div
style="width: var(--spectrum-global-dimension-size-3000); height: var(--spectrum-global-dimension-size-2000); display: flex; flex-direction: column; align-items: center; justify-content: space-around;"
>
<sp-bar-loader
size="l"
label="Loaded a little"
progress="22"
></sp-bar-loader>
</div>
```

</div>

<div class="tabs--xl">

```html
<div
style="width: var(--spectrum-global-dimension-size-3000); height: var(--spectrum-global-dimension-size-2000); display: flex; flex-direction: column; align-items: center; justify-content: space-around;"
>
<sp-bar-loader
size="xl"
label="Loaded a little"
progress="22"
></sp-bar-loader>
</div>
```

</div>

## Variants

### Over background

When a loader needs to be placed on top of a colored background, use the over background loader as signified by `[over-background]`. This loader uses a white opaque color no matter the background. Make sure the background offers enough contrast for the loader to be legible.
Expand Down
6 changes: 2 additions & 4 deletions packages/bar-loader/src/BarLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
TemplateResult,
PropertyValues,
property,
SizedMixin,
} from '@spectrum-web-components/base';

import '@spectrum-web-components/field-label/sp-field-label.js';
Expand All @@ -25,7 +26,7 @@ import styles from './bar-loader.css.js';
/**
* @element sp-bar-loader
*/
export class BarLoader extends SpectrumElement {
export class BarLoader extends SizedMixin(SpectrumElement) {
public static get styles(): CSSResultArray {
return [styles];
}
Expand All @@ -42,9 +43,6 @@ export class BarLoader extends SpectrumElement {
@property({ type: Boolean, reflect: true, attribute: 'side-label' })
public sideLabel = false;

@property({ type: String, reflect: true })
public size = 'm';

@property({ type: Number })
public progress = 0;

Expand Down
1 change: 1 addition & 0 deletions packages/base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ governing permissions and limitations under the License.
*/

export * from './Base.js';
export * from './sizedMixin.js';
export * from 'lit-element';
export { nothing } from 'lit-html';
export { ifDefined } from 'lit-html/directives/if-defined.js';
Expand Down
58 changes: 58 additions & 0 deletions packages/base/src/sizedMixin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
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 { UpdatingElement, property, PropertyValues } from './index.js';

type Constructor<T = Record<string, unknown>> = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
new (...args: any[]): T;
prototype: T;
};

type ElementSize = 's' | 'm' | 'l' | 'xl';

export interface SizedElementInterface {
size: ElementSize;
}

export function SizedMixin<T extends Constructor<UpdatingElement>>(
constructor: T,
sizes = ['s', 'm', 'l', 'xl']
): T & Constructor<SizedElementInterface> {
class SizedElement extends constructor {
@property({ type: String, reflect: true })
public get size(): ElementSize {
return this._size;
}

public set size(value: ElementSize) {
const size = value.toLocaleLowerCase();
const validSize = (sizes.includes(size)
? size
: 'm') as ElementSize;
if (this._size === validSize) return;
const oldSize = this._size;
this._size = validSize;
this.setAttribute('size', validSize);
this.requestUpdate('size', oldSize);
}

private _size: ElementSize = 'm';

protected firstUpdated(changes: PropertyValues): void {
super.firstUpdated(changes);
if (!this.hasAttribute('size')) {
this.setAttribute('size', this.size);
}
}
}
return SizedElement;
}
Loading

0 comments on commit d7b63fb

Please sign in to comment.