Skip to content

Commit

Permalink
🌱 adding some pf5 select wrappers (#1490)
Browse files Browse the repository at this point in the history
effort towards #1242 

pushing a couple new components without any changes to other stuff yet
so ian can use one with something he is working on.

---------

Signed-off-by: gitdallas <dallas.nicol@gmail.com>
  • Loading branch information
gitdallas authored Oct 26, 2023
1 parent ed39248 commit bd5a4b0
Show file tree
Hide file tree
Showing 5 changed files with 543 additions and 112 deletions.
51 changes: 27 additions & 24 deletions client/src/app/components/SimpleSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,32 @@ export const SimpleSelect: React.FC<ISimpleSelectProps> = ({
}) => {
const [isOpen, setIsOpen] = useState(false);
return (
<Select
menuAppendTo="parent" // prevent menu from being clipped by modal edges
maxHeight={200}
placeholderText={placeholderText}
toggleAriaLabel={toggleAriaLabel}
isOpen={isOpen}
onToggle={(_, isOpen) => setIsOpen(isOpen)}
onSelect={(_, selection) => {
onChange(selection);
if (props.variant !== "checkbox") {
setIsOpen(false);
}
}}
selections={value}
{...props}
>
{options.map((option, index) => (
<SelectOption
key={`${index}-${option.toString()}`}
value={option}
{...(typeof option === "object" && (option as OptionWithValue).props)}
/>
))}
</Select>
<>
<Select
menuAppendTo="parent" // prevent menu from being clipped by modal edges
maxHeight={200}
placeholderText={placeholderText}
toggleAriaLabel={toggleAriaLabel}
isOpen={isOpen}
onToggle={(_, isOpen) => setIsOpen(isOpen)}
onSelect={(_, selection) => {
onChange(selection);
if (props.variant !== "checkbox") {
setIsOpen(false);
}
}}
selections={value}
{...props}
>
{options.map((option, index) => (
<SelectOption
key={`${index}-${option.toString()}`}
value={option}
{...(typeof option === "object" &&
(option as OptionWithValue).props)}
/>
))}
</Select>
</>
);
};
59 changes: 59 additions & 0 deletions client/src/app/components/SimpleSelectBasic.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React, { useState } from "react";

import {
Select,
SelectList,
SelectOption,
MenuToggle,
MenuToggleElement,
} from "@patternfly/react-core";

export interface ISimpleSelectBasicProps {
onChange: (selection: string) => void;
options: string[];
value?: string;
placeholderText?: string;
}

export const SimpleSelectBasic: React.FC<ISimpleSelectBasicProps> = ({
onChange,
options,
value,
placeholderText = "Select...",
}) => {
const [isOpen, setIsOpen] = useState(false);

const toggle = (toggleRef: React.Ref<MenuToggleElement>) => (
<MenuToggle
isFullWidth
ref={toggleRef}
onClick={() => {
setIsOpen(!isOpen);
}}
isExpanded={isOpen}
>
{value || placeholderText || ""}
</MenuToggle>
);

return (
<Select
isOpen={isOpen}
toggle={toggle}
onOpenChange={(isOpen) => setIsOpen(isOpen)}
selected={value}
onSelect={(_, selection) => {
onChange(selection as string);
setIsOpen(false);
}}
>
<SelectList>
{options.map((option, index) => (
<SelectOption key={`${index}-${option.toString()}`} value={option}>
{option.toString()}
</SelectOption>
))}
</SelectList>
</Select>
);
};
Loading

0 comments on commit bd5a4b0

Please sign in to comment.