|
|
@ -1,18 +1,51 @@ |
|
|
|
import { createElement, FC, ReactNode, useMemo, useState } from 'react'; |
|
|
|
import { Button, styled } from '@mui/material'; |
|
|
|
|
|
|
|
import { |
|
|
|
|
|
|
|
createElement, |
|
|
|
|
|
|
|
FC, |
|
|
|
|
|
|
|
ReactElement, |
|
|
|
|
|
|
|
ReactNode, |
|
|
|
|
|
|
|
useCallback, |
|
|
|
|
|
|
|
useMemo, |
|
|
|
|
|
|
|
useState, |
|
|
|
|
|
|
|
} from 'react'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { BORDER_RADIUS, EERIE_BLACK } from '../../lib/consts/DEFAULT_THEME'; |
|
|
|
|
|
|
|
|
|
|
|
import BodyText from './BodyText'; |
|
|
|
import BodyText from './BodyText'; |
|
|
|
import FlexBox from '../FlexBox'; |
|
|
|
import FlexBox from '../FlexBox'; |
|
|
|
import IconButton from '../IconButton'; |
|
|
|
import IconButton from '../IconButton'; |
|
|
|
import MonoText from './MonoText'; |
|
|
|
import MonoText from './MonoText'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const InlineButton = styled(Button)({ |
|
|
|
|
|
|
|
backgroundColor: EERIE_BLACK, |
|
|
|
|
|
|
|
borderRadius: BORDER_RADIUS, |
|
|
|
|
|
|
|
minWidth: 'initial', |
|
|
|
|
|
|
|
padding: '0 .6em', |
|
|
|
|
|
|
|
textTransform: 'none', |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
':hover': { |
|
|
|
|
|
|
|
backgroundColor: `${EERIE_BLACK}F0`, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const SensitiveText: FC<SensitiveTextProps> = ({ |
|
|
|
const SensitiveText: FC<SensitiveTextProps> = ({ |
|
|
|
children, |
|
|
|
children, |
|
|
|
|
|
|
|
inline: isInline = false, |
|
|
|
monospaced: isMonospaced = false, |
|
|
|
monospaced: isMonospaced = false, |
|
|
|
revealInitially: isRevealInitially = false, |
|
|
|
revealInitially: isRevealInitially = false, |
|
|
|
textProps, |
|
|
|
textProps, |
|
|
|
}) => { |
|
|
|
}) => { |
|
|
|
const [isReveal, setIsReveal] = useState<boolean>(isRevealInitially); |
|
|
|
const [isReveal, setIsReveal] = useState<boolean>(isRevealInitially); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const clickEventHandler = useCallback(() => { |
|
|
|
|
|
|
|
setIsReveal((previous) => !previous); |
|
|
|
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const textSxLineHeight = useMemo<number | string | undefined>( |
|
|
|
|
|
|
|
() => (isInline ? undefined : 2.8), |
|
|
|
|
|
|
|
[isInline], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const textElementType = useMemo( |
|
|
|
const textElementType = useMemo( |
|
|
|
() => (isMonospaced ? MonoText : BodyText), |
|
|
|
() => (isMonospaced ? MonoText : BodyText), |
|
|
|
[isMonospaced], |
|
|
|
[isMonospaced], |
|
|
@ -27,7 +60,7 @@ const SensitiveText: FC<SensitiveTextProps> = ({ |
|
|
|
textElementType, |
|
|
|
textElementType, |
|
|
|
{ |
|
|
|
{ |
|
|
|
sx: { |
|
|
|
sx: { |
|
|
|
lineHeight: 2.8, |
|
|
|
lineHeight: textSxLineHeight, |
|
|
|
maxWidth: '20em', |
|
|
|
maxWidth: '20em', |
|
|
|
overflowY: 'scroll', |
|
|
|
overflowY: 'scroll', |
|
|
|
whiteSpace: 'nowrap', |
|
|
|
whiteSpace: 'nowrap', |
|
|
@ -38,27 +71,43 @@ const SensitiveText: FC<SensitiveTextProps> = ({ |
|
|
|
) |
|
|
|
) |
|
|
|
: children; |
|
|
|
: children; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
content = createElement(textElementType, textProps, '*****'); |
|
|
|
content = createElement( |
|
|
|
|
|
|
|
textElementType, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
sx: { |
|
|
|
|
|
|
|
lineHeight: textSxLineHeight, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
...textProps, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
'*****', |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return content; |
|
|
|
return content; |
|
|
|
}, [children, isReveal, textElementType, textProps]); |
|
|
|
}, [children, isReveal, textElementType, textProps, textSxLineHeight]); |
|
|
|
|
|
|
|
const rootElement = useMemo<ReactElement>( |
|
|
|
return ( |
|
|
|
() => |
|
|
|
|
|
|
|
isInline ? ( |
|
|
|
|
|
|
|
<InlineButton onClick={clickEventHandler}> |
|
|
|
|
|
|
|
{contentElement} |
|
|
|
|
|
|
|
</InlineButton> |
|
|
|
|
|
|
|
) : ( |
|
|
|
<FlexBox row spacing=".5em"> |
|
|
|
<FlexBox row spacing=".5em"> |
|
|
|
{contentElement} |
|
|
|
{contentElement} |
|
|
|
<IconButton |
|
|
|
<IconButton |
|
|
|
edge="end" |
|
|
|
edge="end" |
|
|
|
mapPreset="visibility" |
|
|
|
mapPreset="visibility" |
|
|
|
onClick={() => { |
|
|
|
onClick={clickEventHandler} |
|
|
|
setIsReveal((previous) => !previous); |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
state={String(isReveal)} |
|
|
|
state={String(isReveal)} |
|
|
|
sx={{ marginRight: '-.2em', padding: '.2em' }} |
|
|
|
sx={{ marginRight: '-.2em', padding: '.2em' }} |
|
|
|
variant="normal" |
|
|
|
variant="normal" |
|
|
|
/> |
|
|
|
/> |
|
|
|
</FlexBox> |
|
|
|
</FlexBox> |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
[clickEventHandler, contentElement, isInline, isReveal], |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return rootElement; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export default SensitiveText; |
|
|
|
export default SensitiveText; |
|
|
|