Skip to content

Commit 655ee88

Browse files
julczkabjarnefmadsrasmusseniOvergaard
authored
feat: new uui-color-* components (color picker) (#413)
* Initial commit * Add color swatch * Use Colord library instead * Update pacage-lock.json * Make slider vertical * Make transparent background * Update Colord type * Adjust events in color picker components * Update inline picker * Update complete * Update HSB spectrum when hue change * Update value * Adjust hue change * Update brightness * Make selection of color swatches working * Outout value * Update single color swatch story * Include names plugin from Colord * update uui-base dependecy to latest rc3 * Update package lock * Update package lock * Update import of utils * update reference to uui-base to avoid clash in main package-lock * Adjust color picker to use popover as default * Adjust selected checkmark and color picker popover * Add example of transparent colors * Move button trigger outside popover so it is closed when clicking next to button trigger * Adjust preview and trigger buttons * Accessibility * Adjust copy color from preview button * Update keyboard selection in color area * Update story * Update keyboard selection on slider handle * Add slot for inner color hue gradient * Close popover when pressing esc key * Modify selection * Simplify clamp function * Update package-lock * Use rem instead * Use regular button element for preview color * Cleanup * Update package-lock * Uppercase text * Update button style * update package-lock to latest * update to new mjs import * add dependency between color-swatches and color-swatch * add dependency between color-swatch and icon-registry-essential * update package-lock * add dependency of colord to color packages and mark as external * remove duplicate class * add demand for uui-color-swatch * Adjust button elements * Adjust styling of sliders * Adjust color area sizing * Use vertical attribute for slider * Make handle in color area update when selecting color from palette * Focus and selection of swatches * Set initial value on color area * Adjust styling * Adjust text transform of button * Adjust story with format * add internal deps between uui --> color* * auto-generate new tsconfig * fix lint warning for a11y keydown on slider * add support for ArrowUp and ArrowDown with vertical on/off * fix eslint errors * add support for storybook controls for uui-color-slider * uui-color-area: add support for disabled state * uui-color-area: add support for storybook controls * add correct storybook category * uui-color-swatches: add default slot to support lightdom swatches * uui-color-picker: dispatch a change event on update * uui-color-picker: add support for controls and actions on storybook * run formatting * update main README * fix a11y tests * update internal dependecies * Update package-lock.json * remove dependency of colord * Revert "Update package-lock.json" This reverts commit a793117. * update package json lock * update lockfile * update package-lock * move assignemnt of handle and container to firstupdated hook * round the display value * add reverse number to math utils * reverse the min and max value on vertical display * add example to docs * simplify styles, remove class map * remove console.logs * correct box-sizing on input so it is aligned with the button group * remove unused display value * add label, disabled, parse color, add invalid color feedback * initialize color in first updated * remove swatches property and cleanup * remove empty state, fallback to black if no value * move toHex function to utils move toHex to utils * if no value start color area as black * initialize opacity as false * remove deprecated copy method * add docs * refactor color picker * add hue and opacity types to slider * refactor color area * implement slider type and cleanup * cleanup * rename slider custom properties * rename custom properties * make picker scale nicely * do not mark colord as external but instead bundle it along with our code * add nodeResolve to esm build to colord will be included * demand custom elements, add label mixin to color picker * add label mixin to color slider * add radiogroup role to swatch * improve imports of uui-color-swatches * docs: add missing slot documentation * docs: add jsdoc to uui-color-slider * remove unknown attribute 'autocorrect' * improve imports * add jsdoc to new props * add jsdocs for element * add docs for label slot * add docs for label slots * renderLabel is not implemented so no docs for the label slot * Revert "add docs for label slot" This reverts commit 693f243. * improve docs --------- Co-authored-by: Bjarne Fyrstenborg <[email protected]> Co-authored-by: Mads Rasmussen <[email protected]> Co-authored-by: Jacob Overgaard <[email protected]>
1 parent 1ed4469 commit 655ee88

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3045
-4
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ If you want to develop a component or contribute to the repository go to ["Get s
3737
| [`<uui-card-user>`](packages/uui-card-user) | [![npm](https://img.shields.io/npm/v/@umbraco-ui/uui-card-user?logoColor=%231B264F)](https://www.npmjs.com/package/@umbraco-ui/uui-card-user) |
3838
| [`<uui-caret>`](packages/uui-caret) | [![npm](https://img.shields.io/npm/v/@umbraco-ui/uui-caret?logoColor=%231B264F)](https://www.npmjs.com/package/@umbraco-ui/uui-caret) |
3939
| [`<uui-checkbox>`](packages/uui-checkbox) | [![npm](https://img.shields.io/npm/v/@umbraco-ui/uui-checkbox?logoColor=%231B264F)](https://www.npmjs.com/package/@umbraco-ui/uui-checkbox) |
40+
| [`<uui-color-area>`](packages/uui-color-area) | [![npm](https://img.shields.io/npm/v/@umbraco-ui/uui-color-area?logoColor=%231B264F)](https://www.npmjs.com/package/@umbraco-ui/uui-color-area) |
41+
| [`<uui-color-picker>`](packages/uui-color-picker) | [![npm](https://img.shields.io/npm/v/@umbraco-ui/uui-color-picker?logoColor=%231B264F)](https://www.npmjs.com/package/@umbraco-ui/uui-color-picker) |
42+
| [`<uui-color-slider>`](packages/uui-color-slider) | [![npm](https://img.shields.io/npm/v/@umbraco-ui/uui-color-slider?logoColor=%231B264F)](https://www.npmjs.com/package/@umbraco-ui/uui-color-slider) |
43+
| [`<uui-color-swatch>`](packages/uui-color-swatch) | [![npm](https://img.shields.io/npm/v/@umbraco-ui/uui-color-swatch?logoColor=%231B264F)](https://www.npmjs.com/package/@umbraco-ui/uui-color-swatch) |
44+
| [`<uui-color-swatches>`](packages/uui-color-swatches) | [![npm](https://img.shields.io/npm/v/@umbraco-ui/uui-color-swatches?logoColor=%231B264F)](https://www.npmjs.com/package/@umbraco-ui/uui-color-swatches) |
4045
| [`<uui-combobox>`](packages/uui-combobox) | [![npm](https://img.shields.io/npm/v/@umbraco-ui/uui-combobox?logoColor=%231B264F)](https://www.npmjs.com/package/@umbraco-ui/uui-combobox) |
4146
| [`<uui-combobox-list>`](packages/uui-combobox-list) | [![npm](https://img.shields.io/npm/v/@umbraco-ui/uui-combobox-list?logoColor=%231B264F)](https://www.npmjs.com/package/@umbraco-ui/uui-combobox-list) |
4247
| [`<uui-dialog>`](packages/uui-dialog) | [![npm](https://img.shields.io/npm/v/@umbraco-ui/uui-dialog?logoColor=%231B264F)](https://www.npmjs.com/package/@umbraco-ui/uui-dialog) |

package-lock.json

+112-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/rollup-package.config.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const createEsModulesConfig = (entryPoints = []) => {
2626
},
2727
external: [/^lit/, /^@umbraco-ui/],
2828
plugins: [
29+
nodeResolve(),
2930
importCss({ from: undefined }),
3031
esbuild(),
3132
processLitCSSPlugin(),

packages/uui-base/lib/utils/drag.ts

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
interface DragOptions {
2+
/** Callback that runs as dragging occurs. */
3+
onMove: (x: number, y: number) => void;
4+
/** Callback that runs when dragging stops. */
5+
onStop: () => void;
6+
/**
7+
* When an initial event is passed, the first drag will be triggered immediately using the coordinates therein. This
8+
* is useful when the drag is initiated by a mousedown/touchstart event but you want the initial "click" to activate
9+
* a drag (e.g. positioning a handle initially at the click target).
10+
*/
11+
initialEvent: PointerEvent;
12+
}
13+
14+
export const drag = (
15+
container: HTMLElement,
16+
options?: Partial<DragOptions>
17+
) => {
18+
function move(pointerEvent: PointerEvent) {
19+
const dims = container.getBoundingClientRect();
20+
const defaultView = container.ownerDocument.defaultView!;
21+
const offsetX = dims.left + defaultView.pageXOffset;
22+
const offsetY = dims.top + defaultView.pageYOffset;
23+
const x = pointerEvent.pageX - offsetX;
24+
const y = pointerEvent.pageY - offsetY;
25+
26+
if (options?.onMove) {
27+
options.onMove(x, y);
28+
}
29+
}
30+
31+
function stop() {
32+
document.removeEventListener('pointermove', move);
33+
document.removeEventListener('pointerup', stop);
34+
35+
if (options?.onStop) {
36+
options.onStop();
37+
}
38+
}
39+
40+
document.addEventListener('pointermove', move, { passive: true });
41+
document.addEventListener('pointerup', stop);
42+
43+
// If an initial event is set, trigger the first drag immediately
44+
if (options?.initialEvent) {
45+
move(options.initialEvent);
46+
}
47+
};

packages/uui-base/lib/utils/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
export * from './Timer';
22
export * from './demandCustomElement';
3+
export * from './drag';
4+
export * from './math';

packages/uui-base/lib/utils/math.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Ensures a number stays within a minimum and maximum value
3+
//
4+
export const clamp = (value: number, min: number, max: number) => {
5+
return Math.min(Math.max(value, min), max);
6+
};
7+
8+
/**
9+
* Reverses a number within a range
10+
*
11+
* @param {number} num - number to reverse
12+
* @param {number} min
13+
* @param {number} max
14+
* @return {*} {number}
15+
* @example
16+
* // returns 8
17+
* reverseNumberInRange (2, 0, 10)
18+
*/
19+
export const reverseNumberInRange = (
20+
num: number,
21+
min: number,
22+
max: number
23+
): number => {
24+
return max + min - num;
25+
};
26+
27+
export const toHex = (value: number) => {
28+
const hex = Math.round(value).toString(16);
29+
return hex.length === 1 ? `0${hex}` : hex;
30+
};

packages/uui-color-area/README.md

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

packages/uui-color-area/lib/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './uui-color-area.element';
2+
export * from './UUIColorAreaEvents';

0 commit comments

Comments
 (0)