-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1007f1e
commit 9f4d1b2
Showing
8 changed files
with
141 additions
and
201 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
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: 2 additions & 32 deletions
34
packages/@sanity/form-builder/src/inputs/PortableText/Toolbar/ActionMenu.css
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,40 +1,10 @@ | ||
@import 'part:@sanity/base/theme/variables-style'; | ||
|
||
.menuItem { | ||
composes: item from 'part:@sanity/base/theme/layout/selectable-style'; | ||
|
||
-webkit-font-smoothing: inherit; | ||
display: block; | ||
appearance: none; | ||
font: inherit; | ||
background: none; | ||
color: none; | ||
border: 0; | ||
border-radius: 0; | ||
text-align: left; | ||
width: 100%; | ||
box-sixing: border-box; | ||
padding: var(--small-padding) calc(var(--medium-padding) - var(--small-padding)); | ||
margin: 0; | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.iconContainer { | ||
display: block; | ||
|
||
@nest & svg { | ||
display: block; | ||
font-size: calc(17 / 16 * 1em); | ||
|
||
@nest &[data-sanity-icon] { | ||
font-size: calc(25 / 16 * 1em); | ||
margin: calc(4 / 25 * -1em); | ||
} | ||
@nest & > span > span { | ||
justify-content: flex-start; | ||
} | ||
} | ||
|
||
.title { | ||
display: block; | ||
margin: -2px 0 -1px var(--small-padding); | ||
} |
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
133 changes: 69 additions & 64 deletions
133
packages/@sanity/form-builder/src/inputs/PortableText/Toolbar/InsertMenu.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 |
---|---|---|
@@ -1,83 +1,88 @@ | ||
/* eslint-disable react/jsx-handler-names */ | ||
/* eslint-disable react/jsx-no-bind */ | ||
|
||
import PlusIcon from 'part:@sanity/base/plus-icon' | ||
import Button from 'part:@sanity/components/buttons/default' | ||
import React from 'react' | ||
import {Popover} from 'part:@sanity/components/popover' | ||
import styles from './InsertMenu.css' | ||
import Button, {ButtonProps} from 'part:@sanity/components/buttons/default' | ||
import {MenuButton} from 'part:@sanity/components/menu-button' | ||
import React, {useCallback} from 'react' | ||
import {BlockItem} from './types' | ||
|
||
type Props = { | ||
import styles from './InsertMenu.css' | ||
|
||
interface InsertMenuProps { | ||
disabled: boolean | ||
items: BlockItem[] | ||
readOnly: boolean | ||
} | ||
|
||
export default function InsertMenu(props: Props) { | ||
export default function InsertMenu(props: InsertMenuProps) { | ||
const {disabled, items, readOnly} = props | ||
const [open, setOpen] = React.useState(false) | ||
|
||
const handleOpen = () => { | ||
setOpen(true) | ||
} | ||
|
||
const handleClose = () => { | ||
const handleClose = useCallback(() => { | ||
setOpen(false) | ||
} | ||
}, []) | ||
|
||
const menu = ( | ||
<div className={styles.menu}> | ||
{items.map(item => ( | ||
<InsertMenuItem item={item} onClick={handleClose} key={item.key} /> | ||
))} | ||
</div> | ||
) | ||
|
||
return ( | ||
<div className={styles.root}> | ||
<Popover | ||
className={styles.initialValueMenuPopover} | ||
placement="bottom" | ||
<MenuButton | ||
buttonProps={{ | ||
'aria-label': 'Insert elements', | ||
'aria-haspopup': 'menu', | ||
'aria-expanded': open, | ||
'aria-controls': 'insertmenu', | ||
disabled: disabled || readOnly, | ||
icon: PlusIcon, | ||
kind: 'simple', | ||
padding: 'small', | ||
selected: open, | ||
title: 'Insert elements' | ||
}} | ||
menu={menu} | ||
open={open} | ||
content={ | ||
( | ||
<div className={styles.menu}> | ||
{items.map(item => { | ||
const itemIsDisabled = item.disabled | ||
const title = item.type.title || item.type.type.name | ||
return ( | ||
<button | ||
aria-label={`Insert ${title}${item.inline ? ' (inline)' : ' (block)'}`} | ||
disabled={itemIsDisabled} | ||
className={styles.menuItem} | ||
key={item.key} | ||
onClick={() => { | ||
item.handle() | ||
handleClose() | ||
}} | ||
title={`Insert ${title}${item.inline ? ' (inline)' : ' (block)'}`} | ||
type="button" | ||
> | ||
<span className={styles.iconContainer}>{React.createElement(item.icon)}</span> | ||
<span className={styles.title}>{title}</span> | ||
</button> | ||
) | ||
})} | ||
</div> | ||
) as any | ||
} | ||
> | ||
<div> | ||
<Button | ||
aria-label="Insert elements" | ||
aria-haspopup="menu" | ||
aria-expanded={open} | ||
aria-controls={'insertmenu'} | ||
disabled={disabled || readOnly} | ||
icon={PlusIcon} | ||
kind="simple" | ||
onClick={handleOpen} | ||
padding="small" | ||
selected={open} | ||
title="Insert elements" | ||
> | ||
Insert | ||
</Button> | ||
</div> | ||
</Popover> | ||
placement="bottom" | ||
setOpen={setOpen} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
function InsertMenuItem({ | ||
item, | ||
onClick, | ||
...restProps | ||
}: {item: BlockItem} & Omit< | ||
ButtonProps, | ||
'aria-label' | 'children' | 'className' | 'disabled' | 'icon' | 'title' | 'type' | ||
>) { | ||
const handleClick = useCallback( | ||
(event: React.MouseEvent<HTMLButtonElement>) => { | ||
item.handle() | ||
if (onClick) onClick(event) | ||
}, | ||
[item] | ||
) | ||
|
||
const title = item.type.title || item.type.type.name | ||
|
||
return ( | ||
<Button | ||
{...restProps} | ||
aria-label={`Insert ${title}${item.inline ? ' (inline)' : ' (block)'}`} | ||
bleed | ||
className={styles.menuItem} | ||
disabled={item.disabled} | ||
icon={item.icon} | ||
kind="simple" | ||
onClick={handleClick} | ||
title={`Insert ${title}${item.inline ? ' (inline)' : ' (block)'}`} | ||
> | ||
{title} | ||
</Button> | ||
) | ||
} |
Oops, something went wrong.