|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Blocks in Blazor BlockEditor Component | Syncfusion |
| 4 | +description: Checkout and learn about Blocks with Blazor BlockEditor component in Blazor WebAssembly App. |
| 5 | +platform: Blazor |
| 6 | +control: BlockEditor |
| 7 | +documentation: ug |
| 8 | +--- |
| 9 | + |
| 10 | +# Blocks in Blazor BlockEditor component |
| 11 | + |
| 12 | +The Block Editor component enables you to create block-based content editing solution using various types of blocks. The [Blocks] property allows you to define and manage the content structure of your editor. |
| 13 | + |
| 14 | +## Blocks |
| 15 | + |
| 16 | +Blocks are the fundamental building elements of the Block Editor. Each block represents a distinct content unit such as a `paragraph`, `heading`, `list`, or specialized content like `code snippets` or `images`. The Block Editor organizes content as a collection of `blocks`, allowing for better structure and formatting options. |
| 17 | + |
| 18 | +You can configure blocks with various properties such as [ID], [Type], [Content], [Children] and more to create rich, structured editor. |
| 19 | + |
| 20 | +## Block types |
| 21 | + |
| 22 | +The Block Editor supports multiple block types. Each block type offers different formatting and functionality options: |
| 23 | + |
| 24 | +| Built-in Block Types | Description | |
| 25 | +|-----------------------------------------|---------------------------------------------------| |
| 26 | +| Paragraph | Default block type for regular text content. | |
| 27 | +| Heading1 to Heading4 | Different levels of headings for document structure.| |
| 28 | +| Checklist | Interactive to-do lists with checkable items. | |
| 29 | +| BulletList | Unordered lists with bullet points. | |
| 30 | +| NumberedList | Ordered lists with sequential numbering. | |
| 31 | +| Code | Formatted code blocks with syntax highlighting. | |
| 32 | +| Quote | Styled block for quotations. | |
| 33 | +| Callout | Highlighted block for important information. | |
| 34 | +| Divider | Horizontal separator line. | |
| 35 | +| CollapsibleParagraph and CollapsibleHeading1-4 | Collapsible content blocks. | |
| 36 | +| Image | Block for displaying images. | |
| 37 | +| Template | Predefined custom templates. | |
| 38 | + |
| 39 | +## Configure indent |
| 40 | + |
| 41 | +You can specify the indentation level of a block using the [Indent] property. This property accepts a numeric value that determines how deeply a block is nested from the left margin. |
| 42 | + |
| 43 | +By default, the [Indent] property is set to `0`. |
| 44 | + |
| 45 | +```cshtml |
| 46 | +
|
| 47 | +@using Syncfusion.Blazor.BlockEditor |
| 48 | +
|
| 49 | +<div class="paste-blockeditor"> |
| 50 | + <SfBlockEditor Blocks="BlockData"></SfBlockEditor> |
| 51 | +</div> |
| 52 | +@code { |
| 53 | + private List<BlockModel> BlockData = new List<BlockModel> |
| 54 | + { |
| 55 | + new BlockModel |
| 56 | + { |
| 57 | + BlockType = BlockType.Paragraph, |
| 58 | + Content = {new ContentModel{ContentType = ContentType.Text, Content = "This is a paragraph with no indentation (indent: 0)"}}, |
| 59 | + Indent = 0 |
| 60 | + }, |
| 61 | + new BlockModel |
| 62 | + { |
| 63 | + BlockType = BlockType.Paragraph, |
| 64 | + Content = {new ContentModel{ContentType = ContentType.Text, Content = "This paragraph has one level of indentation (indent: 1)"}}, |
| 65 | + Indent = 1 |
| 66 | + }, |
| 67 | + new BlockModel |
| 68 | + { |
| 69 | + BlockType = BlockType.Paragraph, |
| 70 | + Content = {new ContentModel{ContentType = ContentType.Text, Content = "This paragraph has two levels of indentation (indent: 2)"}}, |
| 71 | + Indent = 2 |
| 72 | + }, |
| 73 | + new BlockModel |
| 74 | + { |
| 75 | + BlockType = BlockType.Paragraph, |
| 76 | + Content = {new ContentModel{ContentType = ContentType.Text, Content = "Back to no indentation"}}, |
| 77 | + Indent = 0 |
| 78 | + } |
| 79 | + }; |
| 80 | +} |
| 81 | +
|
| 82 | +``` |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | +## Configure CSS Class |
| 87 | + |
| 88 | +You can apply custom styling to individual blocks using the [CssClass] property. This property accepts a string containing one or more CSS class names. |
| 89 | + |
| 90 | +Custom CSS classes allow you to define specialized styling for specific blocks in your editor. |
| 91 | + |
| 92 | +```cshtml |
| 93 | +
|
| 94 | +@using Syncfusion.Blazor.BlockEditor |
| 95 | +
|
| 96 | +<div class="paste-blockeditor"> |
| 97 | + <SfBlockEditor Blocks="BlockData"></SfBlockEditor> |
| 98 | +</div> |
| 99 | +
|
| 100 | +@code { |
| 101 | + private List<BlockModel> BlockData = new List<BlockModel> |
| 102 | + { |
| 103 | + new BlockModel |
| 104 | + { |
| 105 | + BlockType = BlockType.Heading, |
| 106 | + Properties = new HeadingBlockSettings { Level = 1 }, |
| 107 | + Content = {new ContentModel{ContentType = ContentType.Text, Content = "Custom CSS Classes in Block Editor"}} |
| 108 | + }, |
| 109 | + new BlockModel |
| 110 | + { |
| 111 | + BlockType = BlockType.Paragraph, |
| 112 | + Content = {new ContentModel{ContentType = ContentType.Text, Content = "Default paragraph block"}} |
| 113 | + }, |
| 114 | + new BlockModel |
| 115 | + { |
| 116 | + BlockType = BlockType.Paragraph, |
| 117 | + Content = {new ContentModel{ContentType = ContentType.Text, Content = "This is an info block"}}, |
| 118 | + CssClass = "info-block" |
| 119 | + }, |
| 120 | + new BlockModel |
| 121 | + { |
| 122 | + BlockType = BlockType.Paragraph, |
| 123 | + Content = {new ContentModel{ContentType = ContentType.Text, Content = "This is a warning block"}}, |
| 124 | + CssClass = "warning-block" |
| 125 | + }, |
| 126 | + new BlockModel |
| 127 | + { |
| 128 | + BlockType = BlockType.Paragraph, |
| 129 | + Content = {new ContentModel{ContentType = ContentType.Text, Content = "This is a success block"}}, |
| 130 | + CssClass = "success-block" |
| 131 | + }, |
| 132 | + new BlockModel |
| 133 | + { |
| 134 | + BlockType = BlockType.Paragraph, |
| 135 | + Content = {new ContentModel{ContentType = ContentType.Text, Content = "This is a error block"}}, |
| 136 | + CssClass = "error-block" |
| 137 | + }, |
| 138 | + new BlockModel |
| 139 | + { |
| 140 | + BlockType = BlockType.Paragraph, |
| 141 | + Content = {new ContentModel{ContentType = ContentType.Text, Content = "This is a custom font block"}}, |
| 142 | + CssClass = "custom-font" |
| 143 | + } |
| 144 | + }; |
| 145 | +} |
| 146 | +
|
| 147 | +``` |
| 148 | + |
| 149 | + |
0 commit comments