|
@@ -5,12 +5,12 @@ import * as convert from 'color-convert'; |
|
|
|
|
|
|
|
|
export type SwatchDerivedElement = HTMLInputElement; |
|
|
export type SwatchDerivedElement = HTMLInputElement; |
|
|
|
|
|
|
|
|
type ColorValue = ConstructorParameters<typeof Color>; |
|
|
|
|
|
|
|
|
type ColorValue = ConstructorParameters<typeof Color>[0]; |
|
|
|
|
|
|
|
|
type ColorMode = keyof typeof convert; |
|
|
type ColorMode = keyof typeof convert; |
|
|
|
|
|
|
|
|
export interface SwatchProps extends Omit<React.HTMLProps<SwatchDerivedElement>, 'color'> { |
|
|
export interface SwatchProps extends Omit<React.HTMLProps<SwatchDerivedElement>, 'color'> { |
|
|
color: ColorValue; |
|
|
|
|
|
|
|
|
color: NonNullable<ColorValue>; |
|
|
mode?: ColorMode; |
|
|
mode?: ColorMode; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -37,7 +37,7 @@ export const Swatch = React.forwardRef<SwatchDerivedElement, SwatchProps>(({ |
|
|
const { id, copyColor } = useSwatchControls(); |
|
|
const { id, copyColor } = useSwatchControls(); |
|
|
const colorInternal = React.useMemo(() => new Color(color, mode), [color, mode]); |
|
|
const colorInternal = React.useMemo(() => new Color(color, mode), [color, mode]); |
|
|
|
|
|
|
|
|
const colorValue = colorInternal.toString(); |
|
|
|
|
|
|
|
|
const colorValue = colorInternal.hex(); |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<span |
|
|
<span |
|
@@ -51,7 +51,7 @@ export const Swatch = React.forwardRef<SwatchDerivedElement, SwatchProps>(({ |
|
|
{...etcProps} |
|
|
{...etcProps} |
|
|
ref={forwardedRef} |
|
|
ref={forwardedRef} |
|
|
type="text" |
|
|
type="text" |
|
|
value={colorValue} |
|
|
|
|
|
|
|
|
value={colorInternal.toString()} |
|
|
className="sr-only select-all peer" |
|
|
className="sr-only select-all peer" |
|
|
readOnly |
|
|
readOnly |
|
|
id={id} |
|
|
id={id} |
|
@@ -79,23 +79,7 @@ export const Swatch = React.forwardRef<SwatchDerivedElement, SwatchProps>(({ |
|
|
/> |
|
|
/> |
|
|
</span> |
|
|
</span> |
|
|
<span className="tabular-nums text-xs sr-only"> |
|
|
<span className="tabular-nums text-xs sr-only"> |
|
|
{ |
|
|
|
|
|
color.map((c) => c |
|
|
|
|
|
.toString() |
|
|
|
|
|
.padStart(4, ' ') |
|
|
|
|
|
.split('') |
|
|
|
|
|
.map((cc, j) => ( |
|
|
|
|
|
<span |
|
|
|
|
|
key={`${cc}:${j}`} |
|
|
|
|
|
className={clsx({ |
|
|
|
|
|
'opacity-0': cc === ' ', |
|
|
|
|
|
})} |
|
|
|
|
|
> |
|
|
|
|
|
{j === 0 && ' '} |
|
|
|
|
|
{cc === ' ' && j > 0 ? '0' : cc} |
|
|
|
|
|
</span> |
|
|
|
|
|
))) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
{colorInternal.toString()} |
|
|
</span> |
|
|
</span> |
|
|
</label> |
|
|
</label> |
|
|
</span> |
|
|
</span> |
|
|