2022-08-04 19:23:24 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import FocusTrap from 'focus-trap-react';
|
2022-10-12 16:14:35 +00:00
|
|
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
2022-08-04 19:23:24 +00:00
|
|
|
import classNames from 'classnames';
|
2022-09-15 01:58:35 +00:00
|
|
|
import { get, has, noop } from 'lodash';
|
2022-08-04 19:23:24 +00:00
|
|
|
import { usePopper } from 'react-popper';
|
|
|
|
|
|
|
|
import type { LinkPreviewType } from '../types/message/LinkPreviews';
|
|
|
|
import type { LocalizerType } from '../types/Util';
|
|
|
|
import type { TextAttachmentType } from '../types/Attachment';
|
|
|
|
|
|
|
|
import { Button, ButtonVariant } from './Button';
|
|
|
|
import { ContextMenu } from './ContextMenu';
|
|
|
|
import { LinkPreviewSourceType, findLinks } from '../types/LinkPreview';
|
2022-10-06 20:22:59 +00:00
|
|
|
import type { MaybeGrabLinkPreviewOptionsType } from '../types/LinkPreview';
|
2022-08-04 19:23:24 +00:00
|
|
|
import { Input } from './Input';
|
|
|
|
import { Slider } from './Slider';
|
|
|
|
import { StagedLinkPreview } from './conversation/StagedLinkPreview';
|
|
|
|
import { TextAttachment } from './TextAttachment';
|
|
|
|
import { Theme, themeClassName } from '../util/theme';
|
|
|
|
import { getRGBA, getRGBANumber } from '../mediaEditor/util/color';
|
|
|
|
import {
|
|
|
|
COLOR_BLACK_INT,
|
|
|
|
COLOR_WHITE_INT,
|
|
|
|
getBackgroundColor,
|
|
|
|
} from '../util/getStoryBackground';
|
|
|
|
import { objectMap } from '../util/objectMap';
|
2022-09-15 01:58:35 +00:00
|
|
|
import { handleOutsideClick } from '../util/handleOutsideClick';
|
2022-10-12 16:14:35 +00:00
|
|
|
import { ConfirmDiscardDialog } from './ConfirmDiscardDialog';
|
2022-08-04 19:23:24 +00:00
|
|
|
|
|
|
|
export type PropsType = {
|
|
|
|
debouncedMaybeGrabLinkPreview: (
|
|
|
|
message: string,
|
2022-10-06 20:22:59 +00:00
|
|
|
source: LinkPreviewSourceType,
|
|
|
|
options?: MaybeGrabLinkPreviewOptionsType
|
2022-08-04 19:23:24 +00:00
|
|
|
) => unknown;
|
|
|
|
i18n: LocalizerType;
|
|
|
|
linkPreview?: LinkPreviewType;
|
|
|
|
onClose: () => unknown;
|
|
|
|
onDone: (textAttachment: TextAttachmentType) => unknown;
|
|
|
|
};
|
|
|
|
|
2022-09-13 14:08:28 +00:00
|
|
|
enum LinkPreviewApplied {
|
|
|
|
None = 'None',
|
|
|
|
Automatic = 'Automatic',
|
|
|
|
Manual = 'Manual',
|
|
|
|
}
|
|
|
|
|
2022-08-04 19:23:24 +00:00
|
|
|
enum TextStyle {
|
|
|
|
Default,
|
|
|
|
Regular,
|
|
|
|
Bold,
|
|
|
|
Serif,
|
|
|
|
Script,
|
|
|
|
Condensed,
|
|
|
|
}
|
|
|
|
|
|
|
|
enum TextBackground {
|
|
|
|
None,
|
|
|
|
Background,
|
|
|
|
Inverse,
|
|
|
|
}
|
|
|
|
|
|
|
|
const BackgroundStyle = {
|
2022-09-21 14:48:04 +00:00
|
|
|
BG1: { color: 4285041620 },
|
|
|
|
BG2: { color: 4287006657 },
|
|
|
|
BG3: { color: 4290019212 },
|
|
|
|
BG4: { color: 4287205768 },
|
|
|
|
BG5: { color: 4283667331 },
|
|
|
|
BG6: {
|
|
|
|
angle: 180,
|
|
|
|
startColor: 4279871994,
|
|
|
|
endColor: 4294951785,
|
|
|
|
},
|
|
|
|
BG7: {
|
|
|
|
angle: 180,
|
|
|
|
startColor: 4282660824,
|
|
|
|
endColor: 4294938254,
|
|
|
|
},
|
|
|
|
BG8: {
|
|
|
|
angle: 180,
|
|
|
|
startColor: 4278206532,
|
|
|
|
endColor: 4287871076,
|
|
|
|
},
|
2022-08-04 19:23:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
type BackgroundStyleType = typeof BackgroundStyle[keyof typeof BackgroundStyle];
|
|
|
|
|
|
|
|
function getBackground(
|
|
|
|
bgStyle: BackgroundStyleType
|
|
|
|
): Pick<TextAttachmentType, 'color' | 'gradient'> {
|
|
|
|
if (has(bgStyle, 'color')) {
|
|
|
|
return { color: get(bgStyle, 'color') };
|
|
|
|
}
|
|
|
|
|
|
|
|
const angle = get(bgStyle, 'angle');
|
|
|
|
const startColor = get(bgStyle, 'startColor');
|
|
|
|
const endColor = get(bgStyle, 'endColor');
|
|
|
|
|
|
|
|
return {
|
|
|
|
gradient: { angle, startColor, endColor },
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function getBgButtonAriaLabel(
|
|
|
|
i18n: LocalizerType,
|
|
|
|
textBackground: TextBackground
|
|
|
|
): string {
|
|
|
|
if (textBackground === TextBackground.Background) {
|
|
|
|
return i18n('StoryCreator__text-bg--background');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (textBackground === TextBackground.Inverse) {
|
|
|
|
return i18n('StoryCreator__text-bg--inverse');
|
|
|
|
}
|
|
|
|
|
|
|
|
return i18n('StoryCreator__text-bg--none');
|
|
|
|
}
|
|
|
|
|
|
|
|
export const TextStoryCreator = ({
|
|
|
|
debouncedMaybeGrabLinkPreview,
|
|
|
|
i18n,
|
|
|
|
linkPreview,
|
|
|
|
onClose,
|
|
|
|
onDone,
|
|
|
|
}: PropsType): JSX.Element => {
|
2022-10-12 16:14:35 +00:00
|
|
|
const [showConfirmDiscardModal, setShowConfirmDiscardModal] = useState(false);
|
|
|
|
|
|
|
|
const onTryClose = useCallback(() => {
|
|
|
|
setShowConfirmDiscardModal(true);
|
|
|
|
}, [setShowConfirmDiscardModal]);
|
|
|
|
|
2022-08-04 19:23:24 +00:00
|
|
|
const [isEditingText, setIsEditingText] = useState(false);
|
|
|
|
const [selectedBackground, setSelectedBackground] =
|
2022-09-21 14:48:04 +00:00
|
|
|
useState<BackgroundStyleType>(BackgroundStyle.BG1);
|
2022-08-04 19:23:24 +00:00
|
|
|
const [textStyle, setTextStyle] = useState<TextStyle>(TextStyle.Regular);
|
|
|
|
const [textBackground, setTextBackground] = useState<TextBackground>(
|
|
|
|
TextBackground.None
|
|
|
|
);
|
|
|
|
const [sliderValue, setSliderValue] = useState<number>(100);
|
|
|
|
const [text, setText] = useState<string>('');
|
|
|
|
|
|
|
|
const textEditorRef = useRef<HTMLInputElement | null>(null);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (isEditingText) {
|
|
|
|
textEditorRef.current?.focus();
|
|
|
|
} else {
|
|
|
|
textEditorRef.current?.blur();
|
|
|
|
}
|
|
|
|
}, [isEditingText]);
|
|
|
|
|
|
|
|
const [isColorPickerShowing, setIsColorPickerShowing] = useState(false);
|
|
|
|
const [colorPickerPopperButtonRef, setColorPickerPopperButtonRef] =
|
|
|
|
useState<HTMLButtonElement | null>(null);
|
|
|
|
const [colorPickerPopperRef, setColorPickerPopperRef] =
|
|
|
|
useState<HTMLDivElement | null>(null);
|
|
|
|
|
|
|
|
const colorPickerPopper = usePopper(
|
|
|
|
colorPickerPopperButtonRef,
|
|
|
|
colorPickerPopperRef,
|
|
|
|
{
|
|
|
|
modifiers: [
|
|
|
|
{
|
|
|
|
name: 'arrow',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
placement: 'top',
|
|
|
|
strategy: 'fixed',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-09-13 14:08:28 +00:00
|
|
|
const [linkPreviewApplied, setLinkPreviewApplied] = useState(
|
|
|
|
LinkPreviewApplied.None
|
|
|
|
);
|
|
|
|
const hasLinkPreviewApplied = linkPreviewApplied !== LinkPreviewApplied.None;
|
2022-08-04 19:23:24 +00:00
|
|
|
const [linkPreviewInputValue, setLinkPreviewInputValue] = useState('');
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!linkPreviewInputValue) {
|
|
|
|
return;
|
|
|
|
}
|
2022-09-13 14:08:28 +00:00
|
|
|
if (linkPreviewApplied === LinkPreviewApplied.Manual) {
|
|
|
|
return;
|
|
|
|
}
|
2022-08-04 19:23:24 +00:00
|
|
|
debouncedMaybeGrabLinkPreview(
|
|
|
|
linkPreviewInputValue,
|
2022-10-06 20:22:59 +00:00
|
|
|
LinkPreviewSourceType.StoryCreator,
|
|
|
|
{
|
|
|
|
mode: 'story',
|
|
|
|
}
|
2022-08-04 19:23:24 +00:00
|
|
|
);
|
2022-09-13 14:08:28 +00:00
|
|
|
}, [
|
|
|
|
debouncedMaybeGrabLinkPreview,
|
|
|
|
linkPreviewApplied,
|
|
|
|
linkPreviewInputValue,
|
|
|
|
]);
|
2022-08-04 19:23:24 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!text) {
|
|
|
|
return;
|
|
|
|
}
|
2022-09-13 14:08:28 +00:00
|
|
|
if (linkPreviewApplied === LinkPreviewApplied.Manual) {
|
|
|
|
return;
|
|
|
|
}
|
2022-08-04 19:23:24 +00:00
|
|
|
debouncedMaybeGrabLinkPreview(text, LinkPreviewSourceType.StoryCreator);
|
2022-09-13 14:08:28 +00:00
|
|
|
}, [debouncedMaybeGrabLinkPreview, linkPreviewApplied, text]);
|
2022-08-04 19:23:24 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!linkPreview || !text) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const links = findLinks(text);
|
|
|
|
|
|
|
|
const shouldApplyLinkPreview = links.includes(linkPreview.url);
|
2022-09-13 14:08:28 +00:00
|
|
|
setLinkPreviewApplied(oldValue => {
|
|
|
|
if (oldValue === LinkPreviewApplied.Manual) {
|
|
|
|
return oldValue;
|
|
|
|
}
|
|
|
|
if (shouldApplyLinkPreview) {
|
|
|
|
return LinkPreviewApplied.Automatic;
|
|
|
|
}
|
|
|
|
return LinkPreviewApplied.None;
|
|
|
|
});
|
2022-08-04 19:23:24 +00:00
|
|
|
}, [linkPreview, text]);
|
|
|
|
|
|
|
|
const [isLinkPreviewInputShowing, setIsLinkPreviewInputShowing] =
|
|
|
|
useState(false);
|
|
|
|
const [linkPreviewInputPopperButtonRef, setLinkPreviewInputPopperButtonRef] =
|
|
|
|
useState<HTMLButtonElement | null>(null);
|
|
|
|
const [linkPreviewInputPopperRef, setLinkPreviewInputPopperRef] =
|
|
|
|
useState<HTMLDivElement | null>(null);
|
|
|
|
|
|
|
|
const linkPreviewInputPopper = usePopper(
|
|
|
|
linkPreviewInputPopperButtonRef,
|
|
|
|
linkPreviewInputPopperRef,
|
|
|
|
{
|
|
|
|
modifiers: [
|
|
|
|
{
|
|
|
|
name: 'arrow',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
placement: 'top',
|
|
|
|
strategy: 'fixed',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const handleEscape = (event: KeyboardEvent) => {
|
|
|
|
if (event.key === 'Escape') {
|
2022-08-15 19:35:30 +00:00
|
|
|
if (
|
|
|
|
isColorPickerShowing ||
|
|
|
|
isEditingText ||
|
|
|
|
isLinkPreviewInputShowing
|
|
|
|
) {
|
|
|
|
setIsColorPickerShowing(false);
|
|
|
|
setIsEditingText(false);
|
|
|
|
setIsLinkPreviewInputShowing(false);
|
|
|
|
} else {
|
2022-10-12 16:14:35 +00:00
|
|
|
onTryClose();
|
2022-08-15 19:35:30 +00:00
|
|
|
}
|
2022-10-12 16:14:35 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
2022-08-04 19:23:24 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-09-15 01:58:35 +00:00
|
|
|
const useCapture = true;
|
|
|
|
document.addEventListener('keydown', handleEscape, useCapture);
|
2022-08-04 19:23:24 +00:00
|
|
|
|
|
|
|
return () => {
|
2022-09-15 01:58:35 +00:00
|
|
|
document.removeEventListener('keydown', handleEscape, useCapture);
|
2022-08-04 19:23:24 +00:00
|
|
|
};
|
2022-08-15 19:35:30 +00:00
|
|
|
}, [
|
|
|
|
isColorPickerShowing,
|
|
|
|
isEditingText,
|
|
|
|
isLinkPreviewInputShowing,
|
|
|
|
colorPickerPopperButtonRef,
|
2022-10-12 16:14:35 +00:00
|
|
|
showConfirmDiscardModal,
|
|
|
|
setShowConfirmDiscardModal,
|
|
|
|
onTryClose,
|
2022-08-15 19:35:30 +00:00
|
|
|
]);
|
2022-08-04 19:23:24 +00:00
|
|
|
|
2022-09-15 01:58:35 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (!isColorPickerShowing) {
|
|
|
|
return noop;
|
|
|
|
}
|
|
|
|
return handleOutsideClick(
|
|
|
|
() => {
|
|
|
|
setIsColorPickerShowing(false);
|
|
|
|
return true;
|
|
|
|
},
|
2022-09-27 20:24:21 +00:00
|
|
|
{
|
|
|
|
containerElements: [colorPickerPopperRef, colorPickerPopperButtonRef],
|
|
|
|
name: 'TextStoryCreator.colorPicker',
|
|
|
|
}
|
2022-09-15 01:58:35 +00:00
|
|
|
);
|
2022-09-15 19:11:40 +00:00
|
|
|
}, [isColorPickerShowing, colorPickerPopperRef, colorPickerPopperButtonRef]);
|
2022-09-15 01:58:35 +00:00
|
|
|
|
2022-08-04 19:23:24 +00:00
|
|
|
const sliderColorNumber = getRGBANumber(sliderValue);
|
|
|
|
|
|
|
|
let textForegroundColor = sliderColorNumber;
|
|
|
|
let textBackgroundColor: number | undefined;
|
|
|
|
|
|
|
|
if (textBackground === TextBackground.Background) {
|
|
|
|
textBackgroundColor = COLOR_WHITE_INT;
|
|
|
|
textForegroundColor =
|
|
|
|
sliderValue >= 95 ? COLOR_BLACK_INT : sliderColorNumber;
|
|
|
|
} else if (textBackground === TextBackground.Inverse) {
|
|
|
|
textBackgroundColor =
|
|
|
|
sliderValue >= 95 ? COLOR_BLACK_INT : sliderColorNumber;
|
|
|
|
textForegroundColor = COLOR_WHITE_INT;
|
|
|
|
}
|
|
|
|
|
|
|
|
const textAttachment: TextAttachmentType = {
|
|
|
|
...getBackground(selectedBackground),
|
|
|
|
text,
|
|
|
|
textStyle,
|
|
|
|
textForegroundColor,
|
|
|
|
textBackgroundColor,
|
|
|
|
preview: hasLinkPreviewApplied ? linkPreview : undefined,
|
|
|
|
};
|
|
|
|
|
|
|
|
const hasChanges = Boolean(text || hasLinkPreviewApplied);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<FocusTrap focusTrapOptions={{ allowOutsideClick: true }}>
|
|
|
|
<div className="StoryCreator">
|
|
|
|
<div className="StoryCreator__container">
|
|
|
|
<TextAttachment
|
|
|
|
disableLinkPreviewPopup
|
|
|
|
i18n={i18n}
|
|
|
|
isEditingText={isEditingText}
|
|
|
|
onChange={setText}
|
|
|
|
onClick={() => {
|
|
|
|
if (!isEditingText) {
|
|
|
|
setIsEditingText(true);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
onRemoveLinkPreview={() => {
|
2022-09-13 14:08:28 +00:00
|
|
|
setLinkPreviewApplied(LinkPreviewApplied.None);
|
2022-08-04 19:23:24 +00:00
|
|
|
}}
|
|
|
|
textAttachment={textAttachment}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="StoryCreator__toolbar">
|
|
|
|
{isEditingText ? (
|
|
|
|
<div className="StoryCreator__tools">
|
|
|
|
<Slider
|
|
|
|
handleStyle={{ backgroundColor: getRGBA(sliderValue) }}
|
|
|
|
label={getRGBA(sliderValue)}
|
|
|
|
moduleClassName="HueSlider StoryCreator__tools__tool"
|
|
|
|
onChange={setSliderValue}
|
|
|
|
value={sliderValue}
|
|
|
|
/>
|
|
|
|
<ContextMenu
|
|
|
|
i18n={i18n}
|
|
|
|
menuOptions={[
|
|
|
|
{
|
|
|
|
icon: 'StoryCreator__icon--font-regular',
|
|
|
|
label: i18n('StoryCreator__text--regular'),
|
|
|
|
onClick: () => setTextStyle(TextStyle.Regular),
|
|
|
|
value: TextStyle.Regular,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: 'StoryCreator__icon--font-bold',
|
|
|
|
label: i18n('StoryCreator__text--bold'),
|
|
|
|
onClick: () => setTextStyle(TextStyle.Bold),
|
|
|
|
value: TextStyle.Bold,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: 'StoryCreator__icon--font-serif',
|
|
|
|
label: i18n('StoryCreator__text--serif'),
|
|
|
|
onClick: () => setTextStyle(TextStyle.Serif),
|
|
|
|
value: TextStyle.Serif,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: 'StoryCreator__icon--font-script',
|
|
|
|
label: i18n('StoryCreator__text--script'),
|
|
|
|
onClick: () => setTextStyle(TextStyle.Script),
|
|
|
|
value: TextStyle.Script,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: 'StoryCreator__icon--font-condensed',
|
|
|
|
label: i18n('StoryCreator__text--condensed'),
|
|
|
|
onClick: () => setTextStyle(TextStyle.Condensed),
|
|
|
|
value: TextStyle.Condensed,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
moduleClassName={classNames('StoryCreator__tools__tool', {
|
|
|
|
'StoryCreator__tools__button--font-regular':
|
|
|
|
textStyle === TextStyle.Regular,
|
|
|
|
'StoryCreator__tools__button--font-bold':
|
|
|
|
textStyle === TextStyle.Bold,
|
|
|
|
'StoryCreator__tools__button--font-serif':
|
|
|
|
textStyle === TextStyle.Serif,
|
|
|
|
'StoryCreator__tools__button--font-script':
|
|
|
|
textStyle === TextStyle.Script,
|
|
|
|
'StoryCreator__tools__button--font-condensed':
|
|
|
|
textStyle === TextStyle.Condensed,
|
|
|
|
})}
|
|
|
|
theme={Theme.Dark}
|
|
|
|
value={textStyle}
|
|
|
|
/>
|
|
|
|
<button
|
|
|
|
aria-label={getBgButtonAriaLabel(i18n, textBackground)}
|
|
|
|
className={classNames('StoryCreator__tools__tool', {
|
|
|
|
'StoryCreator__tools__button--bg-none':
|
|
|
|
textBackground === TextBackground.None,
|
|
|
|
'StoryCreator__tools__button--bg':
|
|
|
|
textBackground === TextBackground.Background,
|
|
|
|
'StoryCreator__tools__button--bg-inverse':
|
|
|
|
textBackground === TextBackground.Inverse,
|
|
|
|
})}
|
|
|
|
onClick={() => {
|
|
|
|
if (textBackground === TextBackground.None) {
|
|
|
|
setTextBackground(TextBackground.Background);
|
|
|
|
} else if (textBackground === TextBackground.Background) {
|
|
|
|
setTextBackground(TextBackground.Inverse);
|
|
|
|
} else {
|
|
|
|
setTextBackground(TextBackground.None);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
type="button"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="StoryCreator__toolbar--space" />
|
|
|
|
)}
|
|
|
|
<div className="StoryCreator__toolbar--buttons">
|
|
|
|
<Button
|
2022-10-12 16:14:35 +00:00
|
|
|
onClick={onTryClose}
|
2022-08-04 19:23:24 +00:00
|
|
|
theme={Theme.Dark}
|
|
|
|
variant={ButtonVariant.Secondary}
|
|
|
|
>
|
|
|
|
{i18n('discard')}
|
|
|
|
</Button>
|
|
|
|
<div className="StoryCreator__controls">
|
|
|
|
<button
|
|
|
|
aria-label={i18n('StoryCreator__story-bg')}
|
|
|
|
className={classNames({
|
|
|
|
StoryCreator__control: true,
|
|
|
|
'StoryCreator__control--bg': true,
|
|
|
|
'StoryCreator__control--bg--selected': isColorPickerShowing,
|
|
|
|
})}
|
|
|
|
onClick={() => setIsColorPickerShowing(!isColorPickerShowing)}
|
|
|
|
ref={setColorPickerPopperButtonRef}
|
|
|
|
style={{
|
|
|
|
background: getBackgroundColor(
|
|
|
|
getBackground(selectedBackground)
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
type="button"
|
|
|
|
/>
|
|
|
|
{isColorPickerShowing && (
|
|
|
|
<div
|
|
|
|
className="StoryCreator__popper"
|
|
|
|
ref={setColorPickerPopperRef}
|
|
|
|
style={colorPickerPopper.styles.popper}
|
|
|
|
{...colorPickerPopper.attributes.popper}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
data-popper-arrow
|
|
|
|
className="StoryCreator__popper__arrow"
|
|
|
|
/>
|
|
|
|
{objectMap<BackgroundStyleType>(
|
|
|
|
BackgroundStyle,
|
|
|
|
(bg, backgroundValue) => (
|
|
|
|
<button
|
|
|
|
aria-label={i18n('StoryCreator__story-bg')}
|
|
|
|
className={classNames({
|
|
|
|
StoryCreator__bg: true,
|
|
|
|
'StoryCreator__bg--selected':
|
|
|
|
selectedBackground === backgroundValue,
|
|
|
|
})}
|
|
|
|
key={String(bg)}
|
|
|
|
onClick={() => {
|
|
|
|
setSelectedBackground(backgroundValue);
|
|
|
|
setIsColorPickerShowing(false);
|
|
|
|
}}
|
|
|
|
type="button"
|
|
|
|
style={{
|
|
|
|
background: getBackgroundColor(
|
|
|
|
getBackground(backgroundValue)
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<button
|
|
|
|
aria-label={i18n('StoryCreator__control--text')}
|
|
|
|
className={classNames({
|
|
|
|
StoryCreator__control: true,
|
|
|
|
'StoryCreator__control--text': true,
|
|
|
|
'StoryCreator__control--selected': isEditingText,
|
|
|
|
})}
|
|
|
|
onClick={() => {
|
|
|
|
setIsEditingText(!isEditingText);
|
|
|
|
}}
|
|
|
|
type="button"
|
|
|
|
/>
|
|
|
|
<button
|
|
|
|
aria-label={i18n('StoryCreator__control--link')}
|
|
|
|
className="StoryCreator__control StoryCreator__control--link"
|
|
|
|
onClick={() =>
|
|
|
|
setIsLinkPreviewInputShowing(!isLinkPreviewInputShowing)
|
|
|
|
}
|
|
|
|
ref={setLinkPreviewInputPopperButtonRef}
|
|
|
|
type="button"
|
|
|
|
/>
|
|
|
|
{isLinkPreviewInputShowing && (
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'StoryCreator__popper StoryCreator__link-preview-input-popper',
|
|
|
|
themeClassName(Theme.Dark)
|
|
|
|
)}
|
|
|
|
ref={setLinkPreviewInputPopperRef}
|
|
|
|
style={linkPreviewInputPopper.styles.popper}
|
|
|
|
{...linkPreviewInputPopper.attributes.popper}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
data-popper-arrow
|
|
|
|
className="StoryCreator__popper__arrow"
|
|
|
|
/>
|
|
|
|
<Input
|
|
|
|
disableSpellcheck
|
|
|
|
i18n={i18n}
|
|
|
|
moduleClassName="StoryCreator__link-preview-input"
|
|
|
|
onChange={setLinkPreviewInputValue}
|
|
|
|
placeholder={i18n('StoryCreator__link-preview-placeholder')}
|
|
|
|
ref={el => el?.focus()}
|
|
|
|
value={linkPreviewInputValue}
|
|
|
|
/>
|
|
|
|
<div className="StoryCreator__link-preview-container">
|
|
|
|
{linkPreview ? (
|
|
|
|
<>
|
|
|
|
<StagedLinkPreview
|
2022-10-06 20:22:59 +00:00
|
|
|
{...linkPreview}
|
2022-08-04 19:23:24 +00:00
|
|
|
i18n={i18n}
|
|
|
|
moduleClassName="StoryCreator__link-preview"
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
className="StoryCreator__link-preview-button"
|
|
|
|
onClick={() => {
|
2022-09-13 14:08:28 +00:00
|
|
|
setLinkPreviewApplied(LinkPreviewApplied.Manual);
|
2022-08-04 19:23:24 +00:00
|
|
|
setIsLinkPreviewInputShowing(false);
|
|
|
|
}}
|
|
|
|
theme={Theme.Dark}
|
|
|
|
variant={ButtonVariant.Primary}
|
|
|
|
>
|
|
|
|
{i18n('StoryCreator__add-link')}
|
|
|
|
</Button>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<div className="StoryCreator__link-preview-empty">
|
|
|
|
<div className="StoryCreator__link-preview-empty__icon" />
|
|
|
|
{i18n('StoryCreator__link-preview-empty')}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<Button
|
|
|
|
disabled={!hasChanges}
|
|
|
|
onClick={() => onDone(textAttachment)}
|
|
|
|
theme={Theme.Dark}
|
|
|
|
variant={ButtonVariant.Primary}
|
|
|
|
>
|
|
|
|
{i18n('StoryCreator__next')}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-10-12 16:14:35 +00:00
|
|
|
{showConfirmDiscardModal && (
|
|
|
|
<ConfirmDiscardDialog
|
|
|
|
i18n={i18n}
|
|
|
|
onClose={() => setShowConfirmDiscardModal(false)}
|
|
|
|
onDiscard={onClose}
|
|
|
|
/>
|
|
|
|
)}
|
2022-08-04 19:23:24 +00:00
|
|
|
</div>
|
|
|
|
</FocusTrap>
|
|
|
|
);
|
|
|
|
};
|