Skip to content

Commit 9de6f47

Browse files
committed
feat: Add showTriangle prop to Block component. #172
1 parent 2c34a9a commit 9de6f47

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

packages/color-block/src/index.tsx

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@ const CORLER_HEX = ['#D9E3F0', '#F47373', '#697689', '#37D67A', '#2CCCE4', '#555
1515

1616
export interface BlockProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'color'> {
1717
prefixCls?: string;
18+
showTriangle?: boolean;
1819
color?: string | HsvaColor;
1920
colors?: string[];
2021
onChange?: (color: ColorResult) => void;
2122
}
2223

2324
const Block = React.forwardRef<HTMLDivElement, BlockProps>((props, ref) => {
24-
const { prefixCls = 'w-color-block', className, style, color, colors = CORLER_HEX, onChange, ...other } = props;
25+
const {
26+
prefixCls = 'w-color-block',
27+
className,
28+
style,
29+
color,
30+
colors = CORLER_HEX,
31+
showTriangle = true,
32+
onChange,
33+
...other
34+
} = props;
2535
const hsva = (typeof color === 'string' && validHex(color) ? hexToHsva(color) : color) as HsvaColor;
2636
const hex = color ? hsvaToHex(hsva) : '';
2737
const handleChange = (hsv: HsvaColor) => {
@@ -44,19 +54,21 @@ const Block = React.forwardRef<HTMLDivElement, BlockProps>((props, ref) => {
4454
} as CSSProperties;
4555
return (
4656
<div ref={ref} className={[prefixCls, className].filter(Boolean).join(' ')} style={stylePointer} {...other}>
47-
<div
48-
style={{
49-
width: 0,
50-
height: 0,
51-
borderStyle: 'solid',
52-
borderWidth: '0 10px 10px',
53-
borderColor: `transparent transparent ${hex}`,
54-
position: 'absolute',
55-
top: -10,
56-
left: '50%',
57-
marginLeft: -10,
58-
}}
59-
/>
57+
{showTriangle && (
58+
<div
59+
style={{
60+
width: 0,
61+
height: 0,
62+
borderStyle: 'solid',
63+
borderWidth: '0 10px 10px',
64+
borderColor: `transparent transparent ${hex}`,
65+
position: 'absolute',
66+
top: -10,
67+
left: '50%',
68+
marginLeft: -10,
69+
}}
70+
/>
71+
)}
6072
<div
6173
title={hex}
6274
style={{

0 commit comments

Comments
 (0)