|
1 |
| -import React from 'react'; |
2 |
| -import propTypes from 'prop-types'; |
3 |
| - |
| 1 | +import React, { forwardRef } from 'react'; |
4 | 2 | import styled from 'styled-components';
|
| 3 | + |
5 | 4 | import { createBorderStyles, createBoxStyles, focusOutline } from '../common';
|
6 | 5 | import { blockSizes } from '../common/system';
|
| 6 | +import { CommonStyledProps } from '../types'; |
| 7 | + |
| 8 | +type TabProps = { |
| 9 | + children?: React.ReactNode; |
| 10 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 11 | + onClick?: (event: React.MouseEvent<HTMLButtonElement>, value: any) => void; |
| 12 | + selected?: boolean; |
| 13 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 14 | + value?: any; |
| 15 | +} & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'onClick' | 'value'> & |
| 16 | + CommonStyledProps; |
7 | 17 |
|
8 |
| -const StyledTab = styled.button` |
| 18 | +const StyledTab = styled.button<TabProps>` |
9 | 19 | ${createBoxStyles()}
|
10 | 20 | ${createBorderStyles()}
|
11 | 21 | position: relative;
|
@@ -59,34 +69,22 @@ const StyledTab = styled.button`
|
59 | 69 | }
|
60 | 70 | `;
|
61 | 71 |
|
62 |
| -const Tab = React.forwardRef(function Tab(props, ref) { |
63 |
| - const { value, onClick, selected, children, ...otherProps } = props; |
64 |
| - |
| 72 | +const Tab = forwardRef<HTMLButtonElement, TabProps>(function Tab( |
| 73 | + { value, onClick, selected = false, children, ...otherProps }, |
| 74 | + ref |
| 75 | +) { |
65 | 76 | return (
|
66 | 77 | <StyledTab
|
67 |
| - selected={selected} |
68 | 78 | aria-selected={selected}
|
69 |
| - onClick={e => onClick(e, value)} |
70 |
| - role='tab' |
| 79 | + selected={selected} |
| 80 | + onClick={(e: React.MouseEvent<HTMLButtonElement>) => onClick?.(e, value)} |
71 | 81 | ref={ref}
|
| 82 | + role='tab' |
72 | 83 | {...otherProps}
|
73 | 84 | >
|
74 | 85 | {children}
|
75 | 86 | </StyledTab>
|
76 | 87 | );
|
77 | 88 | });
|
78 | 89 |
|
79 |
| -Tab.defaultProps = { |
80 |
| - onClick: () => {}, |
81 |
| - selected: false, |
82 |
| - children: null |
83 |
| -}; |
84 |
| - |
85 |
| -Tab.propTypes = { |
86 |
| - // eslint-disable-next-line react/require-default-props, react/forbid-prop-types |
87 |
| - value: propTypes.any, |
88 |
| - onClick: propTypes.func, |
89 |
| - selected: propTypes.bool, |
90 |
| - children: propTypes.node |
91 |
| -}; |
92 |
| -export default Tab; |
| 90 | +export { Tab, TabProps }; |
0 commit comments