From c3ced8cfd8d32605a38f5052625b4baf34b70a63 Mon Sep 17 00:00:00 2001 From: Cee Chen Date: Wed, 21 Jun 2023 16:51:14 -0700 Subject: [PATCH] Add full pattern storybook demo - 50/50 on this, but it's useful for QA --- .../collapsible_nav.stories.tsx | 302 ++++++++++++++++++ 1 file changed, 302 insertions(+) diff --git a/src/components/collapsible_nav/collapsible_nav.stories.tsx b/src/components/collapsible_nav/collapsible_nav.stories.tsx index 77a89909ea2..e5954a4297d 100644 --- a/src/components/collapsible_nav/collapsible_nav.stories.tsx +++ b/src/components/collapsible_nav/collapsible_nav.stories.tsx @@ -49,3 +49,305 @@ export const Playground: Story = { size: 240, }, }; + +/** + * Full pattern demo - this was copied from src-docs examples, + * and is meant to be an imitation of Kibana's production nav + */ +import { css } from '@emotion/react'; +import find from 'lodash/find'; +import findIndex from 'lodash/findIndex'; + +import { logicalCSSWithFallback } from '../../global_styling'; +import { + EuiButtonIcon, + EuiIcon, + EuiText, + EuiLink, + EuiHeaderSectionItemButton, + EuiHeaderLogo, + EuiHeader, + EuiPageTemplate, + EuiPinnableListGroup, + EuiPinnableListGroupItemProps, + EuiFlexItem, + EuiHorizontalRule, + EuiSkeletonText, + EuiListGroup, +} from '../../components'; + +import { EuiCollapsibleNavGroup } from './collapsible_nav_group'; + +const TopLinks: EuiPinnableListGroupItemProps[] = [ + { + label: 'Home', + iconType: 'home', + isActive: true, + 'aria-current': true, + onClick: () => {}, + pinnable: false, + }, +]; +const KibanaLinks: EuiPinnableListGroupItemProps[] = [ + { label: 'Discover', onClick: () => {} }, + { label: 'Visualize', onClick: () => {} }, + { label: 'Dashboards', onClick: () => {} }, + { label: 'Canvas', onClick: () => {} }, + { label: 'Maps', onClick: () => {} }, + { label: 'Machine Learning', onClick: () => {} }, + { label: 'Graph', onClick: () => {} }, +]; + +const LearnLinks: EuiPinnableListGroupItemProps[] = [ + { label: 'Docs', onClick: () => {} }, + { label: 'Blogs', onClick: () => {} }, + { label: 'Webinars', onClick: () => {} }, + { label: 'Elastic.co', href: 'https://elastic.co' }, +]; + +const CollapsibleNavAll = () => { + const [navIsOpen, setNavIsOpen] = useState(true); + + /** + * Accordion toggling + */ + const [openGroups, setOpenGroups] = useState(['Kibana', 'Learn']); + + const toggleAccordion = (isOpen: boolean, title?: string) => { + if (!title) return; + const itExists = openGroups.includes(title); + if (isOpen) { + if (itExists) return; + openGroups.push(title); + } else { + const index = openGroups.indexOf(title); + if (index > -1) { + openGroups.splice(index, 1); + } + } + setOpenGroups([...openGroups]); + }; + + /** + * Pinning + */ + const [pinnedItems, setPinnedItems] = useState< + EuiPinnableListGroupItemProps[] + >([]); + + const addPin = (item: any) => { + if (!item || find(pinnedItems, { label: item.label })) { + return; + } + item.pinned = true; + const newPinnedItems = pinnedItems ? pinnedItems.concat(item) : [item]; + setPinnedItems(newPinnedItems); + }; + + const removePin = (item: any) => { + const pinIndex = findIndex(pinnedItems, { label: item.label }); + if (pinIndex > -1) { + item.pinned = false; + const newPinnedItems = pinnedItems; + newPinnedItems.splice(pinIndex, 1); + setPinnedItems([...newPinnedItems]); + } + }; + + const collapsibleNav = ( + setNavIsOpen(!navIsOpen)} + > + + ); + + return ( + <> + Elastic, + ], + borders: 'right', + }, + ]} + /> + + + + + + + + ); +}; + +export const FullPattern: Story = { + render: () => , +};