Skip to content

Commit ab43c3a

Browse files
authored
RichText README updated
RichText README updated
1 parent 18d9698 commit ab43c3a

File tree

1 file changed

+120
-2
lines changed

1 file changed

+120
-2
lines changed

README.md

Lines changed: 120 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,126 @@
11
# Angular RichText (Without Packages)
22

33
A functional RichText Component made for Angularjs, no installation needed to use it! <br>
4-
Just download the demo to see how it works
54

65
<br>
76

8-
<img src="./src/assets/rich-text.png">
7+
<img src="./src/assets/rich-text.png">
8+
9+
<br>
10+
11+
# How to use?
12+
13+
## HTML
14+
15+
```html
16+
<!-- RichText code -->
17+
<div class="rich">
18+
<input type="hidden" name="myDoc">
19+
<!-- Controls -->
20+
<div id="toolBar2">
21+
<button type="button" class="intLink controls" (click)="formatDoc('bold');"><img class="controls-img" src="../assets/bold.svg" alt=""> </button>
22+
<button type="button" class="intLink controls" (click)="formatDoc('italic');"><img class="controls-img" src="../assets/italic.svg" alt=""> </button>
23+
<button type="button" class="intLink controls" (click)="formatDoc('underline');"><img class="controls-img" src="../assets/underline.svg" alt=""> </button>
24+
<button type="button" class="intLink controls" (click)="formatDoc('justifyleft');"><img class="controls-img" src="../assets/text-align-left.svg" alt=""></button>
25+
<button type="button" class="intLink controls" (click)="formatDoc('justifycenter');"><img class="controls-img" src="../assets/text-align-center.svg" alt=""> </button>
26+
<button type="button" class="intLink controls" (click)="formatDoc('justifyright');"><img class="controls-img" src="../assets/text-align-right.svg" alt=""> </button>
27+
</div>
28+
<!-- /Controls -->
29+
30+
<!-- Rich text -->
31+
<input class="hidden" formControlName="main_description" type="text"> <!-- The input is hidden because we can't assign formControlName to a div, so we're going to copy the div's HTML to assign it to the input -->
32+
<div #richText class="full" id="textBox" contenteditable="true"></div>
33+
<!-- /Rich text -->
34+
</div>
35+
<!-- /RichText code -->
36+
```
37+
## TypeScript
38+
39+
```javascript
40+
import { Component, ElementRef, ViewChild } from '@angular/core';
41+
42+
@Component({
43+
selector: 'app-root',
44+
templateUrl: './app.component.html',
45+
styleUrls: ['./app.component.scss']
46+
})
47+
export class AppComponent {
48+
title = 'Angular_RichText_Demo';
49+
50+
//Get div element to pass content to input
51+
@ViewChild('richText') richText!: ElementRef;
52+
53+
//Text formatting function
54+
//Initializing variable
55+
oDoc:any;
56+
formatDoc(cmd:any) {
57+
this.oDoc = document.getElementById("textBox");
58+
document.execCommand(cmd); this.oDoc?.focus();
59+
}
60+
61+
save(){
62+
// Open the console to see the output!
63+
//You can set this value on an input to send the data in angular forms
64+
console.log(this.richText?.nativeElement.innerHTML);
65+
}
66+
67+
68+
}
69+
```
70+
71+
## CSS
72+
```css
73+
// Angular RichText styles
74+
.intLink { cursor: pointer; border: 0; background-color: #ffffff;}
75+
#toolBar1 select { font-size:10px; }
76+
77+
#textBox {
78+
width: auto;
79+
height: 250px;
80+
border-bottom: 5px;
81+
border-top: 1px #dad6d6 solid;
82+
padding: 12px;
83+
overflow: scroll;
84+
}
85+
#textBox #sourceText {
86+
padding: 0;
87+
margin: 0;
88+
min-width: 498px;
89+
min-height: 200px;
90+
}
91+
92+
.controls{
93+
margin-right: 8px;
94+
transition: ease-in 0.2s;
95+
padding-top: 5px;
96+
border-radius: 5px;
97+
}
98+
.controls:hover{background-color: #cecbcb;}
99+
100+
.controls-img{
101+
width: 20px;
102+
}
103+
104+
.rich{
105+
background-color: white;
106+
padding-top: 10px;
107+
border-radius: 5px;
108+
box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;
109+
border: 1px #dad6d6 solid;
110+
}
111+
112+
#toolBar2{
113+
padding-left: 6px;
114+
padding-bottom: 9px;
115+
}
116+
117+
.hidden{
118+
display: none;
119+
}
120+
121+
//This class hides the scrollbar space.
122+
::-webkit-scrollbar {
123+
display: none;
124+
}
125+
126+
```

0 commit comments

Comments
 (0)