Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve responsiveness of navbar #2934

Merged
merged 13 commits into from
Nov 26, 2024
8 changes: 5 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion packages/components/navbar/src/Navbar.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ export const getNavbarStyles = ({
},
},
}),

promoNavigationWrapper: css({
display: 'none',
[mqs.small]: {
display: 'flex',
},
}),
account: css({
display: 'none',
[mqs.xsmall]: {
Expand Down
9 changes: 8 additions & 1 deletion packages/components/navbar/src/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,14 @@ function _Navbar(props: ExpandProps<NavbarProps>, ref: React.Ref<HTMLElement>) {
)}
</Flex>
<Flex alignItems="center" gap="spacingXs">
<Flex alignItems="center">{promotions}</Flex>
<Flex
alignItems="center"
className={styles.promoNavigationWrapper}
aria-label="Promotions"
gap="spacingXs"
>
{promotions}
</Flex>
<Flex alignItems="center">{switcher}</Flex>
<Flex alignItems="center" gap="spacingXs">
{secondaryNavigation && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const getNavbarSwitcherStyles = ({
text: css({
color: 'currentcolor',
fontWeight: 'inherit',
lineHeight: 'unset',
}),

navbarSwitcher: ({ showSpaceEnv }: { showSpaceEnv: boolean }) =>
Expand Down Expand Up @@ -65,7 +66,7 @@ export const getNavbarSwitcherStyles = ({
},
maxWidth: '15vw',
[mqs.xsmall]: {
maxWidth: '50vw',
maxWidth: '25vw',
},
[mqs.small]: {
maxWidth: '10vw',
Expand All @@ -82,11 +83,42 @@ export const getNavbarSwitcherStyles = ({
},
}),

switcherSpaceNameStart: css({
display: 'inline-block',
verticalAlign: 'middle',
lineHeight: '1.25rem',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
width: '5ch',
[mqs.small]: {
width: 'unset',
},
}),

switcherSpaceNameTruncation: css({
flexShrink: 1,
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
lineHeight: '1.25rem',
verticalAlign: 'middle',
display: 'none',
[mqs.xsmall]: {
display: 'inline-block',
width: '5ch',
},
[mqs.medium]: {
width: 'unset',
},
}),

switcherSpaceNameEnd: css({
display: 'none',
[mqs.medium]: {
display: 'inline-block',
verticalAlign: 'middle',
lineHeight: '1.25rem',
},
}),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ const SwitcherLabel = ({ value, styles }: SwitcherLabelProps) => {

return start !== undefined ? (
<Text className={styles.text}>
<span>{start}</span>
<span className={styles.switcherSpaceNameStart}>{start}</span>
{middle && (
<span className={styles.switcherSpaceNameTruncation}>{middle}</span>
)}
{end && <span>{end}</span>}
{end && <span className={styles.switcherSpaceNameEnd}>{end}</span>}
</Text>
) : (
<Text className={styles.text}>{value}</Text>
Expand Down
1 change: 1 addition & 0 deletions packages/components/navbar/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { NAVBAR_HEIGHT } from './constants';
export { Navbar } from './CompoundNavbar';
export type { NavbarProps } from './Navbar';
export { getNavbarItemActiveStyles } from './NavbarItem/NavbarItem.styles';
export { mqs as navbarMediaQueries } from './utils.styles';
8 changes: 6 additions & 2 deletions packages/components/navbar/stories/Navbar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,12 @@ export const Complete: Story<{ initials?: string; avatar?: string }> = (
return (
<Navbar
mobileNavigation={<MobileMenu />}
promotions={<TextLink>Upgrade</TextLink>}
promotions={
<>
<TextLink>Upgrade</TextLink>
<Navbar.Item title="Feedback"></Navbar.Item>
</>
}
switcher={<Switcher />}
mainNavigation={<MainItems />}
account={
Expand All @@ -320,7 +325,6 @@ export const Complete: Story<{ initials?: string; avatar?: string }> = (
}
secondaryNavigation={
<>
<Navbar.Item title="Feedback"></Navbar.Item>
<Navbar.Item label="Quick Search" icon={<MagnifyingGlassIcon />} />
<Navbar.Item label="Help Menu" icon={<QuestionIcon />}>
<Navbar.MenuItem
Expand Down