Skip to content

Commit

Permalink
Merge pull request #1300 from ONEARMY/feat/introduce-theme-provider
Browse files Browse the repository at this point in the history
feat: introduce theme provider
  • Loading branch information
davehakkens authored Dec 16, 2021
2 parents 4c67dd6 + 76ed805 commit ef8bbe3
Show file tree
Hide file tree
Showing 93 changed files with 1,019 additions and 493 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"resolutions": {
"__NOTE__": "2021-05-28 storybook clash: https://github.com/storybookjs/storybook/issues/6505",
"webpack": "4.44.2",
"styled-components": "^4",
"__NOTE2__": "2021-07-06 ram issues: https://github.com/facebook/create-react-app/issues/10154",
"react-scripts/eslint-webpack-plugin": "2.4.1",
"__NOTE3__": "2021-10-03 terser issues: https://github.com/facebook/create-react-app/issues/6334",
Expand Down
41 changes: 41 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, { Component } from 'react'
import { observer, Provider } from 'mobx-react'
import { ThemeProvider } from 'styled-components'
import { GlobalStyle } from './themes/app.globalStyles'
import { RootStore } from './stores'
import ErrorBoundary from './common/ErrorBoundary'
import { Routes } from './pages'

const rootStore = new RootStore()

/**
* Additional store and db exports for use in modern context consumers
* @example const {userStore} = useCommonStores()
*/
export const rootStoreContext = React.createContext<RootStore>(rootStore)
export const useCommonStores = () =>
React.useContext<RootStore>(rootStoreContext)
export const dbContext = React.createContext({ db: rootStore.dbV2 })
export const useDB = () => React.useContext(dbContext)

@observer
export class App extends Component {
render() {
return (
<>
<Provider {...rootStore.stores}>
<ThemeProvider
theme={rootStore.stores.themeStore.currentTheme.styles}
>
<>
<ErrorBoundary>
<Routes />
</ErrorBoundary>
<GlobalStyle />
</>
</ThemeProvider>
</Provider>
</>
)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/Avatar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from 'react'

import { Image, ImageProps } from 'rebass'
import { Image, ImageProps } from 'rebass/styled-components'
import { inject, observer } from 'mobx-react'
import { ProfileTypeLabel } from 'src/models/user_pp.models'
import Workspace from 'src/pages/User/workspace/Workspace'
Expand Down
5 changes: 1 addition & 4 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import { Icon, IGlyphs } from 'src/components/Icons'
import {
Button as RebassButton,
ButtonProps as RebassButtonProps,
} from 'rebass'
import theme from 'src/themes/styled.theme'
} from 'rebass/styled-components'
import Text from 'src/components/Text'
import styled from 'styled-components'
// import { IBtnProps } from './index'

// extend to allow any default button props (e.g. onClick) to also be passed
export interface IBtnProps extends React.ButtonHTMLAttributes<HTMLElement> {
Expand Down Expand Up @@ -70,5 +68,4 @@ export const Button = (props: BtnProps) => (

Button.defaultProps = {
type: 'button',
theme,
}
2 changes: 1 addition & 1 deletion src/components/Comment/Comment.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react'
import { FaTrash, FaRegEdit } from 'react-icons/fa'
import { Flex } from 'rebass'
import { Flex } from 'rebass/styled-components'
import { useCommonStores } from 'src'
import { IComment } from 'src/models'
import { CommentHeader } from './CommentHeader'
Expand Down
2 changes: 1 addition & 1 deletion src/components/Comment/CommentHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Flex, Text } from 'rebass'
import { Box, Flex, Text } from 'rebass/styled-components'
import { FlagIconHowTos } from 'src/components/Icons/FlagIcon/FlagIcon'
import { IComment } from 'src/models'
import { Link } from 'src/components/Links'
Expand Down
4 changes: 1 addition & 3 deletions src/components/Comment/CommentTextArea.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from 'react'
import styled from 'styled-components'
import { Box, Text } from 'rebass/styled-components'
import theme from 'src/themes/styled.theme'
import { Avatar } from '../Avatar'
import { useCommonStores } from 'src'
import { Link } from '../Links'
Expand All @@ -19,7 +17,7 @@ const TextAreaStyled = styled.textarea`
min-width: 100%;
max-width: 100%;
font-family: 'Inter', Arial, sans-serif;
font-size: ${theme.fontSizes[2] + 'px'};
font-size: ${props => props.theme.fontSizes[2] + 'px'};
border-radius: 5px;
resize: none;
Expand Down
129 changes: 82 additions & 47 deletions src/components/DevSiteHeader/DevSiteHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,61 +1,96 @@
import { SITE, VERSION, DEV_SITE_ROLE } from 'src/config/config'
import Text from 'src/components/Text'
import theme from 'src/themes/styled.theme'
import { UserRole } from 'src/models'
import { Flex, Box } from 'rebass'
import { Flex, Box } from 'rebass/styled-components'
import Select from 'react-select'
import { observer } from 'mobx-react-lite'
import { useCommonStores } from 'src/index'

/**
* A simple header component that reminds developers that they are working on a dev
* version of the platform, and provide the option to toggle between different dev sites
*/
const DevSiteHeader = () => (
<>
{devSites.find(s => s.value === SITE) && (
<Flex
data-cy="devSiteHeader"
bg={theme.colors.red2}
width={1}
py={1}
px={1}
alignItems="center"
style={{ zIndex: 3001 }}
>
<Text color={'white'} medium txtcenter flex="1">
This is a dev version of the platform (v{VERSION})
</Text>
<Flex data-cy="devSiteRoleSelectContainer" alignItems="center" ml={2}>
<Text color={'white'} medium mr="1" title={SITE}>
View as:
const DevSiteHeader = observer(() => {
const { themeStore } = useCommonStores().stores
const theme = themeStore.currentTheme.styles
return (
<>
{showDevSiteHeader() && (
<Flex
data-cy="devSiteHeader"
bg={theme.colors.red2}
width={1}
py={1}
px={1}
alignItems="center"
style={{ zIndex: 3001 }}
>
<Text color={'white'} medium txtcenter flex="1">
This is a dev version of the platform (v{VERSION})
</Text>
<Box width="150px" mr={3}>
<Select
options={siteRoles}
placeholder="Role"
defaultValue={
siteRoles.find(s => s.value === DEV_SITE_ROLE) || siteRoles[0]
}
onChange={(s: any) => setSiteRole(s.value)}
/>
</Box>
<Flex data-cy="devSiteRoleSelectContainer" alignItems="center" ml={2}>
<Text color={'white'} medium mr="1" title={SITE}>
View as:
</Text>
<Box width="150px" mr={3}>
<Select
options={siteRoles}
placeholder="Role"
defaultValue={
siteRoles.find(s => s.value === DEV_SITE_ROLE) || siteRoles[0]
}
onChange={(s: any) => setSiteRole(s.value)}
/>
</Box>
</Flex>
<Flex data-cy="devSiteSelectContainer" alignItems="center">
<Text color={'white'} medium mr="1" title={SITE}>
Site:
</Text>
<Box width="130px" mr={3}>
<Select
options={devSites}
placeholder="Site"
defaultValue={devSites.find(s => s.value === SITE)}
onChange={(s: any) => setSite(s.value)}
/>
</Box>
</Flex>
<Flex data-cy="devSiteSelectContainer" alignItems="center">
<Text color={'white'} medium mr="1" title={SITE}>
Theme:
</Text>
<Box width="180px">
<Select
options={availableThemes}
placeholder="Pick a theme"
defaultValue={availableThemes.find(s => s.value === SITE)}
onChange={(selectedElement: any) => {
const theme = selectedElement?.value || ''
localStorage.setItem('platformTheme', theme)
themeStore.setActiveTheme(theme)
}}
/>
</Box>
</Flex>
</Flex>
<Flex data-cy="devSiteSelectContainer" alignItems="center">
<Text color={'white'} medium mr="1" title={SITE}>
Site:
</Text>
<Box width="130px">
<Select
options={devSites}
placeholder="Site"
defaultValue={devSites.find(s => s.value === SITE)}
onChange={(s: any) => setSite(s.value)}
/>
</Box>
</Flex>
</Flex>
)}
</>
)
)}
</>
)
})

function showDevSiteHeader() {
return (
devSites.some(s => s.value === SITE) ||
window.location?.hostname === 'localhost'
)
}

const availableThemes = [
{ value: 'precious-plastic', label: 'Precious Plastic' },
{ value: 'project-kamp', label: 'Project Kamp' },
]

// we have 2 different dev sites, only show this component when on one and provide select
const devSites = [
{ value: 'localhost', label: 'Dev' },
Expand Down
2 changes: 1 addition & 1 deletion src/components/DropdownIndicator/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { components } from 'react-select'
import { Image } from 'rebass'
import { Image } from 'rebass/styled-components'
import ArrowSelectIcon from '../../assets/icons/icon-arrow-select.svg'

// https://github.com/JedWatson/react-select/issues/685#issuecomment-420213835
Expand Down
2 changes: 1 addition & 1 deletion src/components/ElWithBeforeIcon/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FunctionComponent } from 'react';
import { Box } from 'rebass'
import { Box } from 'rebass/styled-components'
import checkmarkIcon from 'src/assets/icons/icon-checkmark.svg'

interface IProps {
Expand Down
2 changes: 1 addition & 1 deletion src/components/FileInfo/FileDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Icon, { availableGlyphs } from '../Icons'
import { Flex } from 'rebass'
import { Flex } from 'rebass/styled-components'
import Text from '../Text'
import { IUploadedFileMeta } from 'src/stores/storage'
import styled from 'styled-components'
Expand Down
2 changes: 1 addition & 1 deletion src/components/FileInput/FileInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Uppy from '@uppy/core'
import { DashboardModal } from '@uppy/react'
import { Button } from '../Button'
import { UPPY_CONFIG } from './UppyConfig'
import { Flex } from 'rebass'
import { Flex } from 'rebass/styled-components'
import { FileInfo } from '../FileInfo/FileInfo'

interface IUppyFiles {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import FileUploader from 'react-firebase-file-uploader'
import { FullMetadata } from '@firebase/storage-types'
import { Button } from '../Button'
import { IGlyphs } from '../Icons'
import { Flex } from 'rebass'
import { Flex } from 'rebass/styled-components'
import Loader from '../Loader'
import { logger } from 'src/logger'
/*
Expand Down
2 changes: 1 addition & 1 deletion src/components/Form/FlagSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FieldContainer, ErrorMessage } from './elements'
import ReactFlagsSelect from 'react-flags-select'
import { Flex } from 'rebass'
import { Flex } from 'rebass/styled-components'
import { IFieldProps } from './Fields'

export const FlagSelectField = ({ input, meta }: IFieldProps) => (
Expand Down
11 changes: 3 additions & 8 deletions src/components/Heading/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import styled from 'styled-components'
import theme from 'src/themes/styled.theme'
import Text, { ITextProps } from 'src/components/Text'
import { HeadingProps as RebassHeadingProps } from 'rebass/styled-components'

export const large = (props: ITextProps) =>
props.large ? { fontSize: theme.fontSizes[6] } : null
props.large ? { fontSize: props.theme.fontSizes[6] } : null
export const medium = (props: ITextProps) =>
props.medium ? { fontSize: theme.fontSizes[5] } : null
props.medium ? { fontSize: props.theme.fontSizes[5] } : null
export const small = (props: ITextProps) =>
props.small ? { fontSize: theme.fontSizes[4] } : null
props.small ? { fontSize: props.theme.fontSizes[4] } : null

export const BaseHeading = styled(Text)`
${large}
Expand All @@ -21,8 +20,4 @@ const Heading = (props: IHeadingProps) => (
<BaseHeading {...(props as any)}>{props.children}</BaseHeading>
)

Heading.defaultProps = {
theme,
}

export default Heading
3 changes: 1 addition & 2 deletions src/components/Icons/FlagIcon/FlagIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react'
import FlagIconFactory from 'react-flag-icon-css'
import styled from 'styled-components'
import theme from 'src/themes/styled.theme'

// Please only use `FlagIconFactory` one time in your application, there is no
// need to use it multiple times (it would slow down your app). You may place the
Expand All @@ -15,7 +14,7 @@ const FlagIconEvents = styled(FlagIcon)`
height: 23px;
width: 35px !important;
@media only screen and (max-width: ${theme.breakpoints[1]}) {
@media only screen and (max-width: ${props => props.theme.breakpoints[1]}) {
height: 15px;
width: 25px !important;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ImageInput/ImageConverter.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import { Flex } from 'rebass'
import { Flex } from 'rebass/styled-components'
import imageCompression from 'browser-image-compression'
import { IConvertedFileMeta } from './ImageInput'
import styled from 'styled-components'
Expand Down
2 changes: 1 addition & 1 deletion src/components/ImageInput/ImageInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import { Box, Image } from 'rebass'
import { Box, Image } from 'rebass/styled-components'
import styled from 'styled-components'
import { Button } from '../Button'
import 'react-image-lightbox/style.css'
Expand Down
6 changes: 3 additions & 3 deletions src/components/Links/LinkTargetBlank/LinkTargetBlank.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Link } from 'rebass'
import { Link } from 'rebass/styled-components'
import ImageTargetBlank from 'src/assets/icons/link-target-blank.svg'
import { zIndex } from 'src/themes/styled.theme'
import theme from 'src/themes/styled.theme'

export const LinkTargetBlank = props => (
<Link
Expand All @@ -14,7 +14,7 @@ export const LinkTargetBlank = props => (
backgroundImage: `url("${ImageTargetBlank}")`,
width: '20px',
height: '20px',
zIndex: `${zIndex.level}`,
zIndex: `${theme.zIndex.level}`,
backgroundSize: 'contain',
backgroundRepeat: 'no-repeat',
position: 'absolute',
Expand Down
2 changes: 1 addition & 1 deletion src/components/Links/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link as RouterLink } from 'react-router-dom'
import { Link as RebassLink } from 'rebass'
import { Link as RebassLink } from 'rebass/styled-components'

export const Link = props => <RebassLink {...props} as={RouterLink} />
Loading

0 comments on commit ef8bbe3

Please sign in to comment.