Skip to content

Feature: uui-drag-handle component #1118

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
31 changes: 31 additions & 0 deletions packages/uui-drag-handle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# uui-drag-handle

![npm](https://img.shields.io/npm/v/@umbraco-ui/uui-drag-handle?logoColor=%231B264F)

Umbraco style drag-handle component.

## Installation

### ES imports

```zsh
npm i @umbraco-ui/uui-drag-handle
```

Import the registration of `<uui-drag-handle>` via:

```javascript
import '@umbraco-ui/uui-drag-handle';
```

When looking to leverage the `UUIDragHandleElement` base class as a type and/or for extension purposes, do so via:

```javascript
import { UUIDragHandleElement } from '@umbraco-ui/uui-drag-handle';
```

## Usage

```html
<uui-drag-handle></uui-drag-handle>
```
1 change: 1 addition & 0 deletions packages/uui-drag-handle/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './uui-drag-handle.element';
33 changes: 33 additions & 0 deletions packages/uui-drag-handle/lib/uui-drag-handle.element.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { LabelMixin } from '@umbraco-ui/uui-base/lib/mixins';
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
import { css, html, LitElement } from 'lit';
import { ifDefined } from 'lit/directives/if-defined.js';

/**
* @element uui-drag-handle
*/
@defineElement('uui-drag-handle')
export class UUIDragHandleElement extends LabelMixin('', LitElement) {
render() {
return html`<uui-icon
name="drag"
aria-label=${ifDefined(this.label)}></uui-icon>`;
}

static styles = [
css`
:host {
cursor: grab;
}
:host:active {
cursor: grabbing;
}
`,
];
}

declare global {
interface HTMLElementTagNameMap {
'uui-drag-handle': UUIDragHandleElement;
}
}
24 changes: 24 additions & 0 deletions packages/uui-drag-handle/lib/uui-drag-handle.story.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { Meta, StoryObj } from '@storybook/web-components';

import './uui-drag-handle.element';
import type { UUIDragHandleElement } from './uui-drag-handle.element';
import readme from '../README.md?raw';

const meta: Meta<UUIDragHandleElement> = {
id: 'uui-drag-handle',
title: 'Symbols/Drag Handle',
component: 'uui-drag-handle',
parameters: {
readme: { markdown: readme },
docs: {
source: {
code: `<uui-drag-handle></uui-drag-handle>`,
},
},
},
};

export default meta;
type Story = StoryObj<UUIDragHandleElement>;

export const Overview: Story = {};
18 changes: 18 additions & 0 deletions packages/uui-drag-handle/lib/uui-drag-handle.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { html, fixture, expect } from '@open-wc/testing';
import { UUIDragHandleElement } from './uui-drag-handle.element';

describe('UUIDragHandleElement', () => {
let element: UUIDragHandleElement;

beforeEach(async () => {
element = await fixture(html` <uui-drag-handle></uui-drag-handle> `);
});

it('is defined with its own instance', () => {
expect(element).to.be.instanceOf(UUIDragHandleElement);
});

it('passes the a11y audit', async () => {
await expect(element).shadowDom.to.be.accessible();
});
});
44 changes: 44 additions & 0 deletions packages/uui-drag-handle/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "@umbraco-ui/uui-drag-handle",
"version": "0.0.0",
"license": "MIT",
"keywords": [
"Umbraco",
"Custom elements",
"Web components",
"UI",
"Lit",
"Drag Handle"
],
"description": "Umbraco UI drag-handle component",
"repository": {
"type": "git",
"url": "https://github.com/umbraco/Umbraco.UI.git",
"directory": "packages/uui-drag-handle"
},
"bugs": {
"url": "https://github.com/umbraco/Umbraco.UI/issues"
},
"main": "./lib/index.js",
"module": "./lib/index.js",
"types": "./lib/index.d.ts",
"type": "module",
"customElements": "custom-elements.json",
"files": [
"lib/**/*.d.ts",
"lib/**/*.js",
"custom-elements.json"
],
"dependencies": {
"@umbraco-ui/uui-base": "1.14.0-rc.1"
},
"scripts": {
"build": "npm run analyze && tsc --build --force && rollup -c rollup.config.js",
"clean": "tsc --build --clean && rimraf -g dist lib/*.js lib/**/*.js *.tgz lib/**/*.d.ts custom-elements.json",
"analyze": "web-component-analyzer **/*.element.ts --outFile custom-elements.json"
},
"publishConfig": {
"access": "public"
},
"homepage": "https://uui.umbraco.com/?path=/story/uui-drag-handle"
}
5 changes: 5 additions & 0 deletions packages/uui-drag-handle/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { UUIProdConfig } from '../rollup-package.config.mjs';

export default UUIProdConfig({
entryPoints: ['index'],
});
17 changes: 17 additions & 0 deletions packages/uui-drag-handle/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Don't edit this file directly. It is generated by /scripts/generate-ts-config.js

{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib",
"rootDir": "./lib",
"composite": true
},
"include": ["./**/*.ts"],
"exclude": ["./**/*.test.ts", "./**/*.story.ts"],
"references": [
{
"path": "../uui-base"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
iconFavorite,
iconFolder,
iconForbidden,
iconDrag,
iconInfo,
iconLink,
iconLock,
Expand Down Expand Up @@ -51,6 +52,7 @@ export class UUIIconRegistryEssential extends UUIIconRegistry {
this.defineIcon('delete', iconDelete.strings[0]);
this.defineIcon('document', iconDocument.strings[0]);
this.defineIcon('download', iconDownload.strings[0]);
this.defineIcon('drag', iconDrag.strings[0]);
this.defineIcon('edit', iconEdit.strings[0]);
this.defineIcon('favorite', iconFavorite.strings[0]);
this.defineIcon('folder', iconFolder.strings[0]);
Expand Down
3 changes: 3 additions & 0 deletions packages/uui-icon-registry-essential/lib/svgs/iconDrag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { svg } from 'lit';

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>`;
1 change: 1 addition & 0 deletions packages/uui-icon-registry-essential/lib/svgs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './iconColorPicker';
export * from './iconCopy';
export * from './iconDelete';
export * from './iconDocument';
export * from './iconDrag';
export * from './iconDownload';
export * from './iconEdit';
export * from './iconFavorite';
Expand Down
2 changes: 2 additions & 0 deletions packages/uui/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ export * from '@umbraco-ui/uui-toast-notification-layout/lib';
export * from '@umbraco-ui/uui-toast-notification/lib';
export * from '@umbraco-ui/uui-toggle/lib';
export * from '@umbraco-ui/uui-visually-hidden/lib';

export * from '@umbraco-ui/uui-drag-handle/lib';
Loading