Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use html5 details element instead of javascript #2531

Merged
merged 4 commits into from
Mar 2, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 17 additions & 35 deletions static/js/api_endpoint.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,27 @@ import React from 'react';
// Styles for this element is defined in src/css/custom.css

export default class ApiEndpoint extends React.Component {
constructor(props){
super(props);
this.state = {
open: false
}
this.toggleInfo = this.toggleInfo.bind(this);
}

toggleInfo(e){
this.setState({open: !this.state.open})
}

render() {
return (
<div className="api-endpoint">
<div
onClick={this.toggleInfo}
className="api-endpoint-header"
>
<div className={`api-endpoint-method ${ this.props.method }`}>
<details className="api-endpoint">
<summary className="api-endpoint-header">
<div className={`api-endpoint-method ${this.props.method}`}>
{this.props.method}
</div>
<code>{this.props.path}</code>
<div
className="api-endpoint-protection"
title={this.props.unprotected ?
"Authentication is not required for this endpoint"
: "Authentication is required for this endpoint"
}
>
{this.props.unprotected ? ("🔓") : ("🔒")}
</div>
<code>{this.props.path}</code>
<div
className="api-endpoint-protection"
title={
this.props.unprotected
? 'Authentication is not required for this endpoint'
: 'Authentication is required for this endpoint'
}>
{this.props.unprotected ? '🔓' : '🔒'}
</div>
{this.state.open ? (
<div className="api-endpoint-content">
{this.props.children}
</div>
): null}
</div>
</summary>

<div className="api-endpoint-content">{this.props.children}</div>
</details>
);
}
}
}