Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/icons/dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
172 changes: 172 additions & 0 deletions src/app/app.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,175 @@
opacity: 0.7;
}
}

.theme-switch {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 6px 10px;
border-radius: 999px;
background: #f3f4f6;
color: #111827;
cursor: pointer;
user-select: none;
}

.theme-switch input {
position: absolute;
opacity: 0;
pointer-events: none;
}

.theme-switch__icon {
width: 20px;
height: 20px;
display: block;
}

.theme-switch__track {
width: 44px;
height: 24px;
padding: 2px;
border-radius: 999px;
background: #d1d5db;
display: inline-flex;
align-items: center;
transition: background 0.2s ease;
}

.theme-switch__thumb {
width: 20px;
height: 20px;
border-radius: 999px;
background: #ffffff;
box-shadow: 0 1px 3px rgb(0 0 0 / 0.2);
transition: transform 0.2s ease;
}

.theme-switch-dark {
background: #111827;
color: #f9fafb;
}

.theme-switch-dark .theme-switch__track {
background: #2563eb;
}

.theme-switch-dark .theme-switch__thumb {
transform: translateX(20px);
}

.editor-panel {
background: #ffffff;
}

.editor-panel-dark {
background: #111827;
border-color: #374151;
}

.editor-panel-dark .line-number-panel {
border-color: #374151;
background: #0f172a;
}

.line-number {
color: #9ca3af;
}

.editor-panel-dark .line-number {
color: #6b7280;
}

.editor-textarea {
background: transparent;
color: #111827;
caret-color: #111827;
}

.editor-panel-dark .editor-textarea {
color: #f9fafb;
caret-color: #f9fafb;
}

.editor-textarea::selection {
background: rgb(59 130 246 / 0.25);
}

.preview-panel {
background: #ffffff;
color: #111827;
}

.preview-panel-dark {
background: #0f172a;
color: #e5e7eb;
}

.preview-panel-dark,
.preview-panel-dark .markdown-body,
.preview-panel-dark .markdown-body p,
.preview-panel-dark .markdown-body li,
.preview-panel-dark .markdown-body blockquote,
.preview-panel-dark .markdown-body td,
.preview-panel-dark .markdown-body th {
color: #e5e7eb;
}

.preview-panel-dark .markdown-body {
background: transparent;
}

.preview-panel-dark .markdown-body pre,
.preview-panel-dark .markdown-body code {
background: rgb(148 163 184 / 0.14);
}

.preview-panel-dark .markdown-body .md-alert {
background: #111827;
border: 1px solid #1f2937;
border-left-width: 4px;
border-radius: 12px;
padding: 16px;
}

.preview-panel-dark .markdown-body .md-alert-content,
.preview-panel-dark .markdown-body .md-alert-content p {
color: #cbd5e1;
}

.preview-panel-dark .markdown-body .md-alert-note {
background: rgb(37 99 235 / 0.12);
border-color: rgb(59 130 246 / 0.35);
}

.preview-panel-dark .markdown-body .md-alert-tip {
background: rgb(22 163 74 / 0.12);
border-color: rgb(34 197 94 / 0.35);
}

.preview-panel-dark .markdown-body .md-alert-important {
background: rgb(147 51 234 / 0.12);
border-color: rgb(168 85 247 / 0.35);
}

.preview-panel-dark .markdown-body .md-alert-warning {
background: rgb(217 119 6 / 0.12);
border-color: rgb(245 158 11 / 0.35);
}

.preview-panel-dark .markdown-body .md-alert-caution {
background: rgb(220 38 38 / 0.12);
border-color: rgb(239 68 68 / 0.35);
}

.preview-panel-dark .markdown-body a {
color: #93c5fd;
}

.preview-panel-dark .markdown-body hr,
.preview-panel-dark .markdown-body table th,
.preview-panel-dark .markdown-body table td,
.preview-panel-dark .markdown-body blockquote {
border-color: #334155;
}
34 changes: 28 additions & 6 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
accept=".md,.txt,text/markdown,text/plain"
(change)="onFileUpload($event)"
/>
<button class="button ml-2" title="Upload file" type="button" (click)="fileInput.click()">
<button class="button ml-2" title="Upload MD" type="button" (click)="fileInput.click()">
<img src="icons/upload.svg" alt="Upload" class="w-6 h-6" />
</button>

Expand Down Expand Up @@ -144,6 +144,26 @@
>GitHub</a
>
</button>
<label
class="theme-switch"
[class.theme-switch-dark]="darkEditorTheme()"
title="Cambiar tema del editor y preview"
>
@if (!darkEditorTheme()) {
<img src="icons/light.svg" alt="Modo claro activo" class="theme-switch__icon" />
} @else {
<img src="icons/dark.svg" alt="Modo oscuro activo" class="theme-switch__icon" />
}
<input
type="checkbox"
[checked]="darkEditorTheme()"
(change)="toggleEditorTheme()"
aria-label="Alternar modo oscuro del editor y preview"
/>
<span class="theme-switch__track">
<span class="theme-switch__thumb"></span>
</span>
</label>
</div>
</header>
<main class="w-full h-[85%] flex px-4">
Expand All @@ -152,24 +172,25 @@
[ngClass]="{
'w-full rounded-2xl': !hideOrShowPreview(),
'w-1/2 rounded-l-2xl': hideOrShowPreview(),
'editor-panel-dark': darkEditorTheme(),
}"
class="h-full bg-white flex border-r border-[#cccc] overflow-hidden"
class="editor-panel h-full flex border-r border-[#cccc] overflow-hidden"
>
<div
#lineNumber
id="lineNumber"
class="w-[5%] h-full border-r border-[#cccc] flex flex-col gap-y-1 items-center pt-5 overflow-y-hidden"
class="line-number-panel w-[5%] h-full border-r border-[#cccc] flex flex-col gap-y-1 items-center pt-5 overflow-y-hidden"
>
@for (lineNumber of lineNumbers(); track lineNumber) {
<span class="w-full text-center text-sm text-gray-400 select-none">
<span class="line-number w-full text-center text-sm select-none">
{{ lineNumber }}
</span>
}
</div>
<textarea
#editorTextarea
data-testid="editor-textarea"
class="w-[95%] h-full p-5 text-left resize-none outline-none border-none overflow-y-auto"
class="editor-textarea w-[95%] h-full p-5 text-left resize-none outline-none border-none overflow-y-auto"
(scroll)="syncScroll()"
(input)="onInput($event)"
[value]="inputValue()"
Expand All @@ -183,8 +204,9 @@
[ngClass]="{
'w-full rounded-2xl': fullOrMinPreview(),
'w-1/2 rounded-r-2xl': !fullOrMinPreview(),
'preview-panel-dark': darkEditorTheme(),
}"
class="w-1/2 h-full bg-white p-5 overflow-y-auto markdown-body"
class="preview-panel w-1/2 h-full p-5 overflow-y-auto markdown-body"
>
<div #previewRef class="markdown-body">
<div [innerHTML]="previewHtml()"></div>
Expand Down
5 changes: 5 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class AppComponent {
selectedText = signal<string>('');
hideOrShowPreview = signal<boolean>(true);
fullOrMinPreview = signal<boolean>(false);
darkEditorTheme = signal<boolean>(false);
showModal = signal<boolean>(false);
typeOfModal = signal<string>('');
searchQuery = signal<string>('');
Expand Down Expand Up @@ -307,6 +308,10 @@ export class AppComponent {
this.fullOrMinPreview.set(!this.fullOrMinPreview());
}

toggleEditorTheme() {
this.darkEditorTheme.set(!this.darkEditorTheme());
}

onHeadingChange(event: Event) {
const select = event.target as HTMLSelectElement;
const value = select.value;
Expand Down
Loading