Skip to content

Commit

Permalink
✨ Replace Tabs and skipnav ReachUI with ChakraUI components (#1378)
Browse files Browse the repository at this point in the history
  • Loading branch information
millianapia committed Dec 6, 2022
1 parent e2cf983 commit 96544d2
Show file tree
Hide file tree
Showing 8 changed files with 1,626 additions and 110 deletions.
90 changes: 74 additions & 16 deletions web/components/src/Tabs/Tab.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
import { forwardRef, CSSProperties } from 'react'
import { Tab as RTab, TabProps as RTabProps } from '@reach/tabs'
import styled from 'styled-components'
import { outlineTemplate, Tokens } from '@utils'
import { Tab as CTab } from '@chakra-ui/react'
import { Tab as RTab, TabProps as RTabProps } from '@reach/tabs'
import { Flags } from '../../../common/helpers/datasetHelpers'

const { outline } = Tokens

const StyledCTab = styled(CTab)`
color: var(--font-color);
background: transparent;
border: none;
padding: var(--space-xSmall) 0;
/* Not sure about this one, but some spaces for tab components that wrap multiple lines */
margin-bottom: var(--space-small);
:not(:last-child) {
margin-right: var(--space-medium);
}
&:hover {
cursor: pointer;
}
/* If the text is used inside a inverted component, the text colour must also be inverted */
.inverted-background & {
color: var(--inverted-text);
}
&:focus-visible {
outline: none;
${outlineTemplate(outline)}
outline-color: var(--mist-blue-100);
}
&[data-selected] {
border-bottom: 2px solid;
}
`

const StyledTab = styled(RTab)`
color: var(--font-color);
background: transparent;
Expand Down Expand Up @@ -37,20 +69,46 @@ const StyledTab = styled(RTab)`

export type TabProps = RTabProps & {
inverted?: boolean
variant?: string
}

export const Tab = forwardRef<HTMLButtonElement, TabProps>(function Tab({ inverted = false, children, ...rest }, ref) {
return (
<StyledTab
ref={ref}
{...rest}
style={
{
'--font-color': inverted ? 'var(--inverted-text)' : 'var(--default-text)',
} as CSSProperties
}
>
{children}
</StyledTab>
)
})
export const Tab = Flags.IS_DEV
? forwardRef<HTMLButtonElement, TabProps>(function CTab(
{ inverted = false, children, variant = 'line', ...rest },
ref,
) {
return (
<StyledCTab
ref={ref}
_selected={{
'--font-color': inverted ? 'var(--inverted-text)' : 'var(--default-text)',
borderColor: inverted ? 'var(--inverted-text)' : 'var(--default-text)',
borderBottom: '2px solid',
}}
variant={variant}
{...rest}
style={
{
'--font-color': inverted ? 'var(--inverted-text)' : 'var(--default-text)',
} as CSSProperties
}
>
{children}
</StyledCTab>
)
})
: forwardRef<HTMLButtonElement, TabProps>(function Tab({ inverted = false, children, ...rest }, ref) {
return (
<StyledTab
ref={ref}
{...rest}
style={
{
'--font-color': inverted ? 'var(--inverted-text)' : 'var(--default-text)',
} as CSSProperties
}
>
{children}
</StyledTab>
)
})
29 changes: 22 additions & 7 deletions web/components/src/Tabs/TabList.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import { forwardRef } from 'react'
import { TabList as CTabList } from '@chakra-ui/react'
import { TabList as RTabList, TabListProps as RTabListProps } from '@reach/tabs'
import { Flags } from '../../../common/helpers/datasetHelpers'

export type TabListProps = RTabListProps

export const TabList = forwardRef<HTMLDivElement, TabListProps>(function TabList({ children, ...rest }, ref) {
return (
<RTabList ref={ref} {...rest}>
{children}
</RTabList>
)
})
export type ChakraTabListProps = {
inverted?: boolean
children: React.ReactNode
variant?: string
}
export const TabList = Flags.IS_DEV
? forwardRef<HTMLDivElement, ChakraTabListProps>(function TabList({ children, ...rest }, ref) {
return (
<CTabList ref={ref} {...rest} style={{ border: 'none' }}>
{children}
</CTabList>
)
})
: forwardRef<HTMLDivElement, TabListProps>(function TabList({ children, ...rest }, ref) {
return (
<RTabList ref={ref} {...rest}>
{children}
</RTabList>
)
})
28 changes: 21 additions & 7 deletions web/components/src/Tabs/TabPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import { forwardRef } from 'react'
import { TabPanel as RTabPanel, TabPanelProps as RTabPanelProps } from '@reach/tabs'
import { TabPanel as CTabPanel } from '@chakra-ui/react'
import { Flags } from '../../../common/helpers/datasetHelpers'

export type TabPanelProps = RTabPanelProps

export const TabPanel = forwardRef<HTMLDivElement, TabPanelProps>(function TabPanel({ children, ...rest }, ref) {
return (
<RTabPanel ref={ref} {...rest}>
{children}
</RTabPanel>
)
})
export type ChakraTabPanelProps = {
inverted?: boolean
children: React.ReactNode
}
export const TabPanel = Flags.IS_DEV
? forwardRef<HTMLDivElement, ChakraTabPanelProps>(function TabPanel({ children, ...rest }, ref) {
return (
<CTabPanel ref={ref} {...rest}>
{children}
</CTabPanel>
)
})
: forwardRef<HTMLDivElement, TabPanelProps>(function TabPanel({ children, ...rest }, ref) {
return (
<RTabPanel ref={ref} {...rest}>
{children}
</RTabPanel>
)
})
28 changes: 21 additions & 7 deletions web/components/src/Tabs/TabPanels.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import { forwardRef } from 'react'
import { TabPanels as RTabPanels, TabPanelsProps as RTabPanelsProps } from '@reach/tabs'
import { TabPanels as CTabPanels } from '@chakra-ui/react'
import { Flags } from '../../../common/helpers/datasetHelpers'

export type TabPanelsProps = RTabPanelsProps

export const TabPanels = forwardRef<HTMLDivElement, TabPanelsProps>(function TabPanels({ children, ...rest }, ref) {
return (
<RTabPanels ref={ref} {...rest}>
{children}
</RTabPanels>
)
})
export type ChakraTabPanelsProps = {
inverted?: boolean
children: React.ReactNode
}
export const TabPanels = Flags.IS_DEV
? forwardRef<HTMLDivElement, ChakraTabPanelsProps>(function TabPanels({ children, ...rest }, ref) {
return (
<CTabPanels ref={ref} {...rest}>
{children}
</CTabPanels>
)
})
: forwardRef<HTMLDivElement, TabPanelsProps>(function TabPanels({ children, ...rest }, ref) {
return (
<RTabPanels ref={ref} {...rest}>
{children}
</RTabPanels>
)
})
43 changes: 36 additions & 7 deletions web/components/src/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
import { forwardRef } from 'react'

import { Tabs as CTabs } from '@chakra-ui/react'
import { Tabs as RTabs, TabsProps as RTabsProps } from '@reach/tabs'
import { Flags } from '../../../common/helpers/datasetHelpers'

export type ChakraTabsProps = {

This comment has been minimized.

Copy link
@fernandolucchesi

fernandolucchesi Dec 21, 2022

Contributor

I believe you can remove this and import directly from the lib like it was done for the reach UI before

align?: 'center' | 'end' | 'start'
colorScheme?: string
defaultIndex?: number
direction?: 'ltr' | 'rtl'
id?: string
index?: number
isFitted?: boolean
isLazy?: boolean
isManual?: boolean
lazyBehaviour?: any
onChange?: (index: number) => void
orientation?: 'horizontal' | 'vertical'
size?: 'sm' | 'md' | 'lg'
variant?: 'line' | 'enclosed' | 'enclosed-colored' | 'soft-rounded' | 'solid-rounded' | 'unstyled'
inverted?: boolean
children: React.ReactNode
}

export type TabsProps = RTabsProps

export const Tabs = forwardRef<HTMLDivElement, TabsProps>(function Tabs({ children, ...rest }, ref) {
return (
<RTabs ref={ref} {...rest}>
{children}
</RTabs>
)
})
export const Tabs = Flags.IS_DEV
? forwardRef<HTMLDivElement, ChakraTabsProps>(function Tabs({ children, ...rest }, ref) {
return (
<CTabs ref={ref} {...rest}>
{children}
</CTabs>
)
})
: forwardRef<HTMLDivElement, TabsProps>(function Tabs({ children, ...rest }, ref) {
return (
<RTabs ref={ref} {...rest}>
{children}
</RTabs>
)
})
5 changes: 5 additions & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"type-check": "tsc --project tsconfig.json --pretty --noEmit"
},
"dependencies": {
"@chakra-ui/react": "^2.4.2",
"@chakra-ui/skip-nav": "^2.0.12",
"@emotion/react": "^11",
"@emotion/styled": "^11",
"@equinor/eds-core-react": "0.27.0",
"@equinor/eds-icons": "^0.16.0",
"@equinor/eds-tokens": "^0.9.0",
Expand All @@ -43,6 +47,7 @@
"date-fns-tz": "^1.3.4",
"easy-soap-request": "^4.6.0",
"focus-visible": "^5.2.0",
"framer-motion": "^6",
"friendly-challenge": "^0.9.6",
"hls.js": "^1.1.5",
"html-entities": "^2.3.2",
Expand Down
32 changes: 21 additions & 11 deletions web/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AppProps } from 'next/app'
import type { NextPage } from 'next'
import type { ReactNode } from 'react'
import { ChakraProvider } from '@chakra-ui/react'
import Head from 'next/head'
import { useRouter } from 'next/router'
import { GlobalStyle } from '../styles/globalStyles'
Expand All @@ -15,6 +16,8 @@ import useConsentState from '../lib/hooks/useConsentState'
import { loadSiteImproveScript, cleanUpSiteImproveScript } from '../pageComponents/SiteImprove'
import { enableDynatrace, disableDynatrace } from '../pageComponents/Dynatrace'
import { SWRConfig } from 'swr'
import { SkipNavLink as NewSkipNavLink, SkipNavContent } from '@chakra-ui/skip-nav'
import { Flags } from '../common/helpers/datasetHelpers'

// import archivedStyles from '@equinor/energyvision-legacy-css'
// import { AppInsightsContext, AppInsightsErrorBoundary } from '@microsoft/applicationinsights-react-js'
Expand Down Expand Up @@ -103,17 +106,24 @@ function MyApp({ Component, pageProps }: CustomAppProps): JSX.Element {

return (
<SWRConfig>
<ErrorBoundary FallbackComponent={ErrorFallback} onError={HandleBoundaryError}>
<>
<Head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</Head>
<GlobalStyle />
<SkipNavLink />
{IS_LIVE && <CookieBot locale={router.locale} />}
{getLayout(<Component {...pageProps} />)}
</>
</ErrorBoundary>
<ChakraProvider>
<ErrorBoundary FallbackComponent={ErrorFallback} onError={HandleBoundaryError}>
{Flags.IS_DEV && <NewSkipNavLink style={{ top: '10%' }}>Skip to Content</NewSkipNavLink>}
<>
<Head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</Head>
<GlobalStyle />
<SkipNavLink />
{IS_LIVE && <CookieBot locale={router.locale} />}
{Flags.IS_DEV ? (
<SkipNavContent>{getLayout(<Component {...pageProps} />)}</SkipNavContent>
) : (
<>{getLayout(<Component {...pageProps} />)}</>
)}
</>
</ErrorBoundary>
</ChakraProvider>
</SWRConfig>
)
}
Expand Down
Loading

1 comment on commit 96544d2

@fernandolucchesi
Copy link
Contributor

Choose a reason for hiding this comment

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

tabs look different from the old one, it also has an active color that should be removed.
image

it also doesn't break into different lines on mobile view:
image
vs
image

Please sign in to comment.