Skip to content

Commit e3680c1

Browse files
authored
Merge pull request #14 from lumapps/chore/search-custom-icons
chore(search): add doc for icon customization
2 parents e87a659 + 2d5f269 commit e3680c1

11 files changed

+108
-0
lines changed

docs/javascript/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ And `configuration` is an object that allows these properties:
8585
| `targets.SEARCH` | Target id for the search page. | [Documentation](./capabilities#search) |
8686
| `targets.SEARCH_BOX` | Target id for the search box. | [Documentation](./capabilities#search-box) |
8787
| `targets.SEARCH_CUSTOM_METADATA` | Target id for search custom metadata. | [Documentation](./capabilities#search-custom-metadata) |
88+
| `targets.SEARCH_RESULT_ICON` | Target id for icons of the search result page and quick search. | [Documentation](./capabilities#search-result-icon) |
8889
| `targets.SEARCH_TAB` | Target id for search tab. | [Documentation](./capabilities#search-tab) |
8990
| `targets.SETTINGS` | Target id for the settings menu. | [Documentation](./capabilities#settings) |
9091
| `targets.SETTINGS_BUTTON` | Target id for the settings icon on the top bar. | [Documentation](./capabilities#settings-button) |
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

docs/javascript/capabilities.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,35 @@ Target that allows customizing the search custom metadata.
517517
| Disable | No compatibility. |
518518
| Changing text | No compatibility. |
519519

520+
### Search result icon
521+
522+
Target that allows customizing icons of the search results of both the search page and quick search.
523+
524+
![Search results icons](./assets/search-icon-custo-doc.png "Search results icons")
525+
526+
![Quick search result icons](./assets/quick-search-icon-custo-doc.png "Quick search result icons")
527+
528+
#### Compatibility
529+
530+
| | |
531+
| ------------- | -------------------------------------- |
532+
| Target ID | `search-result-icon` |
533+
| Description | Target the search result icon. |
534+
| Placements | Compatible with placements: `REPLACE`. |
535+
| Disable | No compatibility. |
536+
| Changing text | No compatibility. |
537+
538+
**Note:** Using `context` it is possible to retrieve data of the search result being customized as well as its type.
539+
This allows specific customization depending on result type / data etc...
540+
In addition, a `SearchThumbnail` component is available to be as close as possible to the current implementation.
541+
542+
#### Use cases
543+
544+
- [Replace icons for a specific result type](./use-cases#replace-icons-for-a-specific-result-type)
545+
- [Replace icons with a custom svg](./use-cases#replace-icons-with-a-custom-svg)
546+
- [Replace icons of documents with a specific mimetype](./use-cases#replace-icons-of-documents-with-a-specific-mimetype)
547+
548+
520549
### Search tab
521550

522551
Target that allows customizing the search tab.

docs/javascript/use-cases.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,3 +933,81 @@ window.lumapps.customize(({ targets, components, render, placement, constants })
933933

934934
![Use case customized not found error page](./assets/use-case-customized-not-found-error-page.png "Use case customized not found error page")
935935

936+
937+
## Replace icons for a specific result type
938+
939+
The following script uses the target `targets.SEARCH_RESULT_ICON` and the placement `placements.REPLACE` in order to replace the default icon used for a specific entity (here, `posts` with a `message-text-outline` default icon) by another mdi icon (`typewriter`).
940+
941+
```js
942+
window.lumapps.customize(({ targets, components, render, placement }) => {
943+
const { SearchThumbnail } = components;
944+
render({
945+
placement: placement.REPLACE,
946+
target: targets.SEARCH_RESULT_ICON,
947+
toRenderWithContext: ({ currentProps, entityType, mimeType }) => {
948+
return SearchThumbnail({
949+
...currentProps,
950+
icon: entityType === 'post' ? 'typewriter' : currentProps.icon,
951+
});
952+
},
953+
});
954+
});
955+
```
956+
957+
![Search result page with icons replaced by the typewriter icon](./assets/search-results-customized-post-icon.png "Search result page with icons replaced by the typewriter icon")
958+
959+
![Quick search opened with icons replaced by the typewriter icon](./assets/quick-search-customized-post-icon.png "Quick search opened with icons replaced by the typewriter icon")
960+
961+
## Replace icons with a custom svg
962+
963+
The following script uses the target `targets.SEARCH_RESULT_ICON` and the placement `placements.REPLACE` in order to replace the default icon used for a specific entity (here, `posts` with a `message-text-outline` default icon) by a custom svg path.
964+
965+
**Note:** By default, search results icons are displayed using the `icon` prop that uses mdi names. In order to override this and use a custom svg, we need to set this prop to `null` and use `iconPath` instead.
966+
967+
```js
968+
window.lumapps.customize(({ targets, components, render, placement }) => {
969+
const { SearchThumbnail } = components;
970+
render({
971+
placement: placement.REPLACE,
972+
target: targets.SEARCH_RESULT_ICON,
973+
toRenderWithContext: ({ currentProps, entityType }) => {
974+
return SearchThumbnail({
975+
...currentProps,
976+
icon: entityType === 'post' ? null : currentProps.icon,
977+
iconPath: entityType === 'post' ? 'M21.35,11.1H12.18V13.83H18.69C18.36,17.64 15.19,19.27 12.19,19.27C8.36,19.27 5,16.25 5,12C5,7.9 8.2,4.73 12.2,4.73C15.29,4.73 17.1,6.7 17.1,6.7L19,4.72C19,4.72 16.56,2 12.1,2C6.42,2 2.03,6.8 2.03,12C2.03,17.05 6.16,22 12.25,22C17.6,22 21.5,18.33 21.5,12.91C21.5,11.76 21.35,11.1 21.35,11.1V11.1Z' : undefined,
978+
});
979+
},
980+
});
981+
});
982+
983+
984+
```
985+
986+
![Search result page with icons replaced by a custom svg](./assets/search-results-icon-custom-svg.png "Search result page with icons replaced by a custom svg")
987+
![Quick search opened with icons replaced by a custom svg](./assets/quick-search-icon-custom-svg.png "Quick search opened with icons replaced by a custom svg")
988+
989+
## Replace icons of documents with a specific mimetype
990+
991+
The following script uses the target `targets.SEARCH_RESULT_ICON` and the placement `placements.REPLACE` in order to replace the default icon used documents with a specific mimetype by another mdi icon.
992+
993+
```js
994+
window.lumapps.customize(({ targets, components, render, placement }) => {
995+
const { SearchThumbnail } = components;
996+
render({
997+
placement: placement.REPLACE,
998+
target: targets.SEARCH_RESULT_ICON,
999+
toRenderWithContext: ({ currentProps, entityType, mimeType }) => {
1000+
const isPdf = mimeType === 'application/pdf';
1001+
return SearchThumbnail({
1002+
...currentProps,
1003+
icon: isPdf ? 'file-pdf' : currentProps.icon,
1004+
});
1005+
},
1006+
});
1007+
});
1008+
1009+
```
1010+
1011+
![Search result page with icons replaced by a custom svg](./assets/search-results-mimetype-custom-icon.png "Search result page with icons replaced by a custom svg")
1012+
1013+
![Quick search opened with icons replaced by a custom svg](./assets/quick-search-mimetype-custom-icon.png "Quick search opened with icons replaced by a custom svg")

0 commit comments

Comments
 (0)