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-circular-progress): added connotation support #694

Merged
merged 5 commits into from
Mar 9, 2021
Merged
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions components/circular-progress/package.json
Original file line number Diff line number Diff line change
@@ -28,7 +28,9 @@
"dependencies": {
"@material/mwc-circular-progress": "^0.20.0",
"@vonage/vvd-core": "^2.0.4",
"@vonage/vvd-foundation": "^2.0.4",
"@vonage/vvd-style-coupling": "^2.0.4",
"@vonage/vvd-design-tokens": "^2.0.4",
"lit-element": "^2.4.0",
"tslib": "^2.0.3"
},
14 changes: 14 additions & 0 deletions components/circular-progress/src/vwc-circular-progress.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@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/color-connotation-mixins' with (
$connotations: primary cta success alert
);

@include color-connotation-mixins.connotations-context(
':host(#{color-connotation-mixins.$connotation-placeholder})'
);

:host {
--mdc-theme-primary: var(#{color-semantic.$vvd-color-connotation},
var(#{scheme-variables.$vvd-color-primary}));
}
19 changes: 16 additions & 3 deletions components/circular-progress/src/vwc-circular-progress.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
import '@vonage/vvd-core';
import { customElement } from 'lit-element';
import { customElement, property } from 'lit-element';
import { CircularProgress as MWCCircularProgress } from '@material/mwc-circular-progress';
import { style as mwcCircularProgressStyle } from '@material/mwc-circular-progress/mwc-circular-progress-css.js';
import { style as vwcCircularProgressStyle } from './vwc-circular-progress.css';
import { style as styleCoupling } from '@vonage/vvd-style-coupling/vvd-style-coupling.css.js';
import { Connotation } from '@vonage/vvd-foundation/constants';

declare global {
interface HTMLElementTagNameMap {
'vwc-circular-progress': VWCCircularProgress;
}
}

type CircularProgressConnotation = Extract<
Connotation,
| Connotation.Primary
| Connotation.CTA
| Connotation.Success
| Connotation.Alert
>;

/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-ignore
MWCCircularProgress.styles = [styleCoupling, mwcCircularProgressStyle];
MWCCircularProgress.styles = [styleCoupling, mwcCircularProgressStyle, vwcCircularProgressStyle];

@customElement('vwc-circular-progress')
export class VWCCircularProgress extends MWCCircularProgress {}
export class VWCCircularProgress extends MWCCircularProgress {
@property({ type: String, reflect: true })
connotation?: CircularProgressConnotation | null;
}
8 changes: 8 additions & 0 deletions components/circular-progress/stories/arg-types.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Connotation } from '@vonage/vvd-foundation/constants';

export const argTypes = {
connotation: {
control: {
type: 'select',
options: [Connotation.Primary, Connotation.CTA, Connotation.Success, Connotation.Alert],
}
},
indeterminate: {
control: {
type: 'inline-radio',
64 changes: 64 additions & 0 deletions components/circular-progress/test/circular-progress.test.js
Original file line number Diff line number Diff line change
@@ -5,6 +5,11 @@ import {
textToDomToParent,
waitNextTask,
} from '../../../test/test-helpers';
import {
assertConnotationAttribute,
assertConnotationProperty,
} from '@vonage/vvd-foundation/test/connotation.test.js';
import { Connotation } from '@vonage/vvd-foundation/constants';

chai.use(chaiDomDiff);

@@ -30,4 +35,63 @@ describe('circular progress', () => {
await waitNextTask();
expect(actualElement.shadowRoot.innerHTML).to.equalSnapshot();
});

describe('Connotation', () => {
const CONNOTATIONS_SUPPORTED = [Connotation.Primary, Connotation.CTA, Connotation.Success, Connotation.Alert];

it(`should sync linear progress class member 'connotation' and html attribute 'connotation'`, async function () {
const [linearProgress] = addElement(
textToDomToParent(`<${COMPONENT_NAME}></${COMPONENT_NAME}>`)
);
await waitNextTask();

const syncMatchFn = connotation => linearProgress.connotation == connotation &&
linearProgress.getAttribute('connotation') == connotation;

let connotationValue = 'cta';
linearProgress.connotation = connotationValue;
await waitNextTask();
const propertyChangesAffectsAttribute = syncMatchFn(connotationValue);

connotationValue = 'primary';
linearProgress.setAttribute('connotation', connotationValue);
await waitNextTask();
const attributeChangesAffectsProperty = syncMatchFn(connotationValue);

expect(
propertyChangesAffectsAttribute,
'Property change did not apply to attribute'
).to.equal(true);
expect(
attributeChangesAffectsProperty,
'Attribute change did not apply to property'
).to.equal(true);
});

for (const connotation of CONNOTATIONS_SUPPORTED) {
it(`should reflect '${connotation}' connotation (attribute) visually`, async () => {
const [linearProgress] = addElement(
textToDomToParent(`<${COMPONENT_NAME}></${COMPONENT_NAME}>`)
);
await assertConnotationAttribute({
element: linearProgress,
connotation: connotation,
childrenAffected: ['.mdc-circular-progress__determinate-circle', '.mdc-circular-progress__indeterminate-circle-graphic'],
stylesAffected: ['stroke'],
});
});

it(`should reflect '${connotation}' connotation (property) visually`, async () => {
const [linearProgress] = addElement(
textToDomToParent(`<${COMPONENT_NAME}></${COMPONENT_NAME}>`)
);
await assertConnotationProperty({
element: linearProgress,
connotation: connotation,
childrenAffected: ['.mdc-circular-progress__determinate-circle', '.mdc-circular-progress__indeterminate-circle-graphic'],
stylesAffected: ['stroke'],
});
});
}
});
});
3 changes: 3 additions & 0 deletions components/circular-progress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -12,6 +12,9 @@
{
"path": "../../common/core"
},
{
"path": "../../common/foundation"
},
{
"path": "../../common/style-coupling"
}
2 changes: 2 additions & 0 deletions test/test-helpers.js
Original file line number Diff line number Diff line change
@@ -140,6 +140,8 @@ function assertComputedStyle(element, expectedStyles, pseudoSelector = null) {
case 'borderInlineEndColor':
case 'borderBlockStartColor':
case 'borderBlockEndColor':
case 'fill':
case 'stroke':
actualValue = computedStyle[styleKey].replaceAll(/\s/g, '');
expectedValue = expectedStyles[styleKey].replaceAll(/\s/g, '');
break;