-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #807 from geonetwork/ME/add-rich-text-input-component
Metadata Editor: add rich text input component
- Loading branch information
Showing
21 changed files
with
319 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
libs/ui/elements/src/lib/markdown-editor/markdown-editor.component.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.icon-small { | ||
font-size: 16px; | ||
height: 16px; | ||
width: 16px; | ||
} |
39 changes: 39 additions & 0 deletions
39
libs/ui/elements/src/lib/markdown-editor/markdown-editor.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<div class="h-full flex flex-col"> | ||
<div class="flex-none w-full flex flex-row items-center"> | ||
<p class="flex-none font-bold">{{ label }}</p> | ||
<div class="flex-1 flex justify-end items-center"> | ||
<gn-ui-button | ||
[extraClass]="getButtonExtraClass()" | ||
(buttonClick)="togglePreview()" | ||
> | ||
<span class="material-symbols-outlined mr-1 icon-small">{{ | ||
preview ? 'visibility' : 'visibility_off' | ||
}}</span> | ||
{{ preview ? 'WYSIWYG' : 'Markdown' }} | ||
</gn-ui-button> | ||
<span | ||
class="material-symbols-outlined m-2 icon-small" | ||
[matTooltip]="tooltip" | ||
matTooltipPosition="above" | ||
> | ||
help | ||
</span> | ||
</div> | ||
</div> | ||
<p class="flex-none mb-2 font-medium text-sm text-gray-900"> | ||
{{ helperText }} | ||
</p> | ||
<div class="flex-1" [hidden]="preview"> | ||
<gn-ui-text-area | ||
[placeholder]="placeholder" | ||
[value]="textContent" | ||
(valueChange)="textContentChangedHandler($event)" | ||
></gn-ui-text-area> | ||
</div> | ||
<div | ||
class="flex-1 border border-gray-800 rounded overflow-y-scroll" | ||
[hidden]="!preview" | ||
> | ||
<gn-ui-markdown-parser [textContent]="textContent"></gn-ui-markdown-parser> | ||
</div> | ||
</div> |
20 changes: 20 additions & 0 deletions
20
libs/ui/elements/src/lib/markdown-editor/markdown-editor.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing' | ||
import { MarkdownEditorComponent } from './markdown-editor.component' | ||
|
||
describe('MarkdownEditorComponent', () => { | ||
let component: MarkdownEditorComponent | ||
let fixture: ComponentFixture<MarkdownEditorComponent> | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [MarkdownEditorComponent], | ||
}).compileComponents() | ||
|
||
fixture = TestBed.createComponent(MarkdownEditorComponent) | ||
component = fixture.componentInstance | ||
}) | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy() | ||
}) | ||
}) |
159 changes: 159 additions & 0 deletions
159
libs/ui/elements/src/lib/markdown-editor/markdown-editor.component.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import { Meta, moduleMetadata, StoryObj } from '@storybook/angular' | ||
import { MarkdownEditorComponent } from './markdown-editor.component' | ||
|
||
export default { | ||
title: 'Elements/MarkdownEditorComponent', | ||
component: MarkdownEditorComponent, | ||
decorators: [ | ||
moduleMetadata({ | ||
imports: [MarkdownEditorComponent], | ||
}), | ||
], | ||
} as Meta<MarkdownEditorComponent> | ||
|
||
export const Primary: StoryObj<MarkdownEditorComponent> = { | ||
args: { | ||
label: 'Some label', | ||
tooltip: 'Some tooltip', | ||
helperText: 'Some helper text', | ||
placeholder: 'Some placeholder', | ||
textContent: ` | ||
# SUPPORTED MARKDOWN CONTENT | ||
## 1) Headings | ||
+ # h1 Heading | ||
+ ## h2 Heading | ||
+ ### h3 Heading | ||
+ #### h4 Heading | ||
+ ##### h5 Heading | ||
+ ###### h6 Heading | ||
## 2) Horizontal Rules | ||
+ ___ | ||
+ --- | ||
+ *** | ||
## 3) Emphasis | ||
+ **This is bold text** | ||
+ __This is bold text__ | ||
+ *This is italic text* | ||
+ _This is italic text_ | ||
+ ~~Strikethrough~~ | ||
## 3) Blockquotes | ||
> Blockquotes can also be nested... | ||
>> ...by using additional greater-than signs right next to each other... | ||
> > > ...or with spaces between arrows. | ||
## 4) Lists | ||
**Unordered** | ||
+ Create a list by starting a line with +, -, or * | ||
+ Sub-lists are made by indenting 2 spaces: | ||
- Marker character change forces new list start: | ||
* Ac tristique libero volutpat at | ||
+ Facilisis in pretium nisl aliquet | ||
- Nulla volutpat aliquam velit | ||
+ List continue here | ||
**Ordered** | ||
1. Lorem ipsum dolor sit amet | ||
2. Consectetur adipiscing elit | ||
3. Integer molestie lorem at massa | ||
1. You can use sequential numbers... | ||
1. ...or keep all the numbers as 1. | ||
**Start numbering with offset:** | ||
57. foo | ||
1. bar | ||
## 5) Code | ||
**Inline code** | ||
(no example) | ||
**Indented code** | ||
// Some comments | ||
line 1 of code | ||
line 2 of code | ||
line 3 of code | ||
**Block code "fences"** | ||
(no example) | ||
## 6) Tables | ||
**Left aligned columns** | ||
| Option | Description | | ||
| ------ | ----------- | | ||
| data | path to data files to supply the data that will be passed into templates. | | ||
| engine | engine to be used for processing templates. Handlebars is the default. | | ||
| ext | extension to be used for dest files. | | ||
**Right aligned columns** | ||
| Option | Description | | ||
| ------:| -----------:| | ||
| data | path to data files to supply the data that will be passed into templates. | | ||
| engine | engine to be used for processing templates. Handlebars is the default. | | ||
| ext | extension to be used for dest files. | | ||
## 7) Links | ||
[link text](https://github.com/geonetwork/geonetwork-ui) | ||
[link with title](https://github.com/geonetwork/geonetwork-ui "title text!") | ||
## 8) Images | ||
**With and without title** | ||
`, | ||
}, | ||
argTypes: { | ||
textContent: { | ||
control: 'text', | ||
}, | ||
}, | ||
render: (args) => ({ | ||
props: args, | ||
template: ` | ||
<div style="width: 600px;height: 400px;"> | ||
<gn-ui-markdown-editor | ||
[label]="label" | ||
[tooltip]="tooltip" | ||
[helperText]="helperText" | ||
[placeholder]="placeholder" | ||
[textContent]="textContent" | ||
></gn-ui-markdown-editor> | ||
</div>`, | ||
}), | ||
} |
58 changes: 58 additions & 0 deletions
58
libs/ui/elements/src/lib/markdown-editor/markdown-editor.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { CommonModule } from '@angular/common' | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
EventEmitter, | ||
Input, | ||
Output, | ||
} from '@angular/core' | ||
import { FormsModule } from '@angular/forms' | ||
import { MarkdownParserComponent } from '../markdown-parser/markdown-parser.component' | ||
import { TranslateModule } from '@ngx-translate/core' | ||
import { ButtonComponent, TextAreaComponent } from '@geonetwork-ui/ui/inputs' | ||
import { MatIconModule } from '@angular/material/icon' | ||
import { MatTooltipModule } from '@angular/material/tooltip' | ||
|
||
@Component({ | ||
selector: 'gn-ui-markdown-editor', | ||
templateUrl: './markdown-editor.component.html', | ||
styleUrls: ['./markdown-editor.component.css'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
standalone: true, | ||
imports: [ | ||
CommonModule, | ||
FormsModule, | ||
MatIconModule, | ||
MatTooltipModule, | ||
ButtonComponent, | ||
TextAreaComponent, | ||
MarkdownParserComponent, | ||
TranslateModule, | ||
], | ||
}) | ||
export class MarkdownEditorComponent { | ||
@Input() label: string | ||
@Input() tooltip?: string | ||
@Input() helperText?: string | ||
@Input() placeholder: string | ||
@Input() textContent: string | ||
@Output() textContentChanged: EventEmitter<string> = | ||
new EventEmitter<string>() | ||
|
||
preview = false | ||
|
||
getButtonExtraClass() { | ||
return `${ | ||
this.preview ? 'text-gray-200 bg-gray-900' : 'text-gray-900 bg-gray-200' | ||
} rounded-[1.25rem] p-[0.375rem] text-xs font-medium w-24` | ||
} | ||
|
||
togglePreview() { | ||
this.preview = !this.preview | ||
} | ||
|
||
textContentChangedHandler(textContent: string) { | ||
this.textContent = textContent | ||
this.textContentChanged.emit(this.textContent) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.