Skip to content

Commit

Permalink
#6008 Refactoring search component (#6026)
Browse files Browse the repository at this point in the history
* #6008 Refactoring search component
Fixes #6008

* rename main search class

* #6008 fixed styles

* #6008 - fixed toolbox search color

* #6008 - fix toolbox search placeholder text

* #6008 remove search from toolbox styles

* #6008 fix propertygrid search placeholder

* #6008 fix search clear button size
  • Loading branch information
novikov82 authored Nov 7, 2024
1 parent 954d95a commit a6c7e06
Show file tree
Hide file tree
Showing 29 changed files with 335 additions and 291 deletions.
6 changes: 3 additions & 3 deletions functionalTests/designer/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,10 @@ test("toolbox search in compact mode - clear but do not close", async (t) => {

await t
.click(".svc-toolbox__search-button")
.typeText(".spg-search-editor_input", "d")
.expect(Selector(".spg-search-editor_input").value).eql("d")
.typeText(".svc-search__input", "d")
.expect(Selector(".svc-search__input").value).eql("d")
.expect(Selector(".svc-toolbox").hasClass("svc-toolbox--flyout")).ok()
.click(".svc-toolbox #svd-grid-search-close")
.expect(Selector(".spg-search-editor_input").value).eql("")
.expect(Selector(".svc-search__input").value).eql("")
.expect(Selector(".svc-toolbox").hasClass("svc-toolbox--flyout")).ok();
});
2 changes: 1 addition & 1 deletion packages/survey-creator-angular/src/angular-ui.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { SidebarHeaderComponent } from "./side-bar/side-bar-header.component";

import { ObjectSelectorComponent } from "./side-bar/object-selector.component";
import { PropertyGridComponent } from "./side-bar/property-grid.component";
import { SearchComponent } from "./side-bar/search.component";
import { SearchComponent } from "./components/search.component";
import { TextareaJsonEditorComponent } from "./tabs/json/json-editor-textarea.component";
import { AceJsonEditorComponent } from "./tabs/json/json-editor-ace.component";
import { LogicTabComponent } from "./tabs/logic/logic.component";
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-creator-angular/src/angular-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export * from "./side-bar/side-bar-header.component";

export * from "./side-bar/object-selector.component";
export * from "./side-bar/property-grid.component";
export * from "./side-bar/search.component";
export * from "./components/search.component";
export * from "./tabs/json/json-editor-textarea.component";
export * from "./tabs/json/json-editor-ace.component";
export * from "./tabs/logic/logic.component";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<ng-template #template>
<div *ngIf="model.isVisible" class="svc-search">
<div class="svc-search__search-icon">
<svg [iconName]="'icon-search'" [size]="'auto'" sv-ng-svg-icon></svg>
</div>
<input type="text" class="svc-search__input" [(ngModel)]="model.filterString"
[attr.aria-label]="model.filterStringPlaceholder" [attr.placeholder]="model.filterStringPlaceholder" />
<div class="svc-search__toolbar">
<div class="svc-search__toolbar-counter">{{model.matchCounterText}}</div>
<sv-action-bar [model]="model.searchActionBar"></sv-action-bar>
</div>
</div>
</ng-template>
13 changes: 0 additions & 13 deletions packages/survey-creator-angular/src/side-bar/search.component.html

This file was deleted.

54 changes: 54 additions & 0 deletions packages/survey-creator-core/src/components/search-manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Action, ActionContainer, Base, ComputedUpdater, property } from "survey-core";
import { getLocString } from "../editorLocalization";

export abstract class SearchManager extends Base {
public searchActionBar: ActionContainer = new ActionContainer();
public get filterStringPlaceholder(): string { return this.getFilterStringPlaceholder(); }
@property() filterString: string;
@property() isVisible: boolean;
@property() matchCounterText: string;

protected getSearchActions() {
return [new Action({
id: "svd-grid-search-close",
iconName: "icon-clear_16x16",
component: "sv-action-bar-item",
title: getLocString("ed.clear"),
showTitle: false,
iconSize: "auto",
disableTabStop: true,
innerCss: "svc-search__bar-item",
visible: <any>new ComputedUpdater(() => !!this.filterString),
action: () => {
this.clearFilterString();
}
})];
}
initActionBar() {
this.searchActionBar.setItems(this.getSearchActions());
}
public clearFilterString(): void {
this.filterString = "";
}

protected abstract setFiterString(newValue: string, oldValue: string);
protected abstract getFilterStringPlaceholder(): string;

protected onPropertyValueChanged(name: string, oldValue: any, newValue: any) {
super.onPropertyValueChanged(name, oldValue, newValue);

if (name === "filterString") {
this.setFiterString(newValue, oldValue);
}
}

constructor() {
super();
this.initActionBar();
}

dispose(): void {
this.searchActionBar.dispose();
super.dispose();
}
}
74 changes: 74 additions & 0 deletions packages/survey-creator-core/src/components/search.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@import "../variables.scss";
.svc-search {
// TODO remove v2
--sjs-general-forecolor: rgba(0, 0, 0, 0.91);
--sjs-general-forecolor-light: rgba(0, 0, 0, 0.45);
}

.svc-search {
display: flex;
align-items: center;
}

.svc-search__input {
@include textEllipsis;
@include ctrSmallBoldFont;

border: none;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;

display: block;
background: transparent;
box-sizing: border-box;
outline: none;
padding: 0;
width: 0;
flex-grow: 1;
}

.svc-creator--mobile .svc-search__input {
$fontSize: var(--ctr-font-small-size, #{calcSize(1.5)});
font-size: Max(16px, #{$fontSize});
}


.svc-search__toolbar {
display: flex;
gap: var(--ctr-search-toolbar-gap, calcSize(1.5));
justify-content: flex-end;
align-items: center;
flex-shrink: 0;
}

.svc-search__toolbar .sv-action-bar {
gap: var(--ctr-search-toolbar-gap, calcSize(0.5));
margin: 0;
flex-shrink: 0;
}

.svc-search__toolbar .sv-action--hidden {
display: none;
}

.svc-search__toolbar .svc-search__bar-item {
height: min-content;
margin: 0;
border-radius: var(--ctr-search-button-corner-radius);
padding: var(--ctr-search-button-padding-vertical, calcSize(0.5))
var(--ctr-search-button-padding-horizontal, calcSize(0.5)) var(--ctr-search-button-padding-vertical, calcSize(0.5))
var(--ctr-search-button-padding-horizontal, calcSize(0.5));
border-radius: 100px;

.sv-svg-icon {
width: var(--ctr-search-button-icon-width, calcSize(2));
height: var(--ctr-search-button-icon-height, calcSize(2));
}
}

.svc-search__toolbar-counter {
@include ctrSmallBoldFont;
display: flex;
flex-shrink: 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ $reverse-cubic-ease-out: cubic-bezier(0.32, 0, 0.67, 0);
}
.svc-toolbox__item-submenu-button,
.svc-toolbox__item-title,
.spg-search-editor_input {
.svc-search__input {
animation-duration: var(--fade-animation-duration);
animation-delay: var(--fade-animation-delay);
animation-direction: var(--animation-direction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
.svc-creator__toolbox--right {
.sv-popup__body-content,
.spg-search-editor_container
.svc-search
{
direction: initial;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { property } from "survey-core";
import { getLocString } from "../../editorLocalization";

import { QuestionToolbox } from "../../toolbox";
import { SearchManager } from "../search-manager";

export class SearchManagerToolbox extends SearchManager {
@property() toolbox: QuestionToolbox;
protected getFilterStringPlaceholder(): string { return getLocString("ed.toolboxFilteredTextPlaceholder"); }
protected setFiterString(newValue: string, oldValue: string) {
this.toolbox.showSeparators = !newValue;
this.toolbox.items.forEach(item => item.visible = item.hasText(newValue));
this.toolbox.showPlaceholder = !this.toolbox.items.filter(i => i.visible).length;
this.toolbox.categories.forEach(category => {
category.forceExpand = !!newValue;
category.empty = category.items.filter(item => item.visible).length == 0;
});
}

public clearFilterString(): void {
this.filterString = "";
this.toolbox.rootElement.querySelector("input").focus();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@import "../../variables.scss";

.svc-toolbox {
.svc-search {
padding-top: var(--ctr-toolbox-search-padding-top, calcSize(2.5));
padding-inline-end: var(--ctr-toolbox-search-padding-right, calcSize(2));
padding-bottom: var(--ctr-toolbox-search-padding-bottom, calcSize(2.5));
padding-inline-start: var(--ctr-toolbox-search-padding-left, calcSize(3));
gap: var(--ctr-toolbox-search-gap, calcSize(1));
height: unset;

width: unset;
flex-grow: 1;
border-bottom: none;
}

.svc-search__input {
color: var(--ctr-toolbox-search-text-color, $foreground);
}
.svc-search__input::placeholder {
color: var(--ctr-toolbox-search-text-color-placeholder, $foreground-light);
}
.svc-search__bar-item {
&:hover:enabled {
background-color: var(--ctr-toolbox-search-clear-button-background-color-hovered, $red-light);
svg use {
fill: var(--ctr-toolbox-search-clear-button-icon-color-hovered, $red);
}
}
}

.svc-search__search-icon {
width: var(--ctr-toolbox-search-icon-width, calcSize(3));
height: var(--ctr-toolbox-search-icon-height, calcSize(3));

.sv-svg-icon {
width: var(--ctr-toolbox-search-icon-width, calcSize(3));
height: var(--ctr-toolbox-search-icon-height, calcSize(3));

use {
fill: var(--ctr-toolbox-search-icon-color, $foreground-light);
}
}
}
}
36 changes: 2 additions & 34 deletions packages/survey-creator-core/src/components/toolbox/toolbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +46,6 @@ svc-toolbox {
height: 100%;
display: flex;
flex-direction: column;
.spg-search-editor_container {
background: var(--ctr-toolbox-background-color, $background-dim);
padding-top: var(--ctr-toolbox-search-padding-top, calcSize(2.5));
padding-inline-end: var(--ctr-toolbox-search-padding-right, calcSize(2));
padding-bottom: var(--ctr-toolbox-search-padding-bottom, calcSize(2.5));
padding-inline-start: var(--ctr-toolbox-search-padding-left, calcSize(3));
height: unset;

width: unset;
flex-grow: 1;
border-bottom: none;
}

.spg-search-editor_input {
width: 0;
flex-grow: 1;
}

.spg-search-editor_toolbar-counter {
display: none;
}

.spg-search-editor_bar-item.sv-action-bar-item:not(.sv-action-bar-item--pressed) {
&:hover:enabled {
background-color: var(--ctr-toolbox-search-clear-button-background-color-hovered, $red-light);
border-radius: 100px;

svg use {
fill: var(--ctr-toolbox-search-clear-button-icon-color-hovered, $red);
}
}
}
}

.svc-toolbox__panel {
Expand Down Expand Up @@ -165,7 +133,7 @@ svc-toolbox {
var(--ctr-toolbox-padding-bottom, calcSize(2)) var(--ctr-toolbox-group-padding-left-compact, calcSize(1.5));
pointer-events: none;
}
.spg-search-editor_container {
.svc-search {
opacity: 0;
position: absolute;
}
Expand Down Expand Up @@ -205,7 +173,7 @@ svc-toolbox {
overflow: visible;
border-inline-end: var(--ctr-toolbox-border-width-right, 0px) solid transparent;

.spg-search-editor_container {
.svc-search {
opacity: 1;
position: relative;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/survey-creator-core/src/entries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export * from "../components/tabs/logic-plugin";
export * from "../components/tabs/logic-theme";

export * from "../components/toolbox/toolbox-tool";
export * from "../components/toolbox/toolbox-search-manager";
export * from "../components/page-navigator/page-navigator";
export * from "../components/page";
export * from "../components/row";
Expand All @@ -55,6 +56,7 @@ export * from "../components/header/logo-image";
export * from "../components/string-editor";
export * from "../components/embedded-survey";
export * from "../components/link-value";
export * from "../components/search-manager";
export * from "../editorLocalization";
export * from "../json5";

Expand Down Expand Up @@ -105,13 +107,15 @@ export * from "../presets/presets-tabs";
export * from "../presets/presets-toolbox";
export * from "../survey-elements";

require("../components/search.scss");
require("../components/property-panel/property-panel-item.scss");
require("../components/property-panel/property-panel.scss");
require("../components/tabbed-menu/tabbed-menu-item.scss");
require("../components/tabbed-menu/tabbed-menu.scss");
require("../components/toolbox/toolbox-tool.scss");
require("../components/question-dropdown.scss");
require("../components/toolbox/toolbox.scss");
require("../components/toolbox/toolbox-search.scss");
require("../components/toolbox/toolbox-right.scss");
require("../components/toolbox/toolbox-animation.scss");
require("../components/side-bar/side-bar.scss");
Expand Down
Loading

0 comments on commit a6c7e06

Please sign in to comment.