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

[examples][base-ui] Add Base UI + Vite + Tailwind CSS example in TypeScript #37595

Merged
merged 17 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
migration of the example from CRA to Vite
  • Loading branch information
David authored and David committed Jun 14, 2023
commit e99b68510e8550ee1a75356c98ce2b8ca3d4634b
15 changes: 15 additions & 0 deletions examples/base-cra-tailwind-ts/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': 'warn',
},
}

41 changes: 21 additions & 20 deletions examples/base-cra-tailwind-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

# 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?
10 changes: 8 additions & 2 deletions examples/base-cra-tailwind-ts/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Base UI - Create React App example with Tailwind CSS in TypeScript
# Base UI - Vite React example with Tailwind CSS in TypeScript

[Base UI](https://mui.com/base/getting-started/overview/) is a library of unstyled React UI components which includes prebuilt components with production-ready functionality, along with low-level hooks for transferring that functionality to other components.

[Vite](https://vitejs.dev/) is a build tool that aims to provide a faster and leaner development experience for modern web projects, consisting of a dev server and a build command

[Tailwind CSS](https://tailwindcss.com/) is a utility-first CSS framework that provides low-level CSS classes that can be composed to build custom UI designs.

## How to use

Expand Down Expand Up @@ -28,5 +34,5 @@ or:

## The idea behind the example

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
This project was bootstrapped with [Vite](https://vitejs.dev/guide/).
It shows how you can use Base UI together with [Tailwind CSS](https://tailwindcss.com/) to build your application.
13 changes: 13 additions & 0 deletions examples/base-cra-tailwind-ts/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>
41 changes: 23 additions & 18 deletions examples/base-cra-tailwind-ts/package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
{
"name": "base-cra-tailwind-ts",
"version": "0.1.0",
"name": "base-vite-tailwind-ts",
"private": true,
"version": "0.2.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@mui/base": "latest",
"@testing-library/jest-dom": "latest",
"@testing-library/react": "latest",
"@testing-library/user-event": "latest",
"@types/jest": "latest",
"@types/node": "latest",
"react": "latest",
"react-dom": "latest"
},
"devDependencies": {
"@types/react": "latest",
"@types/react-dom": "latest",
"@typescript-eslint/eslint-plugin": "latest",
"@typescript-eslint/parser": "latest",
"@vitejs/plugin-react": "latest",
"autoprefixer": "latest",
"eslint": "latest",
"eslint-plugin-react-hooks": "latest",
"eslint-plugin-react-refresh": "latest",
"postcss": "latest",
"react": "latest",
"react-dom": "latest",
"react-scripts": "latest",
"typescript": "latest"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"tailwindcss": "latest",
"typescript": "latest",
"vite": "latest"
},
"browserslist": {
"production": [
Expand All @@ -36,4 +41,4 @@
"last 1 safari version"
]
}
}
}
4 changes: 2 additions & 2 deletions examples/base-cra-tailwind-ts/postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
}
Binary file removed examples/base-cra-tailwind-ts/public/favicon.ico
Binary file not shown.
41 changes: 0 additions & 41 deletions examples/base-cra-tailwind-ts/public/index.html

This file was deleted.

Binary file removed examples/base-cra-tailwind-ts/public/logo192.png
Binary file not shown.
Binary file removed examples/base-cra-tailwind-ts/public/logo512.png
Binary file not shown.
25 changes: 0 additions & 25 deletions examples/base-cra-tailwind-ts/public/manifest.json

This file was deleted.

3 changes: 0 additions & 3 deletions examples/base-cra-tailwind-ts/public/robots.txt

This file was deleted.

1 change: 1 addition & 0 deletions examples/base-cra-tailwind-ts/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.
2 changes: 1 addition & 1 deletion examples/base-cra-tailwind-ts/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import React from 'react';
import Player from './Player';

function App() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import React from 'react';
import ButtonUnstyled, { ButtonOwnerState, ButtonProps } from '@mui/base/Button';

const Button = React.forwardRef(function Button(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import React from 'react';
import Button from './Button';
import Slider from './Slider';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import React from 'react';
import SliderUnstyled, { SliderThumbSlotProps, SliderProps } from '@mui/base/Slider';

const Thumb = React.forwardRef(function Thumb(
Expand Down
11 changes: 0 additions & 11 deletions examples/base-cra-tailwind-ts/src/index.tsx

This file was deleted.

10 changes: 10 additions & 0 deletions examples/base-cra-tailwind-ts/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import './index.css'

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
1 change: 0 additions & 1 deletion examples/base-cra-tailwind-ts/src/react-app-env.d.ts

This file was deleted.

5 changes: 0 additions & 5 deletions examples/base-cra-tailwind-ts/src/setupTests.ts

This file was deleted.

1 change: 1 addition & 0 deletions examples/base-cra-tailwind-ts/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
10 changes: 7 additions & 3 deletions examples/base-cra-tailwind-ts/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
module.exports = {
content: ['./src/**/*.{js,jsx,ts,tsx}'],
/** @type {import('tailwindcss').Config} */
export default {
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
};
}
29 changes: 17 additions & 12 deletions examples/base-cra-tailwind-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
"jsx": "react-jsx",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
11 changes: 11 additions & 0 deletions examples/base-cra-tailwind-ts/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}

7 changes: 7 additions & 0 deletions examples/base-cra-tailwind-ts/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
})