Skip to content

Commit 90a96d8

Browse files
committed
fix(toolbar-demo): properly handle node positioning in sections
Fix node filtering logic to correctly distribute nodes into left, center, and right sections based on their position property. Previous behavior: - Filtered out nodes with position='right' - Put everything else in left section - Ignored center positioning entirely New behavior: - Left section: nodes with no position or position='left' - Center section: nodes with position='center' - Right section: nodes with position='right' Also extracted renderNode helper to reduce duplication and improve code readability.
1 parent 63724bc commit 90a96d8

File tree

1 file changed

+42
-35
lines changed
  • examples/next/toolbar-demo/example-app/app/components

1 file changed

+42
-35
lines changed

examples/next/toolbar-demo/example-app/app/components/Toolbar.tsx

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,55 @@ export function Toolbar() {
1717
return unsubscribe;
1818
}, []);
1919

20-
return (
21-
<div className={`hwp-toolbar hwp-toolbar-${position}`}>
22-
<div className="hwp-toolbar-section hwp-toolbar-left">
23-
{nodes
24-
.filter((node) => node.position !== 'right')
25-
.map((node) => {
26-
const label = typeof node.label === 'function' ? node.label() : node.label;
20+
const leftNodes = nodes.filter((node) => !node.position || node.position === 'left');
21+
const centerNodes = nodes.filter((node) => node.position === 'center');
22+
const rightNodes = nodes.filter((node) => node.position === 'right');
23+
24+
const renderNode = (node: any) => {
25+
const label = typeof node.label === 'function' ? node.label() : node.label;
26+
27+
if (node.type === 'divider') {
28+
return <div key={node.id} className="hwp-toolbar-divider" />;
29+
}
2730

28-
if (node.type === 'divider') {
29-
return <div key={node.id} className="hwp-toolbar-divider" />;
30-
}
31+
if (node.type === 'link' && node.href) {
32+
return (
33+
<a
34+
key={node.id}
35+
href={node.href}
36+
target={node.target}
37+
className="hwp-toolbar-link"
38+
>
39+
{label}
40+
</a>
41+
);
42+
}
3143

32-
if (node.type === 'link' && node.href) {
33-
return (
34-
<a
35-
key={node.id}
36-
href={node.href}
37-
target={node.target}
38-
className="hwp-toolbar-link"
39-
>
40-
{label}
41-
</a>
42-
);
43-
}
44+
return (
45+
<button
46+
key={node.id}
47+
onClick={node.onClick}
48+
className={`hwp-toolbar-button ${
49+
node.id === 'preview' && state.preview ? 'hwp-toolbar-button-active' : ''
50+
}`}
51+
>
52+
{label}
53+
</button>
54+
);
55+
};
4456

45-
return (
46-
<button
47-
key={node.id}
48-
onClick={node.onClick}
49-
className={`hwp-toolbar-button ${
50-
node.id === 'preview' && state.preview ? 'hwp-toolbar-button-active' : ''
51-
}`}
52-
>
53-
{label}
54-
</button>
55-
);
56-
})}
57+
return (
58+
<div className={`hwp-toolbar hwp-toolbar-${position}`}>
59+
<div className="hwp-toolbar-section hwp-toolbar-left">
60+
{leftNodes.map(renderNode)}
5761
</div>
5862

59-
<div className="hwp-toolbar-section hwp-toolbar-center"></div>
63+
<div className="hwp-toolbar-section hwp-toolbar-center">
64+
{centerNodes.map(renderNode)}
65+
</div>
6066

6167
<div className="hwp-toolbar-section hwp-toolbar-right">
68+
{rightNodes.map(renderNode)}
6269
{state.user && (
6370
<button
6471
className="hwp-toolbar-button"

0 commit comments

Comments
 (0)