Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions docs/getting-started/dev-portal/react.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ Then, run `cd my-dir` and `yarn start` to see a basic Elements Dev Portal websit

When the server has started, navigate to `http://localhost:3000` to see Elements Dev Portal rendering an [example Git project](https://github.com/stoplightio/studio-demo). Follow the instructions below to change your `projectId` and load up one of your projects.


## Vite Template

Use the [Vite template](https://github.com/stoplightio/elements/tree/main/examples/vite-react) to create a new Elements Dev Portal website in React without additional setup.


```bash
npx degit stoplightio/elements/examples/vite-react my-dir
git init
```

Then, run `cd my-dir`,`yarn install` and `yarn run dev` to see a basic Elements Dev Portal website in the browser.

When the server has started, navigate to `http://localhost:3000` to see Elements Dev Portal rendering an [example Git project](https://github.com/stoplightio/studio-demo). Follow the instructions below to change your `projectId` and load up one of your projects.

## Manual Setup

To install Elements Dev Portal in an existing React app, follow these instructions.
Expand Down
15 changes: 15 additions & 0 deletions docs/getting-started/elements/react.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ npx [email protected] my-dir --template @stoplight/elements

Then, run `cd my-dir` and `yarn start` to see a basic Elements website in the browser.

## Vite Template

Use the [Vite template](https://github.com/stoplightio/elements/tree/main/examples/vite-react) to create a new Elements Dev Portal website in React without additional setup.


```bash
npx degit stoplightio/elements/examples/vite-react my-dir
git init
```

Then, run `cd my-dir`,`yarn install` and `yarn run dev` to see a basic Elements Dev Portal website in the browser.

When the server has started, navigate to `http://localhost:3000` to see Elements Dev Portal rendering an [example Git project](https://github.com/stoplightio/studio-demo). Follow the instructions below to change your `projectId` and load up one of your projects.


## Manual Setup

To install Elements Dev Portal in an existing React app, follow these instructions.
Expand Down
24 changes: 24 additions & 0 deletions examples/vite-react/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
58 changes: 58 additions & 0 deletions examples/vite-react/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Stoplight Elements - React App with vite Example

## Table Of Contents

- [Overview](#overview)
- [Stoplight Project](#stoplight-project)
- [Stoplight API](#stoplight-api)
- [Trying the example](#trying-the-example)
- [Usage](#usage)
- [**Stoplight Project**](#stoplight-project-1)
- [**Stoplight API**](#stoplight-api-1)
- [**Functionality**](#functionality)
- [Elements in your own React App](#elements-in-your-own-react-app)

## Overview

*Stoplight Elements* can be embedded natively in React app. This example demonstrates usage of the Stoplight Project and Stoplight API components in a vite React App application and presents how to embed Elements in your own application.

### Stoplight Project

This component allows embedding documentation that is connected to a Stoplight workspace. In this example, we are referring to [elements-examples.stoplight.io](https://elements-examples.stoplight.io) workspace - [studio-demo](https://elements-examples.stoplight.io/docs/studio-demo) project to be more precise.

### Stoplight API

Stoplight API component allows embedding documentation with no limitations to the file location, it can be anywhere on the web.
In this example, we connect the `API` component directly to [Zoom API](https://raw.githubusercontent.com/stoplightio/Public-APIs/master/reference/zoom/openapi.yaml) OAS3 YAML file hosted on GitHub.

## Trying the example

For instructions on how to run this example, please refer to the [root README file](../../README.md#-examples)

### Usage

#### **Stoplight Project**

Click on the `Stoplight Project` button in the topbar menu to see that component in action:

![stoplight-project-example](https://user-images.githubusercontent.com/58433203/92106502-c617db00-ede4-11ea-8331-34b65bd36391.png)

#### **Stoplight API**

Click on the `Stoplight API` button in the topbar menu to see that component in action:

![stoplight-project-example](https://user-images.githubusercontent.com/58433203/92106493-c31cea80-ede4-11ea-95fa-e786b6b00efa.png)

### **Functionality**

* Navigate to Markdown section in order to see our beautiful Markdown Viewer in action

* Open any of the models to take a look at JSON Schema Viewer (JSV)

* View basic information about a given API in `Overview` section

* Open API endpoints to preview their properties and try out Http Request Maker

## Elements in your own React App

Check out our [Public Documentation](https://meta.stoplight.io/docs/elements) and **start using Stoplight Elements today!**
28 changes: 28 additions & 0 deletions examples/vite-react/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)
13 changes: 13 additions & 0 deletions examples/vite-react/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
31 changes: 31 additions & 0 deletions examples/vite-react/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "vite-react",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@stoplight/elements": "^9.0.1",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"vite-plugin-node-polyfills": "^0.23.0"
},
"devDependencies": {
"@eslint/js": "^9.25.0",
"@types/react": "^19.1.2",
"@types/react-dom": "^19.1.2",
"@vitejs/plugin-react": "^4.4.1",
"eslint": "^9.25.0",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.19",
"globals": "^16.0.0",
"typescript": "~5.8.3",
"typescript-eslint": "^8.30.1",
"vite": "^6.3.5"
}
}
1 change: 1 addition & 0 deletions examples/vite-react/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions examples/vite-react/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @ts-ignore
import {API} from "@stoplight/elements"
import '@stoplight/elements/styles.min.css';

function App() {

return (
<>
<API
apiDescriptionUrl="https://raw.githubusercontent.com/stoplightio/Public-APIs/master/reference/zoom/openapi.yaml"
/>
</>
)
}

export default App
Empty file.
10 changes: 10 additions & 0 deletions examples/vite-react/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.tsx'

createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
)
1 change: 1 addition & 0 deletions examples/vite-react/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
27 changes: 27 additions & 0 deletions examples/vite-react/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
"jsx": "react-jsx",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["src"]
}
7 changes: 7 additions & 0 deletions examples/vite-react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
]
}
25 changes: 25 additions & 0 deletions examples/vite-react/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"target": "ES2022",
"lib": ["ES2023"],
"module": "ESNext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["vite.config.ts"]
}
11 changes: 11 additions & 0 deletions examples/vite-react/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { nodePolyfills } from 'vite-plugin-node-polyfills'

// https://vite.dev/config/
export default defineConfig({
plugins: [react(), nodePolyfills()],
server: {
port: 3000,
},
});
Loading