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

feat(add: defaultMessage prop): add new defaultMessage props #24

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
5 changes: 4 additions & 1 deletion src/components/FloatingWhatsApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export interface FloatingWhatsAppProps {
statusMessage?: string
/** Text inside the chat box */
chatMessage?: string
/** Text that will be submitted with the input value */
defaultMessage?: string
/** Input placeholder */
placeholder?: string

Expand Down Expand Up @@ -86,6 +88,7 @@ export function FloatingWhatsApp({
avatar = dummyAvatar,
statusMessage = 'Typically replies within 1 hour',
chatMessage = 'Hello there! 🤝 \nHow can we help?',
defaultMessage,
placeholder = 'Type a message..',

messageDelay = 2,
Expand Down Expand Up @@ -179,7 +182,7 @@ export function FloatingWhatsApp({
event.preventDefault()
if (!inputRef.current?.value) return

window.open(`https://api.whatsapp.com/send/?phone=${phoneNumber}&text=${inputRef.current.value}`)
window.open(`https://api.whatsapp.com/send/?phone=${phoneNumber}&text=${defaultMessage ?? ''}${inputRef.current.value}`)
if (onSubmit) onSubmit(event, inputRef.current.value)
inputRef.current.value = ''
}
Expand Down
3 changes: 2 additions & 1 deletion src/stories/FloatingWhatsapp.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const Template: ComponentStory<typeof FloatingWhatsApp> = (args) => <FloatingWha
export const Default = Template.bind({})
Default.args = {
accountName: 'John Doe',
phoneNumber: '1234567890'
phoneNumber: '1234567890',
defaultMessage: ''
}

export const DarkMode = Template.bind({})
Expand Down