@grafana/ui
Version:
Grafana Components Library
1 lines • 3.03 kB
Source Map (JSON)
{"version":3,"file":"SecretTextArea.mjs","sources":["../../../../src/components/SecretTextArea/SecretTextArea.tsx"],"sourcesContent":["import { css, cx } from '@emotion/css';\nimport * as React from 'react';\n\nimport { GrafanaTheme2 } from '@grafana/data';\n\nimport { useStyles2 } from '../../themes/ThemeContext';\nimport { Button } from '../Button/Button';\nimport { Box } from '../Layout/Box/Box';\nimport { Stack } from '../Layout/Stack/Stack';\nimport { TextArea } from '../TextArea/TextArea';\n\nexport type Props = React.ComponentProps<typeof TextArea> & {\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\nexport const CONFIGURED_TEXT = 'configured';\nexport const RESET_BUTTON_TEXT = 'Reset';\n\nconst getStyles = (theme: GrafanaTheme2) => {\n return {\n configuredStyle: css({\n minHeight: theme.spacing(theme.components.height.md),\n paddingTop: theme.spacing(0.5) /** Needed to mimic vertically centered text in an input box */,\n resize: 'none',\n }),\n };\n};\n\n/**\n * Text area that does not disclose an already configured value but lets the user reset the current value and enter a new one.\n * Typically useful for asymmetric cryptography keys.\n */\nexport const SecretTextArea = ({ isConfigured, onReset, ...props }: Props) => {\n const styles = useStyles2(getStyles);\n return (\n <Stack>\n <Box>\n {!isConfigured && <TextArea {...props} />}\n {isConfigured && (\n <TextArea\n {...props}\n rows={1}\n disabled={true}\n value={CONFIGURED_TEXT}\n className={cx(styles.configuredStyle)}\n />\n )}\n </Box>\n {isConfigured && (\n <Button onClick={onReset} variant=\"secondary\">\n {RESET_BUTTON_TEXT}\n </Button>\n )}\n </Stack>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;AAkBO,MAAM,eAAA,GAAkB;AACxB,MAAM,iBAAA,GAAoB;AAEjC,MAAM,SAAA,GAAY,CAAC,KAAA,KAAyB;AAC1C,EAAA,OAAO;AAAA,IACL,iBAAiB,GAAA,CAAI;AAAA,MACnB,WAAW,KAAA,CAAM,OAAA,CAAQ,KAAA,CAAM,UAAA,CAAW,OAAO,EAAE,CAAA;AAAA,MACnD,UAAA,EAAY,KAAA,CAAM,OAAA,CAAQ,GAAG,CAAA;AAAA,MAC7B,MAAA,EAAQ;AAAA,KACT;AAAA,GACH;AACF,CAAA;AAMO,MAAM,iBAAiB,CAAC,EAAE,cAAc,OAAA,EAAS,GAAG,OAAM,KAAa;AAC5E,EAAA,MAAM,MAAA,GAAS,WAAW,SAAS,CAAA;AACnC,EAAA,4BACG,KAAA,EAAA,EACC,QAAA,EAAA;AAAA,oBAAA,IAAA,CAAC,GAAA,EAAA,EACE,QAAA,EAAA;AAAA,MAAA,CAAC,YAAA,oBAAgB,GAAA,CAAC,QAAA,EAAA,EAAU,GAAG,KAAA,EAAO,CAAA;AAAA,MACtC,YAAA,oBACC,GAAA;AAAA,QAAC,QAAA;AAAA,QAAA;AAAA,UACE,GAAG,KAAA;AAAA,UACJ,IAAA,EAAM,CAAA;AAAA,UACN,QAAA,EAAU,IAAA;AAAA,UACV,KAAA,EAAO,eAAA;AAAA,UACP,SAAA,EAAW,EAAA,CAAG,MAAA,CAAO,eAAe;AAAA;AAAA;AACtC,KAAA,EAEJ,CAAA;AAAA,IACC,gCACC,GAAA,CAAC,MAAA,EAAA,EAAO,SAAS,OAAA,EAAS,OAAA,EAAQ,aAC/B,QAAA,EAAA,iBAAA,EACH;AAAA,GAAA,EAEJ,CAAA;AAEJ;;;;"}