(bugfix): fix Breadcrumb/CookieConsent linkComponent typing for react-router
Some checks are pending
Storybook tests / storybook-tests (push) Waiting to run

This commit is contained in:
Maksym Sadovnychyy 2026-08-12 16:42:28 +02:00
parent ecce33e42f
commit 55611f8c3b
7 changed files with 61 additions and 27 deletions

View File

@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.4.4] - 2026-08-12
### Fixed
- `Breadcrumb` / `CookieConsent` `linkComponent` typing: `to` is required on the injected link props (and always passed when rendering links), so react-router `Link` is assignable without a host adapter. Exports: `BreadcrumbLinkComponent`, `CookieConsentLinkComponent`.
## [0.4.3] - 2026-08-06 ## [0.4.3] - 2026-08-06
### Added ### Added

View File

@ -14,12 +14,15 @@ export interface BreadcrumbItem {
linkProps?: Record<string, unknown> linkProps?: Record<string, unknown>
} }
type BreadcrumbLinkComponent = ComponentType<{ /**
* Injectable link surface for SPA routers.
* `to` is always provided when Breadcrumb renders a link, so react-router `Link` is assignable.
*/
export type BreadcrumbLinkComponent = ComponentType<{
to: string
href?: string href?: string
to?: string
className?: string className?: string
children?: ReactNode children?: ReactNode
[key: string]: unknown
}> }>
export interface BreadcrumbProps { export interface BreadcrumbProps {
@ -89,10 +92,10 @@ const Breadcrumb: FC<BreadcrumbProps> = ({
</span> </span>
) : null} ) : null}
{isLink ? ( {isLink && target ? (
<LinkComponent <LinkComponent
href={item.href ?? (typeof item.to === 'string' ? item.to : undefined)} href={item.href ?? (typeof item.to === 'string' ? item.to : undefined)}
to={item.to ?? item.href} to={target}
className={linkClassName} className={linkClassName}
{...(item.linkProps ?? {})} {...(item.linkProps ?? {})}
> >

View File

@ -1,2 +1,6 @@
export { Breadcrumb } from './Breadcrumb' export { Breadcrumb } from './Breadcrumb'
export type { BreadcrumbProps, BreadcrumbItem } from './Breadcrumb' export type {
BreadcrumbProps,
BreadcrumbItem,
BreadcrumbLinkComponent,
} from './Breadcrumb'

View File

@ -17,12 +17,15 @@ export interface CookieConsentLink {
linkProps?: Record<string, unknown> linkProps?: Record<string, unknown>
} }
type ConsentLinkComponent = ComponentType<{ /**
* Injectable link surface for SPA routers.
* `to` is always provided when CookieConsent renders a link, so react-router `Link` is assignable.
*/
export type CookieConsentLinkComponent = ComponentType<{
to: string
href?: string href?: string
to?: string
className?: string className?: string
children?: ReactNode children?: ReactNode
[key: string]: unknown
}> }>
export interface CookieConsentProps { export interface CookieConsentProps {
@ -33,13 +36,13 @@ export interface CookieConsentProps {
cookieName?: string cookieName?: string
cookieDays?: number cookieDays?: number
/** Host injects `Link` from react-router (or any anchor-like component). Defaults to `<a>`. */ /** Host injects `Link` from react-router (or any anchor-like component). Defaults to `<a>`. */
linkComponent?: ConsentLinkComponent linkComponent?: CookieConsentLinkComponent
onAccept?: () => void onAccept?: () => void
onDismiss?: () => void onDismiss?: () => void
className?: string className?: string
} }
const DefaultLink: ConsentLinkComponent = ({ const DefaultLink: CookieConsentLinkComponent = ({
href, href,
to, to,
children, children,
@ -108,18 +111,24 @@ const CookieConsent: FC<CookieConsentProps> = ({
{message} {message}
{links.length > 0 ? ( {links.length > 0 ? (
<ul className={'mt-2 flex flex-wrap gap-x-3 gap-y-1'}> <ul className={'mt-2 flex flex-wrap gap-x-3 gap-y-1'}>
{links.map((link, index) => ( {links.map((link, index) => {
<li key={index}> const target = link.to ?? link.href
<LinkComponent if (!target)
href={link.href ?? (typeof link.to === 'string' ? link.to : undefined)} return null
to={link.to ?? link.href}
className={'text-sky-700 underline hover:text-sky-900'} return (
{...(link.linkProps ?? {})} <li key={index}>
> <LinkComponent
{link.label} href={link.href ?? (typeof link.to === 'string' ? link.to : undefined)}
</LinkComponent> to={target}
</li> className={'text-sky-700 underline hover:text-sky-900'}
))} {...(link.linkProps ?? {})}
>
{link.label}
</LinkComponent>
</li>
)
})}
</ul> </ul>
) : null} ) : null}
</div> </div>

View File

@ -1,3 +1,7 @@
export { CookieConsent } from './CookieConsent' export { CookieConsent } from './CookieConsent'
export type { CookieConsentProps, CookieConsentLink } from './CookieConsent' export type {
CookieConsentProps,
CookieConsentLink,
CookieConsentLinkComponent,
} from './CookieConsent'
export { getCookie, setCookie } from './cookies' export { getCookie, setCookie } from './cookies'

View File

@ -4,7 +4,11 @@ export { SecretComponent } from './components/editors/SecretComponent'
export type { SecretDataSource, SecretComponentProps } from './components/editors/SecretComponent' export type { SecretDataSource, SecretComponentProps } from './components/editors/SecretComponent'
export { FormContainer, FormContent, FormFooter, FormHeader } from './components/FormLayout' export { FormContainer, FormContent, FormFooter, FormHeader } from './components/FormLayout'
export { Breadcrumb } from './components/Breadcrumb' export { Breadcrumb } from './components/Breadcrumb'
export type { BreadcrumbProps, BreadcrumbItem } from './components/Breadcrumb' export type {
BreadcrumbProps,
BreadcrumbItem,
BreadcrumbLinkComponent,
} from './components/Breadcrumb'
export { Offcanvas } from './components/Offcanvas' export { Offcanvas } from './components/Offcanvas'
export { Modal, ConfirmDialog } from './components/Modal' export { Modal, ConfirmDialog } from './components/Modal'
export type { ModalProps, ModalSize, ConfirmDialogProps } from './components/Modal' export type { ModalProps, ModalSize, ConfirmDialogProps } from './components/Modal'
@ -22,7 +26,11 @@ export type { MasonryProps } from './components/Masonry'
export { LightBox } from './components/LightBox' export { LightBox } from './components/LightBox'
export type { LightBoxProps, LightBoxSlide } from './components/LightBox' export type { LightBoxProps, LightBoxSlide } from './components/LightBox'
export { CookieConsent, getCookie, setCookie } from './components/CookieConsent' export { CookieConsent, getCookie, setCookie } from './components/CookieConsent'
export type { CookieConsentProps, CookieConsentLink } from './components/CookieConsent' export type {
CookieConsentProps,
CookieConsentLink,
CookieConsentLinkComponent,
} from './components/CookieConsent'
export { export {
WhatsAppButton, WhatsAppButton,
buildWhatsAppHref, buildWhatsAppHref,

View File

@ -1,6 +1,6 @@
{ {
"name": "@maks-it.com/webui", "name": "@maks-it.com/webui",
"version": "0.4.3", "version": "0.4.4",
"description": "Shared contracts, utilities, and React components for MaksIT WebUI apps", "description": "Shared contracts, utilities, and React components for MaksIT WebUI apps",
"type": "module", "type": "module",
"main": "./dist/index.cjs", "main": "./dist/index.cjs",