@cdx-ui/用户
共有的公用设施,在财政发展服务包中使用.
提供常见的助手,用于样式、事件处理、状态管理和背景传播 @cdx-ui/primitives 财务报告和审定财务报表 @cdx-ui/components。 。 。 .
安装
pnpm add @cdx-ui/utils
出口
共同帮助者
| 导出 | 说明 |
|---|---|
cn(...inputs) | 合并类名 clsx + 键 tailwind-merge ——有条件条件和冲突解决在一个呼吁中. |
composeEventHandlers(...handlers) | 将多个事件召回到单个处理器中; 跳过 null编号 :undefined 条目. |
useControllableState(params) | 既支持受控模式,又支持无控模式的钩子,用于单一值. 衍生物 isControlled 从道具是否 undefined。 。 。 . |
mergeRefs(...refs) | 将多回调(召回或对象)合并为一回调. |
flattenChildren(children) | 递归平地反应 children (包括分块)入入有重键元素的平面阵列. |
ariaAttr(condition) | 回返 true (布尔)或 undefined ——布尔ARIA属性值的快手. |
cva(base, config) | Class Difficience 管理局用于编写变量驱动的助手 className 建业者. VariantProps<typeof fn> 生成道具类型. |
A. 背景情况
| 导出 | 说明 |
|---|---|
createContext(displayName) | 环绕回放 createContext 返回一个 [Provider, useHook] tu. 如果在提供者之外调用, 钩子会丢入描述性错误 undefined 诸虫. |
样式上下文
内部使用 @cdx-ui/components 用于传播从复合根到子元件的变种道具(大小、颜色等).
| 导出 | 说明 |
|---|---|
ParentContext | 反应上下文,用于将复合根的变体道具传播到子元件. 包装儿童 <ParentContext.Provider value={...}>。 。 。 . |
useStyleContext(scope?) | 读取最近设置的样式背景 ParentContext.Provider。 。 。 . |
useParentContext() | 读取全文 StyleContextMap 从最近的提供者. |
表格控制
低等窗体- 字段状态 Field 财务报告和审定财务报表 Input 原始的 原始的 原始的.
| 导出 | 说明 |
|---|---|
useFormControlRoot(props) | 创建窗体字段( id 生成, 音轨) 的根态对象 hasFeedbackText编号 :hasHelpText 以便你们集合. |
useFormControl(props) | 将组件级道具与继承的形式控制上下文合并. 组合 aria-describedby 从反馈/帮助文本 id. |
useFormControlContext() | 从最近的提供者读取窗体控制状态 . |
useReportFormControlLabelFocus(isActive) | 向父母报告重点/活动状态 FormControlContext 用于 Input编号 :Select.Trigger 触发 isFocused 关联标签上的样式 . |
useReportFormControlValidation(isInvalid, errorMessage) | 报告自动验证控件的无效状态并给父信件 Field 用于 DatePicker 这样 Field.Error 编号 : Field.Helper 在野外的任何地方都反映出来. |
FormControlContext | 形式控制状态传播的反应上下文对象 . |
导出类型
| 类型 | 来源 |
|---|---|
UseControllableStateParams | 常见 |
VariantProps | 常见 |
Focusable | 窗体控件 |
FormControlContextValue | 窗体控件 |
FormControlFieldProps | 窗体控件 |
FormControlRootProps | 窗体控件 |
FormControlRootReturn | 窗体控件 |
FormControlState | 窗体控件 |
FormControlValidation | 窗体控件 |
StyleContextMap | 样式 |
测试
测试在源文件相邻处( E)*.test.{ts,tsx}) (中文(简体) ). 运行在 utils 最佳项目:
pnpm nx run @cdx-ui/utils:test
所有运行时间出口都使用 @testing-library/react-native (单位:千美元)renderHook, (中文(简体) ), act) (中文(简体) ).
进一步阅读
这个 Forge UI 文档站点 盖设及用. 寄存器的内部编写指南涵盖了这些帮助者背后的规律—— useControllableState 财务报告和审定财务报表 composeEventHandlers 在国家指南中 cn() 和 CVA 变体作者在造型指南中.
许可证
麻省理工学院 2026 Digital First Holdings LLC. 包装的许可证全文 LICENSE。 。 。 .