Skip to content

Commit 033bd5f

Browse files
feat: added NPM Downloads component (#52)
1 parent f255e5f commit 033bd5f

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ function Demo() {
8787
</Npm>
8888
```
8989

90+
### Npm.Downloads
91+
92+
```jsx
93+
<Npm.Downloads scope="@uiw" packageName="react-shields" />
94+
<Npm>
95+
<Npm.Downloads interval="dw" scope="@uiw" packageName="react-github-corners" />
96+
<Npm.Downloads packageName="hotkeys-js" />
97+
</Npm>
98+
```
99+
90100
### Github.Issues
91101

92102
```jsx

src/npm/Downloads.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import Base, { BaseProps} from '../common/Base';
2+
3+
export interface DownloadProps extends BaseProps {
4+
interval?: 'dw' | 'dm' | 'dy' | 'dt';
5+
packageName?: string;
6+
scope?: string;
7+
}
8+
9+
/**
10+
* Npm Size
11+
*
12+
* `/npm/:interval/:packageName`
13+
* npm downloads: npm downloads per interval badge
14+
*
15+
* `/npm/:interval/:scope/:packageName`
16+
* npm downloads (scoped): npm downloads per interval (scoped version) badge
17+
*
18+
*/
19+
export default class Downloads extends Base<DownloadProps> {
20+
constructor(props: DownloadProps) {
21+
super(props, { interval: 'dm' }, { platform: 'npm' });
22+
};
23+
getUrl = () => {
24+
const { base, platform, interval, packageName, scope } = this.state;
25+
if (platform !== 'npm' || !packageName) return '';
26+
27+
const url = [base, 'npm', interval];
28+
29+
if (scope) {
30+
url.push(scope);
31+
}
32+
33+
url.push(packageName);
34+
35+
return url.join('/');
36+
}
37+
}

src/npm/Npm.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import Container from '../common/Container';
22
import Version from './Version';
33
import Size from './Size';
4+
import Downloads from './Downloads';
45

56
export default class Npm extends Container {
67
static Version = Version;
78
static Size = Size;
9+
static Downloads = Downloads;
810
}

website/App.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ const App: React.FC = () => {
4444
<Npm.Size packageName="kkt" version="5.0.0-alpha.12" />
4545
</Npm>
4646
</div>
47+
<div className="App-list">
48+
<div className="title">Npm Downloads</div>
49+
<Npm.Downloads scope="@uiw" packageName="react-shields" />
50+
<Npm>
51+
<Npm.Downloads interval="dw" scope="@uiw" packageName="react-github-corners" />
52+
<Npm.Downloads packageName="hotkeys-js" />
53+
</Npm>
54+
</div>
4755
<div className="App-list">
4856
<div className="title">Github Issue</div>
4957
<Github.Issues user="uiwjs" repo="uiw" />

0 commit comments

Comments
 (0)