Skip to content

Commit bae5491

Browse files
committed
feat: site AppBar
1 parent 21982ff commit bae5491

File tree

4 files changed

+103
-46
lines changed

4 files changed

+103
-46
lines changed

src/components/AppBar/index.tsx

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,32 @@
11
import * as S from './styles'
2-
import { IAppBar } from './types'
2+
import { IAppBar, ISecondaryAppBarButton } from './types'
33
import MenuIcon from '@material-ui/icons/Menu'
44
import { Container } from '@material-ui/core'
55

66
const AppBar = ({ testID, secondaryAppBar }: IAppBar) => {
77
return (
88
<S.Wrapper data-testid={testID}>
9-
<S.SecondaryAppBar>
10-
<Container>
11-
{secondaryAppBar?.leftContent && (
12-
<S.SecondaryAppBarLeftContent>
13-
{secondaryAppBar.leftContent.map((item, index) => {
14-
return (
15-
(item.link && (
16-
<a
17-
key={index}
18-
aria-label={item.link.aria}
19-
href={item.link.url}
20-
>
21-
{item.text}
22-
</a>
23-
)) ||
24-
item.text
25-
)
26-
})}
27-
</S.SecondaryAppBarLeftContent>
28-
)}
29-
{secondaryAppBar?.rightContent && (
30-
<S.SecondaryAppBarRightContent>
31-
{secondaryAppBar.rightContent.map((item, index) => {
32-
return (
33-
(item.link && (
34-
<a
35-
key={index}
36-
aria-label={item.link.aria}
37-
href={item.link.url}
38-
>
39-
{item.text}
40-
</a>
41-
)) ||
42-
item.text
43-
)
44-
})}
45-
</S.SecondaryAppBarRightContent>
46-
)}
47-
</Container>
48-
</S.SecondaryAppBar>
49-
<S.AppBar color="secondary">
9+
{secondaryAppBar && (
10+
<S.SecondaryAppBar>
11+
<S.SecondaryAppBarContainer>
12+
{secondaryAppBar?.leftContent && (
13+
<S.SecondaryAppBarLeftContent>
14+
{secondaryAppBar.leftContent.map((item, index) => {
15+
return (item.link && getButton({ index, item })) || item.text
16+
})}
17+
</S.SecondaryAppBarLeftContent>
18+
)}
19+
{secondaryAppBar?.rightContent && (
20+
<S.SecondaryAppBarRightContent>
21+
{secondaryAppBar.rightContent.map((item, index) => {
22+
return (item.link && getButton({ index, item })) || item.text
23+
})}
24+
</S.SecondaryAppBarRightContent>
25+
)}
26+
</S.SecondaryAppBarContainer>
27+
</S.SecondaryAppBar>
28+
)}
29+
<S.AppBar color="secondary" data-secondary-app-bar={secondaryAppBar}>
5030
<S.Toolbar>
5131
<Container>
5232
<S.IconButton edge="start" color="inherit" aria-label="menu">
@@ -59,4 +39,28 @@ const AppBar = ({ testID, secondaryAppBar }: IAppBar) => {
5939
)
6040
}
6141

42+
const getButton = ({ index, item }: ISecondaryAppBarButton) => {
43+
return (
44+
(item.link?.icon && (
45+
<S.IconButton
46+
size="small"
47+
key={index}
48+
onClick={() => window.open(item.link?.url, '_blank')}
49+
aria-label={item.link?.aria}
50+
>
51+
{item.text}
52+
</S.IconButton>
53+
)) || (
54+
<S.Button
55+
size="small"
56+
key={index}
57+
href={item.link?.url}
58+
aria-label={item.link?.aria}
59+
>
60+
{item.text}
61+
</S.Button>
62+
)
63+
)
64+
}
65+
6266
export default AppBar

src/components/AppBar/styles.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {
22
AppBar as AppBarCore,
3+
Button as ButtonCore,
4+
Container,
35
darken,
46
IconButton as IconButtonCore,
57
Toolbar as ToolbarCore
@@ -9,7 +11,7 @@ import styled from 'styled-components'
911
export const Wrapper = styled.div``
1012

1113
export const AppBar = styled(AppBarCore)`
12-
top: 40px;
14+
top: ${(props) => (props['data-secondary-app-bar'] ? '40px' : 0)};
1315
`
1416

1517
export const SecondaryAppBar = styled.div`
@@ -22,7 +24,14 @@ export const SecondaryAppBar = styled.div`
2224
z-index: 1200;
2325
`
2426

25-
export const SecondaryAppBarLeftContent = styled.div``
27+
export const SecondaryAppBarContainer = styled(Container)`
28+
display: flex;
29+
`
30+
31+
export const SecondaryAppBarLeftContent = styled.div`
32+
display: flex;
33+
flex: 1;
34+
`
2635

2736
export const SecondaryAppBarRightContent = styled.div``
2837

@@ -32,3 +41,5 @@ export const Toolbar = styled(ToolbarCore)`
3241
padding-left: 0;
3342
padding-right: 0;
3443
`
44+
45+
export const Button = styled(ButtonCore)``

src/components/AppBar/types.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ReactElement } from 'react'
2+
13
export interface IAppBar {
24
testID?: string
35
secondaryAppBar?: ISecondaryAppBar
@@ -9,9 +11,15 @@ export interface ISecondaryAppBar {
911
}
1012

1113
export interface ISecondaryAppBarContent {
12-
text: string
14+
text: string | ReactElement
1315
link?: {
1416
aria: string
1517
url: string
18+
icon: boolean
1619
}
1720
}
21+
22+
export interface ISecondaryAppBarButton {
23+
index: number
24+
item: ISecondaryAppBarContent
25+
}

src/components/Site/index.tsx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,46 @@
11
import { IAppBar } from 'components/AppBar/types'
22
import * as S from './styles'
33
import { ISite } from './types'
4+
import FacebookIcon from '@material-ui/icons/Facebook'
5+
import InstagramIcon from '@material-ui/icons/Instagram'
6+
import TwitterIcon from '@material-ui/icons/Twitter'
47

58
const appBarProps: IAppBar = {
69
secondaryAppBar: {
710
leftContent: [
811
{
9-
text: 'item'
12+
text: 'Frannca',
13+
link: {
14+
url: 'http://frannca.com',
15+
aria: 'Link to Frannca',
16+
icon: false
17+
}
18+
}
19+
],
20+
rightContent: [
21+
{
22+
text: <FacebookIcon />,
23+
link: {
24+
url: 'https://facebook.com',
25+
aria: 'Link to Facebook',
26+
icon: true
27+
}
28+
},
29+
{
30+
text: <TwitterIcon />,
31+
link: {
32+
url: 'https://twitter.com',
33+
aria: 'Link to Twitter',
34+
icon: true
35+
}
36+
},
37+
{
38+
text: <InstagramIcon />,
39+
link: {
40+
url: 'https://www.instagram.com',
41+
aria: 'Link to Instagram',
42+
icon: true
43+
}
1044
}
1145
]
1246
}

0 commit comments

Comments
 (0)