-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9586 from hicommonwealth/burton/editor-v4-with-po…
…pover Handle mobile toolbar activation / focus on mobile
- Loading branch information
Showing
37 changed files
with
854 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 6 additions & 2 deletions
8
...ges/commonwealth/client/scripts/views/components/MarkdownEditor/MarkdownSubmitButton.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
.mdxeditor-container-mode-desktop .MarkdownSubmitButton button { | ||
.MarkdownSubmitButton { | ||
border: none; | ||
outline: none; | ||
cursor: pointer; | ||
} | ||
|
||
.mdxeditor-container-mode-desktop .MarkdownSubmitButton { | ||
font-size: 1.2em; | ||
padding: 8px 16px; | ||
cursor: pointer; | ||
border-radius: 8px; | ||
display: inline-block; | ||
} |
1 change: 1 addition & 0 deletions
1
...ages/commonwealth/client/scripts/views/components/MarkdownEditor/MarkdownSubmitButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...monwealth/client/scripts/views/components/MarkdownEditor/indicators/TooltipIndicator.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
@import '../../../../../styles/shared'; | ||
|
||
.TooltipIndicator { | ||
// cover the parent | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
|
||
// needed so that drag operations don't get hijacked by the indicator which | ||
// would prevent dropping images and markdown files into the editor. | ||
pointer-events: none; | ||
|
||
// the z-index is needed because the 'select' in MDXEditor has its own z-index | ||
// which we have to sit on top of. | ||
z-index: 10; | ||
|
||
// needed so that the .inner progress indicator can be centered | ||
display: flex; | ||
|
||
.inner { | ||
// center the contnts | ||
margin: auto auto; | ||
|
||
font-size: 12px; | ||
letter-spacing: 0.24px; | ||
border-radius: 4px; | ||
background-color: $neutral-900; | ||
padding: 4px 8px; | ||
color: $white; | ||
text-align: center; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...mmonwealth/client/scripts/views/components/MarkdownEditor/indicators/TooltipIndicator.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import './TooltipIndicator.scss'; | ||
|
||
type TooltipIndicatorProps = Readonly<{ | ||
label: string; | ||
}>; | ||
|
||
export const TooltipIndicator = (props: TooltipIndicatorProps) => { | ||
const { label } = props; | ||
return ( | ||
<div className="TooltipIndicator"> | ||
<div className="inner">{label}</div> | ||
</div> | ||
); | ||
}; |
23 changes: 23 additions & 0 deletions
23
...onwealth/client/scripts/views/components/MarkdownEditor/toolbars/BlockSelectorButton.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.BlockSelectorButton { | ||
button { | ||
outline: none; | ||
border: none; | ||
cursor: pointer; | ||
} | ||
.DropdownIndicator { | ||
display: flex; | ||
gap: 2px; | ||
} | ||
} | ||
|
||
.FormattingPopover { | ||
padding: 4px; | ||
|
||
margin-bottom: 8px; | ||
margin-top: 8px; | ||
|
||
button { | ||
outline: none; | ||
border: none; | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...monwealth/client/scripts/views/components/MarkdownEditor/toolbars/BlockSelectorButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import ClickAwayListener from '@mui/base/ClickAwayListener'; | ||
import { currentBlockType$, useCellValue } from 'commonwealth-mdxeditor'; | ||
import React, { useCallback } from 'react'; | ||
import { HeadingButton } from 'views/components/MarkdownEditor/toolbars/HeadingButton'; | ||
import { PlaceholderIcon } from 'views/components/MarkdownEditor/toolbars/PlaceholderIcon'; | ||
import { blockTypeToIconName } from 'views/components/MarkdownEditor/toolbars/blockTypeToIconName'; | ||
import { CWIcon } from 'views/components/component_kit/cw_icons/cw_icon'; | ||
import CWPopover, { | ||
usePopover, | ||
} from 'views/components/component_kit/new_designs/CWPopover'; | ||
import './BlockSelectorButton.scss'; | ||
|
||
type BlockSelectorButtonProps = Readonly<{ | ||
focus: () => void; | ||
}>; | ||
|
||
export const BlockSelectorButton = (props: BlockSelectorButtonProps) => { | ||
const { focus } = props; | ||
|
||
const popoverProps = usePopover(); | ||
|
||
const currentBlockType = useCellValue(currentBlockType$); | ||
|
||
const handleClick = useCallback( | ||
(event: React.MouseEvent<HTMLElement, MouseEvent>) => { | ||
popoverProps.handleInteraction(event); | ||
focus(); | ||
}, | ||
[focus, popoverProps], | ||
); | ||
|
||
const handleFormatButtonClick = useCallback( | ||
(event: React.MouseEvent<HTMLElement, MouseEvent>) => { | ||
popoverProps.handleInteraction(event); | ||
}, | ||
[popoverProps], | ||
); | ||
|
||
const handleClickAway = useCallback(() => { | ||
popoverProps.dispose(); | ||
}, [popoverProps]); | ||
|
||
const iconName = blockTypeToIconName(currentBlockType); | ||
|
||
return ( | ||
<ClickAwayListener onClickAway={handleClickAway}> | ||
<div className="BlockSelectorButton"> | ||
<button onClick={handleClick}> | ||
<div className="DropdownIndicator"> | ||
{iconName && <CWIcon iconName={iconName} />} | ||
{!iconName && <PlaceholderIcon />} | ||
<CWIcon iconName="caretDown" iconSize="xs" /> | ||
</div> | ||
</button> | ||
|
||
<CWPopover | ||
className="FormattingPopover" | ||
body={ | ||
<div onMouseLeave={popoverProps.handleInteraction}> | ||
<HeadingButton blockType="p" onClick={handleFormatButtonClick} /> | ||
<HeadingButton blockType="h1" onClick={handleFormatButtonClick} /> | ||
<HeadingButton blockType="h2" onClick={handleFormatButtonClick} /> | ||
<HeadingButton blockType="h3" onClick={handleFormatButtonClick} /> | ||
<HeadingButton | ||
blockType="quote" | ||
onClick={handleFormatButtonClick} | ||
/> | ||
</div> | ||
} | ||
{...popoverProps} | ||
/> | ||
</div> | ||
</ClickAwayListener> | ||
); | ||
}; |
37 changes: 37 additions & 0 deletions
37
...commonwealth/client/scripts/views/components/MarkdownEditor/toolbars/CreateLinkButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { openLinkEditDialog$, usePublisher } from 'commonwealth-mdxeditor'; | ||
import React, { useCallback } from 'react'; | ||
import CWIconButton from 'views/components/component_kit/new_designs/CWIconButton'; | ||
import { CWTooltip } from 'views/components/component_kit/new_designs/CWTooltip'; | ||
import './HeadingButton.scss'; | ||
|
||
export type CWCreateLinkButtonProps = Readonly<{ | ||
onClick?: (event: React.MouseEvent<HTMLElement, MouseEvent>) => void; | ||
}>; | ||
|
||
export const CreateLinkButton = (props: CWCreateLinkButtonProps) => { | ||
const { onClick } = props; | ||
const openLinkDialog = usePublisher(openLinkEditDialog$); | ||
|
||
const handleClick = useCallback( | ||
(event: React.MouseEvent<HTMLElement, MouseEvent>) => { | ||
openLinkDialog(); | ||
onClick?.(event); | ||
}, | ||
[onClick, openLinkDialog], | ||
); | ||
|
||
return ( | ||
<CWTooltip | ||
content="Create link" | ||
renderTrigger={(handleInteraction) => ( | ||
<CWIconButton | ||
buttonSize="lg" | ||
iconName="linkPhosphor" | ||
onMouseEnter={handleInteraction} | ||
onMouseLeave={handleInteraction} | ||
onClick={handleClick} | ||
/> | ||
)} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.