Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vwc-icon-button): viv-306 layout, shape, connotation support #504

Merged
merged 22 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions __snapshots__/icon button.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

```html
<button
aria-label=""
aria-label="bin"
class="mdc-icon-button"
>
<vwc-icon
class="icon"
class="vwc-icon"
size="small"
type=""
type="bin"
>
</vwc-icon>
<span class="default-slot-container">
Expand Down
9 changes: 8 additions & 1 deletion common/foundation/scss/mixins/_layout-mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
@use '../functions';

// override to apply relevance
$layouts: filled outlined soft text !default;
$layouts: filled outlined soft text ghost !default;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the difference between text & ghost?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

text and ghost styles are the same.
I didn't think layout="text" was appropriate for icon-button as there is no text in this element.
What do you think?

Copy link
Contributor

@yinonov yinonov Dec 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then remove the text

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is anyone using layout="text" buttons?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check, if so, we can keep both as css selectors for backwards compatibility

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe late to the party, but:

  • IMHO definitely just one of those should stay, and since it is used in vwc-icon-button which is text-less, as @JoelGraham93 mentioned, ghost sounds better
  • maybe transparent is even better than ghost?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, if had to pick, I would 'ghost'. but am up for more ideas on that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with ghost as it's a common term for buttons with no fill colour - though they usually have a border.
Was there any discoveries about removing layout="text"? I see PR is labeled ready-to-merge

////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
$allLayouts: (
filled: 'filled',
outlined: 'outlined',
soft: 'soft',
text: 'text',
ghost: 'ghost',
);

$bg: var(#{color-semantic.$vvd-color-connotation});
Expand All @@ -32,6 +33,12 @@ $bg: var(#{color-semantic.$vvd-color-connotation});
--opaque: 20;
}

%text,
%ghost {
--background-color: transparent;
--color: var(#{scheme-variables.$vvd-color-on-base});
}

@mixin layout() {
@each $layout in functions.pick($layouts, $allLayouts) {
#{':host([layout="#{$layout}"])'} {
Expand Down
1 change: 1 addition & 0 deletions common/foundation/scss/mixins/_shape-mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
$shapes: (
rounded: var(#{shape-var-names.$shape-border-radius-md-css-variable-name}),
pill: var(#{shape-var-names.$shape-border-radius-lg-css-variable-name}),
circled: 50%,
),
$default: rounded
) {
Expand Down
2 changes: 2 additions & 0 deletions common/foundation/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export enum Connotation {
export enum Shape {
Rounded = 'rounded',
Pill = 'pill',
Circled = 'circled',
}

export enum Size {
Expand All @@ -27,4 +28,5 @@ export enum Layout {
Filled = 'filled',
Outlined = 'outlined',
Soft = 'soft',
Ghost = 'ghost',
}
4 changes: 3 additions & 1 deletion components/badge/src/vwc-badge-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ type BadgeLayout = Extract<
Layout.Filled | Layout.Outlined | Layout.Soft
>;

type BadgeShape = Extract<Shape, Shape.Rounded | Shape.Pill>;

export class BadgeBase extends LitElement {
@property({ type: String, reflect: true })
connotation: BadgeConnotation = Connotation.Primary;

@property({ type: String, reflect: true })
shape?: Shape;
shape?: BadgeShape;

@property({ type: String, reflect: true })
layout: BadgeLayout = Layout.Filled;
Expand Down
4 changes: 3 additions & 1 deletion components/badge/stories/arg-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export const argTypes = {
shape: {
control: {
type: 'select',
options: Object.values(Shape)
options: Object.values(Shape).filter(s => [
Shape.Rounded, Shape.Pill
].includes(s)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just: [Shape.Rounded, Shape.Pill]?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dunno, it's just more supervised. it follows convention anyway, which is what we encourage, so better if this PR merges as is, and if we change this convention we do it in a dedicated PR

}
},
layout: {
Expand Down
4 changes: 3 additions & 1 deletion components/button/src/vwc-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type ButtonConnotation = Extract<
| Connotation.Announcement
>;

type ButtonShape = Extract<Shape, Shape.Rounded | Shape.Pill>;

/**
* This component is an extension of [<mwc-button>](https://github.com/material-components/material-components-web-components/tree/master/packages/button)
* Our button supports native features like the 'form' and 'type' attributes
Expand All @@ -51,7 +53,7 @@ export class VWCButton extends MWCButton {
connotation: ButtonConnotation = Connotation.Primary;

@property({ type: String, reflect: true })
shape?: Shape;
shape?: ButtonShape;

@property({ type: String, reflect: true })
type: ButtonType[number] = 'submit';
Expand Down
4 changes: 3 additions & 1 deletion components/button/stories/arg-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export const argTypes = {
shape: {
control: {
type: 'select',
options: Object.values(Shape),
options: Object.values(Shape).filter(s => [
Shape.Rounded, Shape.Pill
].includes(s)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as remark above - why not simple array of white listed values?

}
},
dense: {
Expand Down
34 changes: 20 additions & 14 deletions components/button/test/button.connotation.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import '../vwc-button.js';
import {
textToDomToParent,
isolatedElementsCreation,
Expand All @@ -7,16 +6,19 @@ import {
assertConnotationAttribute,
assertConnotationProperty,
} from '@vonage/vvd-foundation/test/connotation.test.js';
import { Connotation } from '@vonage/vvd-foundation/constants';

const CONNOTATIONS_SUPPORTED = Object.values(Connotation).filter((c) =>
[
Connotation.Primary,
Connotation.CTA,
Connotation.Success,
Connotation.Alert,
Connotation.Info,
Connotation.Announcement,
].includes(c)
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above - why not a simple array?


const VWC_BUTTON = 'vwc-button';
const CONNOTATIONS_SUPPORTED = [
'primary',
'cta',
'success',
'alert',
'info',
'announcement',
];
const LAYOUTS_AFFECTED = [
{
layout: 'filled',
Expand All @@ -36,15 +38,17 @@ const LAYOUTS_AFFECTED = [
},
];

describe('button connotation', () => {
export async function connotationTestCases(COMPONENT_NAME) {
const addElement = isolatedElementsCreation();

for (const { layout, childrenAffected, stylesAffected } of LAYOUTS_AFFECTED) {
for (const connotation of CONNOTATIONS_SUPPORTED) {
it(`should reflect '${connotation}' connotation (attribute) visually, ${layout}`, async () => {
const [button] = addElement(
textToDomToParent(
`<${VWC_BUTTON} layout="${layout}">Button</${VWC_BUTTON}>`
`<${COMPONENT_NAME} layout="${layout}" icon="bin">
${COMPONENT_NAME === 'vwc-button' ? 'Button' : ''}
</${COMPONENT_NAME}>`
)
);
await assertConnotationAttribute({
Expand All @@ -58,7 +62,9 @@ describe('button connotation', () => {
it(`should reflect '${connotation}' connotation (property) visually, ${layout}`, async () => {
const [button] = addElement(
textToDomToParent(
`<${VWC_BUTTON} layout="${layout}">Button</${VWC_BUTTON}>`
`<${COMPONENT_NAME} layout="${layout}" icon="bin">
${COMPONENT_NAME === 'vwc-button' ? 'Button' : ''}
</${COMPONENT_NAME}>`
)
);
await assertConnotationProperty({
Expand All @@ -70,4 +76,4 @@ describe('button connotation', () => {
});
}
}
});
}
69 changes: 12 additions & 57 deletions components/button/test/button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import {
textToDomToParent,
assertComputedStyle,
} from '../../../test/test-helpers.js';
import { shapeStyles } from '../../../test/style-utils.js';
import {
sizingTestCases,
shapeRoundedTestCases,
shapePillTestCases,
} from '../../../test/shared';
import { connotationTestCases } from './button.connotation.test.js';
import { chaiDomDiff } from '@open-wc/semantic-dom-diff';
import {
isolatedElementsCreation,
Expand Down Expand Up @@ -362,65 +367,15 @@ describe('button', () => {
});

describe('sizing', () => {
it('should have normal size by default', async () => {
const addedElements = addElement(
textToDomToParent(`<${COMPONENT_NAME}>Button Text</${COMPONENT_NAME}>`)
);
const actualElement = addedElements[0];
await waitNextTask();
assertComputedStyle(actualElement, { height: '40px' });
});

it('should have dense size when dense', async () => {
const addedElements = addElement(
textToDomToParent(
`<${COMPONENT_NAME} dense>Button Text</${COMPONENT_NAME}>`
)
);
const actualElement = addedElements[0];
await waitNextTask();
assertComputedStyle(actualElement, { height: '32px' });
});

it('should have enlarged size when enlarged', async () => {
const addedElements = addElement(
textToDomToParent(
`<${COMPONENT_NAME} enlarged>Button Text</${COMPONENT_NAME}>`
)
);
const actualElement = addedElements[0];
await waitNextTask();
assertComputedStyle(actualElement, { height: '48px' });
});
sizingTestCases(COMPONENT_NAME);
});

describe('shape', () => {
let formElement, actualElement;
beforeEach(async () => {
const addedElements = addElement(
textToDomToParent(
`<${COMPONENT_NAME} layout="filled">Button Text</${COMPONENT_NAME}>`
)
);
await waitNextTask();
formElement = addedElements[0];
actualElement = formElement.shadowRoot.querySelector('#button');
});

it('should have rounded shape by default', async () => {
assertComputedStyle(actualElement, shapeStyles('rounded'));
});

it('should have rounded shape when shape set to rounded', async () => {
formElement.shape = 'rounded';
await waitNextTask();
assertComputedStyle(actualElement, shapeStyles('rounded'));
});
shapeRoundedTestCases(COMPONENT_NAME);
shapePillTestCases(COMPONENT_NAME);
});

it('should have pill shape when shape set to pill', async () => {
formElement.shape = 'pill';
await waitNextTask();
assertComputedStyle(actualElement, shapeStyles('pill'));
});
describe('button connotation', () => {
connotationTestCases(COMPONENT_NAME);
});
});
55 changes: 51 additions & 4 deletions components/icon-button/src/vwc-icon-button.scss
Original file line number Diff line number Diff line change
@@ -1,22 +1,52 @@
@use '@vonage/vvd-design-tokens/build/scss/semantic-variables/scheme-variables';
@use '@vonage/vvd-foundation/scss/variable-names/color-semantic-variable-names' as color-semantic;
@use '@vonage/vvd-foundation/scss/mixins/shape-mixins';
@use '@vonage/vvd-foundation/scss/mixins/color-connotation-mixins' with (
$connotations: primary cta success alert info announcement
);
@use '@vonage/vvd-foundation/scss/mixins/layout-mixins' with (
$layouts: filled outlined ghost
);

:host {
.mdc-icon-button {
background-color: var(--background-color);
border: var(--border);
border-radius: var(--border-radius);
color: var(--color);
display: inline-flex;
align-items: center;
justify-content: center;
overflow: hidden;
}

.vwc-icon {
--size: 20px;
height: var(--size);
width: var(--size);
}
}

// theming
:host {
.mdc-icon-button {
color: var(#{scheme-variables.$vvd-color-on-base});
@include color-connotation-mixins.connotations-context(
':host([layout="filled"]#{color-connotation-mixins.$connotation-placeholder}),:host([layout="outlined"]#{color-connotation-mixins.$connotation-placeholder})'
);

:host([layout='filled']) {
.mdc-icon-button:disabled {
background-color: var(#{scheme-variables.$vvd-color-contrast-soft});
}
}

:host([layout='outlined']) {
.mdc-icon-button:disabled {
border-color: var(#{color-semantic.$formfield-disabled-ink});
}
}

:host {
.mdc-icon-button:disabled {
color: var( #{color-semantic.$formfield-disabled-ink});
color: var(#{color-semantic.$formfield-disabled-ink});
}
}

Expand All @@ -27,8 +57,25 @@

:host([dense]) {
--mdc-icon-button-size: 32px;

.vwc-icon {
--size: 16px;
}
}

:host([enlarged]) {
--mdc-icon-button-size: 48px;

.vwc-icon {
--size: 24px;
}
}

@include shape-mixins.shape(
$shapes: (
rounded: 6px,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rounded is 6px by default. can we exclude this from override somehow?

circled: 50%,
)
);

@include layout-mixins.layout();
Loading