Skip to content

Commit 2595878

Browse files
committed
Add drag handle component
1 parent c1c2392 commit 2595878

File tree

12 files changed

+181
-0
lines changed

12 files changed

+181
-0
lines changed

packages/uui-drag-handle/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# uui-drag-handle
2+
3+
![npm](https://img.shields.io/npm/v/@umbraco-ui/uui-drag-handle?logoColor=%231B264F)
4+
5+
Umbraco style drag-handle component.
6+
7+
## Installation
8+
9+
### ES imports
10+
11+
```zsh
12+
npm i @umbraco-ui/uui-drag-handle
13+
```
14+
15+
Import the registration of `<uui-drag-handle>` via:
16+
17+
```javascript
18+
import '@umbraco-ui/uui-drag-handle';
19+
```
20+
21+
When looking to leverage the `UUIDragHandleElement` base class as a type and/or for extension purposes, do so via:
22+
23+
```javascript
24+
import { UUIDragHandleElement } from '@umbraco-ui/uui-drag-handle';
25+
```
26+
27+
## Usage
28+
29+
```html
30+
<uui-drag-handle></uui-drag-handle>
31+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './uui-drag-handle.element';
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { LabelMixin } from '@umbraco-ui/uui-base/lib/mixins';
2+
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
3+
import { css, html, LitElement } from 'lit';
4+
import { ifDefined } from 'lit/directives/if-defined.js';
5+
6+
/**
7+
* @element uui-drag-handle
8+
*/
9+
@defineElement('uui-drag-handle')
10+
export class UUIDragHandleElement extends LabelMixin('', LitElement) {
11+
render() {
12+
return html`<uui-icon
13+
name="drag"
14+
aria-label=${ifDefined(this.label)}></uui-icon>`;
15+
}
16+
17+
static styles = [
18+
css`
19+
:host {
20+
cursor: grab;
21+
}
22+
:host:active {
23+
cursor: grabbing;
24+
}
25+
`,
26+
];
27+
}
28+
29+
declare global {
30+
interface HTMLElementTagNameMap {
31+
'uui-drag-handle': UUIDragHandleElement;
32+
}
33+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { Meta, StoryObj } from '@storybook/web-components';
2+
3+
import './uui-drag-handle.element';
4+
import type { UUIDragHandleElement } from './uui-drag-handle.element';
5+
import readme from '../README.md?raw';
6+
7+
const meta: Meta<UUIDragHandleElement> = {
8+
id: 'uui-drag-handle',
9+
title: 'Symbols/Drag Handle',
10+
component: 'uui-drag-handle',
11+
parameters: {
12+
readme: { markdown: readme },
13+
docs: {
14+
source: {
15+
code: `<uui-drag-handle></uui-drag-handle>`,
16+
},
17+
},
18+
},
19+
};
20+
21+
export default meta;
22+
type Story = StoryObj<UUIDragHandleElement>;
23+
24+
export const Overview: Story = {};
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 { UUIDragHandleElement } from './uui-drag-handle.element';
3+
4+
describe('UUIDragHandleElement', () => {
5+
let element: UUIDragHandleElement;
6+
7+
beforeEach(async () => {
8+
element = await fixture(html` <uui-drag-handle></uui-drag-handle> `);
9+
});
10+
11+
it('is defined with its own instance', () => {
12+
expect(element).to.be.instanceOf(UUIDragHandleElement);
13+
});
14+
15+
it('passes the a11y audit', async () => {
16+
await expect(element).shadowDom.to.be.accessible();
17+
});
18+
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "@umbraco-ui/uui-drag-handle",
3+
"version": "0.0.0",
4+
"license": "MIT",
5+
"keywords": [
6+
"Umbraco",
7+
"Custom elements",
8+
"Web components",
9+
"UI",
10+
"Lit",
11+
"Drag Handle"
12+
],
13+
"description": "Umbraco UI drag-handle component",
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/umbraco/Umbraco.UI.git",
17+
"directory": "packages/uui-drag-handle"
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-drag-handle"
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+
});
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-icon-registry-essential/lib/UUIIconRegistryEssential.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
iconFavorite,
1818
iconFolder,
1919
iconForbidden,
20+
iconDrag,
2021
iconInfo,
2122
iconLink,
2223
iconLock,
@@ -51,6 +52,7 @@ export class UUIIconRegistryEssential extends UUIIconRegistry {
5152
this.defineIcon('delete', iconDelete.strings[0]);
5253
this.defineIcon('document', iconDocument.strings[0]);
5354
this.defineIcon('download', iconDownload.strings[0]);
55+
this.defineIcon('drag', iconDrag.strings[0]);
5456
this.defineIcon('edit', iconEdit.strings[0]);
5557
this.defineIcon('favorite', iconFavorite.strings[0]);
5658
this.defineIcon('folder', iconFolder.strings[0]);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { svg } from 'lit';
2+
3+
export const iconDrag = svg`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="9" cy="12" r="1"/><circle cx="9" cy="5" r="1"/><circle cx="9" cy="19" r="1"/><circle cx="15" cy="12" r="1"/><circle cx="15" cy="5" r="1"/><circle cx="15" cy="19" r="1"/></svg>`;

0 commit comments

Comments
 (0)