Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 1x 3x 3x 3x 2x 1x | import React from 'react'; 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 }) => void; } const ShadeSlider = React.forwardRef<HTMLDivElement, ShadeSliderProps>((props, ref) => { const { prefixCls = 'w-color-saturation', className, onChange, direction = 'horizontal', hsva, ...other } = props; const colorFrom = hsvaToHslaString({ ...hsva, a: 1, v: 100 }); return ( <Alpha ref={ref} {...other} className={`${prefixCls} ${className || ''}`} 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, }); }} /> ); }); ShadeSlider.displayName = 'ShadeSlider'; export default ShadeSlider; |