Skip to content

Commit a74cccc

Browse files
authored
Merge branch 'dev' into feature/loader-bar-looks
2 parents 2447d11 + a70ff42 commit a74cccc

File tree

9 files changed

+162
-82
lines changed

9 files changed

+162
-82
lines changed

package-lock.json

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/uui-box/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,5 @@ import { UUIBoxElement } from '@umbraco-ui/uui-box';
2929
## Usage
3030

3131
```html
32-
<uui-box>
33-
<div slot="header">Header</div>
34-
<div slot="main">Main</main>
35-
</uui-box>
32+
<uui-box headline="Headline"> Content </uui-box>
3633
```

packages/uui-box/lib/uui-box.element.ts

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,96 @@
1+
import { LitElement, html, css } from 'lit';
12
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
2-
import { css, html, LitElement } from 'lit';
3+
import { property, state } from 'lit/decorators.js';
4+
import { UUITextStyles } from '@umbraco-ui/uui-css/lib';
35

46
/**
57
* A box for grouping elements
68
* @element uui-box
7-
* @slot header - header area for title
8-
* @slot main - main content area
9-
* @slot - area with no padding
9+
* @slot headline - headline area
10+
* @slot header - headline area
11+
* @slot default - area for the content of the box
12+
* @cssprop --uui-box-default-padding - overwrite the box padding
1013
*
1114
*/
1215
@defineElement('uui-box')
1316
export class UUIBoxElement extends LitElement {
1417
static styles = [
18+
UUITextStyles,
1519
css`
1620
:host {
1721
display: block;
1822
box-shadow: var(--uui-shadow-depth-1);
1923
border-radius: var(--uui-border-radius);
2024
background-color: var(--uui-interface-surface);
25+
--uui-box-default-padding: var(--uui-size-space-5);
2126
}
2227
23-
::slotted([slot='header']) {
28+
#header {
29+
display: block;
2430
border-bottom: 1px solid var(--uui-interface-border);
25-
padding: var(--uui-size-4) var(--uui-size-5);
31+
padding: var(--uui-size-space-4) var(--uui-size-space-5);
2632
}
2733
28-
::slotted([slot='main']) {
29-
padding: var(--uui-size-5);
34+
slot:not([name]) {
35+
display: block;
36+
padding: var(--uui-box-default-padding, var(--uui-size-space-5));
3037
}
3138
`,
3239
];
3340

41+
/**
42+
* Headline for this box, can also be set via the 'box' slot.
43+
* @type string
44+
* @attr
45+
* @default null
46+
*/
47+
@property({ type: String })
48+
headline: string | null = null;
49+
50+
@state()
51+
private _headlineSlotHasContent = false;
52+
private _headlineSlotChanged = (e: Event) => {
53+
this._headlineSlotHasContent =
54+
(e.target as HTMLSlotElement).assignedNodes({ flatten: true }).length > 0;
55+
};
56+
57+
@state()
58+
private _headerSlotHasContent = false;
59+
private _headerSlotChanged = (e: Event) => {
60+
this._headerSlotHasContent =
61+
(e.target as HTMLSlotElement).assignedNodes({ flatten: true }).length > 0;
62+
};
63+
64+
/**
65+
* Renders a header with the header-slot, headline and headline-slot within
66+
* @returns {TemplateResult}
67+
* @protected
68+
* @method
69+
*/
70+
protected renderHeader() {
71+
return html`<div
72+
id="header"
73+
class="uui-text"
74+
style=${this._headerSlotHasContent ||
75+
this._headlineSlotHasContent ||
76+
this.headline !== null
77+
? ''
78+
: 'display: none'}>
79+
<h5
80+
id="headline"
81+
style=${this._headlineSlotHasContent || this.headline !== null
82+
? ''
83+
: 'display: none'}>
84+
${this.headline}
85+
<slot name="headline" @slotchange=${this._headlineSlotChanged}></slot>
86+
</h5>
87+
<slot name="header" @slotchange=${this._headerSlotChanged}></slot>
88+
</div>`;
89+
}
90+
3491
render() {
3592
return html`
36-
<slot name="header"></slot>
37-
<slot name="main"></slot>
93+
${this.renderHeader()}
3894
<slot></slot>
3995
`;
4096
}

packages/uui-box/lib/uui-box.story.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,20 @@ export default {
1010
};
1111

1212
const Template: Story = () => html`
13-
<uui-box>
14-
<div slot="header">Header</div>
15-
<div slot="main">Main</div>
13+
<uui-box headline="Headline">
14+
Some content of this box, appended in the default slot.
1615
</uui-box>
1716
`;
1817

1918
export const AAAOverview = Template.bind({});
2019
AAAOverview.storyName = 'Overview';
21-
AAAOverview.parameters = {
22-
docs: {
23-
source: {
24-
code: `
25-
<uui-box>
26-
<div slot="header">Header</div>
27-
<div slot="main">Main</div>
28-
</uui-box>
29-
`,
30-
},
31-
},
32-
};
20+
21+
export const Slots: Story = () => html`
22+
<uui-box>
23+
<uui-button slot="headline" look="placeholder" style="font-weight:inherit;"
24+
>Headline slot</uui-button
25+
>
26+
<uui-button slot="header" look="placeholder">Header slot</uui-button>
27+
<uui-button look="placeholder">Default slot</uui-button>
28+
</uui-box>
29+
`;

packages/uui-box/lib/uui-box.test.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import { UUIBoxElement } from './uui-box.element';
55
describe('UUIBox', () => {
66
let element: UUIBoxElement;
77
beforeEach(async () => {
8-
element = await fixture(html` <uui-box>
9-
<div slot="header">Header</div>
10-
<div slot="main">Main</div>
8+
element = await fixture(html` <uui-box headline="headline">
9+
Main
1110
</uui-box>`);
1211
});
1312

@@ -18,4 +17,41 @@ describe('UUIBox', () => {
1817
it('passes the a11y audit', async () => {
1918
await expect(element).shadowDom.to.be.accessible();
2019
});
20+
21+
describe('properties', () => {
22+
it('has a headline property', () => {
23+
expect(element).to.have.property('headline');
24+
});
25+
});
26+
27+
describe('template', () => {
28+
it('renders a default slot', () => {
29+
const slot = element.shadowRoot!.querySelector('slot')!;
30+
expect(slot).to.exist;
31+
});
32+
33+
it('renders an headline slot', () => {
34+
const slot = element.shadowRoot!.querySelector('slot[name=headline]')!;
35+
expect(slot).to.exist;
36+
});
37+
38+
it('renders a header slot', () => {
39+
const slot = element.shadowRoot!.querySelector('slot[name=header]')!;
40+
expect(slot).to.exist;
41+
});
42+
});
43+
44+
describe('UUIBox', () => {
45+
let element: UUIBoxElement;
46+
beforeEach(async () => {
47+
element = await fixture(html` <uui-box>
48+
<div slot="header">Something in the header</div>
49+
Main
50+
</uui-box>`);
51+
});
52+
53+
it('passes the a11y audit', async () => {
54+
await expect(element).shadowDom.to.be.accessible();
55+
});
56+
});
2157
});

packages/uui-box/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"custom-elements.json"
3030
],
3131
"dependencies": {
32-
"@umbraco-ui/uui-base": "0.0.17"
32+
"@umbraco-ui/uui-base": "0.0.17",
33+
"@umbraco-ui/uui-css": "0.0.4"
3334
},
3435
"scripts": {
3536
"build": "npm run analyze && tsc --build --force && rollup -c rollup.config.js",

packages/uui-box/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
"references": [
1313
{
1414
"path": "../uui-base"
15+
},
16+
{
17+
"path": "../uui-css"
1518
}
1619
]
1720
}

0 commit comments

Comments
 (0)