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

separated the catergories without subs #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 70 additions & 2 deletions react/MegaMenu/components/Submenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ const Submenu: FC<ItemProps> = observer((props) => {
return categories
.filter((j) => j.display)
.map((category, i) => {
if(!category.menu?.length) {
return
}
const subcategories = category.menu?.length
? subCategories(category.menu)
: []
Expand Down Expand Up @@ -222,6 +225,66 @@ const Submenu: FC<ItemProps> = observer((props) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
[departmentActive, collapsibleStates]
)

const itemsWithNoSubCategories = useMemo(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the file, it seems that there's a fair bit of duplication between itemsWithSubCategories / items – We might want to extract the following, somehow:

const items = useMemo(
() => {
if (!departmentActive) return
if (departmentActive.menu) {
if (departmentActive.menu.length > 1) {
setShowBtnCat(true)
} else {
setShowBtnCat(false)
}
} else {
setShowBtnCat(false)
}
const categories = getCategories()
return categories
.filter((j) => j.display)

() => {
if (!departmentActive) return

if (departmentActive.menu) {
if (departmentActive.menu.length > 1) {
setShowBtnCat(true)
} else {
setShowBtnCat(false)
}
} else {
setShowBtnCat(false)
}

const categories = getCategories()

return categories
.filter((j) => j.display)
.map((category, i) => {
if(category.menu?.length) {
return
}
return (
<div
key={category.id}
className={classNames(
applyModifiers(
orientation === 'horizontal'
? styles.submenuItem
: handles.submenuItemVertical,
collapsibleStates[category.id] ? 'isOpen' : 'isClosed'
),
orientation === 'vertical' &&
'c-on-base bb b--light-gray mv0 ph5',
orientation === 'vertical' && i === 0 && 'bt',
collapsibleStates[category.id] && 'bg-near-white'
)}
>
<>
<Item
className="vtex-title-link"
to={category.slug}
iconId={category.icon}
level={2}
style={category.styles}
isTitle
enableStyle={category.enableSty}
closeMenu={closeMenu}
>
{category.name}
</Item>
</>
</div>
)
})
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[departmentActive, collapsibleStates]
)

return (
<>
Expand All @@ -244,7 +307,7 @@ const Submenu: FC<ItemProps> = observer((props) => {
</>
)}
</h3>

<div className='syatt-mega-menu-3-x-categories-container'>
<div
className={classNames(
orientation === 'horizontal' && styles.submenuList,
Expand All @@ -253,7 +316,8 @@ const Submenu: FC<ItemProps> = observer((props) => {
>
{orientation === 'horizontal' ? (
<>
<ExtensionPoint id="before-menu" /> {items}{' '}
<ExtensionPoint id="before-menu" />
{items}
<ExtensionPoint id="after-menu" />
</>
) : (
Expand All @@ -262,6 +326,10 @@ const Submenu: FC<ItemProps> = observer((props) => {
</>
)}
</div>
<div className='syatt-mega-menu-3-x-sub-catergories--no-sub'>
{itemsWithNoSubCategories}
</div>
</div>
</>
)}
</>
Expand Down
34 changes: 30 additions & 4 deletions react/MegaMenu/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,36 @@
width: 300px;
}

.categories-container {
display:flex;
}

.categories-container > .submenuList > .submenuItem{
margin-right: 2rem;
}

.submenuList {
display: grid;
gap: 2rem;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
display: flex;
/* display: grid; */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these stylings that are commented out necessary here or can we remove?

/* gap: 0.5rem; */
/* grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); */
flex-wrap: wrap;
}

.sub-catergories--no-sub {
width: 25rem;
max-height: 30rem;
display: flex;
flex-direction: column;
flex-wrap: wrap;
}

.sub-catergories--no-sub > .submenuItem {
margin: 0 1rem 1rem 0;
}

.sub-catergories--no-sub > .submenuItem > .styledLinkContainer > .styledLink {
font-size: 0.85rem;
}

.submenuList > .submenuItem {
Expand All @@ -21,7 +47,7 @@
.styledLink,
.goBackButton,
.triggerContainer {
font-weight: bold;
font-weight: 600;
border: none;
background: transparent;
outline: transparent;
Expand Down