# Alinhamento de texto {#text-align}

Source: [Alinhe o texto no editor React · Yurich](https://leeyujoo.com/yurich/pt-br/features/text-align/)

Package: [`yurich`](https://www.npmjs.com/package/yurich)

Package version: `0.1.2`

Alinhe parágrafos e itens de lista.

## Experimente {#try-it}

Clique em **Centralizar** com o cursor no exemplo. O HTML contém `style="text-align: center"` e o JSON tem `attrs.textAlign` igual a `"center"`.

## Adicione ao seu editor {#setup}

Ative `TextAlign` e conecte os botões de alinhamento à esquerda, centralizado, à direita e justificado.

```tsx
import {
  EditorContent, EditorProvider, TextAlign, useEditor, useIsActive,
  type EditorInstance,
} from 'yurich';

const choices = [
  ['alignLeft', "Esquerda"],
  ['alignCenter', "Centralizar"],
  ['alignRight', "Direita"],
  ['alignJustify', "Justificar"],
] as const;

function AlignButton({ editor, command, label }: {
  editor: EditorInstance;
  command: (typeof choices)[number][0];
  label: string;
}) {
  const active = useIsActive(editor, command);

  return (
    <button
      type="button"
      aria-pressed={active}
      onMouseDown={event => event.preventDefault()}
      onClick={() => editor.execute(command)}
    >
      {label}
    </button>
  );
}

export function AlignmentEditor() {
  const editor = useEditor({
    extensions: [TextAlign],
    initialValue: "<p>Agora a palavra é da barra de ferramentas.</p>",
  });

  return (
    <EditorProvider editor={editor}>
      <div role="group" aria-label="Alinhamento">
        {choices.map(([command, label]) => (
          <AlignButton key={command} editor={editor} command={command} label={label} />
        ))}
      </div>
      <EditorContent ariaLabel="Editor" />
    </EditorProvider>
  );
}
```

## Como o recurso se comporta {#behavior}

Vários blocos podem ser alinhados juntos. Habilite `TextAlign` também ao carregar o conteúdo.

[Recursos](https://leeyujoo.com/yurich/pt-br/features/)
