{"version":3,"file":"SecretInput.mjs","sources":["../../../../src/components/SecretInput/SecretInput.tsx"],"sourcesContent":["import { useState } from 'react';\n\nimport { t } from '@grafana/i18n';\n\nimport { Button } from '../Button/Button';\nimport { IconButton } from '../IconButton/IconButton';\nimport { Input } from '../Input/Input';\nimport { Stack } from '../Layout/Stack/Stack';\n\ntype BaseProps = React.ComponentProps<typeof Input> & {\n  /** TRUE if the secret was already configured. (It is needed as often the backend doesn't send back the actual secret, only the information that it was configured) */\n  isConfigured: boolean;\n  /** Called when the user clicks on the \"Reset\" button in order to clear the secret */\n  onReset: () => void;\n};\n\ntype RevealableProps = {\n  /**\n   * Shows an eye icon button that toggles the secret between masked and plain text.\n   * The toggle occupies the input's suffix slot, so `suffix` cannot be used together with it.\n   */\n  revealable: true;\n  suffix?: never;\n};\n\ntype NonRevealableProps = {\n  revealable?: false;\n};\n\nexport type Props = BaseProps & (RevealableProps | NonRevealableProps);\n\nexport const CONFIGURED_TEXT = 'configured';\nexport const RESET_BUTTON_TEXT = 'Reset';\n\n/**\n * Used for secret/password input.\n *\n * https://developers.grafana.com/ui/latest/index.html?path=/docs/inputs-secretinput--docs\n */\nexport const SecretInput = ({ isConfigured, onReset, revealable, ...props }: Props) => {\n  const [visible, setVisible] = useState(false);\n  const toggleLabel = visible\n    ? t('grafana-ui.secret-input.hide', 'Hide secret')\n    : t('grafana-ui.secret-input.show', 'Show secret');\n\n  return (\n    <Stack>\n      {!isConfigured && (\n        <Input\n          {...props}\n          type={revealable && visible ? 'text' : 'password'}\n          suffix={\n            // While loading, leave the suffix slot empty so Input's built-in spinner takes over.\n            revealable && !props.loading ? (\n              <IconButton\n                name={visible ? 'eye-slash' : 'eye'}\n                aria-controls={props.id}\n                role=\"switch\"\n                aria-checked={visible}\n                onClick={() => setVisible(!visible)}\n                tooltip={toggleLabel}\n                size=\"sm\"\n              />\n            ) : (\n              props.suffix\n            )\n          }\n        />\n      )}\n      {isConfigured && (\n        <>\n          <Input {...props} type=\"text\" disabled={true} value={CONFIGURED_TEXT} />\n          <Button onClick={onReset} variant=\"secondary\">\n            {RESET_BUTTON_TEXT}\n          </Button>\n        </>\n      )}\n    </Stack>\n  );\n};\n"],"names":[],"mappings":";;;;;;;;;AA+BO,MAAM,eAAA,GAAkB;AACxB,MAAM,iBAAA,GAAoB;AAO1B,MAAM,WAAA,GAAc,CAAC,EAAE,YAAA,EAAc,SAAS,UAAA,EAAY,GAAG,OAAM,KAAa;AACrF,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAI,SAAS,KAAK,CAAA;AAC5C,EAAA,MAAM,WAAA,GAAc,UAChB,CAAA,CAAE,8BAAA,EAAgC,aAAa,CAAA,GAC/C,CAAA,CAAE,gCAAgC,aAAa,CAAA;AAEnD,EAAA,4BACG,KAAA,EAAA,EACE,QAAA,EAAA;AAAA,IAAA,CAAC,YAAA,oBACA,GAAA;AAAA,MAAC,KAAA;AAAA,MAAA;AAAA,QACE,GAAG,KAAA;AAAA,QACJ,IAAA,EAAM,UAAA,IAAc,OAAA,GAAU,MAAA,GAAS,UAAA;AAAA,QACvC,MAAA;AAAA;AAAA,UAEE,UAAA,IAAc,CAAC,KAAA,CAAM,OAAA,mBACnB,GAAA;AAAA,YAAC,UAAA;AAAA,YAAA;AAAA,cACC,IAAA,EAAM,UAAU,WAAA,GAAc,KAAA;AAAA,cAC9B,iBAAe,KAAA,CAAM,EAAA;AAAA,cACrB,IAAA,EAAK,QAAA;AAAA,cACL,cAAA,EAAc,OAAA;AAAA,cACd,OAAA,EAAS,MAAM,UAAA,CAAW,CAAC,OAAO,CAAA;AAAA,cAClC,OAAA,EAAS,WAAA;AAAA,cACT,IAAA,EAAK;AAAA;AAAA,cAGP,KAAA,CAAM;AAAA;AAAA;AAAA,KAGZ;AAAA,IAED,gCACC,IAAA,CAAA,QAAA,EAAA,EACE,QAAA,EAAA;AAAA,sBAAA,GAAA,CAAC,KAAA,EAAA,EAAO,GAAG,KAAA,EAAO,IAAA,EAAK,QAAO,QAAA,EAAU,IAAA,EAAM,OAAO,eAAA,EAAiB,CAAA;AAAA,0BACrE,MAAA,EAAA,EAAO,OAAA,EAAS,OAAA,EAAS,OAAA,EAAQ,aAC/B,QAAA,EAAA,iBAAA,EACH;AAAA,KAAA,EACF;AAAA,GAAA,EAEJ,CAAA;AAEJ;;;;"}