feat: added support for cta button

with sliding down animation if an error occurs
pull/3056/head
William Grant 2 years ago
parent 814d793e1c
commit 8dfdd87d0e

@ -41,6 +41,7 @@ import { AttachmentTypeWithPath } from '../../../../types/Attachment';
import { getAbsoluteAttachmentPath } from '../../../../types/MessageAttachment'; import { getAbsoluteAttachmentPath } from '../../../../types/MessageAttachment';
import { Avatar, AvatarSize } from '../../../avatar/Avatar'; import { Avatar, AvatarSize } from '../../../avatar/Avatar';
import { Flex } from '../../../basic/Flex'; import { Flex } from '../../../basic/Flex';
import { SessionButton } from '../../../basic/SessionButton';
import { SpacerLG, SpacerMD, SpacerXL } from '../../../basic/Text'; import { SpacerLG, SpacerMD, SpacerXL } from '../../../basic/Text';
import { SessionInput2 } from '../../../inputs'; import { SessionInput2 } from '../../../inputs';
import { MediaItemType } from '../../../lightbox/LightboxGallery'; import { MediaItemType } from '../../../lightbox/LightboxGallery';
@ -234,7 +235,7 @@ export const OverlayRightPanelSettings = () => {
const handleInputChanged = (name: string) => { const handleInputChanged = (name: string) => {
sanitizeDisplayNameOrToast(name, setInputValue, setInputError); sanitizeDisplayNameOrToast(name, setInputValue, setInputError);
if (name.length > MAX_USERNAME_BYTES) { if (name.length > 8) {
setInputError(window.i18n('displayNameTooLong')); setInputError(window.i18n('displayNameTooLong'));
} }
}; };
@ -347,6 +348,16 @@ export const OverlayRightPanelSettings = () => {
maxLength={MAX_USERNAME_BYTES} maxLength={MAX_USERNAME_BYTES}
onValueChanged={handleInputChanged} onValueChanged={handleInputChanged}
onEnterPressed={handleEnterPressed} onEnterPressed={handleEnterPressed}
ctaButton={
<SessionButton
onClick={() => {
window.log.debug(
`WIP: [OverlayRightPanelSettings] clicked continuing your session! `
);
}}
text={window.i18n('continueYourSession')}
/>
}
/> />
{/* <HeaderItem /> {/* <HeaderItem />
<PanelButtonGroup style={{ margin: '0 var(--margins-lg)' }}> <PanelButtonGroup style={{ margin: '0 var(--margins-lg)' }}>

@ -1,4 +1,4 @@
import { ChangeEvent, useEffect, useState } from 'react'; import { ChangeEvent, ReactNode, useEffect, useState } from 'react';
import { motion } from 'framer-motion'; import { motion } from 'framer-motion';
import { isEmpty, isEqual } from 'lodash'; import { isEmpty, isEqual } from 'lodash';
@ -82,6 +82,10 @@ const ShowHideButton = (props: { toggleForceShow: Noop }) => {
); );
}; };
const StyledCtaContainer = styled(motion.div)`
width: 100%;
`;
type Props = { type Props = {
error?: string; error?: string;
type?: string; type?: string;
@ -95,6 +99,7 @@ type Props = {
ref?: any; ref?: any;
inputDataTestId?: string; inputDataTestId?: string;
id?: string; id?: string;
ctaButton?: ReactNode;
}; };
export const SessionInput2 = (props: Props) => { export const SessionInput2 = (props: Props) => {
@ -109,6 +114,7 @@ export const SessionInput2 = (props: Props) => {
onValueChanged, onValueChanged,
inputDataTestId, inputDataTestId,
id = 'session-input-floating-label', id = 'session-input-floating-label',
ctaButton,
} = props; } = props;
const [inputValue, setInputValue] = useState(''); const [inputValue, setInputValue] = useState('');
const [errorString, setErrorString] = useState(''); const [errorString, setErrorString] = useState('');
@ -174,12 +180,16 @@ export const SessionInput2 = (props: Props) => {
}} }}
/> />
)} )}
{errorString ? (
<> {ctaButton || errorString ? <SpacerMD /> : null}
<SpacerMD /> {errorString ? <ErrorItem id={id} error={errorString} /> : null}
<ErrorItem id={id} error={errorString} />
</> <StyledCtaContainer
) : null} initial={{ y: errorString && ctaButton ? 0 : undefined }}
animate={{ y: errorString && ctaButton ? 'var(--margins-md)' : undefined }}
>
{ctaButton}
</StyledCtaContainer>
</StyledInputContainer> </StyledInputContainer>
); );
}; };

Loading…
Cancel
Save