Skip to content

Commit 2616fe5

Browse files
WesSouzaarturbien
authored andcommitted
feat(loadingindicator): convert to TypeScript and export types
1 parent bb6720d commit 2616fe5

File tree

4 files changed

+37
-43
lines changed

4 files changed

+37
-43
lines changed

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import React from 'react';
2-
31
import { renderWithTheme } from '../../test/utils';
4-
import LoadingIndicator from './LoadingIndicator';
2+
import { LoadingIndicator } from './LoadingIndicator';
53

64
describe('<LoadingIndicator />', () => {
75
it('renders LoadingIndicator', () => {

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import React from 'react';
2-
1+
import { ComponentMeta } from '@storybook/react';
32
import styled from 'styled-components';
43

5-
import { LoadingIndicator } from '..';
4+
import { LoadingIndicator } from 'react95';
65

76
const Wrapper = styled.div`
87
background: ${({ theme }) => theme.material};
@@ -13,7 +12,7 @@ export default {
1312
title: 'LoadingIndicator',
1413
component: LoadingIndicator,
1514
decorators: [story => <Wrapper>{story()}</Wrapper>]
16-
};
15+
} as ComponentMeta<typeof LoadingIndicator>;
1716

1817
export function Default() {
1918
return (

src/LoadingIndicator/LoadingIndicator.js renamed to src/LoadingIndicator/LoadingIndicator.tsx

+32-35
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import React, { forwardRef } from 'react';
2-
import propTypes from 'prop-types';
3-
4-
import styled, { keyframes, css } from 'styled-components';
5-
2+
import styled, { css, keyframes } from 'styled-components';
63
import { StyledCutout } from '../Cutout/Cutout';
4+
import { CommonStyledProps } from '../types';
5+
6+
type LoadingIndicatorProps = {
7+
isLoading?: boolean;
8+
shadow?: boolean;
9+
} & React.HTMLAttributes<HTMLDivElement> &
10+
CommonStyledProps;
711

812
const Wrapper = styled.div`
913
display: inline-block;
@@ -127,35 +131,28 @@ const IndeterminateSecondaryInner = styled.span`
127131
animation: ${secondaryScale} 2s infinite linear;
128132
`;
129133

130-
const LoadingIndicator = forwardRef(function LoadingIndicator(props, ref) {
131-
const { isLoading, shadow, ...otherProps } = props;
132-
133-
return (
134-
<Wrapper ref={ref} role='progressbar' {...otherProps}>
135-
<ProgressCutout shadow={shadow}>
136-
{isLoading && (
137-
<IndeterminateWrapper data-testid='loading-wrapper'>
138-
<IndeterminatePrimary>
139-
<IndeterminatePrimaryInner />
140-
</IndeterminatePrimary>
141-
<IndeterminateSecondary>
142-
<IndeterminateSecondaryInner />
143-
</IndeterminateSecondary>
144-
</IndeterminateWrapper>
145-
)}
146-
</ProgressCutout>
147-
</Wrapper>
148-
);
149-
});
150-
151-
LoadingIndicator.defaultProps = {
152-
shadow: false,
153-
isLoading: true
154-
};
155-
156-
LoadingIndicator.propTypes = {
157-
shadow: propTypes.bool,
158-
isLoading: propTypes.bool
159-
};
134+
const LoadingIndicator = forwardRef<HTMLDivElement, LoadingIndicatorProps>(
135+
function LoadingIndicator(
136+
{ isLoading = true, shadow = false, ...otherProps },
137+
ref
138+
) {
139+
return (
140+
<Wrapper ref={ref} role='progressbar' {...otherProps}>
141+
<ProgressCutout shadow={shadow}>
142+
{isLoading && (
143+
<IndeterminateWrapper data-testid='loading-wrapper'>
144+
<IndeterminatePrimary>
145+
<IndeterminatePrimaryInner />
146+
</IndeterminatePrimary>
147+
<IndeterminateSecondary>
148+
<IndeterminateSecondaryInner />
149+
</IndeterminateSecondary>
150+
</IndeterminateWrapper>
151+
)}
152+
</ProgressCutout>
153+
</Wrapper>
154+
);
155+
}
156+
);
160157

161-
export default LoadingIndicator;
158+
export { LoadingIndicator, LoadingIndicatorProps };

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export { default as Fieldset } from './Fieldset/Fieldset';
1818
export * from './Hourglass/Hourglass';
1919
export { default as List } from './List/List';
2020
export { default as ListItem } from './ListItem/ListItem';
21-
export { default as LoadingIndicator } from './LoadingIndicator/LoadingIndicator';
21+
export * from './LoadingIndicator/LoadingIndicator';
2222
export { default as NumberField } from './NumberField/NumberField';
2323
export * from './Panel/Panel';
2424
export * from './Progress/Progress';

0 commit comments

Comments
 (0)