Skip to content

Commit

Permalink
feat: Add isInvertedTheme param
Browse files Browse the repository at this point in the history
This parameter is used to indicate to cozy-bar
that it is in reverse theme (black, by default white).
This commit allows with this condition to change the icon
`icon-cozy-home.svg` by `icon-cozy-home-inverted.svg`
  • Loading branch information
Merkur39 committed May 19, 2023
1 parent a0a2b6b commit d460806
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 49 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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
26 changes: 20 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/react/AppIcon'
import AppLinker from 'cozy-ui/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,13 @@ export class AppItem extends React.Component {
}

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

const dataIcon = app.slug ? `icon-${app.slug}` : ''
const appName = getAppDisplayName(app)
Expand Down Expand Up @@ -92,7 +99,10 @@ export class AppItem extends React.Component {
aria-hidden={ariaHidden}
>
{useHomeIcon ? (
<HomeIcon className="coz-nav-apps-item-icon" />
<HomeIcon
className="coz-nav-apps-item-icon"
isInvertedTheme={isInvertedTheme}
/>
) : (
<AppIcon
app={app}
Expand All @@ -113,7 +123,11 @@ export class AppItem extends React.Component {

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

export default AppItem
25 changes: 22 additions & 3 deletions src/components/Apps/AppNavButtons.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'

import { getHomeApp } from 'lib/reducers'
import PropTypes from 'prop-types'

import { translate } from 'cozy-ui/react/I18n'
import Icon from 'cozy-ui/react/Icon'

import { getHomeApp } from 'lib/reducers'
import { isFetchingApps } from 'lib/reducers'
import { ButtonCozyHome } from './ButtonCozyHome'

Expand All @@ -17,6 +18,7 @@ class AppNavButton extends Component {
appNamePrefix,
appSlug,
iconPath,
isInvertedTheme,
isFetchingApps,
isPublic,
opened,
Expand Down Expand Up @@ -50,7 +52,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 All @@ -75,6 +77,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
24 changes: 16 additions & 8 deletions src/components/Apps/AppsContent.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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/react/I18n'
import withBreakpoints from 'cozy-ui/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'
import cozyIcon from 'assets/icons/16/icon-cozy-16.svg'
Expand All @@ -27,7 +27,8 @@ export class AppsContent extends Component {
isFetchingApps,
onAppSwitch,
tabIndex,
ariaHidden
ariaHidden,
isInvertedTheme
} = this.props
const { isMobile } = breakpoints
const isHomeApp = homeApp && homeApp.isCurrentApp
Expand All @@ -47,6 +48,7 @@ export class AppsContent extends Component {
onAppSwitch={onAppSwitch}
tabIndex={tabIndex}
ariaHidden={ariaHidden}
isInvertedTheme={isInvertedTheme}
/>
)}
{isFetchingApps
Expand All @@ -63,6 +65,7 @@ export class AppsContent extends Component {
onAppSwitch={onAppSwitch}
tabIndex={tabIndex}
ariaHidden={ariaHidden}
isInvertedTheme={isInvertedTheme}
/>
))}
</ul>
Expand All @@ -88,12 +91,17 @@ AppsContent.defaultProps = {
}

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,
tabIndex: PropTypes.number,
ariaHidden: PropTypes.bool,
isInvertedTheme: PropTypes.bool
}
const translateApp = t => app => {
const namePrefix = app.namePrefix
Expand Down
32 changes: 27 additions & 5 deletions src/components/Apps/ButtonCozyHome.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import React from 'react'
import PropTypes from 'prop-types'

import flag from 'cozy-flags'
import { isFlagshipApp } from 'cozy-device-helper'
import { translate } from 'cozy-ui/react/I18n'

import IconCozyHome from './IconCozyHome'

const ButtonCozyHomeWithI18n = ({ webviewContext, homeHref, t }) => {
const ButtonCozyHomeWithI18n = ({
webviewContext,
homeHref,
t,
isInvertedTheme
}) => {
if (isFlagshipApp() || flag('flagship.debug'))
return (
<a
Expand All @@ -18,11 +24,14 @@ const ButtonCozyHomeWithI18n = ({ webviewContext, homeHref, t }) => {
aria-label={t('menu.home')}
data-testid="ButtonCozyHome-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}
Expand All @@ -31,21 +40,34 @@ const ButtonCozyHomeWithI18n = ({ webviewContext, homeHref, t }) => {
aria-label={t('menu.home')}
data-testid="ButtonCozyHome-homeHref"
>
<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"
aria-hidden="true"
data-testid="ButtonCozyHome-span"
>
<IconCozyHome className="coz-nav-apps-btns-home-svg" />
<IconCozyHome
className="coz-nav-apps-btns-home-svg"
isInvertedTheme={isInvertedTheme}
/>
</span>
)
}

ButtonCozyHomeWithI18n.propTypes = {
webviewContext: PropTypes.object,
homeHref: PropTypes.string,
isInvertedTheme: PropTypes.bool
}

const ButtonCozyHome = translate()(ButtonCozyHomeWithI18n)

export { ButtonCozyHome }
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/react/AppIcon'

Expand All @@ -7,9 +8,13 @@ import homeIcon from 'assets/sprites/icon-cozy-home.svg'

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 @@ -21,4 +26,9 @@ class IconCozyHome extends PureComponent {
}
}

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

export default IconCozyHome
21 changes: 19 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 @@ -45,7 +46,8 @@ class Apps extends Component {
appNamePrefix,
appSlug,
iconPath,
isPublic
isPublic,
isInvertedTheme
} = this.props
const { opened } = this.state
const tabIndex = opened ? 0 : -1
Expand All @@ -66,18 +68,33 @@ 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}
tabIndex={tabIndex}
>
<AppsContent tabIndex={tabIndex} ariaHidden={!opened} />
<AppsContent
tabIndex={tabIndex}
ariaHidden={!opened}
isInvertedTheme={isInvertedTheme}
/>
</div>
</nav>
)
}
}

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

export default Apps
Loading

0 comments on commit d460806

Please sign in to comment.