-
Notifications
You must be signed in to change notification settings - Fork 444
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
f1dd4be
commit ba1e200
Showing
10 changed files
with
246 additions
and
122 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
30 changes: 30 additions & 0 deletions
30
packages/sanity/src/tasks/src/tasks/components/form/FormEdit.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,30 @@ | ||
import {type ObjectInputProps} from 'sanity' | ||
import styled from 'styled-components' | ||
|
||
import {type TaskDocument} from '../../types' | ||
import {StatusSelector} from './StatusSelector' | ||
import {Title} from './TitleField' | ||
|
||
const FirstRow = styled.div` | ||
display: flex; | ||
margin-top: 7px; | ||
` | ||
export function FormEdit(props: ObjectInputProps<TaskDocument>) { | ||
const statusField = props.schemaType.fields.find((f) => f.name === 'status') | ||
if (!statusField) { | ||
throw new Error('Status field not found') | ||
} | ||
return ( | ||
<div> | ||
<Title onChange={props.onChange} value={props.value?.title} path={['title']} /> | ||
<FirstRow> | ||
<StatusSelector | ||
value={props.value?.status} | ||
path={['status']} | ||
onChange={props.onChange} | ||
options={statusField.type.options.list} | ||
/> | ||
</FirstRow> | ||
</div> | ||
) | ||
} |
75 changes: 75 additions & 0 deletions
75
packages/sanity/src/tasks/src/tasks/components/form/StatusSelector.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 {CheckmarkCircleIcon, CheckmarkIcon, CircleIcon} from '@sanity/icons' | ||
import {Menu} from '@sanity/ui' | ||
import {type ForwardedRef, forwardRef, type ReactNode} from 'react' | ||
import { | ||
type FormPatch, | ||
isString, | ||
type PatchEvent, | ||
type Path, | ||
set, | ||
type TitledListValue, | ||
} from 'sanity' | ||
|
||
import {Button, MenuButton, MenuItem} from '../../../../../ui-components' | ||
|
||
// TODO: support customizing icons and options. | ||
const OPTION_ICONS: Record<string, ReactNode> = { | ||
closed: <CheckmarkCircleIcon />, | ||
open: <CircleIcon />, | ||
} | ||
|
||
export const StatusMenuButton = forwardRef(function StatusMenuButton( | ||
props: {value: string | undefined; options: TitledListValue<string>[]}, | ||
ref: ForwardedRef<HTMLButtonElement>, | ||
) { | ||
const {value, options} = props | ||
const selectedOption = options.find((option) => option.value === value) | ||
return ( | ||
<Button | ||
{...props} | ||
ref={ref} | ||
tooltipProps={null} | ||
icon={value && OPTION_ICONS[value]} | ||
text={selectedOption?.title || value} | ||
tone="default" | ||
mode="ghost" | ||
/> | ||
) | ||
}) | ||
|
||
interface StatusSelectorProps { | ||
value: string | undefined | ||
path: Path | ||
options: TitledListValue<string>[] | ||
onChange: (patch: FormPatch | PatchEvent | FormPatch[]) => void | ||
} | ||
|
||
export function StatusSelector(props: StatusSelectorProps) { | ||
const {value, onChange, options, path} = props | ||
return ( | ||
<MenuButton | ||
button={<StatusMenuButton value={value} options={options} />} | ||
id={`reference-menuButton`} | ||
menu={ | ||
<Menu> | ||
{options.map((option) => { | ||
const isSelected = value === option.value | ||
return ( | ||
<MenuItem | ||
key={option.title} | ||
icon={ | ||
isString(option.value) ? OPTION_ICONS[option.value] || CircleIcon : CircleIcon | ||
} | ||
text={option.title || option.value} | ||
pressed={isSelected} | ||
iconRight={isSelected && <CheckmarkIcon />} | ||
// eslint-disable-next-line react/jsx-no-bind | ||
onClick={() => onChange(set(option.value, path))} | ||
/> | ||
) | ||
})} | ||
</Menu> | ||
} | ||
/> | ||
) | ||
} |
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
Oops, something went wrong.