81 lines
2.0 KiB
JavaScript
81 lines
2.0 KiB
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
|
|
import DirectoryListing from './DirectoryListing';
|
|
|
|
export default class App extends React.Component {
|
|
static defaultProps = {
|
|
availableVersions: []
|
|
};
|
|
|
|
handleChange = event => {
|
|
window.location.href = window.location.href.replace(
|
|
'@' + this.props.packageVersion,
|
|
'@' + event.target.value
|
|
);
|
|
};
|
|
|
|
render() {
|
|
return (
|
|
<div css={{ maxWidth: 900, margin: '0 auto' }}>
|
|
<header
|
|
css={{
|
|
display: 'flex',
|
|
flexDirection: 'row',
|
|
alignItems: 'center',
|
|
justifyContent: 'space-between'
|
|
}}
|
|
>
|
|
<h1>
|
|
Index of /{this.props.packageName}@{this.props.packageVersion}
|
|
{this.props.filename}
|
|
</h1>
|
|
|
|
<div css={{ float: 'right', lineHeight: '2.25em' }}>
|
|
Version:{' '}
|
|
<select
|
|
id="version"
|
|
defaultValue={this.props.packageVersion}
|
|
onChange={this.handleChange}
|
|
css={{ fontSize: '1em' }}
|
|
>
|
|
{this.props.availableVersions.map(v => (
|
|
<option key={v} value={v}>
|
|
{v}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</div>
|
|
</header>
|
|
|
|
<hr />
|
|
|
|
<DirectoryListing
|
|
filename={this.props.filename}
|
|
entry={this.props.entry}
|
|
entries={this.props.entries}
|
|
/>
|
|
|
|
<hr />
|
|
|
|
<address css={{ textAlign: 'right' }}>
|
|
{this.props.packageName}@{this.props.packageVersion}
|
|
</address>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
const entryType = PropTypes.object;
|
|
|
|
App.propTypes = {
|
|
packageName: PropTypes.string.isRequired,
|
|
packageVersion: PropTypes.string.isRequired,
|
|
availableVersions: PropTypes.arrayOf(PropTypes.string),
|
|
filename: PropTypes.string.isRequired,
|
|
entry: entryType.isRequired,
|
|
entries: PropTypes.objectOf(entryType).isRequired
|
|
};
|
|
}
|