Skip to content

Commit b849199

Browse files
committed
fix(chrome): fix showAlpha props issue. #159
1 parent 455d820 commit b849199

4 files changed

Lines changed: 64 additions & 17 deletions

File tree

packages/color-chrome/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,48 @@ function Demo() {
7777
export default Demo;
7878
```
7979

80+
Disable the opacity setting by setting `showAlpha` to `false`.
81+
82+
```jsx mdx:preview
83+
import React, { useState } from 'react';
84+
85+
import {
86+
HsvaColor,
87+
hsvaToRgbaString,
88+
color as handleColor,
89+
validHex,
90+
hexToHsva,
91+
hsvaToHex,
92+
hsvaToHexa,
93+
} from '@uiw/color-convert';
94+
95+
import Chrome from '@uiw/react-color-chrome';
96+
import { GithubPlacement } from '@uiw/react-color-github';
97+
98+
function Demo() {
99+
const [hsva, setHsva] = useState({ h:0, s:25.71, v:82.35, a:0.32});
100+
const hex = hsvaToHex(hsva)
101+
return (
102+
<>
103+
<Chrome
104+
color={hsva}
105+
style={{ marginTop: 10 }}
106+
placement={GithubPlacement.TopRight}
107+
showAlpha={false}
108+
onChange={(color) => {
109+
setHsva(color.hsva);
110+
}}
111+
/>
112+
<div style={{ background: hex, marginTop: 30, padding: 10 }}>
113+
{hex}
114+
</div>
115+
</>
116+
);
117+
}
118+
export default Demo;
119+
```
120+
121+
80122
## Props
81123

82124
```ts

packages/color-chrome/src/index.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import React, { CSSProperties, Fragment } from 'react';
1+
import React, { type CSSProperties, Fragment } from 'react';
22
import {
3-
HsvaColor,
3+
type HsvaColor,
44
hsvaToRgbaString,
55
color as handleColor,
66
validHex,
77
hexToHsva,
88
hsvaToHex,
99
hsvaToHexa,
1010
} from '@uiw/color-convert';
11-
import Github, { GithubProps, GithubPlacement } from '@uiw/react-color-github';
11+
import Github, { type GithubProps, GithubPlacement } from '@uiw/react-color-github';
1212
import Saturation from '@uiw/react-color-saturation';
1313
import Hue from '@uiw/react-color-hue';
1414
import Alpha from '@uiw/react-color-alpha';
@@ -132,7 +132,7 @@ const Chrome = React.forwardRef<HTMLDivElement, ChromeProps>((props, ref) => {
132132
{showHue == true && (
133133
<Hue
134134
hue={hsva.h}
135-
style={{ width: '100%', height: 12 }}
135+
style={{ width: '100%', height: 12, borderRadius: 2 }}
136136
pointerProps={pointerProps}
137137
bgProps={{
138138
style: { borderRadius: 2 },
@@ -145,7 +145,7 @@ const Chrome = React.forwardRef<HTMLDivElement, ChromeProps>((props, ref) => {
145145
{showAlpha == true && (
146146
<Alpha
147147
hsva={hsva}
148-
style={{ marginTop: 6, height: 12 }}
148+
style={{ marginTop: 6, height: 12, borderRadius: 2 }}
149149
pointerProps={pointerProps}
150150
bgProps={{
151151
style: { borderRadius: 2 },
@@ -166,7 +166,7 @@ const Chrome = React.forwardRef<HTMLDivElement, ChromeProps>((props, ref) => {
166166
rProps={{ labelStyle, inputStyle }}
167167
gProps={{ labelStyle, inputStyle }}
168168
bProps={{ labelStyle, inputStyle }}
169-
aProps={{ labelStyle, inputStyle }}
169+
aProps={showAlpha == false ? false : { labelStyle, inputStyle }}
170170
onChange={(reColor) => handleChange(reColor.hsva)}
171171
/>
172172
)}
@@ -189,7 +189,7 @@ const Chrome = React.forwardRef<HTMLDivElement, ChromeProps>((props, ref) => {
189189
hProps={{ labelStyle, inputStyle }}
190190
sProps={{ labelStyle, inputStyle }}
191191
lProps={{ labelStyle, inputStyle }}
192-
aProps={{ labelStyle, inputStyle }}
192+
aProps={showAlpha == false ? false : { labelStyle, inputStyle }}
193193
onChange={(reColor) => handleChange(reColor.hsva)}
194194
/>
195195
)}

packages/color-editable-input-hsla/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export interface EditableInputHSLAProps extends Omit<EditableInputRGBAProps, 'rP
4747
hProps?: EditableInputRGBAProps['gProps'];
4848
sProps?: EditableInputRGBAProps['gProps'];
4949
lProps?: EditableInputRGBAProps['gProps'];
50-
aProps?: EditableInputRGBAProps['aProps'];
50+
aProps?: false | EditableInputRGBAProps['aProps'];
5151
}
5252
declare const EditableInputHSLA: React.ForwardRefExoticComponent<EditableInputHSLAProps & React.RefAttributes<HTMLDivElement>>;
5353
export default EditableInputHSLA;

packages/color-editable-input-hsla/src/index.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import React from 'react';
2-
import EditableInputRGBA, { EditableInputRGBAProps } from '@uiw/react-color-editable-input-rgba';
3-
import { HslaColor, color as handleColor, hsvaToHsla, hslaToHsva } from '@uiw/color-convert';
2+
import { type EditableInputProps } from '@uiw/react-color-editable-input';
3+
import EditableInputRGBA, { type EditableInputRGBAProps } from '@uiw/react-color-editable-input-rgba';
4+
import { type HslaColor, color as handleColor, hsvaToHsla, hslaToHsva } from '@uiw/color-convert';
45

56
export interface EditableInputHSLAProps extends Omit<EditableInputRGBAProps, 'rProps' | 'gProps' | 'bProps'> {
67
hProps?: EditableInputRGBAProps['gProps'];
78
sProps?: EditableInputRGBAProps['gProps'];
89
lProps?: EditableInputRGBAProps['gProps'];
9-
aProps?: EditableInputRGBAProps['aProps'];
10+
aProps?: false | EditableInputRGBAProps['aProps'];
1011
}
1112

1213
const EditableInputHSLA = React.forwardRef<HTMLDivElement, EditableInputHSLAProps>((props, ref) => {
@@ -46,6 +47,15 @@ const EditableInputHSLA = React.forwardRef<HTMLDivElement, EditableInputHSLAProp
4647
}
4748
}
4849
};
50+
let aPropsObj: false | EditableInputProps =
51+
aProps == false
52+
? false
53+
: {
54+
label: 'A',
55+
value: Math.round(hsla.a * 100) / 100,
56+
...aProps,
57+
onChange: (evn, val) => handleChange(val, 'a', evn),
58+
};
4959
return (
5060
<EditableInputRGBA
5161
ref={ref}
@@ -68,12 +78,7 @@ const EditableInputHSLA = React.forwardRef<HTMLDivElement, EditableInputHSLAProp
6878
...lProps,
6979
onChange: (evn, val) => handleChange(val, 'l', evn),
7080
}}
71-
aProps={{
72-
label: 'A',
73-
value: Math.round(hsla.a * 100) / 100,
74-
...aProps,
75-
onChange: (evn, val) => handleChange(val, 'a', evn),
76-
}}
81+
aProps={aPropsObj}
7782
className={[prefixCls, className || ''].filter(Boolean).join(' ')}
7883
{...other}
7984
/>

0 commit comments

Comments
 (0)