Skip to content

Commit 0b29e5f

Browse files
WesSouzaarturbien
authored andcommitted
feat(hourglass): convert to TypeScript and export types
1 parent 8d37b0c commit 0b29e5f

File tree

8 files changed

+72
-79
lines changed

8 files changed

+72
-79
lines changed

src/Hourglass/Hourglass.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/Hourglass/Hourglass.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Hourglass
33
menu: Components
44
---
55

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

88
# Hourglass
99

src/Hourglass/Hourglass.spec.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/Hourglass/Hourglass.spec.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { render } from '@testing-library/react';
2+
import React from 'react';
3+
4+
import { Hourglass } from './Hourglass';
5+
6+
describe('<Hourglass />', () => {
7+
it('should render hourglass', () => {
8+
const { container } = render(<Hourglass />);
9+
const hourglass = container.firstElementChild;
10+
11+
expect(hourglass).toBeInTheDocument();
12+
});
13+
14+
it('should render correct size', () => {
15+
const { container } = render(<Hourglass size='66px' />);
16+
const hourglass = container.firstElementChild;
17+
18+
const computedStyles = hourglass
19+
? window.getComputedStyle(hourglass)
20+
: null;
21+
expect(computedStyles?.width).toBe('66px');
22+
expect(computedStyles?.height).toBe('66px');
23+
});
24+
25+
it('should handle custom props', () => {
26+
const customProps: React.HTMLAttributes<HTMLSpanElement> = {
27+
title: 'hourglass'
28+
};
29+
const { container } = render(<Hourglass {...customProps} />);
30+
const hourglass = container.firstElementChild;
31+
32+
expect(hourglass).toHaveAttribute('title', 'hourglass');
33+
});
34+
});

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

Lines changed: 2 additions & 2 deletions
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 { Hourglass } 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: 'Hourglass',
1313
component: Hourglass,
1414
decorators: [story => <Wrapper>{story()}</Wrapper>]
15-
};
15+
} as ComponentMeta<typeof Hourglass>;
1616

1717
export function Default() {
1818
return <Hourglass size={32} />;

src/Hourglass/Hourglass.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { forwardRef } from 'react';
2+
import styled from 'styled-components';
3+
import { getSize } from '../common/utils';
4+
import base64hourglass from './base64hourglass';
5+
6+
type HourglassProps = {
7+
size?: string | number;
8+
};
9+
10+
const StyledContainer = styled.span<Required<Pick<HourglassProps, 'size'>>>`
11+
display: inline-block;
12+
height: ${({ size }) => getSize(size)};
13+
width: ${({ size }) => getSize(size)};
14+
`;
15+
16+
const StyledHourglass = styled.span`
17+
display: block;
18+
background: ${base64hourglass};
19+
background-size: cover;
20+
width: 100%;
21+
height: 100%;
22+
`;
23+
24+
const Hourglass = forwardRef<HTMLSpanElement, HourglassProps>(
25+
function Hourglass({ size = 30, ...otherProps }, ref) {
26+
return (
27+
<StyledContainer size={size} ref={ref} {...otherProps}>
28+
<StyledHourglass />
29+
</StyledContainer>
30+
);
31+
}
32+
);
33+
34+
export { Hourglass, HourglassProps };
File renamed without changes.

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export { default as Cutout } from './Cutout/Cutout';
1515
export * from './Desktop/Desktop';
1616
export * from './Divider/Divider';
1717
export { default as Fieldset } from './Fieldset/Fieldset';
18-
export { default as Hourglass } from './Hourglass/Hourglass';
18+
export * from './Hourglass/Hourglass';
1919
export { default as List } from './List/List';
2020
export { default as ListItem } from './ListItem/ListItem';
2121
export { default as LoadingIndicator } from './LoadingIndicator/LoadingIndicator';

0 commit comments

Comments
 (0)