Skip to content

Commit

Permalink
feat(navbar): various navbar spacing tweaks (#2855)
Browse files Browse the repository at this point in the history
* feat(navbar): various navbar spacing tweaks

* fix: add box-sizing

* fix: change switcher skeleton radius

* fix: use `SkeletonText` instead of `SkeletonDisplayText`

* fix: do not wrap `SwitcherSkeleton` in `Switcher`

* chore: release new navbar version
  • Loading branch information
andipaetzold authored Aug 30, 2024
1 parent b6985d6 commit dc9ba87
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 33 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion packages/components/navbar/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentful/f36-navbar",
"version": "5.0.0-alpha.29",
"version": "5.0.0-alpha.30",
"description": "Forma 36: Navbar component",
"scripts": {
"build": "tsup"
Expand Down
2 changes: 2 additions & 0 deletions packages/components/navbar/src/Navbar.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export const getNavbarStyles = ({

mobileNavigationButton: css({
display: 'flex',
minHeight: 'initial', // unset default 40px height
height: '36px',
padding: '0 12px',
borderRadius: '10px',
[mqs.small]: {
display: 'none',
Expand Down
18 changes: 13 additions & 5 deletions packages/components/navbar/src/NavbarItem/NavbarItem.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import tokens from '@contentful/f36-tokens';
import { hexToRGBA } from '@contentful/f36-utils';
import { getGlowOnFocusStyles, increaseHitArea, mqs } from '../utils.styles';

const borderWidth = '1px';

export const getNavbarItemActiveStyles = () =>
css({
backgroundColor: tokens.blue100,
border: `1px solid ${tokens.blue400}`,
border: `${borderWidth} solid ${tokens.blue400}`,
color: tokens.blue600,
'&:hover': {
backgroundColor: tokens.blue100,
Expand All @@ -16,19 +18,19 @@ export const getNavbarItemActiveStyles = () =>
const commonItemStyles = {
display: 'flex',
justifyContent: 'center',
padding: `${tokens.spacing2Xs} ${tokens.spacingXs}`,
padding: `calc(${tokens.spacing2Xs} - ${borderWidth}) calc(${tokens.spacingXs} - ${borderWidth})`,
alignItems: 'center',
background: 'none',
gap: tokens.spacing2Xs,
};

export const getNavbarItemStyles = ({ title }) => ({
export const getNavbarItemStyles = ({ hasTitle }: { hasTitle: boolean }) => ({
navbarItem: css(
commonItemStyles,
{
appearance: 'none',
background: 'none',
border: '1px solid transparent',
border: `${borderWidth} solid transparent`,
margin: 0,
outline: 'none',
fontSize: tokens.fontSizeM,
Expand All @@ -45,6 +47,10 @@ export const getNavbarItemStyles = ({ title }) => ({
transition: `color ${tokens.transitionDurationShort} ${tokens.transitionEasingCubicBezier}`,
borderRadius: tokens.borderRadiusMedium,

padding: hasTitle
? undefined
: `calc(${tokens.spacing2Xs} - ${borderWidth})`, // square button for icon-only items

'&:hover': {
backgroundColor: hexToRGBA(tokens.gray900, 0.05),
},
Expand Down Expand Up @@ -78,10 +84,12 @@ export const getNavbarItemStyles = ({ title }) => ({
icon: css({
height: '20px',
width: '20px',
display: !title ? 'block' : 'none',
boxSizing: 'content-box',
display: hasTitle ? 'none' : 'block',
[mqs.small]: {
height: '16px',
width: '16px',
padding: hasTitle ? '2px 0' : '2px', // square for icon-only items
},
[mqs.large]: {
display: 'block',
Expand Down
15 changes: 7 additions & 8 deletions packages/components/navbar/src/NavbarItem/NavbarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,18 @@ function _NavbarItem(
onClose,
...otherProps
} = props;
const styles = getNavbarItemStyles({ title });
const styles = getNavbarItemStyles({ hasTitle: !!title });
const isMenuTrigger = isNavbarItemHasMenu(props);
const showCaret = title && isMenuTrigger;
const item = (
<Comp
{...otherProps}
ref={ref}
data-test-id={testId}
className={cx(
styles.navbarItem,
isMenuTrigger && styles.navbarItemMenuTrigger,
isActive && styles.isActive,
className,
)}
className={cx(styles.navbarItem, className, {
[styles.navbarItemMenuTrigger]: showCaret,
[styles.isActive]: isActive,
})}
aria-label={title ? '' : label}
>
{icon && (
Expand All @@ -79,7 +78,7 @@ function _NavbarItem(
/>
)}
{title && <span>{title}</span>}
{title && isMenuTrigger && <CaretIcon size="tiny" isActive={isActive} />}
{showCaret && <CaretIcon size="tiny" isActive={isActive} />}
</Comp>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export const NavbarItemSkeleton = ({
<SkeletonContainer
className={styles.itemSkeleton}
svgWidth={estimatedWidth}
svgHeight={32}
svgHeight={28}
backgroundColor={tokens.gray300}
foregroundColor={tokens.gray200}
>
<SkeletonText
lineHeight={6}
lineHeight={18}
numberOfLines={1}
offsetTop={10}
offsetTop={2}
radiusX={tokens.borderRadiusSmall}
radiusY={tokens.borderRadiusSmall}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import React from 'react';
import {
SkeletonContainer,
SkeletonDisplayText,
} from '@contentful/f36-skeleton';
import { SkeletonContainer, SkeletonText } from '@contentful/f36-skeleton';
import tokens from '@contentful/f36-tokens';

export const NavbarSwitcherSkeleton = ({
Expand All @@ -12,15 +9,15 @@ export const NavbarSwitcherSkeleton = ({
}) => (
<SkeletonContainer
svgWidth={estimatedWidth}
svgHeight={24}
svgHeight={18}
backgroundColor={tokens.gray300}
foregroundColor={tokens.gray200}
>
<SkeletonDisplayText
lineHeight={24}
<SkeletonText
lineHeight={18}
numberOfLines={1}
radiusX={12}
radiusY={12}
radiusX={tokens.borderRadiusSmall}
radiusY={tokens.borderRadiusSmall}
/>
</SkeletonContainer>
);
6 changes: 1 addition & 5 deletions packages/components/navbar/stories/Navbar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,7 @@ export const LoadingSkeleton: Story<{}> = () => {
<Navbar
mobileNavigation={<MobileMenu />}
account={<Navbar.AccountSkeleton ariaLabel="Loading account" />}
switcher={
<Navbar.Switcher>
<Navbar.SwitcherSkeleton estimatedWidth={148} />
</Navbar.Switcher>
}
switcher={<Navbar.SwitcherSkeleton estimatedWidth={148} />}
mainNavigation={
<>
<Navbar.ItemSkeleton estimatedWidth={100} />
Expand Down

0 comments on commit dc9ba87

Please sign in to comment.