Skip to content

Commit

Permalink
work for #8129 extract list-item-content
Browse files Browse the repository at this point in the history
  • Loading branch information
OlgaLarina committed May 22, 2024
1 parent 0d53b95 commit 0d5ead5
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 43 deletions.
5 changes: 3 additions & 2 deletions packages/survey-angular-ui/src/angular-ui.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ import { HeaderMobileComponent } from "./components/header/header-mobile.compone
import { ChooseFileBtn } from "./components/file/choose-file.component";
import { FilePreviewComponent } from "./components/file/file-preview.component";
import { SvgBundleComponent } from "./svgbundle.component";
import { ListItemContentComponent } from "./components/list/list-item-content.component";

@NgModule({
declarations: [
Expand All @@ -129,7 +130,7 @@ import { SvgBundleComponent } from "./svgbundle.component";
QuestionSkeletonComponent, TextQuestionComponent, RadiogroupComponent, RadiogroupItemComponent, CheckboxComponent, CheckboxItemComponent,
DropdownComponent, DropdownQuestionComponent, DropdownSelectComponent, DropdownOptionItemComponent,
PopupComponent, PopupBaseContainerComponent, PopupPointerComponent,
CharacterCounterComponent, ListComponent, ListItemComponent, RatingItemComponent, RatingItemStarComponent, RatingItemSmileyComponent,
CharacterCounterComponent, ListComponent, ListItemComponent, ListItemContentComponent, RatingItemComponent, RatingItemStarComponent, RatingItemSmileyComponent,
TagboxFilterComponent, TagboxComponent, TagboxQuestionComponent, TagboxItemComponent,
ActionBarComponent, ActionComponent, ActionBarItemComponent, ActionBarItemDropdownComponent, HtmlQuestionComponent,
SelectBaseItemComponent, SelectBaseComponent, SurveyCommentComponent, SurveyCommentOtherComponent, ElementHeaderComponent, ElementTitleActionsComponent, ElementTitleComponent, DynamicHeadComponent, RowComponent,
Expand All @@ -151,7 +152,7 @@ import { SvgBundleComponent } from "./svgbundle.component";
CharacterCounterComponent,
DropdownComponent, DropdownQuestionComponent, DropdownSelectComponent, DropdownOptionItemComponent,
PopupComponent, PopupBaseContainerComponent, PopupPointerComponent,
CharacterCounterComponent, ListComponent, ListItemComponent, RatingItemComponent, RatingItemStarComponent, RatingItemSmileyComponent,
CharacterCounterComponent, ListComponent, ListItemComponent, ListItemContentComponent, RatingItemComponent, RatingItemStarComponent, RatingItemSmileyComponent,
TagboxFilterComponent, TagboxComponent, TagboxQuestionComponent, TagboxItemComponent,
ActionBarComponent, ActionComponent, ActionBarItemComponent, ActionBarItemDropdownComponent, HtmlQuestionComponent,
SelectBaseItemComponent, SelectBaseComponent, SurveyCommentComponent, SurveyCommentOtherComponent, ElementHeaderComponent, ElementTitleComponent, DynamicHeadComponent, RowComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ng-template #template>
<svg *ngIf="model.iconName" [class]="listModel.cssClasses.itemIcon" [iconName]="model.iconName" [size]="model.iconSize"
sv-ng-svg-icon></svg>
<sv-ng-string [model]="model.locTitle"></sv-ng-string>
</ng-template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Component, Input } from "@angular/core";
import { ListModel, Action } from "survey-core";
import { BaseAngular } from "../../base-angular";
import { AngularComponentFactory } from "../../component-factory";

@Component({
selector: "sv-ng-list-item-content, '[sv-ng-list-item-content]'",
templateUrl: "./list-item-content.component.html",
styleUrls: ["../../hide-host.scss"],
})

export class ListItemContentComponent extends BaseAngular {
@Input() element: any;
@Input() model!: Action;
@Input() listModel!: ListModel;

getModel() {
return this.model;
}
}

AngularComponentFactory.Instance.registerComponent("sv-list-item-content", ListItemContentComponent);
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@
<div [class]="listModel.cssClasses.itemSeparator"></div>
</ng-container>
<div [class]="listModel.cssClasses.itemBody" [style.paddingInlineStart]="paddingLeft" [attr.title]="model.locTitle.calculatedText">
<ng-container *ngIf="!model.component">
<svg *ngIf="model.iconName" [class]="listModel.cssClasses.itemIcon" [iconName]="model.iconName" [size]="model.iconSize"
sv-ng-svg-icon></svg>
<sv-ng-string [model]="model.locTitle"></sv-ng-string>
</ng-container>
<ng-container *ngIf="model.component">
<ng-template [component]="{ name: model.component, data: { model: model } }"></ng-template>
</ng-container>
<ng-template [component]="{ name: model.component || 'sv-list-item-content', data: { model: model, listModel: listModel } }"></ng-template>
</div>
</li>
</ng-template>
9 changes: 1 addition & 8 deletions packages/survey-vue3-ui/src/components/list/ListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@
v-bind:class="model.cssClasses.itemBody"
:title="item.locTitle.calculatedText"
>
<sv-svg-icon
v-if="item.iconName && !item.component"
v-bind:class="model.cssClasses.itemIcon"
:iconName="item.iconName"
:size="item.iconSize"
></sv-svg-icon>
<survey-string v-if="!item.component" :locString="item.locTitle" />
<component v-if="item.component" :is="item.component" :item="item">
<component :is="item.component || 'sv-list-item-content'" :item="item" :model="model">
</component>
</div>
</li>
Expand Down
18 changes: 18 additions & 0 deletions packages/survey-vue3-ui/src/components/list/ListItemContent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<template>
<sv-svg-icon
v-if="item.iconName"
v-bind:class="model.cssClasses.itemIcon"
:iconName="item.iconName"
:size="item.iconSize"
></sv-svg-icon>
<survey-string :locString="item.locTitle" />
</template>

<script lang="ts" setup>
import { useBase } from "@/base";
import type { ListModel, Action, IAction } from "survey-core";
const props = defineProps<{ model: ListModel; item: Action }>();
useBase(() => props.item);
</script>
2 changes: 2 additions & 0 deletions packages/survey-vue3-ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ import ButtonGroup from "./buttongroup/ButtonGroup.vue";
import ButtonGroupItem from "./buttongroup/ButtonGroupItem.vue";
import Logo from "./Logo.vue";
import SvgBundle from "./SvgBundle.vue";
import ListItemContent from "./components/list/ListItemContent.vue";

export { useBase, useLocString, useQuestion, useComputedArray } from "./base";

Expand Down Expand Up @@ -240,6 +241,7 @@ function registerComponents(app: App) {
app.component("sv-action-bar-separator", ActionBarSeparator);

app.component("sv-list", List);
app.component("sv-list-item-content", ListItemContent);
app.component("sv-list-item", ListItem);

app.component("sv-popup", Popup);
Expand Down
1 change: 1 addition & 0 deletions src/entries/react-ui-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export { SurveyQuestionButtonGroup } from "../react/reactquestion_buttongroup";
export { SurveyQuestionCustom, SurveyQuestionComposite } from "../react/reactquestion_custom";

export { Popup } from "../react/components/popup/popup";
export { ListItemContent } from "../react/components/list/list-item-content";
export { List } from "../react/components/list/list";
export { TitleActions } from "../react/components/title/title-actions";
export { TitleElement } from "../react/components/title/title-element";
Expand Down
49 changes: 49 additions & 0 deletions src/react/components/list/list-item-content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from "react";
import { ListModel } from "survey-core";
import { ReactElementFactory } from "../../element-factory";
import { SurveyElementBase } from "../../reactquestion_element";
import { SvgIcon } from "../svg-icon/svg-icon";

interface IListItemProps {
model: ListModel;
item: any;
}

export class ListItemContent extends SurveyElementBase<IListItemProps, any> {
get model(): ListModel {
return this.props.model;
}
get item(): any {
return this.props.item;
}
getStateElement() {
return this.item;
}
render(): JSX.Element | null {
if (!this.item) return null;

const content: Array<JSX.Element> = [];
const text = this.renderLocString(this.item.locTitle, undefined, "locString");
if(this.item.iconName) {
const icon = <SvgIcon
key={1}
className={this.model.cssClasses.itemIcon}
iconName={this.item.iconName}
size={this.item.iconSize}
aria-label={this.item.title}
></SvgIcon>;
content.push(icon);
content.push(<span key={2}>{text}</span>);
} else {
content.push(text);
}

return <>
{content}
</>;
}
}

ReactElementFactory.Instance.registerElement("sv-list-item-content", (props) => {
return React.createElement(ListItemContent, props);
});
28 changes: 3 additions & 25 deletions src/react/components/list/list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ListModel } from "survey-core";
import { ReactElementFactory } from "../../element-factory";
import { SurveyElementBase } from "../../reactquestion_element";
import { attachKey2click } from "../../reactSurvey";
import { SvgIcon } from "../svg-icon/svg-icon";

interface IListItemProps {
model: ListModel;
Expand All @@ -29,36 +28,15 @@ export class ListItem extends SurveyElementBase<IListItemProps, any> {
paddingInlineStart: this.model.getItemIndent(this.item)
};
const className = this.model.getItemClass(this.item);
const content: Array<JSX.Element> = [];
if (!this.item.component) {
const text = this.renderLocString(this.item.locTitle, undefined, "locString");
if(this.item.iconName) {
const icon = <SvgIcon
key={1}
className={this.model.cssClasses.itemIcon}
iconName={this.item.iconName}
size={this.item.iconSize}
aria-label={this.item.title}
></SvgIcon>;
content.push(icon);
content.push(<span key={2}>{text}</span>);
} else {
content.push(text);
}
} else {
const newElement = ReactElementFactory.Instance.createElement(this.item.component, { item: this.item, key: this.item.id });
if(!!newElement) {
content.push(newElement);
}
}

const itemContent = this.item.component || "sv-list-item-content";
const newElement = ReactElementFactory.Instance.createElement(itemContent, { item: this.item, key: this.item.id, model: this.model });
const contentWrap =
<div
style={contentWrapStyle}
className={this.model.cssClasses.itemBody}
title={this.item.locTitle.calculatedText}
>
{content}
{newElement}
</div>;
const separator = this.item.needSeparator ? <div className = {this.model.cssClasses.itemSeparator}/>:null;
const isVisible = this.model.isItemVisible(this.item);
Expand Down

0 comments on commit 0d5ead5

Please sign in to comment.