Skip to content

Commit bdcab1b

Browse files
committed
feat(json-crdt-peritext-ui): 🎸 improve slice list display
1 parent 50b1f53 commit bdcab1b

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/json-crdt-peritext-ui/plugins/toolbar/cursor/caret/CaretBottomOverlay.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import * as React from 'react';
2-
import {ContextPane} from 'nice-ui/lib/4-card/ContextMenu';
2+
import {ContextPane, ContextItem, ContextSep} from 'nice-ui/lib/4-card/ContextMenu';
33
import {useToolbarPlugin} from '../../context';
4-
import type {SliceRegistryEntry} from '../../../../../json-crdt-extensions/peritext/registry/SliceRegistryEntry';
54
import type {Inline, Peritext, Slice} from '../../../../../json-crdt-extensions';
65
import type {CaretViewProps} from '../../../../web/react/cursor/CaretView';
6+
import type {ToolBarSliceRegistryEntry} from '../../types';
77

8-
class FormattingItem {
8+
class ToolbarSlice {
99
public constructor(
1010
public readonly slice: Slice<string>,
11-
public readonly def: SliceRegistryEntry,
11+
public readonly def: ToolBarSliceRegistryEntry,
1212
) {}
1313
}
1414

1515
const getConfigurableFormattingItems = (txt: Peritext, inline?: Inline) => {
1616
const slices = inline?.p1.layers;
17-
const res: FormattingItem[] = [];
17+
const res: ToolbarSlice[] = [];
1818
if (!slices) return res;
1919
const registry = txt.editor.getRegistry();
2020
for (const slice of slices) {
@@ -24,7 +24,7 @@ const getConfigurableFormattingItems = (txt: Peritext, inline?: Inline) => {
2424
if (!def) continue;
2525
const isConfigurable = !!def.schema;
2626
if (!isConfigurable) continue;
27-
res.push(new FormattingItem(slice, def));
27+
res.push(new ToolbarSlice(slice, def));
2828
}
2929
return res;
3030
};
@@ -42,10 +42,17 @@ export const CaretBottomOverlay: React.FC<CaretBottomOverlayProps> = (props) =>
4242
if (!formatting.length) return;
4343

4444
return (
45-
<ContextPane>
46-
{formatting.map(({slice, def}, index) => (
47-
<div>{slice.type}, {def.name}</div>
48-
))}
45+
<ContextPane style={{minWidth: 'calc(max(220px, min(360px, 80vw)))'}}>
46+
<ContextSep />
47+
{formatting.map(({slice, def}, index) => {
48+
const menu = def.data().menu;
49+
return (
50+
<ContextItem inset icon={menu?.icon?.()} right={<div>right</div>} onClick={() => {}}>
51+
{def.data().menu?.name ?? def.name}
52+
</ContextItem>
53+
);
54+
})}
55+
<ContextSep />
4956
</ContextPane>
5057
);
5158
};

0 commit comments

Comments
 (0)