-
Notifications
You must be signed in to change notification settings - Fork 828
Expand file tree
/
Copy pathindex.tsx
More file actions
152 lines (145 loc) · 5.46 KB
/
index.tsx
File metadata and controls
152 lines (145 loc) · 5.46 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import { Platform, View } from 'react-native';
import { A, HoverEffect, useLayout } from '~/common/styleguide';
import BookmarkButton from '~/components/BookmarkButton';
import CompatibilityTags from '~/components/CompatibilityTags';
import { GitHubIcon } from '~/components/Icons';
import LibraryDescription from '~/components/Library/LibraryDescription';
import UpdatedAtView from '~/components/Library/UpdatedAtView';
import Tooltip from '~/components/Tooltip';
import { type LibraryType } from '~/types';
import tw from '~/util/tailwind';
import MetaData from './MetaData';
import Thumbnail from './Thumbnail';
import TrendingMark from './TrendingMark';
import UnmaintainedLabel from './UnmaintainedLabel';
type Props = {
library: LibraryType;
skipMetadata?: boolean;
skipSecondaryMetadata?: boolean;
skipDate?: boolean;
showTrendingMark?: boolean;
};
export default function Library({
library,
skipMetadata,
skipDate,
skipSecondaryMetadata,
showTrendingMark,
}: Props) {
const { github } = library;
const { isSmallScreen, isBelowMaxWidth } = useLayout();
const libName = library.npmPkg ?? github.fullName;
const hasSecondaryMetadata =
github.license ||
github.urls.homepage ||
github.newArchitecture ||
library.newArchitecture ||
(library.examples && library.examples.length);
return (
<View
style={[
tw`relative mb-4 flex-row overflow-hidden rounded-md border border-palette-gray2 dark:border-default`,
isSmallScreen && tw`flex-col`,
skipMetadata && tw`mx-[0.75%] min-h-[206px] w-[48.5%]`,
skipMetadata && (isSmallScreen || isBelowMaxWidth) && tw`w-[98.5%] max-w-[98.5%]`,
skipSecondaryMetadata && tw`min-h-0`,
library.unmaintained && tw`opacity-85`,
]}>
{!isSmallScreen && (
<BookmarkButton
bookmarkId={libName}
style={tw`absolute right-2.5 top-2.5 z-10 rounded border border-palette-gray2 p-1.5 dark:border-palette-gray6`}
/>
)}
<View
style={[
tw`flex-1 p-4 pb-3 pl-5`,
showTrendingMark && tw`pt-3.5`,
isSmallScreen && tw`px-3.5 pt-2.5`,
showTrendingMark && isSmallScreen && tw`pb-2 pl-3.5 pr-4 pt-3.5`,
]}>
{library.unmaintained && (
<View
style={
isSmallScreen
? tw`mb-1.5 flex-col justify-start self-start`
: tw`mb-1 flex-row items-start justify-between gap-6`
}>
<UnmaintainedLabel alternatives={library.alternatives} />
{!skipDate && <UpdatedAtView library={library} />}
</View>
)}
{showTrendingMark && library.popularity && (
<View
style={[
tw`mb-0.5 flex-row items-center justify-between gap-6`,
!isSmallScreen && skipMetadata && tw`pr-8`,
]}>
<Tooltip sideOffset={8} trigger={<TrendingMark library={library} />}>
Trending Score is based on the last week to last month download rate.
</Tooltip>
{!skipDate && !library.unmaintained && <UpdatedAtView library={library} />}
</View>
)}
<View
style={
isSmallScreen
? tw`w-full flex-col justify-start gap-2 self-start`
: tw`flex-row items-start justify-between gap-6`
}>
<View style={tw`flex-row items-center gap-1.5`}>
<A
href={`/package/${library.npmPkg}`}
style={tw`text-[19px] font-bold`}
hoverStyle={tw`text-hover`}>
{libName}
</A>
<HoverEffect>
<A href={library.githubUrl} style={tw`size-5`} aria-label="GitHub repository">
<GitHubIcon style={tw`size-5 text-palette-gray5 dark:text-palette-gray4`} />
</A>
</HoverEffect>
{isSmallScreen && (
<BookmarkButton
bookmarkId={libName}
style={tw`-mr-1 ml-auto size-7 items-center justify-center rounded border border-palette-gray2 p-1 dark:border-palette-gray6`}
/>
)}
</View>
{!showTrendingMark && !skipDate && !library.unmaintained && (
<UpdatedAtView library={library} />
)}
</View>
<View style={tw`mt-3`}>
<CompatibilityTags library={library} />
</View>
<View style={tw`mt-3`}>
<LibraryDescription github={library.github} maxLines={skipMetadata ? 3 : undefined} />
</View>
{!skipMetadata && Platform.OS === 'web' && library.images && library.images.length > 0 && (
<View style={tw`mt-2 flex-row flex-wrap items-center gap-x-0.5`}>
{library.images.map(image => (
<Thumbnail key={image} url={image} name={libName} />
))}
</View>
)}
{!skipSecondaryMetadata && hasSecondaryMetadata ? (
<View style={[tw`mt-auto w-full`, isSmallScreen && tw`relative mt-0 min-h-0`]}>
<View style={[tw`mt-3 flex-row flex-wrap items-center gap-2.5 gap-y-0.5`]}>
<MetaData library={library} secondary />
</View>
</View>
) : null}
</View>
{skipMetadata ? null : (
<View
style={[
tw`flex-0.35 border-l border-palette-gray2 p-4 dark:border-default`,
isSmallScreen && tw`border-l-0 border-t`,
]}>
<MetaData library={library} />
</View>
)}
</View>
);
}