UNPKG

@progress/sitefinity-nextjs-sdk

Version:

Provides OOB widgets developed using the Next.js framework, which includes an abstraction layer for Sitefinity communication. Additionally, it offers an expanded API, typings, and tools for further development and integration.

43 lines (42 loc) 2.46 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { StyleGenerator } from '../styling/style-generator.service'; import { ListDisplayMode } from '../../editor/widget-framework/list-display-mode'; import { classNames } from '../../editor/utils/classNames'; import { htmlAttributes, getCustomAttributes } from '../../editor/widget-framework/attributes'; import { getMinimumWidgetContext } from '../../editor/widget-framework/widget-context'; import { Tracer } from '@progress/sitefinity-nextjs-sdk/diagnostics/empty'; import { convertToBoolean } from './utils'; import { RenderView } from '../common/render-view'; import { SearchResultsDefaultView } from './search-results.view'; export async function SearchResults(props) { const { span, ctx } = Tracer.traceWidget(props, true); const dataAttributes = htmlAttributes(props); const entity = props.model.Properties; const context = props.requestContext; const cultures = context.layout.Site.Cultures; const currentPageCultureOrDefault = !!(context?.culture) ? context.culture : 'en'; const languageNames = new Intl.DisplayNames(currentPageCultureOrDefault, { type: 'language' }); const languages = cultures.map((culture) => { return { Name: culture, Title: languageNames.of(culture) || culture }; }); const marginClass = entity.Margins && StyleGenerator.getMarginClasses(entity.Margins); const customAttributes = getCustomAttributes(entity.Attributes, 'SearchResults'); dataAttributes['className'] = classNames(entity.CssClass, marginClass); const viewProps = { languagesLabel: entity.LanguagesLabel, resultsNumberLabel: entity.ResultsNumberLabel, cssClass: entity.CssClass || undefined, languages: languages, allowUsersToSortResults: convertToBoolean(entity.AllowUsersToSortResults?.toString()), sorting: entity.Sorting.toString(), sortByLabel: entity.SortByLabel, totalCount: 0, attributes: { ...dataAttributes, ...customAttributes }, widgetContext: getMinimumWidgetContext(props) }; entity.ListSettings = entity.ListSettings || { ItemsPerPage: 20, LimitItemsCount: 20, ShowAllResults: false, DisplayMode: ListDisplayMode.All }; return (_jsx(RenderView, { viewName: entity.SfViewName, widgetKey: props.model.Name, traceSpan: span, viewProps: viewProps, children: _jsx(SearchResultsDefaultView, { ...viewProps }) })); }