Skip to content

Commit

Permalink
Merge pull request #3449 from cowprotocol/hotfix/1.50.1
Browse files Browse the repository at this point in the history
fix: adds NEW! tag to MORE menu item (#3448)
  • Loading branch information
fairlighteth authored Nov 27, 2023
2 parents 2884417 + f6a4358 commit b5c1d49
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 30 deletions.
6 changes: 6 additions & 0 deletions apps/cowswap-frontend/src/legacy/components/Header/styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ export const HeaderLinks = styled(HeaderLinksMod)<{ isMobileMenuOpen: boolean }>
height: 10px;
}
`};
${({ theme }) => theme.mediaWidth.upToSmall`
> button > svg {
order: 3;
}
`};
}
${MenuContent} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ import SVG from 'react-inlinesvg'

import { useMediaQuery, LargeAndUp } from 'legacy/hooks/useMediaQuery'

import { MenuBadge } from 'modules/mainMenu/pure/MenuTree/styled'

import { MenuFlyout, Content } from './styled'

interface MenuProps {
title: string
badge?: string
children: React.ReactNode
}

export function Menu({ title, children }: MenuProps) {
export function Menu({ title, badge, children }: MenuProps) {
const isLargeAndUp = useMediaQuery(LargeAndUp)
const node = useRef<HTMLOListElement>()
const [showMenu, setShowMenu] = useState(false)
Expand All @@ -29,6 +32,7 @@ export function Menu({ title, children }: MenuProps) {
<MenuFlyout ref={node as any}>
<button onClick={handleOnClick} className={showMenu ? 'expanded' : ''}>
{title} <SVG src={IMAGE_CARRET_DOWN} description="dropdown icon" className={showMenu ? 'expanded' : ''} />
{badge && <MenuBadge>{badge}</MenuBadge>}
</button>
{showMenu && <Content onClick={handleOnClick}>{children}</Content>}
</MenuFlyout>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { BadgeType } from '@cowprotocol/ui'

import { Widget } from 'modules/application/pure/Widget'

import { TradeWidgetLinks, BadgeType } from '.';
import { TradeWidgetLinks } from '.'

type BadgeInfo = {
text: string;
type: BadgeType;
text: string
type: BadgeType
}

const BADGES: BadgeInfo[] = [
Expand All @@ -13,24 +15,21 @@ const BADGES: BadgeInfo[] = [
{ text: 'ALPHA', type: 'alert' },
{ text: 'NEW!', type: 'alert2' },
{ text: 'RELEASE', type: 'information' },
];
]

type Fixtures = {
[key: string]: React.FunctionComponent;
};
[key: string]: React.FunctionComponent
}

const BadgeFixtures = BADGES.reduce<Fixtures>((fixtures, badge) => {
const Fixture = () => (
<Widget>
<TradeWidgetLinks
highlightedBadgeText={badge.text}
highlightedBadgeType={badge.type}
/>
<TradeWidgetLinks highlightedBadgeText={badge.text} highlightedBadgeType={badge.type} />
</Widget>
);
)

fixtures[`Badge - ${badge.text} (${badge.type})`] = Fixture;
return fixtures;
}, {});
fixtures[`Badge - ${badge.text} (${badge.type})`] = Fixture
return fixtures
}, {})

export default BadgeFixtures;
export default BadgeFixtures
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from 'react'

import { BadgeType } from '@cowprotocol/ui'
import type { TradeType } from '@cowprotocol/widget-lib'

import { Trans } from '@lingui/macro'
Expand All @@ -26,17 +27,10 @@ interface MenuItemConfig {
badgeType?: BadgeType
}

export type BadgeType = 'information' | 'success' | 'alert' | 'alert2' | 'default'

const MENU_ITEMS: MenuItemConfig[] = [
{ route: Routes.SWAP, label: 'Swap' },
{ route: Routes.LIMIT_ORDER, label: 'Limit' },
{
route: Routes.ADVANCED_ORDERS,
label: 'TWAP',
badgeText: 'NEW!',
badgeType: 'alert2',
},
{ route: Routes.ADVANCED_ORDERS, label: 'TWAP' },
]

const TRADE_TYPE_TO_ROUTE: Record<TradeType, string> = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BadgeType } from '@cowprotocol/ui'

import { NavLink } from 'react-router-dom'
import styled, { css } from 'styled-components/macro'

import { UI } from 'common/constants/theme'

import { BadgeType } from '.'

const badgeBackgrounds: Record<BadgeType, string> = {
information: `var(${UI.COLOR_INFORMATION_BG})`,
alert: `var(${UI.COLOR_ALERT_BG})`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const MAIN_MENU: MenuTreeItem[] = [
{
kind: MenuItemKind.DROP_DOWN,
title: 'More',
badge: 'New!',
items: [
{
sectionTitle: 'Overview',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ interface DropdownProps {
}

const DropDown = ({ item, context }: DropdownProps) => {
const { title, items } = item
const { title, items, badge } = item

return (
<MenuDropdown title={title}>
<MenuDropdown title={title} badge={badge}>
{items?.map((item, index) => {
const { sectionTitle, links } = item
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { UI } from 'common/constants/theme'
export const MenuBadge = styled.div`
display: flex;
align-items: center;
padding: 0 5px;
margin-left: 5px;
padding: 3px 5px;
margin: 0 0 0 5px;
background: var(${UI.COLOR_ALERT2_BG});
color: var(${UI.COLOR_ALERT2_TEXT});
border: 0;
Expand Down
1 change: 1 addition & 0 deletions apps/cowswap-frontend/src/modules/mainMenu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export interface DropDownItem {
kind: MenuItemKind.DROP_DOWN
title: string
items: DropDownSubItem[]
badge?: string
}

export type MenuTreeItem = InternalLink | ExternalLink | DropDownItem | ParametrizedLink | CustomItem
Expand Down
1 change: 1 addition & 0 deletions libs/ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './pure/Tooltip'
export * from './pure/Popover'
export * from './pure/ExternalLink'
export * from './enum'
export * from './types'
2 changes: 2 additions & 0 deletions libs/ui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ export type ComposableCowInfo = {
isVirtualPart?: boolean
isTheLastPart?: boolean
}

export type BadgeType = 'information' | 'success' | 'alert' | 'alert2' | 'default'

2 comments on commit b5c1d49

@vercel
Copy link

@vercel vercel bot commented on b5c1d49 Nov 27, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on b5c1d49 Nov 27, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

cosmos – ./

cosmos-git-main-cowswap.vercel.app
cosmos-cowswap.vercel.app
cowswap-seven.vercel.app
cosmos.cow.fi

Please sign in to comment.