Add Tabs container
Summary: Adding an additional style for tabs on top of a container, similar to the ones used in macOS Reviewed By: passy Differential Revision: D17450843 fbshipit-source-id: 6b58c2aa290e0221d917e60bb3ac0751f77ea1ce
This commit is contained in:
committed by
Facebook Github Bot
parent
2a6462641b
commit
735aee7682
@@ -12,28 +12,54 @@ import FlexRow from './FlexRow';
|
|||||||
import {colors} from './colors';
|
import {colors} from './colors';
|
||||||
import Tab, {Props as TabProps} from './Tab';
|
import Tab, {Props as TabProps} from './Tab';
|
||||||
import {WidthProperty} from 'csstype';
|
import {WidthProperty} from 'csstype';
|
||||||
import React from 'react';
|
import React, {useContext} from 'react';
|
||||||
|
import {TabsContext} from './TabsContainer';
|
||||||
|
|
||||||
const TabList = styled(FlexRow)({
|
const TabList = styled(FlexRow)({
|
||||||
|
justifyContent: 'center',
|
||||||
alignItems: 'stretch',
|
alignItems: 'stretch',
|
||||||
});
|
});
|
||||||
|
|
||||||
const TabListItem = styled('div')(
|
const TabListItem = styled('div')(
|
||||||
(props: {active?: boolean; width?: WidthProperty<number>}) => ({
|
(props: {
|
||||||
backgroundColor: props.active ? colors.light15 : colors.light02,
|
active?: boolean;
|
||||||
borderBottom: '1px solid #dddfe2',
|
width?: WidthProperty<number>;
|
||||||
boxShadow: props.active ? 'inset 0px 0px 3px rgba(0,0,0,0.25)' : 'none',
|
container?: boolean;
|
||||||
color: colors.dark80,
|
}) => ({
|
||||||
flex: 1,
|
background: props.container
|
||||||
|
? props.active
|
||||||
|
? 'linear-gradient(to bottom, #67a6f7 0%, #0072FA 100%)'
|
||||||
|
: `linear-gradient(to bottom, white 0%,${
|
||||||
|
colors.macOSTitleBarButtonBackgroundBlur
|
||||||
|
} 100%)`
|
||||||
|
: props.active
|
||||||
|
? colors.light15
|
||||||
|
: colors.light02,
|
||||||
|
borderBottom: props.container ? '1px solid #B8B8B8' : '1px solid #dddfe2',
|
||||||
|
boxShadow:
|
||||||
|
props.active && props.container
|
||||||
|
? 'inset 0px 0px 3px rgba(0,0,0,0.25)'
|
||||||
|
: 'none',
|
||||||
|
color: props.container && props.active ? colors.white : colors.dark80,
|
||||||
|
flex: props.container ? 'unset' : 1,
|
||||||
|
top: props.container ? -11 : 0,
|
||||||
|
fontWeight: 500,
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
lineHeight: '28px',
|
lineHeight: props.container ? '22px' : '28px',
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
padding: '0 10px',
|
padding: '0 10px',
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
textOverflow: 'ellipsis',
|
textOverflow: 'ellipsis',
|
||||||
whiteSpace: 'nowrap',
|
whiteSpace: 'nowrap',
|
||||||
|
'&:first-child': {
|
||||||
|
borderTopLeftRadius: props.container ? 3 : 0,
|
||||||
|
borderBottomLeftRadius: props.container ? 3 : 0,
|
||||||
|
},
|
||||||
|
'&:last-child': {
|
||||||
|
borderTopRightRadius: props.container ? 3 : 0,
|
||||||
|
borderBottomRightRadius: props.container ? 3 : 0,
|
||||||
|
},
|
||||||
'&:hover': {
|
'&:hover': {
|
||||||
backgroundColor: props.active ? colors.light15 : colors.light05,
|
backgroundColor: props.active ? colors.light15 : colors.light05,
|
||||||
},
|
},
|
||||||
@@ -130,6 +156,8 @@ export default function Tabs(props: {
|
|||||||
*/
|
*/
|
||||||
after?: Array<React.ReactNode>;
|
after?: Array<React.ReactNode>;
|
||||||
}) {
|
}) {
|
||||||
|
const tabsContainer = useContext(TabsContext);
|
||||||
|
|
||||||
const {onActive} = props;
|
const {onActive} = props;
|
||||||
const active: string | undefined =
|
const active: string | undefined =
|
||||||
props.active == null ? props.defaultActive : props.active;
|
props.active == null ? props.defaultActive : props.active;
|
||||||
@@ -200,6 +228,7 @@ export default function Tabs(props: {
|
|||||||
key={key}
|
key={key}
|
||||||
width={width}
|
width={width}
|
||||||
active={isActive}
|
active={isActive}
|
||||||
|
container={tabsContainer}
|
||||||
onMouseDown={
|
onMouseDown={
|
||||||
!isActive && onActive
|
!isActive && onActive
|
||||||
? (event: React.MouseEvent<HTMLDivElement>) => {
|
? (event: React.MouseEvent<HTMLDivElement>) => {
|
||||||
@@ -235,7 +264,7 @@ export default function Tabs(props: {
|
|||||||
add(props.children);
|
add(props.children);
|
||||||
}
|
}
|
||||||
|
|
||||||
let tabList;
|
let tabList: React.ReactNode;
|
||||||
if (props.orderable === true) {
|
if (props.orderable === true) {
|
||||||
tabList = (
|
tabList = (
|
||||||
<OrderableContainer key="orderable-list">
|
<OrderableContainer key="orderable-list">
|
||||||
@@ -250,7 +279,7 @@ export default function Tabs(props: {
|
|||||||
} else {
|
} else {
|
||||||
tabList = [];
|
tabList = [];
|
||||||
for (const key in tabs) {
|
for (const key in tabs) {
|
||||||
tabList.push(tabs[key]);
|
(tabList as Array<React.ReactNode>).push(tabs[key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
29
src/ui/components/TabsContainer.tsx
Normal file
29
src/ui/components/TabsContainer.tsx
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2018-present Facebook.
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
* @format
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
import styled from 'react-emotion';
|
||||||
|
|
||||||
|
const Container = styled('div')({
|
||||||
|
backgroundColor: '#E3E3E3',
|
||||||
|
borderRadius: 4,
|
||||||
|
boxShadow: 'inset 0 1px 2px rgba(0,0,0,0.1)',
|
||||||
|
padding: 10,
|
||||||
|
paddingTop: 0,
|
||||||
|
marginTop: 11,
|
||||||
|
marginBottom: 10,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const TabsContext = React.createContext(true);
|
||||||
|
|
||||||
|
export default function(props: {children: any}) {
|
||||||
|
return (
|
||||||
|
<Container>
|
||||||
|
<TabsContext.Provider value={true}>{props.children}</TabsContext.Provider>
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -64,6 +64,7 @@ export {
|
|||||||
// tabs
|
// tabs
|
||||||
export {default as Tabs} from './components/Tabs';
|
export {default as Tabs} from './components/Tabs';
|
||||||
export {default as Tab} from './components/Tab';
|
export {default as Tab} from './components/Tab';
|
||||||
|
export {default as TabsContainer} from './components/TabsContainer';
|
||||||
|
|
||||||
// inputs
|
// inputs
|
||||||
export {default as Input} from './components/Input';
|
export {default as Input} from './components/Input';
|
||||||
|
|||||||
Reference in New Issue
Block a user