Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow consumers of core to set their own default placeholder URL #111

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { BaseButton } from '../base-button';
import { useRef, useState } from 'react';
import { Tooltip, TooltipTrigger, TooltipContent } from './tooltip';
import {
DEFAULT_PLACEHOLDER_URL,
DEFAULT_RENDER_VARIABLE_FUNCTION,
DEFAULT_VARIABLE_TRIGGER_CHAR,
useMailyContext,
Expand Down Expand Up @@ -59,6 +60,7 @@ export function LinkInputPopover(props: LinkInputPopoverProps) {
variables = [],
variableTriggerCharacter = DEFAULT_VARIABLE_TRIGGER_CHAR,
renderVariable = DEFAULT_RENDER_VARIABLE_FUNCTION,
placeholderUrl = DEFAULT_PLACEHOLDER_URL
} = useMailyContext();

const autoCompleteOptions = useMemo(() => {
Expand Down Expand Up @@ -189,7 +191,7 @@ export function LinkInputPopover(props: LinkInputPopoverProps) {
}}
autoCompleteOptions={autoCompleteOptions}
ref={linkInputRef}
placeholder="maily.to/"
placeholder={placeholderUrl}
className="-mly-ms-px mly-block mly-h-8 mly-w-52 mly-rounded-lg mly-rounded-s-none mly-border mly-border-gray-300 mly-px-2 mly-py-1.5 mly-pr-6 mly-text-sm mly-shadow-sm mly-outline-none placeholder:mly-text-gray-400"
triggerChar={variableTriggerCharacter}
onSelectOption={(value) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { TextBubbleMenu } from './components/text-menu/text-bubble-menu';
import { extensions as defaultExtensions } from './extensions';
import { DEFAULT_SLASH_COMMANDS } from './extensions/slash-command/default-slash-commands';
import {
DEFAULT_PLACEHOLDER_URL,
DEFAULT_RENDER_VARIABLE_FUNCTION,
DEFAULT_VARIABLE_TRIGGER_CHAR,
DEFAULT_VARIABLES,
Expand Down Expand Up @@ -63,6 +64,7 @@ export function Editor(props: EditorProps) {
blocks = DEFAULT_SLASH_COMMANDS,
variableTriggerCharacter = DEFAULT_VARIABLE_TRIGGER_CHAR,
renderVariable = DEFAULT_RENDER_VARIABLE_FUNCTION,
placeholderUrl = DEFAULT_PLACEHOLDER_URL
} = props;

let formattedContent: any = null;
Expand Down Expand Up @@ -136,6 +138,7 @@ export function Editor(props: EditorProps) {
blocks={blocks}
variableTriggerCharacter={variableTriggerCharacter}
renderVariable={renderVariable}
placeholderUrl={placeholderUrl}
>
<div
className={cn('mly-editor mly-antialiased', wrapClassName)}
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/editor/nodes/button/button-label-input.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { InputAutocomplete } from '@/editor/components/ui/input-autocomplete';
import {
DEFAULT_PLACEHOLDER_URL,
DEFAULT_RENDER_VARIABLE_FUNCTION,
DEFAULT_VARIABLE_TRIGGER_CHAR,
useMailyContext,
Expand Down Expand Up @@ -29,6 +30,7 @@ export function ButtonLabelInput(props: ButtonLabelInputProps) {
variables = [],
variableTriggerCharacter = DEFAULT_VARIABLE_TRIGGER_CHAR,
renderVariable = DEFAULT_RENDER_VARIABLE_FUNCTION,
placeholderUrl = DEFAULT_PLACEHOLDER_URL,
} = useMailyContext();

const autoCompleteOptions = useMemo(() => {
Expand Down Expand Up @@ -75,7 +77,7 @@ export function ButtonLabelInput(props: ButtonLabelInputProps) {
}}
autoCompleteOptions={autoCompleteOptions}
ref={linkInputRef}
placeholder="maily.to/"
placeholder={placeholderUrl}
className="mly-h-7 mly-w-40 mly-rounded-md mly-px-2 mly-pr-6 mly-text-sm mly-text-midnight-gray hover:mly-bg-soft-gray focus:mly-bg-soft-gray focus:mly-outline-none"
triggerChar={variableTriggerCharacter}
onSelectOption={(value) => {
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/editor/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,23 @@ export type RenderVariableFunction = (
opts: RenderVariableOptions
) => JSX.Element | null;

export const DEFAULT_PLACEHOLDER_URL = 'maily.to/'

export const DEFAULT_VARIABLE_TRIGGER_CHAR = '@';
export const DEFAULT_VARIABLES: Variables = [];
export const DEFAULT_RENDER_VARIABLE_FUNCTION: RenderVariableFunction =
DefaultRenderVariable;

export type MailyContextType = {
placeholderUrl?: string
variableTriggerCharacter?: string;
variables?: Variables;
blocks?: BlockItem[];
renderVariable?: RenderVariableFunction;
};

export const MailyContext = createContext<MailyContextType>({
placeholderUrl: DEFAULT_PLACEHOLDER_URL,
variableTriggerCharacter: DEFAULT_VARIABLE_TRIGGER_CHAR,
variables: DEFAULT_VARIABLES,
blocks: DEFAULT_SLASH_COMMANDS,
Expand Down