Skip to content

Commit

Permalink
misc(NavigationTab) update the API to allow leftSpacing object (#1726)
Browse files Browse the repository at this point in the history
* misc(NavigationTab) update the API to allow leftSpacing object

* misc: update NavigationTab invocations to use new API
  • Loading branch information
ansmonjol authored Sep 10, 2024
1 parent d14648c commit d360fc8
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 22 deletions.
29 changes: 15 additions & 14 deletions src/components/designSystem/NavigationTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import { ReactNode, useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import styled, { css } from 'styled-components'

import { ResponsiveStyleValue, setResponsiveProperty } from '~/core/utils/responsiveProps'
import { theme } from '~/styles'

import { Icon, IconName } from './Icon'
import { Skeleton } from './Skeleton'

type LeftSpacing = 0 | 16 | 48

type NavigationTabProps = {
leftPadding?: boolean
leftSpacing?: ResponsiveStyleValue<LeftSpacing>
loading?: boolean
name?: string
tabs: {
Expand Down Expand Up @@ -53,7 +56,7 @@ const a11yProps = (index: number) => {
}

export const NavigationTab = ({
leftPadding = false,
leftSpacing = 16,
loading,
name = 'Navigation tab',
tabs,
Expand Down Expand Up @@ -97,7 +100,7 @@ export const NavigationTab = ({
aria-label={name}
onChange={handleChange}
value={value}
$leftPadding={leftPadding}
$leftSpacing={leftSpacing}
$nonHiddenTabsLength={nonHiddenTabs.length}
>
{nonHiddenTabs.length >= 2
Expand Down Expand Up @@ -152,21 +155,19 @@ const TabsWrapper = styled.div`
box-shadow: ${theme.shadows[7]};
`

const LocalTabs = styled(Tabs)<{ $leftPadding: boolean; $nonHiddenTabsLength: number }>`
const LocalTabs = styled(Tabs)<{
$leftSpacing: ResponsiveStyleValue<LeftSpacing>
$nonHiddenTabsLength: number
}>`
align-items: center;
overflow: visible;
min-height: ${({ $nonHiddenTabsLength }) => ($nonHiddenTabsLength > 1 ? theme.spacing(13) : 0)};
${({ $leftPadding }) =>
!!$leftPadding &&
css`
padding-left: ${theme.spacing(12)};
width: fit-content;
${theme.breakpoints.down('md')} {
padding-left: ${theme.spacing(4)};
}
`};
${({ $leftSpacing }) => {
return css`
${setResponsiveProperty('paddingLeft', $leftSpacing)}
`
}}
.MuiTabs-indicator {
/* We hide the default MUI selected tab indicator. It's manually handled by us bellow */
Expand Down
7 changes: 6 additions & 1 deletion src/layouts/CustomerInvoiceDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,12 @@ const CustomerInvoiceDetails = () => {
</div>
</MainInfos>
)}
<NavigationTab name="Invoice details tab switcher" tabs={tabsOptions} loading={loading} />
<NavigationTab
leftSpacing={0}
name="Invoice details tab switcher"
tabs={tabsOptions}
loading={loading}
/>
<Outlet />
</Content>
)}
Expand Down
8 changes: 7 additions & 1 deletion src/layouts/Developers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ const Developers = () => {
{translate('text_6271200984178801ba8bdebe')}
</Typography>
</PageHeader>
<NavigationTab leftPadding tabs={tabsOptions} />
<NavigationTab
leftSpacing={{
default: 16,
md: 48,
}}
tabs={tabsOptions}
/>
<Content>
<Outlet />
</Content>
Expand Down
1 change: 1 addition & 0 deletions src/pages/CustomerDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ const CustomerDetails = () => {

<StyledTabs data-test="customer-navigation-wrapper">
<NavigationTab
leftSpacing={0}
tabs={[
{
title: translate('text_628cf761cbe6820138b8f2e4'),
Expand Down
5 changes: 4 additions & 1 deletion src/pages/InvoicesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@ const InvoicesPage = () => {
</HeaderRigthBlock>
</PageHeader>
<NavigationTab
leftPadding
leftSpacing={{
default: 16,
md: 48,
}}
tabs={[
{
title: translate('text_63ac86d797f728a87b2f9f85'),
Expand Down
2 changes: 1 addition & 1 deletion src/pages/PlanDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const PlanDetails = () => {
</PlanBlockInfos>
</PlanBlockWrapper>
<NavigationTab
leftPadding
leftSpacing={48}
loading={isPlanLoading}
tabs={[
{
Expand Down
2 changes: 1 addition & 1 deletion src/pages/__devOnly/DesignSystem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const DesignSystem = () => {
<Typography variant="caption">Only visible in dev mode</Typography>
</PageHeader>
<NavigationTab
leftPadding
leftSpacing={48}
name="Design system tab switcher"
tabs={[
{
Expand Down
5 changes: 4 additions & 1 deletion src/pages/settings/AnrokIntegrationDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ const AnrokIntegrationDetails = () => {
</MainInfos>

<NavigationTab
leftPadding
leftSpacing={{
default: 16,
md: 48,
}}
loading={loading}
tabs={[
{
Expand Down
5 changes: 4 additions & 1 deletion src/pages/settings/NetsuiteIntegrationDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ const NetsuiteIntegrationDetails = () => {
</MainInfos>

<NavigationTab
leftPadding
leftSpacing={{
default: 16,
md: 48,
}}
loading={loading}
tabs={[
{
Expand Down
5 changes: 4 additions & 1 deletion src/pages/settings/XeroIntegrationDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ const XeroIntegrationDetails = () => {
</MainInfos>

<NavigationTab
leftPadding
leftSpacing={{
default: 16,
md: 48,
}}
loading={loading}
tabs={[
{
Expand Down

0 comments on commit d360fc8

Please sign in to comment.