Skip to content

Commit c419365

Browse files
WesSouzaarturbien
authored andcommitted
feat(bar): convert to TypeScript and export types
1 parent e1ed277 commit c419365

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

src/Bar/Bar.spec.js renamed to src/Bar/Bar.spec.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { renderWithTheme } from '../../test/utils';
32

43
import Bar from './Bar';

src/Bar/Bar.stories.js renamed to src/Bar/Bar.stories.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import React from 'react';
1+
import { ComponentMeta } from '@storybook/react';
2+
import { AppBar, Bar, Button, Toolbar } from 'react95';
23
import styled from 'styled-components';
34

4-
import { Bar, AppBar, Toolbar, Button } from 'react95';
5-
65
const Wrapper = styled.div`
76
padding: 5rem;
87
background: ${({ theme }) => theme.desktopBackground};
@@ -12,7 +11,7 @@ export default {
1211
title: 'Bar',
1312
component: Bar,
1413
decorators: [story => <Wrapper>{story()}</Wrapper>]
15-
};
14+
} as ComponentMeta<typeof Bar>;
1615

1716
export function Default() {
1817
return (
+13-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import React from 'react';
2-
import propTypes from 'prop-types';
1+
import React, { forwardRef } from 'react';
32
import styled from 'styled-components';
3+
import { CommonStyledProps } from '../types';
44

5-
const StyledBar = styled.div`
5+
type BarProps = {
6+
size?: string | number;
7+
} & React.HTMLAttributes<HTMLDivElement> &
8+
CommonStyledProps;
9+
10+
const StyledBar = styled.div<BarProps & { size?: string }>`
611
display: inline-block;
712
box-sizing: border-box;
813
height: ${({ size }) => size};
@@ -13,20 +18,16 @@ const StyledBar = styled.div`
1318
border-right: 2px solid ${({ theme }) => theme.borderDark};
1419
background: ${({ theme }) => theme.material};
1520
`;
21+
1622
// TODO: add horizontal variant
1723
// TODO: allow user to specify number of bars (like 3 horizontal bars for drag handle)
18-
const Bar = React.forwardRef(function Bar(props, ref) {
19-
const { size: sizeProp, ...otherProps } = props;
24+
const Bar = forwardRef<HTMLDivElement, BarProps>(function Bar(
25+
{ size: sizeProp = '100%', ...otherProps },
26+
ref
27+
) {
2028
const size = typeof sizeProp === 'number' ? `${sizeProp}px` : sizeProp;
2129

2230
return <StyledBar size={size} ref={ref} {...otherProps} />;
2331
});
2432

25-
Bar.defaultProps = {
26-
size: '100%'
27-
};
28-
Bar.propTypes = {
29-
size: propTypes.oneOfType([propTypes.string, propTypes.number])
30-
};
31-
3233
export default Bar;

0 commit comments

Comments
 (0)