Skip to content

Commit

Permalink
refactor split and flex instances in favor of toolbar components
Browse files Browse the repository at this point in the history
  • Loading branch information
jenny-s51 committed Aug 6, 2024
1 parent 1f38888 commit c9d584d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from 'react';
import {
Button,
Flex,
FlexItem,
MenuToggle,
MenuToggleElement,
Select,
Expand Down Expand Up @@ -227,66 +225,65 @@ const OptionsContextBar: React.FC = observer(() => {
};

return (
<>
<ToolbarItem variant="label">Nodes:</ToolbarItem>
<ToolbarItem>
<TextInput
aria-label="nodes"
type="number"
value={numNodes || ''}
onChange={(_event, val: string) =>
val ? updateValue(parseInt(val), 0, 9999, setNumNodes) : setNumNodes(null)
}
/>
</ToolbarItem>>
<ToolbarItem variant="label">Edges:</ToolbarItem>
<ToolbarItem>
<TextInput
aria-label="edges"
type="number"
value={numEdges === null ? '' : numEdges}
onChange={(_event, val: string) =>
val ? updateValue(parseInt(val), 0, 200, setNumEdges) : setNumEdges(null)
}
/>
</ToolbarItem>
<ToolbarItem variant="label">Groups:</ToolbarItem>
<TextInput
aria-label="groups"
type="number"
value={numGroups === null ? '' : numGroups}
onChange={(_event, val: string) =>
val ? updateValue(parseInt(val), 0, 100, setNumGroups) : setNumGroups(null)
}
/>
</ToolbarItem>
<ToolbarItem variant="label">Nesting Depth:</ToolbarItem>
<TextInput
aria-label="nesting depth"
type="number"
value={nestedLevel === null ? '' : nestedLevel}
onChange={(_event, val: string) =>
val ? updateValue(parseInt(val), 0, 5, setNestedLevel) : setNestedLevel(null)
}
/>
</Flex>
</FlexItem>
<FlexItem>
<Button
variant="link"
isDisabled={numNodes === undefined || numNodes < 1 || numEdges === undefined || numGroups === undefined}
onClick={() => options.setCreationCounts({ numNodes, numEdges, numGroups, nestedLevel })}
>
Apply
</Button>
</FlexItem>
</Flex>
<TextInput
aria-label="nodes"
type="number"
value={numNodes || ''}
onChange={(_event, val: string) =>
val ? updateValue(parseInt(val), 0, 9999, setNumNodes) : setNumNodes(null)
}
/>
</ToolbarItem>
<ToolbarItem variant="label">Edges:</ToolbarItem>
<ToolbarItem>
<TextInput
aria-label="edges"
type="number"
value={numEdges === null ? '' : numEdges}
onChange={(_event, val: string) =>
val ? updateValue(parseInt(val), 0, 200, setNumEdges) : setNumEdges(null)
}
/>
</ToolbarItem>
<ToolbarItem variant="label">Groups:</ToolbarItem>
<ToolbarItem>
<TextInput
aria-label="groups"
type="number"
value={numGroups === null ? '' : numGroups}
onChange={(_event, val: string) =>
val ? updateValue(parseInt(val), 0, 100, setNumGroups) : setNumGroups(null)
}
/>
</ToolbarItem>
<ToolbarItem variant="label">Nesting Depth:</ToolbarItem>
<ToolbarItem>
<TextInput
aria-label="nesting depth"
type="number"
value={nestedLevel === null ? '' : nestedLevel}
onChange={(_event, val: string) =>
val ? updateValue(parseInt(val), 0, 5, setNestedLevel) : setNestedLevel(null)
}
/>
<ToolbarItem>
<Button
variant="link"
isDisabled={numNodes === undefined || numNodes < 1 || numEdges === undefined || numGroups === undefined}
onClick={() => options.setCreationCounts({ numNodes, numEdges, numGroups, nestedLevel })}
>
Apply
</Button>
</ToolbarItem>
</ToolbarItem>
<ToolbarItem>
<Flex gap={{ default: 'gapMd' }}>
{renderNodeOptionsDropdown()}
{renderEdgeOptionsDropdown()}
</Flex>
{renderNodeOptionsDropdown()}
{renderEdgeOptionsDropdown()}
</ToolbarItem>
</>
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,9 @@ export const LayoutsDemo: React.FC = () => {
}, [controller, layout]);

const layoutDropdown = (
<Split>
<SplitItem>
<label className="pf-v6-u-display-inline-block pf-v6-u-mr-md pf-v6-u-mt-sm">Layout</label>
</SplitItem>
<SplitItem>
<>
<ToolbarItem variant="label">Layout</ToolbarItem>
<ToolbarItem>
<Dropdown
toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
<MenuToggle ref={toggleRef} onClick={() => setLayoutDropdownOpen(!layoutDropdownOpen)}>
Expand Down Expand Up @@ -317,8 +315,8 @@ export const LayoutsDemo: React.FC = () => {
</DropdownItem>
</DropdownList>
</Dropdown>
</SplitItem>
</Split>
</ToolbarItem>
</>
);

return (
Expand Down

0 comments on commit c9d584d

Please sign in to comment.