-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into custom-target-form
Signed-off-by: Ian Bolton <ibolton@redhat.com>
- Loading branch information
Showing
13 changed files
with
564 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
Oops, something went wrong.