Skip to content

Feature/searchbox#82 #131

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

Merged
merged 6 commits into from
Dec 2, 2022
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
10 changes: 6 additions & 4 deletions SearchBox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ This code component provides a wrapper around the [Fluent UI SearchBox](https://

## Properties

- **SearchText** - The action items to render. The first item is considered the root item.
- **Search Text** - The action items to render. The first item is considered the root item.

- **IconName** - Name of the Fluent UI icon (see [Fluent UI Icons](https://developer.microsoft.com/en-us/fluentui#/styles/web/icons)).
- **Icon Name** - Name of the Fluent UI icon (see [Fluent UI Icons](https://developer.microsoft.com/en-us/fluentui#/styles/web/icons)).

- **Underlined** - Whether or not the SearchBox is underlined.

- **DisableAnimation** - Whether or not to animate the SearchBox icon on focus.
- **Disable Animation** - Whether or not to animate the SearchBox icon on focus.

- **PlaceholderText** - Placeholder for the search box.
- **Placeholder Text** - Placeholder for the search box.

- **Delay Output** - To delay output by half a second. Useful when input is provided frequently within short duration.

## Additional properties

Expand Down
4 changes: 2 additions & 2 deletions SearchBox/SearchBox/ControlManifest.Input.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest>
<control namespace="PowerCAT" constructor="SearchBox" version="0.0.1" display-name-key="SearchBox" description-key="SearchBox description" control-type="virtual">
<control namespace="PowerCAT" constructor="SearchBox" version="0.0.1" display-name-key="SearchBox" description-key="SearchBox_desc" control-type="virtual">
<property name="SearchText" display-name-key="SearchBox_SearchText" description-key="SearchBox_SearchText_Desc" of-type="SingleLine.Text" usage="output" hidden="true" />
<property name="Theme" display-name-key="Theme" of-type="Multiple" usage="input" required="false" />
<property name="AccessibilityLabel" display-name-key="AccessibilityLabel" of-type="SingleLine.Text" usage="input" required="false" />
Expand All @@ -9,7 +9,7 @@
<property name="DisableAnimation" display-name-key="DisableAnimation" of-type="TwoOptions" usage="input" required="false" />
<property name="PlaceHolderText" display-name-key="PlaceHolderText" of-type="SingleLine.Text" usage="input" required="false" default-value="Search" />
<property name="InputEvent" display-name-key="InputEvent" of-type="SingleLine.Text" usage="input" required="false"/>

<property name="DelayOutput" display-name-key="DelayOutput" of-type="TwoOptions" usage="input" required="false" />
<resources>
<code path="index.ts" order="1" />
<resx path="strings/SearchBox.1033.resx" version="1.0.0" />
Expand Down
1 change: 1 addition & 0 deletions SearchBox/SearchBox/__mocks__/mock-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export function getMockParameters(): IInputs {
IconName: new MockStringProperty(),
DisableAnimation: new MockTwoOptionsProperty(),
InputEvent: new MockStringProperty(),
DelayOutput: new MockTwoOptionsProperty(),
};
}
32 changes: 25 additions & 7 deletions SearchBox/SearchBox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@ import { IInputs, IOutputs } from './generated/ManifestTypes';
import { SearchBoxComponent } from './components/SearchBox';
import { ISearchBoxComponentProps } from './components/Component.types';
import { InputEvents } from './ManifestConstants';
import { Async } from '@fluentui/react';

export class SearchBox implements ComponentFramework.ReactControl<IInputs, IOutputs> {
private static readonly DELAY_TIMEOUT: number = 500;
context: ComponentFramework.Context<IInputs>;
notifyOutputChanged: () => void;
searchTextValue: string | null;
notifyOutputChanged: ((debounce?: boolean) => void) | null;
searchTextValue: string;
setFocus = '';
asyncFluent: Async;
debouncedOutputChanged: (debounce?: boolean) => void;
delayOutput: boolean;

constructor() {
this.onChange = this.onChange.bind(this);
this.asyncFluent = new Async();
}

/**
* Used to initialize the control instance. Controls can kick off remote server calls and other initialization actions here.
Expand All @@ -17,9 +28,12 @@ export class SearchBox implements ComponentFramework.ReactControl<IInputs, IOutp
* @param container If a control is marked control-type='standard', it will receive an empty div element within which it can render its content.
*/
public init(context: ComponentFramework.Context<IInputs>, notifyOutputChanged: () => void): void {
this.notifyOutputChanged = notifyOutputChanged;
this.context = context;
this.context.mode.trackContainerResize(true);
this.notifyOutputChanged = notifyOutputChanged;
if (this.notifyOutputChanged) {
this.debouncedOutputChanged = this.asyncFluent.debounce(this.notifyOutputChanged, SearchBox.DELAY_TIMEOUT);
}
}

/**
Expand All @@ -29,6 +43,7 @@ export class SearchBox implements ComponentFramework.ReactControl<IInputs, IOutp
public updateView(context: ComponentFramework.Context<IInputs>): React.ReactElement {
const allocatedWidth = parseInt(context.mode.allocatedWidth as unknown as string);
const allocatedHeight = parseInt(context.mode.allocatedHeight as unknown as string);
this.delayOutput = context.parameters.DelayOutput.raw;
const inputEvent = this.context.parameters.InputEvent.raw;
const eventChanged = inputEvent && this.setFocus !== inputEvent;

Expand Down Expand Up @@ -57,9 +72,11 @@ export class SearchBox implements ComponentFramework.ReactControl<IInputs, IOutp
* Called when a change is detected from the control. Updates the searchTextValue variable that is assigned to the output SearchText.
* @param newValue a string returned as the input search text
*/
private onChange = (newValue: string | undefined): void => {
this.searchTextValue = newValue ?? null;
this.notifyOutputChanged();
private onChange = (newValue?: string): void => {
this.searchTextValue = newValue || '';
this.delayOutput
? this.debouncedOutputChanged && this.debouncedOutputChanged()
: this.notifyOutputChanged && this.notifyOutputChanged();
};

/**
Expand All @@ -77,6 +94,7 @@ export class SearchBox implements ComponentFramework.ReactControl<IInputs, IOutp
* i.e. cancelling any pending remote calls, removing listeners, etc.
*/
public destroy(): void {
// Add code to cleanup control if necessary
this.notifyOutputChanged = null;
this.asyncFluent.dispose();
}
}
6 changes: 6 additions & 0 deletions SearchBox/SearchBox/strings/SearchBox.1033.resx
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,10 @@
<data name="InputEvent" xml:space="preserve">
<value>Input Event</value>
</data>
<data name="DelayOutput" xml:space="preserve">
<value>Delay Output</value>
</data>
<data name="SearchBox_desc" xml:space="preserve">
<value>A component to get search text as input</value>
</data>
</root>