Skip to content

Commit 878a07e

Browse files
WesSouzaarturbien
authored andcommitted
feat(desktop): convert to TypeScript and export types
1 parent 4ba305d commit 878a07e

File tree

5 files changed

+21
-24
lines changed

5 files changed

+21
-24
lines changed

src/Desktop/Desktop.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Desktop
33
menu: Components
44
---
55

6-
import Desktop from '../Desktop/Desktop';
6+
import { Desktop } from '../Desktop/Desktop';
77

88
# Desktop
99

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import React from 'react';
22
import { renderWithTheme } from '../../test/utils';
33

4-
import Desktop from './Desktop';
4+
import { Desktop } from './Desktop';
55

66
describe('<Desktop />', () => {
77
it('should render', () => {
88
const { container } = renderWithTheme(<Desktop />);
9-
const desktopElement = container.firstChild;
9+
const desktopElement = container.firstElementChild;
1010

1111
expect(desktopElement).toBeInTheDocument();
1212
});
1313

1414
it('should handle custom props', () => {
15-
const customProps = { title: 'potatoe' };
15+
const customProps: React.HTMLAttributes<HTMLDivElement> = {
16+
title: 'potatoe'
17+
};
1618
const { container } = renderWithTheme(<Desktop {...customProps} />);
17-
const desktopElement = container.firstChild;
19+
const desktopElement = container.firstElementChild;
1820

1921
expect(desktopElement).toHaveAttribute('title', 'potatoe');
2022
});

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React from 'react';
21
import styled from 'styled-components';
32

43
import { Desktop } from 'react95';
4+
import { ComponentMeta } from '@storybook/react';
55

66
const Wrapper = styled.div`
77
padding: 5rem;
@@ -12,7 +12,7 @@ export default {
1212
title: 'Desktop',
1313
component: Desktop,
1414
decorators: [story => <Wrapper>{story()}</Wrapper>]
15-
};
15+
} as ComponentMeta<typeof Desktop>;
1616

1717
export function Default() {
1818
return <Desktop backgroundStyles={{ background: 'blue' }} />;

src/Desktop/Desktop.js renamed to src/Desktop/Desktop.tsx

+11-16
Original file line numberDiff line numberDiff line change
@@ -1,9 +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';
43

54
import { StyledCutout } from '../Cutout/Cutout';
65

6+
type DesktopProps = {
7+
backgroundStyles?: React.CSSProperties;
8+
children?: React.ReactNode;
9+
};
10+
711
const Wrapper = styled.div`
812
position: relative;
913
display: inline-block;
@@ -102,9 +106,10 @@ const Stand = styled.div`
102106
}
103107
`;
104108

105-
const Desktop = React.forwardRef(function Desktop(props, ref) {
106-
const { backgroundStyles, children, ...otherProps } = props;
107-
109+
const Desktop = forwardRef<HTMLDivElement, DesktopProps>(function Desktop(
110+
{ backgroundStyles, children, ...otherProps },
111+
ref
112+
) {
108113
return (
109114
<Wrapper ref={ref} {...otherProps}>
110115
<Inner>
@@ -117,14 +122,4 @@ const Desktop = React.forwardRef(function Desktop(props, ref) {
117122
);
118123
});
119124

120-
Desktop.defaultProps = {
121-
backgroundStyles: null
122-
};
123-
124-
Desktop.propTypes = {
125-
backgroundStyles: propTypes.object,
126-
// eslint-disable-next-line react/require-default-props
127-
children: propTypes.node
128-
};
129-
130-
export default Desktop;
125+
export { Desktop, DesktopProps };

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export { default as Checkbox } from './Checkbox/Checkbox';
1212
export { default as ColorInput } from './ColorInput/ColorInput';
1313
export * from './Counter/Counter';
1414
export { default as Cutout } from './Cutout/Cutout';
15-
export { default as Desktop } from './Desktop/Desktop';
15+
export * from './Desktop/Desktop';
1616
export * from './Divider/Divider';
1717
export { default as Fieldset } from './Fieldset/Fieldset';
1818
export { default as Hourglass } from './Hourglass/Hourglass';

0 commit comments

Comments
 (0)