-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[redesign] move docs components to
@graphiql/react
(#2582)
* move explorer context into folder * move `TypeLink` component to `@graphiql/react` * move `FieldLink` component to `@graphiql/react` * move `DefaultValue` component to `@graphiql/react` * move `Directive` component to `@graphiql/react` * extract `MarkdownContent` component in `@gaphiql/react` * move `Argument` component to `@graphiql/react` * combine and extend changesets
- Loading branch information
1 parent
e54b5c8
commit 1a06818
Showing
42 changed files
with
413 additions
and
371 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
packages/graphiql-react/src/explorer/components/__tests__/test-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { GraphQLNamedType, GraphQLType } from 'graphql'; | ||
|
||
import { ExplorerContextType, ExplorerNavStackItem } from '../../context'; | ||
|
||
export function mockExplorerContextValue( | ||
navStackItem: ExplorerNavStackItem, | ||
): ExplorerContextType { | ||
return { | ||
explorerNavStack: [navStackItem], | ||
hide() {}, | ||
isVisible: true, | ||
pop() {}, | ||
push() {}, | ||
reset() {}, | ||
show() {}, | ||
showSearch() {}, | ||
}; | ||
} | ||
|
||
export function unwrapType(type: GraphQLType): GraphQLNamedType { | ||
return 'ofType' in type ? unwrapType(type.ofType) : type; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/graphiql-react/src/explorer/components/argument.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.graphiql-doc-explorer-argument { | ||
& > * + * { | ||
margin-top: var(--px-12); | ||
} | ||
} | ||
|
||
.graphiql-doc-explorer-argument-name { | ||
color: var(--color-purple); | ||
} | ||
|
||
.graphiql-doc-explorer-argument-deprecation { | ||
background-color: var(--color-orche-background); | ||
border: 1px solid var(--color-orche); | ||
border-radius: var(--border-radius-4); | ||
color: var(--color-orche); | ||
padding: var(--px-8); | ||
} | ||
|
||
.graphiql-doc-explorer-argument-deprecation-label { | ||
font-size: var(--font-size-hint); | ||
font-weight: var(--font-weight-medium); | ||
} |
45 changes: 45 additions & 0 deletions
45
packages/graphiql-react/src/explorer/components/argument.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { GraphQLArgument } from 'graphql'; | ||
|
||
import { DefaultValue } from './default-value'; | ||
import { TypeLink } from './type-link'; | ||
|
||
import './argument.css'; | ||
import { MarkdownContent } from '../../ui'; | ||
|
||
type ArgumentProps = { | ||
arg: GraphQLArgument; | ||
showDefaultValue?: boolean; | ||
inline?: boolean; | ||
}; | ||
|
||
export function Argument({ arg, showDefaultValue, inline }: ArgumentProps) { | ||
const definition = ( | ||
<span> | ||
<span className="graphiql-doc-explorer-argument-name">{arg.name}</span> | ||
{': '} | ||
<TypeLink type={arg.type} /> | ||
{showDefaultValue !== false && <DefaultValue field={arg} />} | ||
</span> | ||
); | ||
if (inline) { | ||
return definition; | ||
} | ||
return ( | ||
<div className="graphiql-doc-explorer-argument"> | ||
{definition} | ||
{arg.description ? ( | ||
<MarkdownContent type="description">{arg.description}</MarkdownContent> | ||
) : null} | ||
{arg.deprecationReason ? ( | ||
<div className="graphiql-doc-explorer-argument-deprecation"> | ||
<div className="graphiql-doc-explorer-argument-deprecation-label"> | ||
Deprecated | ||
</div> | ||
<MarkdownContent type="deprecation"> | ||
{arg.deprecationReason} | ||
</MarkdownContent> | ||
</div> | ||
) : null} | ||
</div> | ||
); | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/graphiql-react/src/explorer/components/default-value.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.graphiql-doc-explorer-default-value { | ||
color: var(--color-green); | ||
} |
34 changes: 34 additions & 0 deletions
34
packages/graphiql-react/src/explorer/components/default-value.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { astFromValue, print, ValueNode } from 'graphql'; | ||
|
||
import { ExplorerFieldDef } from '../context'; | ||
|
||
import './default-value.css'; | ||
|
||
const printDefault = (ast?: ValueNode | null): string => { | ||
if (!ast) { | ||
return ''; | ||
} | ||
return print(ast); | ||
}; | ||
|
||
type DefaultValueProps = { | ||
field: ExplorerFieldDef; | ||
}; | ||
|
||
export function DefaultValue({ field }: DefaultValueProps) { | ||
if (!('defaultValue' in field) || field.defaultValue === undefined) { | ||
return null; | ||
} | ||
const ast = astFromValue(field.defaultValue, field.type); | ||
if (!ast) { | ||
return null; | ||
} | ||
return ( | ||
<> | ||
{' = '} | ||
<span className="graphiql-doc-explorer-default-value"> | ||
{printDefault(ast)} | ||
</span> | ||
</> | ||
); | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/graphiql-react/src/explorer/components/directive.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.graphiql-doc-explorer-directive { | ||
color: var(--color-purple); | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/graphiql-react/src/explorer/components/directive.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { DirectiveNode } from 'graphql'; | ||
|
||
import './directive.css'; | ||
|
||
type DirectiveProps = { | ||
directive: DirectiveNode; | ||
}; | ||
|
||
export function Directive({ directive }: DirectiveProps) { | ||
return ( | ||
<span className="graphiql-doc-explorer-directive"> | ||
@{directive.name.value} | ||
</span> | ||
); | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/graphiql-react/src/explorer/components/field-link.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.graphiql-doc-explorer-field-name { | ||
color: var(--color-blue); | ||
text-decoration: none; | ||
|
||
&:hover { | ||
text-decoration: underline; | ||
} | ||
|
||
&:focus { | ||
outline: var(--color-blue) auto 1px; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/graphiql-react/src/explorer/components/field-link.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ExplorerFieldDef, useExplorerContext } from '../context'; | ||
|
||
import './field-link.css'; | ||
|
||
type FieldLinkProps = { | ||
field: ExplorerFieldDef; | ||
}; | ||
|
||
export function FieldLink(props: FieldLinkProps) { | ||
const { push } = useExplorerContext({ nonNull: true }); | ||
|
||
return ( | ||
<a | ||
className="graphiql-doc-explorer-field-name" | ||
onClick={event => { | ||
event.preventDefault(); | ||
push({ name: props.field.name, def: props.field }); | ||
}} | ||
href="#" | ||
> | ||
{props.field.name} | ||
</a> | ||
); | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/graphiql-react/src/explorer/components/type-link.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.graphiql-doc-explorer-type-name { | ||
color: var(--color-orche); | ||
text-decoration: none; | ||
|
||
&:hover { | ||
text-decoration: underline; | ||
} | ||
|
||
&:focus { | ||
outline: var(--color-orche) auto 1px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export { Argument } from './components/argument'; | ||
export { DefaultValue } from './components/default-value'; | ||
export { Directive } from './components/directive'; | ||
export { FieldLink } from './components/field-link'; | ||
export { TypeLink } from './components/type-link'; | ||
export { | ||
ExplorerContext, | ||
ExplorerContextProvider, | ||
useExplorerContext, | ||
} from './context'; | ||
|
||
export type { | ||
ExplorerContextType, | ||
ExplorerFieldDef, | ||
ExplorerNavStack, | ||
ExplorerNavStackItem, | ||
} from './context'; |
Oops, something went wrong.