import { Link, LinkField, Text, TextField, useSitecoreContext, } from '@sitecore-content-sdk/nextjs'; import React, { JSX } from 'react'; interface Fields { data: { datasource: { url: { path: string; siteName: string; }; field: { jsonValue: { value: string; metadata?: { [key: string]: unknown }; }; }; }; contextItem: { url: { path: string; siteName: string; }; field: { jsonValue: { value: string; metadata?: { [key: string]: unknown }; }; }; }; }; } type TitleProps = { params: { [key: string]: string }; fields: Fields; }; type ComponentContentProps = { id: string; styles: string; children: JSX.Element; }; const ComponentContent = (props: ComponentContentProps) => { const id = props.id; return (
{props.children}
); }; export const Default = (props: TitleProps): JSX.Element => { const datasource = props.fields?.data?.datasource || props.fields?.data?.contextItem; const { sitecoreContext } = useSitecoreContext(); const text: TextField = datasource?.field?.jsonValue || {}; const link: LinkField = { value: { href: datasource?.url?.path, title: datasource?.field?.jsonValue?.value, }, }; if (sitecoreContext.pageState !== 'normal') { link.value.querystring = `sc_site=${datasource?.url?.siteName}`; if (!text?.value) { text.value = 'Title field'; link.value.href = '#'; } } return ( <> {sitecoreContext.pageEditing ? ( ) : ( )} ); };