Skip to content

Commit

Permalink
Implemented #7181 - Advanced header mobile view - fixed paddings
Browse files Browse the repository at this point in the history
  • Loading branch information
tsv2013 committed Oct 19, 2023
1 parent 1363dd9 commit 99b0b27
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<ng-template #template>
<div *ngIf="(survey.headerView === 'advanced' && survey.renderedHasHeader)" [class]="model.coverClasses" [style]="{ height: model.renderedHeight }">
<div *ngIf="(survey.headerView === 'advanced' && survey.renderedHasHeader)" [class]="model.headerClasses" [style]="{ height: model.renderedHeight }">
<div *ngIf="!!model.backgroundImage" [style]="model.backgroundImageStyle" [class]="model.backgroundImageClasses"></div>
<div *ngIf="!survey.isMobile" [class]="model.contentClasses" [style.width]="model.maxWidth">
<ng-container *ngFor="let cell of model.cells">
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-vue3-ui/src/components/header/Header.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div :class="model.coverClasses" :style="{ 'height': model.renderedHeight }">
<div :class="model.headerClasses" :style="{ 'height': model.renderedHeight }">
<div v-if="!!model.backgroundImage" :class="model.backgroundImageClasses" :style="model.backgroundImageStyle"></div>
<div v-if="!survey.isMobile" :class="model.contentClasses" :style="{ maxWidth: model.maxWidth }">
<sv-header-cell
Expand Down
30 changes: 19 additions & 11 deletions src/defaultV2-theme/blocks/header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
background-color: $cover-backcolor;
}

.sv-header--mobile {
padding: calcSize(3);
}

.sv-conver__overlap {
.sv-header__overlap {
margin-bottom: calcSize(-14);
padding-bottom: calcSize(8);
}

.sv-conver__overlap.sv-conver__without-background {
.sv-header__overlap.sv-header__without-background {
margin-bottom: 0;
padding-bottom: 0;
}

.sv-conver__without-background .sv-conver__content {
padding-bottom: 0;
.sv-header__without-background {

.sv-header--mobile,
.sv-header__content {
padding-bottom: 0;
}
}

.sv-conver__content {
.sv-header__content {
padding: calcSize(5);
box-sizing: border-box;
height: 100%;
Expand All @@ -33,7 +33,7 @@
grid-auto-rows: 1fr 1fr 1fr;
}

.sv-conver__content--static {
.sv-header__content--static {
max-width: calcSize(88);
margin-left: auto;
margin-right: auto;
Expand Down Expand Up @@ -122,6 +122,14 @@
color: $cover-description-forecolor;
}

.sv-conver__content .sd-header__text h3 {
.sv-header__content .sd-header__text h3 {
margin: 0;
}

.sv-header--mobile {
padding: calcSize(3);

.sv-header__logo~.sv-header__title {
margin-top: calcSize(3);
}
}
20 changes: 10 additions & 10 deletions src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ export class Cover extends Base {
}
return backgroundImageFit;
}
private updateCoverClasses(): void {
this.coverClasses = new CssClassBuilder()
private updateHeaderClasses(): void {
this.headerClasses = new CssClassBuilder()
.append("sv-header")
.append("sv-conver__without-background", (!this.backgroundColor || this.backgroundColor === "trasparent") && !this.backgroundImage)
.append("sv-conver__overlap", this.overlapEnabled)
.append("sv-header__without-background", (!this.backgroundColor || this.backgroundColor === "trasparent") && !this.backgroundImage)
.append("sv-header__overlap", this.overlapEnabled)
.toString();
}
private updateContentClasses(): void {
const surveyWidthMode = !!this.survey && this.survey.calculateWidthMode();
this.maxWidth = this.inheritWidthFrom === "survey" && !!surveyWidthMode && surveyWidthMode === "static" && this.survey.renderedWidth;
this.contentClasses = new CssClassBuilder()
.append("sv-conver__content")
.append("sv-conver__content--static", this.inheritWidthFrom === "survey" && !!surveyWidthMode && surveyWidthMode === "static")
.append("sv-conver__content--responsive", this.inheritWidthFrom === "container" || (!!surveyWidthMode && surveyWidthMode === "responsive"))
.append("sv-header__content")
.append("sv-header__content--static", this.inheritWidthFrom === "survey" && !!surveyWidthMode && surveyWidthMode === "static")
.append("sv-header__content--responsive", this.inheritWidthFrom === "container" || (!!surveyWidthMode && surveyWidthMode === "responsive"))
.toString();
}
private updateBackgroundImageClasses(): void {
Expand All @@ -111,7 +111,7 @@ export class Cover extends Base {
["top", "middle", "bottom"].forEach((positionY: VerticalAlignment) =>
["left", "center", "right"].forEach((positionX: HorizontalAlignment) => this.cells.push(new CoverCell(this, positionX, positionY)))
);
this.updateCoverClasses();
this.updateHeaderClasses();
this.updateContentClasses();
this.updateBackgroundImageClasses();
}
Expand Down Expand Up @@ -144,7 +144,7 @@ export class Cover extends Base {
@property() logoStyle: { gridColumn: number, gridRow: number };
@property() titleStyle: { gridColumn: number, gridRow: number };
@property() descriptionStyle: { gridColumn: number, gridRow: number };
@property() coverClasses: string;
@property() headerClasses: string;
@property() contentClasses: string;
@property() maxWidth: string;
@property() backgroundImageClasses: string;
Expand Down Expand Up @@ -183,7 +183,7 @@ export class Cover extends Base {
protected propertyValueChanged(name: string, oldValue: any, newValue: any): void {
super.propertyValueChanged(name, oldValue, newValue);
if (name === "backgroundColor" || name === "backgroundImage" || name === "overlapEnabled") {
this.updateCoverClasses();
this.updateHeaderClasses();
}
if (name === "inheritWidthFrom") {
this.updateContentClasses();
Expand Down
2 changes: 1 addition & 1 deletion src/knockout/components/header/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- ko if: (survey.headerView === 'advanced' && survey.renderedHasHeader) -->
<div data-bind="css: model.coverClasses, style: { height: model.renderedHeight }">
<div data-bind="css: model.headerClasses, style: { height: model.renderedHeight }">
<!-- ko if: !!model.backgroundImage -->
<div data-bind="style: model.backgroundImageStyle, css: model.backgroundImageClasses"></div>
<!-- /ko -->
Expand Down
2 changes: 1 addition & 1 deletion src/react/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class Header extends SurveyElementBase<ILayoutElementProps<Cover>, any> {
}

return (
<div className={this.model.coverClasses} style={{ height: this.model.renderedHeight }}>
<div className={this.model.headerClasses} style={{ height: this.model.renderedHeight }}>
{this.model.backgroundImage ? <div style={this.model.backgroundImageStyle} className={this.model.backgroundImageClasses}></div> : null}
{headerContent}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/vue/components/header/header.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div :class="model.coverClasses" :style="{ 'height': model.renderedHeight }">
<div :class="model.headerClasses" :style="{ 'height': model.renderedHeight }">
<div v-if="!!model.backgroundImage" :class="model.backgroundImageClasses" :style="model.backgroundImageStyle"></div>
<div v-if="!survey.isMobile" :class="model.contentClasses" :style="{ maxWidth: model.maxWidth }">
<sv-header-cell
Expand Down
8 changes: 4 additions & 4 deletions tests/headerTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ QUnit.test("contentClasses",

assert.equal(cover.survey.widthMode, "auto", "default widthMode");
assert.equal(cover.inheritWidthFrom, "survey", "default inheritWidthFrom");
assert.equal(cover.contentClasses, "sv-conver__content sv-conver__content--static", "default contentClasses");
assert.equal(cover.contentClasses, "sv-header__content sv-header__content--static", "default contentClasses");

cover.survey.widthMode = "responsive";
assert.equal(cover.contentClasses, "sv-conver__content sv-conver__content--responsive", "survey.widthMode is responsive");
assert.equal(cover.contentClasses, "sv-header__content sv-header__content--responsive", "survey.widthMode is responsive");

cover.survey.widthMode = "static";
assert.equal(cover.contentClasses, "sv-conver__content sv-conver__content--static", "survey.widthMode is static");
assert.equal(cover.contentClasses, "sv-header__content sv-header__content--static", "survey.widthMode is static");

cover.inheritWidthFrom = "container";
assert.equal(cover.contentClasses, "sv-conver__content sv-conver__content--responsive", "inheritWidthFrom is container");
assert.equal(cover.contentClasses, "sv-header__content sv-header__content--responsive", "inheritWidthFrom is container");
}
);

Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions visualRegressionTests/tests/defaultV2/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,36 @@ frameworks.forEach(framework => {
await takeElementScreenshot("survey-advanced-header-mobile-default.png", Selector(".sd-root-modern"), t, comparer);
});
});
test("Check survey advanced header mobile view with background", async (t) => {
await wrapVisualTest(t, async (t, comparer) => {
await t.resizeWindow(500, 600);
await initSurvey(framework, {
title: "Survey Title",
description: "Survey description",
logo: "https://surveyjs.io/Content/Images/examples/image-picker/lion.jpg",
widthMode: "responsive",
questions: [
{
type: "text",
title: "Question title",
name: "q1"
}
]
});
await ClientFunction(() => {
(<any>window).survey.headerView = "advanced";
(<any>window).survey.applyTheme({
cssVariables: {
"--sjs-cover-backcolor": "green"
},
header: {
}
});
(<any>window).survey.setIsMobile(true);
})();
await takeElementScreenshot("survey-advanced-header-mobile-background.png", Selector(".sd-root-modern"), t, comparer);
});
});
test("Check survey with progress top", async (t) => {
await wrapVisualTest(t, async (t, comparer) => {
await t.resizeWindow(1920, 1080);
Expand Down

0 comments on commit 99b0b27

Please sign in to comment.