Skip to content

Commit

Permalink
feat: Add isInvertedTheme param
Browse files Browse the repository at this point in the history
Same as #825
  • Loading branch information
Merkur39 committed May 19, 2023
1 parent 321e078 commit f2ffde5
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 50 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ window.cozy.bar.init({
- `lang` is extracted from the `lang` attribute of the `<html>` tag. Defaults to 'en'
- `iconPath` uses the favicon 32px. Defaults to a blank GIF

To make the icon of Cozy(`icon-cozy-home.svg`) compatible with an inverted theme, please set the parameter `isInvertedTheme` to `true`

## Help link

Help link is defined in your Cozy's [configuration file](https://github.com/cozy/cozy-stack/blob/master/docs/config.md#main-configuration-file), in the `context` section. See the `cozy.example.yaml` file [provided by the stack](https://github.com/cozy/cozy-stack/blob/master/cozy.example.yaml#L80).
Expand Down
19 changes: 13 additions & 6 deletions src/components/Apps/AppItem.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react'
import get from 'lodash/get'
import { appShape } from 'proptypes/index'
import { models } from 'cozy-client'
import PropTypes from 'prop-types'

import { models } from 'cozy-client'
import AppIcon from 'cozy-ui/transpiled/react/AppIcon'
import AppLinker from 'cozy-ui/transpiled/react/AppLinker'

import HomeIcon from 'components/Apps/IconCozyHome'
import { appShape } from 'proptypes/index'
import stack from 'lib/stack'
import PropTypes from 'prop-types'

const getAppDisplayName = get(models, 'applications.getAppDisplayName', app => {
return app.namePrefix && app.namePrefix.toLowerCase() !== 'cozy'
Expand Down Expand Up @@ -64,7 +65,8 @@ export class AppItem extends React.Component {
}

render() {
const { useHomeIcon, app } = this.props
const { useHomeIcon, app, isInvertedTheme } = this.props

const dataIcon = app.slug ? `icon-${app.slug}` : ''
const appName = getAppDisplayName(app)

Expand All @@ -89,7 +91,10 @@ export class AppItem extends React.Component {
onClick={onClick}
>
{useHomeIcon ? (
<HomeIcon className="coz-nav-apps-item-icon" />
<HomeIcon
className="coz-nav-apps-item-icon"
isInvertedTheme={isInvertedTheme}
/>
) : (
<AppIcon
app={app}
Expand All @@ -110,7 +115,9 @@ export class AppItem extends React.Component {

AppItem.propTypes = {
app: appShape.isRequired,
useHomeIcon: PropTypes.bool
useHomeIcon: PropTypes.bool,
isInvertedTheme: PropTypes.bool,
onAppSwitch: PropTypes.func
}

export default AppItem
21 changes: 20 additions & 1 deletion src/components/Apps/AppNavButtons.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'
import PropTypes from 'prop-types'

import BottomIcon from 'cozy-ui/transpiled/react/Icons/Bottom'
import Icon from 'cozy-ui/transpiled/react/Icon'
Expand All @@ -19,6 +20,7 @@ class AppNavButton extends Component {
appNamePrefix,
appSlug,
iconPath,
isInvertedTheme,
isFetchingApps,
isPublic,
opened,
Expand Down Expand Up @@ -52,7 +54,7 @@ class AppNavButton extends Component {

return (
<div className={`coz-nav-apps-btns${isHomeApp ? ' --currentHome' : ''}`}>
<ButtonCozyHome homeHref={homeHref} />
<ButtonCozyHome homeHref={homeHref} isInvertedTheme={isInvertedTheme} />

{!isHomeApp && <span className="coz-nav-apps-btns-sep" />}

Expand Down Expand Up @@ -81,6 +83,23 @@ class AppNavButton extends Component {
}
}

AppNavButton.propTypes = {
homeApp: PropTypes.shape({
isCurrentApp: PropTypes.bool,
slug: PropTypes.string,
href: PropTypes.string
}),
handleClick: PropTypes.func,
appName: PropTypes.string,
appNamePrefix: PropTypes.string,
appSlug: PropTypes.string,
iconPath: PropTypes.string,
isInvertedTheme: PropTypes.bool,
isFetchingApps: PropTypes.bool,
isPublic: PropTypes.bool,
opened: PropTypes.bool
}

const mapStateToProps = state => ({
homeApp: getHomeApp(state),
isFetchingApps: isFetchingApps(state)
Expand Down
36 changes: 25 additions & 11 deletions src/components/Apps/AppsContent.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'
import Proptypes from 'prop-types'
import PropTypes from 'prop-types'

import { translate } from 'cozy-ui/transpiled/react/I18n'
import Icon from 'cozy-ui/transpiled/react/Icon'
import CloudIcon from 'cozy-ui/transpiled/react/Icons/Cloud'

import withBreakpoints from 'cozy-ui/transpiled/react/helpers/withBreakpoints'
import { getApps, getHomeApp, isFetchingApps } from 'lib/reducers'

import { getApps, getHomeApp, isFetchingApps } from 'lib/reducers'
import AppItem from 'components/Apps/AppItem'
import AppItemPlaceholder from 'components/Apps/AppItemPlaceholder'

Expand All @@ -27,7 +26,8 @@ export class AppsContent extends Component {
breakpoints,
homeApp,
isFetchingApps,
onAppSwitch
onAppSwitch,
isInvertedTheme
} = this.props
const { isMobile } = breakpoints
const isHomeApp = homeApp && homeApp.isCurrentApp
Expand All @@ -41,7 +41,12 @@ export class AppsContent extends Component {
<div className="coz-nav-pop-content">
<ul className="coz-nav-group">
{isMobile && homeApp && (
<AppItem app={homeApp} useHomeIcon onAppSwitch={onAppSwitch} />
<AppItem
app={homeApp}
useHomeIcon
onAppSwitch={onAppSwitch}
isInvertedTheme={isInvertedTheme}
/>
)}
{isFetchingApps
? new Array(3)
Expand All @@ -51,7 +56,12 @@ export class AppsContent extends Component {
.filter(app => app.slug !== homeSlug)
.sort(sorter(this.translateApp))
.map((app, index) => (
<AppItem app={app} key={index} onAppSwitch={onAppSwitch} />
<AppItem
app={app}
key={index}
onAppSwitch={onAppSwitch}
isInvertedTheme={isInvertedTheme}
/>
))}
</ul>
{homeApp && !isMobile && !isHomeApp && (
Expand All @@ -64,13 +74,17 @@ export class AppsContent extends Component {
)
}
}

AppsContent.propTypes = {
homeApp: Proptypes.shape({
isCurrentApp: Proptypes.bool,
slug: Proptypes.string
homeApp: PropTypes.shape({
isCurrentApp: PropTypes.bool,
slug: PropTypes.string,
href: PropTypes.string
}),
apps: Proptypes.array,
isFetchingApps: Proptypes.bool.isRequired
apps: PropTypes.array,
isFetchingApps: PropTypes.bool.isRequired,
onAppSwitch: PropTypes.func,
isInvertedTheme: PropTypes.bool
}
const translateApp = t => app => {
const namePrefix = app.namePrefix
Expand Down
33 changes: 27 additions & 6 deletions src/components/Apps/ButtonCozyHome.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import React from 'react'
import { isFlagshipApp } from 'cozy-device-helper'
import PropTypes from 'prop-types'

import flag from 'cozy-flags'
import { isFlagshipApp } from 'cozy-device-helper'

import IconCozyHome from './IconCozyHome'

export const ButtonCozyHome = ({ webviewContext, homeHref }) => {
export const ButtonCozyHome = ({
webviewContext,
homeHref,
isInvertedTheme
}) => {
if (isFlagshipApp() || flag('flagship.debug'))
return (
<a
Expand All @@ -14,20 +19,36 @@ export const ButtonCozyHome = ({ webviewContext, homeHref }) => {
}}
className="coz-nav-apps-btns-home --is-flagship"
>
<IconCozyHome className="coz-nav-apps-btns-home-svg" />
<IconCozyHome
className="coz-nav-apps-btns-home-svg"
isInvertedTheme={isInvertedTheme}
/>
</a>
)

if (homeHref)
if (homeHref) {
return (
<a href={homeHref} className="coz-nav-apps-btns-home">
<IconCozyHome className="coz-nav-apps-btns-home-svg" />
<IconCozyHome
className="coz-nav-apps-btns-home-svg"
isInvertedTheme={isInvertedTheme}
/>
</a>
)
}

return (
<span className="coz-nav-apps-btns-home">
<IconCozyHome className="coz-nav-apps-btns-home-svg" />
<IconCozyHome
className="coz-nav-apps-btns-home-svg"
isInvertedTheme={isInvertedTheme}
/>
</span>
)
}

ButtonCozyHome.propTypes = {
webviewContext: PropTypes.object,
homeHref: PropTypes.string,
isInvertedTheme: PropTypes.bool
}
16 changes: 13 additions & 3 deletions src/components/Apps/IconCozyHome.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'

import AppIcon from 'cozy-ui/transpiled/react/AppIcon'

Expand All @@ -21,9 +22,13 @@ function SvgIconCozyHome(props) {

class IconCozyHome extends PureComponent {
render() {
const { className } = this.props
const fetchIcon = () =>
`${stack.get.cozyURL()}/assets/images/icon-cozy-home.svg`
const { className, isInvertedTheme } = this.props
const fetchIcon = () => {
if (isInvertedTheme) {
return `${stack.get.cozyURL()}/assets/images/icon-cozy-home-inverted.svg`
}
return `${stack.get.cozyURL()}/assets/images/icon-cozy-home.svg`
}

return (
<AppIcon
Expand All @@ -35,4 +40,9 @@ class IconCozyHome extends PureComponent {
}
}

IconCozyHome.propTypes = {
className: PropTypes.string,
isInvertedTheme: PropTypes.bool
}

export default IconCozyHome
22 changes: 20 additions & 2 deletions src/components/Apps/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'

import AppsContent from 'components/Apps/AppsContent'
import AppNavButtons from 'components/Apps/AppNavButtons'
Expand Down Expand Up @@ -39,7 +40,14 @@ class Apps extends Component {

// data-tutorial attribute allows to be targeted in an application tutorial
render() {
const { appName, appNamePrefix, appSlug, iconPath, isPublic } = this.props
const {
appName,
appNamePrefix,
appSlug,
iconPath,
isPublic,
isInvertedTheme
} = this.props
const { opened } = this.state
return (
<nav
Expand All @@ -56,17 +64,27 @@ class Apps extends Component {
handleClick={this.toggleMenu}
opened={opened}
isPublic={isPublic}
isInvertedTheme={isInvertedTheme}
/>
<div
className="coz-nav-pop coz-nav-pop--apps"
id="coz-nav-pop--apps"
aria-hidden={!opened}
>
<AppsContent />
<AppsContent isInvertedTheme={isInvertedTheme} />
</div>
</nav>
)
}
}

Apps.propTypes = {
appName: PropTypes.string,
appNamePrefix: PropTypes.string,
appSlug: PropTypes.string,
iconPath: PropTypes.string,
isPublic: PropTypes.bool,
isInvertedTheme: PropTypes.bool
}

export default Apps
Loading

0 comments on commit f2ffde5

Please sign in to comment.