mirror of
https://github.com/docmost/docmost.git
synced 2026-05-21 01:04:39 +08:00
refactor(base): hoist NavItem type and drop IIFE in select cell
This commit is contained in:
@@ -17,6 +17,10 @@ const CHOICE_COLORS = [
|
|||||||
"blue", "cyan", "teal", "green", "lime", "yellow", "orange",
|
"blue", "cyan", "teal", "green", "lime", "yellow", "orange",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
type NavItem =
|
||||||
|
| { kind: "choice"; choice: Choice }
|
||||||
|
| { kind: "add" };
|
||||||
|
|
||||||
type CellSelectProps = {
|
type CellSelectProps = {
|
||||||
value: unknown;
|
value: unknown;
|
||||||
property: IBaseProperty;
|
property: IBaseProperty;
|
||||||
@@ -77,10 +81,6 @@ export function CellSelect({
|
|||||||
[choices.length],
|
[choices.length],
|
||||||
);
|
);
|
||||||
|
|
||||||
type NavItem =
|
|
||||||
| { kind: "choice"; choice: Choice }
|
|
||||||
| { kind: "add" };
|
|
||||||
|
|
||||||
const navItems = useMemo<NavItem[]>(
|
const navItems = useMemo<NavItem[]>(
|
||||||
() => [
|
() => [
|
||||||
...filteredChoices.map((c) => ({ kind: "choice" as const, choice: c })),
|
...filteredChoices.map((c) => ({ kind: "choice" as const, choice: c })),
|
||||||
@@ -138,6 +138,7 @@ export function CellSelect({
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
|
const addOptionIdx = filteredChoices.length;
|
||||||
return (
|
return (
|
||||||
<Popover
|
<Popover
|
||||||
opened
|
opened
|
||||||
@@ -198,31 +199,28 @@ export function CellSelect({
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
{showAddOption && (() => {
|
{showAddOption && (
|
||||||
const idx = filteredChoices.length;
|
<div
|
||||||
return (
|
ref={setOptionRef(addOptionIdx)}
|
||||||
<div
|
className={clsx(
|
||||||
ref={setOptionRef(idx)}
|
cellClasses.addOptionRow,
|
||||||
className={clsx(
|
addOptionIdx === activeIndex && cellClasses.selectOptionKeyboardActive,
|
||||||
cellClasses.addOptionRow,
|
)}
|
||||||
idx === activeIndex && cellClasses.selectOptionKeyboardActive,
|
onMouseEnter={() => setActiveIndex(addOptionIdx)}
|
||||||
)}
|
onMouseDown={(e) => {
|
||||||
onMouseEnter={() => setActiveIndex(idx)}
|
e.preventDefault();
|
||||||
onMouseDown={(e) => {
|
}}
|
||||||
e.preventDefault();
|
onClick={handleAddOption}
|
||||||
}}
|
>
|
||||||
onClick={handleAddOption}
|
<span className={cellClasses.addOptionLabel}>Add option:</span>
|
||||||
|
<span
|
||||||
|
className={cellClasses.badge}
|
||||||
|
style={choiceColor(addOptionColor)}
|
||||||
>
|
>
|
||||||
<span className={cellClasses.addOptionLabel}>Add option:</span>
|
{trimmedSearch}
|
||||||
<span
|
</span>
|
||||||
className={cellClasses.badge}
|
</div>
|
||||||
style={choiceColor(addOptionColor)}
|
)}
|
||||||
>
|
|
||||||
{trimmedSearch}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})()}
|
|
||||||
</div>
|
</div>
|
||||||
</Popover.Dropdown>
|
</Popover.Dropdown>
|
||||||
</Popover>
|
</Popover>
|
||||||
|
|||||||
Reference in New Issue
Block a user