mm
This commit is contained in:
@@ -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?
|
||||
@@ -0,0 +1,78 @@
|
||||
# React + TypeScript + Vite
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||
|
||||
Currently, two official plugins are available:
|
||||
|
||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs)
|
||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/)
|
||||
|
||||
## React Compiler
|
||||
|
||||
The React Compiler is enabled on this template. See [this documentation](https://react.dev/learn/react-compiler) for more information.
|
||||
|
||||
Note: This will impact Vite dev & build performances.
|
||||
You can also try [the experimental native React Compiler support in plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md#rust-react-compiler) by using `compiler: true` in the plugin options instead of using the Babel plugin.
|
||||
|
||||
## Expanding the ESLint configuration
|
||||
|
||||
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
||||
|
||||
```js
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
|
||||
// Remove tseslint.configs.recommended and replace with this
|
||||
tseslint.configs.recommendedTypeChecked,
|
||||
// Alternatively, use this for stricter rules
|
||||
tseslint.configs.strictTypeChecked,
|
||||
// Optionally, add this for stylistic rules
|
||||
tseslint.configs.stylisticTypeChecked,
|
||||
|
||||
// Other configs...
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
|
||||
```
|
||||
|
||||
You can also install [eslint-plugin-react-x](https://npmx.dev/package/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://npmx.dev/package/eslint-plugin-react-dom) for React-specific lint rules:
|
||||
|
||||
```js
|
||||
// eslint.config.js
|
||||
import reactX from 'eslint-plugin-react-x'
|
||||
import reactDom from 'eslint-plugin-react-dom'
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
// Enable lint rules for React
|
||||
reactX.configs['recommended-typescript'],
|
||||
// Enable lint rules for React DOM
|
||||
reactDom.configs.recommended,
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
|
||||
```
|
||||
@@ -2,11 +2,12 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>vite-project</title>
|
||||
<title>ui-gallery</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/gallery/main.tsx"></script>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "@dg/ui-gallery",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^19.3.1",
|
||||
"react-dom": "^19.3.1",
|
||||
"@dg/ui-react": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.29.13",
|
||||
"@eslint/js": "^10.0.1",
|
||||
"@rolldown/plugin-babel": "^0.3.1",
|
||||
"@types/babel__core": "^7.20.5",
|
||||
"@types/node": "^26.6.6",
|
||||
"@types/react": "^19.3.0",
|
||||
"@types/react-dom": "^19.3.0",
|
||||
"@vitejs/devtools": "^0.8.3",
|
||||
"@vitejs/devtools-rolldown": "^0.8.3",
|
||||
"@vitejs/devtools-vite": "^0.8.3",
|
||||
"@vitejs/plugin-react": "^6.3.0",
|
||||
"babel-plugin-react-compiler": "^1.0.0",
|
||||
"eslint": "^10.15.0",
|
||||
"eslint-plugin-react-hooks": "^7.1.1",
|
||||
"eslint-plugin-react-refresh": "^0.5.8",
|
||||
"globals": "^17.14.0",
|
||||
"typescript": "~6.0.3",
|
||||
"typescript-eslint": "^8.73.0",
|
||||
"vite": "^8.4.0"
|
||||
}
|
||||
}
|
||||
Generated
+2427
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,18 @@
|
||||
import { ButtonGallery } from "./gallery/button-gallery";
|
||||
import { MenuGallery } from "./gallery/menu-gallery";
|
||||
import { PopoverGallery } from "./gallery/popover-gallery";
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className="app">
|
||||
<Theme>
|
||||
<ButtonGallery />
|
||||
<PopoverGallery />
|
||||
<MenuGallery />
|
||||
</Theme>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 8.5 KiB |
+3
-4
@@ -1,7 +1,6 @@
|
||||
import { DownloadSvg } from "../src/assets/svg/download-svg";
|
||||
import { Button } from "../src/components/button/button";
|
||||
import { IW } from "./iw";
|
||||
import { OW } from "./ow";
|
||||
import { IW } from "../common/iw";
|
||||
import { OW } from "../common/ow";
|
||||
|
||||
|
||||
export const ButtonGallery = () => {
|
||||
return (
|
||||
+1
-1
@@ -8,7 +8,7 @@ import {
|
||||
MenuRadioItem,
|
||||
MenuRadioItemGroup,
|
||||
MenuTrigger,
|
||||
} from "../src";
|
||||
} from "../../../ui-react/src";
|
||||
import { IW } from "./iw";
|
||||
import { OW } from "./ow";
|
||||
|
||||
+4
-4
@@ -1,8 +1,8 @@
|
||||
|
||||
import { Button } from "../src/components/button/button";
|
||||
import { Popover } from "../src/components/popover/popover";
|
||||
import { PopoverDropdown } from "../src/components/popover/popover-dropdown";
|
||||
import { PopoverTrigger } from "../src/components/popover/popover-trigger";
|
||||
import { Button } from "../../../ui-react/src/components/button/button";
|
||||
import { Popover } from "../../../ui-react/src/components/popover/popover";
|
||||
import { PopoverDropdown } from "../../../ui-react/src/components/popover/popover-dropdown";
|
||||
import { PopoverTrigger } from "../../../ui-react/src/components/popover/popover-trigger";
|
||||
import { IW } from "./iw";
|
||||
import { OW } from "./ow";
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import App from './App.tsx'
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"target": "es2023",
|
||||
"lib": ["ES2023", "DOM"],
|
||||
"module": "esnext",
|
||||
"types": ["vite/client"],
|
||||
"allowArbitraryExtensions": true,
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
|
||||
/* Linting */
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"target": "es2023",
|
||||
"lib": ["ES2023"],
|
||||
"types": ["node"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"module": "nodenext",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import react, { reactCompilerPreset } from '@vitejs/plugin-react'
|
||||
import babel from '@rolldown/plugin-babel'
|
||||
import { defineConfig } from 'vite'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
devtools: {
|
||||
// Remove this `apply` property to enable devtools for build as well
|
||||
apply: 'serve',
|
||||
},
|
||||
plugins: [
|
||||
react(),
|
||||
babel({ presets: [reactCompilerPreset()] })
|
||||
],
|
||||
})
|
||||
@@ -1 +1,2 @@
|
||||
registry = https://registry.npmmirror.com/
|
||||
registry=https://registry.npmmirror.com
|
||||
shamefully-hoist = true
|
||||
@@ -1,16 +0,0 @@
|
||||
import { ButtonGallery } from "./button-gallery";
|
||||
import { Theme } from "../src/components/theme/theme";
|
||||
import { PopoverGallery } from "./popover-gallery";
|
||||
import { MenuGallery } from "./menu-gallery";
|
||||
|
||||
export function App() {
|
||||
return (
|
||||
<div className="app">
|
||||
<Theme>
|
||||
<ButtonGallery />
|
||||
<PopoverGallery />
|
||||
<MenuGallery />
|
||||
</Theme>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { StrictMode } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import "../src/index.css";
|
||||
import { App } from "./app.tsx";
|
||||
|
||||
createRoot(document.getElementById("root")!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
);
|
||||
@@ -1,29 +0,0 @@
|
||||
# 代码原则
|
||||
|
||||
## UI 开发应该用函数式组件
|
||||
|
||||
其实函数式组件,就是类组件里的一个 render 方法而已。
|
||||
|
||||
类组件里的各种成员变量,框架已经自动传入 render 的参数里了,非常方便。
|
||||
|
||||
再加上 tsx 和 rsx 的特殊语法解析器,智能提示全齐。
|
||||
|
||||
## 有些技术问题,早就有人开发了改进框架
|
||||
|
||||
有时候自己开发 react ,发现两个不是父子关系的组件,仍然需要通信。
|
||||
|
||||
例如,全选按钮,和列表按钮,不是父子关系。
|
||||
|
||||
这就需要一个所谓的 “全局状态库”,或者说 “配置模式”。
|
||||
|
||||
就像 settings 里的一大堆勾勾清单,使用 profile A,和 profile B,批量改变。
|
||||
|
||||
## 不要强求传入的数据有某种格式,而是兼容标准数据
|
||||
|
||||
例如 svg 格式的,要不要写成一个 component 呢?
|
||||
|
||||
试想一下,系统已经上线运营,你不可能添加任何代码,你只能给文件,系统愿不愿意数据转换,那是另一回事。
|
||||
|
||||
如果我想复用 svg 文件,不仅在 react 框架下用,还要在很多框架下用,我不能弄几套不同的版本,那样太占用空间。
|
||||
|
||||
因此,我必须维持 .svg 的原文件格式,不添加任何 jsx 语法。
|
||||
@@ -1,13 +1,18 @@
|
||||
{
|
||||
"name": "@dg/ui-react",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"license": "MIT",
|
||||
"sideEffects": [
|
||||
"*.css"
|
||||
],
|
||||
"files": [
|
||||
"dist/[^.]*",
|
||||
"types/[^.]*",
|
||||
"docs/[^.]*",
|
||||
"doc/[^.]*"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"import": {
|
||||
@@ -16,42 +21,22 @@
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"default": "./dist/index.cjs"
|
||||
"default": "./dist/index.cjs.js"
|
||||
}
|
||||
},
|
||||
"./index.css": "./dist/index.css"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "vite build",
|
||||
"dev": "npm run build && vite dev"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^10.0.1",
|
||||
"@microsoft/api-extractor": "^7.60.1",
|
||||
"@types/node": "^24.19.2",
|
||||
"@types/react": "^19.3.0",
|
||||
"@types/react-dom": "^19.3.0",
|
||||
"@vitejs/plugin-react": "^6.1.2",
|
||||
"eslint": "^10.15.0",
|
||||
"eslint-plugin-react-hooks": "^7.1.1",
|
||||
"glob": "^14.0.6",
|
||||
"globals": "^17.14.0",
|
||||
"prettier": "^3.10.1",
|
||||
"react": "^19.3.1",
|
||||
"react-dom": "^19.3.1",
|
||||
"tinyglobby": "^0.2.17",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^6.0.3",
|
||||
"typescript-eslint": "^8.73.0",
|
||||
"unplugin-dts": "^1.1.2",
|
||||
"vite": "^8.3.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@floating-ui/react": "^0.27.20",
|
||||
"react-hotkeys-hook": "^5.3.3"
|
||||
"react-hotkeys-hook": "^5.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^26.6.6",
|
||||
"@types/react": "^19.3.0",
|
||||
"@types/react-dom": "^19.3.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0"
|
||||
"react": "^19.3.1",
|
||||
"react-dom": "^19.3.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import {
|
||||
type CSSProperties,
|
||||
} from "react";
|
||||
import { mergeClass } from "../../styles/utils/merge-class";
|
||||
import { type CSSProperties } from "react";
|
||||
import { displayRecipe } from "../../styles/recipes/display-recipe";
|
||||
import { dotSizeRecipe } from "../../styles/recipes/dot-size-recipe";
|
||||
import type { CommonProps } from "../../utils/common-props";
|
||||
import { brandRecipe } from "../../styles/recipes/brand-recipe";
|
||||
import { mergeClass } from "../../styles/utils/merge-class";
|
||||
import type { CommonProps } from "../../utils/common-props";
|
||||
|
||||
export type BadgeProps = CommonProps & {
|
||||
size?: "xs" | "sm" | "md" | "lg";
|
||||
@@ -39,12 +37,16 @@ export const Badge = (props: BadgeProps) => {
|
||||
borderRadius: "9999px",
|
||||
};
|
||||
|
||||
|
||||
|
||||
const indicatorClass = mergeClass(displayRecipe(), dotSizeRecipe({ size }), brandRecipe({ brand: "danger" }), "pointer-events--none", className);
|
||||
const indicatorClass = mergeClass(
|
||||
displayRecipe(),
|
||||
dotSizeRecipe({ size }),
|
||||
brandRecipe({ brand: "danger" }),
|
||||
"pointer-events--none",
|
||||
className,
|
||||
);
|
||||
|
||||
return (
|
||||
<div {...rest} ref={ref} style={wrapperStyle}>
|
||||
<div {...rest} ref={ref} style={wrapperStyle}>
|
||||
{children}
|
||||
<div className={indicatorClass} style={indicatorStyle}>
|
||||
{indicatorContent}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
@import './styles/css/overscroll-behavior.css';
|
||||
@import './styles/css/overflow.css';
|
||||
@import './styles/css/outline.css';
|
||||
@import './styles/css/opacity.css';
|
||||
@import './styles/css/max-width.css';
|
||||
@import './styles/css/max-height.css';
|
||||
@import './styles/css/justify-self.css';
|
||||
|
||||
@@ -1,44 +1,6 @@
|
||||
export * from './utils/use-state-registry.ts';
|
||||
export * from './utils/slot.tsx';
|
||||
export * from './utils/radiobox.tsx';
|
||||
export * from './utils/merge-props.ts';
|
||||
export * from './utils/down-grade-size.ts';
|
||||
export * from './utils/common-props.ts';
|
||||
export * from './components/checkbox-input/checkbox-input.tsx';
|
||||
export * from './utils/camel-to-kebab.ts';
|
||||
import './index.css';
|
||||
export * from './styles/utils/merge-class.ts';
|
||||
export * from './styles/utils/create-class-recipe.ts';
|
||||
export * from './styles/recipes/variant-recipe.ts';
|
||||
export * from './styles/recipes/item-size-recipe.ts';
|
||||
export * from './styles/recipes/inline-size-recipe.ts';
|
||||
export * from './styles/recipes/dot-size-recipe.ts';
|
||||
export * from './styles/recipes/display-recipe.ts';
|
||||
export * from './styles/recipes/container-recipe.ts';
|
||||
export * from './styles/recipes/brand-recipe.ts';
|
||||
export * from './components/theme/use-theme-context.ts';
|
||||
export * from './components/theme/theme.tsx';
|
||||
export * from './components/tag/tag.tsx';
|
||||
export * from './components/slider/slider.tsx';
|
||||
export * from './components/popover/use-popover-floating.ts';
|
||||
export * from './components/popover/use-popover-context.ts';
|
||||
export * from './components/popover/popover.tsx';
|
||||
export * from './components/popover/popover-trigger.tsx';
|
||||
export * from './components/popover/popover-dropdown.tsx';
|
||||
export * from './components/menu/use-menu-trigger-context.ts';
|
||||
export * from './components/radiobox-input/use-radiobox-input-group-context.ts';
|
||||
export * from './components/menu/use-menu-floating.ts';
|
||||
export * from './components/menu/use-menu-floating-context.ts';
|
||||
export * from './components/menu/use-menu-context.ts';
|
||||
export * from './components/menu/menu.tsx';
|
||||
export * from './components/menu/menu-trigger.tsx';
|
||||
export * from './components/menu/menu-radio-item.tsx';
|
||||
export * from './components/menu/menu-radio-item-group.tsx';
|
||||
export * from './components/menu/menu-item.tsx';
|
||||
export * from './components/menu/menu-dropdown.tsx';
|
||||
export * from './components/menu/menu-check-item.tsx';
|
||||
export * from './components/icon/icon.tsx';
|
||||
export * from './components/button/button.tsx';
|
||||
export * from './components/badge/badge.tsx';
|
||||
export * from './assets/svg/volume-mute-svg.tsx';
|
||||
export * from './assets/svg/volume-low-svg.tsx';
|
||||
export * from './assets/svg/volume-high-svg.tsx';
|
||||
@@ -61,4 +23,11 @@ export * from './assets/svg/chevron-right-svg.tsx';
|
||||
export * from './assets/svg/checkbox-unchecked-svg.tsx';
|
||||
export * from './assets/svg/checkbox-checked-svg.tsx';
|
||||
export * from './assets/svg/check-indicator-svg.tsx';
|
||||
export * from './assets/svg/bold-svg.tsx';
|
||||
export * from './assets/svg/bold-svg.tsx';
|
||||
export * from './styles/recipes/variant-recipe.ts';
|
||||
export * from './styles/recipes/item-size-recipe.ts';
|
||||
export * from './styles/recipes/inline-size-recipe.ts';
|
||||
export * from './styles/recipes/dot-size-recipe.ts';
|
||||
export * from './styles/recipes/display-recipe.ts';
|
||||
export * from './styles/recipes/container-recipe.ts';
|
||||
export * from './styles/recipes/brand-recipe.ts';
|
||||
@@ -27,12 +27,12 @@
|
||||
border-radius: var(--radius-xl);
|
||||
}
|
||||
|
||||
.rounded--2xl {
|
||||
border-radius: var(--radius-2xl);
|
||||
.rounded--xxl {
|
||||
border-radius: var(--radius-xxl);
|
||||
}
|
||||
|
||||
.rounded--3xl {
|
||||
border-radius: var(--radius-3xl);
|
||||
.rounded--xxxl {
|
||||
border-radius: var(--radius-xxxl);
|
||||
}
|
||||
|
||||
.rounded--4 {
|
||||
|
||||
@@ -24,13 +24,13 @@
|
||||
line-height: var(--line-height);
|
||||
}
|
||||
|
||||
.text--2xl {
|
||||
font-size: var(--font-size-2xl);
|
||||
.text--xxl {
|
||||
font-size: var(--font-size-xxl);
|
||||
line-height: var(--line-height);
|
||||
}
|
||||
|
||||
.text--3xl {
|
||||
font-size: var(--font-size-3xl);
|
||||
.text--xxxl {
|
||||
font-size: var(--font-size-xxxl);
|
||||
line-height: var(--line-height);
|
||||
}
|
||||
}
|
||||
@@ -45,11 +45,11 @@
|
||||
font-weight: var(--font-weight-xl);
|
||||
}
|
||||
|
||||
.font-weight--2xl {
|
||||
font-weight: var(--font-weight-2xl);
|
||||
.font-weight--xxl {
|
||||
font-weight: var(--font-weight-xxl);
|
||||
}
|
||||
|
||||
.font-weight--3xl {
|
||||
font-weight: var(--font-weight-3xl);
|
||||
.font-weight--xxxl {
|
||||
font-weight: var(--font-weight-xxxl);
|
||||
}
|
||||
}
|
||||
@@ -23,11 +23,11 @@
|
||||
gap: var(--gap-lg);
|
||||
}
|
||||
|
||||
.gap--2xl {
|
||||
gap: var(--gap-2xl);
|
||||
.gap--xxl {
|
||||
gap: var(--gap-xxl);
|
||||
}
|
||||
|
||||
.gap--3xl {
|
||||
gap: var(--gap-3xl);
|
||||
.gap--xxxl {
|
||||
gap: var(--gap-xxxl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
height: calc(var(--font-size-xl) / 2);
|
||||
}
|
||||
|
||||
.h--dot-2xl {
|
||||
height: calc(var(--font-size-2xl) / 2);
|
||||
.h--dot-xxl {
|
||||
height: calc(var(--font-size-xxl) / 2);
|
||||
}
|
||||
|
||||
.h--dot-3xl {
|
||||
height: calc(var(--font-size-3xl) / 2);
|
||||
.h--dot-xxxl {
|
||||
height: calc(var(--font-size-xxxl) / 2);
|
||||
}
|
||||
}
|
||||
@@ -39,19 +39,19 @@
|
||||
}
|
||||
}
|
||||
|
||||
.h--inline-2xl {
|
||||
height: calc(var(--font-size-2xl) * var(--line-height));
|
||||
.h--inline-xxl {
|
||||
height: calc(var(--font-size-xxl) * var(--line-height));
|
||||
& svg {
|
||||
height: calc(var(--font-size-2xl) * var(--line-height));
|
||||
width: calc(var(--font-size-2xl) * var(--line-height));
|
||||
height: calc(var(--font-size-xxl) * var(--line-height));
|
||||
width: calc(var(--font-size-xxl) * var(--line-height));
|
||||
}
|
||||
}
|
||||
|
||||
.h--inline-3xl {
|
||||
height: calc(var(--font-size-3xl) * var(--line-height));
|
||||
.h--inline-xxxl {
|
||||
height: calc(var(--font-size-xxxl) * var(--line-height));
|
||||
& svg {
|
||||
height: calc(var(--font-size-3xl) * var(--line-height));
|
||||
width: calc(var(--font-size-3xl) * var(--line-height));
|
||||
height: calc(var(--font-size-xxxl) * var(--line-height));
|
||||
width: calc(var(--font-size-xxxl) * var(--line-height));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,18 +34,18 @@
|
||||
width: calc(var(--font-size-xl) * var(--line-height));
|
||||
}
|
||||
}
|
||||
.h--item-2xl {
|
||||
height: var(--height-item-2xl);
|
||||
.h--item-xxl {
|
||||
height: var(--height-item-xxl);
|
||||
& svg {
|
||||
height: calc(var(--font-size-2xl) * var(--line-height));
|
||||
width: calc(var(--font-size-2xl) * var(--line-height));
|
||||
height: calc(var(--font-size-xxl) * var(--line-height));
|
||||
width: calc(var(--font-size-xxl) * var(--line-height));
|
||||
}
|
||||
}
|
||||
.h--item-3xl {
|
||||
height: var(--height-item-3xl);
|
||||
.h--item-xxxl {
|
||||
height: var(--height-item-xxxl);
|
||||
& svg {
|
||||
height: calc(var(--font-size-3xl) * var(--line-height));
|
||||
width: calc(var(--font-size-3xl) * var(--line-height));
|
||||
height: calc(var(--font-size-xxxl) * var(--line-height));
|
||||
width: calc(var(--font-size-xxxl) * var(--line-height));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
.px--long-xl {
|
||||
padding-inline: var(--padding-long-xl);
|
||||
}
|
||||
.px--long-2xl {
|
||||
padding-inline: var(--padding-long-2xl);
|
||||
.px--long-xxl {
|
||||
padding-inline: var(--padding-long-xxl);
|
||||
}
|
||||
.px--long-3xl {
|
||||
padding-inline: var(--padding-long-3xl);
|
||||
.px--long-xxxl {
|
||||
padding-inline: var(--padding-long-xxxl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
.px--xl {
|
||||
padding-inline: var(--padding-xl);
|
||||
}
|
||||
.px--2xl {
|
||||
padding-inline: var(--padding-2xl);
|
||||
.px--xxl {
|
||||
padding-inline: var(--padding-xxl);
|
||||
}
|
||||
.px--3xl {
|
||||
padding-inline: var(--padding-3xl);
|
||||
.px--xxxl {
|
||||
padding-inline: var(--padding-xxxl);
|
||||
}
|
||||
|
||||
/* =================================================== */
|
||||
@@ -44,11 +44,11 @@
|
||||
.py--xl {
|
||||
padding-block: var(--padding-xl);
|
||||
}
|
||||
.py--2xl {
|
||||
padding-block: var(--padding-2xl);
|
||||
.py--xxl {
|
||||
padding-block: var(--padding-xxl);
|
||||
}
|
||||
.py--3xl {
|
||||
padding-block: var(--padding-3xl);
|
||||
.py--xxxl {
|
||||
padding-block: var(--padding-xxxl);
|
||||
}
|
||||
|
||||
/* =================================================== */
|
||||
|
||||
@@ -335,8 +335,8 @@
|
||||
--font-size-md: 14px;
|
||||
--font-size-lg: 15px;
|
||||
--font-size-xl: 16px;
|
||||
--font-size-2xl: 24px;
|
||||
--font-size-3xl: 30px;
|
||||
--font-size-xxl: 24px;
|
||||
--font-size-xxxl: 30px;
|
||||
|
||||
--line-height: 1.33;
|
||||
|
||||
@@ -352,24 +352,24 @@
|
||||
--font-weight-md: var(--font-weight-extranormal);
|
||||
--font-weight-lg: var(--font-weight-semibold);
|
||||
--font-weight-xl: var(--font-weight-semibold);
|
||||
--font-weight-2xl: var(--font-weight-semibold);
|
||||
--font-weight-3xl: var(--font-weight-bold);
|
||||
--font-weight-xxl: var(--font-weight-semibold);
|
||||
--font-weight-xxxl: var(--font-weight-bold);
|
||||
|
||||
--height-item-xs: 20px;
|
||||
--height-item-sm: 24px;
|
||||
--height-item-md: 28px;
|
||||
--height-item-lg: 32px;
|
||||
--height-item-xl: 42px;
|
||||
--height-item-2xl: 56px;
|
||||
--height-item-3xl: 64px;
|
||||
--height-item-xxl: 56px;
|
||||
--height-item-xxxl: 64px;
|
||||
|
||||
--radius-xs: 2px;
|
||||
--radius-sm: 3px;
|
||||
--radius-md: 4px;
|
||||
--radius-lg: 5px;
|
||||
--radius-xl: 8px;
|
||||
--radius-2xl: 12px;
|
||||
--radius-3xl: 16px;
|
||||
--radius-xxl: 12px;
|
||||
--radius-xxxl: 16px;
|
||||
--radius-none: 0;
|
||||
--radius-full: 9999px;
|
||||
|
||||
@@ -378,8 +378,8 @@
|
||||
--padding-md: 6px;
|
||||
--padding-lg: 7px;
|
||||
--padding-xl: 16px;
|
||||
--padding-2xl: 2px;
|
||||
--padding-3xl: 2px;
|
||||
--padding-xxl: 2px;
|
||||
--padding-xxxl: 2px;
|
||||
|
||||
--times-of-padding-long: 2;
|
||||
|
||||
@@ -388,16 +388,16 @@
|
||||
--padding-long-md: calc(var(--padding-md) * var(--times-of-padding-long));
|
||||
--padding-long-lg: calc(var(--padding-lg) * var(--times-of-padding-long));
|
||||
--padding-long-xl: calc(var(--padding-xl) * var(--times-of-padding-long));
|
||||
--padding-long-2xl: calc(var(--padding-2xl) * var(--times-of-padding-long));
|
||||
--padding-long-3xl: calc(var(--padding-3xl) * var(--times-of-padding-long));
|
||||
--padding-long-xxl: calc(var(--padding-xxl) * var(--times-of-padding-long));
|
||||
--padding-long-xxxl: calc(var(--padding-xxxl) * var(--times-of-padding-long));
|
||||
|
||||
--gap-xs: 2px;
|
||||
--gap-sm: 3px;
|
||||
--gap-md: 4px;
|
||||
--gap-lg: 5px;
|
||||
--gap-xl: 10px;
|
||||
--gap-2xl: 12px;
|
||||
--gap-3xl: 14px;
|
||||
--gap-xxl: 12px;
|
||||
--gap-xxxl: 14px;
|
||||
--gap-none: 0;
|
||||
|
||||
--drop-shadow: drop-shadow(0 0 4px rgba(0, 0, 0, 0.14))
|
||||
@@ -441,6 +441,6 @@
|
||||
--height-inline-md: calc(var(--font-size-md) * var(--line-height));
|
||||
--height-inline-lg: calc(var(--font-size-lg) * var(--line-height));
|
||||
--height-inline-xl: calc(var(--font-size-xl) * var(--line-height));
|
||||
--height-inline-2xl: calc(var(--font-size-2xl) * var(--line-height));
|
||||
--height-inline-3xl: calc(var(--font-size-3xl) * var(--line-height));
|
||||
--height-inline-xxl: calc(var(--font-size-xxl) * var(--line-height));
|
||||
--height-inline-xxxl: calc(var(--font-size-xxxl) * var(--line-height));
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
width: calc(var(--font-size-xl) / 2);
|
||||
}
|
||||
|
||||
.w--dot-2xl {
|
||||
width: calc(var(--font-size-2xl) / 2);
|
||||
.w--dot-xxl {
|
||||
width: calc(var(--font-size-xxl) / 2);
|
||||
}
|
||||
|
||||
.w--dot-3xl {
|
||||
width: calc(var(--font-size-3xl) / 2);
|
||||
.w--dot-xxxl {
|
||||
width: calc(var(--font-size-xxxl) / 2);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,7 +19,11 @@
|
||||
width: calc(var(--font-size-xl) * var(--line-height));
|
||||
}
|
||||
|
||||
.w--inline-xl {
|
||||
width: calc(var(--font-size-2xl) * var(--line-height));
|
||||
.w--inline-xxl {
|
||||
width: calc(var(--font-size-xxl) * var(--line-height));
|
||||
}
|
||||
}
|
||||
|
||||
.w--inline-xxxl {
|
||||
width: calc(var(--font-size-xxxl) * var(--line-height));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,11 @@
|
||||
width: var(--height-item-xl);
|
||||
}
|
||||
|
||||
.w--item--2xl {
|
||||
width: var(--height-item-2xl);
|
||||
.w--item--xxl {
|
||||
width: var(--height-item-xxl);
|
||||
}
|
||||
}
|
||||
|
||||
.w--item--xxxl {
|
||||
width: var(--height-item-xxxl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ type VariantProps<V extends Record<string, Record<string, string>>> = Partial<{
|
||||
[K in keyof V]: keyof V[K] | boolean;
|
||||
}>;
|
||||
|
||||
export function createClassRecipe<V extends Record<string, Record<string, string>>>(
|
||||
config: VariantsConfig<V>,
|
||||
) {
|
||||
export function createClassRecipe<
|
||||
V extends Record<string, Record<string, string>>,
|
||||
>(config: VariantsConfig<V>) {
|
||||
return function (props: VariantProps<V> = {}): string {
|
||||
const classes: string[] = [];
|
||||
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/**
|
||||
* Use "--" as separator to split prefix and surffix.
|
||||
*
|
||||
* If a utility has not "--" separator, all are treated as a prefix.
|
||||
* @example
|
||||
* const a = "text--xs px--xs gap";
|
||||
* const b = "px--none gap--xs";
|
||||
* const result = merge_class([a,b]);
|
||||
* // Output: "text--xs px--none gap--xs"
|
||||
*/
|
||||
export function mergeClass(...classes: (string[] | string)[]) {
|
||||
const map = new Map<string, string>();
|
||||
|
||||
|
||||
@@ -2,3 +2,5 @@ declare module "*.css" {
|
||||
const content: string;
|
||||
export default content;
|
||||
}
|
||||
|
||||
declare module "*.json";
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
// 继承 TS 检查文件,按需覆盖。
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
// 前端用 bundler,交给打包器负责,后端用 nodenext。
|
||||
"moduleResolution": "bundler",
|
||||
// 指定内置工具库,前端需包含 DOM,后端需包含 esnext。
|
||||
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
||||
// 输出编译后文件,如果用于 TS 检查则为 true。
|
||||
"noEmit": false,
|
||||
// 生成 d.ts 声明文件。
|
||||
"declaration": true,
|
||||
// 方便调试
|
||||
"declarationMap": true,
|
||||
// 输出目录
|
||||
"outDir": "./dist/",
|
||||
// 源码根目录,如果用于 TS 检查则不写,默认是 "." 项目根目录。
|
||||
"rootDir": "./src",
|
||||
// 方便调试
|
||||
"sourceMap": true,
|
||||
// 如果你用了 vite,设为 true,本文件仅生成 d.ts,编译完全交给 vite 。
|
||||
"emitDeclarationOnly": false
|
||||
},
|
||||
// 本配置文件的作用范围,打包不需要包含 src 外部的各种配置文件,例如 vite.config.ts 。
|
||||
"include": ["src"]
|
||||
}
|
||||
@@ -1,54 +1,44 @@
|
||||
{
|
||||
// 本文件仅供 TS Server 检查语法,不负责编译,编译使用的是另一个文件 tsconfig.build.json
|
||||
|
||||
// TS 类型检查专用配置, build 配置继承后按需覆盖。
|
||||
"compilerOptions": {
|
||||
// This is a component library, so "ESNext" is a good choice. Also it requires very little down-leveling during transpilation.
|
||||
"target": "esnext",
|
||||
// Include a list of type definitions for build-in JS APIs.
|
||||
"lib": ["esnext", "DOM", "DOM.Iterable"],
|
||||
// Specify the module system for the output files. It's not required for Vite but good to have.
|
||||
// 编译后, 输出的语法格式,自从 2026 年后,cjs 模块也能识别 es 模块了,如果需要兼容老项目则调低版本
|
||||
"target": "es2023",
|
||||
// 前端用 esnext ,后端用 nodenext ,node 其实也是用 js 写的一个库,前端是不带这个库的
|
||||
"module": "esnext",
|
||||
// The types defined in "vite/client" are included in global scope.
|
||||
"types": ["node", "vite/client"],
|
||||
// Do not emit compiled output files, vite will take care of the that.
|
||||
"noEmit": true,
|
||||
// Vite will handle the resolution of the import paths.
|
||||
"moduleResolution": "bundler",
|
||||
// Use the React 17 JSX transform, importing React is no longer required.
|
||||
"jsx": "react-jsx",
|
||||
// Skip the type checking for declaration files to improve performance.
|
||||
"skipLibCheck": true,
|
||||
// Allow importing modules with ".json" extension.
|
||||
"resolveJsonModule": true,
|
||||
// "declarationMap" need to be enabled to let Vite generates source map files.
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
// Importing .js files is not allowed, enable if needed.
|
||||
"allowJs": false,
|
||||
// Fix the mis-match of behaviors between ES import and CommonJS require.
|
||||
// 所有项目必须开,兼容 es 和 cjs 导入,允许 import React from 'react' ,而非 import * as React 。
|
||||
"esModuleInterop": true,
|
||||
// Allow default import from modules with no default export, i.e. you can write `import React from 'react'` instead of `import * as React from 'react'`.
|
||||
"allowSyntheticDefaultImports": true,
|
||||
// Enforce the file name casing to be consistent with development environment.
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
// Ensure the run-time code does not depend on the TypeScript-only features, such as constant enum.
|
||||
"isolatedModules": true,
|
||||
// Allow importing TypeScript modules.
|
||||
// 允许导入 ts,tsx 扩展名,include 里可以省略后缀。
|
||||
"allowImportingTsExtensions": true,
|
||||
// Enfore "type" modifier for type imports.
|
||||
"verbatimModuleSyntax": true,
|
||||
// Ensure the public class field initialization is transpiled correctly to match the future JS standard.
|
||||
"useDefineForClassFields": true,
|
||||
// Type-checking options
|
||||
// 允许 js,jsx 扩展名,include 里可以省略后缀。
|
||||
"allowJs": true,
|
||||
// 启用装饰器,也就是 @XXX 注解。
|
||||
"experimentalDecorators": true,
|
||||
// 发射装饰器元数据。
|
||||
"emitDecoratorMetadata": true,
|
||||
// 转换 jsx 时,使用 17+ 的新语法导入 react 。
|
||||
"jsx": "react-jsx",
|
||||
// 可作为子项目,被其他项目引用,但建议使用 workspace dep 模式,不是写 references 。
|
||||
"composite": false,
|
||||
// 只加载指定类型的声明包,避免加载无用类型,提升编译速度
|
||||
"types": ["node", "vite/client"],
|
||||
// 不输出编译后的文件,也就是 dist 目录下为空, 本文件只做类型检查。
|
||||
"noEmit": true,
|
||||
// 开启严格类型检查模式,只需开启这一个,其他的等于都开启了,要注意这只是类型检查,而非语法检查。
|
||||
"strict": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noImplicitOverride": true,
|
||||
"noImplicitReturns": true,
|
||||
"noImplicitThis": true,
|
||||
"noPropertyAccessFromIndexSignature": true,
|
||||
"noUncheckedIndexedAccess": true,
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": true
|
||||
// 让 TS 编译器保留用于注解的 import 语句,不要优化掉,后面 babel 转义器要用。
|
||||
"verbatimModuleSyntax": true,
|
||||
// 跳过第三方库的类型检查,加快编译速度,减少30% 。
|
||||
"skipLibCheck": true,
|
||||
// 跳过内置库的类型检查,加快编译速度,分钟级降至秒级。
|
||||
"skipDefaultLibCheck": true,
|
||||
// 增量编译,加快编译速度,尤其是大项目。
|
||||
"incremental": true
|
||||
},
|
||||
"include": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx"],
|
||||
// 本配置文件的作用范围,包含根目录下的一切文件,包括 vite.config.ts 等配置文件
|
||||
"include": ["**/*.ts",],
|
||||
// 本配置文件排除的范围。
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"dist",
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
import type { Plugin } from "vite";
|
||||
import { glob } from "glob";
|
||||
import * as path from "path";
|
||||
import * as fs from "fs";
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
export type PluginOption = {
|
||||
include: string[];
|
||||
exclude?: string[];
|
||||
preamble: string;
|
||||
entry: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Per `option` have follow property:
|
||||
* @param include
|
||||
* value like ["src/**\/*.{tsx,jsx,ts,js}"]
|
||||
* @param preamble
|
||||
* value like `"export * from "`
|
||||
*/
|
||||
export function genIndex(...options: PluginOption[]): Plugin {
|
||||
return {
|
||||
name: "VITE_PLUGIN_GEN_INDEX",
|
||||
|
||||
config() {
|
||||
options.forEach((opt) => {
|
||||
const entryToFileArray: string[] = [];
|
||||
const includeArray = opt.include;
|
||||
const excludeArray = opt.exclude;
|
||||
includeArray.forEach((ipath) => {
|
||||
const files = glob.sync(ipath, { ignore: excludeArray });
|
||||
|
||||
files.forEach((file) => {
|
||||
let entryToFile = path.relative(opt.entry, file);
|
||||
// console.log(`origin: ${entryToFile}`);
|
||||
|
||||
// Fix the bug of path.relative, file in the same dir should start with [ ./ ] not [ ../ ]
|
||||
if (entryToFile.startsWith("..")) {
|
||||
entryToFile = entryToFile.substring(1);
|
||||
// console.log(`after substring: ${entryToFile}`);
|
||||
}
|
||||
|
||||
// Fix the bug of lib, default is output "\" , we need handle by self, replace "\" to "/" for Windows
|
||||
entryToFile = entryToFile.replace(/\\/g, "/");
|
||||
// console.log(`after replace: ${entryToFile} \n`);
|
||||
|
||||
entryToFileArray.push(
|
||||
opt.preamble.concat(" ", "'", entryToFile, "';"),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
fs.writeFileSync(opt.entry, entryToFileArray.join("\n"), "utf-8");
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
import { resolve } from "node:path";
|
||||
import { defineConfig } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import dts from "unplugin-dts/vite";
|
||||
import pkg from "./package.json" with { type: "json" };
|
||||
import { genIndex, PluginOption } from "./vite-plugin/vite-plugin-gen-index.ts";
|
||||
|
||||
const genTsOption: PluginOption = {
|
||||
include: ["src/**/*.{tsx,ts,jsx,js}"],
|
||||
exclude: ["src/app.tsx", "src/main.tsx", "src/index.ts"],
|
||||
preamble: "export * from",
|
||||
entry: "src/index.ts",
|
||||
};
|
||||
|
||||
const genCssOption: PluginOption = {
|
||||
include: ["src/**/*.css"],
|
||||
exclude: ["src/index.css"],
|
||||
preamble: "@import",
|
||||
entry: "src/index.css",
|
||||
};
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
genIndex(genTsOption, genCssOption),
|
||||
react(),
|
||||
dts({
|
||||
outDirs: [
|
||||
{ dir: "dist", moduleFormat: "esm" },
|
||||
{ dir: "dist", moduleFormat: "cjs" },
|
||||
],
|
||||
bundleTypes: true,
|
||||
}),
|
||||
],
|
||||
|
||||
build: {
|
||||
target: "esnext",
|
||||
// Must write, vite/css-minify cannot recognize some ruler
|
||||
cssMinify: false,
|
||||
|
||||
lib: {
|
||||
entry: resolve(import.meta.dirname, "src/index.ts"),
|
||||
name: "ui-react",
|
||||
formats: ["es", "cjs"],
|
||||
fileName: `index`,
|
||||
cssFileName: "index",
|
||||
},
|
||||
rolldownOptions: {
|
||||
// make sure to externalize deps that shouldn't be bundled
|
||||
// into your library
|
||||
external: ["react/jsx-runtime", ...Object.keys(pkg.peerDependencies)],
|
||||
// output: {
|
||||
// assetFileNames: (assetInfo) => {
|
||||
// if (assetInfo.name && assetInfo.name.endsWith(".css")) {
|
||||
// return "index.css";
|
||||
// }
|
||||
// return "[name].[hash][extname]";
|
||||
// },
|
||||
// // Provide global variables to use in the UMD build
|
||||
// // for externalized deps
|
||||
// globals: {
|
||||
// react: "React",
|
||||
// "react-dom": "ReactDOM",
|
||||
// },
|
||||
// },
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user