Skip to content

Commit

Permalink
fix: fix shadow slider issue. (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed May 12, 2023
1 parent 56518e2 commit 6b15651
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/color-shade-slider/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ import { hsvaToHslaString } from '@uiw/color-convert';
import Alpha, { AlphaProps } from '@uiw/react-color-alpha';

export interface ShadeSliderProps extends Omit<AlphaProps, 'onChange'> {
onChange?: (newShade: { v: number; s: number }) => void;
onChange?: (newShade: { v: number }) => void;
}

const ShadeSlider = React.forwardRef<HTMLDivElement, ShadeSliderProps>((props, ref) => {
const { prefixCls = 'w-color-saturation', className, onChange, direction = 'horizontal', hsva, ...other } = props;
const colorFrom = hsvaToHslaString(Object.assign({}, hsva, { a: 1, s: 100, v: 100 }));
const colorFrom = hsvaToHslaString({ ...hsva, a: 1, v: 100 });
return (
<Alpha
ref={ref}
{...other}
className={`${prefixCls} ${className || ''}`}
hsva={{ h: hsva.h, s: 100, v: hsva.v, a: 1 - hsva.v / 100 }}
hsva={{ h: hsva.h, s: hsva.s, v: hsva.v, a: 1 - hsva.v / 100 }}
direction={direction}
background={`linear-gradient(to ${direction === 'horizontal' ? 'right' : 'bottom'}, ${colorFrom}, rgb(0, 0, 0))`}
onChange={(_, interaction) => {
onChange &&
onChange({ v: direction === 'horizontal' ? 100 - interaction.left * 100 : 100 - interaction.top * 100, s: 100 });
onChange({
v: direction === 'horizontal' ? 100 - interaction.left * 100 : 100 - interaction.top * 100,
});
}}
/>
);
Expand Down

0 comments on commit 6b15651

Please sign in to comment.