Skip to content

Commit 1c5c0f5

Browse files
committed
Added Atoms CheckboxInput
1 parent dd61d43 commit 1c5c0f5

4 files changed

Lines changed: 84 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { CheckboxInput } from "./checkbox-input";
2+
import React from "react";
3+
import { boolean, text } from "@storybook/addon-knobs";
4+
5+
export default {
6+
title: "Atoms | Forms / Checkbox Input",
7+
component: CheckboxInput,
8+
};
9+
10+
export const checkboxInputKnobs = () => (
11+
<CheckboxInput
12+
checked={boolean("Checked", false)}
13+
label={text("Label", "Remember Me")}
14+
disabled={boolean("Disabled", false)}
15+
onChange={() => {}}
16+
/>
17+
);
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("CheckboxInput", () => {
4+
test.skip("TODO - https://github.com/AndcultureCode/AndcultureCode.JavaScript.React.Components/issues/6", () => {});
5+
});

src/atoms/forms/checkbox-input.tsx

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { InputTypes } from "../constants/input-types";
2+
import React from "react";
3+
4+
// -----------------------------------------------------------------------------------------
5+
// #region Interfaces
6+
// -----------------------------------------------------------------------------------------
7+
8+
export interface CheckboxInputProperties {
9+
checked: boolean;
10+
disabled?: boolean;
11+
label: string;
12+
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
13+
}
14+
15+
// #endregion Interfaces
16+
17+
// -----------------------------------------------------------------------------------------
18+
// #region Constants
19+
// -----------------------------------------------------------------------------------------
20+
21+
const BASE_CLASS_NAME = "e-checkbox";
22+
23+
// #endregion Constants
24+
25+
// -----------------------------------------------------------------------------------------
26+
// #region Component
27+
// -----------------------------------------------------------------------------------------
28+
29+
const CheckboxInput: React.FC<CheckboxInputProperties> = (
30+
props: CheckboxInputProperties
31+
) => {
32+
const { checked, disabled, label, onChange } = props;
33+
let className = BASE_CLASS_NAME;
34+
if (disabled) {
35+
className += " -disabled";
36+
}
37+
38+
return (
39+
<label className={className}>
40+
{label}
41+
<input
42+
checked={checked}
43+
disabled={disabled}
44+
onChange={onChange}
45+
type={InputTypes.Checkbox}
46+
value={checked.toString()}
47+
/>
48+
<span className={`${BASE_CLASS_NAME}__checkmark`}></span>
49+
</label>
50+
);
51+
};
52+
53+
// #endregion Component
54+
55+
// -----------------------------------------------------------------------------------------
56+
// #region Export
57+
// -----------------------------------------------------------------------------------------
58+
59+
export { CheckboxInput };
60+
61+
// #endregion Export

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export { Anchor } from "./atoms/anchors/anchor";
66
export { AnchorWithIcon } from "./atoms/anchors/anchor-with-icon";
77
export { Button } from "./atoms/buttons/button";
88
export { CheckboxButton } from "./atoms/forms/checkbox-button";
9+
export { CheckboxInput } from "./atoms/forms/checkbox-input";
910

1011
// Icons
1112
export { Icon } from "./atoms/icons/icon";

0 commit comments

Comments
 (0)