|
9 | 9 | [](https://github.com/Raiper34/ngx-simple-text-editor)
|
10 | 10 |
|
11 | 11 |
|
12 |
| - |
| 12 | + |
13 | 13 | # Ngx Simple Text editor
|
14 | 14 | Ngx Simple Text editor or ST editor is a simple native text editor component for Angular 9+.
|
15 | 15 | The key features of this editor are simplicity, cross-browser compatibility, and extensibility.
|
16 | 16 |
|
17 |
| - |
| 17 | + |
18 | 18 |
|
19 | 19 |
|
20 | 20 | ### Content
|
21 | 21 | - [🔗 Compatibility](#-compatibility)
|
22 | 22 | - [🚀 Instalation](#-instalation)
|
23 | 23 | - [💻 Usage](#-usage)
|
24 |
| - - [Custom buttons](#custom-buttons) |
25 |
| -- [✨ Demo](#-demo) |
| 24 | +- [📚 Documentation and demos](#-documentation-and-demos) |
26 | 25 | - [📖 License](#-license)
|
27 | 26 |
|
28 | 27 |
|
@@ -88,86 +87,9 @@ export class AppComponent {
|
88 | 87 | };
|
89 | 88 | }
|
90 | 89 | ```
|
91 |
| -You can pass all predefined buttons with predefined order, or you can use only buttons you want with order as you want. |
92 |
| -```typescript |
93 |
| -import {EditorConfig, UNDO_BUTTON, SEPARATOR, BOLD_BUTTON, ITALIC_BUTTON} from 'ngx-simple-text-editor'; |
94 |
| -... |
95 |
| -config: EditorConfig = { |
96 |
| - buttons: [UNDO_BUTTON, SEPARATOR, BOLD_BUTTON, ITALIC_BUTTON], |
97 |
| - }; |
98 |
| -... |
99 |
| -``` |
100 |
| - |
101 |
| -### Custom buttons |
102 |
| -Defining custom buttons is really simple, you just need to create a new constant and pass it into the `buttons` property of the editor config. |
103 |
| -The constant needs to consist of at least `type`, which is basically a type of button that will be rendered on the UI and `command`, which is an action, that will be performed. |
104 |
| -You can use a predefined ExecCommand enum for command definition. |
105 |
| -If you want to read more about exec commands, you can read [here](https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand). |
106 |
| -Other required properties are derived from the given type and interfaces for all button types can be found [here](https://github.com/Raiper34/ngx-simple-text-editor/blob/main/projects/ngx-simple-text-editor/src/lib/models/button.ts). |
107 |
| - |
108 |
| - |
109 |
| -For example, we can create our own custom button that adds preformatted and predefined strings into the editor. |
110 |
| -We need to define a new button type of `EditorDropdown` because we want to pick one string from many and add it to the editor config |
111 |
| -```typescript |
112 |
| -import {EditorConfig, ExecCommand, Separator, ST_BUTTONS} from 'ngx-simple-text-editor'; |
113 |
| - |
114 |
| -export const CUSTOM: EditorDropdown = { |
115 |
| - type: ToolbarItemType.Dropdown, label: 'Custom', title: 'test custom', items: [ |
116 |
| - {command: ExecCommand.insertHTML, value: '<b>This is bold<b>', label: 'Custom bold text'}, |
117 |
| - {command: ExecCommand.italic, value: null, label: 'Make Italic'}, |
118 |
| - ] |
119 |
| -}; |
120 |
| - |
121 |
| -... |
122 |
| -config: EditorConfig = { |
123 |
| - buttons: [...ST_BUTTONS, Separator, CUSTOM], |
124 |
| - }; |
125 |
| -... |
126 |
| -``` |
127 |
| -Or we can create a button that prompts the user to write something and that string can be transformed and added into html. |
128 |
| -Let's say, we want to input a button, where the user writes some string and we want to put it into the editor always bold |
129 |
| -```ts |
130 |
| -export const CUSTOM_INPUT: EditorInput = |
131 |
| - { |
132 |
| - type: ToolbarItemType.Input, |
133 |
| - command: ExecCommand.insertHTML, |
134 |
| - icon: 'fas fa-font', |
135 |
| - text: 'Create bold text', |
136 |
| - title: 'create bold text', |
137 |
| - transform: (val: string) => `<b>${val}</b>` |
138 |
| - }; |
139 |
| -``` |
140 |
| - |
141 |
| -The example of various default button types that have already been created in the editor and are the part of default config (full list [here](https://github.com/Raiper34/ngx-simple-text-editor/blob/main/projects/ngx-simple-text-editor/src/lib/constants/editor-buttons.ts)): |
142 |
| -```ts |
143 |
| -export const UNDO_BUTTON: EditorButton = {type: ToolbarItemType.Button, command: ExecCommand.undo, icon: 'fas fa-undo', title: 'undo'}; |
144 |
| -export const FORE_COLOR: EditorColor = |
145 |
| - {type: ToolbarItemType.Color, command: ExecCommand.foreColor, icon: 'fas fa-palette', title: 'font color'}; |
146 |
| -export const CUSTOM: EditorDropdown = { |
147 |
| - type: ToolbarItemType.Dropdown, label: 'Custom', title: 'test custom', items: [ |
148 |
| - {command: ExecCommand.insertHTML, value: '<b>This is bold<b>', label: 'Custom bold text'}, |
149 |
| - {command: ExecCommand.italic, value: null, label: 'Make Italic'}, |
150 |
| - ] |
151 |
| -}; |
152 |
| -export const LINK_INPUT: EditorInput = |
153 |
| - {type: ToolbarItemType.Input, command: ExecCommand.createLink, icon: 'fas fa-link', text: 'Create link', title: 'create link', label: 'Create link'}; |
154 |
| -export const UNLINK_BUTTON: EditorButton = {type: ToolbarItemType.Button, command: ExecCommand.unlink, icon: 'fas fa-unlink', title: 'unlink'}; |
155 |
| -export const FONT_SIZE_SELECT: EditorSelect = { |
156 |
| - type: ToolbarItemType.Select, command: ExecCommand.fontSize, title: 'font size', items: [ |
157 |
| - {value: 1, label: '1'}, |
158 |
| - {value: 2, label: '2'}, |
159 |
| - {value: 3, label: '3'}, |
160 |
| - {value: 4, label: '4'}, |
161 |
| - {value: 5, label: '5'}, |
162 |
| - {value: 6, label: '6'}, |
163 |
| - {value: 7, label: '7'}, |
164 |
| - ] |
165 |
| -}; |
166 |
| -``` |
167 | 90 |
|
168 |
| -## ✨ Demo |
169 |
| -[Online demo](https://ngx-simple-text-editor.netlify.app/) |
170 |
| -or Stackblitz coming soon. |
| 91 | +## 📚 Documentation and demos |
| 92 | +[Online documentation and demos](https://ngx-simple-text-editor.netlify.app/) |
171 | 93 |
|
172 | 94 | ## 📖 License
|
173 | 95 | MIT
|
0 commit comments