{"version":3,"sources":["../../src/components/search-bar.tsx"],"sourcesContent":["import React, {\n  FunctionComponent,\n  ComponentProps,\n  useContext,\n  forwardRef,\n} from \"react\";\nimport { Command } from \"cmdk\";\nimport { Button, ButtonProps } from \"./button\";\nimport { CrossIcon, SearchIcon } from \"../icons\";\nimport { clx } from \"../utils\";\nimport { cva } from \"class-variance-authority\";\n\ntype SearchBarSize = \"small\" | \"medium\" | \"large\";\nconst DEFAULT_SIZE: SearchBarSize = \"medium\";\n\ntype Context = {\n  size: SearchBarSize;\n};\n\nconst SearchBarContext = React.createContext<Context>({\n  size: DEFAULT_SIZE,\n});\n\ninterface SearchBarProps extends ComponentProps<typeof Command> {\n  size?: SearchBarSize;\n}\n\n/**\n * Uses cmdk's Command API.\n * @see https://github.com/pacocoursey/cmdk#command-cmdk-root\n */\nconst SearchBar: FunctionComponent<SearchBarProps> = forwardRef(\n  ({ children, className, size = DEFAULT_SIZE, ...props }, ref) => {\n    return (\n      <SearchBarContext.Provider value={{ size }}>\n        <Command\n          ref={ref}\n          className={clx(\"relative z-0\", className)}\n          shouldFilter={false}\n          {...props}\n        >\n          {children}\n        </Command>\n      </SearchBarContext.Provider>\n    );\n  },\n);\n\nconst search_bar_input_container_cva = cva(\n  [\n    \"flex items-center bg-bg-white border border-otl-gray-200 shadow-button\",\n    \"has-[input:focus]:ring has-[input:focus]:ring-otl-primary-200 has-[input:focus]:border-otl-primary-300\",\n  ],\n  {\n    variants: {\n      size: {\n        small: \"pl-[10px] pr-2 py-[6px] gap-2 rounded-sm text-sm\",\n        medium: \"px-[12px] pr-2.5 py-[7px] gap-2 rounded-md text-md\",\n        large: \"pl-[18px] pr-1.5 py-[6px] gap-2.5 rounded-full text-md\",\n      },\n    },\n    defaultVariants: {\n      size: DEFAULT_SIZE,\n    },\n  },\n);\nexport const SearchBarInputContainer: FunctionComponent<\n  ComponentProps<\"div\">\n> = ({ className, ...props }) => {\n  const { size } = useContext(SearchBarContext);\n  return (\n    <div\n      className={search_bar_input_container_cva({ size, className })}\n      {...props}\n    />\n  );\n};\n\n/**\n * Uses cmdk's Command.Input API.\n * @see https://github.com/pacocoursey/cmdk#input-cmdk-input\n */\nexport const SearchBarInput: FunctionComponent<\n  ComponentProps<typeof Command.Input>\n> = forwardRef(({ className, ...props }, ref) => {\n  return (\n    <Command.Input\n      ref={ref}\n      className={clx(\n        \"text-txt-black-900 placeholder:text-txt-black-500 flex-1 bg-transparent focus:outline-none\",\n        className,\n      )}\n      asChild\n      {...props}\n    >\n      <input\n        aria-controls=\"search-input\"\n        // The hardcoded aria-controls here is a temporary fix such that it matches the id of SearchBarResults. It is related to this error (https://github.com/dequelabs/axe-core/issues/4172)\n      />\n    </Command.Input>\n  );\n});\n\nexport const SearchBarSearchButton: FunctionComponent<ButtonProps> = ({\n  className,\n  ...props\n}) => {\n  const { size } = useContext(SearchBarContext);\n  if (size === \"large\") {\n    return (\n      <Button\n        className={clx(\n          \"border-primary-600 from-primary-400 to-primary-600 rounded-full border bg-gradient-to-b p-1\",\n          className,\n        )}\n        {...props}\n      >\n        <SearchIcon className=\"text-white\" />\n      </Button>\n    );\n  }\n  return (\n    <Button\n      variant=\"default-ghost\"\n      className={clx(\"p-0\", className)}\n      {...props}\n    >\n      <SearchIcon className=\"text-txt-black-500\" />\n    </Button>\n  );\n};\n\nexport const SearchBarClearButton: FunctionComponent<ButtonProps> = ({\n  className,\n  ...props\n}) => {\n  return (\n    <Button\n      variant=\"default-ghost\"\n      className={clx(\"p-0\", className)}\n      {...props}\n    >\n      <CrossIcon className=\"text-txt-black-500\" />\n    </Button>\n  );\n};\n\nexport const SearchBarHint: FunctionComponent<ComponentProps<\"div\">> = ({\n  className,\n  ...props\n}) => {\n  return (\n    <div\n      className={clx(\n        \"text-txt-black-500 flex items-center gap-1 text-sm\",\n        className,\n      )}\n      {...props}\n    />\n  );\n};\n\nconst search_bar_results_dropdown_cva = cva(\n  [\n    \"-z-10 bg-bg-white absolute w-full border border-t-0 border-otl-gray-200 shadow px-[6px] py-[8px] shadow-context-menu\",\n    \"before:bg-bg-white before:-left-px before:-right-px before:-top-4 before:border-x before:border-otl-gray-200  before:h-4 before:absolute\",\n  ],\n  {\n    variants: {\n      size: {\n        small: \"rounded-b-sm\",\n        medium: \"rounded-b-md\",\n        large: \"rounded-b-2xl\",\n      },\n    },\n    defaultVariants: {\n      size: DEFAULT_SIZE,\n    },\n  },\n);\nexport const SearchBarResults: FunctionComponent<\n  ComponentProps<\"div\"> & {\n    open: boolean;\n  }\n> = ({ className, open, ...props }) => {\n  const { size } = useContext(SearchBarContext);\n  return (\n    <div\n      className={clx(\n        search_bar_results_dropdown_cva({ size, className }),\n        !open && \"hidden\",\n      )}\n      // The hardcoded id here is a temporary fix such that it matches the value of aria-controls props of SearchBarInput. It is related to this error (https://github.com/dequelabs/axe-core/issues/4172)\n      {...props}\n      id=\"search-input\"\n    />\n  );\n};\n\n/**\n * Uses cmdk's Command.List API.\n * @see https://github.com/pacocoursey/cmdk#list-cmdk-list\n */\nexport const SearchBarResultsList: FunctionComponent<\n  ComponentProps<typeof Command.List>\n> = ({ children, ...props }) => {\n  return (\n    <Command.List {...props}>\n      {/* We include a hidden item to prevent cmdk from focusing on the first item automatically. */}\n      <Command.Item className=\"hidden\">--</Command.Item>\n      {children}\n    </Command.List>\n  );\n};\n\n/**\n * Uses cmdk's Command.Group API.\n * @see https://github.com/pacocoursey/cmdk#group-cmdk-group-hidden\n */\nexport const SearchBarResultsGroup: FunctionComponent<\n  ComponentProps<typeof Command.Group>\n> = ({ className, ...props }) => {\n  return (\n    <Command.Group\n      className={clx(\n        \"my-2 text-sm first:mt-0 last:mt-0\",\n        \"[&_[cmdk-group-heading]]:text-txt-black-500 [&_[cmdk-group-heading]]:mb-1 [&_[cmdk-group-heading]]:ml-3 [&_[cmdk-group-heading]]:font-medium\",\n        className,\n      )}\n      {...props}\n    />\n  );\n};\n\n/**\n * Uses cmdk's Command.Item API.\n * @see https://github.com/pacocoursey/cmdk#item-cmdk-item-data-disabled-data-selected\n */\nexport const SearchBarResultsItem: FunctionComponent<\n  ComponentProps<typeof Command.Item>\n> = ({ className, ...props }) => {\n  return (\n    <Command.Item\n      className={clx(\n        \"data-[selected=true]:bg-bg-washed text-txt-black-900 flex cursor-pointer items-center gap-2 rounded px-3 py-2\",\n        className,\n      )}\n      {...props}\n    />\n  );\n};\n\nexport { SearchBar };\n"],"mappings":"+eAAA,OAAOA,GAGL,cAAAC,EACA,cAAAC,MACK,QACP,OAAS,WAAAC,MAAe,OAIxB,OAAS,OAAAC,MAAW,2BAyBZ,cAAAC,EA4KJ,QAAAC,MA5KI,oBAtBR,IAAMC,EAA8B,SAM9BC,EAAmBC,EAAM,cAAuB,CACpD,KAAMF,CACR,CAAC,EAUKG,EAA+CC,EACnD,CAACC,EAAwDC,IAAQ,CAAhE,IAAAC,EAAAF,EAAE,UAAAG,EAAU,UAAAC,EAAW,KAAAC,EAAOV,CAhCjC,EAgCGO,EAA+CI,EAAAC,EAA/CL,EAA+C,CAA7C,WAAU,YAAW,SACtB,OACET,EAACG,EAAiB,SAAjB,CAA0B,MAAO,CAAE,KAAAS,CAAK,EACvC,SAAAZ,EAACe,EAAAC,EAAAC,EAAA,CACC,IAAKT,EACL,UAAWU,EAAI,eAAgBP,CAAS,EACxC,aAAc,IACVE,GAJL,CAME,SAAAH,GACH,EACF,CAEJ,CACF,EAEMS,EAAiCC,EACrC,CACE,yEACA,wGACF,EACA,CACE,SAAU,CACR,KAAM,CACJ,MAAO,mDACP,OAAQ,qDACR,MAAO,wDACT,CACF,EACA,gBAAiB,CACf,KAAMlB,CACR,CACF,CACF,EACamB,EAERd,GAA4B,CAA5B,IAAAE,EAAAF,EAAE,WAAAI,CApEP,EAoEKF,EAAgBI,EAAAC,EAAhBL,EAAgB,CAAd,cACL,GAAM,CAAE,KAAAG,CAAK,EAAIU,EAAWnB,CAAgB,EAC5C,OACEH,EAAC,MAAAiB,EAAA,CACC,UAAWE,EAA+B,CAAE,KAAAP,EAAM,UAAAD,C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CACF,GACIE,EACN,CAEJ,EAEMiB,EAAkCV,EACtC,CACE,uHACA,0IACF,EACA,CACE,SAAU,CACR,KAAM,CACJ,MAAO,eACP,OAAQ,eACR,MAAO,eACT,CACF,EACA,gBAAiB,CACf,KAAMlB,CACR,CACF,CACF,EACa6B,EAIRxB,GAAkC,CAAlC,IAAAE,EAAAF,EAAE,WAAAI,EAAW,KAAAqB,CAxLlB,EAwLKvB,EAAsBI,EAAAC,EAAtBL,EAAsB,CAApB,YAAW,SAChB,GAAM,CAAE,KAAAG,CAAK,EAAIU,EAAWnB,CAAgB,EAC5C,OACEH,EAAC,MAAAgB,EAAAC,EAAA,CACC,UAAWC,EACTY,EAAgC,CAAE,KAAAlB,EAAM,UAAAD,CAAU,CAAC,EACnD,CAACqB,GAAQ,QACX,GAEInB,GANL,CAOC,GAAG,gBACL,CAEJ,EAMaoB,EAER1B,GAA2B,CAA3B,IAAAE,EAAAF,EAAE,UAAAG,CA7MP,EA6MKD,EAAeI,EAAAC,EAAfL,EAAe,CAAb,aACL,OACER,EAACc,EAAQ,KAARC,EAAAC,EAAA,GAAiBJ,GAAjB,CAEC,UAAAb,EAACe,EAAQ,KAAR,CAAa,UAAU,SAAS,cAAE,EAClCL,IACH,CAEJ,EAMawB,EAER3B,GAA4B,CAA5B,IAAAE,EAAAF,EAAE,WAAAI,CA7NP,EA6NKF,EAAgBI,EAAAC,EAAhBL,EAAgB,CAAd,cACL,OACET,EAACe,EAAQ,MAARE,EAAA,CACC,UAAWC,EACT,oCACA,+IACAP,CACF,GACIE,EACN,CAEJ,EAMasB,EAER5B,GAA4B,CAA5B,IAAAE,EAAAF,EAAE,WAAAI,CAhPP,EAgPKF,EAAgBI,EAAAC,EAAhBL,EAAgB,CAAd,cACL,OACET,EAACe,EAAQ,KAARE,EAAA,CACC,UAAWC,EACT,gHACAP,CACF,GACIE,EACN,CAEJ","names":["React","useContext","forwardRef","Command","cva","jsx","jsxs","DEFAULT_SIZE","SearchBarContext","React","SearchBar","forwardRef","_a","ref","_b","children","className","size","props","__objRest","Command","__spreadProps","__spreadValues","clx","search_bar_input_container_cva","cva","SearchBarInputContainer","useContext","SearchBarInput","SearchBarSearchButton","Button","SearchIcon","SearchBarClearButton","CrossIcon","SearchBarHint","search_bar_results_dropdown_cva","SearchBarResults","open","SearchBarResultsList","SearchBarResultsGroup","SearchBarResultsItem"]}