@sproutsocial/seeds-react-progress 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +6 -0
- package/.eslintrc.js +4 -0
- package/.turbo/turbo-build.log +21 -0
- package/CHANGELOG.md +7 -0
- package/dist/esm/index.js +68 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +25 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +105 -0
- package/dist/index.js.map +1 -0
- package/jest.config.js +9 -0
- package/package.json +43 -0
- package/src/Progress.stories.tsx +83 -0
- package/src/Progress.tsx +30 -0
- package/src/ProgressTypes.ts +23 -0
- package/src/__tests__/Progress.test.tsx +120 -0
- package/src/__tests__/Progress.typetest.tsx +32 -0
- package/src/index.ts +5 -0
- package/src/styled.d.ts +7 -0
- package/src/styles.ts +24 -0
- package/tsconfig.json +15 -0
- package/tsup.config.ts +12 -0
package/.eslintignore
ADDED
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
yarn run v1.22.22
|
|
2
|
+
$ tsup --dts
|
|
3
|
+
[34mCLI[39m Building entry: src/index.ts
|
|
4
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
5
|
+
[34mCLI[39m tsup v8.5.0
|
|
6
|
+
[34mCLI[39m Using tsup config: /home/runner/_work/seeds/seeds/seeds-react/seeds-react-progress/tsup.config.ts
|
|
7
|
+
[34mCLI[39m Target: es2022
|
|
8
|
+
[34mCLI[39m Cleaning output folder
|
|
9
|
+
[34mCJS[39m Build start
|
|
10
|
+
[34mESM[39m Build start
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m3.27 KB[39m
|
|
12
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m3.51 KB[39m
|
|
13
|
+
[32mCJS[39m ⚡️ Build success in 14ms
|
|
14
|
+
[32mESM[39m [1mdist/esm/index.js [22m[32m1.46 KB[39m
|
|
15
|
+
[32mESM[39m [1mdist/esm/index.js.map [22m[32m3.41 KB[39m
|
|
16
|
+
[32mESM[39m ⚡️ Build success in 14ms
|
|
17
|
+
[34mDTS[39m Build start
|
|
18
|
+
[32mDTS[39m ⚡️ Build success in 3861ms
|
|
19
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m1.11 KB[39m
|
|
20
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m1.11 KB[39m
|
|
21
|
+
Done in 4.84s.
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// src/Progress.tsx
|
|
2
|
+
import "react";
|
|
3
|
+
|
|
4
|
+
// src/styles.ts
|
|
5
|
+
import styled from "styled-components";
|
|
6
|
+
import * as Progress from "@radix-ui/react-progress";
|
|
7
|
+
import { COMMON } from "@sproutsocial/seeds-react-system-props";
|
|
8
|
+
var StyledRoot = styled(Progress.Root).attrs({
|
|
9
|
+
className: "Progress"
|
|
10
|
+
})`
|
|
11
|
+
position: relative;
|
|
12
|
+
overflow: hidden;
|
|
13
|
+
width: 100%;
|
|
14
|
+
height: 8px;
|
|
15
|
+
border-radius: ${(p) => p.theme.radii.outer};
|
|
16
|
+
background-color: ${(p) => p.theme.colors.container.border.base};
|
|
17
|
+
|
|
18
|
+
${COMMON}
|
|
19
|
+
`;
|
|
20
|
+
var StyledIndicator = styled(Progress.Indicator)`
|
|
21
|
+
height: 100%;
|
|
22
|
+
width: 100%;
|
|
23
|
+
border-radius: ${(p) => p.theme.radii.outer};
|
|
24
|
+
background-color: ${(p) => p.theme.colors.icon.base};
|
|
25
|
+
transition: transform 150ms ease;
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
// src/Progress.tsx
|
|
29
|
+
import { jsx } from "react/jsx-runtime";
|
|
30
|
+
var Progress2 = ({
|
|
31
|
+
value,
|
|
32
|
+
max = 100,
|
|
33
|
+
getValueLabel,
|
|
34
|
+
indicatorStyle,
|
|
35
|
+
...rest
|
|
36
|
+
}) => {
|
|
37
|
+
const percentage = max > 0 ? Math.min(value / max * 100, 100) : 0;
|
|
38
|
+
return /* @__PURE__ */ jsx(
|
|
39
|
+
StyledRoot,
|
|
40
|
+
{
|
|
41
|
+
value,
|
|
42
|
+
max,
|
|
43
|
+
getValueLabel,
|
|
44
|
+
"data-qa-progress": "",
|
|
45
|
+
...rest,
|
|
46
|
+
children: /* @__PURE__ */ jsx(
|
|
47
|
+
StyledIndicator,
|
|
48
|
+
{
|
|
49
|
+
style: {
|
|
50
|
+
transform: `translateX(-${100 - percentage}%)`,
|
|
51
|
+
...indicatorStyle
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// src/ProgressTypes.ts
|
|
60
|
+
import "react";
|
|
61
|
+
|
|
62
|
+
// src/index.ts
|
|
63
|
+
var index_default = Progress2;
|
|
64
|
+
export {
|
|
65
|
+
Progress2 as Progress,
|
|
66
|
+
index_default as default
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Progress.tsx","../../src/styles.ts","../../src/ProgressTypes.ts","../../src/index.ts"],"sourcesContent":["import * as React from \"react\";\nimport { StyledRoot, StyledIndicator } from \"./styles\";\nimport type { TypeProgressProps } from \"./ProgressTypes\";\n\nexport const Progress = ({\n value,\n max = 100,\n getValueLabel,\n indicatorStyle,\n ...rest\n}: TypeProgressProps) => {\n const percentage = max > 0 ? Math.min((value / max) * 100, 100) : 0;\n\n return (\n <StyledRoot\n value={value}\n max={max}\n getValueLabel={getValueLabel}\n data-qa-progress=\"\"\n {...rest}\n >\n <StyledIndicator\n style={{\n transform: `translateX(-${100 - percentage}%)`,\n ...indicatorStyle,\n }}\n />\n </StyledRoot>\n );\n};\n","import styled from \"styled-components\";\nimport * as Progress from \"@radix-ui/react-progress\";\nimport { COMMON } from \"@sproutsocial/seeds-react-system-props\";\n\nexport const StyledRoot = styled(Progress.Root).attrs({\n className: \"Progress\",\n})`\n position: relative;\n overflow: hidden;\n width: 100%;\n height: 8px;\n border-radius: ${(p) => p.theme.radii.outer};\n background-color: ${(p) => p.theme.colors.container.border.base};\n\n ${COMMON}\n`;\n\nexport const StyledIndicator = styled(Progress.Indicator)`\n height: 100%;\n width: 100%;\n border-radius: ${(p) => p.theme.radii.outer};\n background-color: ${(p) => p.theme.colors.icon.base};\n transition: transform 150ms ease;\n`;\n","import * as React from \"react\";\nimport type {\n TypeStyledComponentsCommonProps,\n TypeSystemCommonProps,\n} from \"@sproutsocial/seeds-react-system-props\";\n\ntype TypeAriaLabel =\n | { \"aria-label\": string; \"aria-labelledby\"?: string }\n | { \"aria-label\"?: string; \"aria-labelledby\": string };\n\nexport type TypeProgressProps = TypeStyledComponentsCommonProps &\n TypeSystemCommonProps &\n Omit<React.ComponentPropsWithoutRef<\"div\">, \"color\"> &\n TypeAriaLabel & {\n /** The current progress value */\n value: number;\n /** The maximum progress value. Defaults to 100 */\n max?: number;\n /** A function to get the accessible label text representing the current value. Defaults to \"{value}%\" */\n getValueLabel?: (value: number, max: number) => string;\n /** Custom CSS for the indicator (fill) element, e.g. a gradient background */\n indicatorStyle?: React.CSSProperties;\n };\n","import { Progress } from \"./Progress\";\n\nexport default Progress;\nexport { Progress };\nexport * from \"./ProgressTypes\";\n"],"mappings":";AAAA,OAAuB;;;ACAvB,OAAO,YAAY;AACnB,YAAY,cAAc;AAC1B,SAAS,cAAc;AAEhB,IAAM,aAAa,OAAgB,aAAI,EAAE,MAAM;AAAA,EACpD,WAAW;AACb,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,mBAKkB,CAAC,MAAM,EAAE,MAAM,MAAM,KAAK;AAAA,sBACvB,CAAC,MAAM,EAAE,MAAM,OAAO,UAAU,OAAO,IAAI;AAAA;AAAA,IAE7D,MAAM;AAAA;AAGH,IAAM,kBAAkB,OAAgB,kBAAS;AAAA;AAAA;AAAA,mBAGrC,CAAC,MAAM,EAAE,MAAM,MAAM,KAAK;AAAA,sBACvB,CAAC,MAAM,EAAE,MAAM,OAAO,KAAK,IAAI;AAAA;AAAA;;;ADA/C;AAjBC,IAAMA,YAAW,CAAC;AAAA,EACvB;AAAA,EACA,MAAM;AAAA,EACN;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAyB;AACvB,QAAM,aAAa,MAAM,IAAI,KAAK,IAAK,QAAQ,MAAO,KAAK,GAAG,IAAI;AAElE,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA,oBAAiB;AAAA,MAChB,GAAG;AAAA,MAEJ;AAAA,QAAC;AAAA;AAAA,UACC,OAAO;AAAA,YACL,WAAW,eAAe,MAAM,UAAU;AAAA,YAC1C,GAAG;AAAA,UACL;AAAA;AAAA,MACF;AAAA;AAAA,EACF;AAEJ;;;AE7BA,OAAuB;;;ACEvB,IAAO,gBAAQC;","names":["Progress","Progress"]}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { TypeStyledComponentsCommonProps, TypeSystemCommonProps } from '@sproutsocial/seeds-react-system-props';
|
|
4
|
+
|
|
5
|
+
type TypeAriaLabel = {
|
|
6
|
+
"aria-label": string;
|
|
7
|
+
"aria-labelledby"?: string;
|
|
8
|
+
} | {
|
|
9
|
+
"aria-label"?: string;
|
|
10
|
+
"aria-labelledby": string;
|
|
11
|
+
};
|
|
12
|
+
type TypeProgressProps = TypeStyledComponentsCommonProps & TypeSystemCommonProps & Omit<React.ComponentPropsWithoutRef<"div">, "color"> & TypeAriaLabel & {
|
|
13
|
+
/** The current progress value */
|
|
14
|
+
value: number;
|
|
15
|
+
/** The maximum progress value. Defaults to 100 */
|
|
16
|
+
max?: number;
|
|
17
|
+
/** A function to get the accessible label text representing the current value. Defaults to "{value}%" */
|
|
18
|
+
getValueLabel?: (value: number, max: number) => string;
|
|
19
|
+
/** Custom CSS for the indicator (fill) element, e.g. a gradient background */
|
|
20
|
+
indicatorStyle?: React.CSSProperties;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
declare const Progress: ({ value, max, getValueLabel, indicatorStyle, ...rest }: TypeProgressProps) => react_jsx_runtime.JSX.Element;
|
|
24
|
+
|
|
25
|
+
export { Progress, type TypeProgressProps, Progress as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { TypeStyledComponentsCommonProps, TypeSystemCommonProps } from '@sproutsocial/seeds-react-system-props';
|
|
4
|
+
|
|
5
|
+
type TypeAriaLabel = {
|
|
6
|
+
"aria-label": string;
|
|
7
|
+
"aria-labelledby"?: string;
|
|
8
|
+
} | {
|
|
9
|
+
"aria-label"?: string;
|
|
10
|
+
"aria-labelledby": string;
|
|
11
|
+
};
|
|
12
|
+
type TypeProgressProps = TypeStyledComponentsCommonProps & TypeSystemCommonProps & Omit<React.ComponentPropsWithoutRef<"div">, "color"> & TypeAriaLabel & {
|
|
13
|
+
/** The current progress value */
|
|
14
|
+
value: number;
|
|
15
|
+
/** The maximum progress value. Defaults to 100 */
|
|
16
|
+
max?: number;
|
|
17
|
+
/** A function to get the accessible label text representing the current value. Defaults to "{value}%" */
|
|
18
|
+
getValueLabel?: (value: number, max: number) => string;
|
|
19
|
+
/** Custom CSS for the indicator (fill) element, e.g. a gradient background */
|
|
20
|
+
indicatorStyle?: React.CSSProperties;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
declare const Progress: ({ value, max, getValueLabel, indicatorStyle, ...rest }: TypeProgressProps) => react_jsx_runtime.JSX.Element;
|
|
24
|
+
|
|
25
|
+
export { Progress, type TypeProgressProps, Progress as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
Progress: () => Progress2,
|
|
34
|
+
default: () => index_default
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
|
|
38
|
+
// src/Progress.tsx
|
|
39
|
+
var React = require("react");
|
|
40
|
+
|
|
41
|
+
// src/styles.ts
|
|
42
|
+
var import_styled_components = __toESM(require("styled-components"));
|
|
43
|
+
var Progress = __toESM(require("@radix-ui/react-progress"));
|
|
44
|
+
var import_seeds_react_system_props = require("@sproutsocial/seeds-react-system-props");
|
|
45
|
+
var StyledRoot = (0, import_styled_components.default)(Progress.Root).attrs({
|
|
46
|
+
className: "Progress"
|
|
47
|
+
})`
|
|
48
|
+
position: relative;
|
|
49
|
+
overflow: hidden;
|
|
50
|
+
width: 100%;
|
|
51
|
+
height: 8px;
|
|
52
|
+
border-radius: ${(p) => p.theme.radii.outer};
|
|
53
|
+
background-color: ${(p) => p.theme.colors.container.border.base};
|
|
54
|
+
|
|
55
|
+
${import_seeds_react_system_props.COMMON}
|
|
56
|
+
`;
|
|
57
|
+
var StyledIndicator = (0, import_styled_components.default)(Progress.Indicator)`
|
|
58
|
+
height: 100%;
|
|
59
|
+
width: 100%;
|
|
60
|
+
border-radius: ${(p) => p.theme.radii.outer};
|
|
61
|
+
background-color: ${(p) => p.theme.colors.icon.base};
|
|
62
|
+
transition: transform 150ms ease;
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
// src/Progress.tsx
|
|
66
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
67
|
+
var Progress2 = ({
|
|
68
|
+
value,
|
|
69
|
+
max = 100,
|
|
70
|
+
getValueLabel,
|
|
71
|
+
indicatorStyle,
|
|
72
|
+
...rest
|
|
73
|
+
}) => {
|
|
74
|
+
const percentage = max > 0 ? Math.min(value / max * 100, 100) : 0;
|
|
75
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
76
|
+
StyledRoot,
|
|
77
|
+
{
|
|
78
|
+
value,
|
|
79
|
+
max,
|
|
80
|
+
getValueLabel,
|
|
81
|
+
"data-qa-progress": "",
|
|
82
|
+
...rest,
|
|
83
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
84
|
+
StyledIndicator,
|
|
85
|
+
{
|
|
86
|
+
style: {
|
|
87
|
+
transform: `translateX(-${100 - percentage}%)`,
|
|
88
|
+
...indicatorStyle
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// src/ProgressTypes.ts
|
|
97
|
+
var React2 = require("react");
|
|
98
|
+
|
|
99
|
+
// src/index.ts
|
|
100
|
+
var index_default = Progress2;
|
|
101
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
102
|
+
0 && (module.exports = {
|
|
103
|
+
Progress
|
|
104
|
+
});
|
|
105
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/Progress.tsx","../src/styles.ts","../src/ProgressTypes.ts"],"sourcesContent":["import { Progress } from \"./Progress\";\n\nexport default Progress;\nexport { Progress };\nexport * from \"./ProgressTypes\";\n","import * as React from \"react\";\nimport { StyledRoot, StyledIndicator } from \"./styles\";\nimport type { TypeProgressProps } from \"./ProgressTypes\";\n\nexport const Progress = ({\n value,\n max = 100,\n getValueLabel,\n indicatorStyle,\n ...rest\n}: TypeProgressProps) => {\n const percentage = max > 0 ? Math.min((value / max) * 100, 100) : 0;\n\n return (\n <StyledRoot\n value={value}\n max={max}\n getValueLabel={getValueLabel}\n data-qa-progress=\"\"\n {...rest}\n >\n <StyledIndicator\n style={{\n transform: `translateX(-${100 - percentage}%)`,\n ...indicatorStyle,\n }}\n />\n </StyledRoot>\n );\n};\n","import styled from \"styled-components\";\nimport * as Progress from \"@radix-ui/react-progress\";\nimport { COMMON } from \"@sproutsocial/seeds-react-system-props\";\n\nexport const StyledRoot = styled(Progress.Root).attrs({\n className: \"Progress\",\n})`\n position: relative;\n overflow: hidden;\n width: 100%;\n height: 8px;\n border-radius: ${(p) => p.theme.radii.outer};\n background-color: ${(p) => p.theme.colors.container.border.base};\n\n ${COMMON}\n`;\n\nexport const StyledIndicator = styled(Progress.Indicator)`\n height: 100%;\n width: 100%;\n border-radius: ${(p) => p.theme.radii.outer};\n background-color: ${(p) => p.theme.colors.icon.base};\n transition: transform 150ms ease;\n`;\n","import * as React from \"react\";\nimport type {\n TypeStyledComponentsCommonProps,\n TypeSystemCommonProps,\n} from \"@sproutsocial/seeds-react-system-props\";\n\ntype TypeAriaLabel =\n | { \"aria-label\": string; \"aria-labelledby\"?: string }\n | { \"aria-label\"?: string; \"aria-labelledby\": string };\n\nexport type TypeProgressProps = TypeStyledComponentsCommonProps &\n TypeSystemCommonProps &\n Omit<React.ComponentPropsWithoutRef<\"div\">, \"color\"> &\n TypeAriaLabel & {\n /** The current progress value */\n value: number;\n /** The maximum progress value. Defaults to 100 */\n max?: number;\n /** A function to get the accessible label text representing the current value. Defaults to \"{value}%\" */\n getValueLabel?: (value: number, max: number) => string;\n /** Custom CSS for the indicator (fill) element, e.g. a gradient background */\n indicatorStyle?: React.CSSProperties;\n };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,kBAAAA;AAAA,EAAA;AAAA;AAAA;;;ACAA,YAAuB;;;ACAvB,+BAAmB;AACnB,eAA0B;AAC1B,sCAAuB;AAEhB,IAAM,iBAAa,yBAAAC,SAAgB,aAAI,EAAE,MAAM;AAAA,EACpD,WAAW;AACb,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,mBAKkB,CAAC,MAAM,EAAE,MAAM,MAAM,KAAK;AAAA,sBACvB,CAAC,MAAM,EAAE,MAAM,OAAO,UAAU,OAAO,IAAI;AAAA;AAAA,IAE7D,sCAAM;AAAA;AAGH,IAAM,sBAAkB,yBAAAA,SAAgB,kBAAS;AAAA;AAAA;AAAA,mBAGrC,CAAC,MAAM,EAAE,MAAM,MAAM,KAAK;AAAA,sBACvB,CAAC,MAAM,EAAE,MAAM,OAAO,KAAK,IAAI;AAAA;AAAA;;;ADA/C;AAjBC,IAAMC,YAAW,CAAC;AAAA,EACvB;AAAA,EACA,MAAM;AAAA,EACN;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAyB;AACvB,QAAM,aAAa,MAAM,IAAI,KAAK,IAAK,QAAQ,MAAO,KAAK,GAAG,IAAI;AAElE,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA,oBAAiB;AAAA,MAChB,GAAG;AAAA,MAEJ;AAAA,QAAC;AAAA;AAAA,UACC,OAAO;AAAA,YACL,WAAW,eAAe,MAAM,UAAU;AAAA,YAC1C,GAAG;AAAA,UACL;AAAA;AAAA,MACF;AAAA;AAAA,EACF;AAEJ;;;AE7BA,IAAAC,SAAuB;;;AHEvB,IAAO,gBAAQC;","names":["Progress","styled","Progress","React","Progress"]}
|
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sproutsocial/seeds-react-progress",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Seeds React Progress",
|
|
5
|
+
"author": "Sprout Social, Inc.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"module": "dist/esm/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsup --dts",
|
|
12
|
+
"build:debug": "tsup --dts --metafile",
|
|
13
|
+
"dev": "tsup --watch --dts",
|
|
14
|
+
"clean": "rm -rf .turbo dist",
|
|
15
|
+
"clean:modules": "rm -rf node_modules",
|
|
16
|
+
"typecheck": "tsc --noEmit",
|
|
17
|
+
"test": "jest",
|
|
18
|
+
"test:watch": "jest --watch --coverage=false"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@radix-ui/react-progress": "^1.1.2",
|
|
22
|
+
"@sproutsocial/seeds-react-theme": "^3.6.0",
|
|
23
|
+
"@sproutsocial/seeds-react-system-props": "^3.0.1"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/react": "^18.0.0",
|
|
27
|
+
"@types/styled-components": "^5.1.26",
|
|
28
|
+
"@sproutsocial/eslint-config-seeds": "*",
|
|
29
|
+
"react": "^18.0.0",
|
|
30
|
+
"styled-components": "^5.2.3",
|
|
31
|
+
"tsup": "^8.3.4",
|
|
32
|
+
"typescript": "^5.6.2",
|
|
33
|
+
"@sproutsocial/seeds-tsconfig": "*",
|
|
34
|
+
"@sproutsocial/seeds-testing": "*",
|
|
35
|
+
"@sproutsocial/seeds-react-testing-library": "*"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"styled-components": "^5.2.3"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Progress } from "./";
|
|
3
|
+
import type { TypeProgressProps } from "./ProgressTypes";
|
|
4
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
5
|
+
|
|
6
|
+
const meta: Meta<typeof Progress> = {
|
|
7
|
+
title: "Components/Progress",
|
|
8
|
+
component: Progress,
|
|
9
|
+
args: {
|
|
10
|
+
value: 33,
|
|
11
|
+
max: 100,
|
|
12
|
+
"aria-label": "Credits remaining",
|
|
13
|
+
},
|
|
14
|
+
argTypes: {
|
|
15
|
+
value: { control: { type: "range", min: 0, max: 100, step: 1 } },
|
|
16
|
+
max: { control: { type: "number" } },
|
|
17
|
+
},
|
|
18
|
+
decorators: [
|
|
19
|
+
(Story) => (
|
|
20
|
+
<div style={{ maxWidth: 500 }}>
|
|
21
|
+
<Story />
|
|
22
|
+
</div>
|
|
23
|
+
),
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default meta;
|
|
28
|
+
|
|
29
|
+
type Story = StoryObj<typeof Progress>;
|
|
30
|
+
|
|
31
|
+
export const Default: Story = {
|
|
32
|
+
render: (args: TypeProgressProps) => <Progress {...args} />,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
Default.storyName = "Default";
|
|
36
|
+
|
|
37
|
+
export const Empty: Story = {
|
|
38
|
+
args: {
|
|
39
|
+
value: 0,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const Full: Story = {
|
|
44
|
+
args: {
|
|
45
|
+
value: 100,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const CustomValueLabel: Story = {
|
|
50
|
+
render: (args: TypeProgressProps) => {
|
|
51
|
+
const getValueLabel = (value: number, max: number) =>
|
|
52
|
+
`${value} of ${max} credits remaining`;
|
|
53
|
+
const label = getValueLabel(args.value, args.max ?? 100);
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<div>
|
|
57
|
+
<Progress {...args} getValueLabel={getValueLabel} />
|
|
58
|
+
<p>aria-valuetext: "{label}"</p>
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
},
|
|
62
|
+
args: {
|
|
63
|
+
value: 33,
|
|
64
|
+
max: 100,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const CustomGradient: Story = {
|
|
69
|
+
args: {
|
|
70
|
+
value: 67,
|
|
71
|
+
indicatorStyle: {
|
|
72
|
+
background: `radial-gradient(
|
|
73
|
+
ellipse at left,
|
|
74
|
+
rgba(32, 91, 195, 1) 0%,
|
|
75
|
+
rgba(62, 86, 210, 1) 15%,
|
|
76
|
+
rgba(92, 81, 225, 1) 30%,
|
|
77
|
+
rgba(151, 71, 255, 1) 61%,
|
|
78
|
+
rgba(197, 101, 250, 1) 80%,
|
|
79
|
+
rgba(242, 130, 245, 1) 100%
|
|
80
|
+
)`,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
};
|
package/src/Progress.tsx
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { StyledRoot, StyledIndicator } from "./styles";
|
|
3
|
+
import type { TypeProgressProps } from "./ProgressTypes";
|
|
4
|
+
|
|
5
|
+
export const Progress = ({
|
|
6
|
+
value,
|
|
7
|
+
max = 100,
|
|
8
|
+
getValueLabel,
|
|
9
|
+
indicatorStyle,
|
|
10
|
+
...rest
|
|
11
|
+
}: TypeProgressProps) => {
|
|
12
|
+
const percentage = max > 0 ? Math.min((value / max) * 100, 100) : 0;
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<StyledRoot
|
|
16
|
+
value={value}
|
|
17
|
+
max={max}
|
|
18
|
+
getValueLabel={getValueLabel}
|
|
19
|
+
data-qa-progress=""
|
|
20
|
+
{...rest}
|
|
21
|
+
>
|
|
22
|
+
<StyledIndicator
|
|
23
|
+
style={{
|
|
24
|
+
transform: `translateX(-${100 - percentage}%)`,
|
|
25
|
+
...indicatorStyle,
|
|
26
|
+
}}
|
|
27
|
+
/>
|
|
28
|
+
</StyledRoot>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type {
|
|
3
|
+
TypeStyledComponentsCommonProps,
|
|
4
|
+
TypeSystemCommonProps,
|
|
5
|
+
} from "@sproutsocial/seeds-react-system-props";
|
|
6
|
+
|
|
7
|
+
type TypeAriaLabel =
|
|
8
|
+
| { "aria-label": string; "aria-labelledby"?: string }
|
|
9
|
+
| { "aria-label"?: string; "aria-labelledby": string };
|
|
10
|
+
|
|
11
|
+
export type TypeProgressProps = TypeStyledComponentsCommonProps &
|
|
12
|
+
TypeSystemCommonProps &
|
|
13
|
+
Omit<React.ComponentPropsWithoutRef<"div">, "color"> &
|
|
14
|
+
TypeAriaLabel & {
|
|
15
|
+
/** The current progress value */
|
|
16
|
+
value: number;
|
|
17
|
+
/** The maximum progress value. Defaults to 100 */
|
|
18
|
+
max?: number;
|
|
19
|
+
/** A function to get the accessible label text representing the current value. Defaults to "{value}%" */
|
|
20
|
+
getValueLabel?: (value: number, max: number) => string;
|
|
21
|
+
/** Custom CSS for the indicator (fill) element, e.g. a gradient background */
|
|
22
|
+
indicatorStyle?: React.CSSProperties;
|
|
23
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, screen } from "@sproutsocial/seeds-react-testing-library";
|
|
3
|
+
import { Progress } from "../";
|
|
4
|
+
|
|
5
|
+
describe("Progress", () => {
|
|
6
|
+
it("should render with the progressbar role", () => {
|
|
7
|
+
render(<Progress value={50} aria-label="Credits remaining" />);
|
|
8
|
+
|
|
9
|
+
expect(screen.getByRole("progressbar")).toBeInTheDocument();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("should set aria-valuenow to the value", () => {
|
|
13
|
+
render(<Progress value={33} aria-label="Credits remaining" />);
|
|
14
|
+
|
|
15
|
+
expect(screen.getByRole("progressbar")).toHaveAttribute(
|
|
16
|
+
"aria-valuenow",
|
|
17
|
+
"33"
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should set aria-valuemax to the max", () => {
|
|
22
|
+
render(<Progress value={50} max={200} aria-label="Credits remaining" />);
|
|
23
|
+
|
|
24
|
+
expect(screen.getByRole("progressbar")).toHaveAttribute(
|
|
25
|
+
"aria-valuemax",
|
|
26
|
+
"200"
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should apply the correct transform for the indicator", () => {
|
|
31
|
+
const { container } = render(
|
|
32
|
+
<Progress value={75} aria-label="Credits remaining" />
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const indicator = container.querySelector(".Progress > div");
|
|
36
|
+
expect(indicator).toHaveStyle("transform: translateX(-25%)");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should clamp percentage to 100 when value exceeds max", () => {
|
|
40
|
+
const { container } = render(
|
|
41
|
+
<Progress value={150} max={100} aria-label="Credits remaining" />
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const indicator = container.querySelector(".Progress > div");
|
|
45
|
+
expect(indicator).toHaveStyle("transform: translateX(-0%)");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should handle 0 max gracefully", () => {
|
|
49
|
+
render(<Progress value={50} max={0} aria-label="Credits remaining" />);
|
|
50
|
+
|
|
51
|
+
const progressbar = screen.getByRole("progressbar");
|
|
52
|
+
expect(progressbar).toBeInTheDocument();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should apply custom indicator styles", () => {
|
|
56
|
+
const { container } = render(
|
|
57
|
+
<Progress
|
|
58
|
+
value={50}
|
|
59
|
+
aria-label="Credits remaining"
|
|
60
|
+
indicatorStyle={{ background: "linear-gradient(red, blue)" }}
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const indicator = container.querySelector(".Progress > div");
|
|
65
|
+
expect(indicator).toHaveStyle("background: linear-gradient(red, blue)");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("should use custom getValueLabel", () => {
|
|
69
|
+
render(
|
|
70
|
+
<Progress
|
|
71
|
+
value={3}
|
|
72
|
+
max={10}
|
|
73
|
+
aria-label="Steps completed"
|
|
74
|
+
getValueLabel={(value, max) => `${value} of ${max} steps`}
|
|
75
|
+
/>
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
expect(screen.getByRole("progressbar")).toHaveAttribute(
|
|
79
|
+
"aria-valuetext",
|
|
80
|
+
"3 of 10 steps"
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("should support aria-labelledby", () => {
|
|
85
|
+
render(
|
|
86
|
+
<>
|
|
87
|
+
<span id="progress-label">Upload progress</span>
|
|
88
|
+
<Progress value={50} aria-labelledby="progress-label" />
|
|
89
|
+
</>
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
expect(screen.getByRole("progressbar")).toHaveAttribute(
|
|
93
|
+
"aria-labelledby",
|
|
94
|
+
"progress-label"
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("should set aria-label on the progressbar", () => {
|
|
99
|
+
render(<Progress value={50} aria-label="Credits remaining" />);
|
|
100
|
+
|
|
101
|
+
expect(screen.getByRole("progressbar")).toHaveAttribute(
|
|
102
|
+
"aria-label",
|
|
103
|
+
"Credits remaining"
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("should allow passing qa props", () => {
|
|
108
|
+
render(
|
|
109
|
+
<Progress
|
|
110
|
+
value={50}
|
|
111
|
+
aria-label="Credits remaining"
|
|
112
|
+
data-qa-progress="credits"
|
|
113
|
+
/>
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
expect(
|
|
117
|
+
screen.getByRole("progressbar").closest("[data-qa-progress]")
|
|
118
|
+
).toBeTruthy();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { render } from "@sproutsocial/seeds-react-testing-library";
|
|
3
|
+
import { Progress } from "../";
|
|
4
|
+
|
|
5
|
+
describe.skip("Progress/types", () => {
|
|
6
|
+
it("should accept valid props", () => {
|
|
7
|
+
render(
|
|
8
|
+
<>
|
|
9
|
+
<Progress value={50} aria-label="Credits" />
|
|
10
|
+
<Progress value={50} max={200} aria-label="Credits" />
|
|
11
|
+
<Progress
|
|
12
|
+
value={50}
|
|
13
|
+
aria-label="Credits"
|
|
14
|
+
getValueLabel={(value, max) => `${value}/${max}`}
|
|
15
|
+
/>
|
|
16
|
+
<Progress
|
|
17
|
+
value={50}
|
|
18
|
+
aria-label="Credits"
|
|
19
|
+
indicatorStyle={{ background: "red" }}
|
|
20
|
+
/>
|
|
21
|
+
<Progress value={50} aria-label="Credits" m={400} />
|
|
22
|
+
<Progress value={50} aria-labelledby="my-label" />
|
|
23
|
+
{/* @ts-expect-error - value is required */}
|
|
24
|
+
<Progress aria-label="Credits" />
|
|
25
|
+
{/* @ts-expect-error - value must be a number */}
|
|
26
|
+
<Progress value="50" aria-label="Credits" />
|
|
27
|
+
{/* @ts-expect-error - aria-label or aria-labelledby is required */}
|
|
28
|
+
<Progress value={50} />
|
|
29
|
+
</>
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
});
|
package/src/index.ts
ADDED
package/src/styled.d.ts
ADDED
package/src/styles.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import styled from "styled-components";
|
|
2
|
+
import * as Progress from "@radix-ui/react-progress";
|
|
3
|
+
import { COMMON } from "@sproutsocial/seeds-react-system-props";
|
|
4
|
+
|
|
5
|
+
export const StyledRoot = styled(Progress.Root).attrs({
|
|
6
|
+
className: "Progress",
|
|
7
|
+
})`
|
|
8
|
+
position: relative;
|
|
9
|
+
overflow: hidden;
|
|
10
|
+
width: 100%;
|
|
11
|
+
height: 8px;
|
|
12
|
+
border-radius: ${(p) => p.theme.radii.outer};
|
|
13
|
+
background-color: ${(p) => p.theme.colors.container.border.base};
|
|
14
|
+
|
|
15
|
+
${COMMON}
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
export const StyledIndicator = styled(Progress.Indicator)`
|
|
19
|
+
height: 100%;
|
|
20
|
+
width: 100%;
|
|
21
|
+
border-radius: ${(p) => p.theme.radii.outer};
|
|
22
|
+
background-color: ${(p) => p.theme.colors.icon.base};
|
|
23
|
+
transition: transform 150ms ease;
|
|
24
|
+
`;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@sproutsocial/seeds-tsconfig/bundler/dom/library-monorepo",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"jsx": "react-jsx",
|
|
5
|
+
"module": "esnext"
|
|
6
|
+
},
|
|
7
|
+
"include": ["src/**/*"],
|
|
8
|
+
"exclude": [
|
|
9
|
+
"node_modules",
|
|
10
|
+
"dist",
|
|
11
|
+
"coverage",
|
|
12
|
+
"**/*.stories.tsx",
|
|
13
|
+
"**/*.stories.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineConfig } from "tsup";
|
|
2
|
+
|
|
3
|
+
export default defineConfig((options) => ({
|
|
4
|
+
entry: ["src/index.ts"],
|
|
5
|
+
format: ["cjs", "esm"],
|
|
6
|
+
clean: true,
|
|
7
|
+
legacyOutput: true,
|
|
8
|
+
dts: options.dts,
|
|
9
|
+
external: ["react"],
|
|
10
|
+
sourcemap: true,
|
|
11
|
+
metafile: options.metafile,
|
|
12
|
+
}));
|