Skip to content

Commit

Permalink
feat(cutout): 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 c4bb628 commit a7eeda1
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/Button/Button.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ menu: Components
import { Button } from './Button';
import Window from '../Window/Window';
import WindowContent from '../WindowContent/WindowContent';
import Cutout from '../Cutout/Cutout';
import { Cutout } from '../Cutout/Cutout';
import Toolbar from '../Toolbar/Toolbar';

# Button
Expand Down
2 changes: 1 addition & 1 deletion src/Checkbox/Checkbox.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ menu: Components
import { Checkbox } from './Checkbox';
import Fieldset from '../Fieldset/Fieldset';
import { Button } from '../Button/Button';
import Cutout from '../Cutout/Cutout';
import { Cutout } from '../Cutout/Cutout';
import List from '../List/List';
import ListItem from '../ListItem/ListItem';
import Divider from '../Divider/Divider';
Expand Down
6 changes: 3 additions & 3 deletions src/Cutout/Cutout.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: Cutout
menu: Components
---

import Cutout from './Cutout'
import Window from '../Window/Window'
import WindowContent from '../WindowContent/WindowContent'
import { Cutout } from './Cutout';
import Window from '../Window/Window';
import WindowContent from '../WindowContent/WindowContent';

# Cutout

Expand Down
9 changes: 4 additions & 5 deletions src/Cutout/Cutout.spec.js → src/Cutout/Cutout.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React from 'react';
import { render } from '@testing-library/react';

import Cutout from './Cutout';
import { Cutout } from './Cutout';

describe('<Cutout />', () => {
it('should render cutout', () => {
const { container } = render(<Cutout />);
const cutout = container.firstChild;
const cutout = container.firstElementChild;

expect(cutout).toBeInTheDocument();
});
Expand All @@ -15,7 +14,7 @@ describe('<Cutout />', () => {
const { container } = render(
<Cutout style={{ backgroundColor: 'papayawhip' }} />
);
const cutout = container.firstChild;
const cutout = container.firstElementChild;

expect(cutout).toHaveAttribute('style', 'background-color: papayawhip;');
});
Expand All @@ -34,7 +33,7 @@ describe('<Cutout />', () => {
it('should render custom props', () => {
const customProps = { title: 'cutout' };
const { container } = render(<Cutout {...customProps} />);
const cutout = container.firstChild;
const cutout = container.firstElementChild;

expect(cutout).toHaveAttribute('title', 'cutout');
});
Expand Down
14 changes: 10 additions & 4 deletions src/Cutout/Cutout.stories.js → src/Cutout/Cutout.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import React from 'react';

import { ComponentMeta } from '@storybook/react';
import { Cutout, Window, WindowContent } from 'react95';
import styled from 'styled-components';

const Wrapper = styled.div`
padding: 5rem;
background: ${({ theme }) => theme.desktopBackground};
`;

export default {
title: 'Cutout',
component: Cutout
};
component: Cutout,
decorators: [story => <Wrapper>{story()}</Wrapper>]
} as ComponentMeta<typeof Cutout>;

export function Default() {
return (
Expand Down
32 changes: 15 additions & 17 deletions src/Cutout/Cutout.js → src/Cutout/Cutout.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import React from 'react';
import propTypes from 'prop-types';
import React, { forwardRef } from 'react';
import styled from 'styled-components';
import { insetShadow, createScrollbars } from '../common';
import { CommonStyledProps } from '../types';

export const StyledCutout = styled.div`
type CutoutProps = {
children?: React.ReactNode;
shadow?: boolean;
} & React.HTMLAttributes<HTMLDivElement> &
CommonStyledProps;

export const StyledCutout = styled.div<Pick<CutoutProps, 'shadow'>>`
position: relative;
box-sizing: border-box;
padding: 2px;
Expand Down Expand Up @@ -44,23 +50,15 @@ const Content = styled.div`
${createScrollbars()}
`;

const Cutout = React.forwardRef(function Cutout(props, ref) {
const { children, ...otherProps } = props;
const Cutout = forwardRef<HTMLDivElement, CutoutProps>(function Cutout(
{ children, shadow = true, ...otherProps },
ref
) {
return (
<StyledCutout ref={ref} {...otherProps}>
<StyledCutout ref={ref} shadow={shadow} {...otherProps}>
<Content>{children}</Content>
</StyledCutout>
);
});

Cutout.defaultProps = {
children: null,
shadow: true
};

Cutout.propTypes = {
children: propTypes.node,
shadow: propTypes.bool
};

export default Cutout;
export { Cutout, CutoutProps };
15 changes: 7 additions & 8 deletions src/DatePicker/DatePicker.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import React, { Component } from 'react';
import propTypes from 'prop-types';

import React, { Component } from 'react';
import styled from 'styled-components';

import Window from '../Window/Window';
import WindowHeader from '../WindowHeader/WindowHeader';
import WindowContent from '../WindowContent/WindowContent';
import Select from '../Select/Select';
import NumberField from '../NumberField/NumberField';
import Cutout from '../Cutout/Cutout';
import { Button } from '../Button/Button';
import { Cutout } from '../Cutout/Cutout';
import NumberField from '../NumberField/NumberField';
import Select from '../Select/Select';
import Toolbar from '../Toolbar/Toolbar';
import Window from '../Window/Window';
import WindowContent from '../WindowContent/WindowContent';
import WindowHeader from '../WindowHeader/WindowHeader';

const Calendar = styled(Cutout)`
width: 234px;
Expand Down
2 changes: 1 addition & 1 deletion src/Fieldset/Fieldset.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ menu: Components
import Fieldset from './Fieldset'
import Window from '../Window/Window'
import WindowContent from '../WindowContent/WindowContent'
import Cutout from '../Cutout/Cutout'
import Checkbox from '../Checkbox/Checkbox'
import { Cutout } from '../Cutout/Cutout';

# Fieldset

Expand Down
2 changes: 1 addition & 1 deletion src/NumberField/NumberField.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ menu: Components
---

import NumberField from './NumberField';
import Cutout from '../Cutout/Cutout'
import { Cutout } from '../Cutout/Cutout';

# NumberField

Expand Down
2 changes: 1 addition & 1 deletion src/Select/Select.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ menu: Components
import Select from './Select'
import Window from '../Window/Window'
import WindowContent from '../WindowContent/WindowContent'
import Cutout from '../Cutout/Cutout'
import { Cutout } from '../Cutout/Cutout';

# Select

Expand Down
2 changes: 1 addition & 1 deletion src/TextField/TextField.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ menu: Components
---

import TextField from './TextField';
import Cutout from '../Cutout/Cutout';
import { Cutout } from '../Cutout/Cutout';

# TextField

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export * from './Button/Button';
export * from './Checkbox/Checkbox';
export { default as ColorInput } from './ColorInput/ColorInput';
export * from './Counter/Counter';
export { default as Cutout } from './Cutout/Cutout';
export * from './Cutout/Cutout';
export * from './Desktop/Desktop';
export * from './Divider/Divider';
export { default as Fieldset } from './Fieldset/Fieldset';
Expand Down

0 comments on commit a7eeda1

Please sign in to comment.