Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme api #7122

Merged
merged 5 commits into from
Oct 12, 2023
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
2 changes: 2 additions & 0 deletions src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { getElementWidth, increaseHeightByContent, isContainerVisible } from "./
import { PopupModel } from "./popup";
import { ConsoleWarnings } from "./console-warnings";
import { ProcessValue } from "./conditionProcessValue";
import { ITheme } from "./themes";

export interface IConditionObject {
name: string;
Expand Down Expand Up @@ -113,6 +114,7 @@ export class Question extends SurveyElement<Question>
public setIsMobile(val: boolean) {
this.isMobile = val && (this.allowMobileInDesignMode() || !this.isDesignMode);
}
public themeChanged(theme: ITheme): void { }
@property({ defaultValue: false }) isMobile: boolean;
@property() forceIsInputReadOnly: boolean;

Expand Down
9 changes: 9 additions & 0 deletions src/question_paneldynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { ActionContainer } from "./actions/container";
import { Action, IAction } from "./actions/action";
import { ComputedUpdater } from "./base";
import { AdaptiveActionContainer } from "./actions/adaptive-container";
import { ITheme } from "./themes";

export interface IQuestionPanelDynamicData {
getItemIndex(item: ISurveyData): number;
Expand Down Expand Up @@ -749,6 +750,14 @@ export class QuestionPanelDynamicModel extends Question
question.setIsMobile(val);
}));
}
public themeChanged(theme: ITheme): void {
super.themeChanged(theme);
(this.panels || []).forEach(panel =>
panel.getQuestions(true).forEach(question => {
question.themeChanged(theme);
})
);
}

/**
* The number of panels in Dynamic Panel.
Expand Down
12 changes: 6 additions & 6 deletions src/question_rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { DropdownListModel } from "./dropdownListModel";
import { SurveyModel } from "./survey";
import { ISurveyImpl } from "./base-interfaces";
import { IsTouch } from "./utils/devices";
import { ITheme } from "./themes";

export class RenderedRatingItem extends Base {
private onStringChangedCallback() {
Expand Down Expand Up @@ -811,16 +812,15 @@ export class QuestionRatingModel extends Question {
}
return classes;
}
public themeChanged(theme: ITheme): void {
this.colorsCalculated = false;
this.updateColors(theme.cssVariables);
this.createRenderedRateItems();
}
public setSurveyImpl(value: ISurveyImpl, isLight?: boolean) {
super.setSurveyImpl(value, isLight);
if (!this.survey) return;
this.updateColors((this.survey as SurveyModel).themeVariables);

(<SurveyModel>this.survey).onThemeApplied.add((survey, options) => {
this.colorsCalculated = false;
this.updateColors(options.theme.cssVariables);
this.createRenderedRateItems();
});
}
public dispose(): void {
super.dispose();
Expand Down
14 changes: 5 additions & 9 deletions src/question_signaturepad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CssClassBuilder } from "./utils/cssClassBuilder";
import { SurveyModel } from "./survey";
import { ISurveyImpl } from "./base-interfaces";
import { ConsoleWarnings } from "./console-warnings";
import { ITheme } from "./themes";

var defaultWidth = 300;
var defaultHeight = 200;
Expand Down Expand Up @@ -92,15 +93,10 @@ export class QuestionSignaturePadModel extends Question {
this.destroySignaturePad(el);
}
}
public setSurveyImpl(value: ISurveyImpl, isLight?: boolean) {
super.setSurveyImpl(value, isLight);
if (!this.survey) return;

(<SurveyModel>this.survey).onThemeApplied.add((survey, options) => {
if(!!this.signaturePad) {
this.updateColors(this.signaturePad);
}
});
public themeChanged(theme: ITheme): void {
if(!!this.signaturePad) {
this.updateColors(this.signaturePad);
}
}

initSignaturePad(el: HTMLElement) {
Expand Down
5 changes: 0 additions & 5 deletions src/survey-events-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { QuestionMatrixDynamicModel } from "./question_matrixdynamic";
import { QuestionPanelDynamicModel } from "./question_paneldynamic";
import { SurveyModel } from "./survey";
import { SurveyError } from "./survey-error";
import { ITheme } from "./themes";
import { Trigger } from "./trigger";

export interface QuestionEventMixin {
Expand Down Expand Up @@ -942,8 +941,4 @@ export interface PopupVisibleChangedEvent extends QuestionEventMixin {
* Indicates whether the popup is visible now.
*/
visible: boolean;
}

export interface ThemeAppliedEvent {
theme: ITheme;
}
18 changes: 6 additions & 12 deletions src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import {
MatrixCellValidateEvent, DynamicPanelModifiedEvent, DynamicPanelRemovingEvent, TimerPanelInfoTextEvent, DynamicPanelItemValueChangedEvent, DynamicPanelGetTabTitleEvent,
IsAnswerCorrectEvent, DragDropAllowEvent, ScrollingElementToTopEvent, GetQuestionTitleActionsEvent, GetPanelTitleActionsEvent, GetPageTitleActionsEvent,
GetPanelFooterActionsEvent, GetMatrixRowActionsEvent, ElementContentVisibilityChangedEvent, GetExpressionDisplayValueEvent, ServerValidateQuestionsEvent,
MultipleTextItemAddedEvent, MatrixColumnAddedEvent, GetQuestionDisplayValueEvent, PopupVisibleChangedEvent, ThemeAppliedEvent
MultipleTextItemAddedEvent, MatrixColumnAddedEvent, GetQuestionDisplayValueEvent, PopupVisibleChangedEvent
} from "./survey-events-api";
import { QuestionMatrixDropdownModelBase } from "./question_matrixdropdownbase";
import { QuestionMatrixDynamicModel } from "./question_matrixdynamic";
Expand Down Expand Up @@ -135,13 +135,6 @@ export class SurveyModel extends SurveyElementCore

private navigationBarValue: ActionContainer;

onThemeApplying: EventBase<SurveyModel> = new EventBase<SurveyModel>();
/**
* An event that is raised after a [theme](/form-library/documentation/manage-default-themes-and-styles) is [applied](#applyTheme) to the survey.
* @see applyTheme
*/
onThemeApplied: EventBase<SurveyModel, ThemeAppliedEvent> = new EventBase<SurveyModel, ThemeAppliedEvent>();

//#region Event declarations
/**
* An event that is raised after a [trigger](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#triggers) is executed.
Expand Down Expand Up @@ -2070,7 +2063,7 @@ export class SurveyModel extends SurveyElementCore
if (this._isMobile !== newVal) {
this._isMobile = newVal;
this.updateCss();
this.getAllQuestions().map(q => q.setIsMobile(newVal));
this.getAllQuestions().forEach(q => q.setIsMobile(newVal));
}
}
public get isMobile() {
Expand Down Expand Up @@ -7347,7 +7340,6 @@ export class SurveyModel extends SurveyElementCore
*
* [Themes & Styles](/form-library/documentation/manage-default-themes-and-styles (linkStyle))
* @param theme An [`ITheme`](/form-library/documentation/api-reference/itheme) object with theme settings.
* @see onThemeApplied
*/
public applyTheme(theme: ITheme): void {
if (!theme) return;
Expand All @@ -7370,8 +7362,10 @@ export class SurveyModel extends SurveyElementCore
(this as any)[key] = theme[key];
}
});

this.onThemeApplied.fire(this, { theme: theme });
this.themeChanged(theme);
}
public themeChanged(theme: ITheme): void {
this.getAllQuestions().forEach(q => q.themeChanged(theme));
}

/**
Expand Down
21 changes: 20 additions & 1 deletion src/themes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { HorizontalAlignment, VerticalAlignment } from "./base-interfaces";

export type ImageFit = "auto" | "contain" | "cover";
export type ImageAttachment = "fixed" | "scroll";

Expand Down Expand Up @@ -58,9 +60,26 @@ export interface ITheme {
/**
* An object with survey header settings.
*/
header?: {[index: string]: any};
header?: IHeader;
/**
* An object with CSS variables.
*/
cssVariables?: { [index: string]: string };
}

export interface IHeader {
height: number;
inheritWidthFrom: "survey" | "page";
textAreaWidth: number;
// textGlowEnabled: boolean;
overlapEnabled: boolean;
backgroundImage: string;
backgroundImageOpacity: number;
backgroundImageFit: "cover" | "fill" | "contain" | "tile";
logoPositionX: HorizontalAlignment;
logoPositionY: VerticalAlignment;
titlePositionX: HorizontalAlignment;
titlePositionY: VerticalAlignment;
descriptionPositionX: HorizontalAlignment;
descriptionPositionY: VerticalAlignment;
}
Loading