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(MenuItem): isNew prop and label #257

Merged
merged 3 commits into from
Aug 15, 2024
Merged
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
3 changes: 3 additions & 0 deletions src/assets/icons/new-label.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions src/components/Menu/Menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,18 @@ $border-color: rgba(255, 255, 255, 0.2);
}
}

&__new-label {
[dir='ltr'] & {
margin-left: -4px;
}

[dir='rtl'] & {
margin-right: -4px;
}

color: var(--g-color-text-brand);
}

&__link-icon {
align-self: baseline;
margin-top: 4px;
Expand Down
76 changes: 30 additions & 46 deletions src/components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import nextI18nextConfig from '../../../next-i18next.config';
import linkArrowIcon from '../../assets/icons/link-arrow.svg';
import menuCloseIcon from '../../assets/icons/menu-close.svg';
import menuOpenIcon from '../../assets/icons/menu-open.svg';
import newLabelIcon from '../../assets/icons/new-label.svg';
import soonLabelIcon from '../../assets/icons/soon-label.svg';
import {menu} from '../../content/menu';
import {MenuItem, menu} from '../../content/menu';
import {socialLinks} from '../../content/social-links';
import {EnvironmentContext} from '../../contexts';
import {block} from '../../utils';
Expand All @@ -31,6 +32,32 @@ export const Menu: React.FC = () => {

const {isRtl} = React.useContext(EnvironmentContext);

const renderItem = (item: MenuItem) => {
if (item.isComingSoon) {
return (
<div className={b('link', {lg: true, disabled: true})}>
<div className={b('comming-soon')}>
<div className={b('comming-soon-text')}>{t(item.titleKey)}</div>
<div className={b('comming-soon-label')}>
<Icon data={soonLabelIcon} width={46} height={20} />
</div>
</div>
</div>
);
}

return (
<Link href={item.url} className={b('link', {lg: true})}>
{t(item.titleKey)}
{item.isNew ? (
<div className={b('new-label')}>
<Icon data={newLabelIcon} width={46} height={20} />
</div>
) : null}
</Link>
);
};

return (
<div className={b()}>
<div className={b('wrapper', {open: mobileMenuOpen})}>
Expand All @@ -50,27 +77,7 @@ export const Menu: React.FC = () => {
).startsWith(item.url),
})}
>
{item.isComingSoon ? (
<div
className={b('link', {
lg: true,
disabled: true,
})}
>
<div className={b('comming-soon')}>
<div className={b('comming-soon-text')}>
{t(item.titleKey)}
</div>
<div className={b('comming-soon-label')}>
<Icon data={soonLabelIcon} width={46} height={20} />
</div>
</div>
</div>
) : (
<Link href={item.url} className={b('link', {lg: true})}>
{t(item.titleKey)}
</Link>
)}
{renderItem(item)}
</div>
))}
</div>
Expand Down Expand Up @@ -114,30 +121,7 @@ export const Menu: React.FC = () => {
<div className={b('mobile-menu-items')}>
{menu.map((item) => (
<div className={b('mobile-menu-item')} key={item.titleKey}>
{item.isComingSoon ? (
<div className={b('link', {lg: true, disabled: true})}>
<div className={b('comming-soon')}>
<div className={b('comming-soon-text')}>
{t(item.titleKey)}
</div>
<div className={b('comming-soon-label')}>
<Icon
data={soonLabelIcon}
width={46}
height={20}
/>
</div>
</div>
</div>
) : (
<Link
href={item.url}
key={item.titleKey}
className={b('link', {lg: true})}
>
{t(item.titleKey)}
</Link>
)}
{renderItem(item)}
</div>
))}
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/content/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export type MenuItem = {
titleKey: string;
url: string;
isComingSoon?: boolean;
isNew?: boolean;
};

export const menu: MenuItem[] = [
Expand All @@ -25,5 +26,6 @@ export const menu: MenuItem[] = [
{
titleKey: 'menu_themer',
url: '/themer',
isNew: true,
},
];
Loading