11import * as React from "react" ;
2- import styled from "styled-components" ;
2+ import styled , { css } from "styled-components" ;
33import theme from "../../theme" ;
44
55export type BreadcrumbsList = {
66 label : string ;
77 uri : string ;
8+ isDisabled ?: boolean ;
89} ;
910
1011export type BreadcrumbsListProps = {
1112 list : BreadcrumbsList [ ] ;
12- Component ?: React . FC < { to : string } > ;
13+ Component ?: React . FC < { to : string ; isDisabled ?: boolean } > ;
1314} ;
1415
16+ export function Breadcrumbs ( { list, Component } : BreadcrumbsListProps ) {
17+ return (
18+ < StyledBreadcrumbs >
19+ < ul >
20+ { list . map ( ( breadcrumb ) => (
21+ < li key = { breadcrumb . label } >
22+ { Component ? (
23+ < Component
24+ isDisabled = { breadcrumb . isDisabled }
25+ css = { aStyles }
26+ to = { breadcrumb . uri }
27+ >
28+ { breadcrumb . label }
29+ </ Component >
30+ ) : (
31+ < StyledLink
32+ isDisabled = { breadcrumb . isDisabled }
33+ href = { breadcrumb . uri }
34+ >
35+ { breadcrumb . label }
36+ </ StyledLink >
37+ ) }
38+ </ li >
39+ ) ) }
40+ </ ul >
41+ </ StyledBreadcrumbs >
42+ ) ;
43+ }
44+
45+ const aStyles = css `
46+ line-height : 1.125rem ;
47+ font-size : ${ theme . fontSizes . sm } ;
48+ font-weight : ${ theme . fontWeights . regular } ;
49+ font-family : ${ theme . fonts . body } ;
50+ text-decoration : none;
51+ transition : ${ theme . transition } ;
52+ color : ${ theme . color . interactive . link } ;
53+ & : hover ,
54+ & : focus ,
55+ & : active {
56+ opacity : ${ theme . opacity } ;
57+ }
58+ & : hover {
59+ text-decoration : underline;
60+ }
61+ ` ;
62+
1563const StyledBreadcrumbs = styled . nav `
1664 ul {
1765 padding : 0 ;
@@ -24,21 +72,7 @@ const StyledBreadcrumbs = styled.nav`
2472 text-transform : ${ theme . typography . titleCase } ;
2573
2674 a {
27- line-height: 1.125rem;
28- font-size: ${ theme . fontSizes . sm } ;
29- font-weight: ${ theme . fontWeights . regular } ;
30- font-family: ${ theme . fonts . body } ;
31- color: ${ theme . color . interactive . link } ;
32- text-decoration: none;
33- transition: ${ theme . transition } ;
34- &:hover,
35- &:focus,
36- &:active {
37- opacity: ${ theme . opacity } ;
38- }
39- &:hover {
40- text-decoration: underline;
41- }
75+ ${ aStyles }
4276 }
4377
4478 & : after {
@@ -62,20 +96,14 @@ const StyledBreadcrumbs = styled.nav`
6296 }
6397` ;
6498
65- export function Breadcrumbs ( { list, Component } : BreadcrumbsListProps ) {
66- return (
67- < StyledBreadcrumbs >
68- < ul >
69- { list . map ( ( br ) => (
70- < li key = { br . label } >
71- { Component ? (
72- < Component to = { br . uri || "" } > { br . label } </ Component >
73- ) : (
74- < a href = { br . uri || "" } > { br . label } </ a >
75- ) }
76- </ li >
77- ) ) }
78- </ ul >
79- </ StyledBreadcrumbs >
80- ) ;
81- }
99+ const disabledLinkStyles = css `
100+ pointer-events : none;
101+ color : ${ theme . color . text . text02 } ;
102+ ` ;
103+
104+ const StyledLink = styled . a < { isDisabled ?: boolean } > `
105+ && {
106+ ${ aStyles }
107+ ${ ( props ) => ( props . isDisabled ? disabledLinkStyles : { } ) }
108+ }
109+ ` ;
0 commit comments