{"version":3,"file":"Password.cjs","names":[],"sources":["../../../../../src/components/Form/Controls/Password/Password.tsx"],"sourcesContent":["/*\nCopyright 2023 New Vector Ltd.\n\nSPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial\nPlease see LICENSE files in the repository root for full details.\n*/\nimport React, {\n  type ComponentRef,\n  forwardRef,\n  type ComponentProps,\n  useReducer,\n} from \"react\";\nimport { Control } from \"@radix-ui/react-form\";\n\nimport { ActionInput } from \"../Action\";\n\nimport VisibilityOn from \"@vector-im/compound-design-tokens/assets/web/icons/visibility-on\";\nimport VisibilityOff from \"@vector-im/compound-design-tokens/assets/web/icons/visibility-off\";\n\nconst showState = {\n  isHidden: true,\n  icon: VisibilityOff,\n  label: \"Show\",\n  type: \"password\",\n};\n\nconst hideState = {\n  isHidden: false,\n  icon: VisibilityOn,\n  label: \"Hide\",\n  type: \"text\",\n};\n\ntype Props = Omit<\n  ComponentProps<typeof ActionInput>,\n  \"type\" | \"actionLabel\" | \"onActionClick\" | \"Icon\"\n>;\n\n/**\n * A password input with a toggle to show/hide the password.\n *\n * Standalone input to be used outside of Radix forms.\n */\nexport const PasswordInput = forwardRef<\n  ComponentRef<typeof ActionInput>,\n  Props\n>(function PasswordControl(props, ref) {\n  const [{ icon, label, type }, togglePasswordVisibility] = useReducer(\n    (state) => (!state.isHidden ? showState : hideState),\n    showState,\n  );\n\n  return (\n    <ActionInput\n      ref={ref}\n      {...props}\n      Icon={icon}\n      // TODO: Replace with a function that deal with i18n of those values\n      actionLabel={label}\n      onActionClick={() => togglePasswordVisibility()}\n      type={type}\n    />\n  );\n});\n\n/**\n * A password input with a toggle to show/hide the password.\n *\n * Control to be used in a Radix form.\n */\nexport const PasswordControl = forwardRef<\n  ComponentRef<typeof PasswordInput>,\n  ComponentProps<typeof PasswordInput>\n>(function PasswordControl(props, ref) {\n  return (\n    <Control asChild>\n      <PasswordInput ref={ref} {...props} />\n    </Control>\n  );\n});\n"],"mappings":";;;;;;;;;;;AAmBA,IAAM,YAAY;CAChB,UAAU;CACV,MAAM,kEAAA;CACN,OAAO;CACP,MAAM;CACP;AAED,IAAM,YAAY;CAChB,UAAU;CACV,MAAM,iEAAA;CACN,OAAO;CACP,MAAM;CACP;;;;;;AAYD,IAAa,iBAAA,GAAA,MAAA,YAGX,SAAS,gBAAgB,OAAO,KAAK;CACrC,MAAM,CAAC,EAAE,MAAM,OAAO,QAAQ,6BAAA,GAAA,MAAA,aAC3B,UAAW,CAAC,MAAM,WAAW,YAAY,WAC1C,UACD;AAED,QACE,iBAAA,GAAA,kBAAA,KAAC,eAAA,aAAD;EACO;EACL,GAAI;EACJ,MAAM;EAEN,aAAa;EACb,qBAAqB,0BAA0B;EACzC;EACN,CAAA;EAEJ;;;;;;AAOF,IAAa,mBAAA,GAAA,MAAA,YAGX,SAAS,gBAAgB,OAAO,KAAK;AACrC,QACE,iBAAA,GAAA,kBAAA,KAAC,qBAAA,SAAD;EAAS,SAAA;YACP,iBAAA,GAAA,kBAAA,KAAC,eAAD;GAAoB;GAAK,GAAI;GAAS,CAAA;EAC9B,CAAA;EAEZ"}