Skip to content

Commit

Permalink
fix: enhanced breadcrumbs style (#390)
Browse files Browse the repository at this point in the history
* fix: enhanced breadcrumbs style

* fix: linting error 0 unit

---------

Co-authored-by: Leonardo Di Vittorio <leonardo.divittorio@Leonardos-MacBook-Pro.local>
  • Loading branch information
div-Leo and Leonardo Di Vittorio authored Oct 11, 2023
1 parent 8edfd4d commit e364381
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/components/Breadcrumbs/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import React, { Children, ComponentPropsWithoutRef, ReactElement, ReactNode, cloneElement } from 'react';
import React, {
Children,
ComponentPropsWithoutRef,
ReactElement,
ReactNode,
cloneElement,
useEffect,
useRef
} from 'react';
import styled from 'styled-components';
import { MarginProps } from 'styled-system';

import { ChevronRightIcon } from '../../icons';
import { Text } from '../Text/Text';
Expand All @@ -17,7 +26,7 @@ interface InvertedStyle {
inverted?: boolean;
}

interface BreadcrumbsProps extends InvertedStyle {
interface BreadcrumbsProps extends InvertedStyle, MarginProps {
/**
* Content of the Breadcrumbs
* @required
Expand All @@ -33,17 +42,31 @@ const BreadcrumbsList = styled.ul`
padding: 0;
list-style: none;
display: flex;
overflow: auto;
scrollbar-width: none;
&::-webkit-scrollbar {
width: 0;
}
`;

const BreadcrumbsListItem = styled.li`
display: flex;
text-wrap: nowrap;
`;

const Breadcrumbs = ({ children, inverted }: BreadcrumbsProps): JSX.Element => {
const arrayChildren = Children.toArray(children);
const breadcrumbsListRef = useRef<HTMLUListElement | null>(null);

useEffect(() => {
if (breadcrumbsListRef.current) {
breadcrumbsListRef.current.scrollLeft = breadcrumbsListRef.current.scrollWidth;
}
}, []);

return (
<BreadcrumbsList>
<BreadcrumbsList ref={breadcrumbsListRef}>
{Children.map(arrayChildren, (child, index) => (
<BreadcrumbsListItem>
<nav aria-label="breadcrumbs">
Expand Down

0 comments on commit e364381

Please sign in to comment.