-
Notifications
You must be signed in to change notification settings - Fork 56
Feature: Input color #1156
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
base: main
Are you sure you want to change the base?
Feature: Input color #1156
Changes from all commits
2199308
bd6a5fb
7eea98a
f9a8d48
45f4bfe
d881ef9
e8c7842
586c3d5
6381c69
c828032
7b56c69
e1dff2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# uui-input-color | ||
|
||
 | ||
|
||
Umbraco style input-color component. | ||
|
||
## Installation | ||
|
||
### ES imports | ||
|
||
```zsh | ||
npm i @umbraco-ui/uui-input-color | ||
``` | ||
|
||
Import the registration of `<uui-input-color>` via: | ||
|
||
```javascript | ||
import '@umbraco-ui/uui-input-color'; | ||
``` | ||
|
||
When looking to leverage the `UUIInputColorElement` base class as a type and/or for extension purposes, do so via: | ||
|
||
```javascript | ||
import { UUIInputColorElement } from '@umbraco-ui/uui-input-color'; | ||
``` | ||
|
||
## Usage | ||
|
||
```html | ||
<uui-input-color></uui-input-color> | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './uui-input-color.element'; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,120 @@ | ||||||
import { defineElement } from '@umbraco-ui/uui-base/lib/registration'; | ||||||
import { demandCustomElement } from '@umbraco-ui/uui-base/lib/utils'; | ||||||
import { css, html } from 'lit'; | ||||||
import { InputType, UUIInputElement } from '@umbraco-ui/uui-input/lib'; | ||||||
import { property, query, state } from 'lit/decorators.js'; | ||||||
import type { UUIColorPickerElement } from '@umbraco-ui/uui-color-picker/lib'; | ||||||
|
||||||
/** | ||||||
* @element uui-input-color | ||||||
* @extends uui-input | ||||||
*/ | ||||||
@defineElement('uui-input-color') | ||||||
export class UUIInputColorElement extends UUIInputElement { | ||||||
@state() | ||||||
private inputType: InputType = 'text'; | ||||||
|
||||||
@state() | ||||||
private _valueHex = ''; | ||||||
|
||||||
@query('#color') | ||||||
protected _colorPicker!: UUIColorPickerElement; | ||||||
|
||||||
@property({ type: String }) | ||||||
public override set value(value: string) { | ||||||
if (value.startsWith('#')) { | ||||||
this._valueHex = value; | ||||||
super.value = value.substring(1); | ||||||
} else { | ||||||
super.value = value; | ||||||
this._valueHex = `#${value}`; | ||||||
} | ||||||
} | ||||||
public override get value() { | ||||||
return super.value as string; | ||||||
} | ||||||
|
||||||
// this overrides the inherited type property, and moves the input's type handling to the inputType state. | ||||||
@property() | ||||||
get type() { | ||||||
return this.inputType; | ||||||
} | ||||||
set type(newValue) { | ||||||
this.inputType = newValue; | ||||||
} | ||||||
|
||||||
#onColorClick() { | ||||||
if (this.disabled || this.readonly) { | ||||||
return; | ||||||
} | ||||||
this._colorPicker.click(); | ||||||
} | ||||||
|
||||||
#onColorChange(event: Event) { | ||||||
event.stopPropagation(); | ||||||
this.value = this._colorPicker.value; | ||||||
} | ||||||
|
||||||
connectedCallback(): void { | ||||||
super.connectedCallback(); | ||||||
|
||||||
demandCustomElement(this, 'uui-color-swatch'); | ||||||
} | ||||||
|
||||||
renderPrepend() { | ||||||
return html`<div class="color-wrapper"> | ||||||
<uui-color-swatch | ||||||
?disabled=${this.disabled} | ||||||
?readonly=${this.readonly} | ||||||
value=${this._valueHex} | ||||||
@click=${this.#onColorClick}></uui-color-swatch> | ||||||
<input | ||||||
type="color" | ||||||
id="color" | ||||||
aria-hidden="true" | ||||||
value=${this.value} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The color input value should use
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
@change=${this.#onColorChange} /> | ||||||
</div>`; | ||||||
} | ||||||
|
||||||
static styles = [ | ||||||
...UUIInputElement.styles, | ||||||
css` | ||||||
.color-wrapper { | ||||||
display: inline-flex; | ||||||
position: relative; | ||||||
border-right: var(--uui-input-border-width, 1px) solid | ||||||
var(--uui-input-border-color, var(--uui-color-border)); | ||||||
} | ||||||
|
||||||
input[type='color'] { | ||||||
appearance: none; | ||||||
visibility: hidden; | ||||||
width: 0px; | ||||||
padding: 0; | ||||||
margin: 0; | ||||||
position: absolute; | ||||||
} | ||||||
|
||||||
uui-color-swatch { | ||||||
padding: var(--uui-size-1); | ||||||
} | ||||||
|
||||||
uui-color-swatch:not([disabled], [readonly]) { | ||||||
cursor: pointer; | ||||||
} | ||||||
|
||||||
uui-color-swatch:focus-within { | ||||||
outline: 2px solid var(--uui-color-selected); | ||||||
outline-offset: 0; | ||||||
border-radius: var(--uui-border-radius); | ||||||
} | ||||||
`, | ||||||
]; | ||||||
} | ||||||
|
||||||
declare global { | ||||||
interface HTMLElementTagNameMap { | ||||||
'uui-input-color': UUIInputColorElement; | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import type { Meta, StoryObj } from '@storybook/web-components'; | ||
|
||
import './uui-input-color.element'; | ||
import type { UUIInputColorElement } from './uui-input-color.element'; | ||
import readme from '../README.md?raw'; | ||
import { html } from 'lit'; | ||
import { spread } from '../../../storyhelpers'; | ||
|
||
/** | ||
* uui-input-color extends uui-input. See [uui-input](/docs/uui-input--docs) for more details. | ||
*/ | ||
const meta: Meta<UUIInputColorElement> = { | ||
id: 'uui-input-color', | ||
title: 'Inputs/Input Color', | ||
component: 'uui-input-color', | ||
args: { | ||
label: 'Color', | ||
value: '#d0021b', | ||
}, | ||
render: args => html`<uui-input-color ${spread(args)}></uui-input-color>`, | ||
parameters: { | ||
readme: { | ||
markdown: readme, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<UUIInputColorElement>; | ||
|
||
export const Overview: Story = {}; | ||
|
||
export const Empty: Story = { | ||
args: { | ||
value: '', | ||
}, | ||
}; | ||
|
||
export const Disabled: Story = { | ||
args: { | ||
disabled: true, | ||
}, | ||
}; | ||
|
||
export const Readonly: Story = { | ||
args: { | ||
readonly: true, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { html, fixture, expect } from '@open-wc/testing'; | ||
import { UUIInputColorElement } from './uui-input-color.element'; | ||
|
||
describe('UUIInputColorElement', () => { | ||
let element: UUIInputColorElement; | ||
|
||
beforeEach(async () => { | ||
element = await fixture(html` <uui-input-color></uui-input-color> `); | ||
}); | ||
|
||
it('is defined with its own instance', () => { | ||
expect(element).to.be.instanceOf(UUIInputColorElement); | ||
}); | ||
|
||
it('passes the a11y audit', async () => { | ||
await expect(element).shadowDom.to.be.accessible(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "@umbraco-ui/uui-input-color", | ||
"version": "0.0.0", | ||
"license": "MIT", | ||
"keywords": [ | ||
"Umbraco", | ||
"Custom elements", | ||
"Web components", | ||
"UI", | ||
"Lit", | ||
"Input Color" | ||
], | ||
"description": "Umbraco UI input-color component", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/umbraco/Umbraco.UI.git", | ||
"directory": "packages/uui-input-color" | ||
}, | ||
"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.1", | ||
"@umbraco-ui/uui-color-swatch": "1.14.1", | ||
"@umbraco-ui/uui-input": "1.14.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-input-color" | ||
} |
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'], | ||
}); |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,23 @@ | ||||||||||||
// 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" | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing dependency reference to uui-input package. The component extends UUIInputElement but the tsconfig.json doesn't include a reference to the uui-input package.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"path": "../uui-color-swatch" | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"path": "../uui-input" | ||||||||||||
} | ||||||||||||
] | ||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The component demands 'uui-color-swatch' but the template uses 'uui-color-swatch'. However, the import statement references 'UUIColorPickerElement' which suggests a mismatch in dependencies.
Copilot uses AI. Check for mistakes.