Skip to content
Snippets Groups Projects
Commit 84307295 authored by Jure's avatar Jure
Browse files

feat: add display features to tabs

parent 5ed40d74
No related branches found
No related tags found
No related merge requests found
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } from 'react'
import styled from 'styled-components' import styled, { css } from 'styled-components'
import { th, override } from '@pubsweet/ui-toolkit' import { th, override } from '@pubsweet/ui-toolkit'
const Tab = styled.div` const Tab = styled.div`
padding: ${th('gridUnit')} 1em; padding: calc(${th('gridUnit')} - 1px) 1em;
font-size: ${th('fontSizeBaseSmall')}; font-size: ${th('fontSizeBaseSmall')};
font-weight: 500; font-weight: 500;
background-color: ${({ active }) => background-color: ${({ active }) =>
...@@ -17,16 +17,30 @@ const Tab = styled.div` ...@@ -17,16 +17,30 @@ const Tab = styled.div`
` `
const TabsContainer = styled.div` const TabsContainer = styled.div`
${props =>
props.background &&
css`
background-color: ${th(props.background)};
`}
display: flex; display: flex;
${props =>
props.gridArea &&
css`
grid-area: ${props.gridArea};
`}
` `
const TabContainer = styled.div.attrs(props => ({ const TabContainer = styled.div.attrs(props => ({
'data-test-id': props['data-test-id'] || 'tab-container', 'data-test-id': props['data-test-id'] || 'tab-container',
}))`` }))``
const Content = styled.div`` const Tabs = ({
sections,
const Tabs = ({ sections, onChange, defaultActiveKey = null }) => { onChange,
defaultActiveKey = null,
tabsContainerGridArea,
background,
}) => {
const [activeKey, setActiveKey] = useState(defaultActiveKey) const [activeKey, setActiveKey] = useState(defaultActiveKey)
useEffect(() => { useEffect(() => {
...@@ -45,7 +59,7 @@ const Tabs = ({ sections, onChange, defaultActiveKey = null }) => { ...@@ -45,7 +59,7 @@ const Tabs = ({ sections, onChange, defaultActiveKey = null }) => {
).content ).content
return ( return (
<> <>
<TabsContainer> <TabsContainer background={background} gridArea={tabsContainerGridArea}>
{sections.map(({ key, label }) => ( {sections.map(({ key, label }) => (
<TabContainer <TabContainer
key={key} key={key}
...@@ -56,7 +70,7 @@ const Tabs = ({ sections, onChange, defaultActiveKey = null }) => { ...@@ -56,7 +70,7 @@ const Tabs = ({ sections, onChange, defaultActiveKey = null }) => {
))} ))}
</TabsContainer> </TabsContainer>
{activeKey && <Content>{currentContent}</Content>} {activeKey && currentContent}
</> </>
) )
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment