Skip to content

Commit 9333526

Browse files
committed
Create url.stories.tsx
1 parent 5c0048d commit 9333526

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

stories/url.stories.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React, { useState } from "react";
2+
import { RichTextarea, createRegexRenderer } from "../src";
3+
4+
export default {
5+
title: "examples",
6+
};
7+
8+
const style = { width: "400px", height: "300px" };
9+
10+
const regexRenderer = createRegexRenderer([
11+
[
12+
/https?:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+/g,
13+
({ children, key, value }) => (
14+
<a
15+
key={key}
16+
style={{ color: "blue", textDecoration: "underline" }}
17+
href={value}
18+
target="_blank"
19+
>
20+
{children}
21+
</a>
22+
),
23+
],
24+
]);
25+
26+
export const Url = () => {
27+
const [text, setText] = useState(
28+
`Click this url https://github.com/inokawa/rich-textarea !\n\n`
29+
);
30+
31+
return (
32+
<div>
33+
<RichTextarea
34+
style={style}
35+
onChange={(e) => setText(e.target.value)}
36+
value={text}
37+
>
38+
{regexRenderer}
39+
</RichTextarea>
40+
</div>
41+
);
42+
};

0 commit comments

Comments
 (0)