Skip to content

Commit

Permalink
[architecture] Export subcomponents with . namespacing
Browse files Browse the repository at this point in the history
- a la `EuiPageTemplate`

+ update stories to use namespaced components instead of direct imports

+ add stories for the new group component
  • Loading branch information
cee-chen committed Sep 26, 2023
1 parent 4af5c1a commit ca08339
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ import type { Meta, StoryObj } from '@storybook/react';

import { EuiHeader, EuiHeaderSection, EuiHeaderSectionItem } from '../header';
import { EuiPageTemplate } from '../page_template';
import { EuiFlyout, EuiFlyoutBody, EuiFlyoutFooter } from '../flyout';
import { EuiFlyout } from '../flyout';
import { EuiButton } from '../button';
import { EuiTitle } from '../title';

import { EuiCollapsibleNavItem } from './collapsible_nav_item';
import {
EuiCollapsibleNavBeta,
EuiCollapsibleNavBetaProps,
} from './collapsible_nav_beta';
import { EuiCollapsibleNavBeta, EuiCollapsibleNavBetaProps } from './';

const meta: Meta<EuiCollapsibleNavBetaProps> = {
title: 'EuiCollapsibleNavBeta',
Expand Down Expand Up @@ -78,9 +74,14 @@ const KibanaNavTitle: FunctionComponent<{
export const KibanaExample: Story = {
render: ({ ...args }) => (
<OpenCollapsibleNav {...args}>
<EuiFlyoutBody scrollableTabIndex={-1}>
<EuiCollapsibleNavItem title="Home" icon="home" isSelected href="#" />
<EuiCollapsibleNavItem
<EuiCollapsibleNavBeta.Body>
<EuiCollapsibleNavBeta.Item
title="Home"
icon="home"
isSelected
href="#"
/>
<EuiCollapsibleNavBeta.Item
title="Recent"
icon="clock"
items={[
Expand All @@ -89,7 +90,7 @@ export const KibanaExample: Story = {
{ title: 'Ultricies tellus', icon: 'visMetric', href: '#' },
]}
/>
<EuiCollapsibleNavItem
<EuiCollapsibleNavBeta.Item
title="Elasticsearch"
icon="logoElasticsearch"
href="#"
Expand All @@ -107,7 +108,7 @@ export const KibanaExample: Story = {
{ title: 'API keys', href: '#' },
]}
/>
<EuiCollapsibleNavItem
<EuiCollapsibleNavBeta.Item
title="Enterprise Search"
icon="logoEnterpriseSearch"
href="#"
Expand All @@ -123,7 +124,7 @@ export const KibanaExample: Story = {
{ title: 'Search experiences', href: '#' },
]}
/>
<EuiCollapsibleNavItem
<EuiCollapsibleNavBeta.Item
title="Observability"
icon="logoObservability"
href="#"
Expand Down Expand Up @@ -159,7 +160,7 @@ export const KibanaExample: Story = {
{ title: 'Add data', href: '#' },
]}
/>
<EuiCollapsibleNavItem
<EuiCollapsibleNavBeta.Item
title="Security"
icon="logoSecurity"
href="#"
Expand Down Expand Up @@ -216,7 +217,7 @@ export const KibanaExample: Story = {
},
]}
/>
<EuiCollapsibleNavItem
<EuiCollapsibleNavBeta.Item
title="Analytics"
icon="stats"
href="#"
Expand All @@ -226,7 +227,7 @@ export const KibanaExample: Story = {
{ title: 'Visualize library', href: '#' },
]}
/>
<EuiCollapsibleNavItem
<EuiCollapsibleNavBeta.Item
title="Machine learning"
icon="indexMapping"
href="#"
Expand All @@ -252,9 +253,9 @@ export const KibanaExample: Story = {
{ title: 'Data view', href: '#' },
]}
/>
</EuiFlyoutBody>
<EuiFlyoutFooter>
<EuiCollapsibleNavItem
</EuiCollapsibleNavBeta.Body>
<EuiCollapsibleNavBeta.Footer>
<EuiCollapsibleNavBeta.Item
title="Developer tools"
icon="editorCodeBlock"
href="#"
Expand All @@ -265,7 +266,7 @@ export const KibanaExample: Story = {
{ title: 'Painless lab', href: '#' },
]}
/>
<EuiCollapsibleNavItem
<EuiCollapsibleNavBeta.Item
title="Management"
icon="gear"
items={[
Expand All @@ -276,7 +277,7 @@ export const KibanaExample: Story = {
{ title: 'Stack management', href: '#' },
]}
/>
<EuiCollapsibleNavItem
<EuiCollapsibleNavBeta.Item
title="Project settings"
icon="gear"
items={[
Expand All @@ -298,7 +299,7 @@ export const KibanaExample: Story = {
},
]}
/>
</EuiFlyoutFooter>
</EuiCollapsibleNavBeta.Footer>
</OpenCollapsibleNav>
),
};
Expand All @@ -307,28 +308,10 @@ export const KibanaExample: Story = {
export const SecurityExample: Story = {
render: ({ ...args }) => (
<OpenCollapsibleNav {...args}>
<EuiFlyoutBody scrollableTabIndex={-1}>
<EuiCollapsibleNavItem
title="Recent"
icon="clock"
items={[
{ title: 'Lorem ipsum', icon: 'visMapRegion', href: '#' },
{ title: 'Consectetur cursus', icon: 'visPie', href: '#' },
{ title: 'Ultricies tellus', icon: 'visMetric', href: '#' },
]}
/>
<EuiCollapsibleNavItem
isSelected
<EuiCollapsibleNavBeta.Body>
<EuiCollapsibleNavBeta.Group
title="Security"
icon="logoSecurity"
href="#"
// Workaround to always display this section as open and remove the accordion toggle
// Rather than baking in a top-level prop to support this behavior, this is likely
// the path we'd recommend to Security instead if their use-case isn't standard
accordionProps={{
forceState: 'open',
arrowProps: { css: { display: 'none' } },
}}
items={[
{ title: 'Get started', href: '#' },
{ title: 'Dashboards', href: '#' },
Expand Down Expand Up @@ -382,14 +365,14 @@ export const SecurityExample: Story = {
},
]}
/>
</EuiFlyoutBody>
<EuiFlyoutFooter>
<EuiCollapsibleNavItem
</EuiCollapsibleNavBeta.Body>
<EuiCollapsibleNavBeta.Footer>
<EuiCollapsibleNavBeta.Item
title="Developer tools"
icon="editorCodeBlock"
href="#"
/>
<EuiCollapsibleNavItem
<EuiCollapsibleNavBeta.Item
title="Project settings"
icon="gear"
items={[
Expand All @@ -411,7 +394,7 @@ export const SecurityExample: Story = {
},
]}
/>
</EuiFlyoutFooter>
</EuiCollapsibleNavBeta.Footer>
</OpenCollapsibleNav>
),
};
Expand Down Expand Up @@ -442,10 +425,10 @@ const MockConsumerFlyout: FunctionComponent = () => {
</EuiButton>
{flyoutIsOpen && (
<EuiFlyout onClose={() => setFlyoutOpen(false)}>
<EuiFlyoutBody>
<EuiCollapsibleNavBeta.Body>
Some other mock consumer flyout that <strong>should</strong> overlap
EuiCollapsibleNav
</EuiFlyoutBody>
</EuiCollapsibleNavBeta.Body>
</EuiFlyout>
)}
</>
Expand Down
5 changes: 3 additions & 2 deletions src/components/collapsible_nav_beta/collapsible_nav_beta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ export type EuiCollapsibleNavBetaProps = CommonProps &
'side' | 'focusTrapProps' | 'includeFixedHeadersInFocusTrap'
> & {
/**
* ReactNode(s) to render as navigation flyout content, typically `EuiCollapsibleNavItem`s.
* You may also want to use `EuiFlyoutBody` and `EuiFlyoutFooter` for organization.
* ReactNode(s) to render as navigation flyout content, typically `EuiCollapsibleNavBeta.Item`s.
* You will likely want to use `EuiCollapsibleNavBeta.Body` and `EuiCollapsibleNavBeta.Footer`
* for organization.
*/
children?: ReactNode;
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import React, { FunctionComponent, PropsWithChildren } from 'react';
import type { Meta, StoryObj } from '@storybook/react';

import { EuiHeader, EuiHeaderSection } from '../../header';
import { EuiPageTemplate } from '../../page_template';

import { EuiCollapsibleNavBeta, EuiCollapsibleNavBetaProps } from '../';
import {
EuiCollapsibleNavGroup,
EuiCollapsibleNavGroupProps,
} from './collapsible_nav_group';

const meta: Meta<EuiCollapsibleNavGroupProps> = {
title: 'EuiCollapsibleNavBeta.Group',
component: EuiCollapsibleNavGroup,
parameters: {
layout: 'fullscreen',
},
args: {
title: 'Elastic',
icon: 'logoElastic',
items: [
{ title: 'Get started', href: '#' },
{ title: 'Dashboards', href: '#' },
{
title: 'Explore',
href: '#',
items: [
{ title: 'Hello', href: '#' },
{ title: 'World', href: '#' },
],
},
],
},
argTypes: {
wrapperProps: { control: 'object' },
},
};
export default meta;
type Story = StoryObj<EuiCollapsibleNavGroupProps>;

const CollapsibleNavTemplate: FunctionComponent<
PropsWithChildren & Partial<EuiCollapsibleNavBetaProps>
> = ({ children, ...props }) => {
return (
<>
<EuiHeader position="fixed">
<EuiHeaderSection>
<EuiCollapsibleNavBeta {...props}>
<EuiCollapsibleNavBeta.Body>{children}</EuiCollapsibleNavBeta.Body>
</EuiCollapsibleNavBeta>
</EuiHeaderSection>
</EuiHeader>
<EuiPageTemplate>
<EuiPageTemplate.Section>Hello world</EuiPageTemplate.Section>
</EuiPageTemplate>
</>
);
};

export const Playground: Story = {
render: ({ ...args }) => (
<CollapsibleNavTemplate>
<EuiCollapsibleNavBeta.Group {...args} />
</CollapsibleNavTemplate>
),
args: {
wrapperProps: { 'data-test-subj': 'test' },
},
};

export const EdgeCaseTesting: Story = {
render: ({ ...args }) => (
<CollapsibleNavTemplate initialIsCollapsed={true}>
<EuiCollapsibleNavBeta.Item href="#" title="Test" icon="faceHappy" />
<EuiCollapsibleNavBeta.Item href="#" title="Test" icon="faceSad" />
<EuiCollapsibleNavBeta.Group {...args} />
<EuiCollapsibleNavBeta.Item href="#" title="Test" icon="faceHappy" />
<EuiCollapsibleNavBeta.Item href="#" title="Test" icon="faceSad" />
<EuiCollapsibleNavBeta.Group {...args} />
</CollapsibleNavTemplate>
),
args: {
href: '#',
},
};
17 changes: 15 additions & 2 deletions src/components/collapsible_nav_beta/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,24 @@
* development usage. It is not yet fully documented or supported.
*/

import { EuiCollapsibleNavBeta as _EuiCollapsibleNavBeta } from './collapsible_nav_beta';
import {
EuiCollapsibleNavBody,
EuiCollapsibleNavFooter,
} from './collapsible_nav_body_footer';
import { EuiCollapsibleNavGroup } from './collapsible_nav_group';
import { EuiCollapsibleNavItem } from './collapsible_nav_item';

export const EuiCollapsibleNavBeta = Object.assign(_EuiCollapsibleNavBeta, {
Body: EuiCollapsibleNavBody,
Footer: EuiCollapsibleNavFooter,
Group: EuiCollapsibleNavGroup,
Item: EuiCollapsibleNavItem,
});
export type { EuiCollapsibleNavBetaProps } from './collapsible_nav_beta';
export { EuiCollapsibleNavBeta } from './collapsible_nav_beta';

export { EuiCollapsibleNavItem };
export type {
EuiCollapsibleNavItemProps,
EuiCollapsibleNavSubItemProps,
} from './collapsible_nav_item';
export { EuiCollapsibleNavItem } from './collapsible_nav_item';

0 comments on commit ca08339

Please sign in to comment.