Skip to content

Commit 79c1a14

Browse files
committed
Add basic responsiveness
1 parent ac06034 commit 79c1a14

File tree

1 file changed

+149
-4
lines changed

1 file changed

+149
-4
lines changed

src/components/header.tsx

Lines changed: 149 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,107 @@ const items: MenuItem[] = [
3232
}
3333
];
3434

35+
const small_items: MenuItem[] = [
36+
{
37+
label: (
38+
<a href="/">
39+
Home
40+
</a>
41+
),
42+
key: 'home',
43+
},
44+
{
45+
label: (
46+
<a href='/vicars'>
47+
Vicars
48+
</a>
49+
),
50+
key: 'vicars',
51+
},
52+
{
53+
label: (
54+
<a href='/management'>
55+
Management
56+
</a>
57+
),
58+
key: 'management',
59+
},
60+
{
61+
label: (
62+
<a href='/ministries'>
63+
Ministries
64+
</a>
65+
),
66+
key: 'ministries',
67+
},
68+
{
69+
label: (
70+
<a href='/gallery'>
71+
Gallery
72+
</a>
73+
),
74+
key: 'gallery',
75+
},
76+
{
77+
label: 'Contact Us',
78+
key: 'contact',
79+
},
80+
{
81+
label: (
82+
<Button type='link' style={{ boxShadow: '1px 1px 5px grey' }} href=""> News Letter</Button>
83+
),
84+
key: 'newsletter',
85+
86+
}
87+
];
88+
enum ScreenSize {
89+
SMALL = 0,
90+
MEDIUM = 1,
91+
LARGE = 2
92+
}
93+
3594
export interface HeaderProps {
3695
news: string[];
3796
}
3897

39-
export class Header extends React.Component<HeaderProps> {
98+
interface HeaderState {
99+
screen_size: ScreenSize;
100+
}
101+
102+
export class Header extends React.Component<HeaderProps, HeaderState> {
103+
constructor(props: HeaderProps) {
104+
super(props);
105+
window.onresize = () => {
106+
this.setState({ screen_size: this.getCurrentScreenSize() });
107+
console.log(this.state.screen_size);
108+
}
109+
this.state = {
110+
screen_size: this.getCurrentScreenSize()
111+
}
112+
}
113+
114+
getCurrentScreenSize(): ScreenSize {
115+
const width = window.innerWidth;
116+
if (width < 768) {
117+
return ScreenSize.SMALL;
118+
} else if (width < 1340) {
119+
return ScreenSize.MEDIUM;
120+
} else {
121+
return ScreenSize.LARGE;
122+
}
123+
}
40124
render() {
125+
switch (this.state.screen_size) {
126+
case ScreenSize.SMALL:
127+
return this.render_small_screen();
128+
case ScreenSize.MEDIUM:
129+
return this.render_medium_screen();
130+
case ScreenSize.LARGE:
131+
return this.render_big_screen();
132+
}
133+
}
134+
135+
render_big_screen() {
41136
return (
42137
<>
43138
<Menu mode="horizontal"
@@ -49,17 +144,54 @@ export class Header extends React.Component<HeaderProps> {
49144
position: 'fixed', padding: 0, margin: 0, left: '50%', transform: 'translateX(-50%)',
50145
top: 0
51146
}}>St. George Orthodox Church</Typography.Title>
52-
{this.render_side_nav()}
147+
{this.render_big_side_nav()}
53148
<Card style={{ position: 'fixed', padding: 0, boxShadow: '1px 1px 5px grey', borderRadius: '10px 10px 100px 100px', top: 0 }} size='small' hoverable>
54149
<Image src={avatar} width={150} preview={false} />
55150
</Card>
56151
</>
57152
);
153+
154+
}
155+
156+
render_medium_screen() {
157+
let render_avatar = false;
158+
if (window.location.pathname === '/') {
159+
console.log(window.location.pathname);
160+
render_avatar = true;
161+
}
162+
return (
163+
<>
164+
<Menu mode="horizontal"
165+
title='St. George Orthodox Church'
166+
style={{ justifyContent: 'flex-end', boxShadow: '0 2px 2px -2px grey', position: 'fixed', top: 0, width: '100%', height: 50 }}
167+
items={small_items}>
168+
</Menu>
169+
{render_avatar &&
170+
(
171+
< Card style={{ position: 'fixed', padding: 0, boxShadow: '1px 1px 5px grey', borderRadius: '10px 10px 100px 100px', top: 0 }} size='small' hoverable>
172+
<Image src={avatar} width={100} preview={false} />
173+
</Card >
174+
)
175+
}
176+
</>
177+
);
58178
}
59179

60-
render_side_nav() {
180+
render_small_screen() {
61181
return (
62-
<div style={{ position: 'fixed', top: 80, right: 10, width: 250 }}>
182+
<>
183+
<Menu mode="horizontal"
184+
title='St. George Orthodox Church'
185+
style={{ justifyContent: 'flex-end', boxShadow: '0 2px 2px -2px grey', position: 'fixed', top: 0, width: '100%', height: 50 }}
186+
items={small_items}>
187+
</Menu>
188+
</>
189+
)
190+
}
191+
192+
render_big_side_nav() {
193+
return (
194+
<div style={{ position: 'fixed', top: 80, right: 10, width: 200 }}>
63195
<Flex vertical gap={10}>
64196
<Button shape='round' size='large' style={{ boxShadow: '1px 1px 5px grey' }} block href='/vicars'>Vicars</Button>
65197
<Button shape='round' size='large' style={{ boxShadow: '1px 1px 5px grey' }} block href="/management">Management</Button>
@@ -71,6 +203,19 @@ export class Header extends React.Component<HeaderProps> {
71203
)
72204
}
73205

206+
render_medium_side_nav() {
207+
return (
208+
<div style={{ position: 'fixed', top: 80, right: 10, width: 200 }}>
209+
<Flex vertical gap={10}>
210+
<Button size='large' style={{ boxShadow: '1px 1px 5px grey' }} block href='/vicars'>Vicars</Button>
211+
<Button size='large' style={{ boxShadow: '1px 1px 5px grey' }} block href="/management">Management</Button>
212+
<Button size='large' style={{ boxShadow: '1px 1px 5px grey' }} block href="/ministries" >Ministries</Button>
213+
<Button size='large' style={{ boxShadow: '1px 1px 5px grey' }} block>Gallery</Button>
214+
<Button size='large' style={{ boxShadow: '1px 1px 5px grey' }} block>News</Button>
215+
</Flex>
216+
</div>
217+
)
218+
}
74219
render_news() {
75220
const news_items = this.props.news;
76221
return (

0 commit comments

Comments
 (0)