Skip to content

Commit

Permalink
feat: added NPM Downloads component (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
cecilia-sanare authored Aug 5, 2023
1 parent f255e5f commit 033bd5f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ function Demo() {
</Npm>
```

### Npm.Downloads

```jsx
<Npm.Downloads scope="@uiw" packageName="react-shields" />
<Npm>
<Npm.Downloads interval="dw" scope="@uiw" packageName="react-github-corners" />
<Npm.Downloads packageName="hotkeys-js" />
</Npm>
```

### Github.Issues

```jsx
Expand Down
37 changes: 37 additions & 0 deletions src/npm/Downloads.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Base, { BaseProps} from '../common/Base';

export interface DownloadProps extends BaseProps {
interval?: 'dw' | 'dm' | 'dy' | 'dt';
packageName?: string;
scope?: string;
}

/**
* Npm Size
*
* `/npm/:interval/:packageName`
* npm downloads: npm downloads per interval badge
*
* `/npm/:interval/:scope/:packageName`
* npm downloads (scoped): npm downloads per interval (scoped version) badge
*
*/
export default class Downloads extends Base<DownloadProps> {
constructor(props: DownloadProps) {
super(props, { interval: 'dm' }, { platform: 'npm' });
};
getUrl = () => {
const { base, platform, interval, packageName, scope } = this.state;
if (platform !== 'npm' || !packageName) return '';

const url = [base, 'npm', interval];

if (scope) {
url.push(scope);
}

url.push(packageName);

return url.join('/');
}
}
2 changes: 2 additions & 0 deletions src/npm/Npm.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Container from '../common/Container';
import Version from './Version';
import Size from './Size';
import Downloads from './Downloads';

export default class Npm extends Container {
static Version = Version;
static Size = Size;
static Downloads = Downloads;
}
8 changes: 8 additions & 0 deletions website/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ const App: React.FC = () => {
<Npm.Size packageName="kkt" version="5.0.0-alpha.12" />
</Npm>
</div>
<div className="App-list">
<div className="title">Npm Downloads</div>
<Npm.Downloads scope="@uiw" packageName="react-shields" />
<Npm>
<Npm.Downloads interval="dw" scope="@uiw" packageName="react-github-corners" />
<Npm.Downloads packageName="hotkeys-js" />
</Npm>
</div>
<div className="App-list">
<div className="title">Github Issue</div>
<Github.Issues user="uiwjs" repo="uiw" />
Expand Down

0 comments on commit 033bd5f

Please sign in to comment.