Palette

Maintainer:
Ruminat
GitHub
size
columns
disabled
multiple
import {Palette} from '@gravity-ui/uikit';

The Palette component is used to display a grid of icons, emojis, reactions, and symbols which you can select or deselect.

Disabled state

You can disable every option using the disabled property. If you want to disable only certain options, you can change the disabled property of those options (PaletteOption[]).

const options: PaletteOption[] = [
    {content: '😎', value: 'ID-cool'},
    {content: '🥴', value: 'ID-woozy'},
];
// disable the first item
<Palette options={[{ ...options[0], disabled: true }, options[1]]} disabled={true} />
// or disable all of them
<Palette options={options} disabled={true} />

Size

Use the size property to manage the Palette size. The default size is s.

const options: PaletteOption[] = [
    {content: '😎', value: 'ID-cool'},
    {content: '🥴', value: 'ID-woozy'},
];
<Palette options={options} size={"xs"} />
<Palette options={options} size={"s"} />
<Palette options={options} size={"m"} />
<Palette options={options} size={"l"} />
<Palette options={options} size={"xl"} />

Columns

You can change the number of columns in the grid by changing the columns property (the default value is 6).

const options: PaletteOption[] = [
    {content: '😎', value: 'ID-cool'},
    {content: '🥴', value: 'ID-woozy'},
];
<Palette options={options} columns={1} />

Multiple

By default, you can select and deselect multiple options. In case you only want to make a single option selectable, you can disable the multiple property.

const options: PaletteOption[] = [
    {content: '😎', value: 'ID-cool'},
    {content: '🥴', value: 'ID-woozy'},
];
<Palette options={options} multiple={false} />

Properties

PaletteProps:

NameDescriptionTypeDefault
aria-labelaria-label HTML attributestring
aria-labelledbyID of the visible Palette caption elementstring
classNameclass HTML attributestring
columnsNumber of elements per rownumber6
defaultValueSets the initial value state when the component is mountedstring[]
disabledDisables the optionsbooleanfalse
multipleEnables selecting multiple optionsbooleantrue
onBluronBlur event handler(event: React.FocusEvent<HTMLButtonElement>) => void
onFocusonFocus event handler(event: React.FocusEvent<HTMLButtonElement>) => void
onUpdateFires when the user changes the state Provides the new value as a callback's argument(value: string[]) => void
optionClassNameclass HTML attribute for the palette buttonstring
optionsList of options (palette elements)PaletteOption[][]
qadata-qa HTML attribute, used for testingstring
rowClassNameclass HTML attribute for a palette rowstring
sizeSets the size of the elementsxs s m l xlm
stylestyle HTML attributeReact.CSSProperties
valueCurrent value for the controlled usage of the componentstring[]

PaletteOption:

NameDescriptionTypeDefault
contentclass HTML attributeReactNode
disabledDisables the buttonbooleanfalse
titletitle HTML attributestring
valueControl valuestring