-
Notifications
You must be signed in to change notification settings - Fork 1
feat: redesign API reference page #56
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3e2583f
feat: add read-only API overview page (api-v2)
rsbh 72bb6b0
feat: match API overview to Figma design
rsbh c907c08
feat: add View documentation button in API navbar
rsbh 9512309
feat: add playground dialog with auth type switching
rsbh b168258
chore: remove api-v2 PLAN.md
rsbh 53f2a6e
feat: improve playground fields and schema handling
rsbh 29092ba
feat: JSON body editor and response headers in playground
rsbh 6331266
chore: remove old API components replaced by api-v2
rsbh 0912fad
feat: redesign API sidebar and fix method colors
rsbh b1ebc1c
refactor: rename api-v2 to api, use Flex for sidebar
rsbh 864e3ac
refactor: replace layout divs with Flex components
rsbh be55a31
fix: address CodeRabbit PR review comments
rsbh 719bdee
fix: revert broken Flex refactor in playground, keep valid fixes
rsbh 552d79f
fix: move useState before early return in ResponseSection
rsbh 3c1e106
fix: address remaining CodeRabbit PR comments
rsbh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
packages/chronicle/src/components/api/api-code-snippet.module.css
This file contains hidden or 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,23 @@ | ||
| .container { | ||
| border: 0.5px solid var(--rs-color-border-base-primary); | ||
| border-radius: var(--rs-radius-2); | ||
| overflow: hidden; | ||
| width: 100%; | ||
| } | ||
|
|
||
| .header { | ||
| justify-content: space-between; | ||
| } | ||
|
|
||
| .title { | ||
| font-size: var(--rs-font-size-regular); | ||
| font-weight: var(--rs-font-weight-regular); | ||
| line-height: var(--rs-line-height-regular); | ||
| letter-spacing: var(--rs-letter-spacing-regular); | ||
| color: var(--rs-color-foreground-base-primary); | ||
| white-space: nowrap; | ||
| } | ||
|
|
||
| .body { | ||
| background: var(--rs-color-background-base-primary); | ||
| } | ||
64 changes: 64 additions & 0 deletions
64
packages/chronicle/src/components/api/api-code-snippet.tsx
This file contains hidden or 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,64 @@ | ||
| 'use client' | ||
|
|
||
| import { useMemo, useState } from 'react' | ||
| import { CodeBlock, Flex } from '@raystack/apsara' | ||
| import { | ||
| generateCurl, | ||
| generatePython, | ||
| generateGo, | ||
| generateTypeScript, | ||
| } from '@/lib/snippet-generators' | ||
| import styles from './api-code-snippet.module.css' | ||
|
|
||
| interface ApiCodeSnippetProps { | ||
| title: string | ||
| method: string | ||
| url: string | ||
| headers: Record<string, string> | ||
| body?: string | ||
| } | ||
|
|
||
| const languages = [ | ||
| { value: 'curl', label: 'cURL', lang: 'bash', generate: generateCurl }, | ||
| { value: 'python', label: 'Python', lang: 'python', generate: generatePython }, | ||
| { value: 'go', label: 'Go', lang: 'go', generate: generateGo }, | ||
| { value: 'typescript', label: 'TypeScript', lang: 'typescript', generate: generateTypeScript }, | ||
| ] | ||
|
|
||
| export function ApiCodeSnippet({ title, method, url, headers, body }: ApiCodeSnippetProps) { | ||
| const [selected, setSelected] = useState('curl') | ||
| const current = languages.find((l) => l.value === selected) ?? languages[0] | ||
|
|
||
| const code = useMemo( | ||
| () => current.generate({ method, url, headers, body }), | ||
| [current.generate, method, url, headers, body], | ||
| ) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| return ( | ||
| <CodeBlock | ||
| value={selected} | ||
| onValueChange={setSelected} | ||
| className={styles.container} | ||
| > | ||
| <CodeBlock.Header className={styles.header}> | ||
| <CodeBlock.Label className={styles.title}>{title}</CodeBlock.Label> | ||
| <Flex align='center' gap={4}> | ||
| <CodeBlock.LanguageSelect> | ||
| <CodeBlock.LanguageSelectTrigger /> | ||
| <CodeBlock.LanguageSelectContent> | ||
| {languages.map((l) => ( | ||
| <CodeBlock.LanguageSelectItem key={l.value} value={l.value}> | ||
| {l.label} | ||
| </CodeBlock.LanguageSelectItem> | ||
| ))} | ||
| </CodeBlock.LanguageSelectContent> | ||
| </CodeBlock.LanguageSelect> | ||
| <CodeBlock.CopyButton /> | ||
| </Flex> | ||
| </CodeBlock.Header> | ||
| <CodeBlock.Content className={styles.body}> | ||
| <CodeBlock.Code value={selected} language={current.lang}>{code}</CodeBlock.Code> | ||
| </CodeBlock.Content> | ||
| </CodeBlock> | ||
| ) | ||
| } | ||
62 changes: 62 additions & 0 deletions
62
packages/chronicle/src/components/api/api-field-list.module.css
This file contains hidden or 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,62 @@ | ||
| .sectionTitle { | ||
| font-size: var(--rs-font-size-large); | ||
| font-weight: var(--rs-font-weight-medium); | ||
| line-height: var(--rs-line-height-large); | ||
| letter-spacing: var(--rs-letter-spacing-large); | ||
| color: var(--rs-color-foreground-base-primary); | ||
| } | ||
|
|
||
| .fieldItem { | ||
| padding-bottom: var(--rs-space-5); | ||
| border-bottom: 0.5px solid var(--rs-color-border-base-primary); | ||
| } | ||
|
|
||
| .fieldItem:last-child { | ||
| border-bottom: none; | ||
| padding-bottom: 0; | ||
| } | ||
|
|
||
| .fieldType { | ||
| font-size: var(--rs-font-size-small); | ||
| line-height: var(--rs-line-height-small); | ||
| letter-spacing: var(--rs-letter-spacing-small); | ||
| color: var(--rs-color-foreground-base-secondary); | ||
| } | ||
|
|
||
| .fieldDescription { | ||
| font-size: var(--rs-font-size-small); | ||
| line-height: var(--rs-line-height-small); | ||
| letter-spacing: var(--rs-letter-spacing-small); | ||
| color: var(--rs-color-foreground-base-secondary); | ||
| } | ||
|
|
||
| .statusDescription { | ||
| font-size: var(--rs-font-size-regular); | ||
| line-height: var(--rs-line-height-regular); | ||
| color: var(--rs-color-foreground-base-primary); | ||
| } | ||
|
|
||
| .expandButton { | ||
| padding: var(--rs-space-3) var(--rs-space-4); | ||
| border: 1px solid var(--rs-color-border-base-primary); | ||
| border-radius: var(--rs-radius-2); | ||
| background: var(--rs-color-background-base-secondary); | ||
| cursor: pointer; | ||
| width: 100%; | ||
| color: var(--rs-color-foreground-base-primary); | ||
| } | ||
|
|
||
| .expandButton:hover { | ||
| background: var(--rs-color-background-neutral-secondary); | ||
| } | ||
|
|
||
| .expandLabel { | ||
| font-size: var(--rs-font-size-small); | ||
| line-height: var(--rs-line-height-small); | ||
| color: var(--rs-color-foreground-base-primary); | ||
| } | ||
|
|
||
| .childFields { | ||
| padding-left: var(--rs-space-5); | ||
| margin-top: var(--rs-space-3); | ||
| } |
This file contains hidden or 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,87 @@ | ||
| 'use client' | ||
|
|
||
| import { useState, type ReactNode } from 'react' | ||
| import { Badge, Flex } from '@raystack/apsara' | ||
| import { ChevronRightIcon, ChevronDownIcon } from '@radix-ui/react-icons' | ||
| import type { SchemaField } from '@/lib/schema' | ||
| import styles from './api-field-list.module.css' | ||
|
|
||
| interface ApiFieldSectionProps { | ||
| title: string | ||
| fields: SchemaField[] | ||
| headerRight?: ReactNode | ||
| description?: string | ||
| } | ||
|
|
||
| export function ApiFieldSection({ title, fields, headerRight, description }: ApiFieldSectionProps) { | ||
| if (fields.length === 0 && !description) return null | ||
|
|
||
| return ( | ||
| <Flex direction="column" gap={6}> | ||
| <Flex align="center" justify="between"> | ||
| <span className={styles.sectionTitle}>{title}</span> | ||
| {headerRight && ( | ||
| <Flex align="center" gap={3}> | ||
| {headerRight} | ||
| </Flex> | ||
| )} | ||
| </Flex> | ||
| {description && <span className={styles.statusDescription}>{description}</span>} | ||
| <Flex direction="column" gap={5}> | ||
| {fields.map((field) => ( | ||
| <FieldItem key={field.name} field={field} /> | ||
| ))} | ||
| </Flex> | ||
| </Flex> | ||
| ) | ||
| } | ||
|
|
||
| function FieldItem({ field }: { field: SchemaField }) { | ||
| const hasChildren = field.children && field.children.length > 0 | ||
|
|
||
| return ( | ||
| <Flex direction="column" gap={4} className={styles.fieldItem}> | ||
| <Flex align="center" gap={3}> | ||
| <Badge variant="neutral" size="micro">{field.name}</Badge> | ||
| <span className={styles.fieldType}>{field.type}</span> | ||
| </Flex> | ||
| {field.description && ( | ||
| <span className={styles.fieldDescription}>{field.description}</span> | ||
| )} | ||
| {hasChildren && <ExpandableChildren field={field} />} | ||
| </Flex> | ||
| ) | ||
| } | ||
|
|
||
| function ExpandableChildren({ field }: { field: SchemaField }) { | ||
| const [expanded, setExpanded] = useState(false) | ||
|
|
||
| return ( | ||
| <Flex direction="column"> | ||
| <Flex | ||
| align="center" | ||
| justify="between" | ||
| className={styles.expandButton} | ||
| onClick={() => setExpanded(!expanded)} | ||
| role="button" | ||
| tabIndex={0} | ||
| > | ||
| <span className={styles.expandLabel}> | ||
| {expanded ? 'Hide' : 'Show'} child attributes | ||
| </span> | ||
| {expanded ? ( | ||
| <ChevronDownIcon width={16} height={16} /> | ||
| ) : ( | ||
| <ChevronRightIcon width={16} height={16} /> | ||
| )} | ||
| </Flex> | ||
| {expanded && ( | ||
| <Flex direction="column" gap={5} className={styles.childFields}> | ||
| {field.children!.map((child) => ( | ||
| <FieldItem key={child.name} field={child} /> | ||
| ))} | ||
| </Flex> | ||
| )} | ||
| </Flex> | ||
| ) | ||
| } |
65 changes: 65 additions & 0 deletions
65
packages/chronicle/src/components/api/api-overview.module.css
This file contains hidden or 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,65 @@ | ||
| .layout { | ||
| align-items: flex-start; | ||
| justify-content: space-between; | ||
| padding-left: var(--rs-space-9); | ||
| padding-right: var(--rs-space-9); | ||
| width: 100%; | ||
| } | ||
|
|
||
| .left { | ||
| min-width: 0; | ||
| flex: 0 1 545px; | ||
| } | ||
|
|
||
| .right { | ||
| min-width: 376px; | ||
| max-width: 500px; | ||
| width: 100%; | ||
| } | ||
|
|
||
| .title { | ||
| font-family: var(--rs-font-title); | ||
| font-size: var(--rs-font-size-t3); | ||
| font-weight: var(--rs-font-weight-medium); | ||
| line-height: var(--rs-line-height-t3); | ||
| letter-spacing: var(--rs-letter-spacing-t3); | ||
| color: var(--rs-color-foreground-base-primary); | ||
| margin: 0; | ||
| } | ||
|
|
||
| .description { | ||
| font-size: var(--rs-font-size-regular); | ||
| line-height: var(--rs-line-height-regular); | ||
| letter-spacing: var(--rs-letter-spacing-regular); | ||
| color: var(--rs-color-foreground-base-secondary); | ||
| margin: 0; | ||
| } | ||
|
|
||
| .methodBar { | ||
| padding: var(--rs-space-3) 0; | ||
| border-radius: var(--rs-radius-2); | ||
| } | ||
|
|
||
| .path { | ||
| font-family: var(--rs-font-mono); | ||
| font-size: var(--rs-font-size-mono-regular); | ||
| line-height: var(--rs-line-height-regular); | ||
| color: var(--rs-color-foreground-base-primary); | ||
| } | ||
|
|
||
| .divider { | ||
| padding: 0; | ||
| margin: var(--rs-space-2) 0; | ||
| } | ||
|
|
||
| @media (max-width: 1100px) { | ||
| .layout { | ||
| flex-direction: column; | ||
| gap: var(--rs-space-9); | ||
| } | ||
|
|
||
| .left, | ||
| .right { | ||
| width: 100%; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.