Skip to content

Commit d28d46b

Browse files
committed
Add icons for editing url
1 parent 802ed7d commit d28d46b

File tree

6 files changed

+24
-8
lines changed

6 files changed

+24
-8
lines changed

packages/gitbook/src/components/DocumentView/OpenAPI/OpenAPI.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ async function OpenAPIBody(props: BlockProps<DocumentBlockSwagger>) {
5454
icons: {
5555
chevronDown: <Icon icon="chevron-down" />,
5656
chevronRight: <Icon icon="chevron-right" />,
57+
edit: <Icon icon="edit" />,
58+
clear: <Icon icon="x" />
5759
},
5860
CodeBlock: PlainCodeBlock,
5961
defaultInteractiveOpened: context.mode === 'print',

packages/gitbook/src/components/DocumentView/OpenAPI/style.css

+14-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
/** URL */
5858

5959
.openapi-url {
60-
@apply font-mono text-sm text-dark/8 dark:text-light/8;
60+
@apply flex items-center font-mono text-sm text-dark/8 dark:text-light/8;
6161
}
6262

6363
.openapi-url-var {
@@ -365,6 +365,17 @@
365365
@apply mb-0;
366366
}
367367

368-
.openapi-server-button {
369-
@apply disabled:opacity-5;
368+
.openapi-select-button,
369+
.openapi-edit-button {
370+
@apply p-0.5 inline-flex text-dark/6 dark:text-light/6 hover:opacity-8;
371+
}
372+
373+
.openapi-edit-button { @apply p-0.5 ml-4 size-4; }
374+
375+
.openapi-edit-button > * {
376+
@apply size-full;
377+
}
378+
379+
.openapi-select-button {
380+
@apply leading-[1cap] disabled:opacity-5;
370381
}

packages/react-openapi/src/OpenAPIOperation.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export async function OpenAPIOperation(props: {
3737
{operation.description ? (
3838
<Markdown className="openapi-description" source={operation.description} />
3939
) : null}
40-
<div className="openapi-target">
40+
<div className="openapi-target flex items-center">
4141
<span
4242
className={classNames(
4343
'openapi-method',

packages/react-openapi/src/OpenAPIServerURLForm.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export function ServerURLForm(props: {
4949
});
5050
}
5151

52+
const isEditable = servers.length > 1 || server.variables;
5253
return (
5354
<form ref={formRef} onSubmit={e => { e.preventDefault(); updateServerVariables(new FormData(e.currentTarget)); }} className="contents">
5455
<fieldset disabled={ctx?.isPending} className="contents">
@@ -61,11 +62,11 @@ export function ServerURLForm(props: {
6162
onChange={switchServer}
6263
/>
6364
) : null}
64-
<button className='inline-flex pl-4' onClick={() => {
65+
{ isEditable ? <button className='openapi-edit-button ml-2' onClick={() => {
6566
const state = { ...ctx?.state };
6667
delete state.edit;
6768
update({ server: `${serverIndex}`, ...state, ...(ctx?.state?.edit ? undefined : { edit: 'true' }) });
68-
}} aria-label={ctx?.state?.edit ? "Clear" : "Edit"}>{ctx?.state?.edit ? 'X' : 'Edit'}</button>
69+
}} title={ctx?.state?.edit ? undefined : "Try different server options"} aria-label={ctx?.state?.edit ? "Clear" : "Edit"}>{ctx?.state?.edit ? context.icons.clear : context.icons.edit}</button> : null}
6970
</fieldset>
7071
</form>
7172
);

packages/react-openapi/src/ServerSelector.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function ServerSelector(props: {
1818
<span className="inline-flex pl-4 gap-2">
1919
<input type="hidden" value={`${index}`} name="server" />
2020
<button
21-
className="openapi-server-button"
21+
className="openapi-select-button"
2222
disabled={index === 0}
2323
onClick={(e) => {
2424
e.preventDefault();
@@ -31,7 +31,7 @@ export function ServerSelector(props: {
3131
3232
</button>
3333
<button
34-
className="openapi-server-button"
34+
className="openapi-select-button"
3535
disabled={index >= servers.length - 1}
3636
onClick={(e) => {
3737
e.preventDefault();

packages/react-openapi/src/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export interface OpenAPIClientContext {
88
icons: {
99
chevronDown: React.ReactNode;
1010
chevronRight: React.ReactNode;
11+
edit: React.ReactNode;
12+
clear: React.ReactNode;
1113
};
1214

1315
/**

0 commit comments

Comments
 (0)