Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/navbar overhaul #2072

Merged
merged 5 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"cozy-device-helper": "^1.16.1",
"cozy-doctypes": "^1.69.0",
"cozy-harvest-lib": "^6.7.3",
"cozy-intent": "^1.6.0",
"cozy-intent": "^1.13.0",
"cozy-sharing": "^3.10.0",
"cozy-stack-client": "27.19.1",
"css-loader": "0.28.11",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem que précédemment : pourquoi ce commit est nécessaire ici ? Est-ce qu'on peut ajouter de la description dans le commit message ?

Expand Down
22 changes: 22 additions & 0 deletions react/ActionMenu/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import Radio from '../Radio'
import { spacingProp } from '../Stack'
import { usePopper } from 'react-popper'
import createDepreciationLogger from '../helpers/createDepreciationLogger'
import { useSetFlagshipUI } from '../hooks/useSetFlagshipUi/useSetFlagshipUI'
import { useTheme } from '@material-ui/core'
acezard marked this conversation as resolved.
Show resolved Hide resolved

const ActionMenuWrapper = ({
inline,
Expand Down Expand Up @@ -101,6 +103,26 @@ const ActionMenu = ({
anchorElRef,
containerElRef
}) => {
const theme = useTheme()
const sidebar = document.querySelector('[class*="sidebar"]')
acezard marked this conversation as resolved.
Show resolved Hide resolved

useSetFlagshipUI(
acezard marked this conversation as resolved.
Show resolved Hide resolved
{
bottomBackground: theme.palette.background.paper,
bottomTheme: 'dark',
topOverlay: getCssVariableValue('overlay'),
acezard marked this conversation as resolved.
Show resolved Hide resolved
topBackground: theme.palette.background.paper,
topTheme: 'light'
},
{
bottomBackground: theme.palette.background[sidebar ? 'default' : 'paper'],
bottomTheme: 'dark',
topOverlay: 'transparent',
topBackground: theme.palette.background.paper,
topTheme: 'dark'
}
)

if (placement)
logDepecratedPlacement(
'<ActionMenu placement /> is deprecated, use <ActionMenu popperOptions={{ placement }} /> instead'
Expand Down
23 changes: 0 additions & 23 deletions react/BarContextProvider/index.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,27 +172,4 @@ describe('BarContextProvider', () => {

expect(queryByText(mockVoidWebviewService)).toBeInTheDocument()
})

it('should not try to provide a cozy-intent context if one is provided', () => {
// Set Web context
trollepierre marked this conversation as resolved.
Show resolved Hide resolved
window.cozy.isFlagshipApp = false

const client = createMockClient({})
const mockStore = configureStore()
const store = mockStore(x => x)

const { queryByText } = render(
<Provider store={store}>
<CozyProvider client={client}>
<I18n lang="en" dictRequire={() => locales}>
<App webviewService={mockWebviewService}>
<IntentComponent />
</App>
</I18n>
</CozyProvider>
</Provider>
)

expect(queryByText(mockWebviewService.foo)).not.toBeInTheDocument()
})
})
41 changes: 39 additions & 2 deletions react/Dialog/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { RemoveScroll } from 'react-remove-scroll'
import useBreakpoints from '../hooks/useBreakpoints'
import { useCozyTheme } from '../CozyTheme'
import themesStyles from '../../stylus/settings/palette.styl'
import { useSetFlagshipUI } from '../hooks/useSetFlagshipUi/useSetFlagshipUI'
import { useTheme } from '@material-ui/core'

const Dialog = props => {
const { isMobile, isTablet } = useBreakpoints()
Expand All @@ -21,12 +23,47 @@ const Dialog = props => {
(props.open || props.opened) && shouldBlockScroll
? RemoveScroll
: React.Fragment
const cozyTheme = useCozyTheme()
const theme = useTheme()
const cozBar = document.querySelector('.coz-bar-wrapper')
const sidebar = document.getElementById('sidebar')

const theme = useCozyTheme()
useSetFlagshipUI(
acezard marked this conversation as resolved.
Show resolved Hide resolved
props.fullScreen
? {
bottomBackground: theme.palette.background.paper,
bottomTheme: 'dark',
topBackground: theme.palette.background.paper,
topTheme: 'dark'
}
: {
bottomBackground: theme.palette.background.default,
bottomTheme: 'light',
bottomOverlay: 'rgba(0, 0, 0, 0.5)',
acezard marked this conversation as resolved.
Show resolved Hide resolved
topOverlay: 'rgba(0, 0, 0, 0.5)',
topBackground: theme.palette.background.paper,
topTheme: 'light'
},
{
bottomBackground: theme.palette.background[sidebar ? 'default' : 'paper'],
bottomTheme: 'dark',
bottomOverlay: 'transparent',
topOverlay: 'transparent',
topBackground:
cozBar && getComputedStyle(cozBar).getPropertyValue('background-color'),
acezard marked this conversation as resolved.
Show resolved Hide resolved
topTheme:
cozBar && cozBar.classList.contains('coz-theme-primary')
? 'light'
: 'dark'
}
)

return (
<Wrapper>
<MUIDialog className={themesStyles[`CozyTheme--${theme}`]} {...props} />
<MUIDialog
className={themesStyles[`CozyTheme--${cozyTheme}`]}
{...props}
/>
</Wrapper>
)
}
Expand Down
35 changes: 34 additions & 1 deletion react/SelectionBar/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useEffect } from 'react'
import PropTypes from 'prop-types'
import cx from 'classnames'

Expand All @@ -11,6 +11,8 @@ import useBreakpoints from '../hooks/useBreakpoints'
import styles from './styles.styl'

import CrossIcon from 'cozy-ui/transpiled/react/Icons/Cross'
import { useWebviewIntent } from 'cozy-intent'
import { useTheme } from '@material-ui/core'

/*

Expand Down Expand Up @@ -39,6 +41,37 @@ const SelectionBar = ({ actions, selected, hideSelectionBar }) => {
action.displayCondition === undefined || action.displayCondition(selected)
)
})
const webviewIntent = useWebviewIntent()
const theme = useTheme()

// This component is always rendered but hidden with CSS if there is no selection
acezard marked this conversation as resolved.
Show resolved Hide resolved
// That is why we do not use useSetFlagship API here because that hook can not accept changing values
acezard marked this conversation as resolved.
Show resolved Hide resolved
useEffect(() => {
if (!webviewIntent || !theme) return
acezard marked this conversation as resolved.
Show resolved Hide resolved

selectedCount === 0 &&
webviewIntent &&
webviewIntent.call('setFlagshipUI', {
bottomBackground: theme.palette.background.default,
bottomTheme: 'dark'
})

selectedCount > 0 &&
webviewIntent &&
webviewIntent.call('setFlagshipUI', {
bottomBackground: theme.palette.grey[700],
bottomTheme: 'light'
})

return () =>
webviewIntent &&
theme &&
webviewIntent.call('setFlagshipUI', {
bottomBackground: theme.palette.background.default,
bottomTheme: 'dark'
})
}, [selectedCount, webviewIntent])

return (
<div
data-testid="selectionBar"
Expand Down
30 changes: 25 additions & 5 deletions react/Sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,32 @@ import React from 'react'
import cx from 'classnames'
import PropTypes from 'prop-types'
import styles from './styles.styl'
import { useSetFlagshipUI } from '../hooks/useSetFlagshipUi/useSetFlagshipUI'
import { useTheme } from '@material-ui/core'

const Sidebar = ({ children, className, ...restProps }) => (
<aside className={cx(styles['o-sidebar'], className)} {...restProps}>
{children}
</aside>
)
const Sidebar = ({ children, className, ...restProps }) => {
const theme = useTheme()

useSetFlagshipUI(
acezard marked this conversation as resolved.
Show resolved Hide resolved
{
bottomBackground: theme.palette.background.default,
bottomTheme: 'dark'
},
{
bottomBackground: theme.palette.background.paper
}
)

return (
<aside
id="sidebar"
className={cx(styles['o-sidebar'], className)}
{...restProps}
>
{children}
</aside>
)
}

Sidebar.propTypes = {
children: PropTypes.node,
Expand Down
15 changes: 15 additions & 0 deletions react/Viewer/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import ViewerByFile from './ViewerByFile'
import { isValidForPanel } from './helpers'
import PanelContent from './Panel/PanelContent'
import FooterContent from './Footer/FooterContent'
import { useSetFlagshipUI } from '../hooks/useSetFlagshipUi/useSetFlagshipUI'
import { useTheme } from '@material-ui/core'

const KEY_CODE_LEFT = 37
const KEY_CODE_RIGHT = 39
Expand Down Expand Up @@ -149,6 +151,19 @@ const ViewerInformationsWrapper = ({
validForPanel,
toolbarRef
}) => {
const theme = useTheme()
const sidebar = document.querySelector('[class*="sidebar"]')

useSetFlagshipUI(
acezard marked this conversation as resolved.
Show resolved Hide resolved
{
bottomBackground: theme.palette.background.paper,
bottomTheme: 'dark'
},
{
bottomBackground: theme.palette.background[sidebar ? 'default' : 'paper']
trollepierre marked this conversation as resolved.
Show resolved Hide resolved
}
)

return (
<>
{!disableFooter && (
Expand Down
2 changes: 1 addition & 1 deletion react/__snapshots__/examples.spec.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8090,7 +8090,7 @@ exports[`SelectBox should render examples: SelectBox 14`] = `"<div><button>Toggl

exports[`Sidebar should render examples: Sidebar 1`] = `
"<div>
<aside class=\\"styles__o-sidebar___1295j\\" id=\\"sidebar\\">
<aside id=\\"sidebar\\" class=\\"styles__o-sidebar___1295j\\">
<nav role=\\"navigation\\">
<ul class=\\"styles__c-nav___33dZy\\">
<li class=\\"styles__c-nav-item___3XOLK\\" id=\\"nav-item\\"><a class=\\"styles__c-nav-link___3mK6W styles__is-active___2D0jN\\"><span class=\\"styles__c-nav-icon___hrJUe\\"><svg viewBox=\\"0 0 48 48\\" class=\\"styles__icon___23x3R\\" width=\\"16\\" height=\\"16\\" aria-hidden=\\"true\\" focusable=\\"false\\"><path fill-rule=\\"evenodd\\" d=\\"M24 48c13.255 0 24-10.745 24-24S37.255 0 24 0 0 10.745 0 24s10.745 24 24 24zm-1.503-34.897c.83-1.438 2.175-1.44 3.007 0l9.992 17.294c.83 1.438.16 2.603-1.504 2.603H14.008c-1.661 0-2.336-1.162-1.504-2.603l9.993-17.294zm.082 5.323A1.334 1.334 0 0123.93 17h.141c.79 0 1.395.633 1.35 1.426l-.365 6.576c-.03.551-.499.998-1.055.998a1.069 1.069 0 01-1.055-.998l-.366-6.576zM22.5 29c0-.828.666-1.5 1.5-1.5.828 0 1.5.666 1.5 1.5 0 .828-.666 1.5-1.5 1.5-.828 0-1.5-.666-1.5-1.5z\\"></path></svg></span><span class=\\"styles__c-nav-text___1J3yU\\">Warn</span></a></li>
Expand Down
25 changes: 25 additions & 0 deletions react/hooks/useSetFlagshipUi/useSetFlagshipUI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useEffect } from 'react'
import { useWebviewIntent } from 'cozy-intent'
import pickBy from 'lodash/pickBy'
import identity from 'lodash/identity'
import isEmpty from 'lodash/isEmpty'
import isObject from 'lodash/isObject'

export const useSetFlagshipUI = (onMount, onUnmount) => {
const webviewIntent = useWebviewIntent()

useEffect(() => {
const parsedOnMount = isObject(onMount) && pickBy(onMount, identity)
acezard marked this conversation as resolved.
Show resolved Hide resolved
const parsedOnUnmount = isObject(onUnmount) && pickBy(onUnmount, identity)

webviewIntent &&
!isEmpty(parsedOnMount) &&
webviewIntent.call('setFlagshipUI', parsedOnMount)

return () => {
webviewIntent &&
acezard marked this conversation as resolved.
Show resolved Hide resolved
!isEmpty(parsedOnUnmount) &&
webviewIntent.call('setFlagshipUI', parsedOnUnmount)
}
}, [webviewIntent])
}
Loading