# टेक्स्ट का अलाइनमेंट {#text-align}

Source: [React एडिटर में टेक्स्ट का अलाइनमेंट बदलें · Yurich](https://leeyujoo.com/yurich/hi/features/text-align/)

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

Package version: `0.1.2`

पैराग्राफ़ और सूची का अलाइनमेंट बदलें।

## आज़माएँ {#try-it}

पैराग्राफ़ में **बीच में** दबाएँ। HTML में `style="text-align: center"` और JSON में `attrs.textAlign` की वैल्यू `"center"` होती है।

## एडिटर में जोड़ें {#setup}

`TextAlign` चालू करें और बाएँ, बीच, दाएँ और जस्टिफ़ाई करने के बटन जोड़ें।

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

const choices = [
  ['alignLeft', "बाएँ"],
  ['alignCenter', "बीच में"],
  ['alignRight', "दाएँ"],
  ['alignJustify', "जस्टिफ़ाई"],
] 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>अब टूलबार की बारी है।</p>",
  });

  return (
    <EditorProvider editor={editor}>
      <div role="group" aria-label="टेक्स्ट अलाइनमेंट">
        {choices.map(([command, label]) => (
          <AlignButton key={command} editor={editor} command={command} label={label} />
        ))}
      </div>
      <EditorContent ariaLabel="एडिटर" />
    </EditorProvider>
  );
}
```

## ध्यान देने योग्य व्यवहार {#behavior}

कमांड सभी चुने हुए ब्लॉक पर चलता है। सेव किया HTML लोड करते समय भी `TextAlign` चालू रखें।

[सुविधाएँ](https://leeyujoo.com/yurich/hi/features/)
