forked from styleguidist/react-styleguidist
/
TabButtonRenderer.tsx
90 lines (84 loc) · 1.89 KB
/
TabButtonRenderer.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import React from 'react';
import PropTypes from 'prop-types';
import Styled, { JssInjectedProps } from 'rsg-components/Styled';
import { Styles } from 'jss';
import cx from 'clsx';
import * as Rsg from '../../../typings';
export const styles = ({
space,
color,
fontFamily,
fontSize,
buttonTextTransform,
}: Rsg.Theme): Styles => ({
button: {
padding: [[space[1], 0]],
fontFamily: fontFamily.base,
fontSize: fontSize.base,
color: color.light,
background: 'transparent',
textTransform: buttonTextTransform,
transition: 'color 750ms ease-out',
border: 'none',
cursor: 'pointer',
'&:hover, &:focus': {
isolate: false,
outline: 0,
color: color.linkHover,
transition: 'color 150ms ease-in',
},
'&:focus:not($isActive)': {
isolate: false,
outline: [[1, 'dotted', color.linkHover]],
},
'& + &': {
isolate: false,
marginLeft: space[1],
},
},
isActive: {
borderBottom: [[2, color.linkHover, 'solid']],
},
});
interface TabButtonProps extends JssInjectedProps {
className?: string;
name: string;
onClick: (e: React.MouseEvent) => void;
active?: boolean;
children: React.ReactNode;
}
export const TabButtonRenderer: React.FunctionComponent<TabButtonProps> = ({
classes,
name,
className,
onClick,
active,
children,
}) => {
const classNames = cx(classes.button, className, {
[classes.isActive]: active,
});
return (
<button
type="button"
name={name}
className={classNames}
onClick={onClick}
aria-pressed={active}
>
{children}
</button>
);
};
TabButtonRenderer.propTypes = {
classes: PropTypes.objectOf(PropTypes.string.isRequired).isRequired,
name: PropTypes.string.isRequired,
className: PropTypes.string,
onClick: PropTypes.func.isRequired,
active: PropTypes.bool,
children: PropTypes.node.isRequired,
};
TabButtonRenderer.defaultProps = {
active: false,
};
export default Styled<TabButtonProps>(styles)(TabButtonRenderer);