Skip to content

Commit 5a35ed6

Browse files
committed
Added atoms progress bar
1 parent 417ecfb commit 5a35ed6

9 files changed

Lines changed: 210 additions & 3 deletions

File tree

src/assets/scss/6-components/atoms/__atoms.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@import "buttons";
55
@import "checkbox-button";
66
@import "labels";
7+
@import "progress-bar";
78
@import "radios";
89
@import "selects";
910
@import "text-input-icon";
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
.c-progress-bar {
2+
width: 100%;
3+
height: rem(6px);
4+
border-radius: $border-radius-small;
5+
border: 1px solid get-color-neutral("50");
6+
background-color: get-color-neutral("30");
7+
8+
&.-thick {
9+
height: rem(24px);
10+
11+
.c-progress-bar__bar {
12+
height: rem(22px);
13+
}
14+
}
15+
16+
&.-error {
17+
.c-progress-bar__bar {
18+
background-color: get-color-status("error");
19+
}
20+
}
21+
22+
&__bar {
23+
height: rem(4px);
24+
border-top-left-radius: $border-radius-small;
25+
border-bottom-left-radius: $border-radius-small;
26+
background-color: get-color-status("success");
27+
28+
/**
29+
* generate classes -w-0, -w-1, -w-2, etc. up to -w-100
30+
* to set the width to the progress percentage
31+
*/
32+
@for $i from 0 through 100 {
33+
&.-w-#{$i} {
34+
width: #{$i}#{unquote("%")};
35+
36+
@if ($i >= 100) {
37+
border-top-right-radius: $border-radius-small;
38+
border-bottom-right-radius: $border-radius-small;
39+
}
40+
}
41+
}
42+
}
43+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from "react";
2+
import { number } from "@storybook/addon-knobs";
3+
import { InputCharacterCount } from "./input-character-count";
4+
5+
export default {
6+
component: InputCharacterCount,
7+
title: "Atoms | Forms / Input Character Count",
8+
};
9+
10+
export const inputCharacterCountKnobs = () => (
11+
<InputCharacterCount
12+
currentLength={number("Current Length", 5)}
13+
maxLength={number("Max Length", 100)}
14+
/>
15+
);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from "react";
2+
3+
describe("InputCharacterCount", () => {
4+
test.skip("TODO - https://github.com/AndcultureCode/AndcultureCode.JavaScript.React.Components/issues/12", () => {});
5+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from "react";
2+
3+
// -------------------------------------------------------------------------------------------------
4+
// #region Interfaces
5+
// -------------------------------------------------------------------------------------------------
6+
7+
export interface InputCharacterCountProps {
8+
currentLength: number;
9+
maxLength: number;
10+
}
11+
12+
// #endregion Interfaces
13+
14+
// -------------------------------------------------------------------------------------------------
15+
// #region Component
16+
// -------------------------------------------------------------------------------------------------
17+
18+
const InputCharacterCount: React.FC<InputCharacterCountProps> = (
19+
props: InputCharacterCountProps
20+
) => {
21+
return (
22+
<div className="c-form-field__bottom__character-count">
23+
{props.currentLength}/{props.maxLength}
24+
</div>
25+
);
26+
};
27+
28+
// #endregion Component
29+
30+
// -------------------------------------------------------------------------------------------------
31+
// #region Exports
32+
// -------------------------------------------------------------------------------------------------
33+
34+
export { InputCharacterCount };
35+
36+
// #endregion Exports
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { boolean, number, optionsKnob } from "@storybook/addon-knobs";
2+
import { ProgressBar, ProgressBarStyles } from "./progress-bar";
3+
import React from "react";
4+
5+
export default {
6+
component: ProgressBar,
7+
title: "Atoms | Progress / Progress Bar",
8+
};
9+
10+
export const progressBarKnobs = () => (
11+
<ProgressBar
12+
value={number("Progress Percent", 50, {
13+
step: 1,
14+
min: 0,
15+
max: 100,
16+
})}
17+
isErrored={boolean("Is Errored", false)}
18+
style={optionsKnob(
19+
"Style",
20+
{
21+
thick: ProgressBarStyles.Thick,
22+
thin: ProgressBarStyles.Thin,
23+
},
24+
ProgressBarStyles.Thick,
25+
{ display: "radio" }
26+
)}
27+
/>
28+
);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from "react";
2+
3+
describe("ProgressBar", () => {
4+
test.skip("TODO - https://github.com/AndcultureCode/AndcultureCode.JavaScript.React.Components/issues/13", () => {});
5+
});
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import React from "react";
2+
import { StringUtils } from "andculturecode-javascript-core";
3+
4+
// -------------------------------------------------------------------------------------------------
5+
// #region Enums
6+
// -------------------------------------------------------------------------------------------------
7+
8+
export enum ProgressBarStyles {
9+
Thick = "-thick",
10+
Thin = "-thin",
11+
}
12+
13+
// #endregion Enums
14+
15+
// -------------------------------------------------------------------------------------------------
16+
// #region Interfaces
17+
// -------------------------------------------------------------------------------------------------
18+
19+
interface ProgressBarProps {
20+
cssClassName?: string;
21+
isErrored?: boolean;
22+
style?: ProgressBarStyles;
23+
value: number;
24+
}
25+
26+
// #endregion Interfaces
27+
28+
// -------------------------------------------------------------------------------------------------
29+
// #region Component
30+
// -------------------------------------------------------------------------------------------------
31+
32+
const ProgressBar: React.FC<ProgressBarProps> = (props: ProgressBarProps) => {
33+
const CSS_CLASS_NAME = "c-progress-bar";
34+
const classNames = [CSS_CLASS_NAME];
35+
36+
if (StringUtils.hasValue(props.cssClassName)) {
37+
classNames.push(props.cssClassName!);
38+
}
39+
40+
if (props.style != null) {
41+
classNames.push(props.style);
42+
}
43+
44+
if (props.isErrored) {
45+
classNames.push("-error");
46+
}
47+
48+
// value must be an integer 0 < value < 100
49+
let value = Math.round(props.value);
50+
51+
if (value < 0) {
52+
value = 0;
53+
}
54+
55+
if (value > 100) {
56+
value = 100;
57+
}
58+
59+
return (
60+
<div className={classNames.join(" ")}>
61+
<div className={`${CSS_CLASS_NAME}__bar -w-${value}`} />
62+
</div>
63+
);
64+
};
65+
66+
// #endregion Component
67+
68+
// -------------------------------------------------------------------------------------------------
69+
// #region Exports
70+
// -------------------------------------------------------------------------------------------------
71+
72+
export { ProgressBar };
73+
74+
// #endregion Exports

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
export { Anchor } from "./atoms/anchors/anchor";
66
export { AnchorWithIcon } from "./atoms/anchors/anchor-with-icon";
77
export { Button } from "./atoms/buttons/button";
8+
export { Icon } from "./atoms/icons/icon";
9+
export { ProgressBar } from "./atoms/progress-bar/progress-bar";
810

911
// Forms
1012
export { CheckboxButton } from "./atoms/forms/checkbox-button";
1113
export { CheckboxInput } from "./atoms/forms/checkbox-input";
14+
export { InputCharacterCount } from "./atoms/forms/input-character-count";
1215
export { PasswordInput } from "./atoms/forms/password-input";
1316
export { Select } from "./atoms/forms/select";
1417
export { SubmitButton } from "./atoms/forms/submit-button";
1518
export { TextArea } from "./atoms/forms/text-area";
1619
export { TextInput } from "./atoms/forms/text-input";
1720
export { TextInputIcon } from "./atoms/forms/text-input-icon";
1821

19-
// Icons
20-
export { Icon } from "./atoms/icons/icon";
21-
2222
// #endregion Atoms
2323

2424
// -----------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)