Skip to content

Commit 37b263d

Browse files
authored
Merge pull request #668 from strapi/enhancement/subnav-v2-alignment
Subnav (v2): Improve styling of child links
2 parents 2058895 + 4ffccb4 commit 37b263d

File tree

7 files changed

+304
-270
lines changed

7 files changed

+304
-270
lines changed

packages/strapi-design-system/src/v2/SubNav/SubNav.stories.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ import {
106106
</SubNavLink>
107107
))}
108108
</SubNavSection>
109-
<Box paddingLeft={7}>
109+
<Box paddingLeft={7} paddingBottom={3}>
110110
<TextButton startIcon={<Plus />}>Click on me</TextButton>
111111
</Box>
112112
<SubNavSection label="Single Type" collapsable badgeLabel={links.length.toString()}>
113113
<SubNavLinkSection label="Default">
114114
{links.map((link) => (
115-
<SubNavLink to={link.to} key={link.id}>
115+
<SubNavLink to={link.to} key={link.id} isSubSectionChild>
116116
{link.label}
117117
</SubNavLink>
118118
))}
@@ -135,7 +135,7 @@ import {
135135
{links.map(
136136
(link) =>
137137
link.icon && (
138-
<SubNavLink to={link.to} active={link.active} icon={link.icon} key={link.id}>
138+
<SubNavLink to={link.to} active={link.active} icon={link.icon} key={link.id} isSubSectionChild>
139139
{link.label}
140140
</SubNavLink>
141141
),

packages/strapi-design-system/src/v2/SubNav/SubNavLink.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ const IconWrapper = styled.div`
5151
}
5252
`;
5353

54-
export const SubNavLink = React.forwardRef(({ children, icon, withBullet, as, ...props }, ref) => {
54+
export const SubNavLink = React.forwardRef(({ children, icon, withBullet, as, isSubSectionChild, ...props }, ref) => {
5555
return (
5656
<SubNavLinkWrapper
5757
as={as}
5858
icon={icon}
5959
background="neutral100"
60-
paddingLeft={7}
60+
paddingLeft={isSubSectionChild ? 9 : 7}
6161
paddingBottom={2}
6262
paddingTop={2}
6363
ref={ref}
@@ -82,12 +82,14 @@ SubNavLink.displayName = 'SubNavLink';
8282
SubNavLink.defaultProps = {
8383
as: BaseLink,
8484
icon: null,
85+
isSubSectionChild: false,
8586
withBullet: false,
8687
};
8788
SubNavLink.propTypes = {
8889
as: PropTypes.elementType,
8990
children: PropTypes.node,
9091
icon: PropTypes.element,
92+
isSubSectionChild: PropTypes.bool,
9193
link: PropTypes.element,
9294
withBullet: PropTypes.bool,
9395
};

packages/strapi-design-system/src/v2/SubNav/SubNavLinkSection.js

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { Typography } from '../../Typography';
88
import { useId } from '../../helpers/useId';
99

1010
const SubNavLinkSectionWrapper = styled(Box)`
11-
max-height: ${32 / 16}rem;
1211
svg {
1312
height: ${4 / 16}rem;
1413
path {

packages/strapi-design-system/src/v2/SubNav/SubNavSection.js

+16-14
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,19 @@ import React, { Children, useState } from 'react';
22
import PropTypes from 'prop-types';
33
import styled from 'styled-components';
44
import { Box } from '../../Box';
5-
import { Flex } from '../../Flex';
65
import { Badge } from '../../Badge';
6+
import { Stack } from '../../Stack';
77
import { SubNavSectionLabel } from './SubNavSectionLabel';
88
import { useId } from '../../helpers/useId';
99

1010
const SubNavSectionWrapper = styled(Box)`
11-
max-height: ${32 / 16}rem;
1211
svg {
1312
height: ${4 / 16}rem;
1413
path {
1514
fill: ${({ theme }) => theme.colors.neutral500};
1615
}
1716
}
1817
`;
19-
const SubNavSectionBadge = styled(Badge)`
20-
display: flex;
21-
align-items: center;
22-
`;
2318

2419
export const SubNavSection = ({ collapsable, label, badgeLabel, children, id }) => {
2520
const [isOpen, setOpenLinks] = useState(true);
@@ -30,9 +25,9 @@ export const SubNavSection = ({ collapsable, label, badgeLabel, children, id })
3025
};
3126

3227
return (
33-
<Box>
28+
<Stack spacing={1}>
3429
<SubNavSectionWrapper paddingLeft={6} paddingTop={2} paddingBottom={2} paddingRight={4}>
35-
<Flex justifyContent="space-between">
30+
<Box position="relative" paddingRight={badgeLabel ? 6 : 0}>
3631
<SubNavSectionLabel
3732
onClick={handleClick}
3833
ariaExpanded={isOpen}
@@ -41,20 +36,27 @@ export const SubNavSection = ({ collapsable, label, badgeLabel, children, id })
4136
label={label}
4237
/>
4338
{badgeLabel && (
44-
<SubNavSectionBadge backgroundColor="neutral150" textColor="neutral600">
39+
<Badge
40+
backgroundColor="neutral150"
41+
textColor="neutral600"
42+
position="absolute"
43+
right={0}
44+
top="50%"
45+
transform="translateY(-50%)"
46+
>
4547
{badgeLabel}
46-
</SubNavSectionBadge>
48+
</Badge>
4749
)}
48-
</Flex>
50+
</Box>
4951
</SubNavSectionWrapper>
5052
{(!collapsable || isOpen) && (
51-
<ul id={listId}>
53+
<ol id={listId}>
5254
{Children.map(children, (child, index) => {
5355
return <li key={index}>{child}</li>;
5456
})}
55-
</ul>
57+
</ol>
5658
)}
57-
</Box>
59+
</Stack>
5860
);
5961
};
6062

packages/strapi-design-system/src/v2/SubNav/SubNavSectionLabel.js

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const SubNavSectionLabel = ({ collapsable, label, onClick, ariaExpanded,
2525
onClick={onClick}
2626
aria-expanded={ariaExpanded}
2727
aria-controls={ariaControls}
28+
textAlign="left"
2829
>
2930
<Box paddingRight={1}>
3031
<Typography variant="sigma" textColor="neutral600">

packages/strapi-design-system/src/v2/SubNav/SubNavSections.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Box } from '../../Box';
66
export const SubNavSections = ({ children, ...props }) => {
77
return (
88
<Box paddingTop={2} paddingBottom={4}>
9-
<Stack as="ul" spacing={2} {...props}>
9+
<Stack as="ol" spacing={2} {...props}>
1010
{Children.map(children, (child, index) => {
1111
return <li key={index}>{child}</li>;
1212
})}

0 commit comments

Comments
 (0)