Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Increase column, show dash and use tooltip mobile #113

Merged
merged 6 commits into from
Jun 14, 2022
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
35 changes: 32 additions & 3 deletions src/components/orders/OrderSurplusDisplay/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import styled, { useTheme } from 'styled-components'
import styled, { css, useTheme, FlattenSimpleInterpolation } from 'styled-components'

import { Order } from 'api/operator'

Expand Down Expand Up @@ -101,11 +101,37 @@ const IconWrapper = styled(FontAwesomeIcon)`
}
`

export function OrderSurplusTooltipDisplay({ order }: Props): JSX.Element | null {
const HiddenSection = styled.span<{ showHiddenSection: boolean; strechHiddenSection?: boolean }>`
display: ${({ showHiddenSection }): string => (showHiddenSection ? 'flex' : 'none')};
${({ strechHiddenSection }): FlattenSimpleInterpolation | false | undefined =>
strechHiddenSection &&
css`
width: 3.4rem;
henrypalacios marked this conversation as resolved.
Show resolved Hide resolved
display: 'inline-block';
justify-content: end;
`}
`

export function OrderSurplusTooltipDisplay({
order,
amountSmartFormatting,
showHiddenSection = false,
defaultWhenNoSurplus,
strechWhenNoSurplus = false,
}: Props & {
showHiddenSection?: boolean
defaultWhenNoSurplus?: string
strechWhenNoSurplus?: boolean
}): JSX.Element {
const surplus = useGetSurplus(order)
const theme = useTheme()

if (!surplus) return null
if (!surplus)
return (
<HiddenSection showHiddenSection strechHiddenSection={strechWhenNoSurplus}>
{defaultWhenNoSurplus}
</HiddenSection>
)

return (
<BaseIconTooltipOnHover
Expand All @@ -114,6 +140,9 @@ export function OrderSurplusTooltipDisplay({ order }: Props): JSX.Element | null
<span>
<IconWrapper icon={faIcon} color={theme.green} />
<Surplus>{surplus.percentage}</Surplus>
<HiddenSection showHiddenSection={showHiddenSection}>
{amountSmartFormatting ? surplus.formattedSmartAmount : surplus.amount}
</HiddenSection>
</span>
}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import React from 'react'
import styled from 'styled-components'

import { media } from 'theme/styles/media'
import { Order } from 'api/operator'
import { useMediaBreakpoint } from 'hooks/useMediaBreakPoint'
import { OrderSurplusTooltipDisplay, OrderSurplusDisplay } from '../OrderSurplusDisplay'
import { OrderSurplusTooltipDisplay } from '../OrderSurplusDisplay'

type Props = React.HTMLAttributes<HTMLSpanElement> & {
order: Order
}

export const OrderSurplusDisplayStyled = styled(OrderSurplusDisplay)`
${media.mobile} {
flex-direction: column;
}
`
/**
* Displays surplus amount inside tooltip when display mode has little space to display
*/
export function OrderSurplusDisplayStyledByRow({ order }: { order: Order }): JSX.Element {
export function OrderSurplusDisplayStyledByRow({ order }: Props): JSX.Element {
const isDesktop = useMediaBreakpoint(['xl', 'lg'])
const showAmountBesideSurplus = !isDesktop
const defaultWhenNoSurplus = '-'

if (isDesktop) {
return <OrderSurplusTooltipDisplay order={order} />
}

return <OrderSurplusDisplayStyled order={order} amountSmartFormatting />
return (
<OrderSurplusTooltipDisplay
order={order}
amountSmartFormatting
showHiddenSection={showAmountBesideSurplus}
defaultWhenNoSurplus={defaultWhenNoSurplus}
strechWhenNoSurplus
/>
)
}
2 changes: 1 addition & 1 deletion src/components/orders/OrdersUserDetailsTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { OrderSurplusDisplayStyledByRow } from './OrderSurplusTooltipStyledByRow
const Wrapper = styled(StyledUserDetailsTable)`
> thead > tr,
> tbody > tr {
grid-template-columns: 12rem 5.5rem repeat(2, minmax(16rem, 1.5fr)) minmax(18rem, 2fr) 9rem minmax(21.6rem, 2fr) 1.18fr;
grid-template-columns: 11rem 5.5rem repeat(2, minmax(16rem, 1.5fr)) minmax(18rem, 2fr) 10rem minmax(21.6rem, 2fr) 1.18fr;
}
tr > td {
span.span-inside-tooltip {
Expand Down