@onewelcome/react-lib-components 1.0.1 → 1.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/dist/ProgressBar/ProgressBar.d.ts +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/react-lib-components.cjs.development.js +95 -70
- package/dist/react-lib-components.cjs.development.js.map +1 -1
- package/dist/react-lib-components.cjs.production.min.js +1 -1
- package/dist/react-lib-components.cjs.production.min.js.map +1 -1
- package/dist/react-lib-components.esm.js +95 -71
- package/dist/react-lib-components.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/ProgressBar/ProgressBar.module.scss +56 -0
- package/src/ProgressBar/ProgressBar.test.tsx +58 -0
- package/src/ProgressBar/ProgressBar.tsx +38 -0
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright 2022 OneWelcome B.V.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
.progress-bar {
|
|
18
|
+
position: relative;
|
|
19
|
+
display: block;
|
|
20
|
+
height: 0.5rem;
|
|
21
|
+
width: 100%;
|
|
22
|
+
border-radius: 0.25rem;
|
|
23
|
+
background-color: var(--disabled);
|
|
24
|
+
overflow: hidden;
|
|
25
|
+
|
|
26
|
+
@media (prefers-reduced-motion: reduce) {
|
|
27
|
+
display: none;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.bar {
|
|
31
|
+
position: absolute;
|
|
32
|
+
height: 0.5rem;
|
|
33
|
+
width: 50%;
|
|
34
|
+
border-radius: 0.25rem;
|
|
35
|
+
background-color: var(--color-primary);
|
|
36
|
+
animation: cubic-bezier(0.23, 0.78, 0.78, 0.23) 1s slide-in infinite;
|
|
37
|
+
|
|
38
|
+
@keyframes slide-in {
|
|
39
|
+
0% {
|
|
40
|
+
left: -50%;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
100% {
|
|
44
|
+
left: 100%;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.placeholder {
|
|
51
|
+
display: none;
|
|
52
|
+
|
|
53
|
+
@media (prefers-reduced-motion: reduce) {
|
|
54
|
+
display: unset;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from "react";
|
|
2
|
+
import { ProgressBar, Props } from "./ProgressBar";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
|
|
5
|
+
const defaultParams: Props = {
|
|
6
|
+
placeholderText: "Loading"
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const createProgressBar = (params?: (defaultParams: Props) => Props) => {
|
|
10
|
+
let parameters: Props = defaultParams;
|
|
11
|
+
if (params) {
|
|
12
|
+
parameters = params(defaultParams);
|
|
13
|
+
}
|
|
14
|
+
const queries = render(<ProgressBar {...parameters} data-testid="ProgressBar" />);
|
|
15
|
+
const ProgressBarComponent = queries.getByTestId("ProgressBar");
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
...queries,
|
|
19
|
+
ProgressBarComponent
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
describe("ProgressBar should render", () => {
|
|
24
|
+
it("renders without crashing", () => {
|
|
25
|
+
const { ProgressBarComponent } = createProgressBar(defaultParams => ({
|
|
26
|
+
...defaultParams,
|
|
27
|
+
className: "test"
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
expect(ProgressBarComponent).toBeDefined();
|
|
31
|
+
expect(ProgressBarComponent).toHaveClass(`test`, { exact: true });
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe("ref should work", () => {
|
|
36
|
+
it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
|
|
37
|
+
const ExampleComponent = ({
|
|
38
|
+
propagateRef
|
|
39
|
+
}: {
|
|
40
|
+
propagateRef: (ref: React.RefObject<HTMLElement>) => void;
|
|
41
|
+
}) => {
|
|
42
|
+
const ref = useRef(null);
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
propagateRef(ref);
|
|
46
|
+
}, [ref]);
|
|
47
|
+
|
|
48
|
+
return <ProgressBar {...defaultParams} data-ref="testing" ref={ref} />;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
52
|
+
expect(ref.current).toHaveAttribute("data-ref", "testing");
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const container = document.createElement("div");
|
|
56
|
+
render(<ExampleComponent propagateRef={refCheck} />, { container });
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 OneWelcome B.V.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import React, { ComponentPropsWithRef } from "react";
|
|
18
|
+
import { Typography } from "../Typography/Typography";
|
|
19
|
+
import classes from "./ProgressBar.module.scss";
|
|
20
|
+
|
|
21
|
+
export interface Props extends Omit<ComponentPropsWithRef<"span">, "children"> {
|
|
22
|
+
placeholderText: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const ProgressBar = React.forwardRef<HTMLSpanElement, Props>(
|
|
26
|
+
({ placeholderText, ...rest }: Props, ref) => {
|
|
27
|
+
return (
|
|
28
|
+
<span {...rest} ref={ref} role="progressbar">
|
|
29
|
+
<span className={classes["progress-bar"]}>
|
|
30
|
+
<span className={classes["bar"]} />
|
|
31
|
+
</span>
|
|
32
|
+
<Typography className={classes["placeholder"]} spacing={{ marginBottom: 0 }} variant="body">
|
|
33
|
+
{placeholderText}
|
|
34
|
+
</Typography>
|
|
35
|
+
</span>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
);
|
package/src/index.ts
CHANGED
|
@@ -30,6 +30,7 @@ export { Tile, Props as TileProps } from "./Tiles/Tile";
|
|
|
30
30
|
export { Tiles, Props as TilesProps } from "./Tiles/Tiles";
|
|
31
31
|
export { Tooltip, Props as TooltipProps } from "./Tooltip/Tooltip";
|
|
32
32
|
export { Typography, Variant, Props as TypographyProps } from "./Typography/Typography";
|
|
33
|
+
export { ProgressBar, Props as ProgressBarProps } from "./ProgressBar/ProgressBar";
|
|
33
34
|
export { Skeleton, Props as SkeletonProps } from "./Skeleton/Skeleton";
|
|
34
35
|
export { StatusIndicator, Props as StatusIndicatorProps } from "./StatusIndicator/StatusIndicator";
|
|
35
36
|
export {
|