Skip to content

Commit 36235ab

Browse files
authored
Merge pull request #145 from umbraco/feature/uui-input-lock
uui-input-lock
2 parents f66ef73 + 695cb72 commit 36235ab

14 files changed

+293
-1
lines changed

package-lock.json

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

packages/uui-input-lock/README.md

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

packages/uui-input-lock/lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './uui-input-lock.element';
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
2+
import { css, html } from 'lit';
3+
import { UUIInputElement } from '@umbraco-ui/uui-input/lib';
4+
import {
5+
iconLock,
6+
iconUnlock,
7+
} from '@umbraco-ui/uui-icon-registry-essential/lib/svgs';
8+
import { property } from 'lit/decorators.js';
9+
10+
/**
11+
* @element uui-input-lock
12+
* @extends uui-input
13+
*/
14+
@defineElement('uui-input-lock')
15+
export class UUIInputLockElement extends UUIInputElement {
16+
static styles = [
17+
...UUIInputElement.styles,
18+
css`
19+
#lock {
20+
height: 100%;
21+
22+
--uui-button-padding-top-factor: 0;
23+
--uui-button-padding-bottom-factor: 0;
24+
--uui-button-padding-left-factor: 0.75;
25+
--uui-button-padding-right-factor: 0.75;
26+
font-size: 12px;
27+
}
28+
29+
:host([locked]) #input {
30+
cursor: not-allowed;
31+
opacity: 0.5;
32+
}
33+
`,
34+
];
35+
36+
/**
37+
* Determine the inputs locked state.
38+
* @type {boolean}
39+
* @attr
40+
* @default true
41+
*/
42+
@property({ type: Boolean, reflect: true })
43+
public locked: boolean = true;
44+
45+
constructor() {
46+
super();
47+
this.readonly = true;
48+
}
49+
50+
_onLockToggle() {
51+
this.readonly = this.locked = !this.locked;
52+
}
53+
54+
renderIcon() {
55+
return this.locked === true
56+
? html`<uui-icon name="lock" .fallback=${iconLock.strings[0]}></uui-icon>`
57+
: html`<uui-icon
58+
name="unlock"
59+
.fallback=${iconUnlock.strings[0]}></uui-icon>`;
60+
}
61+
62+
renderPrepend() {
63+
return html`<uui-button
64+
.disabled=${this.disabled}
65+
@click=${this._onLockToggle}
66+
compact
67+
id="lock">
68+
${this.renderIcon()}
69+
</uui-button>`;
70+
}
71+
}
72+
73+
declare global {
74+
interface HTMLElementTagNameMap {
75+
'uui-input-lock': UUIInputLockElement;
76+
}
77+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import '.';
2+
3+
import { Story } from '@storybook/web-components';
4+
import { html } from 'lit-html';
5+
6+
export default {
7+
id: 'uui-input-lock',
8+
title: 'Inputs/Input Lock',
9+
component: 'uui-input-lock',
10+
args: {
11+
value: '',
12+
label: 'Label',
13+
},
14+
parameters: {
15+
docs: {
16+
source: {
17+
code: `<uui-input-lock></uui-input-lock>`,
18+
},
19+
},
20+
},
21+
};
22+
23+
export const AAAOverview: Story = props =>
24+
html`<uui-input-lock
25+
.disabled=${props.disabled}
26+
.error=${props.error}
27+
.label=${props.label}
28+
.name=${props.name}
29+
.placeholder=${props.placeholder}
30+
.value=${props.value}></uui-input-lock>`;
31+
32+
AAAOverview.storyName = 'Overview';
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { html, fixture, expect } from '@open-wc/testing';
2+
import { UUIInputLockElement } from './uui-input-lock.element';
3+
import '.';
4+
import { UUIInputElement } from '@umbraco-ui/uui-input/lib/';
5+
6+
describe('UUIInputLockElement', () => {
7+
let element: UUIInputLockElement;
8+
9+
beforeEach(async () => {
10+
element = await fixture(
11+
html` <uui-input-lock label="Input label"></uui-input-lock> `
12+
);
13+
});
14+
15+
it('is defined with its own instance', () => {
16+
expect(element).to.be.instanceOf(UUIInputLockElement);
17+
});
18+
19+
it('inherits from uui-input', () => {
20+
expect(element).to.be.instanceOf(UUIInputElement);
21+
});
22+
23+
it('passes the a11y audit', async () => {
24+
// Only verify that the color contrast is good when its not locked.
25+
element.locked = false;
26+
await expect(element).shadowDom.to.be.accessible();
27+
});
28+
29+
describe('properties', () => {
30+
it('has a locked property', () => {
31+
expect(element).to.have.property('name');
32+
});
33+
});
34+
35+
it('correctly toggles lock', async () => {
36+
await expect(element.readonly).to.be.true;
37+
const toggle = element.shadowRoot?.querySelector(
38+
'#lock'
39+
) as HTMLButtonElement;
40+
toggle.click();
41+
await expect(element.readonly).to.be.false;
42+
toggle.click();
43+
await expect(element.readonly).to.be.true;
44+
});
45+
});

packages/uui-input-lock/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-input-lock",
3+
"version": "0.0.0",
4+
"license": "MIT",
5+
"keywords": [
6+
"Umbraco",
7+
"Custom elements",
8+
"Web components",
9+
"UI",
10+
"Lit",
11+
"Input Lock"
12+
],
13+
"description": "Umbraco UI input-lock component",
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/umbraco/Umbraco.UI.git",
17+
"directory": "packages/uui-input-lock"
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": "0.0.17"
34+
},
35+
"scripts": {
36+
"build": "npm run analyze && tsc --build --force && rollup -c rollup.config.js",
37+
"clean": "tsc --build --clean && rimraf dist lib/*.js lib/**/*.js 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-input-lock"
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';
2+
3+
export default UUIProdConfig({
4+
entryPoints: ['index'],
5+
});

packages/uui-input-lock/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-input-password/lib/uui-input-password.element.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { property, state } from 'lit/decorators.js';
99

1010
/**
1111
* @element uui-input-password
12+
* @extends uui-input
1213
*/
1314
@defineElement('uui-input-password')
1415
export class UUIInputPasswordElement extends UUIInputElement {

0 commit comments

Comments
 (0)