Skip to content
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

feat: widget configurator app #3205

Closed
wants to merge 3 commits into from
Closed
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
10 changes: 10 additions & 0 deletions apps/widget-configurator-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": ["plugin:cypress/recommended", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
}
]
}
8 changes: 8 additions & 0 deletions apps/widget-configurator-e2e/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'cypress'
import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'

export default defineConfig({
e2e: nxE2EPreset(__dirname, {
bundler: 'vite',
}),
})
33 changes: 33 additions & 0 deletions apps/widget-configurator-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "widget-configurator-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/widget-configurator-e2e/src",
"projectType": "application",
"targets": {
"e2e": {
"executor": "@nx/cypress:cypress",
"options": {
"cypressConfig": "apps/widget-configurator-e2e/cypress.config.ts",
"devServerTarget": "widget-configurator:serve:development",
"testingType": "e2e"
},
"configurations": {
"production": {
"devServerTarget": "widget-configurator:serve:production"
},
"ci": {
"devServerTarget": "widget-configurator:serve-static"
}
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/widget-configurator-e2e/**/*.{js,ts}"]
}
}
},
"tags": [],
"implicitDependencies": ["widget-configurator"]
}
13 changes: 13 additions & 0 deletions apps/widget-configurator-e2e/src/e2e/app.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { getGreeting } from '../support/app.po'

describe('widget-configurator', () => {
beforeEach(() => cy.visit('/'))

it('should display welcome message', () => {
// Custom command example, see `../support/commands.ts` file
cy.login('[email protected]', 'myPassword')

// Function helper example, see `../support/app.po.ts` file
getGreeting().contains('Welcome widget-configurator')
})
})
4 changes: 4 additions & 0 deletions apps/widget-configurator-e2e/src/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]"
}
1 change: 1 addition & 0 deletions apps/widget-configurator-e2e/src/support/app.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const getGreeting = () => cy.get('h1')
33 changes: 33 additions & 0 deletions apps/widget-configurator-e2e/src/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************

// eslint-disable-next-line @typescript-eslint/no-namespace
declare namespace Cypress {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Chainable<Subject> {
login(email: string, password: string): void
}
}
//
// -- This is a parent command --
Cypress.Commands.add('login', (email, password) => {
console.log('Custom command example: Login', email, password)
})
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
17 changes: 17 additions & 0 deletions apps/widget-configurator-e2e/src/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'
10 changes: 10 additions & 0 deletions apps/widget-configurator-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"sourceMap": false,
"outDir": "../../dist/out-tsc",
"allowJs": true,
"types": ["cypress", "node"]
},
"include": ["src/**/*.ts", "src/**/*.js", "cypress.config.ts"]
}
18 changes: 18 additions & 0 deletions apps/widget-configurator/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["plugin:@nx/react", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
14 changes: 14 additions & 0 deletions apps/widget-configurator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>CoW Swap: Widget configurator</title>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, width=device-width" />
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
78 changes: 78 additions & 0 deletions apps/widget-configurator/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"name": "widget-configurator",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/widget-configurator/src",
"projectType": "application",
"targets": {
"build": {
"executor": "@nx/vite:build",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"outputPath": "dist/apps/widget-configurator"
},
"configurations": {
"development": {
"mode": "development"
},
"production": {
"mode": "production"
}
}
},
"serve": {
"executor": "@nx/vite:dev-server",
"defaultConfiguration": "development",
"options": {
"buildTarget": "widget-configurator:build"
},
"configurations": {
"development": {
"buildTarget": "widget-configurator:build:development",
"hmr": true
},
"production": {
"buildTarget": "widget-configurator:build:production",
"hmr": false
}
}
},
"preview": {
"executor": "@nx/vite:preview-server",
"defaultConfiguration": "development",
"options": {
"buildTarget": "widget-configurator:build"
},
"configurations": {
"development": {
"buildTarget": "widget-configurator:build:development"
},
"production": {
"buildTarget": "widget-configurator:build:production"
}
}
},
"test": {
"executor": "@nx/vite:test",
"outputs": ["coverage/apps/widget-configurator"],
"options": {
"passWithNoTests": true,
"reportsDirectory": "../../coverage/apps/widget-configurator"
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/widget-configurator/**/*.{ts,tsx,js,jsx}"]
}
},
"serve-static": {
"executor": "@nx/web:file-server",
"options": {
"buildTarget": "widget-configurator:build"
}
}
},
"tags": []
}
Binary file added apps/widget-configurator/public/favicon.ico
Binary file not shown.
15 changes: 15 additions & 0 deletions apps/widget-configurator/src/app/app.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { render } from '@testing-library/react'

import App from './app'

describe('App', () => {
it('should render successfully', () => {
const { baseElement } = render(<App />)
expect(baseElement).toBeTruthy()
})

it('should have a greeting as the title', () => {
const { getByText } = render(<App />)
expect(getByText(/Welcome widget-configurator/gi)).toBeTruthy()
})
})
21 changes: 21 additions & 0 deletions apps/widget-configurator/src/app/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Box from '@mui/material/Box'
import { Configurator } from './configurator'
import { Theme } from '@mui/material/styles';

const WrapperStyled = (theme: Theme) => ({
display: 'flex',
flexDirection: 'column',
height: '100%',
width: '100%',
background: theme.palette.background.paper,
})

export function App() {
return (
<Box sx={WrapperStyled}>
<Configurator title="CoW Widget" />
</Box>
)
}

export default App
65 changes: 65 additions & 0 deletions apps/widget-configurator/src/app/configurator/embedDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import * as React from 'react';
import Button from '@mui/material/Button';
import Dialog, { DialogProps } from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
import DialogContentText from '@mui/material/DialogContentText';
import DialogTitle from '@mui/material/DialogTitle';

export default function EmbedDialog() {
const [open, setOpen] = React.useState(false);
const [scroll, setScroll] = React.useState<DialogProps['scroll']>('paper');

const handleClickOpen = (scrollType: DialogProps['scroll']) => () => {
setOpen(true);
setScroll(scrollType);
};

const handleClose = () => {
setOpen(false);
};

const descriptionElementRef = React.useRef<HTMLElement>(null);
React.useEffect(() => {
if (open) {
const { current: descriptionElement } = descriptionElementRef;
if (descriptionElement !== null) {
descriptionElement.focus();
}
}
}, [open]);

return (
<div>
<Button onClick={handleClickOpen('paper')}>{`View Embed Code </>`}</Button>
{/* <Button onClick={handleClickOpen('body')}>scroll=body</Button> */}
<Dialog
open={open}
onClose={handleClose}
scroll={scroll}
aria-labelledby="scroll-dialog-title"
aria-describedby="scroll-dialog-description"
>
<DialogTitle id="scroll-dialog-title">CoW Widget Embed</DialogTitle>
<DialogContent dividers={scroll === 'paper'}>
<DialogContentText
id="scroll-dialog-description"
ref={descriptionElementRef}
tabIndex={-1}
>
{[...new Array(50)]
.map(
() => `<embed type="text/html" src="snippet.html" width="500" height="200">
`,
)
.join('\n')}
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={handleClose}>Cancel</Button>
<Button onClick={handleClose}>Copy</Button>
</DialogActions>
</Dialog>
</div>
);
}
Loading
Loading