Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Add emoji handling for rich text mode
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Nov 30, 2022
1 parent dd91250 commit 2064ccb
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ export function SendWysiwygComposer(
className="mx_SendWysiwygComposer"
leftComponent={e2eStatus && <E2EIcon status={e2eStatus} />}
// TODO add emoji support
rightComponent={<EmojiButton menuPosition={menuPosition} addEmoji={() => false} />}
rightComponent={composerFunctions =>
<EmojiButton menuPosition={menuPosition}
addEmoji={(unicode) => {
composerFunctions.insertText(unicode);
return true;
}}
/>}
{...props}
>
{ (ref, composerFunctions) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface PlainTextComposerProps {
initialContent?: string;
className?: string;
leftComponent?: ReactNode;
rightComponent?: ReactNode;
rightComponent?: (composerFunctions: ComposerFunctions) => ReactNode;
children?: (
ref: MutableRefObject<HTMLDivElement | null>,
composerFunctions: ComposerFunctions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface WysiwygComposerProps {
initialContent?: string;
className?: string;
leftComponent?: ReactNode;
rightComponent?: ReactNode;
rightComponent?: (composerFunctions: FormattingFunctions) => ReactNode;
children?: (
ref: MutableRefObject<HTMLDivElement | null>,
wysiwyg: FormattingFunctions,
Expand Down Expand Up @@ -69,10 +69,12 @@ export const WysiwygComposer = memo(function WysiwygComposer(
const { isFocused, onFocus } = useIsFocused();
const computedPlaceholder = !content && placeholder || undefined;

// const rightComp = rightComponent(wysiwyg);

return (
<div data-testid="WysiwygComposer" className={classNames(className, { [`${className}-focused`]: isFocused })} onFocus={onFocus} onBlur={onFocus}>
<FormattingButtons composer={wysiwyg} actionStates={actionStates} />
<Editor ref={ref} disabled={!isReady} leftComponent={leftComponent} rightComponent={rightComponent} placeholder={computedPlaceholder} />
<Editor ref={ref} disabled={!isReady} leftComponent={leftComponent} rightComponent={rightComponent(wysiwyg)} placeholder={computedPlaceholder} />
{ children?.(ref, wysiwyg) }
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ export function useComposerFunctions(ref: RefObject<HTMLDivElement>) {
ref.current.innerHTML = '';
}
},
insertText: (text: string) => {
// TODO
},
}), [ref]);
}
1 change: 1 addition & 0 deletions src/components/views/rooms/wysiwyg_composer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ limitations under the License.

export type ComposerFunctions = {
clear: () => void;
insertText: (text: string) => void;
};

0 comments on commit 2064ccb

Please sign in to comment.