Skip to content

Commit 3440e81

Browse files
authored
Merge pull request #145 from sourcefuse/GH-144
docs(arc-ui): update readme
2 parents 3bc0209 + d677bda commit 3440e81

1 file changed

Lines changed: 102 additions & 79 deletions

File tree

  • docs/arc-ui-docs/arc-angular/libraries/search

docs/arc-ui-docs/arc-angular/libraries/search/README.md

Lines changed: 102 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,32 @@
22

33
An Angular module that exports a component that can enable users to search over configured models using the search microservice provided in the sourceloop microservice catalog.
44

5-
### Deprecation Notice
6-
7-
Search-client now supports angular v14, we will provide support for the older version that is based on angular v13 till 30th June 2024.
5+
### Angular Version Compatibility
6+
7+
To ensure smooth integration, install the Search Library version that corresponds to your Angular version:
8+
9+
<table border="1" cellpadding="8" style="border-collapse: collapse; width: 100%; text-align: left;">
10+
<thead>
11+
<tr>
12+
<th>Angular Version</th>
13+
<th>Compatible Search-Client Version</th>
14+
</tr>
15+
</thead>
16+
<tbody>
17+
<tr>
18+
<td>Angular v19</td>
19+
<td>@sourceloop/search-client v8.x</td>
20+
</tr>
21+
<tr>
22+
<td>Angular v20</td>
23+
<td>@sourceloop/search-client v9.x</td>
24+
</tr>
25+
<tr>
26+
<td>Angular v21+</td>
27+
<td>Latest version (v11.x and above)</td>
28+
</tr>
29+
</tbody>
30+
</table>
831

932
## Angular Module
1033

@@ -16,33 +39,21 @@ npm i @sourceloop/search-client
1639

1740
### Usage
1841

19-
Create a new Application using Angular CLI and import the SearchLibModule and add it to the imports array of the module. Also create a new service that implements the ISearchService interface exported by the search library. This service will be used by the exported component to make API calls whenever needed. You will have to update the providers section of your module with { provide: SEARCH_SERVICE_TOKEN, useExisting: Your_Service_Name }
20-
Your module will then look something like this
42+
Create a new Application using Angular CLI and import the `SearchComponent` in your application.SearchComponent is now a standalone component, so no NgModule is required.Also create a new service that implements the ISearchService interface exported by the search library. This service will be used by the exported component to make API calls whenever needed. You will have to update the providers section of your module with { provide: SEARCH_SERVICE_TOKEN, useExisting: Your_Service_Name }
2143

2244
```ts
23-
import { NgModule } from "@angular/core";
24-
import { BrowserModule } from "@angular/platform-browser";
25-
26-
import { AppComponent } from "./app.component";
27-
28-
import { HttpClientModule } from "@angular/common/http";
29-
import { XComponent } from "./x/x.component";
30-
import { ReactiveFormsModule } from "@angular/forms";
31-
32-
import { SearchLibModule, SEARCH_SERVICE_TOKEN } from "search-lib";
33-
import { SearchService } from "./search.service";
34-
@NgModule({
35-
declarations: [AppComponent, XComponent],
36-
imports: [
37-
BrowserModule,
38-
SearchLibModule, //import SearchLibModule
39-
HttpClientModule,
40-
ReactiveFormsModule,
41-
],
42-
providers: [{ provide: SEARCH_SERVICE_TOKEN, useClass: SearchService }], //Add your service here
43-
bootstrap: [AppComponent],
45+
import {Component} from '@angular/core';
46+
import {SearchComponent, SEARCH_SERVICE_TOKEN} from '@sourceloop/search-client';
47+
import {SearchService} from './search.service';
48+
49+
@Component({
50+
selector: 'app-root',
51+
standalone: true,
52+
imports: [SearchComponent],
53+
templateUrl: './app.component.html',
54+
providers: [{provide: SEARCH_SERVICE_TOKEN, useClass: SearchService}],
4455
})
45-
export class AppModule {}
56+
export class AppComponent {}
4657
```
4758

4859
### Search Service
@@ -86,7 +97,6 @@ Apart from these there are some optional properties that you can give:
8697
- **noResultMessage (string) :** Message to display in dropdown incase no matching result found.
8798
- **searchIconClass (string) :** Can be used to give custom icon for search in search bar.
8899
- **crossIconClass (string) :** Can be used to give custom icon for clearing text input in search bar.
89-
- **dropDownButtonIconClass (string) :** Can be used to give custom icon for category drop down button.
90100
- **recentSearchIconClass (string) :** Can be used to give custom icon for recent searches displayed in the search dropdown.
91101

92102
Your component might look something like
@@ -97,16 +107,16 @@ export class XComponent implements OnInit {
97107

98108
constructor(private fb: FormBuilder) {
99109
this.config = new Configuration<IDefaultReturnType>({
100-
displayPropertyName: "name",
110+
displayPropertyName: 'name',
101111
models: [
102112
{
103-
name: "ToDo",
104-
displayName: "List",
113+
name: 'ToDo',
114+
displayName: 'List',
105115
},
106116
{
107-
name: "User",
108-
displayName: "Users",
109-
imageUrl: "https://picsum.photos/id/1/50",
117+
name: 'User',
118+
displayName: 'Users',
119+
imageUrl: 'https://picsum.photos/id/1/50',
110120
},
111121
],
112122
order: [`name ASC`, `description DESC`],
@@ -135,7 +145,7 @@ type ItemClickedEvent<T> = {
135145
type RecentSearchEvent = {
136146
event: KeyboardEvent | Event;
137147
keyword: string;
138-
category: "All" | IModel;
148+
category: 'All' | IModel;
139149
};
140150
```
141151

@@ -149,32 +159,6 @@ type RecentSearchEvent = {
149159
></sourceloop-search>
150160
```
151161

152-
````
153-
`Configuration to show only result overlay without search input box`
154-
There are other parameters which you can configure to use only the search result overlay without search input box
155-
156-
```html
157-
<sourceloop-search
158-
[config]="config"
159-
[(ngModel)]="value"
160-
[showOnlySearchResultOverlay]="true"
161-
[customAllLabel]="customAllLabel"
162-
[customSearchEvent]="customSearchEvent"
163-
></sourceloop-search>
164-
````
165-
166-
You can pass `showOnlySearchResultOverlay` to true to use only search result overlay. You can also pass `customAllLabel` in case you have different model name configuration for performing search in All categories
167-
168-
**Manadatory parameter when you configure `showOnlySearchResultOverlay` to true**
169-
You should pass `customSearchEvent`
170-
171-
```ts
172-
interface CustomSearchEvent {
173-
searchValue: string;
174-
modelName: string;
175-
}
176-
```
177-
178162
### Icons
179163

180164
To use the default icons you will have to import the following in your styles.scss:
@@ -185,6 +169,45 @@ To use the default icons you will have to import the following in your styles.sc
185169

186170
You can also choose to use your own icons by providing classes for icons in the configuration.
187171

172+
### Required Global Styles
173+
174+
The search component uses Angular CDK overlays for the dropdown, which require global styles to function properly.
175+
176+
### Styling and Theming
177+
178+
The search component uses CSS custom properties (CSS variables) for theming, allowing you to customize colors without modifying the library code. You can override these variables in your application's global styles or in a component-specific stylesheet.
179+
180+
#### Available CSS Variables
181+
182+
````scss
183+
sourceloop-search {
184+
--search-background: #f7f7f7; /* Background of the search container */
185+
--search-input-background: #f1f3f4; /* Background of the input field */
186+
--search-input-text-color: #6b6b6b; /* Text color in the input field */
187+
--search-border-hover: #a53159; /* Border color on hover */
188+
--search-border-focus: #90003b; /* Border color when focused */
189+
--search-dropdown-background: #90003b; /* Background of the category dropdown (on hover/focus) */
190+
--search-dropdown-text-color: #ffffff; /* Text color in the category dropdown (on hover/focus) */
191+
--search-highlight-bg: #fee8e8; /* Background color for highlighted suggestions */
192+
--search-heading-color: #9c9c9c; /* Color of category headings */
193+
--search-text-color: #333; /* General text color */
194+
--search-icon-color: #33333380; /* Color of icons */
195+
}
196+
197+
####Example: Custom Theming To customize the search component, add the following
198+
to your `component.scss` ```scss
199+
200+
// Customize component colors
201+
202+
:host ::ng-deep sourceloop-search {
203+
--search-border-hover: #5c26f1 !important;
204+
--search-border-focus: #5c26f1 !important;
205+
--search-dropdown-background: #5c26f2 !important;
206+
}
207+
````
208+
209+
This allows you to match the search component's appearance with your application's design system.
210+
188211
## Web Component
189212

190213
This library is also available as a [Web Component](https://developer.mozilla.org/en-US/docs/Web/Web_Components) so users of frameworks like React and Vue can also integrate this search element in their application with minimal effort.
@@ -218,44 +241,44 @@ The web component accepts all the same inputs and services as the regular Angula
218241
<sourceloop-search-element></sourceloop-search-element>
219242
<script type="text/javascript" src="search-element.js"></script>
220243
<script>
221-
document.addEventListener("DOMContentLoaded", () => {
222-
const element = document.querySelector("sourceloop-search-element");
244+
document.addEventListener('DOMContentLoaded', () => {
245+
const element = document.querySelector('sourceloop-search-element');
223246
// Code to set inputs of the component
224247
element.searchProvider = {
225248
searchApiRequestWithPromise: () =>
226249
Promise.resolve([
227250
{
228-
name: "Test",
229-
description: "Test",
251+
name: 'Test',
252+
description: 'Test',
230253
rank: 0.4,
231-
source: "ToDo",
254+
source: 'ToDo',
232255
},
233256
{
234-
name: "Akshat",
235-
description: "Dubey",
257+
name: 'Akshat',
258+
description: 'Dubey',
236259
rank: 0.4,
237-
source: "User",
260+
source: 'User',
238261
},
239262
]),
240263
recentSearchApiRequestWithPromise: () => Promise.resolve([]),
241264
};
242265
element.config = new SearchConfiguration({
243-
displayPropertyName: "name",
266+
displayPropertyName: 'name',
244267
models: [
245268
{
246-
name: "ToDo",
247-
displayName: "List",
248-
imageUrl: "https://picsum.photos/id/1000/50",
269+
name: 'ToDo',
270+
displayName: 'List',
271+
imageUrl: 'https://picsum.photos/id/1000/50',
249272
},
250273
{
251-
name: "User",
252-
displayName: "Users",
253-
imageUrl: "https://picsum.photos/id/1/50",
274+
name: 'User',
275+
displayName: 'Users',
276+
imageUrl: 'https://picsum.photos/id/1/50',
254277
},
255278
],
256279
order: [`name ASC`, `description DESC`],
257280
hideCategorizeButton: false,
258-
placeholder: "Search Programs, Projects or Dashboards",
281+
placeholder: 'Search Programs, Projects or Dashboards',
259282
categorizeResults: true,
260283
saveInRecents: true,
261284
limit: 4,
@@ -272,10 +295,10 @@ Note that the instance of `SearchService` passed to the element is following a d
272295
export interface ISearchServiceWithPromises<T extends IReturnType> {
273296
searchApiRequestWithPromise(
274297
requestParameters: ISearchQuery,
275-
saveInRecents: boolean
298+
saveInRecents: boolean,
276299
): Promise<T[]>;
277300
recentSearchApiRequestWithPromise?(): Promise<ISearchQuery[]>;
278301
}
279302
```
280303

281-
This facilitates the use of the `Web Component` without relying on [rxjs](https://rxjs.dev/). You can still use the `Observable` based service if you want by importing the rxjs library manually.
304+
This facilitates the use of the `Web Component` without relying on [rxjs](https://rxjs.dev/). You can still use the `Observable` based service if you want by importing the rxjs library manually.

0 commit comments

Comments
 (0)