You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.2 KiB
52 lines
1.2 KiB
import { Box, styled } from '@mui/material'; |
|
import { createElement, FC, useMemo, useState } from 'react'; |
|
|
|
import { BORDER_RADIUS, EERIE_BLACK } from '../../lib/consts/DEFAULT_THEME'; |
|
|
|
import BodyText from './BodyText'; |
|
import MonoText from './MonoText'; |
|
|
|
const BaseStyle = styled(Box)({ |
|
backgroundColor: EERIE_BLACK, |
|
borderRadius: BORDER_RADIUS, |
|
color: EERIE_BLACK, |
|
cursor: 'pointer', |
|
display: 'inline-flex', |
|
padding: '0 .6em', |
|
width: 'fit-content', |
|
|
|
':focus': { |
|
color: 'unset', |
|
cursor: 'text', |
|
}, |
|
}); |
|
|
|
const SensitiveText: FC<SensitiveTextProps> = ({ |
|
children, |
|
monospaced = false, |
|
revealInitially = false, |
|
textProps, |
|
}) => { |
|
const [reveal, setReveal] = useState<boolean>(revealInitially); |
|
|
|
const content = useMemo(() => { |
|
if (typeof children !== 'string') return children; |
|
|
|
const elementType = monospaced ? MonoText : BodyText; |
|
|
|
return createElement(elementType, textProps, children); |
|
}, [children, monospaced, textProps]); |
|
|
|
return ( |
|
<BaseStyle |
|
component="div" |
|
onBlur={() => setReveal(false)} |
|
onFocus={() => setReveal(true)} |
|
tabIndex={0} |
|
> |
|
{reveal ? content : '*****'} |
|
</BaseStyle> |
|
); |
|
}; |
|
|
|
export default SensitiveText;
|
|
|