MCPcopy Create free account
hub / github.com/MagicCube/agentara / WebPreviewUrl

Function WebPreviewUrl

web/src/components/ai-elements/web-preview.tsx:142–184  ·  view source on GitHub ↗
({
  value,
  onChange,
  onKeyDown,
  ...props
}: WebPreviewUrlProps)

Source from the content-addressed store, hash-verified

140export type WebPreviewUrlProps = ComponentProps<typeof Input>;
141
142export const WebPreviewUrl = ({
143 value,
144 onChange,
145 onKeyDown,
146 ...props
147}: WebPreviewUrlProps) => {
148 const { url, setUrl } = useWebPreview();
149 const [prevUrl, setPrevUrl] = useState(url);
150 const [inputValue, setInputValue] = useState(url);
151
152 // Sync input value with context URL when it changes externally (derived state pattern)
153 if (url !== prevUrl) {
154 setPrevUrl(url);
155 setInputValue(url);
156 }
157
158 const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
159 setInputValue(event.target.value);
160 onChange?.(event);
161 };
162
163 const handleKeyDown = useCallback(
164 (event: React.KeyboardEvent<HTMLInputElement>) => {
165 if (event.key === "Enter") {
166 const target = event.target as HTMLInputElement;
167 setUrl(target.value);
168 }
169 onKeyDown?.(event);
170 },
171 [setUrl, onKeyDown]
172 );
173
174 return (
175 <Input
176 className="h-8 flex-1 text-sm"
177 onChange={onChange ?? handleChange}
178 onKeyDown={handleKeyDown}
179 placeholder="Enter URL..."
180 value={value ?? inputValue}
181 {...props}
182 />
183 );
184};
185
186export type WebPreviewBodyProps = ComponentProps<"iframe"> & {
187 loading?: ReactNode;

Callers

nothing calls this directly

Calls 1

useWebPreviewFunction · 0.85

Tested by

no test coverage detected