import { BlockDefinition, ResolvableString } from '@ministryofjustice/hmpps-forge/core/components' import { nunjucksComponent } from '../../utils/nunjucksComponent' /** * GOV.UK Back Link component. * * Use this to help users go back to the previous page in a multi-page transaction. * Should be placed at the top of the page, before the main content. * * @see https://design-system.service.gov.uk/components/back-link/ * @example * ```typescript * GovUKBackLink({ * href: '/previous-page', * }) * * // With custom text * GovUKBackLink({ * href: '/dashboard', * text: 'Return to dashboard', * }) * ``` */ export interface GovUKBackLink extends BlockDefinition { /** * The value of the link's `href` attribute. * This is the URL that the user will be taken to when they click the back link. */ href: ResolvableString /** * Plain text content for the back link. * Defaults to "Back" if neither `text` nor `html` is provided. * If `html` is provided, this option will be ignored. */ text?: ResolvableString /** * HTML content for the back link. * Takes precedence over `text` if both are provided. * Defaults to "Back" if neither `text` nor `html` is provided. */ html?: ResolvableString /** * Additional CSS classes to add to the anchor tag. * Use this to apply custom styling or modifier classes. */ classes?: ResolvableString /** * HTML attributes (for example data attributes) to add to the anchor tag. * Useful for adding custom data attributes or ARIA attributes. */ attributes?: Record } /** * GOV.UK Back Link component. * * Use this to help users go back to the previous page in a multi-page transaction. * Should be placed at the top of the page, before the main content. * * @see https://design-system.service.gov.uk/components/back-link/ * @example * ```typescript * GovUKBackLink({ * href: '/previous-page', * }) * * // With custom text * GovUKBackLink({ * href: '/dashboard', * text: 'Return to dashboard', * }) * ``` */ export const GovUKBackLink = nunjucksComponent('govukBackLink', { render: (props, nunjucksEnv) => { const params: Record = { href: props.href, text: props.html ? undefined : props.text, html: props.html, classes: props.classes, attributes: props.attributes, } return nunjucksEnv.render('govuk/components/back-link/template.njk', { params }) }, })