diff --git a/CHANGELOG.md b/CHANGELOG.md index 56970bb5be..aab1034ce7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ - Clean up `react-datepicker` package to remove unnecessary directories and files ([#1067](https://github.com/opensearch-project/oui/pull/1067)) - Bump `@types/react` and `csstype` ([#1105](https://github.com/opensearch-project/oui/pull/1105)) - Add `scripts` folder to lint-es script ([#1143](https://github.com/opensearch-project/oui/pull/1143)) +- Clean up code OUI Breadcrumb component from previous updates ([#1144](https://github.com/opensearch-project/oui/pull/1144)) - Update deprecated Babel plugins ([#1155](https://github.com/opensearch-project/oui/pull/1155)) - Move @seanneumann to emeritus maintainer ([#1188](https://github.com/opensearch-project/oui/pull/1188)) diff --git a/src/components/breadcrumbs/_breadcrumbs.scss b/src/components/breadcrumbs/_breadcrumbs.scss index 26d7433e4d..e75d15cf49 100644 --- a/src/components/breadcrumbs/_breadcrumbs.scss +++ b/src/components/breadcrumbs/_breadcrumbs.scss @@ -25,18 +25,15 @@ .ouiBreadcrumb { display: inline-block; + // TODO: remove important: https://github.com/opensearch-project/oui/issues/376 + color: $ouiBreadcrumbInactiveTextColor !important; // sass-lint:disable-line no-important - &:not(.ouiBreadcrumb--last) { - // TODO: remove important: https://github.com/opensearch-project/oui/issues/376 - color: $ouiBreadcrumbInactiveTextColor !important; // sass-lint:disable-line no-important - - &:hover { - color: $ouiBreadCrumbHoverColor !important; // sass-lint:disable-line no-important - } + &:hover { + color: $ouiBreadCrumbHoverColor !important; // sass-lint:disable-line no-important } } -.ouiBreadcrumbs:not(.ouiBreadcrumbs__inPopover) .ouiBreadcrumb--last { +.ouiBreadcrumbs:not(.ouiBreadcrumbs__inPopover) .ouiBreadcrumbWrapper--last .ouiBreadcrumb { font-weight: $ouiFontWeightMedium; } @@ -114,6 +111,16 @@ margin-bottom: $ouiSizeXS; /* 1 */ padding-left: $ouiSizeL - $ouiSizeXS + calc($ouiBreadcrumbSpacing / 2); } + + // This targets the last breadcrumb wrapper and sets a different text color for the breadcrumb inside it. + &.ouiBreadcrumbWrapper--last .ouiBreadcrumb { + // TODO: remove important: https://github.com/opensearch-project/oui/issues/376 + color: inherit !important; // sass-lint:disable-line no-important + + &:hover { + color: inherit !important; // sass-lint:disable-line no-important + } + } } .ouiBreadcrumbWall { diff --git a/src/components/breadcrumbs/breadcrumbs.tsx b/src/components/breadcrumbs/breadcrumbs.tsx index 94b82627ef..015b91a533 100644 --- a/src/components/breadcrumbs/breadcrumbs.tsx +++ b/src/components/breadcrumbs/breadcrumbs.tsx @@ -241,10 +241,8 @@ export const OuiBreadcrumbs: FunctionComponent = ({ 'ouiBreadcrumb--truncate': truncate, }); - let link; - - if (!href && !onClick) { - link = ( + const link = + !href && !onClick ? ( {(ref, innerText) => ( = ({ )} - ); - } else { - link = ( + ) : ( {(ref, innerText) => ( = ({ )} ); - } - - let wrapper =
{link}
; - if (isFirstBreadcrumb) { - const breadcrumbWallClasses = classNames('ouiBreadcrumbWall', { - 'ouiBreadcrumbWall--single': isLastBreadcrumb, - }); + const breadcrumbWallClasses = classNames('ouiBreadcrumbWall', { + 'ouiBreadcrumbWall--single': isFirstBreadcrumb && isLastBreadcrumb, + }); - wrapper =
{wrapper}
; - } + const wrapper =
{link}
; + const wall = isFirstBreadcrumb ? ( +
{wrapper}
+ ) : ( + wrapper + ); - return {wrapper}; + return {wall}; }); // Use the default object if they simply passed `true` for responsive @@ -297,15 +293,16 @@ export const OuiBreadcrumbs: FunctionComponent = ({ // The max property collapses any breadcrumbs past the max quantity. // This is the same behavior we want for responsiveness. // So calculate the max value based on the combination of `max` and `responsive` - let calculatedMax: OuiBreadcrumbsProps['max'] = max; - // Set the calculated max to the number associated with the currentBreakpoint key if it exists - if (responsive && responsiveObject[currentBreakpoint as OuiBreakpointSize]) { - calculatedMax = responsiveObject[currentBreakpoint as OuiBreakpointSize]; - } - // Final check is to make sure max is used over a larger breakpoint value - if (max && calculatedMax) { - calculatedMax = max < calculatedMax ? max : calculatedMax; - } + + // First, calculate the responsive max value + const responsiveMax = + responsive && responsiveObject[currentBreakpoint as OuiBreakpointSize] + ? responsiveObject[currentBreakpoint as OuiBreakpointSize] + : null; + + // Second, if both max and responsiveMax are set, use the smaller of the two. Otherwise, use the one that is set. + const calculatedMax: OuiBreadcrumbsProps['max'] = + max && responsiveMax ? Math.min(max, responsiveMax) : max || responsiveMax; const limitedBreadcrumbs = calculatedMax ? limitBreadcrumbs(breadcrumbElements, calculatedMax, breadcrumbs)