Skip to content

feat: Circle support semantic structure #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defineConfig } from 'dumi';
export default defineConfig({
favicons: ['https://avatars0.githubusercontent.com/u/9441414?s=200&v=4'],
themeConfig: {
name: 'rc-progress',
name: '@rc-component/progress',
logo: 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4',
},
exportStatic: {},
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# rc-progress
# @rc-component/progress

Progress Bar.

[![NPM version][npm-image]][npm-url] [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![Test coverage][coveralls-image]][coveralls-url] [![npm download][download-image]][download-url] [![bundle size][bundlephobia-image]][bundlephobia-url]

[npm-image]: http://img.shields.io/npm/v/rc-progress.svg?style=flat-square
[npm-url]: http://npmjs.org/package/rc-progress
[npm-image]: http://img.shields.io/npm/v/@rc-component/progress.svg?style=flat-square
[npm-url]: http://npmjs.org/package/@rc-component/progress
[github-actions-image]: https://github.com/react-component/progress/workflows/CI/badge.svg
[github-actions-url]: https://github.com/react-component/progress/actions
[circleci-image]: https://img.shields.io/circleci/react-component/progress/master?style=flat-square
Expand All @@ -16,10 +16,10 @@ Progress Bar.
[david-image]: https://david-dm.org/react-component/progress/status.svg?style=flat-square
[david-dev-url]: https://david-dm.org/react-component/progress?type=dev
[david-dev-image]: https://david-dm.org/react-component/progress/dev-status.svg?style=flat-square
[download-image]: https://img.shields.io/npm/dm/rc-progress.svg?style=flat-square
[download-url]: https://npmjs.org/package/rc-progress
[bundlephobia-url]: https://bundlephobia.com/result?p=rc-progress
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-progress
[download-image]: https://img.shields.io/npm/dm/@rc-component/progress.svg?style=flat-square
[download-url]: https://npmjs.org/package/@rc-component/progress
[bundlephobia-url]: https://bundlephobia.com/result?p=@rc-component/progress
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/progress

## Example

Expand All @@ -35,12 +35,12 @@ https://progress.react-component.vercel.app/

## Install

[![rc-progress](https://nodei.co/npm/rc-progress.png)](https://npmjs.org/package/rc-progress)
[![@rc-component/progress](https://nodei.co/npm/@rc-component/progress.png)](https://npmjs.org/package/@rc-component/progress)

## Usage

```js
import { Line, Circle } from 'rc-progress';
import { Line, Circle } from '@rc-component/progress';

export default () => (
<>
Expand Down Expand Up @@ -148,7 +148,7 @@ export default () => (
## Installation

```
npm install --save rc-progress
npm install --save @rc-component/progress
```

## Development
Expand All @@ -160,4 +160,4 @@ npm start

## License

rc-progress is released under the MIT license.
@rc-component/progress is released under the MIT license.
4 changes: 2 additions & 2 deletions docs/examples/fast-progress.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Line, Circle } from 'rc-progress';
import type { ProgressProps } from 'rc-progress';
import { Line, Circle } from '@rc-component/progress';
import type { ProgressProps } from '@rc-component/progress';

class App extends React.Component<ProgressProps, any> {
constructor(props: ProgressProps) {
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/gap.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Circle } from 'rc-progress';
import type { ProgressProps } from 'rc-progress';
import { Circle } from '@rc-component/progress';
import type { ProgressProps } from '@rc-component/progress';

const colorMap = ['#3FC7FA', '#85D262', '#FE8C6A', '#FF5959', '#BC3FFA'];

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/gradient-circle.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Circle } from 'rc-progress';
import { Circle } from '@rc-component/progress';

const circleContainerStyle: React.CSSProperties = {
width: 250,
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/loading.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Line, Circle } from 'rc-progress';
import { Line, Circle } from '@rc-component/progress';

const Loading = () => {
return (
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/simple.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Line, Circle } from 'rc-progress';
import type { ProgressProps } from 'rc-progress';
import { Line, Circle } from '@rc-component/progress';
import type { ProgressProps } from '@rc-component/progress';

class Example extends React.Component<ProgressProps, any> {
constructor(props: ProgressProps) {
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/steps.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { Circle } from 'rc-progress';
import { Circle } from '@rc-component/progress';

const Example: React.FC = () => {
const [percent, setPercent] = useState<number>(30);
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
hero:
title: rc-progress
title: '@rc-component/progress'
description: React Progress Component
---

Expand Down
2 changes: 1 addition & 1 deletion now.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": 2,
"name": "rc-progress",
"name": "@rc-component/progress",
"builds": [
{
"src": "package.json",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-progress",
"version": "4.0.0",
"name": "@rc-component/progress",
"version": "1.0.0",
"description": "progress ui component for react",
"keywords": [
"react",
Expand Down
5 changes: 4 additions & 1 deletion src/Circle/PtgCircle.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import type { ProgressProps } from '..';
import type { StrokeColorObject } from '../interface';
import classNames from 'classnames';

interface BlockProps {
bg: string;
Expand All @@ -22,6 +23,7 @@ function getPtgColors(color: Record<string, string | boolean>, scale: number) {

export interface ColorGradientProps {
prefixCls: string;
className?: string;
gradientId: string;
style: React.CSSProperties;
ptg: number;
Expand All @@ -39,6 +41,7 @@ const PtgCircle = React.forwardRef<SVGCircleElement, ColorGradientProps>((props,
color,
gradientId,
radius,
className,
style: circleStyleForStack,
ptg,
strokeLinecap,
Expand All @@ -56,7 +59,7 @@ const PtgCircle = React.forwardRef<SVGCircleElement, ColorGradientProps>((props,

const circleNode = (
<circle
className={`${prefixCls}-circle-path`}
className={classNames(`${prefixCls}-circle-path`, className)}
r={radius}
cx={halfSize}
cy={halfSize}
Expand Down
27 changes: 18 additions & 9 deletions src/Circle/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react';
import classNames from 'classnames';
import cls from 'classnames';
import { defaultProps, useTransitionDuration } from '../common';
import type { ProgressProps } from '../interface';
import useId from '../hooks/useId';
import useId from '@rc-component/util/lib/hooks/useId';
import PtgCircle from './PtgCircle';
import { VIEW_BOX_SIZE, getCircleStyle } from './util';
import getIndeterminateCircle from '../utils/getIndeterminateCircle';
Expand All @@ -16,6 +16,8 @@ const Circle: React.FC<ProgressProps> = (props) => {
const {
id,
prefixCls,
classNames = {},
styles = {},
steps,
strokeWidth,
trailWidth,
Expand Down Expand Up @@ -100,7 +102,8 @@ const Circle: React.FC<ProgressProps> = (props) => {
radius={radius}
prefixCls={prefixCls}
gradientId={gradientId}
style={{ ...circleStyleForStack, ...indeterminateStyleProps }}
className={classNames.track}
style={{ ...circleStyleForStack, ...indeterminateStyleProps, ...styles.track }}
strokeLinecap={mergedStrokeLinecap}
strokeWidth={strokeWidth}
gapDegree={gapDegree}
Expand Down Expand Up @@ -148,14 +151,14 @@ const Circle: React.FC<ProgressProps> = (props) => {
return (
<circle
key={index}
className={`${prefixCls}-circle-path`}
className={cls(`${prefixCls}-circle-path`, classNames.track)}
r={radius}
cx={halfSize}
cy={halfSize}
stroke={stroke}
strokeWidth={strokeWidth}
opacity={1}
style={circleStyleForStack}
style={{ ...circleStyleForStack, ...styles.track }}
ref={(elem) => {
paths[index] = elem;
}}
Expand All @@ -166,23 +169,29 @@ const Circle: React.FC<ProgressProps> = (props) => {

return (
<svg
className={classNames(`${prefixCls}-circle`, className)}
className={cls(`${prefixCls}-circle`, classNames.root, className)}
viewBox={`0 0 ${VIEW_BOX_SIZE} ${VIEW_BOX_SIZE}`}
style={style}
style={{
...styles.root,
...style,
}}
id={id}
role="presentation"
{...restProps}
>
{!stepCount && (
<circle
className={`${prefixCls}-circle-trail`}
className={cls(`${prefixCls}-circle-trail`, classNames.rail)}
r={radius}
cx={halfSize}
cy={halfSize}
stroke={trailColor}
strokeLinecap={mergedStrokeLinecap}
strokeWidth={trailWidth || strokeWidth}
style={circleStyle}
style={{
...circleStyle,
...styles.rail,
}}
/>
)}
{stepCount ? getStepStokeList() : getStokeList()}
Expand Down
2 changes: 1 addition & 1 deletion src/Line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import classNames from 'classnames';
import { useTransitionDuration, defaultProps } from './common';
import type { ProgressProps } from './interface';
import getIndeterminateLine from './utils/getIndeterminateLine';
import useId from './hooks/useId';
import useId from '@rc-component/util/lib/hooks/useId';

const Line: React.FC<ProgressProps> = (props) => {
const {
Expand Down
32 changes: 0 additions & 32 deletions src/hooks/useId.ts

This file was deleted.

4 changes: 4 additions & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
export type SemanticName = 'root' | 'rail' | 'track';

export interface ProgressProps {
id?: string;
strokeWidth?: number;
trailWidth?: number;
className?: string;
classNames?: Partial<Record<SemanticName, string>>;
styles?: Partial<Record<SemanticName, React.CSSProperties>>;
percent?: number | number[];
strokeColor?: StrokeColorType;
trailColor?: string;
Expand Down
12 changes: 6 additions & 6 deletions tests/__snapshots__/conic.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ exports[`Circle.conic gapDegree 1`] = `
style="stroke: #D9D9D9; stroke-dasharray: 237.88837704682715px 295.3097094374406; stroke-dashoffset: 0; transform: rotate(125deg); transform-origin: 50px 50px; transition: stroke-dashoffset .3s ease 0s, stroke-dasharray .3s ease 0s, stroke .3s, stroke-width .06s ease .3s, opacity .3s ease 0s; fill-opacity: 0;"
/>
<mask
id="rc_progress_TEST_OR_SSR-gradient-conic"
id="test-id-gradient-conic"
>
<circle
class="rc-progress-circle-path"
Expand All @@ -29,12 +29,12 @@ exports[`Circle.conic gapDegree 1`] = `
stroke="#FFF"
stroke-linecap="butt"
stroke-width="6"
style="stroke-dasharray: 237.88837704682715px 295.3097094374406; stroke-dashoffset: 0; transform: rotate(125deg); transform-origin: 50px 50px; transition: stroke-dashoffset .3s ease 0s, stroke-dasharray .3s ease 0s, stroke .3s, stroke-width .06s ease .3s, opacity .3s ease 0s; fill-opacity: 0; transition-duration: 0s, 0s;"
style="stroke-dasharray: 237.88837704682715px 295.3097094374406; stroke-dashoffset: 0; transform: rotate(125deg); transform-origin: 50px 50px; transition: stroke-dashoffset .3s ease 0s, stroke-dasharray .3s ease 0s, stroke .3s, stroke-width .06s ease .3s, opacity .3s ease 0s; fill-opacity: 0; transition-duration: .3s, .3s, .3s, .06s;"
/>
</mask>
<foreignobject
height="100"
mask="url(#rc_progress_TEST_OR_SSR-gradient-conic)"
mask="url(#test-id-gradient-conic)"
width="100"
x="0"
y="0"
Expand Down Expand Up @@ -69,7 +69,7 @@ exports[`Circle.conic should work 1`] = `
style="stroke: #D9D9D9; stroke-dasharray: 295.3097094374406px 295.3097094374406; stroke-dashoffset: 0; transform: rotate(-90deg); transform-origin: 50px 50px; transition: stroke-dashoffset .3s ease 0s, stroke-dasharray .3s ease 0s, stroke .3s, stroke-width .06s ease .3s, opacity .3s ease 0s; fill-opacity: 0;"
/>
<mask
id="rc_progress_TEST_OR_SSR-gradient-conic"
id="test-id-gradient-conic"
>
<circle
class="rc-progress-circle-path"
Expand All @@ -80,12 +80,12 @@ exports[`Circle.conic should work 1`] = `
stroke="#FFF"
stroke-linecap="butt"
stroke-width="6"
style="stroke-dasharray: 295.3097094374406px 295.3097094374406; stroke-dashoffset: 0; transform: rotate(-90deg); transform-origin: 50px 50px; transition: stroke-dashoffset .3s ease 0s, stroke-dasharray .3s ease 0s, stroke .3s, stroke-width .06s ease .3s, opacity .3s ease 0s; fill-opacity: 0; transition-duration: 0s, 0s;"
style="stroke-dasharray: 295.3097094374406px 295.3097094374406; stroke-dashoffset: 0; transform: rotate(-90deg); transform-origin: 50px 50px; transition: stroke-dashoffset .3s ease 0s, stroke-dasharray .3s ease 0s, stroke .3s, stroke-width .06s ease .3s, opacity .3s ease 0s; fill-opacity: 0; transition-duration: .3s, .3s, .3s, .06s;"
/>
</mask>
<foreignobject
height="100"
mask="url(#rc_progress_TEST_OR_SSR-gradient-conic)"
mask="url(#test-id-gradient-conic)"
width="100"
x="0"
y="0"
Expand Down
Loading