Skip to content

Commit ded8fd9

Browse files
committed
Merge branch 'master' into fix/rgba-calc-error
2 parents ce3b546 + 0af33fa commit ded8fd9

File tree

15 files changed

+98
-25
lines changed

15 files changed

+98
-25
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
### 5.6.0
2+
3+
- Add new `HexAlphaColorPicker` component (via #186)
4+
- Fix types export for TYpeScript 4.7. Thanks to @AnotherHermit (via #189)
5+
- Improve ARIA attribute values for sliders. Thanks to @aitchiss (via #177)
6+
17
### 5.5.1
28

39
- Fix embedding into `<iframe>`. The component is rendered correctly by libraries like `react-frame-component`. Thanks to @leoc4e (via #166)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ We provide 12 additional color picker components for different color models, unl
8989
| Import | Value example |
9090
| --------------------------- | ---------------------------------- |
9191
| `{ HexColorPicker }` | `"#ffffff"` |
92+
| `{ HexAlphaColorPicker }` | `"#ffffff88"` |
9293
| `{ RgbColorPicker }` | `{ r: 255, g: 255, b: 255 }` |
9394
| `{ RgbaColorPicker }` | `{ r: 255, g: 255, b: 255, a: 1 }` |
9495
| `{ RgbStringColorPicker }` | `"rgb(255, 255, 255)"` |

demo/src/components/DevTools.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { PickerPreview } from "./PickerPreview";
33
import {
44
// HEX
55
HexColorPicker,
6+
HexAlphaColorPicker,
67
// RGB
78
RgbColor,
89
RgbColorPicker,
@@ -33,6 +34,11 @@ export const DevTools = (): JSX.Element => {
3334
return (
3435
<div>
3536
<PickerPreview<string> title="HEX" PickerComponent={HexColorPicker} initialColor="#406090" />
37+
<PickerPreview<string>
38+
title="HEX Alpha"
39+
PickerComponent={HexAlphaColorPicker}
40+
initialColor="#40609088"
41+
/>
3642
<PickerPreview<RgbColor>
3743
title="RGB"
3844
PickerComponent={RgbColorPicker}

demo/src/components/PickerPreview.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/ban-ts-comment */
12
import React, { useState } from "react";
23
import Frame from "react-frame-component";
34
import { HexColorInput } from "../../../src";
@@ -33,9 +34,10 @@ export function PickerPreview<T extends AnyColor>({
3334
<Wrapper>
3435
<PickerComponent color={color} onChange={handleChange} />
3536
</Wrapper>
36-
{/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
37-
{/* @ts-ignore */}
38-
{title === "HEX" && <HexColorInput color={color} onChange={handleChange} prefixed alpha />}
37+
{title.startsWith("HEX") && (
38+
// @ts-ignore
39+
<HexColorInput color={color} onChange={handleChange} prefixed alpha />
40+
)}
3941
</PreviewDemo>
4042
<PreviewOutput>{JSON.stringify(color)}</PreviewOutput>
4143
</PreviewContainer>

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-colorful",
3-
"version": "5.5.1",
3+
"version": "5.6.0",
44
"description": "🎨 A tiny (2,8 KB) color picker component for React and Preact apps. Fast, well-tested, dependency-free, mobile-friendly and accessible",
55
"source": "src/index.ts",
66
"main": "dist/index.js",
@@ -14,7 +14,8 @@
1414
"umd": "./dist/index.umd.js",
1515
"import": "./dist/index.mjs",
1616
"require": "./dist/index.js",
17-
"default": "./dist/index.module.js"
17+
"default": "./dist/index.module.js",
18+
"types": "./dist/index.d.ts"
1819
}
1920
},
2021
"scripts": {
@@ -108,7 +109,7 @@
108109
"path": "dist/index.module.js",
109110
"name": "RgbaStringColorPicker",
110111
"import": "{ RgbaStringColorPicker }",
111-
"limit": "3 KB"
112+
"limit": "3.1 KB"
112113
},
113114
{
114115
"path": "dist/index.module.js",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from "react";
2+
3+
import { AlphaColorPicker } from "./common/AlphaColorPicker";
4+
import { ColorModel, ColorPickerBaseProps } from "../types";
5+
import { equalHex } from "../utils/compare";
6+
import { hexToHsva, hsvaToHex } from "../utils/convert";
7+
8+
const colorModel: ColorModel<string> = {
9+
defaultColor: "0001",
10+
toHsva: hexToHsva,
11+
fromHsva: hsvaToHex,
12+
equal: equalHex,
13+
};
14+
15+
export const HexAlphaColorPicker = (props: Partial<ColorPickerBaseProps<string>>): JSX.Element => (
16+
<AlphaColorPicker {...props} colorModel={colorModel} />
17+
);

src/components/HexColorInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const HexColorInput = (props: HexColorInputProps): JSX.Element => {
1919

2020
/** Escapes all non-hexadecimal characters including "#" */
2121
const escape = useCallback(
22-
(value: string) => value.replace(/([^0-9A-F]+)/gi, "").substr(0, alpha ? 8 : 6),
22+
(value: string) => value.replace(/([^0-9A-F]+)/gi, "").substring(0, alpha ? 8 : 6),
2323
[alpha]
2424
);
2525

src/components/HexColorPicker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { hexToHsva, hsvaToHex } from "../utils/convert";
88
const colorModel: ColorModel<string> = {
99
defaultColor: "000",
1010
toHsva: hexToHsva,
11-
fromHsva: hsvaToHex,
11+
fromHsva: ({ h, s, v }) => hsvaToHex({ h, s, v, a: 1 }),
1212
equal: equalHex,
1313
};
1414

src/components/common/Alpha.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const Alpha = ({ className, hsva, onChange }: Props): JSX.Element => {
3535
};
3636

3737
const nodeClassName = formatClassName(["react-colorful__alpha", className]);
38+
const ariaValue = round(hsva.a * 100);
3839

3940
return (
4041
<div className={nodeClassName}>
@@ -43,7 +44,10 @@ export const Alpha = ({ className, hsva, onChange }: Props): JSX.Element => {
4344
onMove={handleMove}
4445
onKey={handleKey}
4546
aria-label="Alpha"
46-
aria-valuetext={`${round(hsva.a * 100)}%`}
47+
aria-valuetext={`${ariaValue}%`}
48+
aria-valuenow={ariaValue}
49+
aria-valuemin="0"
50+
aria-valuemax="100"
4751
>
4852
<Pointer
4953
className="react-colorful__alpha-pointer"

0 commit comments

Comments
 (0)