Skip to content

Commit

Permalink
Adjust OuiSimplifiedBreadcrumbs alignment, colors, and tailing slash (#…
Browse files Browse the repository at this point in the history
…1401) (#1409)

* Add methods to control the appearance of trailing and last breadcrumbs in OuiSimplifiedBreadcrumbs

Also:
* Adjust alignments, colors, and separator in OuiSimplifiedBreadcrumbs
* Add documentation for OuiSimplifiedBreadcrumbs
* Add CSS breakpoints to OuiBreakpointSize

Signed-off-by: Miki <[email protected]>

* Remove the unwanted OuiBreadcrumbs focus rectangle

Also:
* Correctly color the OuiBreadcrumbs when focused
* Display the last breadcrumb in a nested breadcrumb as a normal breadcrumb

Signed-off-by: Miki <[email protected]>

* Update changelog for #1401

Signed-off-by: Miki <[email protected]>

* Allow limiting the allowed breakpoints when calling `getBreakpoint()`

Also:
* Limit allowed breakpoints to those provided by the `responsive` prop of Oui*Breadcrumbs

Signed-off-by: Miki <[email protected]>

* Adjust number of responsive breadcrumbs shown per breakpoint

Signed-off-by: Miki <[email protected]>

* Update snapshots

Signed-off-by: Miki <[email protected]>

---------

Signed-off-by: Miki <[email protected]>
(cherry picked from commit fd5b78a)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 2c91d14 commit 9a5fc37
Show file tree
Hide file tree
Showing 20 changed files with 1,694 additions and 1,061 deletions.
54 changes: 48 additions & 6 deletions src-docs/src/views/breadcrumbs/breadcrumbs_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import { renderToHtml } from '../../services';

import { GuideSectionTypes } from '../../components';

import { OuiCode, OuiBreadcrumbs } from '../../../../src/components';
import {
OuiCode,
OuiBreadcrumbs,
OuiSimplifiedBreadcrumbs,
} from '../../../../src/components';
import { BreadcrumbResponsiveMaxCount, BreadcrumbProps } from './props';

import Breadcrumbs from './breadcrumbs';
Expand All @@ -35,12 +39,22 @@ import Max from './max';
const maxSource = require('!!raw-loader!./max');
const maxHtml = renderToHtml(Max);

const breadcrumpProps = {
import Simplified from './simplified_breadcrumbs';
const simplifiedSource = require('!!raw-loader!./simplified_breadcrumbs');
const simplifiedHtml = renderToHtml(Simplified);

const breadcrumbProps = {
OuiBreadcrumbs,
OuiBreadcrumb: BreadcrumbProps,
OuiBreadcrumbResponsiveMaxCount: BreadcrumbResponsiveMaxCount,
};

const simplifiedProps = {
OuiSimplifiedBreadcrumbs,
OuiBreadcrumb: BreadcrumbProps,
OuiBreadcrumbResponsiveMaxCount: BreadcrumbResponsiveMaxCount,
};

export const BreadcrumbsExample = {
title: 'Breadcrumbs',
sections: [
Expand Down Expand Up @@ -73,7 +87,7 @@ export const BreadcrumbsExample = {
.
</p>
),
props: breadcrumpProps,
props: breadcrumbProps,
snippet: `<OuiBreadcrumbs
breadcrumbs={[
{
Expand Down Expand Up @@ -112,7 +126,7 @@ export const BreadcrumbsExample = {
</p>
</>
),
props: breadcrumpProps,
props: breadcrumbProps,
snippet: `<OuiBreadcrumbs
max={4}
breadcrumbs={breadcrumbs}
Expand Down Expand Up @@ -144,7 +158,7 @@ export const BreadcrumbsExample = {
</p>
</>
),
props: breadcrumpProps,
props: breadcrumbProps,
demo: <Truncate />,
snippet: [
`<OuiBreadcrumbs
Expand Down Expand Up @@ -190,7 +204,7 @@ export const BreadcrumbsExample = {
</p>
</>
),
props: breadcrumpProps,
props: breadcrumbProps,
snippet: [
`<OuiBreadcrumbs
responsive={false}
Expand All @@ -210,5 +224,33 @@ export const BreadcrumbsExample = {
],
demo: <Responsive />,
},
{
title: 'Simplified breadcrumbs',
source: [
{
type: GuideSectionTypes.JS,
code: simplifiedSource,
},
{
type: GuideSectionTypes.HTML,
code: simplifiedHtml,
},
],
text: (
<>
<p>
<strong>OuiSimplifiedBreadcrumbs</strong> are a variant of
OuiBreadcrumbs using a simplified appearence.
</p>
</>
),
props: simplifiedProps,
snippet: [
`<OuiSimplifiedBreadcrumbs
breadcrumbs={breadcrumbs}
/>`,
],
demo: <Simplified />,
},
],
};
148 changes: 148 additions & 0 deletions src-docs/src/views/breadcrumbs/display_breadcrumbs_toggles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

import React, { cloneElement, useState, Fragment } from 'react';
import PropTypes from 'prop-types';

import {
OuiFlexGroup,
OuiSwitch,
OuiFlexItem,
OuiButtonEmpty,
OuiPopover,
OuiSpacer,
} from '../../../../src/components';

export const DisplayBreadCrumbsToggles = ({
canResponsive,
canTruncate,
canHideLastBreadCrumb,
canHideTrailingSeparator,
canDisableTrailingLink,
children,
spacerSize,
}) => {
const [responsive, setResponsive] = useState(false);
const [truncate, setTruncate] = useState(true);
const [hideLastBreadCrumb, setHideLastBreadCrumb] = useState(false);
const [hideTrailingSeparator, setHideTrailingSeparator] = useState(false);
const [disableTrailingLink, setDisableTrailingLink] = useState(false);
const [isPopoverOpen, setIsPopoverOpen] = useState(false);

const canProps = {};
if (canResponsive) canProps.responsive = responsive;
if (canTruncate) canProps.truncate = truncate;
if (canHideLastBreadCrumb) canProps.hideLastBreadCrumb = hideLastBreadCrumb;
if (canHideTrailingSeparator)
canProps.hideTrailingSeparator = hideTrailingSeparator;
if (canDisableTrailingLink)
canProps.disableTrailingLink = disableTrailingLink;

return (
<Fragment>
{cloneElement(children, canProps)}
<OuiSpacer size={spacerSize} />
<OuiPopover
panelPaddingSize="s"
isOpen={isPopoverOpen}
closePopover={() => {
setIsPopoverOpen(false);
}}
button={
<OuiButtonEmpty
iconType="controlsHorizontal"
size="xs"
onClick={() => {
setIsPopoverOpen(!isPopoverOpen);
}}>
Display toggles
</OuiButtonEmpty>
}>
<div>
<OuiFlexGroup
wrap={true}
direction="column"
gutterSize="s"
responsive={false}>
{canResponsive && (
<OuiFlexItem grow={false}>
<OuiSwitch
compressed
label="responsive"
checked={responsive}
onChange={(e) => setResponsive(e.target.checked)}
/>
</OuiFlexItem>
)}
{canTruncate && (
<OuiFlexItem grow={false}>
<OuiSwitch
compressed
label="truncate"
checked={truncate}
onChange={(e) => setTruncate(e.target.checked)}
/>
</OuiFlexItem>
)}
{canHideLastBreadCrumb && (
<OuiFlexItem grow={false}>
<OuiSwitch
compressed
label="hideLastBreadCrumb"
checked={hideLastBreadCrumb}
onChange={(e) => setHideLastBreadCrumb(e.target.checked)}
/>
</OuiFlexItem>
)}
{canHideTrailingSeparator && (
<OuiFlexItem grow={false}>
<OuiSwitch
compressed
label="hideTrailingSeparator"
checked={hideTrailingSeparator}
onChange={(e) => setHideTrailingSeparator(e.target.checked)}
/>
</OuiFlexItem>
)}
{canDisableTrailingLink && (
<OuiFlexItem grow={false}>
<OuiSwitch
compressed
label="disableTrailingLink"
checked={disableTrailingLink}
onChange={(e) => setDisableTrailingLink(e.target.checked)}
/>
</OuiFlexItem>
)}
</OuiFlexGroup>
</div>
</OuiPopover>
</Fragment>
);
};

DisplayBreadCrumbsToggles.propTypes = {
canResponsive: PropTypes.bool,
canTruncate: PropTypes.bool,
canHideLastBreadCrumb: PropTypes.bool,
canHideTrailingSeparator: PropTypes.bool,
canDisableTrailingLink: PropTypes.bool,
spacerSize: PropTypes.oneOf(['xs', 's', 'm', 'l', 'xl', 'xxl']),
};

DisplayBreadCrumbsToggles.defaultProps = {
canResponsive: true,
canTruncate: true,
canHideLastBreadCrumb: false,
canHideTrailingSeparator: false,
canDisableTrailingLink: false,
spacerSize: 'l',
};
82 changes: 82 additions & 0 deletions src-docs/src/views/breadcrumbs/simplified_breadcrumbs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

import React from 'react';

import { OuiSimplifiedBreadcrumbs } from '../../../../src/components';

import { DisplayBreadCrumbsToggles } from './display_breadcrumbs_toggles';

export default () => {
const breadcrumbs = [
{
text: 'Universe',
href: '#',
},
{
text: 'Observable Universe',
href: '#',
},
{
text: 'Pisces–Cetus Supercluster Complex',
href: '#',
},
{
text: 'Laniakea Supercluster',
href: '#',
},
{
text: 'Virgo Cluster',
href: '#',
},
{
text: 'Local Group',
href: '#',
},
{
text: 'Local Bubble',
href: '#',
},
{
text: 'Local Interstellar Cloud',
href: '#',
},
{
text: 'Milky Way Galaxy',
href: '#',
},
{
text: 'Orion Arm',
href: '#',
},
{
text: 'Solar System',
href: '#',
},
{
text: 'Geospace',
href: '#',
},
{
text: 'Earth',
href: '#',
},
];

return (
<DisplayBreadCrumbsToggles
canHideLastBreadCrumb
canHideTrailingSeparator
canDisableTrailingLink>
<OuiSimplifiedBreadcrumbs breadcrumbs={breadcrumbs} max={null} />
</DisplayBreadCrumbsToggles>
);
};
Loading

0 comments on commit 9a5fc37

Please sign in to comment.