Skip to content

Instantly share code, notes, and snippets.

@ruucm-working
Created May 29, 2025 07:23
Show Gist options
  • Save ruucm-working/f905e0064aff02127a4bfc5ac64f70a5 to your computer and use it in GitHub Desktop.
Save ruucm-working/f905e0064aff02127a4bfc5ac64f70a5 to your computer and use it in GitHub Desktop.
// Get Started: https://www.framer.com/developers
import { addPropertyControls, ControlType } from "framer"
import { useState } from "react"
/**
* @framerSupportedLayoutWidth auto
* @framerSupportedLayoutHeight auto
*/
export default function Button({ title, loadingText }) {
const [text, setText] = useState("")
const [isLoading, setIsLoading] = useState(false)
const handleStart = () => {
if (!("webkitSpeechRecognition" in window)) {
alert("Not supported Browser")
return
}
// @ts-ignore
const recognition = new window.webkitSpeechRecognition()
recognition.lang = "ko-KR"
recognition.interimResults = false
setIsLoading(true)
recognition.onresult = (event) => {
const transcript = event.results[0][0].transcript
setText(transcript)
setIsLoading(false)
}
recognition.onerror = (event) => {
console.error("Speech recognition error", event)
setText("Error")
setIsLoading(false)
}
recognition.onend = () => {
setIsLoading(false)
}
recognition.start()
}
return (
<div style={{ textAlign: "center", marginTop: "100px" }}>
<div style={{ marginBottom: "20px", fontSize: "1.5rem" }}>
{text}
</div>
<button
onClick={handleStart}
style={{
backgroundColor: "black",
color: "white",
paddingTop: 8,
paddingBottom: 8,
paddingLeft: 12,
paddingRight: 12,
borderRadius: 10,
fontSize: 14,
border: "none",
fontFamily: "Inter",
fontWeight: 500,
cursor: "pointer",
}}
>
{isLoading ? loadingText : title}
</button>
</div>
)
}
addPropertyControls(Button, {
title: {
type: ControlType.String,
defaultValue: "Button",
},
loadingText: {
type: ControlType.String,
defaultValue: "Loading...",
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment