-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- allow custom component to be passed - improve sample - allow other props to be passed
- Loading branch information
Showing
5 changed files
with
97 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 11 additions & 25 deletions
36
packages/core/src/components/BreadCrumb/Page/Page.styles.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,22 @@ | ||
import styled from "@emotion/styled"; | ||
import { CSSInterpolation } from "@emotion/css"; | ||
import { outlineStyles } from "@hitachivantara/uikit-react-core"; | ||
import { theme } from "@hitachivantara/uikit-styles"; | ||
import { forwardRef, Ref } from "react"; | ||
import { | ||
HvLink, | ||
HvLinkProps, | ||
HvTypography, | ||
HvTypographyProps, | ||
} from "@core/components"; | ||
|
||
export const StyledLink = styled((props: HvLinkProps) => <HvLink {...props} />)( | ||
{ | ||
export const styles = { | ||
link: { | ||
padding: `8px ${theme.space.xs}`, | ||
textDecoration: "none", | ||
borderRadius: theme.radii.base, | ||
maxWidth: 170 + 16, | ||
textTransform: "capitalize", | ||
"&:hover": { | ||
cursor: "pointer", | ||
backgroundColor: theme.colors.atmo3, | ||
}, | ||
"&:focus": { | ||
backgroundColor: theme.colors.atmo3, | ||
}, | ||
} | ||
); | ||
|
||
export const StyledTypography = styled( | ||
forwardRef((props: HvTypographyProps, ref?: Ref<HTMLElement>) => { | ||
return <HvTypography {...props} ref={ref} />; | ||
}) | ||
)({ | ||
maxWidth: "170px", | ||
textTransform: "capitalize", | ||
"&:hover": { | ||
cursor: "pointer", | ||
backgroundColor: theme.colors.atmo3, | ||
"&:focus-visible": { | ||
...outlineStyles, | ||
}, | ||
}, | ||
}); | ||
} satisfies Record<string, CSSInterpolation>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,51 @@ | ||
import { clsx } from "clsx"; | ||
import { HvOverflowTooltip } from "@core/components"; | ||
import { ClassNames } from "@emotion/react"; | ||
import { | ||
HvBreadCrumbPathElement, | ||
HvOverflowTooltip, | ||
HvTypography, | ||
} from "@core/components"; | ||
import startCase from "lodash/startCase"; | ||
import { MouseEventHandler } from "react"; | ||
import { MouseEvent } from "react"; | ||
import pageClasses, { HvPageClasses } from "./pageClasses"; | ||
import { StyledLink, StyledTypography } from "./Page.styles"; | ||
|
||
export interface HvPageElement { | ||
path?: string; | ||
label?: string; | ||
} | ||
import { styles } from "./Page.styles"; | ||
|
||
export interface HvPageProps { | ||
Component?: React.ElementType; | ||
onClick?: ( | ||
event: MouseEventHandler<HTMLAnchorElement>, | ||
data: any | ||
) => void | undefined; | ||
elem: HvPageElement; | ||
component?: React.ElementType; | ||
onClick?: (event: MouseEvent<HTMLElement>, data: any) => void; | ||
elem: HvBreadCrumbPathElement; | ||
classes?: HvPageClasses; | ||
} | ||
|
||
export const HvPage = ({ | ||
/* Component, */ onClick, | ||
elem, | ||
classes, | ||
}: HvPageProps) => { | ||
export const HvPage = ({ component, onClick, elem, classes }: HvPageProps) => { | ||
const { label, path, ...others } = elem; | ||
const handleClick = (event: MouseEvent<HTMLElement>) => { | ||
event.preventDefault(); | ||
onClick?.(event, elem); | ||
}; | ||
|
||
return ( | ||
<StyledLink | ||
route={elem.path} | ||
// component={Component} | ||
onClick={onClick} | ||
data={elem} | ||
classes={{ a: clsx(pageClasses.a, classes?.a) }} | ||
> | ||
<StyledTypography | ||
noWrap | ||
component="div" | ||
variant="label" | ||
className={clsx( | ||
pageClasses.link, | ||
classes?.link, | ||
pageClasses.label, | ||
classes?.label | ||
)} | ||
> | ||
<HvOverflowTooltip data={startCase(elem.label)} /> | ||
</StyledTypography> | ||
</StyledLink> | ||
<ClassNames> | ||
{({ css, cx }) => ( | ||
<HvTypography | ||
noWrap | ||
variant="label" | ||
component={component || "a"} | ||
href={elem.path} | ||
onClick={onClick && handleClick} | ||
className={cx( | ||
css(styles.link), | ||
pageClasses.link, | ||
classes?.link, | ||
pageClasses.label, | ||
classes?.label, | ||
pageClasses.a, | ||
classes?.a | ||
)} | ||
{...others} | ||
> | ||
<HvOverflowTooltip data={startCase(elem.label)} /> | ||
</HvTypography> | ||
)} | ||
</ClassNames> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters