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.

51 lines (50 loc) 2.35 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { Tracer } from '@progress/sitefinity-nextjs-sdk/diagnostics/empty'; import { htmlAttributes } from '../../../editor/widget-framework/attributes'; import { getMinimumWidgetContext } from '../../../editor/widget-framework/widget-context'; import { RenderView } from '../../common/render-view'; import { DateTimeFieldDefaultView } from './date-time-field.view'; import { DateFieldType } from './interfaces/date-field-type'; const InvalidDefaultValidationMessageWithLabel = '{0} field is invalid'; const InvalidDefaultValidationMessage = 'Field is invalid'; export function DateTimeField(props) { const { span } = Tracer.traceWidget(props, false); const entity = props.model.Properties; const viewProps = { cssClass: entity.CssClass, fieldName: entity.SfFieldName, hasDescription: !entity.InstructionalText, label: entity.Label, inputType: getInputType(entity), instructionalText: entity.InstructionalText, validationAttributes: buildValidationAttributes(entity), violationRestrictionsMessages: { invalid: InvalidDefaultValidationMessage, required: entity.RequiredErrorMessage }, attributes: { ...htmlAttributes(props) }, widgetContext: getMinimumWidgetContext(props) }; if (entity.Label) { if (entity.RequiredErrorMessage) { viewProps.violationRestrictionsMessages.required = entity.RequiredErrorMessage.replace('{0}', entity.Label); } viewProps.violationRestrictionsMessages.invalid = InvalidDefaultValidationMessageWithLabel.replace('{0}', entity.Label); } return (_jsx(RenderView, { viewName: entity.SfViewName, widgetKey: props.model.Name, traceSpan: span, viewProps: viewProps, children: _jsx(DateTimeFieldDefaultView, { ...viewProps }) })); } function buildValidationAttributes(entity) { const validationAttributes = {}; if (entity.Required) { validationAttributes['required'] = 'required'; } return validationAttributes; } function getInputType(entity) { switch (entity.FieldType) { case DateFieldType.DateTime: return 'datetime-local'; case DateFieldType.DateOnly: return 'date'; case DateFieldType.TimeOnly: return 'time'; default: return 'date'; } }