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(facelift): create menu item StudioUI #5090

Merged
merged 8 commits into from
Nov 2, 2023
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ module.exports = {
paths: [
{
name: '@sanity/ui',
importNames: ['Tooltip', 'TooltipProps'],
importNames: ['Tooltip', 'TooltipProps', 'MenuItem', 'MenuItemProps'],
message:
'Please use the (more opinionated) exported components in sanity/src/ui instead.',
},
Expand Down
12 changes: 12 additions & 0 deletions dev/test-studio/schema/book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ export default {
},
],
},
{
name: 'genre',
title: 'Genre',
type: 'string',
options: {
list: [
{title: 'Fiction', value: 'fiction'},
{title: 'Non Fiction', value: 'nonfiction'},
{title: 'Poetry', value: 'poetry'},
],
},
},
],
orderings: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Menu, MenuButton, MenuButtonProps, MenuDivider, MenuItem} from '@sanity/ui'
import {Menu, MenuButton, MenuButtonProps, MenuDivider} from '@sanity/ui'
import React from 'react'
import {MenuItem} from '../../../ui'
import {CollapseMenuProps} from './CollapseMenu'

const MENU_BUTTON_POPOVER_PROPS: MenuButtonProps['popover'] = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {MenuItem, Text} from '@sanity/ui'
import {Text} from '@sanity/ui'
import React, {useCallback} from 'react'
import {CheckmarkIcon} from '@sanity/icons'
import {TooltipOfDisabled} from '../../../components'
import {DocumentFieldActionItem} from '../../../config'
import {MenuItem} from '../../../../ui'

export function FieldActionMenuItem(props: {action: DocumentFieldActionItem}) {
const {action} = props
Expand All @@ -19,13 +20,10 @@ export function FieldActionMenuItem(props: {action: DocumentFieldActionItem}) {
<TooltipOfDisabled content={disabledTooltipContent} placement="left">
<MenuItem
disabled={Boolean(action.disabled)}
fontSize={1}
icon={action.icon}
iconRight={action.iconRight || (action.selected ? CheckmarkIcon : undefined)}
onClick={handleClick}
padding={3}
pressed={action.selected}
space={3}
text={action.title}
tone={action.tone}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import {EditIcon, LinkIcon, TrashIcon, EyeOpenIcon, EllipsisVerticalIcon} from '@sanity/icons'
import {
Box,
Button,
Flex,
Menu,
MenuButton,
MenuButtonProps,
MenuItem,
useGlobalKeyDown,
} from '@sanity/ui'
import {Box, Button, Flex, Menu, MenuButton, MenuButtonProps, useGlobalKeyDown} from '@sanity/ui'
import React, {
forwardRef,
ReactElement,
Expand All @@ -20,6 +11,7 @@ import React, {
PropsWithChildren,
} from 'react'
import {PortableTextBlock, isReference} from '@sanity/types'
import {MenuItem} from '../../../../../ui'
import {IntentLink} from 'sanity/router'

interface BlockObjectActionsMenuProps extends PropsWithChildren {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {memo, useCallback, useMemo} from 'react'
import {PortableTextEditor, usePortableTextEditor} from '@sanity/portable-text-editor'
import {Button, Menu, MenuButton, MenuButtonProps, MenuItem, Text} from '@sanity/ui'
import {Button, Menu, MenuButton, MenuButtonProps, Text} from '@sanity/ui'
import {SelectIcon} from '@sanity/icons'
import styled from 'styled-components'
import {
Expand All @@ -13,6 +13,7 @@ import {
BlockQuote,
Normal,
} from '../text/textStyles'
import {MenuItem} from '../../../../../ui'
import {useActiveStyleKeys, useFocusBlock} from './hooks'
import {BlockStyleItem} from './types'

Expand Down Expand Up @@ -145,6 +146,8 @@ export const BlockStyleSelect = memo(function BlockStyleSelect(
// eslint-disable-next-line react/jsx-no-bind
onClick={_disabled ? undefined : () => handleChange(item)}
>
{/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
{/* @ts-ignore: This item uses a specific render of the menu item.*/}
{renderOption(item.style, item?.title || item.style)}
</StyledMenuItem>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
Menu,
MenuButton,
MenuDivider,
MenuItem,
Stack,
Text,
} from '@sanity/ui'
Expand All @@ -36,6 +35,7 @@ import {AlertStrip} from '../../components/AlertStrip'
import {FieldActionsResolver} from '../../field'
import {DocumentFieldActionNode} from '../../../config'
import {useFormPublishedId} from '../../useFormPublishedId'
import {MenuItem} from '../../../../ui'
import {useReferenceInput} from './useReferenceInput'
import {useReferenceInfo} from './useReferenceInfo'
import {PreviewReferenceValue} from './PreviewReferenceValue'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
Menu,
MenuButton,
MenuDivider,
MenuItem,
Spinner,
Stack,
Text,
Expand Down Expand Up @@ -36,6 +35,7 @@ import {AlertStrip} from '../../components/AlertStrip'
import {set, unset} from '../../patch'
import {createProtoArrayValue} from '../arrays/ArrayOfObjectsInput/createProtoArrayValue'
import {InsertMenu} from '../arrays/ArrayOfObjectsInput/InsertMenu'
import {MenuItem} from '../../../../ui'
import {useReferenceInfo} from './useReferenceInfo'
import {PreviewReferenceValue} from './PreviewReferenceValue'
import {useReferenceInput} from './useReferenceInput'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {ArraySchemaType, isReferenceSchemaType} from '@sanity/types'
import {AddIcon} from '@sanity/icons'
import React, {useId, useCallback} from 'react'
import {Box, Button, Grid, Menu, MenuButton, MenuItem, Text, MenuButtonProps} from '@sanity/ui'
import {Button, Grid, Menu, MenuButton, MenuButtonProps} from '@sanity/ui'
import {ArrayInputFunctionsProps, ObjectItem} from '../../../types'
import {Tooltip} from '../../../../../ui'
import {MenuItem, Tooltip} from '../../../../../ui'

const POPOVER_PROPS: MenuButtonProps['popover'] = {
constrainSize: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, {useCallback, useId} from 'react'
import {EllipsisVerticalIcon, TrashIcon} from '@sanity/icons'
import {Button, Menu, MenuButton, MenuItem} from '@sanity/ui'
import {Button, Menu, MenuButton} from '@sanity/ui'
import {ArrayItemError} from '../../../../store'
import {useFormCallbacks} from '../../../../studio/contexts/FormCallbacks'
import {PatchEvent, unset} from '../../../../patch'
import {CellLayout} from '../../layouts/CellLayout'
import {MenuItem} from '../../../../../../ui'
import {IncompatibleItemType} from './IncompatibleItemType'

const MENU_POPOVER_PROPS = {portal: true, tone: 'default'} as const
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
import {
Box,
Button,
Card,
CardTone,
Flex,
Menu,
MenuButton,
MenuItem,
Spinner,
Text,
} from '@sanity/ui'
import {Box, Button, Card, CardTone, Flex, Menu, MenuButton, Spinner, Text} from '@sanity/ui'
import React, {useCallback, useMemo, useRef} from 'react'
import {SchemaType} from '@sanity/types'
import {CopyIcon as DuplicateIcon, EllipsisVerticalIcon, TrashIcon} from '@sanity/icons'
Expand All @@ -29,6 +18,7 @@ import {createProtoArrayValue} from '../createProtoArrayValue'
import {InsertMenu} from '../InsertMenu'
import {FIXME} from '../../../../../FIXME'
import {EditPortal} from '../../../../components/EditPortal'
import {MenuItem} from '../../../../../../ui'

type GridItemProps<Item extends ObjectItem> = Omit<ObjectItemProps<Item>, 'renderDefault'>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable react/jsx-no-bind */
import {SchemaType} from '@sanity/types'
import React, {ComponentProps, memo} from 'react'
import {MenuGroup, MenuItem, PopoverProps} from '@sanity/ui'
import {MenuGroup, PopoverProps} from '@sanity/ui'
import {InsertAboveIcon, InsertBelowIcon} from '@sanity/icons'
import {MenuItem} from '../../../../../ui'

interface Props {
types?: SchemaType[]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {useCallback, useId} from 'react'
import React, {useId} from 'react'
import {EllipsisVerticalIcon, TrashIcon} from '@sanity/icons'
import {Box, Button, Menu, MenuButton, MenuItem} from '@sanity/ui'
import {Box, Button, Menu, MenuButton} from '@sanity/ui'
import {MenuItem} from '../../../../../../ui'
import {ArrayItemError} from '../../../../store'
import {RowLayout} from '../../layouts/RowLayout'
import {IncompatibleItemType} from './IncompatibleItemType'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
import {
Box,
Button,
Card,
CardTone,
Flex,
Menu,
MenuButton,
MenuItem,
Spinner,
Text,
} from '@sanity/ui'
import {Box, Button, Card, CardTone, Flex, Menu, MenuButton, Spinner, Text} from '@sanity/ui'
import React, {useCallback, useMemo, useRef} from 'react'
import {SchemaType} from '@sanity/types'
import {CopyIcon as DuplicateIcon, EllipsisVerticalIcon, TrashIcon} from '@sanity/icons'
Expand All @@ -27,6 +16,7 @@ import {RowLayout} from '../../layouts/RowLayout'
import {createProtoArrayValue} from '../createProtoArrayValue'
import {InsertMenu} from '../InsertMenu'
import {EditPortal} from '../../../../components/EditPortal'
import {MenuItem} from '../../../../../../ui'

type PreviewItemProps<Item extends ObjectItem> = Omit<ObjectItemProps<Item>, 'renderDefault'>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React, {useCallback, useMemo} from 'react'
import {Box, Button, Flex, Menu, MenuButton, MenuItem} from '@sanity/ui'
import {Box, Button, Flex, Menu, MenuButton} from '@sanity/ui'
import {SchemaType} from '@sanity/types'
import {CopyIcon as DuplicateIcon, EllipsisVerticalIcon, TrashIcon} from '@sanity/icons'
import {FormFieldValidationStatus} from '../../../components/formField'
import {InsertMenu} from '../ArrayOfObjectsInput/InsertMenu'
import {PrimitiveItemProps} from '../../../types/itemProps'
import {RowLayout} from '../layouts/RowLayout'
import {FieldPresence} from '../../../../presence'
import {MenuItem} from '../../../../../ui'
import {getEmptyValue} from './getEmptyValue'

export type DefaultItemProps = Omit<PrimitiveItemProps, 'renderDefault'> & {
Expand Down
12 changes: 2 additions & 10 deletions packages/sanity/src/core/form/inputs/files/FileInput/FileInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,7 @@ import {
UploadState,
} from '@sanity/types'
import {ImageIcon, SearchIcon} from '@sanity/icons'
import {
Box,
Button,
Card,
Menu,
MenuButton,
MenuItem,
ThemeColorToneKey,
ToastParams,
} from '@sanity/ui'
import {Box, Button, Card, Menu, MenuButton, ThemeColorToneKey, ToastParams} from '@sanity/ui'
import {SanityClient} from '@sanity/client'
import {isFileSource} from '@sanity/asset-utils'
import {WithReferencedAsset} from '../../../utils/WithReferencedAsset'
Expand All @@ -38,6 +29,7 @@ import {InputProps, ObjectInputProps} from '../../../types'
import {PatchEvent, setIfMissing, unset} from '../../../patch'
import {MemberField, MemberFieldError, MemberFieldSet} from '../../../members'
import {ImperativeToast} from '../../../../components'
import {MenuItem} from '../../../../../ui'
import {ChangeIndicator} from '../../../../changeIndicators'
import {CardOverlay, FlexContainer} from './styles'
import {FileActionsMenu} from './FileActionsMenu'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
Menu,
MenuButton,
MenuButtonProps,
MenuItem,
Stack,
ToastParams,
} from '@sanity/ui'
Expand Down Expand Up @@ -52,6 +51,7 @@ import {PresenceOverlay} from '../../../../presence'
import {FIXME} from '../../../../FIXME'
import {ImperativeToast} from '../../../../components'
import {ChangeIndicator} from '../../../../changeIndicators'
import {MenuItem} from '../../../../../ui'
import {ImageActionsMenu} from './ImageActionsMenu'
import {ImagePreview} from './ImagePreview'
import {InvalidImageWarning} from './InvalidImageWarning'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, {MouseEventHandler, useCallback} from 'react'

import {UploadIcon, CopyIcon, ResetIcon, DownloadIcon} from '@sanity/icons'
import {Box, MenuItem, MenuDivider, Label, useToast} from '@sanity/ui'
import {Box, MenuDivider, Label, useToast} from '@sanity/ui'
import {MenuItem} from '../../../../../ui'
import {FileInputMenuItem} from './FileInputMenuItem/FileInputMenuItem'

interface Props {
Expand Down Expand Up @@ -40,7 +41,6 @@ export function ActionsMenu(props: Props) {
text="Upload"
data-testid="file-input-upload-button"
disabled={readOnly || !directUploads}
fontSize={2}
/>
{browse}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {MenuItem} from '@sanity/ui'
import styled from 'styled-components'
import {MenuItem} from '../../../../../../ui'

export const FileMenuItem = styled(MenuItem)`
position: relative;
Expand Down
Loading
Loading