Skip to content

Commit

Permalink
feat(kit): highlight improvements
Browse files Browse the repository at this point in the history
1. Adding support for multiple occurrences
2. Adding support for multiple highlights
3. Adding support for case-sensitive mode
4. Adding support for regexp
  • Loading branch information
MillerSvt committed May 6, 2024
1 parent a9b960d commit 6bc7604
Show file tree
Hide file tree
Showing 37 changed files with 1,000 additions and 141 deletions.
1 change: 1 addition & 0 deletions projects/cdk/types/array-or-value.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type TuiArrayOrValue<T> = T | readonly T[];
1 change: 1 addition & 0 deletions projects/cdk/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './array-or-value';
export * from './autocomplete';
export * from './context';
export * from './deep-partial';
Expand Down
1 change: 1 addition & 0 deletions projects/cdk/utils/miscellaneous/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ export * from './nullable-same';
export * from './provide';
export * from './provide-options';
export * from './pure';
export * from './to-array';
export * from './uniq-by';
export * from './with-styles';
5 changes: 5 additions & 0 deletions projects/cdk/utils/miscellaneous/to-array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type {TuiArrayOrValue} from '@taiga-ui/cdk/types';

export function tuiToArray<T>(value: TuiArrayOrValue<T>): readonly T[] {
return value instanceof Array ? value : [value];
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
>
Search
</tui-input>
<table class="tui-space_top-4">
<table
class="tui-space_top-4"
[tuiHighlight]="search"
>
<thead>
<tr>
<th>Member</th>
Expand All @@ -14,11 +17,7 @@
</thead>
<tbody>
<tr *ngFor="let row of rows">
<td
*ngFor="let cell of row"
[tuiHighlight]="search"
[tuiHighlightColor]="'#228B22'"
>
<td *ngFor="let cell of row">
{{ cell }}
</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
:host {
display: block;
--tui-highlight-background: var(--tui-primary);
--tui-highlight-radius: 5px;
--tui-highlight-color: var(--tui-base-01);
}

table {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<tui-input
tuiTextfieldIconLeft="tuiIconSearchLarge"
[(ngModel)]="search"
>
Search
</tui-input>
<table
tuiHighlightMultiOccurrences
class="tui-space_top-4"
[tuiHighlight]="search"
>
<thead>
<tr>
<th>Member</th>
<th>Nickname</th>
<th>Fate</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let row of rows">
<td *ngFor="let cell of row">
{{ cell }}
</td>
</tr>
</tbody>
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
:host {
display: block;
--tui-highlight-background: var(--tui-primary);
--tui-highlight-radius: 5px;
--tui-highlight-color: var(--tui-base-01);
}

table {
width: 100%;
border-spacing: 0;
}

th,
td {
text-align: left;
border: 1px solid var(--tui-base-03);
height: 3.375rem;
padding: 0 1rem;
vertical-align: middle;
}
22 changes: 22 additions & 0 deletions projects/demo/src/modules/directives/highlight/examples/2/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {Component} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';
import {encapsulation} from '@demo/emulate/encapsulation';

@Component({
selector: 'tui-highlight-example-2',
templateUrl: './index.html',
styleUrls: ['./index.less'],
encapsulation,
changeDetection,
})
export class TuiHighlightExample2 {
protected search = '';

protected readonly rows = [
['King Arthur', '-', 'Arrested'],
['Sir Bedevere', 'The Wise', 'Arrested'],
['Sir Lancelot', 'The Brave', 'Arrested'],
['Sir Galahad', 'The Chaste', 'Killed'],
['Sir Robin', 'The Not-Quite-So-Brave-As-Sir-Lancelot', 'Killed'],
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<table
tuiHighlightMultiOccurrences
class="tui-space_top-4"
[tuiHighlight]="regexp"
>
<thead>
<tr>
<th>Member</th>
<th>Nickname</th>
<th>Fate</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let row of rows">
<td *ngFor="let cell of row">
{{ cell }}
</td>
</tr>
</tbody>
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
:host {
display: block;
--tui-highlight-background: var(--tui-primary);
--tui-highlight-radius: 5px;
--tui-highlight-color: var(--tui-base-01);
}

table {
width: 100%;
border-spacing: 0;
}

th,
td {
text-align: left;
border: 1px solid var(--tui-base-03);
height: 3.375rem;
padding: 0 1rem;
vertical-align: middle;
}
22 changes: 22 additions & 0 deletions projects/demo/src/modules/directives/highlight/examples/3/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {Component} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';
import {encapsulation} from '@demo/emulate/encapsulation';

@Component({
selector: 'tui-highlight-example-3',
templateUrl: './index.html',
styleUrls: ['./index.less'],
encapsulation,
changeDetection,
})
export class TuiHighlightExample3 {
protected readonly rows = [
['King Arthur', '-', 'Arrested'],
['Sir Bedevere', 'The Wise', 'Arrested'],
['Sir Lancelot', 'The Brave', 'Arrested'],
['Sir Galahad', 'The Chaste', 'Killed'],
['Sir Robin', 'The Not-Quite-So-Brave-As-Sir-Lancelot', 'Killed'],
];

protected readonly regexp = [/S[a-z]+/g, /A[a-z]+/g];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<table
tuiHighlightMultiOccurrences
class="tui-space_top-4"
[tuiHighlight]="search | tuiToRegexp"
>
<thead>
<tr>
<th>Member</th>
<th>Nickname</th>
<th>Fate</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let row of rows">
<td *ngFor="let cell of row">
{{ cell }}
</td>
</tr>
</tbody>
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
:host {
display: block;
--tui-highlight-background: var(--tui-primary);
--tui-highlight-radius: 5px;
--tui-highlight-color: var(--tui-base-01);
}

table {
width: 100%;
border-spacing: 0;
}

th,
td {
text-align: left;
border: 1px solid var(--tui-base-03);
height: 3.375rem;
padding: 0 1rem;
vertical-align: middle;
}
23 changes: 23 additions & 0 deletions projects/demo/src/modules/directives/highlight/examples/4/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Component} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';
import {encapsulation} from '@demo/emulate/encapsulation';

@Component({
selector: 'tui-highlight-example-4',
templateUrl: './index.html',
styleUrls: ['./index.less'],
encapsulation,
changeDetection,
})
export class TuiHighlightExample4 {
protected readonly rows = [
['King Arthur', '-', 'Arrested'],
['Sir Bedevere', 'The Wise', 'Arrested'],
['Sir Lancelot', 'The Brave', 'Arrested'],
['Sir Galahad', 'The Chaste', 'Killed'],
['Sir Robin', 'The Not-Quite-So-Brave-As-Sir-Lancelot', 'Killed'],
];

/* cspell:disable-next-line */
protected readonly search = ['Sir', 'Arrested', 'killed'];
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
```ts
import {TuiHighlightModule} from '@taiga-ui/kit';
import {TuiHighlightDirective} from '@taiga-ui/kit';

// ...

@NgModule({
imports: [
// ...
TuiHighlightModule,
TuiHighlightDirective,
],
// ...
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
```html
<div
class="block"
[tuiHighlight]="query"
[tuiHighlightColor]="'#228B22'"
>
...
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,26 @@ import type {TuiDocExample} from '@taiga-ui/addon-doc';
changeDetection,
})
export class ExampleTuiHighlightComponent {
protected readonly exampleModule = import('./examples/import/import-module.md?raw');
protected readonly exampleHtml = import('./examples/import/insert-template.md?raw');
public readonly exampleModule = import('./examples/import/import-module.md?raw');
public readonly exampleHtml = import('./examples/import/insert-template.md?raw');

protected readonly example1: TuiDocExample = {
public readonly example1: TuiDocExample = {
TypeScript: import('./examples/1/index.ts?raw'),
HTML: import('./examples/1/index.html?raw'),
};

public readonly example2: TuiDocExample = {
TypeScript: import('./examples/2/index.ts?raw'),
HTML: import('./examples/2/index.html?raw'),
};

public readonly example3: TuiDocExample = {
TypeScript: import('./examples/3/index.ts?raw'),
HTML: import('./examples/3/index.html?raw'),
};

public readonly example4: TuiDocExample = {
TypeScript: import('./examples/4/index.ts?raw'),
HTML: import('./examples/4/index.html?raw'),
};
}
16 changes: 13 additions & 3 deletions projects/demo/src/modules/directives/highlight/highlight.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,33 @@ import {RouterModule} from '@angular/router';
import {TuiSetupComponent} from '@demo/utils';
import {TuiAddonDocModule, tuiGenerateRoutes} from '@taiga-ui/addon-doc';
import {TuiTextfieldControllerModule} from '@taiga-ui/core';
import {TuiHighlightModule, TuiInputModule} from '@taiga-ui/kit';
import {TuiHighlightDirective, TuiInputModule, TuiToRegexpModule} from '@taiga-ui/kit';

import {TuiHighlightExample1} from './examples/1';
import {TuiHighlightExample2} from './examples/2';
import {TuiHighlightExample3} from './examples/3';
import {TuiHighlightExample4} from './examples/4';
import {ExampleTuiHighlightComponent} from './highlight.component';

@NgModule({
imports: [
CommonModule,
FormsModule,
TuiInputModule,
TuiHighlightModule,
TuiHighlightDirective,
TuiAddonDocModule,
RouterModule.forChild(tuiGenerateRoutes(ExampleTuiHighlightComponent)),
TuiTextfieldControllerModule,
TuiToRegexpModule,
TuiSetupComponent,
],
declarations: [ExampleTuiHighlightComponent, TuiHighlightExample1],
declarations: [
ExampleTuiHighlightComponent,
TuiHighlightExample1,
TuiHighlightExample2,
TuiHighlightExample3,
TuiHighlightExample4,
],
exports: [ExampleTuiHighlightComponent],
})
export class ExampleTuiHighlightModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,36 @@
<p>Directive is used to highlight text in element</p>

<tui-doc-example
id="usage"
heading="Usage"
id="single-occurrence-usage"
heading="Single Occurrence Usage"
[content]="example1"
>
<tui-highlight-example-1 />
</tui-doc-example>

<tui-doc-example
id="multi-occurrences-usage"
heading="Multi Occurrences Usage"
[content]="example2"
>
<tui-highlight-example-2 />
</tui-doc-example>

<tui-doc-example
id="regexp-array-usage"
heading="Regexp Array Usage"
[content]="example3"
>
<tui-highlight-example-3 />
</tui-doc-example>

<tui-doc-example
id="search-array-usage"
heading="Search Array Usage"
[content]="example4"
>
<tui-highlight-example-4 />
</tui-doc-example>
</ng-template>

<ng-template pageTab="Setup">
Expand Down
3 changes: 3 additions & 0 deletions projects/demo/src/utils/setup.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export class TuiSetupComponent {
@Input()
public template: TuiRawLoaderContent = '';

@Input()
public styles: TuiRawLoaderContent = '';

@tuiPure
protected get computedImport(): TuiRawLoaderContent {
return (
Expand Down
Loading

0 comments on commit 6bc7604

Please sign in to comment.