Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit cc7eafb

Browse files
author
Dom Harrington
committed
Make booleans appear as a dropdown
This makes styling booleans so much easier as they just inherit dropdown styles
1 parent 8c39550 commit cc7eafb

File tree

3 files changed

+25
-30
lines changed

3 files changed

+25
-30
lines changed

packages/api-explorer/api-explorer.css

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -130,36 +130,6 @@ fieldset fieldset .form-group label {
130130
margin-left: 15px;
131131
}
132132

133-
/* Fix how booleans are displayed. */
134-
.checkbox {
135-
display: flex;
136-
flex-flow: row nowrap;
137-
justify-content: flex-start;
138-
align-items: center;
139-
align-content: space-around;
140-
}
141-
142-
.checkbox :nth-child(1) {
143-
order: 2;
144-
}
145-
146-
.checkbox :nth-child(2) {
147-
order: 1;
148-
}
149-
150-
.checkbox > .field-description {
151-
margin-left: 1em;
152-
}
153-
154-
.checkbox > label {
155-
font-size: 14px !important;
156-
font-weight: bold;
157-
}
158-
159-
.checkbox input[type='checkbox'] {
160-
margin-right: 1em;
161-
}
162-
163133
/* Style select boxes. */
164134

165135
.field .form-group select {

packages/api-explorer/src/Params.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const DateTimeWidget = require('react-jsonschema-form/lib/components/widgets/Dat
1010
const createBaseInput = require('./form-components/BaseInput');
1111
const createSelectWidget = require('./form-components/SelectWidget');
1212
const createArrayField = require('./form-components/ArrayField');
13+
const createSchemaField = require('./form-components/SchemaField');
1314
const Oas = require('./lib/Oas');
1415

1516
const { Operation } = Oas;
@@ -20,6 +21,7 @@ function Params({ oas, operation, formData, onChange, onSubmit }) {
2021
const BaseInput = createBaseInput(oas);
2122
const SelectWidget = createSelectWidget(oas);
2223
const ArrayField = createArrayField(oas);
24+
const SchemaField = createSchemaField(oas);
2325

2426
return (
2527
jsonSchema &&
@@ -56,6 +58,7 @@ function Params({ oas, operation, formData, onChange, onSubmit }) {
5658
fields={{
5759
// DescriptionField,
5860
ArrayField,
61+
SchemaField,
5962
}}
6063
>
6164
<button type="submit" style={{ display: 'none' }} />
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const React = require('react');
2+
const extensions = require('@readme/oas-extensions');
3+
4+
const SchemaField = require('react-jsonschema-form/lib/components/fields/SchemaField').default;
5+
6+
function createSchemaField(oas) {
7+
const explorerEnabled = oas[extensions.EXPLORER_ENABLED];
8+
9+
return function (props) {
10+
// if (!explorerEnabled) {
11+
// props.uiSchema = Object.assign(props.uiSchema, { "ui:options": { addable: false }})
12+
// };
13+
14+
if (props.schema.type === 'boolean') {
15+
props.schema.enumNames = ['true', 'false']
16+
return <SchemaField {...props} uiSchema={{ "ui:widget": "select" }} />
17+
}
18+
return <SchemaField {...props} />
19+
}
20+
}
21+
22+
module.exports = createSchemaField;

0 commit comments

Comments
 (0)