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 27, 2023
1 parent 5152f08 commit de3c73e
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ 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,
EuiCollapsibleNavItemProps,
} from './collapsible_nav_item';
import {
EuiCollapsibleNavBeta,
EuiCollapsibleNavBetaProps,
} from './collapsible_nav_beta';
EuiCollapsibleNavItemProps,
} from './';

const meta: Meta<EuiCollapsibleNavBetaProps> = {
title: 'EuiCollapsibleNavBeta',
Expand Down Expand Up @@ -89,9 +86,14 @@ const renderGroup = (
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 @@ -100,7 +102,7 @@ export const KibanaExample: Story = {
{ title: 'Ultricies tellus', icon: 'visMetric', href: '#' },
]}
/>
<EuiCollapsibleNavItem
<EuiCollapsibleNavBeta.Item
title="Elasticsearch"
icon="logoElasticsearch"
href="#"
Expand All @@ -119,7 +121,7 @@ export const KibanaExample: Story = {
...renderGroup('Security', [{ title: 'API keys', href: '#' }]),
]}
/>
<EuiCollapsibleNavItem
<EuiCollapsibleNavBeta.Item
title="Enterprise Search"
icon="logoEnterpriseSearch"
href="#"
Expand All @@ -135,7 +137,7 @@ export const KibanaExample: Story = {
{ title: 'Search experiences', href: '#' },
]}
/>
<EuiCollapsibleNavItem
<EuiCollapsibleNavBeta.Item
title="Observability"
icon="logoObservability"
href="#"
Expand Down Expand Up @@ -173,7 +175,7 @@ export const KibanaExample: Story = {
]),
]}
/>
<EuiCollapsibleNavItem
<EuiCollapsibleNavBeta.Item
title="Security"
icon="logoSecurity"
href="#"
Expand Down Expand Up @@ -230,7 +232,7 @@ export const KibanaExample: Story = {
},
]}
/>
<EuiCollapsibleNavItem
<EuiCollapsibleNavBeta.Item
title="Analytics"
icon="stats"
href="#"
Expand All @@ -240,7 +242,7 @@ export const KibanaExample: Story = {
{ title: 'Visualize library', href: '#' },
]}
/>
<EuiCollapsibleNavItem
<EuiCollapsibleNavBeta.Item
title="Machine learning"
icon="indexMapping"
href="#"
Expand Down Expand Up @@ -268,9 +270,9 @@ export const KibanaExample: Story = {
]),
]}
/>
</EuiFlyoutBody>
<EuiFlyoutFooter>
<EuiCollapsibleNavItem
</EuiCollapsibleNavBeta.Body>
<EuiCollapsibleNavBeta.Footer>
<EuiCollapsibleNavBeta.Item
title="Developer tools"
icon="editorCodeBlock"
href="#"
Expand All @@ -281,7 +283,7 @@ export const KibanaExample: Story = {
{ title: 'Painless lab', href: '#' },
]}
/>
<EuiCollapsibleNavItem
<EuiCollapsibleNavBeta.Item
title="Management"
icon="gear"
items={[
Expand All @@ -292,7 +294,7 @@ export const KibanaExample: Story = {
{ title: 'Stack management', href: '#' },
]}
/>
<EuiCollapsibleNavItem
<EuiCollapsibleNavBeta.Item
title="Project settings"
icon="gear"
items={[
Expand All @@ -314,7 +316,7 @@ export const KibanaExample: Story = {
},
]}
/>
</EuiFlyoutFooter>
</EuiCollapsibleNavBeta.Footer>
</OpenCollapsibleNav>
),
};
Expand All @@ -323,28 +325,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 @@ -398,14 +382,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 @@ -427,7 +411,7 @@ export const SecurityExample: Story = {
},
]}
/>
</EuiFlyoutFooter>
</EuiCollapsibleNavBeta.Footer>
</OpenCollapsibleNav>
),
};
Expand Down Expand Up @@ -458,10 +442,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
27 changes: 22 additions & 5 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 Expand Up @@ -76,9 +77,7 @@ export type EuiCollapsibleNavBetaProps = CommonProps &
'aria-label'?: string;
};

export const EuiCollapsibleNavBeta: FunctionComponent<
EuiCollapsibleNavBetaProps
> = ({
const _EuiCollapsibleNavBeta: FunctionComponent<EuiCollapsibleNavBetaProps> = ({
id,
children,
className,
Expand Down Expand Up @@ -211,3 +210,21 @@ export const EuiCollapsibleNavBeta: FunctionComponent<
</EuiCollapsibleNavContext.Provider>
);
};

/**
* Combined export with subcomponents
*/

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,
});
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: '#',
},
};
2 changes: 1 addition & 1 deletion src/components/collapsible_nav_beta/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* development usage. It is not yet fully documented or supported.
*/

export type { EuiCollapsibleNavBetaProps } from './collapsible_nav_beta';
export { EuiCollapsibleNavBeta } from './collapsible_nav_beta';
export type { EuiCollapsibleNavBetaProps } from './collapsible_nav_beta';

export type {
EuiCollapsibleNavItemProps,
Expand Down

0 comments on commit de3c73e

Please sign in to comment.