Skip to content

Commit

Permalink
feat(loadingindicator): convert to TypeScript and export types
Browse files Browse the repository at this point in the history
  • Loading branch information
WesSouza authored and arturbien committed Jul 26, 2022
1 parent bb6720d commit 2616fe5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from 'react';

import { renderWithTheme } from '../../test/utils';
import LoadingIndicator from './LoadingIndicator';
import { LoadingIndicator } from './LoadingIndicator';

describe('<LoadingIndicator />', () => {
it('renders LoadingIndicator', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react';

import { ComponentMeta } from '@storybook/react';
import styled from 'styled-components';

import { LoadingIndicator } from '..';
import { LoadingIndicator } from 'react95';

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

export function Default() {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import React, { forwardRef } from 'react';
import propTypes from 'prop-types';

import styled, { keyframes, css } from 'styled-components';

import styled, { css, keyframes } from 'styled-components';
import { StyledCutout } from '../Cutout/Cutout';
import { CommonStyledProps } from '../types';

type LoadingIndicatorProps = {
isLoading?: boolean;
shadow?: boolean;
} & React.HTMLAttributes<HTMLDivElement> &
CommonStyledProps;

const Wrapper = styled.div`
display: inline-block;
Expand Down Expand Up @@ -127,35 +131,28 @@ const IndeterminateSecondaryInner = styled.span`
animation: ${secondaryScale} 2s infinite linear;
`;

const LoadingIndicator = forwardRef(function LoadingIndicator(props, ref) {
const { isLoading, shadow, ...otherProps } = props;

return (
<Wrapper ref={ref} role='progressbar' {...otherProps}>
<ProgressCutout shadow={shadow}>
{isLoading && (
<IndeterminateWrapper data-testid='loading-wrapper'>
<IndeterminatePrimary>
<IndeterminatePrimaryInner />
</IndeterminatePrimary>
<IndeterminateSecondary>
<IndeterminateSecondaryInner />
</IndeterminateSecondary>
</IndeterminateWrapper>
)}
</ProgressCutout>
</Wrapper>
);
});

LoadingIndicator.defaultProps = {
shadow: false,
isLoading: true
};

LoadingIndicator.propTypes = {
shadow: propTypes.bool,
isLoading: propTypes.bool
};
const LoadingIndicator = forwardRef<HTMLDivElement, LoadingIndicatorProps>(
function LoadingIndicator(
{ isLoading = true, shadow = false, ...otherProps },
ref
) {
return (
<Wrapper ref={ref} role='progressbar' {...otherProps}>
<ProgressCutout shadow={shadow}>
{isLoading && (
<IndeterminateWrapper data-testid='loading-wrapper'>
<IndeterminatePrimary>
<IndeterminatePrimaryInner />
</IndeterminatePrimary>
<IndeterminateSecondary>
<IndeterminateSecondaryInner />
</IndeterminateSecondary>
</IndeterminateWrapper>
)}
</ProgressCutout>
</Wrapper>
);
}
);

export default LoadingIndicator;
export { LoadingIndicator, LoadingIndicatorProps };
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export { default as Fieldset } from './Fieldset/Fieldset';
export * from './Hourglass/Hourglass';
export { default as List } from './List/List';
export { default as ListItem } from './ListItem/ListItem';
export { default as LoadingIndicator } from './LoadingIndicator/LoadingIndicator';
export * from './LoadingIndicator/LoadingIndicator';
export { default as NumberField } from './NumberField/NumberField';
export * from './Panel/Panel';
export * from './Progress/Progress';
Expand Down

0 comments on commit 2616fe5

Please sign in to comment.