Skip to content

Commit

Permalink
fix: Improve toolbars UI
Browse files Browse the repository at this point in the history
  • Loading branch information
acezard committed Nov 17, 2021
1 parent 8d5e3a2 commit db30b49
Show file tree
Hide file tree
Showing 10 changed files with 416 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": ["cozy-app/react"],
"ignorePatterns": ["src/plugins/**/*.ts", "src/plugins/**/*.tsx"],
"ignorePatterns": ["src/plugins/**/*.ts", "src/plugins/**/*.tsx", "src/ui/**/*.ts", "src/ui/**/*.tsx"],
"parser": "@babel/eslint-parser",
"overrides": [
{
Expand Down
8 changes: 8 additions & 0 deletions app.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ const extraConfig = {
__dirname,
'node_modules/cozy-editor-core/src/plugins/image-upload'
)]: path.resolve(__dirname, './src/plugins/image-upload'),
[path.resolve(
__dirname,
'node_modules/cozy-editor-core/src/ui/Dropdown'
)]: path.resolve(__dirname, './src/ui/Dropdown'),
[path.resolve(
__dirname,
'node_modules/cozy-editor-core/src/ui/DropdownMenu'
)]: path.resolve(__dirname, './src/ui/DropdownMenu'),
['@atlaskit/editor-core']: path.resolve(
__dirname,
'node_modules/cozy-editor-core/src'
Expand Down
21 changes: 11 additions & 10 deletions src/components/header_menu.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import React, { useMemo } from 'react'

import { models } from 'cozy-client'
import { SharedRecipients } from 'cozy-sharing'
import AppLinker from 'cozy-ui/transpiled/react/AppLinker'
import AppIcon from 'cozy-ui/transpiled/react/AppIcon'
import Divider from 'cozy-ui/transpiled/react/MuiCozyTheme/Divider'
import Link from 'cozy-ui/transpiled/react/Link'
import { SharedRecipients } from 'cozy-sharing'
import { Typography } from '@material-ui/core'
import Typography from 'cozy-ui/transpiled/react/Typography'

import { Slugs } from 'constants/strings'
import { NotePath } from './notes/List/NotePath'
import { CozyFile } from 'cozy-doctypes'
import { Breakpoints } from 'types/enums'
import { getDriveLink } from 'lib/utils'

import styles from './header_menu.styl'
import { NotePath } from './notes/List/NotePath'
import { WithBreakpoints } from './notes/List/WithBreakpoints'
import { Breakpoints } from 'types/enums'
import styles from './header_menu.styl'

const HeaderMenu = ({
homeHref,
Expand All @@ -28,8 +28,9 @@ const HeaderMenu = ({
() => getDriveLink(client, file.attributes.dir_id),
[client, file.attributes.dir_id]
)
const simplifiedDrivePath = drivePath.split('#')[1]

const { filename } = CozyFile.splitFilename(file.attributes)
const { filename } = models.file.splitFilename(file.attributes)

return (
<header className={styles['header-menu']}>
Expand All @@ -42,7 +43,7 @@ const HeaderMenu = ({
)}
</AppLinker>

<Divider orientation="vertical" className={styles['divider']} />
<Divider orientation="vertical" className="u-mh-1" />
</WithBreakpoints>

{backFromEditing && <div className="u-mr-1">{backFromEditing}</div>}
Expand All @@ -63,7 +64,7 @@ const HeaderMenu = ({
<WithBreakpoints hideOn={Breakpoints.Mobile}>
<NotePath
drivePath={drivePath}
path={file.attributes.path || drivePath.split('#')[1]}
path={file.attributes.path || simplifiedDrivePath}
target="_blank"
/>
</WithBreakpoints>
Expand Down
4 changes: 1 addition & 3 deletions src/components/header_menu.styl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
justify-content space-between
padding 0.5rem 1rem
position relative
z-index 1
z-index var(--zIndex-low) // Needed for the drop-shadow to be above the editor area

.app-icon
.home-link
Expand All @@ -21,5 +21,3 @@
display flex
flex-grow 1

.divider
margin 0 1rem !important
4 changes: 3 additions & 1 deletion src/locales/atlassian_missing_french.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
"fabric.editor.layoutFixedWidth": "Retour au centre",
"fabric.editor.alignImageLeft": "Aligner l'image à gauche",
"fabric.editor.alignImageCenter": "Centrer l'image",
"fabric.editor.alignImageRight": "Aligner l'image à droite"
"fabric.editor.alignImageRight": "Aligner l'image à droite",
"fabric.editor.numberedColumn": "Lignes numérotées"

}
30 changes: 21 additions & 9 deletions src/styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ html {
--note-title5-color: var(--coolGrey);
--note-title6-color: var(--coolGrey);
--note-border-radius: 8px;
--note-header-height: 3rem;
--note-header-height: 64px;
--note-header-height-half: 1.5rem;
color: var(--note-base-color);
}
Expand Down Expand Up @@ -72,7 +72,7 @@ html .akEditor > div:first-child {
}

.note-editor-container {
height: calc(100% - 48px);
overflow: hidden;
}

/* prose mirror toolbar in the upper bar */
Expand All @@ -82,16 +82,19 @@ html .akEditor > div:first-child {
height: auto;
position: fixed;
top: auto;
bottom: 1rem;
bottom: calc(env(safe-area-inset-bottom, 1rem) + 1rem);
left: 50%;
transform: translateX(-50%);
background: none;
box-shadow: none;
}

/* toolbar inner wrapper */
html .akEditor > div:first-child > div > div:last-child {
box-shadow: 0px 0px 0px 0.5px rgba(29, 33, 42, 0.12), 0px 2px 4px rgba(29, 33, 42, 0.0793047), 0px 4px 16px rgba(29, 33, 42, 0.06);
border-radius: 8px;
padding: 0 0.5rem;
padding: 0.5rem;
background: white;
}

/* This is the main toolbar wrapper */
Expand Down Expand Up @@ -120,14 +123,12 @@ html .akEditor > div:first-child > div:first-child + div hr {
[data-testid="ak-editor-main-toolbar"] > div > div:nth-child(2) {
display: flex;
align-items: center;
width: 730px; /* full toolbar */
max-width: 100%;
max-width: 768px;
margin: auto;
height: var(--note-header-height);
}

[data-testid="ak-editor-main-toolbar"] + div {
height: calc(100% - 130px);
height: calc(100%);
}

/*
Expand Down Expand Up @@ -402,7 +403,7 @@ html .fabric-editor-popup-scroll-parent > div > div {
}

html .ak-editor-content-area {
padding: var(--documentTopPadding) var(--documentPadding) var(--documentPadding) var(--documentPadding) !important;
padding: var(--documentTopPadding) var(--documentPadding) calc(3 * var(--note-base-size)) var(--documentPadding) !important;
background-color: var(--white);
}

Expand Down Expand Up @@ -454,3 +455,14 @@ html .fabric-editor-popup-scroll-parent > div > div {
.richMedia-resize-handle-right {
z-index: auto !important;
}

/* Required for toolbar's popups because unidentified internals miscalculate the popups position */
/* Since we always display the toolbar at the bottom of the screen we do not care about any other top position than zero */
[data-testid="ak-editor-main-toolbar"] [aria-label*="Popup"] {
top: 0 !important;
}

/* Weird overflow linked to the floating toolbar, could not locate the exact origin of the problem */
body {
overflow-x: hidden;
}
102 changes: 102 additions & 0 deletions src/ui/Dropdown/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import React from 'react'
import { PureComponent } from 'react'
import DropdownList from '@atlaskit/droplist'
import { Popup } from '@atlaskit/editor-common'
import withOuterListeners from '../with-outer-listeners'

export interface Props {
mountTo?: HTMLElement
boundariesElement?: HTMLElement
scrollableElement?: HTMLElement
trigger: React.ReactElement<any>
isOpen?: boolean
onOpenChange?: (attrs: any) => void
fitWidth?: number
fitHeight?: number
zIndex?: number
}

export interface State {
target?: HTMLElement
popupPlacement: [string, string]
}

/**
* Wrapper around @atlaskit/droplist which uses Popup and Portal to render
* droplist outside of "overflow: hidden" containers when needed.
*
* Also it controls popper's placement.
*/
export class Dropdown extends PureComponent<Props, State> {
constructor(props: Props) {
super(props)

this.state = {
popupPlacement: ['bottom', 'left']
}
}

private handleRef = (target: HTMLElement | null) => {
this.setState({ target: target || undefined })
}

private updatePopupPlacement = (placement: [string, string]) => {
this.setState({ popupPlacement: placement })
}

private renderDropdown() {
const { target } = this.state
const {
children,
mountTo,
boundariesElement,
scrollableElement,
onOpenChange,
fitHeight,
fitWidth,
zIndex
} = this.props

return (
<Popup
target={target}
mountTo={mountTo}
boundariesElement={boundariesElement}
scrollableElement={scrollableElement}
onPlacementChanged={this.updatePopupPlacement}
fitHeight={fitHeight}
fitWidth={fitWidth}
zIndex={zIndex}
>
<div style={{ height: 0, minWidth: fitWidth || 0 }}>
<DropdownList
disabled={true}
isOpen={true}
onOpenChange={onOpenChange}
appearance="tall"
position="top left"
shouldFlip={false}
shouldFitContainer={true}
>
{children}
</DropdownList>
</div>
</Popup>
)
}

render() {
const { trigger, isOpen } = this.props

return (
<>
<div ref={this.handleRef}>{trigger}</div>
{isOpen ? this.renderDropdown() : null}
</>
)
}
}

const DropdownWithOuterListeners = withOuterListeners(Dropdown)

export default DropdownWithOuterListeners
Loading

0 comments on commit db30b49

Please sign in to comment.