Skip to content
Snippets Groups Projects
Select Git revision
  • ee9562f600d65ed6a9329025c6a9cf782d8f7c17
  • main default protected
  • fix-textinput-label-styling
  • feature/add_tabs
  • v2.9.0
  • v2.8.0
  • v2.7.0
  • v2.6.0
  • v2.5.0
  • v2.4.0
  • v2.3.0
  • v2.2.0
  • v2.1.1
  • v2.1.0
  • v2.0.0
  • v1.10.0
  • v1.9.1
  • v1.9.0
  • v1.8.4
  • v1.8.3
  • v1.8.2
  • v1.8.1
  • v1.8.0
  • v1.7.0
24 results

Toggle.tsx

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Toggle.tsx 1.00 KiB
    import { Dispatch, SetStateAction } from "react";
    import { Switch } from "@nextui-org/react";
    import { disabledCursor } from "./utils/classes.ts";
    
    type ToggleProps = {
      isDisabled?: boolean;
      isSelected: boolean;
      setIsSelected?: Dispatch<SetStateAction<boolean>>;
      label?: string;
    };
    
    const Toggle = ({
      isDisabled = false,
      isSelected,
      setIsSelected,
      label,
    }: ToggleProps) => {
      const selectedClass = isSelected
        ? "group-data-[selected=true]:ml-0 bg-primary"
        : "ml-[11px] bg-grey";
      return (
        <Switch
          isDisabled={isDisabled}
          // Does not support "isRequired": https://github.com/nextui-org/nextui/issues/1610
          isSelected={isSelected}
          onValueChange={setIsSelected}
          color="default"
          classNames={{
            base: disabledCursor(isDisabled),
            thumb: `h-[14px] w-[14px] ${selectedClass}`,
            wrapper:
              "h-[8px] w-[25px] p-0 overflow-visible bg-lightGrey dark:bg-mediumGrey",
          }}
        >
          {label}
        </Switch>
      );
    };
    
    export default Toggle;