Skip to content

Commit 74f56ec

Browse files
WesSouzaarturbien
authored andcommitted
refactor(appbar): add position prop
This also deprecates the fixed prop.
1 parent e3c0338 commit 74f56ec

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/AppBar/AppBar.spec.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ describe('<AppBar />', () => {
3131
expect(headerEl).toHaveStyleRule('position', 'absolute');
3232
});
3333

34+
it('should render position prop properly', () => {
35+
const { container } = render(
36+
<AppBar {...defaultProps} position='sticky' />
37+
);
38+
const headerEl = container.firstElementChild;
39+
40+
expect(headerEl).toHaveStyleRule('position', 'sticky');
41+
});
42+
3443
it('should custom style', () => {
3544
const { container } = render(
3645
<AppBar {...defaultProps} style={{ backgroundColor: 'papayawhip' }} />

src/AppBar/AppBar.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import React, { forwardRef } from 'react';
2-
import styled from 'styled-components';
2+
import styled, { CSSProperties } from 'styled-components';
33

44
import { createBorderStyles, createBoxStyles } from '../common';
55
import { CommonStyledProps } from '../types';
66

77
type AppBarProps = {
88
children: React.ReactNode;
9+
/** @deprecated Use `position` instead */
910
fixed?: boolean;
11+
position?: CSSProperties['position'];
1012
} & React.HTMLAttributes<HTMLElement> &
1113
CommonStyledProps;
1214

1315
const StyledAppBar = styled.header<AppBarProps>`
1416
${createBorderStyles()};
1517
${createBoxStyles()};
1618
17-
position: ${props => (props.fixed ? 'fixed' : 'absolute')};
19+
position: ${props => props.position ?? (props.fixed ? 'fixed' : 'absolute')};
1820
top: 0;
1921
right: 0;
2022
left: auto;
@@ -24,9 +26,14 @@ const StyledAppBar = styled.header<AppBarProps>`
2426
`;
2527

2628
const AppBar = forwardRef<HTMLElement, AppBarProps>(
27-
({ children, fixed = true, ...otherProps }, ref) => {
29+
({ children, fixed = true, position = 'fixed', ...otherProps }, ref) => {
2830
return (
29-
<StyledAppBar fixed={fixed} ref={ref} {...otherProps}>
31+
<StyledAppBar
32+
fixed={fixed}
33+
position={fixed !== false ? position : undefined}
34+
ref={ref}
35+
{...otherProps}
36+
>
3037
{children}
3138
</StyledAppBar>
3239
);

0 commit comments

Comments
 (0)