दस्तावेज़

टेक्स्ट का अलाइनमेंट

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

आज़माएँ

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

लाइव उदाहरण
उदाहरण का परिणाम

एडिटर में जोड़ें

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

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>
  );
}

ध्यान देने योग्य व्यवहार

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

सुविधाएँ