Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 adding some pf5 select wrappers #1490

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading