Skip to content

Commit

Permalink
Work for #3390: implement tabbed menu in angular
Browse files Browse the repository at this point in the history
  • Loading branch information
dk981234 committed Aug 31, 2022
1 parent ce35a6e commit 61c2ebf
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 78 deletions.
5 changes: 4 additions & 1 deletion packages/survey-creator-angular/src/angular-ui.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import { CreatorComponent } from "./creator.component";
import { SurveyAngularModule } from "survey-angular-ui";
import { DesignerTabComponent } from "./tabs/designer.component";
import { SvgBundleComponent } from "./svg-bundle.component";
import { TabbedMenuItemComponent } from "./tabbed-menu/tabbed-menu/tabbed-menu-item.component";
import { TabbledMenuComponent } from "./tabbed-menu/tabbed-menu/tabbed-menu.component";
import { TabbedMenuItemWrapperComponent } from "./tabbed-menu/tabbed-menu/tabbed-menu-item-wrapper.component";

@NgModule({
declarations: [CreatorComponent, DesignerTabComponent, SvgBundleComponent],
declarations: [CreatorComponent, DesignerTabComponent, SvgBundleComponent, TabbledMenuComponent, TabbedMenuItemComponent, TabbedMenuItemWrapperComponent],
imports: [
CommonModule, FormsModule, SurveyAngularModule
],
Expand Down
4 changes: 1 addition & 3 deletions packages/survey-creator-angular/src/creator.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
<div class="svc-flex-column svc-flex-row__element svc-flex-row__element--growing">
<div class="svc-top-bar">
<div class="svc-tabbed-menu-wrapper" [visible]="creator.showTabs">
<span>TODO TABBED MENU</span>
<!-- ko component: { name: 'svc-tabbed-menu', params: { model: creator.tabbedMenu } } -->
<!-- /ko -->
<svc-tabbed-menu [model]="creator.tabbedMenu"></svc-tabbed-menu>
</div>
<div *ngIf="creator.showToolbar" class="svc-toolbar-wrapper" [visible]="creator.showToolbar">
<sv-action-bar [model]="creator.toolbar"></sv-action-bar>
Expand Down
82 changes: 8 additions & 74 deletions packages/survey-creator-angular/src/creator.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Component, Input } from "@angular/core";
import { SurveyModel } from "survey-core";
import { ChangeDetectorRef, Component, Input } from "@angular/core";
import { BaseAngular } from "survey-angular-ui";
import { CreatorBase } from "survey-creator-core";

Expand All @@ -11,82 +10,17 @@ import { CreatorBase } from "survey-creator-core";
export class CreatorComponent extends BaseAngular<CreatorBase> {
@Input() model!: CreatorBase;

constructor(changeDetectorRef: ChangeDetectorRef) {
super(changeDetectorRef);
changeDetectorRef.detach();
}
protected getModel(): CreatorBase {
return this.model;
}

public get creator(): CreatorBase {
return this.model;
}

public survey = new SurveyModel({
"logoPosition": "right",
"completedHtml": "<h3>Thank you for your feedback.</h3><h5>Your thoughts and ideas will help us to create a great product!</h5>",
"completedHtmlOnCondition": [
{
"expression": "{nps_score} > 8",
"html": "<h3>Thank you for your feedback.</h3><h5>We glad that you love our product. Your ideas and suggestions will help us to make our product even better!</h5>"
},
{
"expression": "{nps_score} < 7",
"html": "<h3>Thank you for your feedback.</h3><h5> We are glad that you share with us your ideas.We highly value all suggestions from our customers. We do our best to improve the product and reach your expectation.</h5><br />"
}
],
"pages": [
{
"name": "page1",
"elements": [
{
"type": "rating",
"name": "nps_score",
"title": "On a scale of zero to ten, how likely are you to recommend our product to a friend or colleague?",
"isRequired": true,
"rateMin": 0,
"rateMax": 10,
"minRateDescription": "(Most unlikely)",
"maxRateDescription": "(Most likely)"
},
{
"type": "checkbox",
"name": "promoter_features",
"visible": false,
"visibleIf": "{nps_score} >= 9",
"title": "Which features do you value the most?",
"isRequired": true,
"validators": [
{
"type": "answercount",
"text": "Please select two features maximum.",
"maxCount": 2
}
],
"choices": [
"Performance",
"Stability",
"User Interface",
"Complete Functionality"
],
"hasOther": true,
"otherText": "Other feature:",
"colCount": 2
},
{
"type": "comment",
"name": "passive_experience",
"visible": false,
"visibleIf": "{nps_score} > 6 and {nps_score} < 9",
"title": "What do you like about our product?"
},
{
"type": "comment",
"name": "disappointed_experience",
"visible": false,
"visibleIf": "{nps_score} notempty",
"title": "What do you miss or find disappointing in your experience with our products?"
}
]
}
],
"showQuestionNumbers": "off"
});
protected override onModelChanged(): void {
this.changeDetectorRef.detectChanges();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<ng-template #template>
<span class="svc-tabbed-menu-item-container" [class.sv-action--hidden]="!model.isVisible" [class]="model.css">
<div class="sv-action__content">
<ng-template [component]="{ name: model.component || 'svc-tabbed-menu-item', data: { model } }"></ng-template>
</div>
</span>
</ng-template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component, Input } from "@angular/core";
import { BaseAngular } from "survey-angular-ui";
import { TabbedMenuItem } from "survey-creator-core";

@Component({
selector: "svc-tabbed-menu-item-wrapper",
templateUrl: "./tabbed-menu-item-wrapper.component.html",
styles: [":host { display: none; }"]
})
export class TabbedMenuItemWrapperComponent extends BaseAngular<TabbedMenuItem> {
@Input() model!: TabbedMenuItem;
protected getModel(): TabbedMenuItem {
return this.model;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<ng-template #template>
<div
class="svc-tabbed-menu-item"
[class.svc-tabbed-menu-item--selected]="model.active"
[class.svc-tabbed-menu-item--disabled]="model.disabled"
(click)="model.action()" [key2click]
>
<span
class="svc-text svc-text--normal svc-tabbed-menu-item__text"
[class.svc-text--bold]="model.active"
>
{{model.title}}
</span>
</div>
</ng-template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Component, Input } from "@angular/core";
import { AngularComponentFactory, BaseAngular } from "survey-angular-ui";
import { TabbedMenuItem } from "survey-creator-core";

@Component({
selector: "svc-tabbed-menu-item",
templateUrl: "./tabbed-menu-item.component.html",
styles: [":host { display: none; }"]
})
export class TabbedMenuItemComponent extends BaseAngular<TabbedMenuItem> {
@Input() model!: TabbedMenuItem;
protected getModel(): TabbedMenuItem {
return this.model;
}
}
AngularComponentFactory.Instance.registerComponent("svc-tabbed-menu-item", TabbedMenuItemComponent);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<ng-template #template>
<div class="svc-tabbed-menu" #container>
<ng-container *ngFor="let action of model.renderedActions">
<svc-tabbed-menu-item-wrapper [model]="action"></svc-tabbed-menu-item-wrapper>
</ng-container>
</div>
</ng-template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { AfterViewInit, Component, ElementRef, Input, ViewChild } from "@angular/core";
import { AngularComponentFactory, BaseAngular } from "survey-angular-ui";
import { ResponsivityManager } from "survey-core";
import { TabbedMenuContainer } from "survey-creator-core";

@Component({
selector: "svc-tabbed-menu",
templateUrl: "./tabbed-menu.component.html",
styles: [":host { display: none; }"]
})
export class TabbledMenuComponent extends BaseAngular<TabbedMenuContainer> implements AfterViewInit {
@Input() model!: TabbedMenuContainer;
@ViewChild("container") container!: ElementRef<HTMLDivElement>;
private responsivityManager!: ResponsivityManager;
protected getModel(): TabbedMenuContainer {
return this.model;
}
ngAfterViewInit(): void {
this.responsivityManager = new ResponsivityManager(
this.container.nativeElement,
this.model,
".svc-tabbed-menu-item-container:not(.sv-dots)>.sv-action__content"
);
}
override ngOnDestroy(): void {
super.ngOnDestroy();
this.responsivityManager.dispose();
}

}
AngularComponentFactory.Instance.registerComponent("svc-tabbed-menu", TabbledMenuComponent);

0 comments on commit 61c2ebf

Please sign in to comment.