-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add breadcrumbs component and add it to strategies (#1505)
- Loading branch information
1 parent
64ebbcd
commit 66677f7
Showing
12 changed files
with
253 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { forwardRef } from 'react'; | ||
|
||
import { Icon, IconProps } from '@/component-library/Icon'; | ||
|
||
const ChevronRight = forwardRef<SVGSVGElement, IconProps>((props, ref) => ( | ||
<Icon | ||
{...props} | ||
ref={ref} | ||
xmlns='http://www.w3.org/2000/svg' | ||
fill='none' | ||
viewBox='0 0 24 24' | ||
strokeWidth='1.5' | ||
stroke='currentColor' | ||
> | ||
<path strokeLinecap='round' strokeLinejoin='round' d='M8.25 4.5l7.5 7.5-7.5 7.5' /> | ||
</Icon> | ||
)); | ||
|
||
ChevronRight.displayName = 'ChevronRight'; | ||
|
||
export { ChevronRight }; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { AriaBreadcrumbsProps, useBreadcrumbItem } from '@react-aria/breadcrumbs'; | ||
import { mergeProps } from '@react-aria/utils'; | ||
import { AnchorHTMLAttributes, Fragment, useRef } from 'react'; | ||
|
||
import { ChevronRight } from '@/assets/icons'; | ||
|
||
import { TextLinkProps } from '../TextLink'; | ||
import { StyledLinkBreadcrumb, StyledSpanBreadcrumb } from './Breadcrumbs.style'; | ||
|
||
type Props = { | ||
isDisabled?: boolean; | ||
isCurrent: boolean; | ||
to: TextLinkProps['to']; | ||
}; | ||
|
||
type InheritAttrs = Omit<AriaBreadcrumbsProps, keyof Props>; | ||
|
||
type NativeAttrs = Omit<AnchorHTMLAttributes<unknown>, keyof (Props & InheritAttrs)>; | ||
|
||
type BreadcrumbItemProps = Props & NativeAttrs & InheritAttrs; | ||
|
||
const BreadcrumbItem = ({ children, isDisabled, isCurrent, to, ...props }: BreadcrumbItemProps): JSX.Element => { | ||
const ref = useRef(null); | ||
const { itemProps } = useBreadcrumbItem( | ||
{ | ||
...props, | ||
children, | ||
isDisabled: isCurrent, | ||
elementType: isCurrent ? 'span' : 'a' | ||
}, | ||
ref | ||
); | ||
|
||
const commonProps: Pick<TextLinkProps, 'size' | 'color'> = { | ||
size: 's', | ||
color: isCurrent ? 'secondary' : 'tertiary' | ||
}; | ||
|
||
return ( | ||
<Fragment> | ||
{isCurrent ? ( | ||
<StyledSpanBreadcrumb ref={ref} {...mergeProps(commonProps, itemProps)}> | ||
{children} | ||
</StyledSpanBreadcrumb> | ||
) : ( | ||
<StyledLinkBreadcrumb ref={ref} to={to} $isDisabled={isDisabled} {...mergeProps(commonProps, itemProps)}> | ||
{children} | ||
</StyledLinkBreadcrumb> | ||
)} | ||
{isCurrent === false && <ChevronRight size='xs' color='tertiary' />} | ||
</Fragment> | ||
); | ||
}; | ||
|
||
export { BreadcrumbItem }; | ||
export type { BreadcrumbItemProps }; |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Meta, Story } from '@storybook/react'; | ||
|
||
import { BreadcrumbItem, Breadcrumbs, BreadcrumbsProps } from '.'; | ||
|
||
const Template: Story<BreadcrumbsProps> = (args) => ( | ||
<Breadcrumbs {...args}> | ||
<BreadcrumbItem to='#'>Strategies</BreadcrumbItem> | ||
<BreadcrumbItem to='#'>BTC Passive Income</BreadcrumbItem> | ||
</Breadcrumbs> | ||
); | ||
|
||
const Default = Template.bind({}); | ||
Default.args = {}; | ||
|
||
export { Default }; | ||
|
||
export default { | ||
title: 'Forms/Breadcrumbs', | ||
component: Breadcrumbs | ||
} as Meta; |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import styled from 'styled-components'; | ||
|
||
import { Span } from '../Text'; | ||
import { TextLink } from '../TextLink'; | ||
import { theme } from '../theme'; | ||
|
||
type StyledBreadcrumbProps = { | ||
$isDisabled?: boolean; | ||
}; | ||
|
||
const StyledNav = styled.nav``; | ||
|
||
const StyledList = styled.ul` | ||
flex-wrap: nowrap; | ||
flex: 1 0; | ||
justify-content: flex-start; | ||
margin: 0; | ||
padding: 0; | ||
list-style-type: none; | ||
display: flex; | ||
`; | ||
|
||
const StyledListItem = styled.li` | ||
justify-content: flex-start; | ||
align-items: center; | ||
display: inline-flex; | ||
position: relative; | ||
`; | ||
|
||
const StyledSpanBreadcrumb = styled(Span)<StyledBreadcrumbProps>` | ||
padding: 0 ${theme.spacing.spacing2}; | ||
cursor: default; | ||
`; | ||
|
||
const StyledLinkBreadcrumb = styled(TextLink)<StyledBreadcrumbProps>` | ||
padding: 0 ${theme.spacing.spacing2}; | ||
text-decoration: none; | ||
`; | ||
|
||
export { StyledLinkBreadcrumb, StyledList, StyledListItem, StyledNav, StyledSpanBreadcrumb }; |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { AriaBreadcrumbsProps, useBreadcrumbs } from '@react-aria/breadcrumbs'; | ||
import { Children, forwardRef, HTMLAttributes, isValidElement, ReactElement } from 'react'; | ||
|
||
import { useDOMRef } from '../utils/dom'; | ||
import { BreadcrumbItem } from './BreadcrumbItem'; | ||
import { StyledList, StyledListItem, StyledNav } from './Breadcrumbs.style'; | ||
|
||
type Props = { | ||
onAction?: (key: React.Key) => void; | ||
isDisabled?: boolean; | ||
}; | ||
|
||
type NativeAttrs = Omit<HTMLAttributes<unknown>, keyof Props>; | ||
|
||
type InheritAttrs = Omit<AriaBreadcrumbsProps, keyof Props>; | ||
|
||
type BreadcrumbsProps = Props & NativeAttrs & InheritAttrs; | ||
|
||
const Breadcrumbs = forwardRef<HTMLElement, BreadcrumbsProps>( | ||
({ children, isDisabled, ...props }, ref): JSX.Element => { | ||
const domRef = useDOMRef(ref); | ||
|
||
const { navProps } = useBreadcrumbs(props); | ||
|
||
const childArray: ReactElement[] = []; | ||
Children.forEach(children, (child) => { | ||
if (isValidElement(child)) { | ||
childArray.push(child); | ||
} | ||
}); | ||
|
||
const lastIndex = childArray.length - 1; | ||
|
||
const breadcrumbItems = childArray.map((child, index) => { | ||
const isCurrent = index === lastIndex; | ||
|
||
return ( | ||
<StyledListItem key={index}> | ||
<BreadcrumbItem {...child.props} isCurrent={isCurrent} isDisabled={isDisabled} /> | ||
</StyledListItem> | ||
); | ||
}); | ||
|
||
return ( | ||
<StyledNav {...navProps} ref={domRef}> | ||
<StyledList>{breadcrumbItems}</StyledList> | ||
</StyledNav> | ||
); | ||
} | ||
); | ||
|
||
Breadcrumbs.displayName = 'Breadcrumbs'; | ||
|
||
export { Breadcrumbs }; | ||
export type { BreadcrumbsProps }; |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { BreadcrumbItem as LibBreadcrumbItem, BreadcrumbItemProps as LibBreadcrumbItemProps } from './BreadcrumbItem'; | ||
|
||
type BreadcrumbItemProps = Omit<LibBreadcrumbItemProps, 'isCurrent'>; | ||
|
||
const BreadcrumbItem = (props: BreadcrumbItemProps): JSX.Element => <LibBreadcrumbItem isCurrent={false} {...props} />; | ||
|
||
export type { BreadcrumbsProps } from './Breadcrumbs'; | ||
export { Breadcrumbs } from './Breadcrumbs'; | ||
export { BreadcrumbItem }; | ||
export type { BreadcrumbItemProps }; |
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
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
66677f7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
interbtc-ui-kintsugi-testnet – ./
interbtc-ui.vercel.app
kintnet.interlay.io
interbtc-ui-kintsugi-testnet-git-master-interlay.vercel.app
interbtc-ui-kintsugi-testnet-interlay.vercel.app
66677f7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
interbtc-ui-interlay-testnet – ./
interbtc-ui-interlay-testnet.vercel.app
interbtc-ui-interlay-testnet-interlay.vercel.app
interbtc-ui-interlay-testnet-git-master-interlay.vercel.app
testnet.interlay.io