This commit is contained in:
2026-11-29 23:46:33 +08:00
parent 94b38931d7
commit 215d6d1253
42 changed files with 369 additions and 8367 deletions
+78
View File
@@ -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...
},
},
])
```
+19
View File
@@ -0,0 +1,19 @@
import { Theme } from "../src/components/theme/theme";
import { ButtonGallery } from "./gallery/button-gallery";
import { MenuGallery } from "./gallery/menu-gallery";
import { PopoverGallery } from "./gallery/popover-gallery";
import "../src/index.css";
function App() {
return (
<div className="app">
<Theme>
<ButtonGallery />
<PopoverGallery />
<MenuGallery />
</Theme>
</div>
);
}
export default App;
+15
View File
@@ -0,0 +1,15 @@
import type { ReactNode } from "react";
export const IW = ({ children }: { children: ReactNode }) => {
return (
<div
style={{
gap: "10px",
display: "flex",
flexWrap: "nowrap",
}}
>
{children}
</div>
);
};
+17
View File
@@ -0,0 +1,17 @@
import type { ReactNode } from "react";
export const OW = ({ children }: { children: ReactNode }) => {
return (
<div
style={{
margin: "20px",
gap: "20px",
display: "flex",
flexDirection: "column",
flexWrap: "nowrap",
}}
>
{children}
</div>
);
};
@@ -0,0 +1,110 @@
import { DownloadSvg } from "../../src/assets/svg/download-svg";
import { Button } from "../../src/components/button/button";
import { IW } from "../common/iw";
import { OW } from "../common/ow";
export const ButtonGallery = () => {
return (
<OW>
<IW>
<Button size="xs">xsmall</Button>
<Button size="xs" iconSvg={<DownloadSvg />}>
xsmall
</Button>
<Button size="xs" iconSvg={<DownloadSvg />} isIconOnly={true}>
xsmall
</Button>
<Button
size="xs"
iconSvg={<DownloadSvg />}
canLoading={true}
isLoading={true}
>
isLoading
</Button>
<Button size="xs" iconSvg={<DownloadSvg />} canLoading={true}>
canLoading
</Button>
</IW>
<IW>
<Button size="sm">small</Button>
<Button size="sm" iconSvg={<DownloadSvg />}>
下载
</Button>
<Button size="sm" iconSvg={<DownloadSvg />} isIconOnly={true}>
small
</Button>
<Button
size="sm"
iconSvg={<DownloadSvg />}
canLoading={true}
isLoading={true}
>
isLoading
</Button>
<Button size="sm" iconSvg={<DownloadSvg />} canLoading={true}>
canLoading
</Button>
</IW>
<IW>
<Button size="md">medium</Button>
<Button size="md" iconSvg={<DownloadSvg />}>
medium
</Button>
<Button size="md" iconSvg={<DownloadSvg />} isIconOnly={true}>
medium
</Button>
<Button
size="md"
iconSvg={<DownloadSvg />}
canLoading={true}
isLoading={true}
>
isLoading
</Button>{" "}
<Button size="md" iconSvg={<DownloadSvg />} canLoading={true}>
canLoading
</Button>
</IW>
<IW>
<Button size="lg">large</Button>
<Button size="lg" iconSvg={<DownloadSvg />}>
large
</Button>
<Button size="lg" iconSvg={<DownloadSvg />} isIconOnly={true}>
large
</Button>
<Button
size="lg"
iconSvg={<DownloadSvg />}
canLoading={true}
isLoading={true}
>
isLoading
</Button>{" "}
<Button
size="lg"
iconSvg={<DownloadSvg />}
canLoading={true}
>
canLoading
</Button>
</IW>
<IW>
<Button size="md" variant={"filled"} iconSvg={<DownloadSvg />}>
filled
</Button>
<Button size="md" variant={"outline"} iconSvg={<DownloadSvg />}>
outline
</Button>
<Button size="md" variant={"subtle"} iconSvg={<DownloadSvg />}>
subtle
</Button>
<Button size="md" variant={"ghost"} iconSvg={<DownloadSvg />}>
ghost
</Button>
</IW>
</OW>
);
};
@@ -0,0 +1,110 @@
import { KeySvg } from "../../src/assets/svg/key-svg";
import { Button } from "../../src/components/button/button";
import { Menu } from "../../src/components/menu/menu";
import { MenuCheckItem } from "../../src/components/menu/menu-check-item";
import { MenuDropdown } from "../../src/components/menu/menu-dropdown";
import { MenuItem } from "../../src/components/menu/menu-item";
import { MenuRadioItem } from "../../src/components/menu/menu-radio-item";
import { MenuRadioItemGroup } from "../../src/components/menu/menu-radio-item-group";
import { MenuTrigger } from "../../src/components/menu/menu-trigger";
import { IW } from "../common/iw";
import { OW } from "../common/ow";
export const MenuGallery = () => {
return (
<OW>
<IW>
<Menu>
<MenuTrigger>
<Button size="sm" variant="ghost">
文件
</Button>
</MenuTrigger>
<MenuDropdown>
<MenuItem iconSvg={<KeySvg />}>Open File...</MenuItem>
<MenuItem>Open Folder...</MenuItem>
<Menu>
<MenuTrigger>
<MenuItem>Preferences</MenuItem>
</MenuTrigger>
<MenuDropdown>
<MenuItem>Profile</MenuItem>
<MenuItem>Settings</MenuItem>
</MenuDropdown>
</Menu>
<MenuCheckItem name={"auto-link"} value={"auto-link"}>
Auto Lint
</MenuCheckItem>
<Menu>
<MenuTrigger>
<MenuItem>Ruler</MenuItem>
</MenuTrigger>
<MenuDropdown>
<MenuRadioItemGroup
defaultSelectedValue="hori"
name="direction"
>
<MenuRadioItem value="hori">Hori</MenuRadioItem>
<MenuRadioItem value="verti">Verti</MenuRadioItem>
<MenuRadioItem value="both">Hoth</MenuRadioItem>
</MenuRadioItemGroup>
</MenuDropdown>
</Menu>
</MenuDropdown>
</Menu>
</IW>
<IW>
<Menu size="md">
<MenuTrigger>
<Button size="md" variant="ghost">
文件
</Button>
</MenuTrigger>
<MenuDropdown>
<MenuItem iconSvg={<KeySvg />}>Open File...</MenuItem>
<MenuItem>Open Folder...</MenuItem>
{/* 子菜单 */}
<Menu>
<MenuTrigger>
<MenuItem>Preferences</MenuItem>
</MenuTrigger>
<MenuDropdown>
<MenuItem>Profile</MenuItem>
<MenuItem>Settings</MenuItem>
{/* 子菜单 */}
<Menu>
<MenuTrigger>
<MenuItem>To open 3</MenuItem>
</MenuTrigger>
<MenuDropdown>
<MenuItem>Profile</MenuItem>
<MenuItem>Settings</MenuItem>
</MenuDropdown>
</Menu>
</MenuDropdown>
</Menu>
<MenuCheckItem name={"auto-link"} value={"auto-link"}>
Auto Lint
</MenuCheckItem>
<Menu>
<MenuTrigger>
<MenuItem>Ruler</MenuItem>
</MenuTrigger>
<MenuDropdown>
<MenuRadioItemGroup
defaultSelectedValue="hori"
name={"direaction"}
>
<MenuRadioItem value="hori">Hori</MenuRadioItem>
<MenuRadioItem value="verti">Verti</MenuRadioItem>
<MenuRadioItem value="both">Hoth</MenuRadioItem>
</MenuRadioItemGroup>
</MenuDropdown>
</Menu>
</MenuDropdown>
</Menu>
</IW>
</OW>
);
};
@@ -0,0 +1,21 @@
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 { IW } from "../common/iw";
import { OW } from "../common/ow";
export const PopoverGallery = () => {
return (
<OW>
<IW>
<Popover>
<PopoverTrigger>
<Button>Open Popover</Button>
</PopoverTrigger>
<PopoverDropdown>This is Popover Content !</PopoverDropdown>
</Popover>
</IW>
</OW>
);
};
+9
View File
@@ -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>,
)
+12
View File
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ui-react</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/demo/main.tsx"></script>
</body>
</html>
+14 -16
View File
@@ -1,39 +1,36 @@
{
"name": "@dg/ui-react",
"version": "1.0.0",
"private": true,
"version": "0.0.0",
"type": "module",
"license": "MIT",
"sideEffects": [
"*.css"
],
"files": [
"dist/[^.]*",
"types/[^.]*",
"docs/[^.]*",
"doc/[^.]*"
"dist",
"types",
"docs",
"doc"
],
"module": "index.js",
"browser": "index.umd.js",
"typings": "index.d.ts",
"exports": {
"./index.css": "./dist/index.css"
},
"scripts": {
"build": "vite build && tsc --project tsconfig.build.json"
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@floating-ui/react": "^0.27.20",
"react-hotkeys-hook": "^5.4.0"
},
"devDependencies": {
"@types/node": "^26.6.6",
"@types/react": "^19.3.0",
"@types/react-dom": "^19.3.0",
"@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",
@@ -44,7 +41,8 @@
"eslint-plugin-react-refresh": "^0.5.8",
"globals": "^17.14.0",
"typescript": "~6.0.3",
"typescript-eslint": "^8.73.0"
"typescript-eslint": "^8.73.0",
"vite": "^8.4.0"
},
"peerDependencies": {
"react": "^19.3.1",
@@ -4,11 +4,11 @@ import { mergeClass } from "../../styles/utils/merge-class";
import { inlineSizeRecipe } from "../../styles/recipes/inline-size-recipe";
import { useMergeRefs } from "@floating-ui/react";
import { containerRecipe } from "../../styles/recipes/container-recipe";
import { downGradeSize } from "../../utils/down-grade-size";
import { Icon } from "../icon/icon";
import { CheckboxCheckedSvg } from "../../assets/svg/checkbox-checked-svg";
import { CheckboxUncheckedSvg } from "../../assets/svg/checkbox-unchecked-svg";
import { itemSizeRecipe } from "../../styles/recipes/item-size-recipe";
import { downGradeSize } from "../../styles/utils/down-grade-size";
export type CheckboxInputProps = CommonProps & {
size?: "sm" | "md";
@@ -21,12 +21,14 @@ import { inlineSizeRecipe } from "../../styles/recipes/inline-size-recipe";
export type MenuCheckItemProps = CommonProps & {
size?: "sm" | "md";
iconSvg?: React.ReactNode;
hotkey?: string;
// =================
name: string;
value: string;
checked?: boolean;
defaultChecked?: boolean;
onChange?: (nextChecked: boolean) => void;
// =================
iconSvg?: React.ReactNode;
hotkey?: string;
};
export const MenuCheckItem = (props: MenuCheckItemProps) => {
@@ -42,6 +44,8 @@ export const MenuCheckItem = (props: MenuCheckItemProps) => {
isDisabled = false,
hotkey,
style,
name,
value,
...rest
} = props;
@@ -140,8 +144,8 @@ export const MenuCheckItem = (props: MenuCheckItemProps) => {
})}
>
<CheckboxInput
name=""
value=""
name={name}
value={value}
ref={useMergeRefs([inputRef, ref])}
size={size}
defaultChecked={checked}
@@ -149,6 +153,7 @@ export const MenuCheckItem = (props: MenuCheckItemProps) => {
checked={checked}
// 绑定 state 第2/2步,本元素被键盘点击后,将新值写回 state
onChange={changeHandler}
asBoxOnly={true}
/>
<div className={startSectionClass}>
@@ -3,7 +3,6 @@ import {
FloatingFocusManager,
FloatingList,
FloatingPortal,
useMergeRefs,
} from "@floating-ui/react";
import { useMenuFloatingContext } from "./use-menu-floating-context";
import { useMenuContext } from "./use-menu-context";
@@ -1,35 +1,39 @@
import { useEffect, useRef, useState } from "react";
import type { CommonProps } from "../../utils/common-props";
import { MenuRadioItemGroupContext } from "../radiobox-input/use-radiobox-input-group-context";
import { useMenuContext } from "./use-menu-context";
import { RadioboxInputGroup } from "../radiobox-input/radiobox-input-group";
export type MenuRadioItemGroupProps = CommonProps & {
size?: "sm" | "md";
name: string;
defaultSelectName?: string;
onChange?: (nextSelect?: string) => void;
defaultSelectedValue?: string;
onChange?: (nextSelected?: string) => void;
canNoneSelected?: boolean;
};
export const MenuRadioItemGroup = (props: MenuRadioItemGroupProps) => {
const {
size = "sm",
defaultSelectName = "",
children,
defaultSelectedValue,
name,
onChange,
...rest
canNoneSelected = false,
children,
} = props;
const [selectValue, setSelectValue] = useState<string>(defaultSelectName);
const { size: menuSize } = useMenuContext()!;
const currentSize = menuSize ?? size;
return (
<MenuRadioItemGroupContext
value={{ size: currentSize, selectValue, setSelectValue}}
<RadioboxInputGroup
name={name}
size={currentSize}
onChange={onChange}
defaultSelectedValue={defaultSelectedValue}
canNoneSelected={canNoneSelected}
>
<div {...rest}>{children}</div>
</MenuRadioItemGroupContext>
{children}
</RadioboxInputGroup>
);
};
@@ -1,21 +1,38 @@
import { useRef } from "react";
import {
useEffect,
useId,
useRef,
useState,
type CSSProperties,
type MouseEvent,
} from "react";
import type { CommonProps } from "../../utils/common-props";
import { useMenuRadioItemGroupContext } from "../radiobox-input/use-radiobox-input-group-context";
import { useMenuContext } from "./use-menu-context";
import { useMenuFloatingContext } from "./use-menu-floating-context";
import { useListItem, useMergeRefs } from "@floating-ui/react";
import { mergeClass } from "../../styles/utils/merge-class";
import { displayRecipe } from "../../styles/recipes/display-recipe";
import { containerRecipe } from "../../styles/recipes/container-recipe";
import { itemSizeRecipe } from "../../styles/recipes/item-size-recipe";
import { variantRecipe } from "../../styles/recipes/variant-recipe";
import { inlineSizeRecipe } from "../../styles/recipes/inline-size-recipe";
import { Icon } from "../icon/icon";
import { RadioboxInput } from "../radiobox-input/radiobox-input";
export type MenuRadioItemProps = CommonProps & {
value: string;
size?: "sm" | "md";
name?: string;
value?: string;
checked?: boolean;
defaultChecked?: boolean;
onChange?: (nextChecked: boolean) => void;
// ===============
iconSvg?: React.ReactNode;
hotkey?: string;
// ===============
onChange?: (nextSelect?: boolean) => void;
};
export const MenuRadioItem = (props: MenuRadioItemProps) => {
const {
size: propSize = "sm",
name,
value,
iconSvg,
hotkey,
@@ -23,16 +40,140 @@ export const MenuRadioItem = (props: MenuRadioItemProps) => {
ref,
children,
className,
checked: controlledChecked,
defaultChecked = false,
isDisabled = false,
style,
...rest
} = props;
// ========= Radio Group Context Cunsumer =====================================================
const { selectValue, setSelectValue } = useMenuRadioItemGroupContext()!;
const isSelect = value === selectValue;
const [checked, setChecked] = useState<boolean>(
controlledChecked ?? defaultChecked,
);
const inputRef = useRef<HTMLInputElement>(null);
// =========================================================
return <div></div>;
// =============== Menu Context Consumer ====================================================================
const menuContext = useMenuContext();
const size = menuContext?.size ?? propSize;
const stateRegistry = menuContext?.stateRegistry;
const stateKeyRef = useRef<string>(null);
useEffect(() => {
stateKeyRef.current = useId();
stateRegistry?.insertKey(stateKeyRef.current);
stateRegistry?.updateValue(stateKeyRef.current, {
hasIcon: iconSvg != undefined,
hasCheckbox: true,
hasIndicator: false,
});
return () => {
// 清除注册表里的数据,永远不会有无用 key
stateRegistry?.deleteEntry(stateKeyRef.current!);
};
}, []);
// 后面渲染要用到
const stateResult = menuContext?.stateResult;
// =============== Menu Floating Context Consumer ====================================================================
const menuFloatingContext = useMenuFloatingContext();
const { getItemProps, activeIndex } = menuFloatingContext!;
const item = useListItem();
const isActive = item.index === activeIndex;
// ================== Style =================================================================
const rootClass = mergeClass(
displayRecipe({ justifyContent: "between" }),
containerRecipe({ hasFocusOutline: "false" }),
itemSizeRecipe({ size, shape: "rounded" }),
variantRecipe({ variant: "ghost", isDisabled }),
);
const rootStyle: CSSProperties = {
width: "100%",
...style,
};
const startSectionClass = mergeClass([
displayRecipe(),
inlineSizeRecipe({ size }),
]);
const endSectionClass = mergeClass([
displayRecipe(),
inlineSizeRecipe({ size }),
]);
// =============== Event ==========================================
// 将 Checkbox 的 onClick 范围扩大至整个容器元素
function clickHandler(e: MouseEvent<HTMLDivElement>) {
// 防止 input 和 div 重叠,响应两次 onClick
e.stopPropagation();
// 前面没有 on
inputRef?.current?.click();
}
function changeHandler(nextChecked: boolean) {
// 触发重新渲染,受控模式下,即使 set 也改变不了状态
setChecked(nextChecked);
// 执行受控回调函数,向上层传递新值,或许上层组件会拒绝变更从 prop 传入的 checked
onChange?.(nextChecked);
}
return (
<button
{...rest}
// 此处不需要 mergeRefs,通过 onClick 已经连上了 ref
ref={item.ref}
className={rootClass}
role="menuitem"
tabIndex={isActive ? 0 : -1}
disabled={isDisabled}
{...getItemProps({
style: rootStyle,
onClick: clickHandler,
})}
>
<RadioboxInput
value={value}
ref={useMergeRefs([inputRef, ref])}
size={size}
defaultChecked={checked}
// 绑定 state 第1/2步,从 state 中获取数据
checked={checked}
// 绑定 state 第2/2步,本元素被键盘点击后,将新值写回 state
onChange={changeHandler}
asBoxOnly={true}
/>
<div className={startSectionClass}>
{stateResult?.hasIcon && iconSvg ? (
<Icon size={size}>{iconSvg}</Icon>
) : (
<Icon size={size}>
<div></div>
</Icon>
)}
{children}
</div>
<div className={endSectionClass}>
{hotkey && <div>{hotkey}</div>}
{stateResult?.hasIndicator && (
<Icon size={size}>
<div></div>
</Icon>
)}
</div>
</button>
);
};
@@ -2,7 +2,7 @@ import { useMenuFloatingContext } from "./use-menu-floating-context";
import { Slot } from "../../utils/slot";
import { MenuTriggerContext } from "./use-menu-trigger-context";
import type { CommonProps } from "../../utils/common-props";
import { containerRecipe } from "../../styles/recipes/container-recipe";
export type MenuTriggerProps = CommonProps;
@@ -23,7 +23,6 @@ export const PopoverDropdown = (props: PopoverDropdownProps) => {
context,
arrowRef,
isMounted,
isOpen,
transitionStyles,
arrowWidth,
arrowHeight,
@@ -58,7 +57,7 @@ export const PopoverDropdown = (props: PopoverDropdownProps) => {
return (
<>
{isOpen && (
{isMounted && (
<FloatingPortal>
<FloatingFocusManager context={context} modal={false}>
<div
@@ -5,7 +5,7 @@ import { usePopoverContext } from "./use-popover-context";
export type PopoverTriggerProps = CommonProps;
export const PopoverTrigger = (props: PopoverTriggerProps) => {
const { children, ...rest } = props;
const { children } = props;
const { refs, getReferenceProps } = usePopoverContext()!;
@@ -1,7 +1,6 @@
import { useRef, useState, type ChangeEvent, type MouseEvent } from "react";
import { useRef, type ChangeEvent, type MouseEvent } from "react";
import { useMergeRefs } from "@floating-ui/react";
import type { CommonProps } from "../../utils/common-props";
import { downGradeSize } from "../../utils/down-grade-size";
import { mergeClass } from "../../styles/utils/merge-class";
import { containerRecipe } from "../../styles/recipes/container-recipe";
import { inlineSizeRecipe } from "../../styles/recipes/inline-size-recipe";
@@ -11,6 +10,7 @@ import { RadioboxUncheckedSvg } from "../../assets/svg/radiobox-unchecked-svg";
import { itemSizeRecipe } from "../../styles/recipes/item-size-recipe";
import { useRadioboxInputGroupContext } from "./use-radiobox-input-group-context";
import { displayRecipe } from "../../styles/recipes/display-recipe";
import { downGradeSize } from "../../styles/utils/down-grade-size";
export type RadioboxInputProps = CommonProps & {
value: string;
@@ -1,23 +1,17 @@
import type { CSSProperties } from "react";
export const Slider = () => {
const sliderStyle: CSSProperties = {
display: "flex",
flexWrap: "nowrap",
justifyContent: "center",
alignItems: "center",
userSelect: "none",
};
const sliderThumbStyle: CSSProperties = {
height: "16px",
width: "16px",
};
const sliderRailStyle: CSSProperties = {
height: "6px",
width: "auto",
};
// const sliderThumbStyle: CSSProperties = {
// height: "16px",
// width: "16px",
// };
return <div></div>
// const sliderRailStyle: CSSProperties = {
// height: "6px",
// width: "auto",
// };
return <div ></div>
};
@@ -6,7 +6,6 @@ import { itemSizeRecipe } from "../../styles/recipes/item-size-recipe";
import { brandRecipe } from "../../styles/recipes/brand-recipe";
import { variantRecipe } from "../../styles/recipes/variant-recipe";
import type { CommonProps } from "../../utils/common-props";
import { useState, type ReactNode } from "react";
import { mergeClass } from "../../styles/utils/merge-class";
export type TagProps = CommonProps & {
@@ -5,7 +5,7 @@
* @example
* const a = "text--xs px--xs gap";
* const b = "px--none gap--xs";
* const result = merge_class([a,b]);
* const result = mergeClass([a,b]);
* // Output: "text--xs px--none gap--xs"
*/
export function mergeClass(...classes: (string[] | string)[]) {
@@ -8,7 +8,6 @@ export function mergeProps(...propsList: AnyProps[]): AnyProps {
const result: AnyProps = {}
const refsArray: any[] = []
const classArray: string[] = []
const fnMap = new Map<string, Array<(...args: unknown[]) => void>>()
if (propsList.length === 1) {
return propsList[0]!
+30
View File
@@ -0,0 +1,30 @@
{
"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,
/* d.ts */
// "declaration": true,
// "emitDeclarationOnly": true
},
"include": ["src", "demo"]
}
-26
View File
@@ -1,26 +0,0 @@
{
// 继承 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": true
},
// 本配置文件的作用范围,打包不需要包含 src 外部的各种配置文件,例如 vite.config.ts 。
"include": ["src"]
}
File diff suppressed because one or more lines are too long
+4 -70
View File
@@ -1,73 +1,7 @@
{
// 本文件仅供 TS Server 检查语法,不负责编译,编译使用的是另一个文件 tsconfig.build.json
// TS 类型检查专用配置, build 配置继承后按需覆盖。
"compilerOptions": {
// 编译后, 输出的语法格式,自从 2026 年后,cjs 模块也能识别 es 模块了,如果需要兼容老项目则调低版本
"target": "es2023",
// 前端用 esnext ,后端用 nodenext ,node 其实也是用 js 写的一个库,前端是不带这个库的
"module": "esnext",
// 所有项目必须开,兼容 es 和 cjs 导入,允许 import React from 'react' ,而非 import * as React 。
"esModuleInterop": true,
// 允许导入 ts,tsx 扩展名。
"allowImportingTsExtensions": true,
// 允许导入 js,jsx 扩展名。
"allowJs": true,
// 允许导入 json 模块,而不只是 ts,js,css 。
"resolveJsonModule": true,
// 启用装饰器,也就是 @XXX 注解。
"experimentalDecorators": true,
// 发射装饰器元数据。
"emitDecoratorMetadata": true,
// 转换 jsx 时,使用 17+ 的新语法导入 react 。
"jsx": "react-jsx",
// 可作被其他项目引用源码,但有潜在的 ts 版本问题,建议使用 workspace dep 模式,而不是写 references 。
"composite": false,
// 只加载指定类型的声明包,避免加载无用类型,提升编译速度
"types": ["node", "vite/client"],
// 不输出编译后的文件,也就是 dist 目录下为空, 本文件只做类型检查。
"noEmit": true,
// 开启严格类型检查模式,只需开启这一个,其他的等于都开启了,要注意这只是类型检查,而非语法检查。
"strict": true,
// 让 TS 编译器保留用于注解的 import 语句,不要优化掉,后面 babel 转义器要用。
"verbatimModuleSyntax": true,
// 跳过第三方库的类型检查,加快编译速度,减少30% 。
"skipLibCheck": true,
// 跳过内置库的类型检查,加快编译速度,分钟级降至秒级。
"skipDefaultLibCheck": true,
// 增量编译,加快编译速度,尤其是大项目。
"incremental": true
},
// 本配置文件的作用范围,包含根目录下的一切文件,包括 vite.config.ts 等配置文件
"include": ["**/*.ts", "*/*.tsx"],
// 本配置文件排除的范围。
"exclude": [
"node_modules",
"dist",
".turbo/**/*",
".cache/**/*",
".vite/**/*",
"vite.config.ts",
"*.config.ts",
"*.config.js",
"tsconfig.*.json",
"__tests__/**/*",
"test/**/*",
"tests/**/*",
"**/*.test.ts",
"**/*.test.tsx",
"**/*.spec.ts",
"**/*.spec.tsx",
".storybook/**/*",
"stories/**/*",
"example/**/*",
"examples/**/*",
"scripts/**/*",
".env",
".env.*",
"public/**/*",
"docs/**/*",
"README.md",
"LICENSE"
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
]
}
+26
View File
@@ -0,0 +1,26 @@
{
"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,
/* custom */
"resolveJsonModule": true
},
"include": ["vite.config.ts"]
}
+1 -1
View File
@@ -8,7 +8,7 @@ import pkg from "./package.json" with { type: "json" };
export default defineConfig({
devtools: {
// Remove this `apply` property to enable devtools for build as well
// apply: 'serve',
apply: "serve",
},
plugins: [react(), babel({ presets: [reactCompilerPreset()] })],