Skip to content
Snippets Groups Projects
Select Git revision
  • c820653c1aa8ec814ce88e796035071cbf90bae1
  • MCCS-163 default
  • main
  • sar-277-update-docs-with-examples-for-lrc
  • st-946-automate
  • sar_302-log-fix
  • sar-287_subarray_commands_to_lrc
  • sar_302-POC_await_sub_device_state
  • sat_302_fix_pipelines
  • sar-286_lrc_one_subarry_command
  • sar-286_lrc_improvements
  • sar-288-async-controller
  • sar-276-combine-tango-queue
  • sar-255_remove_nexus_reference
  • sar-275-add-LRC
  • sar-273-add-lrc-attributes
  • sar-272
  • sp-1106-marvin-1230525148-ska-tango-base
  • sp-1106-marvin-813091765-ska-tango-base
  • sar-255/Publish-package-to-CAR
  • mccs-661-device-under-test-fixture
  • mccs-659-pep257-docstring-linting
  • 0.11.3
  • 0.11.2
  • 0.11.1
  • 0.11.0
  • 0.10.1
  • 0.10.0
  • 0.9.1
  • 0.9.0
  • 0.8.1
  • 0.8.0
  • 0.7.2
  • 0.7.1
  • 0.7.0
  • 0.6.6
  • 0.6.5
  • 0.6.4
  • 0.6.3
  • 0.6.2
  • 0.6.1
  • 0.6.0
42 results

setup.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Dropdown.tsx 1.90 KiB
    import { Autocomplete, AutocompleteItem } from "@nextui-org/react";
    import { Dispatch, SetStateAction } from "react";
    import { clsx } from "clsx";
    import { baseInputClassNames } from "./utils/baseComponents.tsx";
    import Icon from "./Icon.tsx";
    import { textColor } from "./utils/classes.ts";
    
    type DropdownProps = {
      isRequired?: boolean;
      label?: string;
      valueOptions: { value: string; label: string }[];
      value?: string;
      onValueChange: Dispatch<SetStateAction<string | undefined>>;
    };
    
    const Dropdown = ({
      isRequired = false,
      label,
      valueOptions,
      value,
      onValueChange,
    }: DropdownProps) => {
      const focusClass =
        "data-[focus=true]:bg-lightGrey/50 dark:data-[focus=true]:bg-grey/50";
      const hoverCLass =
        "data-[selected=true]:!bg-primary hover:!bg-lightGrey dark:hover:!bg-grey";
      return (
        <Autocomplete
          isRequired={isRequired}
          label={label}
          selectedKey={value}
          onSelectionChange={(key) => onValueChange(key as string)}
          labelPlacement="outside"
          placeholder=" " // so the label stays outside
          disableAnimation
          disableSelectorIconRotation
          inputProps={{
            classNames: baseInputClassNames(false),
            variant: "bordered",
            isRequired: isRequired,
          }} // use the same props as BaseInput
          selectorIcon={<Icon name="dropdown" />}
          isClearable={false} // so the "cross" button does not show
          classNames={{
            selectorButton: clsx(
              textColor("body"),
              "data-[hover=true]:bg-default opacity-100"
            ),
            popoverContent: "rounded-[4px]",
          }}
        >
          {valueOptions.map((option) => {
            return (
              <AutocompleteItem
                key={option.value}
                value={option.value}
                className={clsx(focusClass, hoverCLass)}
              >
                {option.label}
              </AutocompleteItem>
            );
          })}
        </Autocomplete>
      );
    };
    
    export default Dropdown;