forked from Dhaiwat10/react-link-preview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinkPreview.stories.tsx
93 lines (89 loc) · 3.51 KB
/
LinkPreview.stories.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import React from 'react';
import { storiesOf } from '@storybook/react';
import { LinkPreview } from './LinkPreview';
const customFetcher = async (url: string) => {
const response = await fetch(`http://localhost:3000/parse-link?url=${url}`);
const json = await response.json();
return {
title: json.title,
description: json.description,
image: json.image,
cardType: json.image_x === json.image_y || json.image_x < 300 ? 'square' : 'rectangle',
siteName: json.site_name,
hostname: (new URL(url)).hostname,
};
};
storiesOf('LinkPreview', module)
.add('Default', () => <LinkPreview url='https://barcauniversal.com' fetcher={customFetcher} />)
.add('Default2', () => <LinkPreview descriptionLength={90} url='https://www.paradigm.xyz/2022/08/das' fetcher={customFetcher} />)
.add('Article', () => (
<LinkPreview url='https://barcauniversal.com/predicted-barcelona-lineup-against-eibar/' fetcher={customFetcher} />
))
.add('Text align right', () => (
<LinkPreview
url='https://barcauniversal.com/predicted-barcelona-lineup-against-eibar/'
textAlign='right'
fetcher={customFetcher}
/>
))
.add('Custom image height', () => (
<LinkPreview
url='https://barcauniversal.com/predicted-barcelona-lineup-against-eibar/'
imageHeight='50vh'
fetcher={customFetcher}
/>
))
.add('YouTube link', () => (
<LinkPreview url='https://www.youtube.com/watch?v=JKJdGNHW1xk' fetcher={customFetcher} />
))
.add('Twitter link', () => (
<LinkPreview url='https://twitter.com/BarcaUniversal/status/1396232440314830856' fetcher={customFetcher} />
))
.add('Reddit link', () => (
<LinkPreview
url='https://www.reddit.com/r/LifeProTips/comments/nivqb3/lpt_if_your_your_largest_hex_key_is_to_small_you/'
descriptionLength={100}
fetcher={customFetcher}
/>
))
.add('Fallback', () => <LinkPreview url='https://webzy.dev' fallback={<div>Fallback</div>} fetcher={customFetcher} />)
.add('Colors', () => (
<LinkPreview
url='https://www.youtube.com/watch?v=dQw4w9WgXcQ'
backgroundColor='black'
primaryTextColor='white'
secondaryTextColor='#ccc'
borderColor='red'
margin='30px auto'
fetcher={customFetcher}
/>
))
.add('Fallback image', () => (
<LinkPreview
url='https://google.com'
fallbackImageSrc='https://www.aljazeera.com/wp-content/uploads/2021/08/2019-12-07T000000Z_879038429_RC2LQD9L67FQ_RTRMADP_3_SOCCER-SPAIN-FCB-RCD-REPORT.jpg?resize=770%2C513'
fetcher={customFetcher}
/>
))
.add('Using custom fetcher', () => (
<LinkPreview url='https://www.brianfriel.xyz/learning-how-to-build-on-solana/' fetcher={customFetcher} fallback={<div>Fallback</div>} />
))
.add('Image onError', () => (
<LinkPreview url='https://www.brianfriel.xyz/learning-how-to-build-on-solana/' fetcher={customFetcher} />
))
.add('Explicit image', () => (
<LinkPreview
url='https://barcauniversal.com/predicted-barcelona-lineup-against-eibar/'
explicitImageSrc='https://barcauniversal.com/wp-content/uploads/2021/05/1002622558-2048x1365.jpg'
fetcher={customFetcher}
/>
))
.add('Explicit no image in case of no image in metadata', () => (
<LinkPreview url='https://barcauniversal.com' showPlaceholderIfNoImage={false} fetcher={customFetcher} />
))
.add('Square Card Type', () => (
<LinkPreview url='https://danromero.org/books/' fetcher={customFetcher} />
))
.add('Broken Link', () => (
<LinkPreview url='https://redfin.com' fetcher={customFetcher} />
));