This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/app/components/Tab.js

67 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-08-10 06:14:51 +00:00
// @flow
import { m } from "framer-motion";
import * as React from "react";
import styled, { useTheme } from "styled-components";
import NavLinkWithChildrenFunc from "components/NavLink";
2018-08-10 06:14:51 +00:00
type Props = {
children: React.Node,
};
const TabLink = styled(NavLinkWithChildrenFunc)`
position: relative;
display: inline-flex;
align-items: center;
2018-08-10 06:14:51 +00:00
font-weight: 500;
font-size: 14px;
color: ${(props) => props.theme.textTertiary};
2019-01-08 07:42:55 +00:00
margin-right: 24px;
padding: 6px 0;
2019-01-08 07:42:55 +00:00
&:hover {
color: ${(props) => props.theme.textSecondary};
2019-01-08 07:42:55 +00:00
}
2018-08-10 06:14:51 +00:00
`;
const Active = styled(m.div)`
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 3px;
width: 100%;
border-top-left-radius: 2px;
border-top-right-radius: 2px;
background: ${(props) => props.theme.textSecondary};
`;
const transition = {
type: "spring",
stiffness: 500,
damping: 30,
};
export default function Tab({ children, ...rest }: Props) {
const theme = useTheme();
2018-08-10 06:14:51 +00:00
const activeStyle = {
color: theme.textSecondary,
2018-08-10 06:14:51 +00:00
};
return (
<TabLink {...rest} activeStyle={activeStyle}>
{(match) => (
<>
{children}
{match && (
<Active
layoutId="underline"
initial={false}
transition={transition}
/>
)}
</>
)}
</TabLink>
);
2018-08-10 06:14:51 +00:00
}