chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
60158935f4
commit
6519682885
15831 files changed
+3063428
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { render } from 'vitest-browser-react'
|
||||
import { ProgressCircle } from '../index'
|
||||
|
||||
describe('ProgressCircle', () => {
|
||||
it('exposes progressbar semantics through Base UI Progress', async () => {
|
||||
const screen = await render(<ProgressCircle value={40} aria-label="Uploading" />)
|
||||
|
||||
const progress = screen.getByLabelText('Uploading')
|
||||
|
||||
await expect.element(progress).toHaveAttribute('role', 'progressbar')
|
||||
await expect.element(progress).toHaveAttribute('aria-valuemin', '0')
|
||||
await expect.element(progress).toHaveAttribute('aria-valuemax', '100')
|
||||
await expect.element(progress).toHaveAttribute('aria-valuenow', '40')
|
||||
})
|
||||
|
||||
it('supports custom min and max', async () => {
|
||||
const screen = await render(
|
||||
<ProgressCircle value={3} min={1} max={5} aria-label="Installing" />,
|
||||
)
|
||||
|
||||
const progress = screen.getByLabelText('Installing')
|
||||
|
||||
await expect.element(progress).toHaveAttribute('aria-valuemin', '1')
|
||||
await expect.element(progress).toHaveAttribute('aria-valuemax', '5')
|
||||
await expect.element(progress).toHaveAttribute('aria-valuenow', '3')
|
||||
})
|
||||
|
||||
it('renders indeterminate state when value is null', async () => {
|
||||
const screen = await render(<ProgressCircle value={null} aria-label="Processing" />)
|
||||
const progress = screen.getByLabelText('Processing')
|
||||
|
||||
await expect.element(progress).toHaveAttribute('role', 'progressbar')
|
||||
await expect.element(progress).toHaveAttribute('data-indeterminate')
|
||||
await expect.element(progress).not.toHaveAttribute('aria-valuenow')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,78 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite'
|
||||
import type { ProgressCircleProps } from '.'
|
||||
import * as React from 'react'
|
||||
import { ProgressCircle } from '.'
|
||||
|
||||
type ProgressCircleColor = NonNullable<ProgressCircleProps['color']>
|
||||
type ProgressCircleSize = NonNullable<ProgressCircleProps['size']>
|
||||
|
||||
const colors: ProgressCircleColor[] = ['gray', 'white', 'blue', 'warning', 'error']
|
||||
const sizes: ProgressCircleSize[] = ['small', 'medium', 'large']
|
||||
|
||||
const meta = {
|
||||
title: 'Base/UI/Progress',
|
||||
component: ProgressCircle,
|
||||
parameters: {
|
||||
layout: 'centered',
|
||||
docs: {
|
||||
description: {
|
||||
component:
|
||||
'Task progress primitives. ProgressCircle matches the Dify Design Kit circular Progress component and uses Base UI Progress semantics.',
|
||||
},
|
||||
},
|
||||
},
|
||||
tags: ['autodocs'],
|
||||
} satisfies Meta<typeof ProgressCircle>
|
||||
|
||||
export default meta
|
||||
|
||||
type Story = StoryObj<typeof meta>
|
||||
|
||||
export const Circle: Story = {
|
||||
args: {
|
||||
value: 42,
|
||||
color: 'blue',
|
||||
size: 'small',
|
||||
'aria-label': 'Uploading',
|
||||
},
|
||||
}
|
||||
|
||||
export const CircleMatrix: Story = {
|
||||
args: {
|
||||
value: 62,
|
||||
'aria-label': 'Progress',
|
||||
},
|
||||
render: () => (
|
||||
<div className="grid grid-cols-[auto_auto_auto_auto] items-center gap-4 rounded-lg bg-components-panel-bg p-4">
|
||||
<div />
|
||||
{sizes.map((size) => (
|
||||
<div key={size} className="system-xs-medium text-text-tertiary">
|
||||
{size}
|
||||
</div>
|
||||
))}
|
||||
{colors.map((color) => (
|
||||
<React.Fragment key={color}>
|
||||
<div className="system-xs-semibold-uppercase text-text-secondary">{color}</div>
|
||||
{sizes.map((size) => (
|
||||
<ProgressCircle
|
||||
key={`${color}-${size}`}
|
||||
value={62}
|
||||
color={color}
|
||||
size={size}
|
||||
aria-label={`${color} ${size} progress`}
|
||||
/>
|
||||
))}
|
||||
</React.Fragment>
|
||||
))}
|
||||
</div>
|
||||
),
|
||||
}
|
||||
|
||||
export const Indeterminate: Story = {
|
||||
args: {
|
||||
value: null,
|
||||
color: 'gray',
|
||||
size: 'medium',
|
||||
'aria-label': 'Processing',
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
'use client'
|
||||
|
||||
import type { VariantProps } from 'class-variance-authority'
|
||||
import { Progress as BaseProgress } from '@base-ui/react/progress'
|
||||
import { cva } from 'class-variance-authority'
|
||||
import { cn } from '../cn'
|
||||
import { resolveClassName } from '../internal/resolve-class-name'
|
||||
|
||||
const progressCircleRootVariants = cva('inline-flex shrink-0 items-center justify-center', {
|
||||
variants: {
|
||||
size: {
|
||||
small: 'size-3',
|
||||
medium: 'size-4',
|
||||
large: 'size-5',
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
size: 'small',
|
||||
},
|
||||
})
|
||||
|
||||
const progressCircleColorClasses = {
|
||||
gray: {
|
||||
stroke: 'stroke-components-progress-gray-border',
|
||||
fill: 'fill-components-progress-gray-bg',
|
||||
sector: 'fill-components-progress-gray-progress',
|
||||
},
|
||||
white: {
|
||||
stroke: 'stroke-components-progress-white-border',
|
||||
fill: 'fill-components-progress-white-bg',
|
||||
sector: 'fill-components-progress-white-progress',
|
||||
},
|
||||
blue: {
|
||||
stroke: 'stroke-components-progress-brand-border',
|
||||
fill: 'fill-components-progress-brand-bg',
|
||||
sector: 'fill-components-progress-brand-progress',
|
||||
},
|
||||
warning: {
|
||||
stroke: 'stroke-components-progress-warning-border',
|
||||
fill: 'fill-components-progress-warning-bg',
|
||||
sector: 'fill-components-progress-warning-progress',
|
||||
},
|
||||
error: {
|
||||
stroke: 'stroke-components-progress-error-border',
|
||||
fill: 'fill-components-progress-error-bg',
|
||||
sector: 'fill-components-progress-error-progress',
|
||||
},
|
||||
} as const
|
||||
|
||||
type ProgressCircleSize = NonNullable<VariantProps<typeof progressCircleRootVariants>['size']>
|
||||
type ProgressCircleColor = keyof typeof progressCircleColorClasses
|
||||
|
||||
const progressCircleSizeValues = {
|
||||
small: 12,
|
||||
medium: 16,
|
||||
large: 20,
|
||||
} as const satisfies Record<ProgressCircleSize, number>
|
||||
|
||||
type ProgressCircleAccessibleNameProps =
|
||||
| {
|
||||
'aria-label': string
|
||||
'aria-labelledby'?: never
|
||||
}
|
||||
| {
|
||||
'aria-label'?: never
|
||||
'aria-labelledby': string
|
||||
}
|
||||
|
||||
type ProgressCircleProps = Omit<
|
||||
BaseProgress.Root.Props,
|
||||
'children' | 'aria-label' | 'aria-labelledby'
|
||||
> &
|
||||
ProgressCircleAccessibleNameProps & {
|
||||
color?: ProgressCircleColor
|
||||
size?: ProgressCircleSize
|
||||
circleStrokeWidth?: number
|
||||
}
|
||||
|
||||
function getProgressPercentage(value: number | null, min: number, max: number) {
|
||||
if (value === null || !Number.isFinite(value) || max <= min) return null
|
||||
|
||||
return Math.min(100, Math.max(0, ((value - min) / (max - min)) * 100))
|
||||
}
|
||||
|
||||
function getSectorPath(size: number, percentage: number | null) {
|
||||
if (percentage === null || percentage <= 0) return ''
|
||||
|
||||
const radius = size / 2
|
||||
const center = size / 2
|
||||
|
||||
if (percentage >= 100) {
|
||||
return `
|
||||
M ${center},${center - radius}
|
||||
A ${radius},${radius} 0 1 1 ${center},${center + radius}
|
||||
A ${radius},${radius} 0 1 1 ${center},${center - radius}
|
||||
Z
|
||||
`
|
||||
}
|
||||
|
||||
const angle = (percentage / 100) * 360
|
||||
const radians = (angle * Math.PI) / 180
|
||||
const x = center + radius * Math.cos(radians - Math.PI / 2)
|
||||
const y = center + radius * Math.sin(radians - Math.PI / 2)
|
||||
const largeArcFlag = percentage > 50 ? 1 : 0
|
||||
|
||||
return `
|
||||
M ${center},${center}
|
||||
L ${center},${center - radius}
|
||||
A ${radius},${radius} 0 ${largeArcFlag} 1 ${x},${y}
|
||||
Z
|
||||
`
|
||||
}
|
||||
|
||||
function ProgressCircle({
|
||||
className,
|
||||
color = 'blue',
|
||||
size = 'small',
|
||||
circleStrokeWidth = 1,
|
||||
value,
|
||||
min = 0,
|
||||
max = 100,
|
||||
...props
|
||||
}: ProgressCircleProps) {
|
||||
const numericSize = progressCircleSizeValues[size]
|
||||
const percentage = getProgressPercentage(value, min, max)
|
||||
const radius = numericSize / 2
|
||||
const center = numericSize / 2
|
||||
const pathData = getSectorPath(numericSize, percentage)
|
||||
const colors = progressCircleColorClasses[color]
|
||||
|
||||
return (
|
||||
<BaseProgress.Root
|
||||
className={(state) =>
|
||||
cn(progressCircleRootVariants({ size }), resolveClassName(className, state))
|
||||
}
|
||||
value={value}
|
||||
min={min}
|
||||
max={max}
|
||||
{...props}
|
||||
>
|
||||
<svg
|
||||
width={numericSize + circleStrokeWidth}
|
||||
height={numericSize + circleStrokeWidth}
|
||||
viewBox={`0 0 ${numericSize + circleStrokeWidth} ${numericSize + circleStrokeWidth}`}
|
||||
aria-hidden="true"
|
||||
className="block"
|
||||
>
|
||||
<circle
|
||||
className={cn(colors.fill, colors.stroke)}
|
||||
cx={center + circleStrokeWidth / 2}
|
||||
cy={center + circleStrokeWidth / 2}
|
||||
r={radius}
|
||||
strokeWidth={circleStrokeWidth}
|
||||
/>
|
||||
{pathData && (
|
||||
<path
|
||||
className={colors.sector}
|
||||
d={pathData}
|
||||
transform={`translate(${circleStrokeWidth / 2}, ${circleStrokeWidth / 2})`}
|
||||
/>
|
||||
)}
|
||||
</svg>
|
||||
</BaseProgress.Root>
|
||||
)
|
||||
}
|
||||
|
||||
export { ProgressCircle }
|
||||
export type { ProgressCircleProps }
|
||||
Reference in new issue
Block a user