Skip to content
This repository was archived by the owner on Mar 28, 2019. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
language switcher
  • Loading branch information
reinhard committed May 19, 2018
commit 3a5420a1bcfb0c120d78ddd174c00b5d10281fde
57 changes: 38 additions & 19 deletions src/main/commons/components/templates/MainMenuTemplate.react.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
import * as React from 'react'
import {Box, Flex} from 'indoqa-react-fela'
import {Box, Text, Flex} from 'indoqa-react-fela'

import i18n from '../../../app/i18n'
import Bar from '../molecules/Bar.react'
Expand All @@ -15,26 +15,45 @@ type Props = {

const changeLanguage = (lng) => i18n.changeLanguage(lng)

const MainMenuTemplate = ({title, header, children}: Props) => (
<Flex stretch height="100%">
<MainMenu />
<Box grow={1}>
<Bar pl={1} pr={1}>
<Box>{title}</Box>
<Box grow={1} />
<Box>{header}</Box>
<Box>
<a onClick={() => changeLanguage('en')}>en</a> |
<a onClick={() => changeLanguage('de')}> de </a>
</Box>
</Bar>
<Content grow={1}>
{children}
</Content>
</Box>
</Flex>
const renderLanguage = (lang: string) => {
if (lang === i18n.language) {
return <Text>{lang}</Text>
}
return (
<a href="#" onClick={() => changeLanguage(lang)}>{lang}</a>
)
}

const renderLanguages = () => (
<Box>
{renderLanguage('en')} | {renderLanguage('de')}
</Box>
)

const renderHeaderContent = (title?:string, header?:string | null) => (
<React.Fragment>
<Box>{title}</Box>
<Box grow={1} />
<Box mr={3}>{header}</Box>
</React.Fragment>
)
const MainMenuTemplate = ({title, header, children}: Props) => {
return (
<Flex stretch height="100%">
<MainMenu />
<Box grow={1}>
<Bar pl={1} pr={1}>
{renderHeaderContent(title, header)}
{renderLanguages()}
</Bar>
<Content grow={1}>
{children}
</Content>
</Box>
</Flex>
)
}

MainMenuTemplate.defaultProps = {
title: '',
header: null,
Expand Down