Skip to content

feat(ui5-search): add samples to playground #11148

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 3 commits into from
Mar 25, 2025
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
1 change: 1 addition & 0 deletions packages/fiori/src/SearchFieldScopeOption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { ISearchFieldScopeOption } from "./SearchField.js";
* @implements {ISearchFieldScopeOption}
* @public
* @since 2.9.0
* @experimental
*/
@customElement("ui5-search-field-scope-option")
class SearchFieldScopeOption extends UI5Element implements ISearchFieldScopeOption {
Expand Down
22 changes: 22 additions & 0 deletions packages/website/docs/_components_pages/fiori/Search/Search.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
sidebar_class_name: newComponentBadge
---

import Basic from "../../../_samples/fiori/Search/Basic/Basic.md";
import Advanced from "../../../_samples/fiori/Search/Advanced/Advanced.md";

<%COMPONENT_OVERVIEW%>

## Basic Sample
A Search component with enabled scope and items and filtering by scope.

<Basic />

<%COMPONENT_METADATA%>

## More Samples

### Filtering
The examples shows filtering per user input, typeahead and highlighting suggestions per user input.

<Advanced />
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
slug: ../SearchFieldScopeOption
sidebar_class_name: newComponentBadge
---

<%COMPONENT_OVERVIEW%>

<%COMPONENT_METADATA%>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
slug: ../SearchItem
sidebar_class_name: newComponentBadge
---

<%COMPONENT_OVERVIEW%>

<%COMPONENT_METADATA%>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
slug: ../SearchItemGroup
sidebar_class_name: newComponentBadge
---

<%COMPONENT_OVERVIEW%>

<%COMPONENT_METADATA%>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import html from '!!raw-loader!./sample.html';
import js from '!!raw-loader!./main.js';

<Editor html={html} js={js} />
45 changes: 45 additions & 0 deletions packages/website/docs/_samples/fiori/Search/Advanced/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

import "@ui5/webcomponents-fiori/dist/Search.js";
import "@ui5/webcomponents-fiori/dist/SearchItem.js";

const data = [
{ name: "Red Apple", category: "Fruit" },
{ name: "Apple", category: "Fruit" },
{ name: "Cucumber", category: "Vegetable" },
{ name: "Orange", category: "Fruit" },
{ name: "Tomato", category: "Vegetable" },
];

function onDelete(event) {
const item = event.target;
if (item) {
item.remove();
}
}

function createItems(parent, data) {
data.forEach(item => {
const searchItem = document.createElement("ui5-search-item");
searchItem.headingText = item.name;
searchItem.icon = "search";
searchItem.addEventListener("ui5-delete", onDelete);
parent.appendChild(searchItem);
});
}

const filtering = document.getElementById("filtering");
createItems(filtering, data);
filtering.addEventListener("ui5-input", (event) => {
const value = event.target.value.toLowerCase();
const filteredData = data.filter(item => item.name.toLowerCase().includes(value));

// clear search items
filtering.innerHTML = "";

filtering.getSlottedNodes("items").forEach(item => {
item.remove();
});

// create search items based on search
createItems(filtering, filteredData);
});
20 changes: 20 additions & 0 deletions packages/website/docs/_samples/fiori/Search/Advanced/sample.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!-- playground-fold -->
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sample</title>
</head>

<body style="background-color: var(--sapBackgroundColor); height: 350px">
<!-- playground-fold-end -->
<ui5-search id="filtering" show-popup-action popup-action-text="Show all search results" expanded show-clear-icon placeholder="Start typing ..."></ui5-search>
</div>
<!-- playground-fold -->
<script type="module" src="main.js"></script>
</body>

</html>
<!-- playground-fold-end -->
4 changes: 4 additions & 0 deletions packages/website/docs/_samples/fiori/Search/Basic/Basic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import html from '!!raw-loader!./sample.html';
import js from '!!raw-loader!./main.js';

<Editor html={html} js={js} />
44 changes: 44 additions & 0 deletions packages/website/docs/_samples/fiori/Search/Basic/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

import "@ui5/webcomponents-fiori/dist/Search.js";
import "@ui5/webcomponents-fiori/dist/SearchItem.js";
import "@ui5/webcomponents-fiori/dist/SearchFieldScopeOption.js";

const scopeData = [
{ name: "Laptop", scope: "products" },
{ name: "Leave Requests", scope: "apps" },
{ name: "Log work", scope: "apps" },
{ name: "Manage Products", scope: "apps" },
{ name: "Mobile Phones", scope: "products" },
{ name: "Tablet", scope: "products" },
];

function createScopeItems(scope) {
let filterData = [];

if (!scope) {
filterData = scopeData;
} else {
filterData = scopeData.filter(item => item.scope === scope);
}

filterData.forEach(item => {
const searchItem = document.createElement("ui5-search-item");
searchItem.headingText = item.name;
searchItem.scopeName = item.scope;
searchScope.appendChild(searchItem);
});
}

const searchScope = document.getElementById("search-scope");

createScopeItems();

searchScope.addEventListener("ui5-scope-change", (event) => {
const scope = event.detail.scope.text === "All" ? "" : event.detail.scope.text.toLowerCase();

searchScope.items.forEach(item => {
item.remove();
});

createScopeItems(scope);
});
24 changes: 24 additions & 0 deletions packages/website/docs/_samples/fiori/Search/Basic/sample.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- playground-fold -->
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sample</title>
</head>

<body style="background-color: var(--sapBackgroundColor); height: 350px">
<!-- playground-fold-end -->
<ui5-search id="search-scope" mode="Scoped" expanded show-clear-icon placeholder="Search Apps, Products">
<ui5-search-field-scope-option text="All" selected slot="scopeOptions"></ui5-search-field-scope-option>
<ui5-search-field-scope-option text="Apps" slot="scopeOptions"></ui5-search-field-scope-option>
<ui5-search-field-scope-option text="Products" slot="scopeOptions"></ui5-search-field-scope-option>
</ui5-search>
</div>
<!-- playground-fold -->
<script type="module" src="main.js"></script>
</body>

</html>
<!-- playground-fold-end -->