This commit is contained in:
2026-12-02 09:30:54 +08:00
parent 215d6d1253
commit fc2dc46f43
76 changed files with 1235 additions and 870 deletions
@@ -94,6 +94,36 @@
如果一个国家,不想背债,那就要上门槛,不让外资轻易进入搞价格战,不能把价格搞得非常之低。
## 统治者,银行家的剥削手段
通货膨胀,稀释普通人财富。
通货膨胀并不直接等于经济泡沫,泡沫是分领域的,只有供不应求的领域才有泡沫,例如,房地产,芯片。
想要规避通货膨胀,就要把所有的钱,以保值的形式储蓄,只保留必要的现金流。
如果需要大量的现金流,那就贷款,把通胀的损失转嫁给银行。
如果银行也随通胀而提高利率,那就要懂得非法融资,以会员制,充值,押金等方式,变相获得低息贷款。
产能过剩,十分有利于控制着稀缺土地的统治者利益,各种,水电,油,电信,房价,只要价格不降反升,就能实现收割。
产能过剩,还能节约给公务员发的年薪,理由就用经济不好,反正物价便宜,对公务员生活影响不是很大。
普通人,之要还在使用法币,还在支付电信和房租,就注定是被剥削的对象。
## 统治者只需提高生存成本,即使不打价格战,仍可以变相打压所有行业
房租,电信,水电,这几个是拉高人工成本的关键,收入不变,刚需费用上升,人群购买力降低,利润降低,引发变相价格战。
## 线下倒卖,和线上倒卖
如果你是一个旅行者,每到一个城市,都需要把
+4
View File
@@ -122,3 +122,7 @@ index.js,作为入口文件名,不同语法的,会插入第二扩展名,
但如如果是给 ts 搞,那就固定为 index.d.ts 。
## useState的局限性,每次发信号都强制渲染,造成很多不必要的渲染
## 状态提升,加上复杂状态结构,能解决嵌套通讯的任何问题
+2
View File
@@ -0,0 +1,2 @@
registry=https://registry.npmmirror.com
node-linker=hoisted
+4
View File
@@ -3,14 +3,18 @@ import { ButtonGallery } from "./gallery/button-gallery";
import { MenuGallery } from "./gallery/menu-gallery";
import { PopoverGallery } from "./gallery/popover-gallery";
import "../src/index.css";
import { BadgeGallery } from "./gallery/badge-gallery";
import { TagGallery } from "./gallery/tag-gallery";
function App() {
return (
<div className="app">
<Theme>
<TagGallery />
<ButtonGallery />
<PopoverGallery />
<MenuGallery />
<BadgeGallery />
</Theme>
</div>
);
+1 -1
View File
@@ -4,7 +4,7 @@ export const IW = ({ children }: { children: ReactNode }) => {
return (
<div
style={{
gap: "10px",
gap: "20px",
display: "flex",
flexWrap: "nowrap",
}}
@@ -0,0 +1,45 @@
import { Badge } from "../../src/components/badge/badge";
import { Button } from "../../src/components/button/button";
import { IW } from "../common/iw";
import { OW } from "../common/ow";
export const BadgeGallery = () => {
return (
<OW>
<IW>
<Badge isDot={true}>
<Button isIconOnly={true}>PU</Button>
</Badge>
<Badge indicatorContent="996">
<Button isIconOnly={true}>Cotton</Button>
</Badge>
<Badge indicatorContent="96">
<Button isIconOnly={true}>Cotton</Button>
</Badge>
<Badge indicatorContent="9">
<Button isIconOnly={true}>Cotton</Button>
</Badge>
<Badge isDot={true}>
<Button isIconOnly={true} size="lg">
PU
</Button>
</Badge>
<Badge indicatorContent="996">
<Button isIconOnly={true} size="lg">
Cotton
</Button>
</Badge>
<Badge indicatorContent="96">
<Button isIconOnly={true} size="lg">
Cotton
</Button>
</Badge>
<Badge indicatorContent="9">
<Button isIconOnly={true} size="lg">
Cotton
</Button>
</Badge>
</IW>
</OW>
);
};
@@ -14,7 +14,7 @@ export const MenuGallery = () => {
return (
<OW>
<IW>
<Menu>
<Menu size="sm">
<MenuTrigger>
<Button size="sm" variant="ghost">
文件
@@ -35,6 +35,11 @@ export const MenuGallery = () => {
<MenuCheckItem name={"auto-link"} value={"auto-link"}>
Auto Lint
</MenuCheckItem>
<MenuRadioItemGroup defaultSelectedValue="hori" name="direction">
<MenuRadioItem value="hori">Hori</MenuRadioItem>
<MenuRadioItem value="verti">Verti</MenuRadioItem>
<MenuRadioItem value="both">Hoth</MenuRadioItem>
</MenuRadioItemGroup>
<Menu>
<MenuTrigger>
<MenuItem>Ruler</MenuItem>
@@ -63,19 +68,19 @@ export const MenuGallery = () => {
</MenuTrigger>
<MenuDropdown>
<MenuItem iconSvg={<KeySvg />}>Open File...</MenuItem>
<MenuItem>Open Folder...</MenuItem>
<MenuItem iconSvg={<KeySvg />}>Open Folder...</MenuItem>
{/* 子菜单 */}
<Menu>
<MenuTrigger>
<MenuItem>Preferences</MenuItem>
<MenuItem iconSvg={<KeySvg />}>Preferences</MenuItem>
</MenuTrigger>
<MenuDropdown>
<MenuItem>Profile</MenuItem>
<MenuItem>Settings</MenuItem>
<MenuItem iconSvg={<KeySvg />}>Profile</MenuItem>
<MenuItem iconSvg={<KeySvg />}>Settings</MenuItem>
{/* 子菜单 */}
<Menu>
<MenuTrigger>
<MenuItem>To open 3</MenuItem>
<MenuItem iconSvg={<KeySvg />}>To open 3</MenuItem>
</MenuTrigger>
<MenuDropdown>
<MenuItem>Profile</MenuItem>
@@ -84,12 +89,16 @@ export const MenuGallery = () => {
</Menu>
</MenuDropdown>
</Menu>
<MenuCheckItem name={"auto-link"} value={"auto-link"}>
<MenuCheckItem
name={"auto-link"}
value={"auto-link"}
iconSvg={<KeySvg />}
>
Auto Lint
</MenuCheckItem>
<Menu>
<MenuTrigger>
<MenuItem>Ruler</MenuItem>
<MenuItem iconSvg={<KeySvg />}>Ruler</MenuItem>
</MenuTrigger>
<MenuDropdown>
<MenuRadioItemGroup
@@ -0,0 +1,32 @@
import { CheckmarkCircleSvg, StarFilledSvg } from "../../src";
import { ExclamationCircleSvg } from "../../src/assets/svg/exclamation-circle-svg";
import { Tag } from "../../src/components/tag/tag";
import { IW } from "../common/iw";
import { OW } from "../common/ow";
export const TagGallery = () => {
return (
<OW>
<IW>
<Tag>PU</Tag>
<Tag isClosable={true}>PU</Tag>
<Tag leftIconSvg={<StarFilledSvg />} isClosable={true}>
PU
</Tag>
<Tag
leftIconSvg={<StarFilledSvg />}
rightIconSvg={<CheckmarkCircleSvg />}
isClosable={true}
>
PU
</Tag>
<Tag
leftIconSvg={<StarFilledSvg />}
rightIconSvg={<ExclamationCircleSvg />}
>
PU
</Tag>
</IW>
</OW>
);
};
+1 -1
View File
@@ -14,7 +14,7 @@
"doc"
],
"scripts": {
"dev": "vite",
"dev": "vite --force",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
@@ -1,5 +1,5 @@
export const BoldSvg = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
export const BoldSvg = (props: any) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
<path
fill="none"
stroke="currentColor"
@@ -1,5 +1,5 @@
export const CheckIndicatorSvg = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
export const CheckIndicatorSvg = (props: any) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
<path
fill="currentColor"
d="M9 16.17L4.83 12l-1.42 1.41L9 19L21 7l-1.41-1.41z"
@@ -1,5 +1,5 @@
export const CheckboxCheckedSvg = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
export const CheckboxCheckedSvg = (props: any) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" {...props}>
<path d="M0 0h32v32H0z" fill="none" />
<path
fill="currentColor"
@@ -1,5 +1,5 @@
export const CheckboxUncheckedSvg = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
export const CheckboxUncheckedSvg = (props: any) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" {...props}>
<path d="M0 0h32v32H0z" fill="none" />
<path
fill="currentColor"
@@ -0,0 +1,11 @@
export const CheckmarkCircleSvg = (props: any) => {
return (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 12" {...props}>
<path d="M0 0h12v12H0z" fill="none" />
<path
fill="currentColor"
d="M8.354 5.104a.5.5 0 1 0-.708-.708L5.5 6.543L4.354 5.396a.5.5 0 1 0-.708.708l1.5 1.5a.5.5 0 0 0 .708 0zM6 1a5 5 0 1 0 0 10A5 5 0 0 0 6 1M2 6a4 4 0 1 1 8 0a4 4 0 0 1-8 0"
/>
</svg>
);
};
@@ -1,5 +1,5 @@
export const ChevronRightSvg = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
export const ChevronRightSvg = (props: any) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
<path
fill="none"
stroke="currentColor"
@@ -1,5 +1,5 @@
export const CloseSvg = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
export const CloseSvg = (props: any) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
<path
fill="none"
stroke="currentColor"
+2 -2
View File
@@ -1,5 +1,5 @@
export const CutSvg = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
export const CutSvg = (props: any) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
<path
fill="currentColor"
d="M12.14 9.342L7.37 2.329a.75.75 0 1 0-1.24.844l5.13 7.545l-2.395 3.743a4 4 0 1 0 1.178.943l2.135-3.337l2.065 3.036a4 4 0 1 0 1.261-.813l-2.447-3.597l.002-.002zM4.5 18a2.5 2.5 0 1 1 5 0a2.5 2.5 0 0 1-5 0m10 0a2.5 2.5 0 1 1 5 0a2.5 2.5 0 0 1-5 0m-.562-8.684l3.943-6.162a.75.75 0 1 0-1.263-.808L13.02 7.968z"
@@ -1,6 +1,13 @@
export const DownloadSvg = () => (
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 24 24">
<path fill="currentColor" d="M20,15.5c.55,0,1,.45,1,1v2c0,1.66-1.34,3-3,3H6c-1.66,0-3-1.34-3-3v-2c0-.55.45-1,1-1s1,.45,1,1v2c0,.55.45,1,1,1h12c.55,0,1-.45,1-1v-2c0-.55.45-1,1-1M12,2.5c.55,0,1,.45,1,1v9.59l3.29-3.29c.4-.38,1.03-.37,1.41.02.37.39.37,1,0,1.39l-5,5s-.06.06-.09.08l.09-.08c-.18.18-.42.28-.67.29h-.03s-.03,0-.03,0h-.05s.09,0,.09,0c-.22,0-.44-.07-.62-.21-.03-.02-.06-.05-.09-.08l-5-5c-.38-.4-.37-1.03.02-1.41.39-.37,1-.37,1.39,0l3.29,3.29V3.5c0-.55.45-1,1-1" />
export const DownloadSvg = (props: any) => (
<svg
xmlns="http://www.w3.org/2000/svg"
version="1.1"
viewBox="0 0 24 24"
{...props}
>
<path
fill="currentColor"
d="M20,15.5c.55,0,1,.45,1,1v2c0,1.66-1.34,3-3,3H6c-1.66,0-3-1.34-3-3v-2c0-.55.45-1,1-1s1,.45,1,1v2c0,.55.45,1,1,1h12c.55,0,1-.45,1-1v-2c0-.55.45-1,1-1M12,2.5c.55,0,1,.45,1,1v9.59l3.29-3.29c.4-.38,1.03-.37,1.41.02.37.39.37,1,0,1.39l-5,5s-.06.06-.09.08l.09-.08c-.18.18-.42.28-.67.29h-.03s-.03,0-.03,0h-.05s.09,0,.09,0c-.22,0-.44-.07-.62-.21-.03-.02-.06-.05-.09-.08l-5-5c-.38-.4-.37-1.03.02-1.41.39-.37,1-.37,1.39,0l3.29,3.29V3.5c0-.55.45-1,1-1"
/>
</svg>
);
@@ -0,0 +1,11 @@
export const ExclamationCircleSvg = (props: any) => {
return (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" {...props}>
<path d="M0 0h16v16H0z" fill="none" />
<g fill="currentColor">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16" />
<path d="M7.002 11a1 1 0 1 1 2 0a1 1 0 0 1-2 0M7.1 4.995a.905.905 0 1 1 1.8 0l-.35 3.507a.552.552 0 0 1-1.1 0z" />
</g>
</svg>
);
};
+7 -6
View File
@@ -1,8 +1,9 @@
export const KeySvg = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
fill="currentColor"
d="M7 14q-.825 0-1.412-.587T5 12t.588-1.412T7 10t1.413.588T9 12t-.587 1.413T7 14m0 4q-2.5 0-4.25-1.75T1 12t1.75-4.25T7 6q1.675 0 3.038.825T12.2 9h8.375q.2 0 .388.075t.337.225l2 2q.15.15.212.325t.063.375t-.063.375t-.212.325l-3.175 3.175q-.125.125-.3.2t-.35.1t-.35-.025t-.325-.175L17.5 15l-1.425 1.075q-.125.1-.275.15t-.3.05t-.313-.05t-.287-.15L13.375 15H12.2q-.8 1.35-2.163 2.175T7 18m0-2q1.4 0 2.463-.85T10.875 13H14l1.45 1.025v.013v-.013L17.5 12.5l1.775 1.375L21.15 12h-.012h.012l-1-1v-.012V11h-9.275q-.35-1.3-1.412-2.15T7 8Q5.35 8 4.175 9.175T3 12t1.175 2.825T7 16"
/>
export const KeySvg = (props: any) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" {...props}>
<path d="M0 0h16v16H0z" fill="none" />
<g fill="currentColor">
<path d="M0 8a4 4 0 0 1 7.465-2H14a.5.5 0 0 1 .354.146l1.5 1.5a.5.5 0 0 1 0 .708l-1.5 1.5a.5.5 0 0 1-.708 0L13 9.207l-.646.647a.5.5 0 0 1-.708 0L11 9.207l-.646.647a.5.5 0 0 1-.708 0L9 9.207l-.646.647A.5.5 0 0 1 8 10h-.535A4 4 0 0 1 0 8m4-3a3 3 0 1 0 2.712 4.285A.5.5 0 0 1 7.163 9h.63l.853-.854a.5.5 0 0 1 .708 0l.646.647l.646-.647a.5.5 0 0 1 .708 0l.646.647l.646-.647a.5.5 0 0 1 .708 0l.646.647l.793-.793l-1-1h-6.63a.5.5 0 0 1-.451-.285A3 3 0 0 0 4 5" />
<path d="M4 8a1 1 0 1 1-2 0a1 1 0 0 1 2 0" />
</g>
</svg>
);
@@ -1,5 +1,5 @@
export const MeshSvg = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
export const MeshSvg = (props: any) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
<g
fill="none"
stroke="currentColor"
@@ -1,5 +1,5 @@
export const MoonSvg = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
export const MoonSvg = (props: any) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
<path
fill="none"
stroke="currentColor"
@@ -1,5 +1,5 @@
export const PasteSvg = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
export const PasteSvg = (props: any) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
<path
fill="currentColor"
d="M12.753 2c1.158 0 2.111.875 2.234 2h1.763a2.25 2.25 0 0 1 2.245 2.096L19 6.25a.75.75 0 0 1-.647.742L18.249 7a.75.75 0 0 1-.742-.647L17.5 6.25a.75.75 0 0 0-.648-.743L16.75 5.5h-2.132a2.24 2.24 0 0 1-1.865.993H9.247a2.24 2.24 0 0 1-1.865-.992L5.25 5.5a.75.75 0 0 0-.743.648L4.5 6.25v13.505c0 .38.282.693.648.743l.102.007h3a.75.75 0 0 1 .743.647l.007.102a.75.75 0 0 1-.75.75h-3a2.25 2.25 0 0 1-2.245-2.095L3 19.755V6.25a2.25 2.25 0 0 1 2.096-2.245L5.25 4h1.763a2.247 2.247 0 0 1 2.234-2zm5.997 6a2.25 2.25 0 0 1 2.245 2.096l.005.154v9.5a2.25 2.25 0 0 1-2.096 2.245L18.75 22h-6.5a2.25 2.25 0 0 1-2.245-2.096L10 19.75v-9.5a2.25 2.25 0 0 1 2.096-2.245L12.25 8zm0 1.5h-6.5a.75.75 0 0 0-.743.648l-.007.102v9.5c0 .38.282.694.648.743l.102.007h6.5a.75.75 0 0 0 .743-.648l.007-.102v-9.5a.75.75 0 0 0-.648-.743zm-5.997-6H9.247a.747.747 0 0 0 0 1.493h3.506a.747.747 0 1 0 0-1.493"
@@ -1,5 +1,5 @@
export const RadioboxCheckedSvg = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
export const RadioboxCheckedSvg = (props: any) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" {...props}>
<path
fill="currentColor"
d="M16 2a14 14 0 1 0 14 14A14 14 0 0 0 16 2m0 26a12 12 0 1 1 12-12a12 12 0 0 1-12 12"
@@ -1,5 +1,5 @@
export const RadioboxUncheckedSvg = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
export const RadioboxUncheckedSvg = (props: any) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" {...props}>
<path
fill="currentColor"
d="M16 2a14 14 0 1 0 14 14A14 14 0 0 0 16 2m0 26a12 12 0 1 1 12-12a12 12 0 0 1-12 12"
@@ -1,5 +1,5 @@
export const RulerSvg = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
export const RulerSvg = (props: any) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
<path
fill="none"
stroke="currentColor"
@@ -1,5 +1,5 @@
export const SearchSvg = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
export const SearchSvg = (props: any) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
<path
fill="currentColor"
d="M9.5 16q-2.725 0-4.612-1.888T3 9.5t1.888-4.612T9.5 3t4.613 1.888T16 9.5q0 1.1-.35 2.075T14.7 13.3l5.6 5.6q.275.275.275.7t-.275.7t-.7.275t-.7-.275l-5.6-5.6q-.75.6-1.725.95T9.5 16m0-2q1.875 0 3.188-1.312T14 9.5t-1.312-3.187T9.5 5T6.313 6.313T5 9.5t1.313 3.188T9.5 14"
@@ -1,5 +1,5 @@
export const SettingSvg = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
export const SettingSvg = (props: any) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
<path
fill="currentColor"
fillRule="evenodd"
@@ -1,6 +1,6 @@
export const SpinnerSvg = () => {
export const SpinnerSvg = (props: any) => {
return (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
<path
fill="currentColor"
d="M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"
@@ -0,0 +1,11 @@
export const StarFilledSvg = (props: any) => {
return (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" {...props}>
<path d="M0 0h16v16H0z" fill="none" />
<path
fill="currentColor"
d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327l4.898.696c.441.062.612.636.282.95l-3.522 3.356l.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z"
/>
</svg>
);
};
@@ -0,0 +1,11 @@
export const StarOutlineSvg = (props: any) => {
return (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" {...props}>
<path d="M0 0h16v16H0z" fill="none" />
<path
fill="currentColor"
d="M2.866 14.85c-.078.444.36.791.746.593l4.39-2.256l4.389 2.256c.386.198.824-.149.746-.592l-.83-4.73l3.522-3.356c.33-.314.16-.888-.282-.95l-4.898-.696L8.465.792a.513.513 0 0 0-.927 0L5.354 5.12l-4.898.696c-.441.062-.612.636-.283.95l3.523 3.356l-.83 4.73zm4.905-2.767l-3.686 1.894l.694-3.957a.56.56 0 0 0-.163-.505L1.71 6.745l4.052-.576a.53.53 0 0 0 .393-.288L8 2.223l1.847 3.658a.53.53 0 0 0 .393.288l4.052.575l-2.906 2.77a.56.56 0 0 0-.163.506l.694 3.957l-3.686-1.894a.5.5 0 0 0-.461 0z"
/>
</svg>
);
};
+2 -2
View File
@@ -1,5 +1,5 @@
export const SunSvg = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
export const SunSvg = (props: any) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
<path
fill="none"
stroke="currentColor"
@@ -1,6 +1,6 @@
export const UserSvg = () => {
export const UserSvg = (props: any) => {
return (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
<path
fill="none"
stroke="currentColor"
@@ -1,5 +1,5 @@
export const VolumeHighSvg = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
export const VolumeHighSvg = (props: any) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
<path
fill="none"
stroke="currentColor"
@@ -1,5 +1,5 @@
export const VolumeLowSvg = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" >
export const VolumeLowSvg = (props: any) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
<path
fill="none"
stroke="currentColor"
@@ -1,5 +1,5 @@
export const VolumeMuteSvg = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" >
export const VolumeMuteSvg = (props: any) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
<path
fill="none"
stroke="currentColor"
@@ -1,27 +1,18 @@
import { type CSSProperties } from "react";
import { displayRecipe } from "../../styles/recipes/display-recipe";
import { dotSizeRecipe } from "../../styles/recipes/dot-size-recipe";
import { brandRecipe } from "../../styles/recipes/brand-recipe";
import { mergeClass } from "../../styles/utils/merge-class";
import type { CommonProps } from "../../utils/common-props";
import { variantRecipe } from "../../styles/recipes/variant-recipe";
import { inlineSizeRecipe } from "../../styles/recipes/inline-size-recipe";
export type BadgeProps = CommonProps & {
size?: "xs" | "sm" | "md" | "lg";
} & {
export type BadgeProps = CommonProps & {} & {
isDot?: boolean;
indicatorContent?: string;
};
export const Badge = (props: BadgeProps) => {
const {
indicatorContent = "",
isDot = false,
size = "md",
children,
className = "",
ref,
...rest
} = props;
const { indicatorContent, isDot = false, children, ref, ...rest } = props;
const wrapperStyle: CSSProperties = {
position: "relative",
@@ -39,10 +30,17 @@ export const Badge = (props: BadgeProps) => {
const indicatorClass = mergeClass(
displayRecipe(),
dotSizeRecipe({ size }),
isDot
? "h--6 w--6"
: inlineSizeRecipe({
size: "xs",
shape: "circle",
hasMinWidth: true,
hasPadding: true,
}),
variantRecipe({ isUnclickable: true, variant: "filled" }),
brandRecipe({ brand: "danger" }),
"pointer-events--none",
className,
);
return (
@@ -9,6 +9,7 @@ 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";
import { displayRecipe } from "../../styles/recipes/display-recipe";
export type CheckboxInputProps = CommonProps & {
size?: "sm" | "md";
@@ -27,7 +28,7 @@ export type CheckboxInputProps = CommonProps & {
*/
export const CheckboxInput = (props: CheckboxInputProps) => {
const {
size: propSize = "sm",
size = "md",
name,
value,
checked: controlledChecked,
@@ -39,7 +40,7 @@ export const CheckboxInput = (props: CheckboxInputProps) => {
asBoxOnly = false,
} = props;
const size = asBoxOnly ? downGradeSize(propSize, 1) : propSize;
// const size = asBoxOnly ? downGradeSize(propSize, 1) : propSize;
const downSize = asBoxOnly ? downGradeSize(size, 1) : size;
const [checked, setChecked] = useState<boolean>(
@@ -48,12 +49,20 @@ export const CheckboxInput = (props: CheckboxInputProps) => {
const inputRef = useRef<HTMLInputElement>(null);
// =======================================================
const rootClass = mergeClass(
containerRecipe(),
itemSizeRecipe({
size,
isIconOnly: asBoxOnly === true,
}),
displayRecipe(),
containerRecipe({ hasFocusOutline: "false" }),
asBoxOnly === true
? inlineSizeRecipe({
size,
isIconOnly: true,
})
: itemSizeRecipe({
size,
isIconOnly: true,
}),
className,
);
@@ -84,6 +93,8 @@ export const CheckboxInput = (props: CheckboxInputProps) => {
onChange?.(e.target.checked);
}
// =======================================================
return (
<div className={rootClass} onClick={clickHandler}>
<div className={boxClass}>
@@ -98,9 +109,15 @@ export const CheckboxInput = (props: CheckboxInputProps) => {
onChange={changeHandler}
className={inputClass}
/>
<Icon size={downSize}>
{checked ? <CheckboxCheckedSvg /> : <CheckboxUncheckedSvg />}
</Icon>
{checked ? (
<Icon size={downSize}>
<CheckboxCheckedSvg />
</Icon>
) : (
<Icon size={downSize}>
<CheckboxUncheckedSvg />
</Icon>
)}
{!asBoxOnly && children}
</div>
</div>
@@ -4,7 +4,7 @@ import { inlineSizeRecipe } from "../../styles/recipes/inline-size-recipe";
import { mergeClass } from "../../styles/utils/merge-class";
export type IconProps = CommonProps & {
size?: "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl";
size?: "xs" | "sm" | "md" | "lg" | "xl" | "xxl" | "xxxl";
shape?: "square" | "circle" | "rounded";
} & {
onClick?: (e?: React.MouseEvent) => void;
@@ -1,9 +1,8 @@
import { useMenuFloatingContext } from "./use-menu-floating-context";
import { useListItem, useMergeRefs } from "@floating-ui/react";
import { useMenuContext } from "./use-menu-context";
import React, {
useEffect,
useId,
useLayoutEffect,
useRef,
useState,
type CSSProperties,
@@ -18,9 +17,10 @@ import { variantRecipe } from "../../styles/recipes/variant-recipe";
import type { CommonProps } from "../../utils/common-props";
import { containerRecipe } from "../../styles/recipes/container-recipe";
import { inlineSizeRecipe } from "../../styles/recipes/inline-size-recipe";
import { useMenuContext } from "./use-menu-context";
import { useMenuDropdownContext } from "./use-menu-dropdown-context";
export type MenuCheckItemProps = CommonProps & {
size?: "sm" | "md";
name: string;
value: string;
checked?: boolean;
@@ -33,7 +33,6 @@ export type MenuCheckItemProps = CommonProps & {
export const MenuCheckItem = (props: MenuCheckItemProps) => {
const {
size: propSize = "sm",
checked: controlledChecked,
defaultChecked = false,
// ==============================
@@ -54,31 +53,31 @@ export const MenuCheckItem = (props: MenuCheckItemProps) => {
);
const inputRef = useRef<HTMLInputElement>(null);
// =============== Menu Context Consumer ====================================================================
// ===================================================================================
const menuContext = useMenuContext();
const size = menuContext?.size ?? propSize;
// 获取来自所属菜单的公共状态
const { size } = useMenuContext()!;
const stateRegistry = menuContext?.stateRegistry;
const stateKeyRef = useRef<string>(null);
// ==============================================================
useEffect(() => {
stateKeyRef.current = useId();
stateRegistry?.insertKey(stateKeyRef.current);
stateRegistry?.updateValue(stateKeyRef.current, {
const { stateRegistryRef } = useMenuDropdownContext()!;
const stateKey = useId();
// 此函数一定会在 “父同名函数” 之前执行,在 “子同名函数” 之后执行。
useLayoutEffect(() => {
stateRegistryRef.current.insertKey(stateKey);
stateRegistryRef.current.updateValue(stateKey, {
hasIcon: iconSvg != undefined,
hasCheckbox: true,
hasIndicator: false,
});
return () => {
// 清除注册表里的数据,永远不会有无用 key
stateRegistry?.deleteEntry(stateKeyRef.current!);
stateRegistryRef.current.deleteEntry(stateKey);
};
}, []);
});
// 后面渲染要用到
const stateResult = menuContext?.stateResult;
// 当菜单搜集完毕,刷新时,此处总是拿到最终结果。
const stateResult = stateRegistryRef.current.getResult();
// =============== Menu Floating Context Consumer ====================================================================
@@ -143,26 +142,30 @@ export const MenuCheckItem = (props: MenuCheckItemProps) => {
onClick: clickHandler,
})}
>
<CheckboxInput
name={name}
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>
<CheckboxInput
name={name}
value={value}
ref={useMergeRefs([inputRef, ref])}
size={size}
defaultChecked={checked}
// 绑定 state 第1/2步,从 state 中获取数据
checked={checked}
// 绑定 state 第2/2步,本元素被键盘点击后,将新值写回 state
onChange={changeHandler}
asBoxOnly={true}
/>
{stateResult?.hasIcon ? (
iconSvg ? (
<Icon size={size}>{iconSvg}</Icon>
) : (
<Icon size={size}>
<div></div>
</Icon>
)
) : (
<Icon size={size}>
<div></div>
</Icon>
<></>
)}
{children}
@@ -1,4 +1,4 @@
import type { CSSProperties } from "react";
import { useLayoutEffect, useRef, useState, type CSSProperties } from "react";
import {
FloatingFocusManager,
FloatingList,
@@ -11,6 +11,8 @@ import { containerRecipe } from "../../styles/recipes/container-recipe";
import { useThemeContext } from "../theme/use-theme-context";
import type { CommonProps } from "../../utils/common-props";
import { brandRecipe } from "../../styles/recipes/brand-recipe";
import { StateRegistry } from "../../utils/state-registry";
import { MenuDropdownContext } from "./use-menu-dropdown-context";
export type MenuDropdownProps = CommonProps & {
modal?: boolean;
@@ -26,11 +28,7 @@ export const MenuDropdown = (props: MenuDropdownProps) => {
...rest
} = props;
// =========== Menu Context Consumer ===================================================================================================
const { size } = useMenuContext()!;
// =========== Menu Floating Context Consumer ===================================================================================================
// ==============================================================================================================
const {
refs,
@@ -41,17 +39,63 @@ export const MenuDropdown = (props: MenuDropdownProps) => {
isOpen,
} = useMenuFloatingContext()!;
// =========== Theme Context Consumer ===================================================================================================
// =====================================================================
const { themeBaseClass, themeClass } = useThemeContext()!;
type V = {
hasIcon: boolean;
hasCheckbox: boolean;
hasIndicator: boolean;
};
type R = {
hasIcon: boolean;
hasCheckbox: boolean;
hasIndicator: boolean;
};
const stateRegistryRef = useRef(new StateRegistry<V, R>());
const [isRenderReady, setIsRenderReady] = useState<boolean>(false);
// 此函数一定会在 “父同名函数” 之前执行,在 “子同名函数” 之后执行。
useLayoutEffect(() => {
if (stateRegistryRef.current.checkAllReady()) {
stateRegistryRef.current.calculateResult((registry) => {
let result: R = {
hasIcon: false,
hasCheckbox: false,
hasIndicator: false,
};
for (const v of registry.values()) {
if (v?.hasIcon == true) {
result.hasIcon = true;
}
if (v?.hasCheckbox == true) {
result.hasCheckbox = true;
}
if (v?.hasIndicator == true) {
result.hasIndicator = true;
}
}
return result;
});
setIsRenderReady(true);
}
});
// ============== Style =================================================================================================
const { themeBaseClass, themeClass } = useThemeContext()!;
const { size } = useMenuContext()!;
const rootClass = mergeClass(
containerRecipe({
boxShadow: true,
rounded: size == "sm" ? 4 : size == "md" ? 8 : undefined,
padding: size == "sm" ? 4 : size == "md" ? 8 : undefined,
rounded: size == "sm" ? 4 : size == "md" ? 6 : undefined,
padding: size == "sm" ? 4 : size == "md" ? 6 : undefined,
minWidth: 160,
background: "base",
hasFocusOutline: "false",
}),
@@ -66,23 +110,30 @@ export const MenuDropdown = (props: MenuDropdownProps) => {
...style,
};
return (
<FloatingList elementsRef={elementsRef}>
{isOpen && (
<FloatingPortal>
<FloatingFocusManager context={context} modal={modal}>
<div
{...rest}
className={rootClass}
style={rootStyle}
ref={refs.setFloating}
{...getFloatingProps()}
>
{children}
</div>
</FloatingFocusManager>
</FloatingPortal>
)}
</FloatingList>
);
// =====================================================================
// 条件渲染
if (isRenderReady) {
return (
<MenuDropdownContext.Provider value={{ stateRegistryRef }}>
<FloatingList elementsRef={elementsRef}>
{isOpen && (
<FloatingPortal>
<FloatingFocusManager context={context} modal={modal}>
<div
{...rest}
className={rootClass}
style={rootStyle}
ref={refs.setFloating}
{...getFloatingProps()}
>
{children}
</div>
</FloatingFocusManager>
</FloatingPortal>
)}
</FloatingList>
</MenuDropdownContext.Provider>
);
}
};
@@ -1,10 +1,10 @@
import { useMenuFloatingContext } from "./use-menu-floating-context";
import { useListItem, useMergeRefs } from "@floating-ui/react";
import React, { useEffect, useId, useRef, type CSSProperties } from "react";
import React, { useId, useLayoutEffect, type CSSProperties } from "react";
import { Icon } from "../icon/icon";
import { ChevronRightSvg } from "../../assets/svg/chevron-right-svg";
import { useMenuTriggerContext } from "./use-menu-trigger-context";
import { useMenuContext } from "./use-menu-context";
import { useMenuDropdownContext } from "./use-menu-dropdown-context";
import { mergeClass } from "../../styles/utils/merge-class";
import { displayRecipe } from "../../styles/recipes/display-recipe";
import { itemSizeRecipe } from "../../styles/recipes/item-size-recipe";
@@ -12,9 +12,9 @@ import { variantRecipe } from "../../styles/recipes/variant-recipe";
import type { CommonProps } from "../../utils/common-props";
import { containerRecipe } from "../../styles/recipes/container-recipe";
import { inlineSizeRecipe } from "../../styles/recipes/inline-size-recipe";
import { useMenuContext } from "./use-menu-context";
export type MenuItemProps = CommonProps & {
size?: "sm" | "md";
onClick?: (e?: React.MouseEvent) => void;
iconSvg?: React.ReactNode;
indicatorSvg?: React.ReactNode;
@@ -23,7 +23,6 @@ export type MenuItemProps = CommonProps & {
export const MenuItem = (props: MenuItemProps) => {
const {
size: propSize = "sm",
ref,
children,
iconSvg,
@@ -35,48 +34,48 @@ export const MenuItem = (props: MenuItemProps) => {
...rest
} = props;
// =============== Menu Trigger Context Consumer ====================================================================
// ===================================================================================
// 获取来自所属菜单的公共状态
const { size } = useMenuContext()!;
// 检测本组件是否是 Trigger 。
const menuTriggerContext = useMenuTriggerContext();
const isTrigger = !!menuTriggerContext;
// =============== Menu Context Consumer ====================================================================
// ===================================================================================
const menuContext = useMenuContext();
const size = menuContext?.size ?? propSize;
const { stateRegistryRef } = useMenuDropdownContext()!;
const stateKey = useId();
const stateRegistry = menuContext?.stateRegistry;
const stateKeyRef = useRef<string>(null);
// 注册 state
useEffect(() => {
stateKeyRef.current = useId();
stateRegistry?.insertKey(stateKeyRef.current);
stateRegistry?.updateValue(stateKeyRef.current, {
hasIcon: iconSvg != undefined,
// 此函数一定会在 “父同名函数” 之前执行,在 “子同名函数” 之后执行。
useLayoutEffect(() => {
stateRegistryRef.current.insertKey(stateKey);
stateRegistryRef.current.updateValue(stateKey, {
hasIcon: iconSvg ? true : false,
hasCheckbox: false,
hasIndicator: isTrigger,
hasIndicator: isTrigger ?? false,
});
return () => {
// 清除注册表里的数据,永远不会有无用 key 和脏数据
stateRegistry?.deleteEntry(stateKeyRef.current!);
stateRegistryRef.current.deleteEntry(stateKey);
};
}, []);
});
// 后面渲染要用到
const stateResult = menuContext?.stateResult;
// 当菜单搜集完毕,刷新时,此处总是拿到最终结果。
const stateResult = stateRegistryRef.current.getResult();
// =============== Menu Floating Context Consumer ====================================================================
// ===================================================================================
// 悬浮相关逻辑。
const menuFloatingContext = useMenuFloatingContext();
const { getItemProps, activeIndex, isOpen } = menuFloatingContext!;
const item = useListItem();
const isActive = item.index === activeIndex;
// ================== Style =================================================================
// ===================================================================================
// 样式。
const rootClass = mergeClass(
displayRecipe({ justifyContent: "between" }),
containerRecipe({ hasFocusOutline: "false" }),
@@ -89,6 +88,11 @@ export const MenuItem = (props: MenuItemProps) => {
...style,
};
const checkPlaceholderClass = mergeClass([
displayRecipe(),
inlineSizeRecipe({ size, isIconOnly: true }),
]);
const startSectionClass = mergeClass([
displayRecipe(),
inlineSizeRecipe({ size }),
@@ -115,12 +119,20 @@ export const MenuItem = (props: MenuItemProps) => {
})}
>
<div className={startSectionClass}>
{stateResult?.hasIcon && iconSvg ? (
<Icon size={size}>{iconSvg}</Icon>
{stateResult?.hasCheckbox && (
<div className={checkPlaceholderClass}></div>
)}
{stateResult?.hasIcon ? (
iconSvg ? (
<Icon size={size}>{iconSvg}</Icon>
) : (
<Icon size={size}>
<div></div>
</Icon>
)
) : (
<Icon size={size}>
<div></div>
</Icon>
<></>
)}
{children}
@@ -129,18 +141,20 @@ export const MenuItem = (props: MenuItemProps) => {
<div className={endSectionClass}>
{hotkey && <div>{hotkey}</div>}
{isTrigger && isOpen && (
<Icon size={size} style={{ rotate: "90deg" }}>
{indicatorSvg}
</Icon>
)}
{isTrigger && !isOpen && <Icon size={size}>{indicatorSvg}</Icon>}
{stateResult?.hasIndicator && (
<Icon size={size}>
<div></div>
</Icon>
{isTrigger ? (
isOpen == true ? (
<Icon size={size} style={{ rotate: "90deg" }}>
{indicatorSvg}
</Icon>
) : (
<Icon size={size}>{indicatorSvg}</Icon>
)
) : (
stateResult?.hasIndicator && (
<Icon size={size}>
<div></div>
</Icon>
)
)}
</div>
</button>
@@ -1,10 +1,8 @@
import type { CommonProps } from "../../utils/common-props";
import { useMenuContext } from "./use-menu-context";
import { RadioboxInputGroup } from "../radiobox-input/radiobox-input-group";
import { useMenuContext } from "./use-menu-context";
export type MenuRadioItemGroupProps = CommonProps & {
size?: "sm" | "md";
name: string;
defaultSelectedValue?: string;
onChange?: (nextSelected?: string) => void;
@@ -13,7 +11,6 @@ export type MenuRadioItemGroupProps = CommonProps & {
export const MenuRadioItemGroup = (props: MenuRadioItemGroupProps) => {
const {
size = "sm",
defaultSelectedValue,
name,
onChange,
@@ -21,14 +18,16 @@ export const MenuRadioItemGroup = (props: MenuRadioItemGroupProps) => {
children,
} = props;
const { size: menuSize } = useMenuContext()!;
// =======================================
const currentSize = menuSize ?? size;
const { size } = useMenuContext()!;
// =======================================
return (
<RadioboxInputGroup
name={name}
size={currentSize}
size={size}
onChange={onChange}
defaultSelectedValue={defaultSelectedValue}
canNoneSelected={canNoneSelected}
@@ -1,13 +1,13 @@
import {
useEffect,
useId,
useLayoutEffect,
useRef,
useState,
type CSSProperties,
type MouseEvent,
} from "react";
import type { CommonProps } from "../../utils/common-props";
import { useMenuContext } from "./use-menu-context";
import { useMenuDropdownContext } from "./use-menu-dropdown-context";
import { useMenuFloatingContext } from "./use-menu-floating-context";
import { useListItem, useMergeRefs } from "@floating-ui/react";
import { mergeClass } from "../../styles/utils/merge-class";
@@ -18,10 +18,10 @@ 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";
import { useMenuContext } from "./use-menu-context";
export type MenuRadioItemProps = CommonProps & {
value: string;
size?: "sm" | "md";
checked?: boolean;
defaultChecked?: boolean;
onChange?: (nextChecked: boolean) => void;
@@ -32,7 +32,6 @@ export type MenuRadioItemProps = CommonProps & {
export const MenuRadioItem = (props: MenuRadioItemProps) => {
const {
size: propSize = "sm",
value,
iconSvg,
hotkey,
@@ -52,33 +51,33 @@ export const MenuRadioItem = (props: MenuRadioItemProps) => {
);
const inputRef = useRef<HTMLInputElement>(null);
// =============== Menu Context Consumer ====================================================================
// ====================================================================
const menuContext = useMenuContext();
const size = menuContext?.size ?? propSize;
// 获取来自所属菜单的公共状态
const { size } = useMenuContext()!;
const stateRegistry = menuContext?.stateRegistry;
const stateKeyRef = useRef<string>(null);
// ====================================================================
useEffect(() => {
stateKeyRef.current = useId();
stateRegistry?.insertKey(stateKeyRef.current);
stateRegistry?.updateValue(stateKeyRef.current, {
const { stateRegistryRef } = useMenuDropdownContext()!;
const stateKey = useId();
// 此函数一定会在 “父同名函数” 之前执行,在 “子同名函数” 之后执行。
useLayoutEffect(() => {
stateRegistryRef.current.insertKey(stateKey);
stateRegistryRef.current.updateValue(stateKey, {
hasIcon: iconSvg != undefined,
hasCheckbox: true,
hasIndicator: false,
});
return () => {
// 清除注册表里的数据,永远不会有无用 key
stateRegistry?.deleteEntry(stateKeyRef.current!);
stateRegistryRef.current.deleteEntry(stateKey);
};
}, []);
});
// 后面渲染要用到
const stateResult = menuContext?.stateResult;
// 当菜单搜集完毕,刷新时,此处总是拿到最终结果。
const stateResult = stateRegistryRef.current.getResult();
// =============== Menu Floating Context Consumer ====================================================================
// ===================================================================================
const menuFloatingContext = useMenuFloatingContext();
const { getItemProps, activeIndex } = menuFloatingContext!;
@@ -91,7 +90,7 @@ export const MenuRadioItem = (props: MenuRadioItemProps) => {
const rootClass = mergeClass(
displayRecipe({ justifyContent: "between" }),
containerRecipe({ hasFocusOutline: "false" }),
itemSizeRecipe({ size, shape: "rounded" }),
itemSizeRecipe({ size, shape: "rounded"}),
variantRecipe({ variant: "ghost", isDisabled }),
);
@@ -127,6 +126,8 @@ export const MenuRadioItem = (props: MenuRadioItemProps) => {
onChange?.(nextChecked);
}
// =========================================================
return (
<button
{...rest}
@@ -141,25 +142,29 @@ export const MenuRadioItem = (props: MenuRadioItemProps) => {
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>
<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}
/>
{stateResult?.hasIcon ? (
iconSvg ? (
<Icon size={size}>{iconSvg}</Icon>
) : (
<Icon size={size}>
<div></div>
</Icon>
)
) : (
<Icon size={size}>
<div></div>
</Icon>
<></>
)}
{children}
+27 -80
View File
@@ -1,17 +1,16 @@
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, useMenuContext } from "./use-menu-context";
import { mergeClass } from "../../styles/utils/merge-class";
import { useStateRegistry } from "../../utils/use-state-registry";
import type { CommonProps } from "../../utils/common-props";
export type MenuProps = ComponentPropsWithoutRef<"div"> & {
export type MenuProps = CommonProps & {
size?: "sm" | "md";
};
export const Menu = (props: MenuProps) => {
const { size: propSize = "sm", className = "", children, ...rest } = props;
const { size: propSize = "md", className = "", children, ...rest } = props;
// ============= parent Menu Context Cunsumer ==================================
@@ -23,86 +22,34 @@ export const Menu = (props: MenuProps) => {
const menuFloatingContextValue = useMenuFloating();
const { isNested, nodeId } = menuFloatingContextValue!;
// ============= Menu Context Provider ==================================
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;
}
});
return result;
});
// ============== 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 = (
<FloatingTree>
<FloatingNode id={nodeId}>
<div {...rest} className={rootClass}>
{children}
</div>
</FloatingNode>
</FloatingTree>
);
} else {
returnStatement = (
<FloatingNode id={nodeId}>
<div {...rest} className={rootClass}>
{children}
</div>
</FloatingNode>
);
}
}
return (
<MenuContext.Provider value={{ size, stateRegistry, stateResult }}>
<MenuFloatingContext.Provider value={menuFloatingContextValue}>
{returnStatement}
</MenuFloatingContext.Provider>
</MenuContext.Provider>
const commonStatement = (
<MenuFloatingContext.Provider value={menuFloatingContextValue}>
<FloatingNode id={nodeId}>
<div {...rest} className={rootClass}>
{children}
</div>
</FloatingNode>
</MenuFloatingContext.Provider>
);
if (!isNested) {
// “根菜单” 和 “嵌套菜单” 是同一颗 Tree,用同一套 MenuContext。
return (
<MenuContext.Provider
value={{
size,
}}
>
<FloatingTree>{commonStatement}</FloatingTree>
</MenuContext.Provider>
);
} else {
return <>{commonStatement}</>;
}
};
@@ -1,20 +1,7 @@
import { createContext, useContext } from "react";
import type { useStateRegistry } from "../../utils/use-state-registry";
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<MenuContextValue>(null);
@@ -0,0 +1,27 @@
import { createContext, useContext } from "react";
import type { StateRegistry } from "../../utils/state-registry";
type V = {
hasIcon: boolean;
hasCheckbox: boolean;
hasIndicator: boolean;
};
type R = {
hasIcon: boolean;
hasCheckbox: boolean;
hasIndicator: boolean;
};
export type MenuDropdownContextValue = {
stateRegistryRef: React.RefObject<StateRegistry<V, R>>;
} | null;
export const MenuDropdownContext =
createContext<MenuDropdownContextValue>(null);
export function useMenuDropdownContext() {
const menuDropdownContext = useContext(MenuDropdownContext);
return menuDropdownContext;
}
@@ -50,12 +50,9 @@ export function usePopoverFloating() {
const { isMounted, styles: transitionStyles } = useTransitionStyles(context, {
duration: 150,
initial: {
opacity: 0,
transform: "scale(0)",
},
close: {
opacity: 0,
},
common: ({ side }) => ({
transitionTimingFunction: "ease",
transformOrigin: {
@@ -28,7 +28,7 @@ export type RadioboxInputProps = CommonProps & {
*/
export const RadioboxInput = (props: RadioboxInputProps) => {
const {
size: propSize = "sm",
size: propSize = "md",
value,
onChange,
ref,
@@ -47,8 +47,7 @@ export const RadioboxInput = (props: RadioboxInputProps) => {
canNoneSelected,
} = useRadioboxInputGroupContext()!;
const currentSize = groupSize ?? propSize;
const size = asBoxOnly ? downGradeSize(currentSize, 1) : currentSize;
const size = groupSize ?? propSize;
const downSize = asBoxOnly ? downGradeSize(size, 1) : size;
const inputRef = useRef<HTMLInputElement>(null);
@@ -58,8 +57,17 @@ export const RadioboxInput = (props: RadioboxInputProps) => {
// ========= Style =========================================
const rootClass = mergeClass(
containerRecipe(),
itemSizeRecipe({ size, isIconOnly: asBoxOnly === true }),
displayRecipe(),
containerRecipe({ hasFocusOutline: "false" }),
asBoxOnly === true
? inlineSizeRecipe({
size,
isIconOnly: true,
})
: itemSizeRecipe({
size,
isIconOnly: true,
}),
className,
);
+65 -18
View File
@@ -1,17 +1,19 @@
import { Icon } from "../icon/icon";
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/common-props";
import { mergeClass } from "../../styles/utils/merge-class";
import { itemSizeRecipe } from "../../styles/recipes/item-size-recipe";
import type { CSSProperties, ReactNode } from "react";
export type TagProps = CommonProps & {
size?: "xs" | "sm";
variant?: "filled" | "outline";
brand?: "success" | "danger" | "info" | "warning" | "default";
leftIconSvg?: ReactNode;
rightIconSvg?: ReactNode;
} & {
color?: string;
background?: string;
borderColor?: string;
@@ -22,41 +24,86 @@ export type TagProps = CommonProps & {
export const Tag = (props: TagProps) => {
const {
className = "",
children,
size = "xs",
variant = "filled",
brand = "info",
leftIconSvg,
rightIconSvg,
// ===================
color,
background,
borderColor,
// ===================
isClosable,
onClose,
// ===================
className = "",
style,
children,
...rest
} = props;
// Fix size
const size = "xs";
// ===============================================
const rootClass = mergeClass(
displayRecipe(),
variantRecipe({ variant: "filled", isUnclickable: true }),
itemSizeRecipe({ size, shape: 'rounded' }),
brandRecipe({ brand }),
variantRecipe({ variant: "subtle", isUnclickable: true }),
itemSizeRecipe({ size, shape: "rounded", isLongPadding: true }),
className,
);
let rootStyle: CSSProperties = {};
if (color) {
rootStyle = { ...rootStyle, color };
}
if (background) {
rootStyle = { ...rootStyle, background };
}
if (borderColor) {
rootStyle = { ...rootStyle, borderColor };
}
rootStyle = { ...rootStyle, ...style };
const iconStyle: CSSProperties = {
width: "12px",
height: "12px",
};
const closeIconClase = mergeClass(
variantRecipe({ variant: "ghost" }),
brandRecipe({ brand: "default" }),
"cursor--pointer"
"cursor--pointer",
);
return (
<div {...rest} className={rootClass} style={{ color: color, background: background, borderColor: borderColor }}>
<div {...rest} className={rootClass} style={rootStyle}>
{leftIconSvg && (
<Icon size={size} style={iconStyle}>
{leftIconSvg}
</Icon>
)}
{children}
<Icon
className={closeIconClase}
size={size}
shape={"circle"}
onClick={onClose}
>
<CloseSvg />
</Icon>
{rightIconSvg && (
<Icon size={size} style={iconStyle}>
{rightIconSvg}
</Icon>
)}
{isClosable && (
<Icon
className={closeIconClase}
style={iconStyle}
size={size}
shape={"circle"}
onClick={onClose}
>
<CloseSvg />
</Icon>
)}
</div>
);
};
+59 -56
View File
@@ -1,56 +1,59 @@
@import './styles/css/z-index.css';
@import './styles/css/width-item.css';
@import './styles/css/width-inline.css';
@import './styles/css/width-dot.css';
@import './styles/css/white-space.css';
@import './styles/css/visibility.css';
@import './styles/css/variant.css';
@import './styles/css/variant-unclickable.css';
@import './styles/css/variant-disabled.css';
@import './styles/css/user-select.css';
@import './styles/css/transition.css';
@import './styles/css/theme.css';
@import './styles/css/theme-base.css';
@import './styles/css/text-align.css';
@import './styles/css/screen-reader.css';
@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';
@import './styles/css/opacity.css';
@import './styles/css/max-width.css';
@import './styles/css/max-height.css';
@import './styles/css/justify-self.css';
@import './styles/css/justify-items.css';
@import './styles/css/justify-content.css';
@import './styles/css/height-item.css';
@import './styles/css/height-inline.css';
@import './styles/css/height-dot.css';
@import './styles/css/gap.css';
@import './styles/css/font-weight.css';
@import './styles/css/font-size.css';
@import './styles/css/font-family.css';
@import './styles/css/flex-wrap.css';
@import './styles/css/flex-shrink.css';
@import './styles/css/flex-direction.css';
@import './styles/css/drop-shadow.css';
@import './styles/css/display.css';
@import './styles/css/cursor.css';
@import './styles/css/color.css';
@import './styles/css/break-before.css';
@import './styles/css/break-after.css';
@import './styles/css/brand.css';
@import './styles/css/box-sizing.css';
@import './styles/css/box-shadow.css';
@import './styles/css/box-inside.css';
@import './styles/css/box-decoration.css';
@import './styles/css/border.css';
@import './styles/css/border-radius.css';
@import './styles/css/background.css';
@import './styles/css/animation.css';
@import './styles/css/align-self.css';
@import './styles/css/align-items.css';
@import './styles/css/align-content.css';
@import "./styles/css/z-index.css";
@import "./styles/css/width-item.css";
@import "./styles/css/width-inline.css";
@import "./styles//css/min-width.css";
@import "./styles/css/width.css";
@import "./styles/css/white-space.css";
@import "./styles/css/visibility.css";
@import "./styles/css/variant.css";
@import "./styles/css/variant-unclickable.css";
@import "./styles/css/variant-disabled.css";
@import "./styles/css/user-select.css";
@import "./styles/css/transition.css";
@import "./styles/css/theme.css";
@import "./styles/css/theme-base.css";
@import "./styles/css/text-align.css";
@import "./styles/css/screen-reader.css";
@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";
@import "./styles/css/opacity.css";
@import "./styles/css/max-width.css";
@import "./styles/css/max-height.css";
@import "./styles/css/justify-self.css";
@import "./styles/css/justify-items.css";
@import "./styles/css/justify-content.css";
@import "./styles/css/height-item.css";
@import "./styles/css/height-inline.css";
@import "./styles/css/height.css";
@import "./styles/css/gap.css";
@import "./styles/css/font-weight.css";
@import "./styles/css/font-size.css";
@import "./styles/css/font-family.css";
@import "./styles/css/flex-wrap.css";
@import "./styles/css/flex-shrink.css";
@import "./styles/css/flex-direction.css";
@import "./styles/css/drop-shadow.css";
@import "./styles/css/display.css";
@import "./styles/css/cursor.css";
@import "./styles/css/color.css";
@import "./styles/css/break-before.css";
@import "./styles/css/break-after.css";
@import "./styles/css/brand.css";
@import "./styles/css/box-sizing.css";
@import "./styles/css/box-shadow.css";
@import "./styles/css/box-inside.css";
@import "./styles/css/box-decoration.css";
@import "./styles/css/border.css";
@import "./styles/css/border-radius.css";
@import "./styles/css/background.css";
@import "./styles/css/animation.css";
@import "./styles/css/align-self.css";
@import "./styles/css/align-items.css";
@import "./styles/css/align-content.css";
@import "./styles/css/min-width-item.css";
@import "./styles/css/min-width-inline.css";
+36 -33
View File
@@ -1,33 +1,36 @@
import './index.css';
export * from './styles/utils/merge-class.ts';
export * from './styles/utils/create-class-recipe.ts';
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';
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';
import "./index.css";
export * from "./styles/utils/merge-class.ts";
export * from "./styles/utils/create-class-recipe.ts";
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";
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/display-recipe.ts";
export * from "./styles/recipes/container-recipe.ts";
export * from "./styles/recipes/brand-recipe.ts";
export * from "./assets/svg/star-filled-svg.tsx";
export * from "./assets/svg/star-outline-svg.tsx";
export * from "./assets/svg/checkmark-circle-svg.tsx";
export * from "./assets/svg/exclamation-circle-svg.tsx";
@@ -2,4 +2,7 @@
.background--base {
background: var(--base-background);
}
.background--red {
background: var(--danger-background-high);
}
}
@@ -39,14 +39,26 @@
border-radius: var(--radius-4);
}
.rounded--6 {
border-radius: var(--radius-6);
}
.rounded--8 {
border-radius: var(--radius-8);
}
.rounded--10 {
border-radius: var(--radius-10);
}
.rounded--12 {
border-radius: var(--radius-12);
}
.rounded--14 {
border-radius: var(--radius-14);
}
.rounded--16 {
border-radius: var(--radius-16);
}
@@ -1,57 +1,29 @@
@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));
}
height: var(--height-inline-xs);
}
.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));
}
height: var(--height-inline-sm);
}
.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));
}
height: var(--height-inline-md);
}
.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));
}
height: var(--height-inline-lg);
}
.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));
}
height: var(--height-inline-xl);
}
.h--inline-xxl {
height: calc(var(--font-size-xxl) * var(--line-height));
& svg {
height: calc(var(--font-size-xxl) * var(--line-height));
width: calc(var(--font-size-xxl) * var(--line-height));
}
height: var(--height-inline-xxl);
}
.h--inline-xxxl {
height: calc(var(--font-size-xxxl) * var(--line-height));
& svg {
height: calc(var(--font-size-xxxl) * var(--line-height));
width: calc(var(--font-size-xxxl) * var(--line-height));
}
height: var(--height-inline-xxxl);
}
}
@@ -1,51 +1,23 @@
@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-xxl {
height: var(--height-item-xxl);
& svg {
height: calc(var(--font-size-xxl) * var(--line-height));
width: calc(var(--font-size-xxl) * var(--line-height));
}
}
.h--item-xxxl {
height: var(--height-item-xxxl);
& svg {
height: calc(var(--font-size-xxxl) * var(--line-height));
width: calc(var(--font-size-xxxl) * var(--line-height));
}
}
}
@@ -0,0 +1,5 @@
@layer utility {
.h--6 {
height: 6px;
}
}
@@ -0,0 +1,30 @@
@layer utility {
.min-w--inline-xs {
box-sizing: border-box;
min-width: var(--height-inline-xs);
}
.min-w--inline-sm {
box-sizing: border-box;
min-width: var(--height-inline-sm);
}
.min-w--inline-md {
box-sizing: border-box;
min-width: var(--height-inline-md);
}
.min-w--inline-lg {
box-sizing: border-box;
min-width: var(--height-inline-lg);
}
.min-w--inline-xl {
box-sizing: border-box;
min-width: var(--height-inline-xl);
}
.min-w--inline-xxl {
box-sizing: border-box;
min-width: var(--height-inline-xxl);
}
.min-w--inline-xxxl {
box-sizing: border-box;
min-width: var(--height-inline-xxxl);
}
}
@@ -0,0 +1,30 @@
@layer utility {
.min-w--item-xs {
box-sizing: border-box;
min-width: var(--height-item-xs);
}
.min-w--item-sm {
box-sizing: border-box;
min-width: var(--height-item-sm);
}
.min-w--item-md {
box-sizing: border-box;
min-width: var(--height-item-md);
}
.min-w--item-lg {
box-sizing: border-box;
min-width: var(--height-item-lg);
}
.min-w--item-xl {
box-sizing: border-box;
min-width: var(--height-item-xl);
}
.min-w--item-xxl {
box-sizing: border-box;
min-width: var(--height-item-xxl);
}
.min-w--item-xxxl {
box-sizing: border-box;
min-width: var(--height-item-xxxl);
}
}
@@ -0,0 +1,6 @@
@layer utility {
.min-w--220 {
box-sizing: border-box;
min-width: 220px;
}
}
@@ -59,18 +59,36 @@
.py--4 {
padding-block: var(--padding-4);
}
.px--6 {
padding-inline: var(--padding-6);
}
.py--6 {
padding-block: var(--padding-6);
}
.px--8 {
padding-inline: var(--padding-8);
}
.py--8 {
padding-block: var(--padding-8);
}
.px--10 {
padding-inline: var(--padding-10);
}
.py--10 {
padding-block: var(--padding-10);
}
.px--12 {
padding-inline: var(--padding-12);
}
.py--12 {
padding-block: var(--padding-12);
}
.px--14 {
padding-inline: var(--padding-14);
}
.py--14 {
padding-block: var(--padding-14);
}
.px--16 {
padding-inline: var(--padding-16);
}
+36 -14
View File
@@ -363,6 +363,30 @@
--height-item-xxl: 56px;
--height-item-xxxl: 64px;
--times-of-height-inline: 1.3;
--height-inline-xs: calc(
var(--font-size-xs) * var(--times-of-height-inline)
);
--height-inline-sm: calc(
var(--font-size-sm) * var(--times-of-height-inline)
);
--height-inline-md: calc(
var(--font-size-md) * var(--times-of-height-inline)
);
--height-inline-lg: calc(
var(--font-size-lg) * var(--times-of-height-inline)
);
--height-inline-xl: calc(
var(--font-size-xl) * var(--times-of-height-inline)
);
--height-inline-xxl: calc(
var(--font-size-xxl) * var(--times-of-height-inline)
);
--height-inline-xxl: calc(
var(--font-size-xxl) * var(--times-of-height-inline)
);
--radius-xs: 2px;
--radius-sm: 3px;
--radius-md: 4px;
@@ -381,7 +405,7 @@
--padding-xxl: 2px;
--padding-xxxl: 2px;
--times-of-padding-long: 2;
--times-of-padding-long: 1.5;
--padding-long-xs: calc(var(--padding-xs) * var(--times-of-padding-long));
--padding-long-sm: calc(var(--padding-sm) * var(--times-of-padding-long));
@@ -391,10 +415,10 @@
--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-xs: 3px;
--gap-sm: 4px;
--gap-md: 5px;
--gap-lg: 6px;
--gap-xl: 10px;
--gap-xxl: 12px;
--gap-xxxl: 14px;
@@ -406,17 +430,23 @@
--box-shadow:
0 0 16px 0px rgba(0, 0, 0, 0.1), 0 8px 20px 0px rgba(0, 0, 0, 0.1);
--border-1: 1px solid;
--border-1: 1.2px solid;
--border-none: 0 solid;
--radius-4: 4px;
--radius-6: 6px;
--radius-8: 8px;
--radius-10: 10px;
--radius-12: 12px;
--radius-14: 14px;
--radius-16: 16px;
--padding-4: 4px;
--padding-6: 6px;
--padding-8: 8px;
--padding-10: 10px;
--padding-12: 12px;
--padding-14: 14px;
--padding-16: 16px;
--animate-spin: spin 1s linear infinite;
@@ -435,12 +465,4 @@
--font-mono:
ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
"Courier New", monospace;
--height-inline-xs: calc(var(--font-size-xs) * var(--line-height));
--height-inline-sm: calc(var(--font-size-sm) * var(--line-height));
--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-xxl: calc(var(--font-size-xxl) * var(--line-height));
--height-inline-xxxl: calc(var(--font-size-xxxl) * var(--line-height));
}
@@ -1,155 +1,149 @@
@layer utility {
.variant--filled-disabled {
--filled-color: var(--color-white);
--filled-color-hover: var(--color-white);
--filled-color-active: var(--color-white);
.variant--filled-disabled {
--filled-color: var(--color-white);
--filled-color-hover: var(--color-white);
--filled-color-active: var(--color-white);
--filled-background: var(--brand-background-high);
--filled-background-hover: var(--brand-background-high-hover);
--filled-background-active: var(--brand-background-high-active);
--filled-background: var(--brand-background-high);
--filled-background-hover: var(--brand-background-high-hover);
--filled-background-active: var(--brand-background-high-active);
--filled-border: var(--border-none);
--filled-border-color: var(--color-transparent);
color: var(--filled-color);
background-color: var(--filled-background);
border: var(--filled-border);
border-color: var(--filled-border-color);
filter: grayscale(100);
&:hover {
color: var(--filled-color);
background-color: var(--filled-background);
filter: grayscale(100);
}
&:focus-visible {
color: var(--filled-color);
background-color: var(--filled-background);
filter: grayscale(100);
}
&:active {
color: var(--filled-color);
background-color: var(--filled-background);
filter: grayscale(100);
}
--filled-border: var(--border-none);
--filled-border-color: var(--color-transparent);
color: var(--filled-color);
background-color: var(--filled-background);
border: var(--filled-border);
border-color: var(--filled-border-color);
filter: grayscale(100);
&:hover {
color: var(--filled-color);
background-color: var(--filled-background);
filter: grayscale(100);
}
.variant--outline-disabled {
--outline-color: var(--brand-background);
--outline-color-hover: var(--brand-background);
--outline-color-active: var(--brand-background);
--outline-background: var(--color-transparent);
--outline-background-hover: var(--brand-background-low-hover);
--outline-background-active: var(--brand-background-low-active);
--outline-border: var(--border-1);
--outline-border-color: var(--brand-background);
color: var(--outline-color);
background-color: var(--outline-background);
border: var(--outline-border);
border-color: var(--outline-border-color);
filter: grayscale(100);
&:hover {
color: var(--outline-color);
background-color: var(--outline-background);
filter: grayscale(100);
}
&:focus-visible {
color: var(--outline-color);
background-color: var(--outline-background);
filter: grayscale(100);
}
&:active {
color: var(--outline-color);
background-color: var(--outline-background);
filter: grayscale(100);
}
&:focus-visible {
color: var(--filled-color);
background-color: var(--filled-background);
filter: grayscale(100);
}
.variant--subtle-disabled {
--subtle-color: var(--brand-background);
--subtle-color-hover: var(--brand-background);
--subtle-color-active: var(--brand-background);
&:active {
color: var(--filled-color);
background-color: var(--filled-background);
filter: grayscale(100);
}
}
--subtle-background: var(--brand-background-low);
--subtle-background-hover: var(--brand-background-low-hover);
--subtle-background-active: var(--brand-background-low-active);
.variant--outline-disabled {
--outline-color: var(--brand-background-high);
--outline-color-hover: var(--brand-background-high);
--outline-color-active: var(--brand-background-high);
--subtle-border: var(--border-none);
--subtle-border-color: var(--color-transparent);
--outline-background: var(--color-transparent);
--outline-background-hover: var(--brand-background-low-hover);
--outline-background-active: var(--brand-background-low-active);
color: var(--subtle-color);
background-color: var(--subtle-background);
border: var(--subtle-border);
border-color: var(--subtle-border-color);
filter: grayscale(100);
--outline-border: var(--border-1);
--outline-border-color: var(--brand-background-high-active);
&:hover {
color: var(--subtle-color);
background-color: var(--subtle-background);
filter: grayscale(100);
}
&:focus-visible {
color: var(--subtle-color);
background-color: var(--subtle-background);
filter: grayscale(100);
}
&:active {
color: var(--subtle-color);
background-color: var(--subtle-background);
filter: grayscale(100);
}
color: var(--outline-color);
background-color: var(--outline-background);
border: var(--outline-border);
border-color: var(--outline-border-color);
filter: grayscale(100);
&:hover {
color: var(--outline-color);
background-color: var(--outline-background);
filter: grayscale(100);
}
.variant--ghost-disabled {
--ghost-color: var(--brand-background);
--ghost-color-hover: var(--brand-background);
--ghost-color-active: var(--brand-background);
--ghost-background: var(--color-transparent);
--ghost-background-hover: var(--brand-background-low-hover);
--ghost-background-active: var(--brand-background-low-active);
--ghost-border: var(--border-none);
--ghost-border-color: var(--color-transparent);
color: var(--ghost-color);
background-color: var(--ghost-background);
border: var(--ghost-border);
border-color: var(--ghost-border-color);
filter: grayscale(100);
&:hover {
color: var(--ghost-color);
background-color: var(--ghost-background);
filter: grayscale(100);
}
&:focus-visible {
color: var(--ghost-color);
background-color: var(--ghost-background);
filter: grayscale(100);
}
&:active {
color: var(--ghost-color);
background-color: var(--ghost-background);
filter: grayscale(100);
}
&:focus-visible {
color: var(--outline-color);
background-color: var(--outline-background);
filter: grayscale(100);
}
}
&:active {
color: var(--outline-color);
background-color: var(--outline-background);
filter: grayscale(100);
}
}
.variant--subtle-disabled {
--subtle-color: var(--brand-background-high);
--subtle-color-hover: var(--brand-background-high);
--subtle-color-active: var(--brand-background-high);
--subtle-background: var(--brand-background-low);
--subtle-background-hover: var(--brand-background-low-hover);
--subtle-background-active: var(--brand-background-low-active);
--subtle-border: var(--border-none);
--subtle-border-color: var(--color-transparent);
color: var(--subtle-color);
background-color: var(--subtle-background);
border: var(--subtle-border);
border-color: var(--subtle-border-color);
filter: grayscale(100);
&:hover {
color: var(--subtle-color);
background-color: var(--subtle-background);
filter: grayscale(100);
}
&:focus-visible {
color: var(--subtle-color);
background-color: var(--subtle-background);
filter: grayscale(100);
}
&:active {
color: var(--subtle-color);
background-color: var(--subtle-background);
filter: grayscale(100);
}
}
.variant--ghost-disabled {
--ghost-color: var(--brand-background-high);
--ghost-color-hover: var(--brand-background-high);
--ghost-color-active: var(--brand-background-high);
--ghost-background: var(--color-transparent);
--ghost-background-hover: var(--brand-background-low-hover);
--ghost-background-active: var(--brand-background-low-active);
--ghost-border: var(--border-none);
--ghost-border-color: var(--color-transparent);
color: var(--ghost-color);
background-color: var(--ghost-background);
border: var(--ghost-border);
border-color: var(--ghost-border-color);
filter: grayscale(100);
&:hover {
color: var(--ghost-color);
background-color: var(--ghost-background);
filter: grayscale(100);
}
&:focus-visible {
color: var(--ghost-color);
background-color: var(--ghost-background);
filter: grayscale(100);
}
&:active {
color: var(--ghost-color);
background-color: var(--ghost-background);
filter: grayscale(100);
}
}
}
@@ -1,76 +1,73 @@
@layer utility {
.variant--filled-unclickable {
--filled-color: var(--color-white);
--filled-color-hover: var(--color-white);
--filled-color-active: var(--color-white);
.variant--filled-unclickable {
--filled-color: var(--color-white);
--filled-color-hover: var(--color-white);
--filled-color-active: var(--color-white);
--filled-background: var(--brand-background-high);
--filled-background-hover: var(--brand-background-high-hover);
--filled-background: var(--brand-background-high);
--filled-background-hover: var(--brand-background-high-hover);
--filled-background-active: var(--brand-background-high-active);
--filled-border: var(--border-none);
--filled-border-color: var(--color-transparent);
--filled-background-active: var(--brand-background-high-active);
--filled-border: var(--border-none);
--filled-border-color: var(--color-transparent);
color: var(--filled-color);
background-color: var(--filled-background);
border: var(--filled-border);
border-color: var(--filled-border-color);
color: var(--filled-color);
background-color: var(--filled-background);
border: var(--filled-border);
border-color: var(--filled-border-color);
}
}
.variant--outline-unclickable {
--outline-color: var(--brand-background-high);
--outline-color-hover: var(--brand-background-high);
--outline-color-active: var(--brand-background-high);
.variant--outline-unclickable {
--outline-color: var(--brand-background);
--outline-color-hover: var(--brand-background);
--outline-color-active: var(--brand-background);
--outline-background: var(--color-transparent);
--outline-background-hover: var(--brand-background-low-hover);
--outline-background-active: var(--brand-background-low-active);
--outline-background: var(--color-transparent);
--outline-background-hover: var(--brand-background-low-hover);
--outline-background-active: var(--brand-background-low-active);
--outline-border: var(--border-1);
--outline-border-color: var(--brand-background-high-active);
--outline-border: var(--border-1);
--outline-border-color: var(--brand-background);
color: var(--outline-color);
background-color: var(--outline-background);
border: var(--outline-border);
border-color: var(--outline-border-color);
}
color: var(--outline-color);
background-color: var(--outline-background);
border: var(--outline-border);
border-color: var(--outline-border-color);
.variant--subtle-unclickable {
--subtle-color: var(--brand-background-high);
--subtle-color-hover: var(--brand-background-high);
--subtle-color-active: var(--brand-background-high);
}
--subtle-background: var(--brand-background-low);
--subtle-background-hover: var(--brand-background-low-hover);
--subtle-background-active: var(--brand-background-low-active);
.variant--subtle-unclickable {
--subtle-color: var(--brand-background);
--subtle-color-hover: var(--brand-background);
--subtle-color-active: var(--brand-background);
--subtle-border: var(--border-none);
--subtle-border-color: var(--color-transparent);
--subtle-background: var(--brand-background-low);
--subtle-background-hover: var(--brand-background-low-hover);
--subtle-background-active: var(--brand-background-low-active);
color: var(--subtle-color);
background-color: var(--subtle-background);
border: var(--subtle-border);
border-color: var(--subtle-border-color);
}
--subtle-border: var(--border-none);
--subtle-border-color: var(--color-transparent);
.variant--ghost-unclickable {
--ghost-color: var(--brand-background-high);
--ghost-color-hover: var(--brand-background-high);
--ghost-color-active: var(--brand-background-high);
color: var(--subtle-color);
background-color: var(--subtle-background);
border: var(--subtle-border);
border-color: var(--subtle-border-color);
--ghost-background: var(--color-transparent);
--ghost-background-hover: var(--brand-background-low-hover);
--ghost-background-active: var(--brand-background-low-active);
}
--ghost-border: var(--border-none);
--ghost-border-color: var(--color-transparent);
.variant--ghost-unclickable {
--ghost-color: var(--brand-background);
--ghost-color-hover: var(--brand-background);
--ghost-color-active: var(--brand-background);
--ghost-background: var(--color-transparent);
--ghost-background-hover: var(--brand-background-low-hover);
--ghost-background-active: var(--brand-background-low-active);
--ghost-border: var(--border-none);
--ghost-border-color: var(--color-transparent);
color: var(--ghost-color);
background-color: var(--ghost-background);
border: var(--ghost-border);
border-color: var(--ghost-border-color);
}
}
color: var(--ghost-color);
background-color: var(--ghost-background);
border: var(--ghost-border);
border-color: var(--ghost-border-color);
}
}
@@ -1,30 +0,0 @@
@layer utility {
.w--dot-xs {
width: calc(var(--font-size-xs) / 2);
}
.w--dot-sm {
width: calc(var(--font-size-sm) / 2);
}
.w--dot-md {
width: calc(var(--font-size-md) / 2);
}
.w--dot-lg {
width: calc(var(--font-size-lg) / 2);
}
.w--dot-xl {
width: calc(var(--font-size-xl) / 2);
}
.w--dot-xxl {
width: calc(var(--font-size-xxl) / 2);
}
.w--dot-xxxl {
width: calc(var(--font-size-xxxl) / 2);
}
}
@@ -1,29 +1,29 @@
@layer utility {
.w--inline-xs {
width: calc(var(--font-size-xs) * var(--line-height));
width: var(--height-inline-xs);
}
.w--inline-sm {
width: calc(var(--font-size-sm) * var(--line-height));
width: var(--height-inline-sm);
}
.w--inline-md {
width: calc(var(--font-size-md) * var(--line-height));
width: var(--height-inline-md);
}
.w--inline-lg {
width: calc(var(--font-size-lg) * var(--line-height));
width: var(--height-inline-lg);
}
.w--inline-xl {
width: calc(var(--font-size-xl) * var(--line-height));
width: var(--height-inline-xl);
}
.w--inline-xxl {
width: calc(var(--font-size-xxl) * var(--line-height));
width: var(--height-inline-xxl);
}
.w--inline-xxxl {
width: calc(var(--font-size-xxxl) * var(--line-height));
width: var(--height-inline-xxxl);
}
}
@@ -0,0 +1,5 @@
@layer utility {
.w--6 {
width: 6px;
}
}
@@ -11,14 +11,20 @@ export const containerRecipe = createClassRecipe({
},
rounded: {
4: "rounded--4",
6: "rounded--6",
8: "rounded--8",
10: "rounded--10",
12: "rounded--12",
14: "rounded--14",
16: "rounded--16",
},
padding: {
4: "px--4 py--4",
8: "px--8 py--8",
6: "px--6 py--6",
8: "px--8 py--8",
10: "px--10 py--10",
12: "px--12 py--12",
14: "px--14 py--14",
16: "px--16 py--16",
},
boxShadow: {
@@ -27,6 +33,10 @@ export const containerRecipe = createClassRecipe({
dropShadow: {
true: "drop-shadow",
},
minWidth: {
160: "min-w--160",
220: "min-w--220",
},
hasFocusOutline: {
true: "outline",
false: "outline--none",
@@ -1,16 +0,0 @@
import { createClassRecipe } from "../utils/create-class-recipe";
export const dotSizeRecipe = createClassRecipe({
base: "bg--red color--white",
variants: {
size: {
xs: "h--dot-xs w--dot-xs",
sm: "h--dot-sm w--dot-sm",
md: "h--dot-md w--dot-md",
lg: "h--dot-lg w--dot-lg",
xl: "h--dot-lg w--dot-xl",
"2xl": "h--dot-lg w--dot-2xl",
"3xl": "h--dot-lg w--dot-3xl",
},
},
});
@@ -9,8 +9,8 @@ export const inlineSizeRecipe = createClassRecipe({
md: "text--md font-weight--md h--inline-md gap--md",
lg: "text--lg font-weight--lg h--inline-lg gap--lg",
xl: "text--xl font-weight--xl h--inline-xl gap--xl",
"2xl": "text--2xl font-weight--2xl h--inline-2xl gap--2xl",
"3xl": "text--3xl font-weight--3xl h--inline-3xl gap--3xl",
xxl: "text--xxl font-weight--xxl h--inline-xxl gap--xxl",
xxxl: "text--xxxl font-weight--xxxl h--inline-xxxl gap--xxxl",
},
shape: {
square: "rounded--none",
@@ -19,30 +19,66 @@ export const inlineSizeRecipe = createClassRecipe({
},
isIconOnly: {
true: "",
false: ""
}
false: "",
},
hasPadding: {
true: "",
false: "",
},
hasMinWidth: {
true: "",
false: "",
},
},
compoundVariants: [
{ size: "xs", hasPadding: true, class: "px--xs" },
{ size: "sm", hasPadding: true, class: "px--sm" },
{ size: "md", hasPadding: true, class: "px--md" },
{ size: "lg", hasPadding: true, class: "px--lg" },
{ size: "xl", hasPadding: true, class: "px--xl" },
{ size: "xxl", hasPadding: true, class: "px--xxl" },
{ size: "xxxl", hasPadding: true, class: "px--xxxl" },
{ size: "xs", hasMinWidth: true, class: "min-w--inline-xs" },
{ size: "sm", hasMinWidth: true, class: "min-w--inline-sm" },
{ size: "md", hasMinWidth: true, class: "min-w--inline-md" },
{ size: "lg", hasMinWidth: true, class: "min-w--inline-lg" },
{ size: "xl", hasMinWidth: true, class: "min-w--inline-xl" },
{ size: "xxl", hasMinWidth: true, class: "min-w--inline-xxl" },
{ size: "xxxl", hasMinWidth: true, class: "min-w--inline-xxxl" },
{
size: "xs", isIconOnly: true, class: "w--inline-xs px--none"
size: "xs",
isIconOnly: true,
class: "w--inline-xs px--none",
},
{
size: "sm", isIconOnly: true, class: "w--inline-sm px--none"
size: "sm",
isIconOnly: true,
class: "w--inline-sm px--none",
},
{
size: "md", isIconOnly: true, class: "w--inline-md px--none"
size: "md",
isIconOnly: true,
class: "w--inline-md px--none",
},
{
size: "lg", isIconOnly: true, class: "w--inline-lg px--none"
size: "lg",
isIconOnly: true,
class: "w--inline-lg px--none",
},
{
size: "xl", isIconOnly: true, class: "w--inline-xl px--none"
size: "xl",
isIconOnly: true,
class: "w--inline-xl px--none",
},
{
size: "2xl", isIconOnly: true, class: "w--inline-2xl px--none"
size: "xxl",
isIconOnly: true,
class: "w--inline-xxl px--none",
},
{
size: "3xl", isIconOnly: true, class: "w--inline-3xl px--none"
size: "xxxl",
isIconOnly: true,
class: "w--inline-xxxl px--none",
},
// ==================================================
{ shape: "rounded", size: "xs", class: "rounded--xs" },
@@ -50,7 +86,7 @@ export const inlineSizeRecipe = createClassRecipe({
{ shape: "rounded", size: "md", class: "rounded--md" },
{ shape: "rounded", size: "lg", class: "rounded--lg" },
{ shape: "rounded", size: "xl", class: "rounded--xl" },
{ shape: "rounded", size: "2xl", class: "rounded--2xl" },
{ shape: "rounded", size: "3xl", class: "rounded--3xl" },
]
{ shape: "rounded", size: "xxl", class: "rounded--xxl" },
{ shape: "rounded", size: "xxxl", class: "rounded--xxxl" },
],
});
@@ -4,13 +4,13 @@ export const itemSizeRecipe = createClassRecipe({
base: "py--none",
variants: {
size: {
xs: "text--xs font-weight--xs h--item-xs gap--xs px--xs",
sm: "text--sm font-weight--sm h--item-sm gap--sm px--sm",
md: "text--md font-weight--md h--item-md gap--md px--md",
lg: "text--lg font-weight--lg h--item-lg gap--lg px--lg",
xl: "text--xl font-weight--xl h--item-xl gap--xl px--xl",
"2xl": "text--2xl font-weight--2xl h--item-2xl gap--2xl px--2xl",
"3xl": "text--3xl font-weight--3xl h--item-3xl gap--3xl px--3xl",
xs: "text--xs font-weight--xs h--item-xs gap--xs px--xs min-w--item-xs",
sm: "text--sm font-weight--sm h--item-sm gap--sm px--sm min-w--item-sm",
md: "text--md font-weight--md h--item-md gap--md px--md min-w--item-md",
lg: "text--lg font-weight--lg h--item-lg gap--lg px--lg min-w--item-lg",
xl: "text--xl font-weight--xl h--item-xl gap--xl px--xl min-w--item-xl",
xxl: "text--xxl font-weight--xxl h--item-xxl gap--xxl px--xxl min-w--item-xxl",
xxxl: "text--xxxl font-weight--xxxl h--item-xxxl gap--xxxl px--xxxl min-w--item-xxxl",
},
shape: {
square: "rounded--none",
@@ -32,21 +32,21 @@ export const itemSizeRecipe = createClassRecipe({
{ 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" },
{ isLongPadding: true, size: "xxl", class: "px--long-xxl" },
{ isLongPadding: true, size: "xxxl", class: "px--long-xxxl" },
{ shape: "rounded", size: "xs", class: "rounded--xs" },
{ shape: "rounded", size: "sm", class: "rounded--sm" },
{ shape: "rounded", size: "md", class: "rounded--md" },
{ shape: "rounded", size: "lg", class: "rounded--lg" },
{ shape: "rounded", size: "xl", class: "rounded--xl" },
{ shape: "rounded", size: "2xl", class: "rounded--2xl" },
{ shape: "rounded", size: "3xl", class: "rounded--3xl" },
{ shape: "rounded", size: "xxl", class: "rounded--xxl" },
{ shape: "rounded", size: "xxxl", class: "rounded--xxxl" },
{ 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" },
{ isIconOnly: true, size: "lg", class: "w--item-lg px--none" },
{ isIconOnly: true, size: "xl", class: "w--item-xl px--none" },
{ isIconOnly: true, size: "2xl", class: "w--item-2xl px--none" },
{ isIconOnly: true, size: "3xl", class: "w--item-3xl px--none" },
{ isIconOnly: true, size: "xxl", class: "w--item-xxl px--none" },
{ isIconOnly: true, size: "xxxl", class: "w--item-xxxl px--none" },
],
});
@@ -1,4 +1,4 @@
type SizeType = ["xs", "sm", "md", "lg", "xl", "2xl", "3xl"];
type SizeType = ["xs", "sm", "md", "lg", "xl", "xxl", "xxxl"];
/**
*
@@ -6,16 +6,16 @@ type SizeType = ["xs", "sm", "md", "lg", "xl", "2xl", "3xl"];
* Return available value or undefind
*/
export function downGradeSize(
size: "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | undefined,
size: "xs" | "sm" | "md" | "lg" | "xl" | "xxl" | "xxxl" | undefined,
downGrade: number = 1,
): "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | undefined {
): "xs" | "sm" | "md" | "lg" | "xl" | "xxl" | "xxxl" | undefined {
if (size == undefined) {
return undefined;
}
const sizeArray: SizeType = ["xs", "sm", "md", "lg", "xl", "2xl", "3xl"];
const sizeArray: SizeType = ["xs", "sm", "md", "lg", "xl", "xxl", "xxxl"];
const index = sizeArray.findIndex((v) => v == size);
const index = sizeArray.findIndex((v) => v === size);
const downIndex = index - downGrade;
+1 -1
View File
@@ -6,7 +6,7 @@ export const Slot = (props: Record<string, any> & { children?: ReactNode }) => {
const { children, ...rest } = props;
if (!isValidElement(children)) {
throw new Error("isValidElement no pass !");
throw new Error("The children of Slot Component must be ValidElement.");
}
const mergedProps = mergeProps(children.props as any, rest);
@@ -0,0 +1,71 @@
export class StateRegistry<V, R> {
private registry: Map<string, V | undefined> = new Map();
private result: R | undefined;
/**
* If the key exists, return false.
*/
public insertKey = (key: string) => {
if (this.registry.has(key)) {
return false;
} else {
this.registry.set(key, undefined);
return true;
}
};
/**
* If the `key` dose not exists, return `false`.
*
* Use insertKey before updateValue.
*/
public updateValue = (key: string, value: V) => {
if (this.registry.has(key)) {
this.registry.set(key, value);
return true;
} else {
return false;
}
};
/**
* If the `key` dose not exists, return `false`.
*/
public deleteEntry = (key: string) => {
if (this.registry.has(key)) {
this.registry.delete(key);
return true;
} else {
return false;
}
};
/**
* If the `value` of an entry is found to be `undefined`, return `false`.
*/
public checkAllReady = () => {
for (const e of this.registry.values()) {
if (e == undefined) {
return false;
}
}
return true;
};
/**
* Using your own logic to calculate and return the `result`.
*
* Or use `this.result` to access it.
*/
public calculateResult = (
callback: (registry: Map<String, V | undefined>) => R,
) => {
this.result = callback(this.registry);
return this.result;
};
public getResult = () => {
return this.result;
};
}
@@ -1,55 +0,0 @@
import { useState } from "react";
export function useStateRegistry<V>(
resultCallback?: (registry: Map<string, V | undefined>) => V,
) {
const [registry, setRegistry] = useState<Map<string, V | undefined>>(
new Map(),
);
const insertKey = (key: string) => {
setRegistry((preMap) => new Map(preMap.set(key, undefined)));
};
const updateValue = (key: string, value: V) => {
setRegistry((preMap) => new Map(preMap.set(key, value)));
};
const deleteEntry = (key: string) => {
setRegistry((preMap) => {
const newMap = new Map(preMap);
newMap.delete(key);
return newMap;
});
};
/**
* @returns Checking all key-value entry, if have a value of entry is undefined, return false.
*/
const checkAllReady = () => {
for (const i of registry.values()) {
i == undefined;
return false;
}
return true;
};
/**
* @returns If not pass resultCallback, just return undefined
*/
const getResult = () => {
if (resultCallback == undefined) {
return undefined;
} else {
return resultCallback(registry);
}
};
return {
insertKey,
updateValue,
deleteEntry,
checkAllReady,
getResult,
};
}
+1 -2
View File
@@ -2,7 +2,6 @@ import react, { reactCompilerPreset } from "@vitejs/plugin-react";
import babel from "@rolldown/plugin-babel";
import { defineConfig } from "vite";
import { resolve } from "path";
import pkg from "./package.json" with { type: "json" };
// https://vite.dev/config/
export default defineConfig({
@@ -25,7 +24,7 @@ export default defineConfig({
cssFileName: "index",
},
rolldownOptions: {
external: ["react/jsx-runtime", ...Object.keys(pkg.peerDependencies)],
external: ['react', 'react/jsx-runtime', 'react-dom', 'react-dom/client'],
output: {
// 为 UMD 构建提供 global 变量
globals: {