Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

refactor(dify-ui): narrow checkbox public API (#42953)

yyh698ecd3e6244
diff --git a/packages/dify-ui/docs/authoring.md b/packages/dify-ui/docs/authoring.md
index a361ee118f7..2cdda20303e 100644
--- a/packages/dify-ui/docs/authoring.md
+++ b/packages/dify-ui/docs/authoring.md
@@ -20,8 +20,8 @@ package components; consumers import only through public subpaths.
Use the primitive name without a `Root` suffix for the canonical boundary and matching props type:
`Select` and `SelectProps`, `Drawer` and `DrawerProps`. Keep `Root` only when the same subpath
-exports both low-level anatomy and a higher-level convenience component, such as `CheckboxRoot`
-and `Checkbox`.
+exports both low-level anatomy and a higher-level convenience component, such as `AvatarRoot`
+and `Avatar`.
Every runtime component must have an accurate, importable props type with the matching name. Use a
direct alias for an unchanged Base UI part. Define Dify-authored composite props at the Dify UI
diff --git a/packages/dify-ui/src/checkbox-group/index.tsx b/packages/dify-ui/src/checkbox-group/index.tsx
index 45204d36030..a080d0b1788 100644
--- a/packages/dify-ui/src/checkbox-group/index.tsx
+++ b/packages/dify-ui/src/checkbox-group/index.tsx
@@ -4,10 +4,7 @@ import type { CheckboxGroup as BaseCheckboxGroupNS } from '@base-ui/react/checkb
import { CheckboxGroup as BaseCheckboxGroup } from '@base-ui/react/checkbox-group'
type CheckboxGroupProps = BaseCheckboxGroupNS.Props
-
-function CheckboxGroup(props: CheckboxGroupProps) {
- return <BaseCheckboxGroup {...props} />
-}
+const CheckboxGroup = BaseCheckboxGroup
export { CheckboxGroup }
diff --git a/packages/dify-ui/src/checkbox/__tests__/index.spec.tsx b/packages/dify-ui/src/checkbox/__tests__/index.spec.tsx
index f96abb09b82..7c4fc8bb123 100644
--- a/packages/dify-ui/src/checkbox/__tests__/index.spec.tsx
+++ b/packages/dify-ui/src/checkbox/__tests__/index.spec.tsx
@@ -1,5 +1,5 @@
import { render } from 'vitest-browser-react'
-import { Checkbox, CheckboxIndicator, CheckboxRoot, CheckboxSkeleton } from '../index'
+import { Checkbox, CheckboxSkeleton } from '../index'
describe('Checkbox', () => {
it('should render an unchecked checkbox with Base UI semantics', async () => {
@@ -92,19 +92,6 @@ describe('Checkbox', () => {
expect(data.get('terms')).toBe('accepted')
expect(data.get('newsletter')).toBe('no')
})
-
- it('should support custom compound composition with CheckboxRoot and CheckboxIndicator', async () => {
- const screen = await render(
- <CheckboxRoot checked aria-label="Custom checkbox" className="custom-root">
- <CheckboxIndicator className="custom-indicator" />
- </CheckboxRoot>,
- )
-
- await expect
- .element(screen.getByRole('checkbox', { name: 'Custom checkbox' }))
- .toHaveClass('custom-root')
- expect(screen.container.querySelector('.custom-indicator')).toBeInTheDocument()
- })
})
describe('CheckboxSkeleton', () => {
diff --git a/packages/dify-ui/src/checkbox/index.tsx b/packages/dify-ui/src/checkbox/index.tsx
index 93fcab52f42..e724ec8443e 100644
--- a/packages/dify-ui/src/checkbox/index.tsx
+++ b/packages/dify-ui/src/checkbox/index.tsx
@@ -26,24 +26,17 @@ const checkboxIndicatorClassName =
const checkboxSkeletonClassName = 'size-4 shrink-0 rounded-sm bg-text-quaternary opacity-20'
-type CheckboxRootProps = BaseCheckboxNS.Root.Props
-function CheckboxRoot({ className, ...props }: CheckboxRootProps) {
+type CheckboxProps = Omit<BaseCheckboxNS.Root.Props, 'children'>
+
+function Checkbox({ className, ...props }: CheckboxProps) {
return (
<BaseCheckbox.Root
className={(state) => cn(checkboxRootClassName, resolveClassName(className, state))}
{...props}
- />
- )
-}
-
-type CheckboxIndicatorProps = Omit<BaseCheckboxNS.Indicator.Props, 'children'>
-function CheckboxIndicator({ className, render, ...props }: CheckboxIndicatorProps) {
- return (
- <BaseCheckbox.Indicator
- className={(state) => cn(checkboxIndicatorClassName, resolveClassName(className, state))}
- render={
- render ??
- ((indicatorProps, state) => (
+ >
+ <BaseCheckbox.Indicator
+ className={checkboxIndicatorClassName}
+ render={(indicatorProps, state) => (
<span {...indicatorProps}>
{state.indeterminate ? (
<span className="block h-[1.5px] w-1.75 rounded-full bg-current" />
@@ -51,20 +44,9 @@ function CheckboxIndicator({ className, render, ...props }: CheckboxIndicatorPro
<span className="i-ri-check-line block size-3 shrink-0" />
)}
</span>
- ))
- }
- {...props}
- />
- )
-}
-
-type CheckboxProps = Omit<CheckboxRootProps, 'children'>
-
-function Checkbox({ ...props }: CheckboxProps) {
- return (
- <CheckboxRoot {...props}>
- <CheckboxIndicator />
- </CheckboxRoot>
+ )}
+ />
+ </BaseCheckbox.Root>
)
}
@@ -76,6 +58,6 @@ function CheckboxSkeleton({ className, ...props }: CheckboxSkeletonProps) {
return <div className={cn(checkboxSkeletonClassName, className)} {...props} />
}
-export { Checkbox, CheckboxIndicator, CheckboxRoot, CheckboxSkeleton }
+export { Checkbox, CheckboxSkeleton }
-export type { CheckboxIndicatorProps, CheckboxProps, CheckboxRootProps, CheckboxSkeletonProps }
+export type { CheckboxProps, CheckboxSkeletonProps }