Skip to content

Commit

Permalink
Read more button in topic form
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmartyrk committed Nov 8, 2023
1 parent c222128 commit 41def32
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 39 deletions.
40 changes: 21 additions & 19 deletions src/app/topic/components/topic-form/topic-form.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -453,26 +453,28 @@ <h3 translate="VIEWS.TOPIC_CREATE.SETTINGS_HEADING_ADD_TO_GROUP"></h3>
<div class="topic_image">
<img *ngIf="topic.imageUrl" [src]="topic.imageUrl">
</div>
<div class="topic_title">
<div class="main_heading" [innerHTML]="topic.title"></div>
</div>
<div class="topic_intro" [innerHTML]="topic.intro">
</div>
<div class="topic_content">
<div [innerHTML]="topic.description"></div>
<div class="button_wrap"><button class="btn_medium_secondary" (click)="readMore=!readMore">
<svg *ngIf="!readMore" width="24" height="24" viewBox="0 0 24 24" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path d="M17 10L12 15L7 10" stroke="#1168A8" stroke-width="2" stroke-linecap="round" />
</svg>
<svg *ngIf="readMore" width="24" height="24" viewBox="0 0 24 24" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path d="M17 15L12 10L7 15" stroke="#2C3B47" stroke-width="2" stroke-linecap="round" />
</svg>
<span *ngIf="!readMore" translate="VIEWS.TOPIC_CREATE.BTN_READ_MORE"></span>
<span *ngIf="readMore" translate="VIEWS.TOPIC_CREATE.BTN_READ_LESS"></span>
</button>
<div id="topic_text_wrap" #topicText [@readMore]="readMore? 'open' : 'closed'">
<div class="topic_title">
<div class="main_heading" [innerHTML]="topic.title"></div>
</div>
<div class="topic_intro" [innerHTML]="topic.intro">
</div>
<div class="topic_content" [innerHTML]="topic.description">
</div>
</div>
<div class="button_wrap" *ngIf="readMoreButton">
<button class="btn_medium_secondary" (click)="readMore=!readMore">
<svg *ngIf="!readMore" width="24" height="24" viewBox="0 0 24 24" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path d="M17 10L12 15L7 10" stroke="#1168A8" stroke-width="2" stroke-linecap="round" />
</svg>
<svg *ngIf="readMore" width="24" height="24" viewBox="0 0 24 24" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path d="M17 15L12 10L7 15" stroke="#2C3B47" stroke-width="2" stroke-linecap="round" />
</svg>
<span *ngIf="!readMore" translate="VIEWS.TOPIC_CREATE.BTN_READ_MORE"></span>
<span *ngIf="readMore" translate="VIEWS.TOPIC_CREATE.BTN_READ_LESS"></span>
</button>
</div>
</div>
</ng-container>
Expand Down
41 changes: 28 additions & 13 deletions src/app/topic/components/topic-form/topic-form.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
height: max-content;
}


#help_wrap {
flex-direction: column;
gap: 16px;
Expand Down Expand Up @@ -174,10 +173,16 @@
width: 100%;
}

#topic_text_wrap {
display: flex;
flex-direction: column;
}

.topic_image {
border-top-left-radius: 16px;
border-top-right-radius: 16px;
display: flex;
min-height: 60px;
max-height: 324px;
width: 100%;
overflow: hidden;
Expand Down Expand Up @@ -205,22 +210,32 @@
display: flex;
flex-direction: column;
padding: 8px 16px;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
position: relative;
font-weight: 400;
font-size: 15px;
line-height: 30px;
margin-bottom: 36px;
}

.button_wrap {
display: flex;
.button_wrap {
position: relative;
display: flex;
width: 100%;
justify-content: center;
z-index: 3;
button {
margin-top: -21px;
position: absolute;
bottom: -21px;
align-self: center;
justify-self: center;
button {
path {
fill: none;
}
&:hover {
path {
fill: none;
}
&:hover {
path {
stroke: var(--color-surfaces);
}
stroke: var(--color-surfaces);
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/app/topic/components/topic-form/topic-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ import { InterruptDialogComponent } from 'src/app/shared/components/interrupt-di
templateUrl: './topic-form.component.html',
styleUrls: ['./topic-form.component.scss'],
animations: [
trigger('readMore', [
state('open', style({
maxHeight: '100%',
transition: '0.1s max-height'
})),
state('closed', style({
maxHeight: '320px',
transition: '0.1s max-height'
}))
]),
trigger('openClose', [
// ...
state('open', style({
Expand Down Expand Up @@ -50,6 +60,16 @@ import { InterruptDialogComponent } from 'src/app/shared/components/interrupt-di
])]
})
export class TopicFormComponent {
topicText?: ElementRef
readMoreButton = false;
@ViewChild('topicText') set content(content: ElementRef) {
if (content) { // initially setter gets called with undefined
this.topicText = content;
if (content.nativeElement.offsetHeight > 200) {
this.readMoreButton = true;
}
}
}
@ViewChild('imageUpload') fileInput?: ElementRef;
@Input() topic!: Topic;
topicUrl = <SafeResourceUrl>'';
Expand Down Expand Up @@ -123,6 +143,8 @@ export class TopicFormComponent {
const tabIndex = this.tabs.indexOf(tab);
if (tabIndex > -1 && tabIndex < 3) {
this.selectTab(this.tabs[tabIndex + 1]);
} else {
this.TopicService.reloadTopic();
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/app/topic/topic.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ <h3 [innerHTML]="'VIEWS.TOPICS_TOPICID.HEADING_BACK_TO_MY_TOPICS'| translate"></
<div class="main_heading" [innerHTML]="topic.title"></div>
</div>
<div class="topic_intro" [innerHTML]="topic.intro"></div>
<div class="topic_content" [innerHTML]="topic.description">
</div>
<div class="topic_content" [innerHTML]="topic.description"></div>
</div>
<div class="button_wrap" *ngIf="readMoreButton">
<button class="btn_medium_secondary" (click)="readMore=!readMore">
Expand Down
8 changes: 5 additions & 3 deletions src/app/topic/topic.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
position: relative;

.moderated_topic {
background: rgba(255, 255, 255, 0.90);
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(16px);
}
.topic_image {
Expand Down Expand Up @@ -220,9 +220,11 @@
overflow: hidden;
position: relative;
font-weight: 400;
font-size: 15px !important;
line-height: 30px !important;
font-size: 15px;
line-height: 30px;
margin-bottom: 36px;
}

.button_wrap {
position: relative;
display: flex;
Expand Down
4 changes: 2 additions & 2 deletions src/app/topic/topic.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ import { TourService } from 'src/app/services/tour.service';
trigger('readMore', [
state('open', style({
maxHeight: '100%',
transition: '0.3s ease-in-out max-height'
transition: '0.1s max-height'
})),
state('closed', style({
maxHeight: '320px',
transition: '0.3s ease-in-out max-height'
transition: '0.1s max-height'
}))
]),
trigger('openClose', [
Expand Down

0 comments on commit 41def32

Please sign in to comment.