@uiw/react-color-block
Version:
Color Block Picker
79 lines (61 loc) • 2.41 kB
Markdown
React Color Block
===
[](https://jaywcjlove.github.io/#/sponsor)
[](https://bundlephobia.com/package/@uiw/react-color-block) [](https://www.npmjs.com/package/@uiw/react-color-block) [](https://uiwjs.github.io/npm-unpkg/#/pkg/@uiw/react-color-block/file/README.md)
Block is a subcomponent of [**`@react-color`**](https://uiwjs.github.io/react-color).
<!--rehype:ignore:start-->
[](https://uiwjs.github.io/react-color/#/block)
<!--rehype:ignore:end-->
## Install
```bash
npm i @uiw/react-color-block
```
## Usage
```jsx mdx:preview
import React, { useState } from 'react';
import Block from '@uiw/react-color-block';
export default function Demo() {
const [hex, setHex] = useState("#fff");
return (
<>
<div style={{ display: "flex", gap: 10 }}>
<Block
color={hex}
onChange={(color) => setHex(color.hex)}
/>
<Block
color={hex}
showTriangle={false}
onChange={(color) => setHex(color.hex)}
/>
</div>
<div style={{ background: hex, marginTop: 30, padding: 10 }}>
{hex}
</div>
</>
);
}
```
## Props
```ts
import React from 'react';
import { HsvaColor, ColorResult } from '@uiw/color-convert';
export interface BlockProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'color'> {
prefixCls?: string;
showTriangle?: boolean;
color?: string | HsvaColor;
colors?: string[];
onChange?: (color: ColorResult) => void;
}
declare const Block: React.ForwardRefExoticComponent<BlockProps & React.RefAttributes<HTMLDivElement>>;
export default Block;
```
<!--footer-dividing-->
## Contributors
As always, thanks to our amazing contributors!
<a href="https://github.com/uiwjs/react-color/graphs/contributors">
<img src="https://uiwjs.github.io/react-color/coverage/CONTRIBUTORS.svg" />
</a>
Made with [contributors](https://github.com/jaywcjlove/github-action-contributors).
## License
Licensed under the MIT License.