{hotkey &&
{hotkey}
}
+
{isTrigger && isOpen && (
{indicatorSvg}
)}
+
{isTrigger && !isOpen &&
{indicatorSvg}}
- {!isTrigger && (
- // 占位
+
+ {stateResult?.hasIndicator && (
diff --git a/packages/ui-react/src/components/menu/menu-radio-item-group.tsx b/packages/ui-react/src/components/menu/menu-radio-item-group.tsx
index 00f3686..b530bf2 100644
--- a/packages/ui-react/src/components/menu/menu-radio-item-group.tsx
+++ b/packages/ui-react/src/components/menu/menu-radio-item-group.tsx
@@ -1,10 +1,11 @@
import { useEffect, useRef, useState } from "react";
-import type { CommonProps } from "../../utils/CommonProps";
-import { MenuRadioItemGroupContext } from "./use-menu-radio-item-group-context";
+import type { CommonProps } from "../../utils/common-props";
+import { MenuRadioItemGroupContext } from "../radiobox-input/use-radiobox-input-group-context";
import { useMenuContext } from "./use-menu-context";
export type MenuRadioItemGroupProps = CommonProps & {
size?: "sm" | "md";
+ name: string;
defaultSelectName?: string;
onChange?: (nextSelect?: string) => void;
};
@@ -18,7 +19,7 @@ export const MenuRadioItemGroup = (props: MenuRadioItemGroupProps) => {
...rest
} = props;
- const [selectName, setSelectName] = useState
(defaultSelectName);
+ const [selectValue, setSelectValue] = useState(defaultSelectName);
const { size: menuSize } = useMenuContext()!;
@@ -26,7 +27,7 @@ export const MenuRadioItemGroup = (props: MenuRadioItemGroupProps) => {
return (
{children}
diff --git a/packages/ui-react/src/components/menu/menu-radio-item.tsx b/packages/ui-react/src/components/menu/menu-radio-item.tsx
index e194a8c..dc96ba1 100644
--- a/packages/ui-react/src/components/menu/menu-radio-item.tsx
+++ b/packages/ui-react/src/components/menu/menu-radio-item.tsx
@@ -1,20 +1,38 @@
import { useRef } from "react";
-import type { CommonProps } from "../../utils/CommonProps";
-import { useMenuRadioItemGroupContext } from "./use-menu-radio-item-group-context";
+import type { CommonProps } from "../../utils/common-props";
+import { useMenuRadioItemGroupContext } from "../radiobox-input/use-radiobox-input-group-context";
export type MenuRadioItemProps = CommonProps & {
- name: string;
- iconSvg?: React.ReactNode;
- hotkey?: string;
- onChange?: (preCheck?: boolean, nextCheck?: boolean) => void
+ size?: "sm" | "md";
+ name?: string;
+ value?: string;
+ iconSvg?: React.ReactNode;
+ hotkey?: string;
+ // ===============
+ onChange?: (nextSelect?: boolean) => void;
};
export const MenuRadioItem = (props: MenuRadioItemProps) => {
- const { name, children, className, hotkey, onChange, ref, iconSvg, style } = props
+ const {
+ size: propSize = "sm",
+ name,
+ value,
+ iconSvg,
+ hotkey,
+ onChange,
+ ref,
+ children,
+ className,
+ style,
+ } = props;
- const { selectName, setSelectName } = useMenuRadioItemGroupContext()!
- const isSelect = name === selectName
-
- return
-}
+ // ========= Radio Group Context Cunsumer =====================================================
+ const { selectValue, setSelectValue } = useMenuRadioItemGroupContext()!;
+ const isSelect = value === selectValue;
+
+ const inputRef = useRef(null);
+ // =========================================================
+
+ return ;
+};
diff --git a/packages/ui-react/src/components/menu/menu-trigger.tsx b/packages/ui-react/src/components/menu/menu-trigger.tsx
index b80e939..9f8d021 100644
--- a/packages/ui-react/src/components/menu/menu-trigger.tsx
+++ b/packages/ui-react/src/components/menu/menu-trigger.tsx
@@ -1,25 +1,24 @@
-import type { ComponentPropsWithoutRef } from "react";
-
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 = ComponentPropsWithoutRef<"div">;
+export type MenuTriggerProps = CommonProps;
export const MenuTrigger = (props: MenuTriggerProps) => {
const { children } = props;
- const menuFloatingContext = useMenuFloatingContext();
- const { refs, setIsOpen, getReferenceProps } = menuFloatingContext!;
+ const { refs, getReferenceProps } = useMenuFloatingContext()!;
return (
- { setIsOpen(true) } }
- )}>
+
{children}
- )
-
+ );
};
diff --git a/packages/ui-react/src/components/menu/menu.tsx b/packages/ui-react/src/components/menu/menu.tsx
index ab1aefb..bcc22a3 100644
--- a/packages/ui-react/src/components/menu/menu.tsx
+++ b/packages/ui-react/src/components/menu/menu.tsx
@@ -1,54 +1,107 @@
-import {
- FloatingNode,
- FloatingTree,
-} from "@floating-ui/react";
-import type { ComponentPropsWithoutRef } from "react";
+import { FloatingNode, FloatingTree } from "@floating-ui/react";
+import { useLayoutEffect, type ComponentPropsWithoutRef } from "react";
import { useMenuFloating } from "./use-menu-floating";
import { MenuFloatingContext } from "./use-menu-floating-context";
-import { MenuContext } from "./use-menu-context";
+import { MenuContext, useMenuContext } from "./use-menu-context";
import { mergeClass } from "../../styles/utils/merge-class";
+import { useStateRegistry } from "../../utils/use-state-registry";
export type MenuProps = ComponentPropsWithoutRef<"div"> & {
size?: "sm" | "md";
};
export const Menu = (props: MenuProps) => {
- const { size = "sm", className = "", children, ...rest } = props;
+ const { size: propSize = "sm", className = "", children, ...rest } = props;
+ // ============= parent Menu Context Cunsumer ==================================
+
+ const parentMenuContext = useMenuContext();
+ const size = parentMenuContext?.size ?? propSize;
+
+ // ============= Menu Floating Provider ==================================
const menuFloatingContextValue = useMenuFloating();
- const { isNested, nodeId } = menuFloatingContextValue!
+ const { isNested, nodeId } = menuFloatingContextValue!;
- // ==========================================================================================
+ // ============= Menu Context Provider ==================================
- const rootClass = mergeClass("position--relative",className)
+ const stateRegistry = useStateRegistry<{
+ hasIcon: boolean;
+ hasCheckbox: boolean;
+ hasIndicator: boolean;
+ }>((registry) => {
+ let result: {
+ hasIcon: boolean;
+ hasCheckbox: boolean;
+ hasIndicator: boolean;
+ } = { hasIcon: false, hasCheckbox: false, hasIndicator: false };
- // ==========================================================================================
+ registry.forEach((v) => {
+ if (v?.hasIcon) {
+ result.hasIcon = true;
+ }
+ if (v?.hasCheckbox) {
+ result.hasCheckbox = true;
+ }
+ if (v?.hasIndicator) {
+ result.hasIndicator = true;
+ }
+ });
- if (!isNested) {
- return (
-
-
-
-
-
- {children}
-
-
-
-
-
- );
- }
+ return result;
+ });
- return (
-
-
+ // ============== Style ============================================================================
+
+ const rootClass = mergeClass("position--relative", className);
+
+ // ============== Collect Childrens States ============================================================================
+
+ let stateResult:
+ | {
+ hasIcon: boolean;
+ hasCheckbox: boolean;
+ hasIndicator: boolean;
+ }
+ | undefined = undefined;
+
+ useLayoutEffect(() => {
+ if (stateRegistry.checkAllReady()) {
+ stateResult = stateRegistry.getResult();
+ }
+ });
+
+ // ======= Condition Return ======================================================
+
+ let returnStatement;
+
+ // 如果值为 undefined,则 return 空值, 也就是不渲染任何东西,但实际渲染函数还是执行了的
+ if (stateResult) {
+ if (!isNested) {
+ returnStatement = (
+
+
+
+ {children}
+
+
+
+ );
+ } else {
+ returnStatement = (
-
+
{children}
+ );
+ }
+ }
+
+ return (
+
+
+ {returnStatement}
);
diff --git a/packages/ui-react/src/components/menu/use-menu-context.ts b/packages/ui-react/src/components/menu/use-menu-context.ts
index 325cbd1..5b20f57 100644
--- a/packages/ui-react/src/components/menu/use-menu-context.ts
+++ b/packages/ui-react/src/components/menu/use-menu-context.ts
@@ -1,6 +1,21 @@
import { createContext, useContext } from "react";
+import type { useStateRegistry } from "../../utils/use-state-registry";
-export type MenuContextValue = { size?: "sm" | "md" } | null;
+export type MenuContextValue = {
+ size?: "sm" | "md";
+ stateRegistry?: ReturnType<
+ typeof useStateRegistry<{
+ hasIcon: boolean;
+ hasCheckbox: boolean;
+ hasIndicator: boolean;
+ }>
+ >;
+ stateResult?: {
+ hasIcon: boolean;
+ hasCheckbox: boolean;
+ hasIndicator: boolean;
+ };
+} | null;
export const MenuContext = createContext
(null);
diff --git a/packages/ui-react/src/components/menu/use-menu-floating.ts b/packages/ui-react/src/components/menu/use-menu-floating.ts
index fd07ffb..e6bfb44 100644
--- a/packages/ui-react/src/components/menu/use-menu-floating.ts
+++ b/packages/ui-react/src/components/menu/use-menu-floating.ts
@@ -44,20 +44,20 @@ export function useMenuFloating() {
});
const hover = useHover(context, {
+ // 仅子菜单启用 hover
enabled: isNested,
- delay: { open: 75 },
+ // 模拟 click, 鼠标即使移出了安全区,也不关闭 1s=1000ms
+ // 10分钟 = 6,000,000
+ delay: { open: 75, close: 6000000 },
+ // 必须开启,否则鼠标进入子菜单就关闭
handleClose: safePolygon({ blockPointerEvents: true }),
});
- const click = useClick(context, {
- event: "mousedown",
- toggle: !isNested,
- ignoreMouse: isNested,
- });
+ const click = useClick(context, {});
const role = useRole(context, { role: "menu" });
- const dismiss = useDismiss(context, { bubbles: true });
+ const dismiss = useDismiss(context);
const listNav = useListNavigation(context, {
listRef: elementsRef,
@@ -86,6 +86,6 @@ export function useMenuFloating() {
setSelectedIndex,
activeIndex,
isOpen,
- setIsOpen
+ setIsOpen,
};
}
diff --git a/packages/ui-react/src/components/menu/use-menu-radio-item-group-context.ts b/packages/ui-react/src/components/menu/use-menu-radio-item-group-context.ts
deleted file mode 100644
index dcee7a1..0000000
--- a/packages/ui-react/src/components/menu/use-menu-radio-item-group-context.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import { createContext, useContext } from "react";
-
-export type MenuRadioItemGroupContextValue = {
- size: "sm" | "md"
- selectName: string;
- setSelectName: React.Dispatch>;
-} | null;
-
-export const MenuRadioItemGroupContext = createContext(null)
-
-export function useMenuRadioItemGroupContext() {
- return useContext(MenuRadioItemGroupContext)
-}
\ No newline at end of file
diff --git a/packages/ui-react/src/components/popover/popover-dropdown.tsx b/packages/ui-react/src/components/popover/popover-dropdown.tsx
index f294115..628af74 100644
--- a/packages/ui-react/src/components/popover/popover-dropdown.tsx
+++ b/packages/ui-react/src/components/popover/popover-dropdown.tsx
@@ -1,5 +1,5 @@
import type { CSSProperties } from "react";
-import type { CommonProps } from "../../utils/CommonProps";
+import type { CommonProps } from "../../utils/common-props";
import { usePopoverContext } from "./use-popover-context";
import {
FloatingArrow,
@@ -23,6 +23,7 @@ export const PopoverDropdown = (props: PopoverDropdownProps) => {
context,
arrowRef,
isMounted,
+ isOpen,
transitionStyles,
arrowWidth,
arrowHeight,
@@ -57,14 +58,15 @@ export const PopoverDropdown = (props: PopoverDropdownProps) => {
return (
<>
- {isMounted && (
+ {isOpen && (
{children}
{
- const { children, ...rest } = props;
+ const { children, ...rest } = props;
- const { refs, getReferenceProps, setIsOpen, isOpen } = usePopoverContext()!
+ const { refs, getReferenceProps } = usePopoverContext()!;
- return { setIsOpen(!isOpen) } }
- )}>
- {children}
+ return (
+
+ {children}
-}
\ No newline at end of file
+ );
+};
diff --git a/packages/ui-react/src/components/popover/popover.tsx b/packages/ui-react/src/components/popover/popover.tsx
index 600fc5e..d165e05 100644
--- a/packages/ui-react/src/components/popover/popover.tsx
+++ b/packages/ui-react/src/components/popover/popover.tsx
@@ -1,16 +1,16 @@
-import type { CommonProps } from "../../utils/CommonProps"
-import { PopoverContext } from "./use-popover-context"
-import { usePopoverFloating } from "./use-popover-floating"
+import type { CommonProps } from "../../utils/common-props";
+import { PopoverContext } from "./use-popover-context";
+import { usePopoverFloating } from "./use-popover-floating";
-export type PopoverProps = CommonProps & {
-
-}
+export type PopoverProps = CommonProps & {};
export const Popover = (props: PopoverProps) => {
- const { children } = props
- const popoverFloatingContext = usePopoverFloating()
+ const { children } = props;
+ const popoverFloatingContext = usePopoverFloating();
- return
- {children}
+ return (
+
+ {children}
-}
\ No newline at end of file
+ );
+};
diff --git a/packages/ui-react/src/components/popover/use-popover-floating.ts b/packages/ui-react/src/components/popover/use-popover-floating.ts
index 10c10c0..d2c404d 100644
--- a/packages/ui-react/src/components/popover/use-popover-floating.ts
+++ b/packages/ui-react/src/components/popover/use-popover-floating.ts
@@ -1,83 +1,111 @@
-import { arrow, autoUpdate, flip, offset, shift, useClick, useDismiss, useFloating, useInteractions, useRole, useTransitionStyles } from "@floating-ui/react";
+import {
+ arrow,
+ autoUpdate,
+ flip,
+ offset,
+ shift,
+ useClick,
+ useDismiss,
+ useFloating,
+ useInteractions,
+ useRole,
+ useTransitionStyles,
+} from "@floating-ui/react";
import { useMemo, useRef, useState } from "react";
export function usePopoverFloating() {
- const [isOpen, setIsOpen] = useState(false);
- const arrowRef = useRef(null);
+ const [isOpen, setIsOpen] = useState(false);
+ const arrowRef = useRef(null);
- // 拉扯 svg 图像,让三角变得,更尖更长,或者更宽更扁
- const arrowWidth = 16
- const arrowHeight = 8
+ // 拉扯 svg 图像,让三角变得,更尖更长,或者更宽更扁
+ const arrowWidth = 16;
+ const arrowHeight = 8;
- const { refs, floatingStyles, context, middlewareData } = useFloating({
- placement: "top-start",
- open: isOpen,
- onOpenChange: setIsOpen,
- whileElementsMounted: autoUpdate,
- middleware: [
- offset(arrowHeight),
- flip({ padding: 8 }),
- // 偏移完成后,再留 8px 空白,而不是紧贴着父容器
- shift({ padding: 8 }),
- arrow({
- element: arrowRef,
- }),
- ],
- });
+ const { refs, floatingStyles, context, middlewareData } = useFloating({
+ placement: "top-start",
+ open: isOpen,
+ onOpenChange: setIsOpen,
+ whileElementsMounted: autoUpdate,
+ middleware: [
+ offset(arrowHeight),
+ flip({ padding: 8 }),
+ // 偏移完成后,再留 8px 空白,而不是紧贴着父容器
+ shift({ padding: 8 }),
+ arrow({
+ element: arrowRef,
+ }),
+ ],
+ });
- // 这两个是未经 useFloating 变换前的坐标
- // 也就是 arrow 悬浮,左对齐 floating,两者水平中线重合
- const arrowX = middlewareData.arrow?.x ?? 0;
- const arrowY = middlewareData.arrow?.y ?? 0;
+ // 这两个是未经 useFloating 变换前的坐标
+ // 也就是 arrow 悬浮,左对齐 floating,两者水平中线重合
+ const arrowX = middlewareData.arrow?.x ?? 0;
+ const arrowY = middlewareData.arrow?.y ?? 0;
- // 变换中心的起始坐标就是 floating 的左上角
- const transformX = arrowX + arrowWidth / 2;
- const transformY = arrowY + arrowHeight;
+ // 变换中心的起始坐标就是 floating 的左上角
+ const transformX = arrowX + arrowWidth / 2;
+ const transformY = arrowY + arrowHeight;
- // style 用于内容框,而不是 FloatingArrow
- const { isMounted, styles: transitionStyles } = useTransitionStyles(context, {
- duration: 150,
- initial: {
- opacity: 0,
- transform: "scale(0)"
- },
- close: {
- opacity: 0
- },
- common: ({ side }) => ({
- transitionTimingFunction: "ease",
- transformOrigin: {
- top: `${transformX}px calc(100% + ${arrowHeight}px)`,
- bottom: `${transformX}px ${-arrowHeight}px`,
- left: `calc(100% + ${arrowHeight}px) ${transformY}px`,
- right: `${-arrowHeight}px ${transformY}px`
- }[side]
- })
- })
+ // style 用于内容框,而不是 FloatingArrow
+ const { isMounted, styles: transitionStyles } = useTransitionStyles(context, {
+ duration: 150,
+ initial: {
+ opacity: 0,
+ transform: "scale(0)",
+ },
+ close: {
+ opacity: 0,
+ },
+ common: ({ side }) => ({
+ transitionTimingFunction: "ease",
+ transformOrigin: {
+ top: `${transformX}px calc(100% + ${arrowHeight}px)`,
+ bottom: `${transformX}px ${-arrowHeight}px`,
+ left: `calc(100% + ${arrowHeight}px) ${transformY}px`,
+ right: `${-arrowHeight}px ${transformY}px`,
+ }[side],
+ }),
+ });
- const click = useClick(context);
- const dismiss = useDismiss(context);
- const role = useRole(context);
+ const click = useClick(context);
+ const dismiss = useDismiss(context);
+ const role = useRole(context);
- const { getReferenceProps, getFloatingProps } = useInteractions([
- click,
- dismiss,
- role,
- ]);
+ const { getReferenceProps, getFloatingProps } = useInteractions([
+ click,
+ dismiss,
+ role,
+ ]);
- return useMemo(() => ({
- isOpen,
- setIsOpen,
- /* only use at {isMounted && } */
- isMounted,
- arrowRef,
- arrowHeight,
- arrowWidth,
- refs,
- floatingStyles,
- transitionStyles,
- context,
- getReferenceProps,
- getFloatingProps
- }), [isOpen, setIsOpen, isMounted, refs, arrowHeight, arrowWidth, arrowRef, floatingStyles, transitionStyles, context, getReferenceProps, getFloatingProps])
-}
\ No newline at end of file
+ return useMemo(
+ () => ({
+ isOpen,
+ setIsOpen,
+ /* only use at {isMounted && } */
+ isMounted,
+ arrowRef,
+ arrowHeight,
+ arrowWidth,
+ refs,
+ floatingStyles,
+ transitionStyles,
+ context,
+ getReferenceProps,
+ getFloatingProps,
+ }),
+ [
+ isOpen,
+ setIsOpen,
+ isMounted,
+ refs,
+ arrowHeight,
+ arrowWidth,
+ arrowRef,
+ floatingStyles,
+ transitionStyles,
+ context,
+ getReferenceProps,
+ getFloatingProps,
+ ],
+ );
+}
diff --git a/packages/ui-react/src/components/radiobox-input/radiobox-input-group.tsx b/packages/ui-react/src/components/radiobox-input/radiobox-input-group.tsx
new file mode 100644
index 0000000..5b50c8d
--- /dev/null
+++ b/packages/ui-react/src/components/radiobox-input/radiobox-input-group.tsx
@@ -0,0 +1,37 @@
+import { useEffect, useState } from "react";
+import type { CommonProps } from "../../utils/common-props";
+import { RadioboxInputGroupContext } from "./use-radiobox-input-group-context";
+
+export type RadioboxInputGroupProps = CommonProps & {
+ size?: "sm" | "md";
+ name: string;
+ defaultSelectedValue?: string;
+ onChange?: (nextSelected?: string) => void;
+ canNoneSelected?: boolean;
+};
+
+export const RadioboxInputGroup = (props: RadioboxInputGroupProps) => {
+ const {
+ size = "sm",
+ defaultSelectedValue,
+ name,
+ onChange,
+ canNoneSelected = false,
+ children,
+ } = props;
+ const [selectedValue, setSelectedValue] = useState(
+ defaultSelectedValue,
+ );
+
+ useEffect(() => {
+ onChange?.(selectedValue);
+ }, [selectedValue]);
+
+ return (
+
+ {children}
+
+ );
+};
diff --git a/packages/ui-react/src/components/radiobox-input/radiobox-input.tsx b/packages/ui-react/src/components/radiobox-input/radiobox-input.tsx
new file mode 100644
index 0000000..837cefb
--- /dev/null
+++ b/packages/ui-react/src/components/radiobox-input/radiobox-input.tsx
@@ -0,0 +1,122 @@
+import { useRef, useState, 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";
+import { Icon } from "../icon/icon";
+import { RadioboxCheckedSvg } from "../../assets/svg/radiobox-checked-svg";
+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";
+
+export type RadioboxInputProps = CommonProps & {
+ value: string;
+ size?: "sm" | "md";
+ checked?: boolean;
+ defaultChecked?: boolean;
+ onChange?: (nextChecked: boolean) => void;
+ asBoxOnly?: boolean;
+};
+
+/**
+ * Use RadioboxInput instead, this just a piece of Component.
+ *
+ * a group is define by the same name.
+ */
+export const RadioboxInput = (props: RadioboxInputProps) => {
+ const {
+ size: propSize = "sm",
+ value,
+ onChange,
+ ref,
+ className = "",
+ children,
+ asBoxOnly = false,
+ } = props;
+
+ // ======== Group Context =============================================
+
+ const {
+ size: groupSize,
+ name: groupName,
+ selectedValue,
+ setSelectedValue,
+ canNoneSelected,
+ } = useRadioboxInputGroupContext()!;
+
+ const currentSize = groupSize ?? propSize;
+ const size = asBoxOnly ? downGradeSize(currentSize, 1) : currentSize;
+ const downSize = asBoxOnly ? downGradeSize(size, 1) : size;
+
+ const inputRef = useRef(null);
+
+ const isSelected = selectedValue === value ? true : false;
+
+ // ========= Style =========================================
+
+ const rootClass = mergeClass(
+ containerRecipe(),
+ itemSizeRecipe({ size, isIconOnly: asBoxOnly === true }),
+ className,
+ );
+
+ const boxClass = mergeClass(
+ inlineSizeRecipe({
+ size: downSize,
+ shape: "circle",
+ isIconOnly: asBoxOnly === true,
+ }),
+ );
+
+ // sr-only 1个像素都没有,更不可能被鼠标点击
+ const inputClass = mergeClass(displayRecipe({ screenReaderOnly: "hide" }));
+
+ // ========== Event ===================================================
+
+ // 将 input 的 onClick 范围扩大至整个容器元素
+ function clickHandler(e: MouseEvent) {
+ e.stopPropagation();
+ // 这里点击 input
+ inputRef.current?.click();
+ }
+
+ function changeHandler(e: ChangeEvent) {
+ if (isSelected == true && canNoneSelected == true) {
+ setSelectedValue?.(undefined);
+ } else if (isSelected == true && canNoneSelected == false) {
+ // do nothing, bucause repeat selected
+ // isSelected will reset input.checked value
+ } else {
+ setSelectedValue?.(value);
+ onChange?.(e.target.checked);
+ }
+ }
+
+ // =============================================================
+
+ return (
+
+
+
+
+ {isSelected ? : }
+
+ {!asBoxOnly && children}
+
+
+ );
+};
+RadioboxInput.displayName = "RadioboxInput";
diff --git a/packages/ui-react/src/components/radiobox-input/use-radiobox-input-group-context.ts b/packages/ui-react/src/components/radiobox-input/use-radiobox-input-group-context.ts
new file mode 100644
index 0000000..bc9d57c
--- /dev/null
+++ b/packages/ui-react/src/components/radiobox-input/use-radiobox-input-group-context.ts
@@ -0,0 +1,16 @@
+import { createContext, useContext } from "react";
+
+export type RadioboxInputGroupContextValue = {
+ size?: "sm" | "md";
+ selectedValue?: string;
+ setSelectedValue?: React.Dispatch>;
+ name?: string;
+ canNoneSelected?: boolean;
+} | null;
+
+export const RadioboxInputGroupContext =
+ createContext(null);
+
+export function useRadioboxInputGroupContext() {
+ return useContext(RadioboxInputGroupContext);
+}
diff --git a/packages/ui-react/src/components/tag/tag.tsx b/packages/ui-react/src/components/tag/tag.tsx
index b98375a..a0b52da 100644
--- a/packages/ui-react/src/components/tag/tag.tsx
+++ b/packages/ui-react/src/components/tag/tag.tsx
@@ -1,11 +1,11 @@
import { Icon } from "../icon/icon";
-import { CloseSvg } from "../../assets/svg/CloseSvg";
+import { CloseSvg } from "../../assets/svg/close-svg";
import { displayRecipe } from "../../styles/recipes/display-recipe";
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/CommonProps";
+import type { CommonProps } from "../../utils/common-props";
import { useState, type ReactNode } from "react";
import { mergeClass } from "../../styles/utils/merge-class";
diff --git a/packages/ui-react/src/components/theme/theme.tsx b/packages/ui-react/src/components/theme/theme.tsx
index 2d41ab9..db019ed 100644
--- a/packages/ui-react/src/components/theme/theme.tsx
+++ b/packages/ui-react/src/components/theme/theme.tsx
@@ -1,6 +1,6 @@
import { useState } from "react";
-import type { CommonProps } from "../../utils/CommonProps";
+import type { CommonProps } from "../../utils/common-props";
import { ThemeContext } from "./use-theme-context";
import { mergeClass } from "../../styles/utils/merge-class";
diff --git a/packages/ui-react/src/index.css b/packages/ui-react/src/index.css
index a288e04..fcd2c34 100644
--- a/packages/ui-react/src/index.css
+++ b/packages/ui-react/src/index.css
@@ -16,6 +16,7 @@
@import './styles/css/position.css';
@import './styles/css/pointer-events.css';
@import './styles/css/padding.css';
+@import './styles/css/padding-long.css';
@import './styles/css/overscroll-behavior.css';
@import './styles/css/overflow.css';
@import './styles/css/outline.css';
diff --git a/packages/ui-react/src/index.ts b/packages/ui-react/src/index.ts
index 6cc0b90..c515d39 100644
--- a/packages/ui-react/src/index.ts
+++ b/packages/ui-react/src/index.ts
@@ -1,8 +1,11 @@
-export * from './utils/state-registry.ts';
+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/CommonProps.ts';
-export * from './utils/camelToKebab.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';
export * from './styles/utils/merge-class.ts';
export * from './styles/utils/create-class-recipe.ts';
export * from './styles/recipes/variant-recipe.ts';
@@ -22,7 +25,7 @@ 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/menu/use-menu-radio-item-group-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';
@@ -34,26 +37,28 @@ 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/checkbox/checkbox.tsx';
export * from './components/button/button.tsx';
export * from './components/badge/badge.tsx';
-export * from './assets/svg/VolumeMuteSvg.tsx';
-export * from './assets/svg/VolumeLowSvg.tsx';
-export * from './assets/svg/VolumeHighSvg.tsx';
-export * from './assets/svg/UserSvg.tsx';
-export * from './assets/svg/SunSvg.tsx';
-export * from './assets/svg/SpinnerSvg.tsx';
-export * from './assets/svg/SettingSvg.tsx';
-export * from './assets/svg/SearchSvg.tsx';
-export * from './assets/svg/Ruler.tsx';
-export * from './assets/svg/PasteSvg.tsx';
-export * from './assets/svg/MoonSvg.tsx';
-export * from './assets/svg/MeshSvg.tsx';
-export * from './assets/svg/KeySvg.tsx';
-export * from './assets/svg/FileSvg.tsx';
-export * from './assets/svg/DownloadSvg.tsx';
-export * from './assets/svg/CutSvg.tsx';
-export * from './assets/svg/CloseSvg.tsx';
-export * from './assets/svg/ChevronRightSvg.tsx';
-export * from './assets/svg/CheckIndicatorSvg.tsx';
-export * from './assets/svg/BoldSvg.tsx';
\ No newline at end of file
+export * from './assets/svg/volume-mute-svg.tsx';
+export * from './assets/svg/volume-low-svg.tsx';
+export * from './assets/svg/volume-high-svg.tsx';
+export * from './assets/svg/user-svg.tsx';
+export * from './assets/svg/sun-svg.tsx';
+export * from './assets/svg/spinner-svg.tsx';
+export * from './assets/svg/setting-svg.tsx';
+export * from './assets/svg/search-svg.tsx';
+export * from './assets/svg/ruler-svg.tsx';
+export * from './assets/svg/radiobox-unchecked-svg.tsx';
+export * from './assets/svg/radiobox-checked-svg.tsx';
+export * from './assets/svg/paste-svg.tsx';
+export * from './assets/svg/moon-svg.tsx';
+export * from './assets/svg/mesh-svg.tsx';
+export * from './assets/svg/key-svg.tsx';
+export * from './assets/svg/download-svg.tsx';
+export * from './assets/svg/cut-svg.tsx';
+export * from './assets/svg/close-svg.tsx';
+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';
\ No newline at end of file
diff --git a/packages/ui-react/src/styles/css/height-inline.css b/packages/ui-react/src/styles/css/height-inline.css
index 1c86bda..acda3dd 100644
--- a/packages/ui-react/src/styles/css/height-inline.css
+++ b/packages/ui-react/src/styles/css/height-inline.css
@@ -1,25 +1,57 @@
@layer utility {
.h--inline-xs {
height: calc(var(--font-size-xs) * var(--line-height));
+ & svg {
+ height: calc(var(--font-size-xs) * var(--line-height));
+ width: calc(var(--font-size-xs) * var(--line-height));
+ }
}
.h--inline-sm {
height: calc(var(--font-size-sm) * var(--line-height));
+ & svg {
+ height: calc(var(--font-size-sm) * var(--line-height));
+ width: calc(var(--font-size-sm) * var(--line-height));
+ }
}
.h--inline-md {
height: calc(var(--font-size-md) * var(--line-height));
+ & svg {
+ height: calc(var(--font-size-md) * var(--line-height));
+ width: calc(var(--font-size-md) * var(--line-height));
+ }
}
.h--inline-lg {
height: calc(var(--font-size-lg) * var(--line-height));
+ & svg {
+ height: calc(var(--font-size-lg) * var(--line-height));
+ width: calc(var(--font-size-lg) * var(--line-height));
+ }
}
.h--inline-xl {
height: calc(var(--font-size-xl) * var(--line-height));
+ & svg {
+ height: calc(var(--font-size-xl) * var(--line-height));
+ width: calc(var(--font-size-xl) * var(--line-height));
+ }
}
.h--inline-2xl {
height: calc(var(--font-size-2xl) * var(--line-height));
+ & svg {
+ height: calc(var(--font-size-2xl) * var(--line-height));
+ width: calc(var(--font-size-2xl) * var(--line-height));
+ }
}
-}
\ No newline at end of file
+
+ .h--inline-3xl {
+ height: calc(var(--font-size-3xl) * var(--line-height));
+ & svg {
+ height: calc(var(--font-size-3xl) * var(--line-height));
+ width: calc(var(--font-size-3xl) * var(--line-height));
+ }
+ }
+}
diff --git a/packages/ui-react/src/styles/css/height-item.css b/packages/ui-react/src/styles/css/height-item.css
index d607285..084d88b 100644
--- a/packages/ui-react/src/styles/css/height-item.css
+++ b/packages/ui-react/src/styles/css/height-item.css
@@ -1,23 +1,51 @@
@layer utility {
.h--item-xs {
height: var(--height-item-xs);
+ & svg {
+ height: calc(var(--font-size-xs) * var(--line-height));
+ width: calc(var(--font-size-xs) * var(--line-height));
+ }
}
.h--item-sm {
height: var(--height-item-sm);
+ & svg {
+ height: calc(var(--font-size-sm) * var(--line-height));
+ width: calc(var(--font-size-sm) * var(--line-height));
+ }
}
.h--item-md {
height: var(--height-item-md);
+ & svg {
+ height: calc(var(--font-size-md) * var(--line-height));
+ width: calc(var(--font-size-md) * var(--line-height));
+ }
}
.h--item-lg {
height: var(--height-item-lg);
+ & svg {
+ height: calc(var(--font-size-lg) * var(--line-height));
+ width: calc(var(--font-size-lg) * var(--line-height));
+ }
}
.h--item-xl {
height: var(--height-item-xl);
+ & svg {
+ height: calc(var(--font-size-xl) * var(--line-height));
+ width: calc(var(--font-size-xl) * var(--line-height));
+ }
}
.h--item-2xl {
height: var(--height-item-2xl);
+ & svg {
+ height: calc(var(--font-size-2xl) * var(--line-height));
+ width: calc(var(--font-size-2xl) * var(--line-height));
+ }
}
.h--item-3xl {
height: var(--height-item-3xl);
+ & svg {
+ height: calc(var(--font-size-3xl) * var(--line-height));
+ width: calc(var(--font-size-3xl) * var(--line-height));
+ }
}
}
diff --git a/packages/ui-react/src/styles/css/opacity.css b/packages/ui-react/src/styles/css/opacity.css
new file mode 100644
index 0000000..907ac45
--- /dev/null
+++ b/packages/ui-react/src/styles/css/opacity.css
@@ -0,0 +1,9 @@
+@layer utility {
+ .opacity--0 {
+ opacity: 0;
+ }
+
+ .opacity--1 {
+ opacity: 1;
+ }
+}
diff --git a/packages/ui-react/src/styles/css/outline.css b/packages/ui-react/src/styles/css/outline.css
index e1ecf79..0acaf5a 100644
--- a/packages/ui-react/src/styles/css/outline.css
+++ b/packages/ui-react/src/styles/css/outline.css
@@ -1,16 +1,22 @@
@layer utility {
- .outline--none {
- outline: none;
+ /* 要注意,这不是不可焦距,只是不显示 outline 而已,但仍可能显示 hover */
+ .outline--none {
+ outline: none;
+ }
+ /* 仅启用键盘焦距,显示 outline,但仍可能显示其他的,例如,hover */
+ .outline {
+ /* 先移除所有显示 */
+ &:focus {
+ outline: none;
}
-
- .outline {
- &:focus-visible {
- outline: 3px solid var(--base-focus-outline-color);
- outline-offset: 1px;
- }
-
- &:focus:not(:focus-visible) {
- outline: none;
- }
+ /* 键盘点击,显示 */
+ &:focus-visible {
+ outline: 3px solid var(--base-focus-outline-color);
+ outline-offset: 1px;
}
-}
\ No newline at end of file
+ /* 鼠标点击后,不显示 */
+ &:focus:not(:focus-visible) {
+ outline: none;
+ }
+ }
+}
diff --git a/packages/ui-react/src/styles/css/padding-long.css b/packages/ui-react/src/styles/css/padding-long.css
new file mode 100644
index 0000000..ce1376f
--- /dev/null
+++ b/packages/ui-react/src/styles/css/padding-long.css
@@ -0,0 +1,23 @@
+@layer utility {
+ .px--long-xs {
+ padding-inline: var(--padding-long-xs);
+ }
+ .px--long-sm {
+ padding-inline: var(--padding-long-sm);
+ }
+ .px--long-md {
+ padding-inline: var(--padding-long-md);
+ }
+ .px--long-lg {
+ padding-inline: var(--padding-long-lg);
+ }
+ .px--long-xl {
+ padding-inline: var(--padding-long-xl);
+ }
+ .px--long-2xl {
+ padding-inline: var(--padding-long-2xl);
+ }
+ .px--long-3xl {
+ padding-inline: var(--padding-long-3xl);
+ }
+}
diff --git a/packages/ui-react/src/styles/css/theme-base.css b/packages/ui-react/src/styles/css/theme-base.css
index 857383c..87dde41 100644
--- a/packages/ui-react/src/styles/css/theme-base.css
+++ b/packages/ui-react/src/styles/css/theme-base.css
@@ -333,7 +333,7 @@
--font-size-xs: 12px;
--font-size-sm: 13px;
--font-size-md: 14px;
- --font-size-lg: 16px;
+ --font-size-lg: 15px;
--font-size-xl: 16px;
--font-size-2xl: 24px;
--font-size-3xl: 30px;
@@ -374,13 +374,23 @@
--radius-full: 9999px;
--padding-xs: 4px;
- --padding-sm: 6px;
- --padding-md: 8px;
- --padding-lg: 10px;
+ --padding-sm: 5px;
+ --padding-md: 6px;
+ --padding-lg: 7px;
--padding-xl: 16px;
--padding-2xl: 2px;
--padding-3xl: 2px;
+ --times-of-padding-long: 2;
+
+ --padding-long-xs: calc(var(--padding-xs) * var(--times-of-padding-long));
+ --padding-long-sm: calc(var(--padding-sm) * var(--times-of-padding-long));
+ --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));
+
--gap-xs: 2px;
--gap-sm: 3px;
--gap-md: 4px;
diff --git a/packages/ui-react/src/styles/recipes/container-recipe.ts b/packages/ui-react/src/styles/recipes/container-recipe.ts
index 842f57a..9771f25 100644
--- a/packages/ui-react/src/styles/recipes/container-recipe.ts
+++ b/packages/ui-react/src/styles/recipes/container-recipe.ts
@@ -17,7 +17,7 @@ export const containerRecipe = createClassRecipe({
},
padding: {
4: "px--4 py--4",
- 8: "px--8 py--8",
+ 8: "px--8 py--8",
12: "px--12 py--12",
16: "px--16 py--16",
},
diff --git a/packages/ui-react/src/styles/recipes/display-recipe.ts b/packages/ui-react/src/styles/recipes/display-recipe.ts
index 82a7781..38e9349 100644
--- a/packages/ui-react/src/styles/recipes/display-recipe.ts
+++ b/packages/ui-react/src/styles/recipes/display-recipe.ts
@@ -61,5 +61,9 @@ export const displayRecipe = createClassRecipe({
grab: "cursor--grab",
grabbing: "cursor--grabbing",
},
+ opacity: {
+ 0: "opacity--0",
+ 1: "opacity--1",
+ },
},
});
diff --git a/packages/ui-react/src/styles/recipes/item-size-recipe.ts b/packages/ui-react/src/styles/recipes/item-size-recipe.ts
index 02af392..14376f8 100644
--- a/packages/ui-react/src/styles/recipes/item-size-recipe.ts
+++ b/packages/ui-react/src/styles/recipes/item-size-recipe.ts
@@ -27,6 +27,13 @@ export const itemSizeRecipe = createClassRecipe({
},
},
compoundVariants: [
+ { isLongPadding: true, size: "xs", class: "px--long-xs" },
+ { isLongPadding: true, size: "sm", class: "px--long-sm" },
+ { isLongPadding: true, size: "md", class: "px--long-md" },
+ { isLongPadding: true, size: "lg", class: "px--long-lg" },
+ { isLongPadding: true, size: "xl", class: "px--long-xl" },
+ { isLongPadding: true, size: "2xl", class: "px--long-2xl" },
+ { isLongPadding: true, size: "3xl", class: "px--long-3xl" },
{ shape: "rounded", size: "xs", class: "rounded--xs" },
{ shape: "rounded", size: "sm", class: "rounded--sm" },
{ shape: "rounded", size: "md", class: "rounded--md" },
@@ -34,7 +41,6 @@ export const itemSizeRecipe = createClassRecipe({
{ shape: "rounded", size: "xl", class: "rounded--xl" },
{ shape: "rounded", size: "2xl", class: "rounded--2xl" },
{ shape: "rounded", size: "3xl", class: "rounded--3xl" },
- // ==================================================
{ isIconOnly: true, size: "xs", class: "w--item-xs px--none" },
{ isIconOnly: true, size: "sm", class: "w--item-sm px--none" },
{ isIconOnly: true, size: "md", class: "w--item-md px--none" },
diff --git a/packages/ui-react/src/utils/camelToKebab.ts b/packages/ui-react/src/utils/camel-to-kebab.ts
similarity index 100%
rename from packages/ui-react/src/utils/camelToKebab.ts
rename to packages/ui-react/src/utils/camel-to-kebab.ts
diff --git a/packages/ui-react/src/utils/CommonProps.ts b/packages/ui-react/src/utils/common-props.ts
similarity index 100%
rename from packages/ui-react/src/utils/CommonProps.ts
rename to packages/ui-react/src/utils/common-props.ts
diff --git a/packages/ui-react/src/utils/down-grade-size.ts b/packages/ui-react/src/utils/down-grade-size.ts
new file mode 100644
index 0000000..299462f
--- /dev/null
+++ b/packages/ui-react/src/utils/down-grade-size.ts
@@ -0,0 +1,27 @@
+type SizeType = ["xs", "sm", "md", "lg", "xl", "2xl", "3xl"];
+
+/**
+ *
+ * @returns
+ * Return available value or undefind
+ */
+export function downGradeSize(
+ size: "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | undefined,
+ downGrade: number = 1,
+): "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | undefined {
+ if (size == undefined) {
+ return undefined;
+ }
+
+ const sizeArray: SizeType = ["xs", "sm", "md", "lg", "xl", "2xl", "3xl"];
+
+ const index = sizeArray.findIndex((v) => v == size);
+
+ const downIndex = index - downGrade;
+
+ if (downIndex < 0) {
+ return undefined;
+ }
+
+ return sizeArray[downIndex];
+}
diff --git a/packages/ui-react/src/utils/state-registry.ts b/packages/ui-react/src/utils/state-registry.ts
deleted file mode 100644
index 0348683..0000000
--- a/packages/ui-react/src/utils/state-registry.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-export class StateRegistry {
- constructor(excuteCallback: (registry: Map) => boolean) {
- this._excuteCallback = excuteCallback;
- }
-
- _excuteCallback: (registry: Map) => boolean;
-
- _registryMap = new Map();
-
- insertKey = (key: string) => {
- this._registryMap.set(key, null);
- };
-
- updateValue = (key: string, value: V) => {
- this._registryMap.set(key, value);
- };
-
- deleteEntry = (key: string) => {
- this._registryMap.delete(key);
- };
-
- execute = () => {
- return this._excuteCallback(this._registryMap);
- };
-
- checkAllReady = () => {
- for (const i of this._registryMap.values()) {
- i == null;
- return false;
- }
- return true;
- };
-}
diff --git a/packages/ui-react/src/utils/use-state-registry.ts b/packages/ui-react/src/utils/use-state-registry.ts
new file mode 100644
index 0000000..9fddfe0
--- /dev/null
+++ b/packages/ui-react/src/utils/use-state-registry.ts
@@ -0,0 +1,55 @@
+import { useState } from "react";
+
+export function useStateRegistry(
+ resultCallback?: (registry: Map) => V,
+) {
+ const [registry, setRegistry] = useState