Skip to content

Commit c58b612

Browse files
committed
Add uui-divider component
1 parent c1c2392 commit c58b612

File tree

9 files changed

+248
-0
lines changed

9 files changed

+248
-0
lines changed

packages/uui-divider/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# uui-divider
2+
3+
![npm](https://img.shields.io/npm/v/@umbraco-ui/uui-divider?logoColor=%231B264F)
4+
5+
Umbraco style divider component.
6+
7+
## Installation
8+
9+
### ES imports
10+
11+
```zsh
12+
npm i @umbraco-ui/uui-divider
13+
```
14+
15+
Import the registration of `<uui-divider>` via:
16+
17+
```javascript
18+
import '@umbraco-ui/uui-divider';
19+
```
20+
21+
When looking to leverage the `UUIDividerElement` base class as a type and/or for extension purposes, do so via:
22+
23+
```javascript
24+
import { UUIDividerElement } from '@umbraco-ui/uui-divider';
25+
```
26+
27+
## Usage
28+
29+
```html
30+
<uui-divider></uui-divider>
31+
```

packages/uui-divider/lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './uui-divider.element';
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
2+
import { css, LitElement } from 'lit';
3+
import { property } from 'lit/decorators.js';
4+
5+
/**
6+
* @element uui-divider
7+
* @cssprop --uui-divider-width - Divider width
8+
* @cssprop --uui-divider-color - Divider color
9+
* @cssprop --uui-divider-spacing - Spacing around the divider
10+
*/
11+
@defineElement('uui-divider')
12+
export class UUIDividerElement extends LitElement {
13+
/**
14+
* Draws the divider in a vertical orientation.
15+
* @type {boolean}
16+
* @attr
17+
* @default false
18+
**/
19+
@property({ type: Boolean, reflect: true }) vertical = false;
20+
21+
connectedCallback() {
22+
super.connectedCallback();
23+
this.setAttribute('role', 'separator');
24+
}
25+
26+
updated(_changedProperties: Map<string | number | symbol, unknown>) {
27+
super.updated(_changedProperties);
28+
if (_changedProperties.has('vertical')) {
29+
this.setAttribute(
30+
'aria-orientation',
31+
this.vertical ? 'vertical' : 'horizontal',
32+
);
33+
}
34+
}
35+
36+
static styles = [
37+
css`
38+
:host(:not([vertical])) {
39+
display: block;
40+
border-top: var(--uui-divider-width, 1px) solid
41+
var(--uui-divider-color, var(--uui-color-border));
42+
margin: var(--uui-divider-spacing) 0;
43+
}
44+
45+
:host([vertical]) {
46+
display: inline-block;
47+
height: 100%;
48+
border-left: solid var(--uui-divider-border-width, 1px)
49+
var(--uui-divider-color, var(--uui-color-border));
50+
margin: 0 var(--uui-divider-spacing);
51+
}
52+
`,
53+
];
54+
}
55+
56+
declare global {
57+
interface HTMLElementTagNameMap {
58+
'uui-divider': UUIDividerElement;
59+
}
60+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import type { Meta, StoryObj } from '@storybook/web-components';
2+
3+
import './uui-divider.element';
4+
import readme from '../README.md?raw';
5+
import type { UUIDividerElement } from './uui-divider.element';
6+
import { html } from 'lit';
7+
import { renderSlots, spread } from '../../../storyhelpers';
8+
9+
const meta: Meta<UUIDividerElement> = {
10+
id: 'uui-divider',
11+
title: 'Displays/Divider',
12+
component: 'uui-divider',
13+
render: args =>
14+
html`<uui-divider ${spread(args)}>${renderSlots(args)}</divider>`,
15+
parameters: {
16+
readme: { markdown: readme },
17+
docs: {
18+
source: {
19+
code: `<uui-divider></uui-divider>`,
20+
},
21+
},
22+
},
23+
};
24+
25+
export default meta;
26+
type Story = StoryObj<UUIDividerElement>;
27+
28+
export const Overview: Story = {};
29+
30+
export const Vertical: Story = {
31+
args: {
32+
vertical: true,
33+
},
34+
render: args => {
35+
return html`
36+
<div style="display: flex; align-items: center; height: 400px">
37+
<uui-divider ${spread(args)}>${renderSlots(args)}></uui-divider>
38+
</div>
39+
`;
40+
},
41+
};
42+
43+
export const Color: Story = {
44+
render: () => {
45+
return html`
46+
<uui-divider
47+
style="--uui-divider-color: var(--uui-palette-space-cadet);"></uui-divider>
48+
`;
49+
},
50+
};
51+
52+
export const Width: Story = {
53+
render: () => {
54+
return html`
55+
<uui-divider style="--uui-divider-width: 4px;"></uui-divider>
56+
`;
57+
},
58+
};
59+
60+
export const Spacing: Story = {
61+
render: () => {
62+
return html`
63+
<div style="text-align: center;">
64+
Above
65+
<uui-divider style="--uui-divider-spacing: 1rem;"></uui-divider>
66+
Below
67+
</div>
68+
`;
69+
},
70+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { html, fixture, expect } from '@open-wc/testing';
2+
import { UUIDividerElement } from './uui-divider.element';
3+
4+
describe('UUIDividerElement', () => {
5+
let element: UUIDividerElement;
6+
7+
beforeEach(async () => {
8+
element = await fixture(html` <uui-divider></uui-divider> `);
9+
});
10+
11+
it('is defined with its own instance', () => {
12+
expect(element).to.be.instanceOf(UUIDividerElement);
13+
});
14+
15+
it('passes the a11y audit', async () => {
16+
await expect(element).shadowDom.to.be.accessible();
17+
});
18+
});

packages/uui-divider/package.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "@umbraco-ui/uui-divider",
3+
"version": "0.0.0",
4+
"license": "MIT",
5+
"keywords": [
6+
"Umbraco",
7+
"Custom elements",
8+
"Web components",
9+
"UI",
10+
"Lit",
11+
"Divider"
12+
],
13+
"description": "Umbraco UI divider component",
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/umbraco/Umbraco.UI.git",
17+
"directory": "packages/uui-divider"
18+
},
19+
"bugs": {
20+
"url": "https://github.com/umbraco/Umbraco.UI/issues"
21+
},
22+
"main": "./lib/index.js",
23+
"module": "./lib/index.js",
24+
"types": "./lib/index.d.ts",
25+
"type": "module",
26+
"customElements": "custom-elements.json",
27+
"files": [
28+
"lib/**/*.d.ts",
29+
"lib/**/*.js",
30+
"custom-elements.json"
31+
],
32+
"dependencies": {
33+
"@umbraco-ui/uui-base": "1.14.0-rc.1"
34+
},
35+
"scripts": {
36+
"build": "npm run analyze && tsc --build --force && rollup -c rollup.config.js",
37+
"clean": "tsc --build --clean && rimraf -g dist lib/*.js lib/**/*.js *.tgz lib/**/*.d.ts custom-elements.json",
38+
"analyze": "web-component-analyzer **/*.element.ts --outFile custom-elements.json"
39+
},
40+
"publishConfig": {
41+
"access": "public"
42+
},
43+
"homepage": "https://uui.umbraco.com/?path=/story/uui-divider"
44+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { UUIProdConfig } from '../rollup-package.config.mjs';
2+
3+
export default UUIProdConfig({
4+
entryPoints: ['index'],
5+
});

packages/uui-divider/tsconfig.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Don't edit this file directly. It is generated by /scripts/generate-ts-config.js
2+
3+
{
4+
"extends": "../../tsconfig.json",
5+
"compilerOptions": {
6+
"outDir": "./lib",
7+
"rootDir": "./lib",
8+
"composite": true
9+
},
10+
"include": ["./**/*.ts"],
11+
"exclude": ["./**/*.test.ts", "./**/*.story.ts"],
12+
"references": [
13+
{
14+
"path": "../uui-base"
15+
}
16+
]
17+
}

packages/uui/lib/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,5 @@ export * from '@umbraco-ui/uui-toast-notification-layout/lib';
8181
export * from '@umbraco-ui/uui-toast-notification/lib';
8282
export * from '@umbraco-ui/uui-toggle/lib';
8383
export * from '@umbraco-ui/uui-visually-hidden/lib';
84+
85+
export * from '@umbraco-ui/uui-divider/lib/index.js';

0 commit comments

Comments
 (0)