Skip to content

Commit 334cf5e

Browse files
WesSouzaarturbien
authored andcommitted
feat(appbar): convert to TypeScript and export types
1 parent 105c6c6 commit 334cf5e

File tree

4 files changed

+44
-46
lines changed

4 files changed

+44
-46
lines changed

src/AppBar/AppBar.js

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

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { render } from '@testing-library/react';
32

43
import AppBar from './AppBar';
@@ -8,21 +7,21 @@ const defaultProps = { children: '' };
87
describe('<AppBar />', () => {
98
it('should render header', () => {
109
const { container } = render(<AppBar {...defaultProps} />);
11-
const headerEl = container.firstChild;
10+
const headerEl = container.firstElementChild;
1211

13-
expect(headerEl.tagName).toBe('HEADER');
12+
expect(headerEl && headerEl.tagName).toBe('HEADER');
1413
});
1514

1615
it('should render children', () => {
1716
const { container } = render(<AppBar>A nice app bar</AppBar>);
18-
const headerEl = container.firstChild;
17+
const headerEl = container.firstElementChild;
1918

2019
expect(headerEl).toHaveTextContent('A nice app bar');
2120
});
2221

2322
it('should render fixed prop properly', () => {
2423
const { container, rerender } = render(<AppBar {...defaultProps} fixed />);
25-
const headerEl = container.firstChild;
24+
const headerEl = container.firstElementChild;
2625

2726
expect(headerEl).toHaveStyleRule('position', 'fixed');
2827

@@ -35,15 +34,15 @@ describe('<AppBar />', () => {
3534
const { container } = render(
3635
<AppBar {...defaultProps} style={{ backgroundColor: 'papayawhip' }} />
3736
);
38-
const headerEl = container.firstChild;
37+
const headerEl = container.firstElementChild;
3938

4039
expect(headerEl).toHaveAttribute('style', 'background-color: papayawhip;');
4140
});
4241

4342
it('should render custom props', () => {
4443
const customProps = { title: 'cool-header' };
4544
const { container } = render(<AppBar {...defaultProps} {...customProps} />);
46-
const headerEl = container.firstChild;
45+
const headerEl = container.firstElementChild;
4746

4847
expect(headerEl).toHaveAttribute('title', 'cool-header');
4948
});

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ListItem,
1010
Divider
1111
} from 'react95';
12+
import { ComponentMeta } from '@storybook/react';
1213
import logoIMG from '../assets/images/logo.png';
1314

1415
const Wrapper = styled.div`
@@ -20,7 +21,7 @@ export default {
2021
title: 'AppBar',
2122
component: AppBar,
2223
decorators: [story => <Wrapper>{story()}</Wrapper>]
23-
};
24+
} as ComponentMeta<typeof AppBar>;
2425

2526
export function Default() {
2627
const [open, setOpen] = React.useState(false);

src/AppBar/AppBar.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React, { forwardRef } from 'react';
2+
import styled from 'styled-components';
3+
import { CommonStyledProps } from '../types';
4+
import { createBorderStyles, createBoxStyles } from '../common';
5+
6+
export type AppBarProps = {
7+
children: React.ReactNode;
8+
fixed?: boolean;
9+
} & React.HTMLAttributes<HTMLElement> &
10+
CommonStyledProps;
11+
12+
const StyledAppBar = styled.header<AppBarProps>`
13+
${createBorderStyles()};
14+
${createBoxStyles()};
15+
16+
position: ${props => (props.fixed ? 'fixed' : 'absolute')};
17+
top: 0;
18+
right: 0;
19+
left: auto;
20+
display: flex;
21+
flex-direction: column;
22+
width: 100%;
23+
`;
24+
25+
const AppBar = forwardRef<HTMLElement, AppBarProps>(function AppBar(
26+
{ children, fixed = true, ...otherProps },
27+
ref
28+
) {
29+
return (
30+
<StyledAppBar fixed={fixed} ref={ref} {...otherProps}>
31+
{children}
32+
</StyledAppBar>
33+
);
34+
});
35+
36+
export default AppBar;

0 commit comments

Comments
 (0)