Skip to content

Commit

Permalink
[EuiHeaderLinks] Add default padding to mobile popover (#7961)
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen authored Aug 14, 2024
1 parent bf9eb33 commit e143ed0
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 65 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/eui/changelogs/upcoming/7961.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Updated `EuiHeaderLinks`'s mobile menu to set a slight popover padding by default
- This can be overridden via `popoverProps.panelPaddingSize` if needed.
- Updated `EuiHeaderLink` to default to a size of `s` (down from `m`)
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import React, { useState, useMemo } from 'react';
import React, { useMemo } from 'react';

import {
EuiBadge,
EuiButtonEmpty,
EuiFlexGroup,
EuiFlexItem,
EuiHeader,
EuiHeaderLink,
EuiHeaderLinks,
EuiHeaderLogo,
EuiHeaderSectionItemButton,
EuiIcon,
EuiPopover,
EuiToolTip,
} from '../../../../src/components';
import { useIsWithinBreakpoints } from '../../../../src/services';
Expand Down Expand Up @@ -69,14 +67,9 @@ export const GuidePageHeader: React.FunctionComponent<GuidePageHeaderProps> = ({
const github = useMemo(() => {
const label = 'EUI GitHub repo';
return isMobileSize ? (
<EuiButtonEmpty
size="s"
flush="both"
iconType="logoGithub"
href={GITHUB_URL}
>
<EuiHeaderLink color="primary" iconType="logoGithub" href={GITHUB_URL}>
{label}
</EuiButtonEmpty>
</EuiHeaderLink>
) : (
<EuiToolTip content="Github">
<EuiHeaderSectionItemButton aria-label={label} href={GITHUB_URL}>
Expand All @@ -90,9 +83,9 @@ export const GuidePageHeader: React.FunctionComponent<GuidePageHeaderProps> = ({
const label = 'Codesandbox';
return isMobileSize ? (
<CodeSandboxLink type="tsx">
<EuiButtonEmpty size="s" flush="both" iconType="logoCodesandbox">
<EuiHeaderLink color="primary" iconType="logoCodesandbox">
{label}
</EuiButtonEmpty>
</EuiHeaderLink>
</CodeSandboxLink>
) : (
<EuiToolTip content="Codesandbox" key="codesandbox">
Expand All @@ -105,39 +98,18 @@ export const GuidePageHeader: React.FunctionComponent<GuidePageHeaderProps> = ({
);
}, [isMobileSize]);

const [mobilePopoverIsOpen, setMobilePopoverIsOpen] = useState(false);

const mobileMenu = useMemo(() => {
const button = (
<EuiHeaderSectionItemButton
aria-label="Open EUI options menu"
onClick={() => setMobilePopoverIsOpen((isOpen) => !isOpen)}
>
<EuiIcon type="apps" aria-hidden="true" />
</EuiHeaderSectionItemButton>
);

return (
<EuiPopover
button={button}
isOpen={mobilePopoverIsOpen}
closePopover={() => setMobilePopoverIsOpen(false)}
<EuiHeaderLinks
popoverButtonProps={{ 'aria-label': 'Open EUI options menu' }}
popoverBreakpoints="all"
>
<EuiFlexGroup
direction="column"
alignItems="flexStart"
gutterSize="none"
responsive={false}
>
<EuiFlexItem>{github}</EuiFlexItem>
<EuiFlexItem>
<GuideFigmaLink />
</EuiFlexItem>
<EuiFlexItem>{codesandbox}</EuiFlexItem>
</EuiFlexGroup>
</EuiPopover>
{github}
<GuideFigmaLink />
{codesandbox}
</EuiHeaderLinks>
);
}, [mobilePopoverIsOpen, codesandbox, github]);
}, [codesandbox, github]);

const rightSideItems = isMobileSize
? [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
/* eslint-disable no-restricted-globals */
import React from 'react';

import { EuiButtonEmpty } from '../../../../src/components/button';
import { useIsWithinBreakpoints } from '../../../../src/services';

import { ThemeContext } from '../with_theme';
import { EuiHeaderSectionItemButton } from '../../../../src/components/header';
import {
EuiHeaderLink,
EuiHeaderSectionItemButton,
} from '../../../../src/components/header';
import { EuiToolTip } from '../../../../src/components/tool_tip';
import { EuiIcon } from '../../../../src/components/icon';
import logoFigma from '../../images/logo-figma.svg';

import { ThemeContext } from '../with_theme';

type GuideFigmaLinkProps = {
context?: any;
};
Expand All @@ -34,9 +36,9 @@ const GuideFigmaLinkComponent: React.FunctionComponent<
const label = 'EUI Figma Design Library';

return isMobileSize ? (
<EuiButtonEmpty size="s" flush="both" iconType={logoFigma} href={href}>
<EuiHeaderLink color="primary" iconType={logoFigma} href={href}>
{label}
</EuiButtonEmpty>
</EuiHeaderLink>
) : (
<EuiToolTip
title={label}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`EuiHeaderLink can render as specific color 1`] = `
<button
class="euiButtonEmpty euiHeaderLink emotion-euiButtonDisplay-euiButtonEmpty-m-empty-danger"
class="euiButtonEmpty euiHeaderLink emotion-euiButtonDisplay-euiButtonEmpty-s-empty-danger"
type="button"
>
<span
Expand All @@ -18,7 +18,7 @@ exports[`EuiHeaderLink can render as specific color 1`] = `
exports[`EuiHeaderLink is rendered 1`] = `
<button
aria-label="aria-label"
class="euiButtonEmpty euiHeaderLink testClass1 testClass2 emotion-euiButtonDisplay-euiButtonEmpty-m-empty-text-euiTestCss"
class="euiButtonEmpty euiHeaderLink testClass1 testClass2 emotion-euiButtonDisplay-euiButtonEmpty-s-empty-text-euiTestCss"
data-test-subj="test subject string"
type="button"
>
Expand All @@ -34,7 +34,7 @@ exports[`EuiHeaderLink is rendered 1`] = `

exports[`EuiHeaderLink is rendered as active 1`] = `
<button
class="euiButtonEmpty euiHeaderLink euiHeaderLink-isActive emotion-euiButtonDisplay-euiButtonEmpty-m-empty-primary"
class="euiButtonEmpty euiHeaderLink euiHeaderLink-isActive emotion-euiButtonDisplay-euiButtonEmpty-s-empty-primary"
type="button"
>
<span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const meta: Meta<EuiHeaderLinkProps> = {
// Component defaults
args: {
isActive: false,
size: 's',
},
};
moveStorybookControlsToCategory(
Expand Down
20 changes: 10 additions & 10 deletions packages/eui/src/components/header/header_links/header_link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ export type EuiHeaderLinkProps = EuiButtonEmptyProps & {
export const EuiHeaderLink: FunctionComponent<EuiHeaderLinkProps> = ({
isActive,
className,
size = 's',
...rest
}) => {
const classes = classNames(
'euiHeaderLink',
{
'euiHeaderLink-isActive': isActive,
},
{ 'euiHeaderLink-isActive': isActive },
className
);

const props = {
color: isActive ? 'primary' : 'text',
...rest,
className: classes,
};

return <EuiButtonEmpty {...(props as EuiButtonEmptyProps)} />;
return (
<EuiButtonEmpty
className={classes}
color={isActive ? 'primary' : 'text'}
size={size}
{...rest}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import { LOKI_SELECTORS } from '../../../../.storybook/loki';

import { EuiHeader, EuiHeaderSection, EuiHeaderSectionItem } from '../';

Expand All @@ -21,7 +22,11 @@ const meta: Meta<EuiHeaderLinksProps> = {
// Component defaults
gutterSize: 's',
popoverBreakpoints: ['xs', 's'],
// VRT
popoverProps: { isOpen: true },
},
// Required to capture mobile popover
parameters: { loki: { chromeSelector: LOKI_SELECTORS.body } },
};

export default meta;
Expand All @@ -35,7 +40,7 @@ export const Playground: Story = {
<EuiHeaderLinks {...args}>
<EuiHeaderLink isActive>Docs</EuiHeaderLink>
<EuiHeaderLink>Code</EuiHeaderLink>
<EuiHeaderLink iconType="help"> Help</EuiHeaderLink>
<EuiHeaderLink iconType="help">Help</EuiHeaderLink>
</EuiHeaderLinks>
</EuiHeaderSectionItem>
</EuiHeaderSection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export const euiHeaderLinksStyles = ({ euiTheme }: UseEuiTheme) => {
.euiHeaderLink {
display: block;
${logicalCSS('width', '100%')}
padding: ${euiTheme.size.s};
/* EuiButtons normally center, which makes sense. In mobile though we want
* them to align left. This is a safe hack given the specificity. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const EuiHeaderLinks: FunctionComponent<EuiHeaderLinksProps> = ({
isOpen={mobileMenuIsOpen}
anchorPosition="downRight"
closePopover={closeMenu}
panelPaddingSize="none"
panelPaddingSize="s"
repositionOnScroll
{...popoverProps}
>
Expand Down

0 comments on commit e143ed0

Please sign in to comment.