|
| 1 | +# Style Menu |
| 2 | + |
| 3 | +A Style Menu for the Rich Text Editor (RTE) is configurable extension to add a cascading menu to the toolbar, to apply text styles and formatting. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +{% hint style="info" %} |
| 8 | +Please note that any custom stylesheets associated with the Rich Text Editor will not auto generate a style menu in the toolbar. |
| 9 | +{% endhint %} |
| 10 | + |
| 11 | +### Creating a Style Menu |
| 12 | + |
| 13 | +In this article you can find an example of how to setup an RTE Style Menu using the package manifest file. |
| 14 | + |
| 15 | +{% code title="umbraco-package.json" %} |
| 16 | +```json |
| 17 | +{ |
| 18 | + "name": "Name of your package", |
| 19 | + "alias": "My.Package", |
| 20 | + "extensions": [ |
| 21 | + { |
| 22 | + "type": "tiptapToolbarExtension", |
| 23 | + "kind": "styleMenu", |
| 24 | + "alias": "MyCustom.Tiptap.StyleMenu", |
| 25 | + "name": "My Custom Tiptap Style Menu", |
| 26 | + "meta": { |
| 27 | + "alias": "myCustomStyleMenu", |
| 28 | + "icon": "icon-palette", |
| 29 | + "label": "My custom styles" |
| 30 | + }, |
| 31 | + "items": [ |
| 32 | + { |
| 33 | + "label": "Headings", |
| 34 | + "items": [ |
| 35 | + { |
| 36 | + "label": "Heading 2", |
| 37 | + "data": { "tag": "h2" }, |
| 38 | + "appearance": { "icon": "icon-heading-2" } |
| 39 | + }, |
| 40 | + { |
| 41 | + "label": "Heading 3", |
| 42 | + "data": { "tag": "h3" }, |
| 43 | + "appearance": { "style": "font-size: large;" } |
| 44 | + }, |
| 45 | + { |
| 46 | + "label": "Heading 4", |
| 47 | + "data": { "tag": "h4" } |
| 48 | + } |
| 49 | + ] |
| 50 | + }, |
| 51 | + { |
| 52 | + "label": "Attributes", |
| 53 | + "items": [ |
| 54 | + { |
| 55 | + "label": "Classes", |
| 56 | + "data": { "class": "foo" } |
| 57 | + }, |
| 58 | + { |
| 59 | + "label": "IDs", |
| 60 | + "data": { "id": "bar" } |
| 61 | + }, |
| 62 | + { |
| 63 | + "label": "Mixed", |
| 64 | + "data": { "tag": "span", "class": "foo", "id": "bar" } |
| 65 | + } |
| 66 | + ] |
| 67 | + } |
| 68 | + ] |
| 69 | + } |
| 70 | + ] |
| 71 | +} |
| 72 | +``` |
| 73 | +{% endcode %} |
| 74 | + |
| 75 | + |
| 76 | +The "`items`" property defines the structure of the style menu. Each menu item has the following options. |
| 77 | + |
| 78 | +- `label`: _(required)_ The label of the menu item. This supports localization keys. |
| 79 | +- `appearance`: This defines the appearance of the menu item. The value has 2 optional properties: |
| 80 | + - `icon`: To prefix an icon to the menu item. |
| 81 | + - `style`: To apply CSS rules to the menu item. |
| 82 | +- `data`: To configure the function of the style menu item. The value has 3 optional properties: |
| 83 | + - `tag`: A supported HTML tag name, _(see below)_, this will be applied to the selected text. |
| 84 | + - `class`: Applies a class attribute with the defined class name to the containing tag of the selected text. |
| 85 | + - `id`: Applies an ID attribute with the defined ID value to the containing tag of the selected text. |
| 86 | +- `separatorAfter`: When `true`, it will add a line separator after the menu item. |
| 87 | +- `items`: To enable a cascading menu, an array of nested menu items may be added. |
| 88 | + |
| 89 | + |
| 90 | +Once configured, all custom style menus will appear in the Rich Text Editor toolbar options, as described in the [RTE Configuration](configuration.md) article. |
| 91 | + |
| 92 | + |
| 93 | +#### Supported HTML tags |
| 94 | + |
| 95 | +Since the Tiptap has a strict RTE schema, only supported HTML tags can be used in the style menu, _(arbitrary markup will be excluded)._ The following HTML tag names are supported: `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `p`, `blockquote`, `code`, `codeBlock`, `div`, `em` (italic), `ol`, `strong` (bold), `s` (strike-through), `span`, `u` (underline) and `ul`. |
0 commit comments