Skip to content

Commit

Permalink
feat(vwc-inline): add support for auto-fill/fit variance (#746)
Browse files Browse the repository at this point in the history
* feat(vwc-inline): add support for auto-fill/fit variance

* inline tests

* test inline template prop

* snapshot update
  • Loading branch information
yinonov authored Apr 6, 2021
1 parent 3f9fa1e commit 17732b3
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 21 deletions.
4 changes: 3 additions & 1 deletion __snapshots__/inline.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# `inline`

#### `should have internal contents`
## `basics`

#### `should have internal contents`

```html
<slot>
Expand Down
13 changes: 12 additions & 1 deletion components/inline/src/vwc-inline.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
$items-min-inline-size-v-name: --items-min-inline-size;
$items-spacing-v-name: --items-spacing;

$inline-template: --inline-template;

/* #region SIZE */
$items-min-inline-sizes: (
'sm': 10rem,
Expand Down Expand Up @@ -37,7 +39,7 @@ $items-spacings: (
gap: var(#{$items-spacing-v-name}, #{map.get($items-spacings, md)});
grid-auto-rows: min-content;
grid-template-columns: repeat(
auto-fit,
var(#{$inline-template}),
minmax(
var(
#{$items-min-inline-size-v-name},
Expand All @@ -48,3 +50,12 @@ $items-spacings: (
);
inline-size: 100%;
}

:host(:not(template)),
:host([template="fit"i]) {
#{$inline-template}: auto-fit;
}

:host([template="fill"i]) {
#{$inline-template}: auto-fill;
}
9 changes: 9 additions & 0 deletions components/inline/src/vwc-inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import { style } from './vwc-inline.css.js';

type SizeSpacing = Extract<Size, Size.Small | Size.Medium>;

// eslint-disable-next-line no-shadow
export enum InlineTemplate {
Fit = 'fit',
Fill = 'fill',
}

@customElement('vwc-inline')
export class Inline extends LitElement {
static styles = style;
Expand All @@ -21,6 +27,9 @@ export class Inline extends LitElement {
@property({ type: String, reflect: true })
spacing: SizeSpacing = Size.Small;

@property({ type: String, reflect: true })
template?: InlineTemplate;

protected render(): TemplateResult {
return html`<slot></slot>`;
}
Expand Down
9 changes: 8 additions & 1 deletion components/inline/stories/arg-types.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { Size } from '@vonage/vvd-foundation/constants';
import { InlineTemplate } from '../vwc-inline';


export const argTypes = {
template: {
control: {
type: 'select',
options: Object.values(InlineTemplate),
}
},
size: {
control: {
type: 'select',
Expand All @@ -14,4 +21,4 @@ export const argTypes = {
options: Object.values(Size).filter(s => [Size.Small, Size.Medium].includes(s)),
}
}
}
};
4 changes: 2 additions & 2 deletions components/inline/stories/inline-basic.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { spread } from '@open-wc/lit-helpers';
import { argTypes } from './arg-types.js';

export default {
title: 'Components/Atoms/Inline',
title: 'Components/Beta/Inline',
component: 'vwc-inline',
argTypes
}
};

const Template = args => html`
<style>
Expand Down
58 changes: 42 additions & 16 deletions components/inline/test/inline.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,52 @@ import { chaiDomDiff } from '@open-wc/semantic-dom-diff';
chai.use(chaiDomDiff);

const VWC_INLINE = 'vwc-inline';
const inlineHtmlStr = `<${VWC_INLINE}>
<span>1</span>
<span>2</span>
<span>3</span>
<span>4</span>
</${VWC_INLINE}>`;

const getNewElement = () => isolatedElementsCreation()(textToDomToParent(inlineHtmlStr))[0];

describe('inline', () => {
const addElement = isolatedElementsCreation();
describe('basics', () => {
it(`${VWC_INLINE} is defined as a custom element`, async () => {
assert.exists(
customElements.get(VWC_INLINE, `${VWC_INLINE} element is not defined`)
);
});

it(`${VWC_INLINE} is defined as a custom element`, async () => {
assert.exists(
customElements.get(VWC_INLINE, `${VWC_INLINE} element is not defined`)
);
it('should have internal contents', async () => {
const actualElement = getNewElement();
await waitNextTask();
expect(actualElement.shadowRoot.innerHTML).to.equalSnapshot();
});
});

it('should have internal contents', async () => {
const [actualElement] = addElement(
textToDomToParent(`<${VWC_INLINE}>
<span>1</span>
<span>2</span>
<span>3</span>
<span>4</span>
</${VWC_INLINE}>`)
);
await waitNextTask();
expect(actualElement.shadowRoot.innerHTML).to.equalSnapshot();
describe('API', () => {
it(`should set template fit`, async () => {
const actualElement = getNewElement();
actualElement.template = "fit";
actualElement.style.width = "1300px";
await waitNextTask();
const { shadowRoot: { firstElementChild: slot } } = actualElement;
const assignedElements = slot.assignedElements();
const [childEl] = assignedElements;
await waitNextTask();
expect(childEl.clientWidth).to.equal(307);
});
it(`should set template fill`, async () => {
const actualElement = getNewElement();
actualElement.template = "fill";
actualElement.style.width = "1300px";
await waitNextTask();
const { shadowRoot: { firstElementChild: slot } } = actualElement;
const assignedElements = slot.assignedElements();
const [childEl] = assignedElements;
await waitNextTask();
expect(childEl.clientWidth).to.equal(165);
});
});
});

0 comments on commit 17732b3

Please sign in to comment.