@nice-digital/nds-checkbox 3.0.2 → 4.0.1-alpha.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/es/Checkbox.d.ts +20 -0
- package/es/Checkbox.js +34 -50
- package/es/Checkbox.test.d.ts +1 -0
- package/es/Checkbox.test.js +58 -0
- package/package.json +13 -13
- package/es/Checkbox.js.map +0 -1
- package/lib/Checkbox.js +0 -107
- package/lib/Checkbox.js.map +0 -1
- package/nds-checkbox.d.ts +0 -22
package/es/Checkbox.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import "../scss/checkbox.scss";
|
|
3
|
+
export interface CheckboxProps {
|
|
4
|
+
/** Allow any additional props to be passed and applied to the checkbox */
|
|
5
|
+
[prop: string]: unknown;
|
|
6
|
+
/** The name attribute for the checkbox */
|
|
7
|
+
name: string;
|
|
8
|
+
/** The label for the checkbox. If none supplied will use the value */
|
|
9
|
+
label?: React.ReactNode;
|
|
10
|
+
/** The value for the checkbox */
|
|
11
|
+
value: string;
|
|
12
|
+
/** Add to checkboxes that you would like to display inline, left to right */
|
|
13
|
+
inline?: boolean;
|
|
14
|
+
/** Option for putting the checkbox into a visual error state. Set to true for error styling or supply a string for error styling and addional error text*/
|
|
15
|
+
error?: boolean | string;
|
|
16
|
+
/** Add hint text for extra context to the checkbox */
|
|
17
|
+
hint?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare const Checkbox: React.FC<CheckboxProps>;
|
|
20
|
+
export default Checkbox;
|
package/es/Checkbox.js
CHANGED
|
@@ -1,50 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
id: unique,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
className: "checkbox__label",
|
|
36
|
-
htmlFor: unique
|
|
37
|
-
}, label ? label : value), hint && /*#__PURE__*/React.createElement("span", {
|
|
38
|
-
className: "checkbox__hint"
|
|
39
|
-
}, hint))));
|
|
40
|
-
};
|
|
41
|
-
Checkbox.propTypes = {
|
|
42
|
-
name: PropTypes.string.isRequired,
|
|
43
|
-
label: PropTypes.node.isRequired,
|
|
44
|
-
value: PropTypes.string,
|
|
45
|
-
inline: PropTypes.bool,
|
|
46
|
-
error: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
|
47
|
-
hint: PropTypes.string
|
|
48
|
-
};
|
|
49
|
-
export default Checkbox;
|
|
50
|
-
//# sourceMappingURL=Checkbox.js.map
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Checkbox = void 0;
|
|
18
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
19
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
20
|
+
require("../scss/checkbox.scss");
|
|
21
|
+
const Checkbox = (props) => {
|
|
22
|
+
const { error, inline, name, label, value, hint } = props, rest = __rest(props, ["error", "inline", "name", "label", "value", "hint"]);
|
|
23
|
+
if (!value)
|
|
24
|
+
return null;
|
|
25
|
+
const unique = name + "_" + value;
|
|
26
|
+
const classNames = (0, classnames_1.default)({
|
|
27
|
+
checkbox: true,
|
|
28
|
+
"checkbox--inline": inline,
|
|
29
|
+
"checkbox--error": error
|
|
30
|
+
});
|
|
31
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [error && error.toString().length && ((0, jsx_runtime_1.jsx)("p", Object.assign({ className: "checkbox__error-message" }, { children: error }))), (0, jsx_runtime_1.jsx)("div", Object.assign({ className: classNames }, { children: (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("input", Object.assign({ type: "checkbox", className: "checkbox__input", id: unique, name: name, value: value }, rest)), (0, jsx_runtime_1.jsx)("label", Object.assign({ className: "checkbox__label", htmlFor: unique }, { children: label ? label : value })), hint && (0, jsx_runtime_1.jsx)("span", Object.assign({ className: "checkbox__hint" }, { children: hint }))] }) }))] }));
|
|
32
|
+
};
|
|
33
|
+
exports.Checkbox = Checkbox;
|
|
34
|
+
exports.default = exports.Checkbox;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
+
const react_1 = require("@testing-library/react");
|
|
5
|
+
const Checkbox_1 = require("./../src/Checkbox");
|
|
6
|
+
const props = {
|
|
7
|
+
name: "contact-preference",
|
|
8
|
+
label: "Email",
|
|
9
|
+
value: "email",
|
|
10
|
+
disabled: false,
|
|
11
|
+
error: false
|
|
12
|
+
};
|
|
13
|
+
describe("Checkbox", () => {
|
|
14
|
+
it("should match snapshot with some default attributes", () => {
|
|
15
|
+
const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, Object.assign({}, props)));
|
|
16
|
+
expect(wrapper).toMatchSnapshot();
|
|
17
|
+
});
|
|
18
|
+
it("should match snapshot with hint text supplied", () => {
|
|
19
|
+
const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, Object.assign({}, props, { hint: "This is a hint to appear." })));
|
|
20
|
+
expect(wrapper).toMatchSnapshot();
|
|
21
|
+
});
|
|
22
|
+
it("should not render a checkbox control if it doesn't have a value", () => {
|
|
23
|
+
const localProps = Object.assign({}, props);
|
|
24
|
+
localProps.value = "";
|
|
25
|
+
const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, Object.assign({}, localProps)));
|
|
26
|
+
expect(wrapper.queryByRole("checkbox")).toBe(null);
|
|
27
|
+
});
|
|
28
|
+
it("should prevent actions if the button is disabled", () => {
|
|
29
|
+
const localProps = Object.assign({}, props);
|
|
30
|
+
localProps.disabled = true;
|
|
31
|
+
const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, Object.assign({}, localProps)));
|
|
32
|
+
const input = wrapper.getByRole("checkbox");
|
|
33
|
+
expect(input.disabled).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
it("should add an error class to the parent if the error prop is true", () => {
|
|
36
|
+
const localProps = Object.assign({}, props);
|
|
37
|
+
localProps.error = true;
|
|
38
|
+
const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, Object.assign({}, localProps)));
|
|
39
|
+
const parent = container.querySelector("div.checkbox--error");
|
|
40
|
+
expect(parent).toBeInTheDocument();
|
|
41
|
+
});
|
|
42
|
+
it("should add display error text above the control if an error string is supplied", () => {
|
|
43
|
+
const localProps = Object.assign({}, props);
|
|
44
|
+
localProps.error = "Error message here.";
|
|
45
|
+
const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, Object.assign({}, localProps)));
|
|
46
|
+
const parent = container.querySelector("p.checkbox__error-message");
|
|
47
|
+
expect(parent === null || parent === void 0 ? void 0 : parent.textContent).toBe("Error message here.");
|
|
48
|
+
});
|
|
49
|
+
it("should pass through any additional attributes supplied", () => {
|
|
50
|
+
const localProps = Object.assign({}, props);
|
|
51
|
+
localProps.defaultChecked = true;
|
|
52
|
+
localProps["data-something"] = "test";
|
|
53
|
+
const wrapper = (0, react_1.render)((0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, Object.assign({}, localProps)));
|
|
54
|
+
const checked = wrapper.getByRole("checkbox");
|
|
55
|
+
expect(checked.checked).toBe(true);
|
|
56
|
+
expect(checked.getAttribute("data-something")).toBe("test");
|
|
57
|
+
});
|
|
58
|
+
});
|
package/package.json
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nice-digital/nds-checkbox",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1-alpha.0",
|
|
4
4
|
"description": "Checkbox component for the NICE Design System",
|
|
5
5
|
"author": "Warren Keith <warren.keith@nice.org.uk>",
|
|
6
6
|
"homepage": "https://design-system.nice.org.uk/",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"main": "
|
|
9
|
-
"module": "es/Checkbox.js",
|
|
8
|
+
"main": "es/Checkbox.js",
|
|
10
9
|
"style": "scss/checkbox.scss",
|
|
11
|
-
"types": "nds-checkbox.d.ts",
|
|
12
10
|
"directories": {
|
|
13
|
-
"lib": "
|
|
14
|
-
"test": "__tests__"
|
|
11
|
+
"lib": "es"
|
|
15
12
|
},
|
|
16
13
|
"files": [
|
|
17
|
-
"lib",
|
|
18
14
|
"es",
|
|
19
15
|
"scss",
|
|
20
16
|
"*.d.ts"
|
|
@@ -34,16 +30,20 @@
|
|
|
34
30
|
"url": "https://github.com/nice-digital/nice-design-system/issues"
|
|
35
31
|
},
|
|
36
32
|
"dependencies": {
|
|
37
|
-
"@nice-digital/nds-core": "^
|
|
38
|
-
"classnames": "^2.2.6"
|
|
39
|
-
"prop-types": "^15.7.2"
|
|
33
|
+
"@nice-digital/nds-core": "^4.0.1-alpha.0",
|
|
34
|
+
"classnames": "^2.2.6"
|
|
40
35
|
},
|
|
41
36
|
"peerDependencies": {
|
|
42
37
|
"react": "^16 || ^17 || ^18",
|
|
43
38
|
"react-dom": "^16 || ^17 || ^18"
|
|
44
39
|
},
|
|
45
40
|
"devDependencies": {
|
|
46
|
-
"@
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
"@testing-library/jest-dom": "^5.16.5",
|
|
42
|
+
"@testing-library/react": "^13.4.0",
|
|
43
|
+
"@testing-library/user-event": "^14.4.3",
|
|
44
|
+
"@types/jest": "^29.2.2",
|
|
45
|
+
"@types/node": "^18.11.9",
|
|
46
|
+
"typescript": "^4.8.4"
|
|
47
|
+
},
|
|
48
|
+
"gitHead": "e75957040c9acfbd7eeb164cad724e3b48760679"
|
|
49
49
|
}
|
package/es/Checkbox.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.js","names":["React","PropTypes","classnames","Checkbox","props","error","inline","name","label","value","hint","rest","unique","classNames","checkbox","length","propTypes","string","isRequired","node","bool","oneOfType"],"sources":["../src/Checkbox.js"],"sourcesContent":["import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport classnames from \"classnames\";\n\nimport \"../scss/checkbox.scss\";\n\nexport const Checkbox = (props) => {\n\tconst { error, inline, name, label, value, hint, ...rest } = props;\n\tif (!value) return null;\n\tconst unique = name + \"_\" + value;\n\tconst classNames = classnames({\n\t\tcheckbox: true,\n\t\t\"checkbox--inline\": inline,\n\t\t\"checkbox--error\": error\n\t});\n\treturn (\n\t\t<>\n\t\t\t{error && error.length && (\n\t\t\t\t<p className=\"checkbox__error-message\">{error}</p>\n\t\t\t)}\n\t\t\t<div className={classNames}>\n\t\t\t\t<div>\n\t\t\t\t\t<input\n\t\t\t\t\t\ttype=\"checkbox\"\n\t\t\t\t\t\tclassName=\"checkbox__input\"\n\t\t\t\t\t\tid={unique}\n\t\t\t\t\t\tname={name}\n\t\t\t\t\t\tvalue={value}\n\t\t\t\t\t\t{...rest}\n\t\t\t\t\t/>\n\t\t\t\t\t<label className=\"checkbox__label\" htmlFor={unique}>\n\t\t\t\t\t\t{label ? label : value}\n\t\t\t\t\t</label>\n\t\t\t\t\t{hint && <span className=\"checkbox__hint\">{hint}</span>}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</>\n\t);\n};\n\nCheckbox.propTypes = {\n\tname: PropTypes.string.isRequired,\n\tlabel: PropTypes.node.isRequired,\n\tvalue: PropTypes.string,\n\tinline: PropTypes.bool,\n\terror: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),\n\thint: PropTypes.string\n};\n\nexport default Checkbox;\n"],"mappings":";;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,SAAP,MAAsB,YAAtB;AACA,OAAOC,UAAP,MAAuB,YAAvB;AAEA,OAAO,uBAAP;AAEA,OAAO,IAAMC,QAAQ,GAAG,SAAXA,QAAW,CAACC,KAAD,EAAW;EAClC,IAAQC,KAAR,GAA6DD,KAA7D,CAAQC,KAAR;EAAA,IAAeC,MAAf,GAA6DF,KAA7D,CAAeE,MAAf;EAAA,IAAuBC,IAAvB,GAA6DH,KAA7D,CAAuBG,IAAvB;EAAA,IAA6BC,KAA7B,GAA6DJ,KAA7D,CAA6BI,KAA7B;EAAA,IAAoCC,KAApC,GAA6DL,KAA7D,CAAoCK,KAApC;EAAA,IAA2CC,IAA3C,GAA6DN,KAA7D,CAA2CM,IAA3C;EAAA,IAAoDC,IAApD,iCAA6DP,KAA7D;;EACA,IAAI,CAACK,KAAL,EAAY,OAAO,IAAP;EACZ,IAAMG,MAAM,GAAGL,IAAI,GAAG,GAAP,GAAaE,KAA5B;EACA,IAAMI,UAAU,GAAGX,UAAU,CAAC;IAC7BY,QAAQ,EAAE,IADmB;IAE7B,oBAAoBR,MAFS;IAG7B,mBAAmBD;EAHU,CAAD,CAA7B;EAKA,oBACC,0CACEA,KAAK,IAAIA,KAAK,CAACU,MAAf,iBACA;IAAG,SAAS,EAAC;EAAb,GAAwCV,KAAxC,CAFF,eAIC;IAAK,SAAS,EAAEQ;EAAhB,gBACC,8CACC;IACC,IAAI,EAAC,UADN;IAEC,SAAS,EAAC,iBAFX;IAGC,EAAE,EAAED,MAHL;IAIC,IAAI,EAAEL,IAJP;IAKC,KAAK,EAAEE;EALR,GAMKE,IANL,EADD,eASC;IAAO,SAAS,EAAC,iBAAjB;IAAmC,OAAO,EAAEC;EAA5C,GACEJ,KAAK,GAAGA,KAAH,GAAWC,KADlB,CATD,EAYEC,IAAI,iBAAI;IAAM,SAAS,EAAC;EAAhB,GAAkCA,IAAlC,CAZV,CADD,CAJD,CADD;AAuBA,CAhCM;AAkCPP,QAAQ,CAACa,SAAT,GAAqB;EACpBT,IAAI,EAAEN,SAAS,CAACgB,MAAV,CAAiBC,UADH;EAEpBV,KAAK,EAAEP,SAAS,CAACkB,IAAV,CAAeD,UAFF;EAGpBT,KAAK,EAAER,SAAS,CAACgB,MAHG;EAIpBX,MAAM,EAAEL,SAAS,CAACmB,IAJE;EAKpBf,KAAK,EAAEJ,SAAS,CAACoB,SAAV,CAAoB,CAACpB,SAAS,CAACgB,MAAX,EAAmBhB,SAAS,CAACmB,IAA7B,CAApB,CALa;EAMpBV,IAAI,EAAET,SAAS,CAACgB;AANI,CAArB;AASA,eAAed,QAAf"}
|
package/lib/Checkbox.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
exports.__esModule = true;
|
|
6
|
-
exports["default"] = exports.Checkbox = void 0;
|
|
7
|
-
|
|
8
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
-
|
|
10
|
-
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
11
|
-
|
|
12
|
-
var _react = _interopRequireDefault(require("react"));
|
|
13
|
-
|
|
14
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
15
|
-
|
|
16
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
|
17
|
-
|
|
18
|
-
require("../scss/checkbox.scss");
|
|
19
|
-
|
|
20
|
-
var _excluded = ["error", "inline", "name", "label", "value", "hint"];
|
|
21
|
-
|
|
22
|
-
var _jsxFileName = "C:\\dev\\nice-design-system\\components\\nds-checkbox\\src\\Checkbox.js",
|
|
23
|
-
_this = void 0;
|
|
24
|
-
|
|
25
|
-
var Checkbox = function Checkbox(props) {
|
|
26
|
-
var error = props.error,
|
|
27
|
-
inline = props.inline,
|
|
28
|
-
name = props.name,
|
|
29
|
-
label = props.label,
|
|
30
|
-
value = props.value,
|
|
31
|
-
hint = props.hint,
|
|
32
|
-
rest = (0, _objectWithoutPropertiesLoose2["default"])(props, _excluded);
|
|
33
|
-
if (!value) return null;
|
|
34
|
-
var unique = name + "_" + value;
|
|
35
|
-
var classNames = (0, _classnames["default"])({
|
|
36
|
-
checkbox: true,
|
|
37
|
-
"checkbox--inline": inline,
|
|
38
|
-
"checkbox--error": error
|
|
39
|
-
});
|
|
40
|
-
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, error && error.length && /*#__PURE__*/_react["default"].createElement("p", {
|
|
41
|
-
className: "checkbox__error-message",
|
|
42
|
-
__self: _this,
|
|
43
|
-
__source: {
|
|
44
|
-
fileName: _jsxFileName,
|
|
45
|
-
lineNumber: 19,
|
|
46
|
-
columnNumber: 5
|
|
47
|
-
}
|
|
48
|
-
}, error), /*#__PURE__*/_react["default"].createElement("div", {
|
|
49
|
-
className: classNames,
|
|
50
|
-
__self: _this,
|
|
51
|
-
__source: {
|
|
52
|
-
fileName: _jsxFileName,
|
|
53
|
-
lineNumber: 21,
|
|
54
|
-
columnNumber: 4
|
|
55
|
-
}
|
|
56
|
-
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
57
|
-
__self: _this,
|
|
58
|
-
__source: {
|
|
59
|
-
fileName: _jsxFileName,
|
|
60
|
-
lineNumber: 22,
|
|
61
|
-
columnNumber: 5
|
|
62
|
-
}
|
|
63
|
-
}, /*#__PURE__*/_react["default"].createElement("input", (0, _extends2["default"])({
|
|
64
|
-
type: "checkbox",
|
|
65
|
-
className: "checkbox__input",
|
|
66
|
-
id: unique,
|
|
67
|
-
name: name,
|
|
68
|
-
value: value
|
|
69
|
-
}, rest, {
|
|
70
|
-
__self: _this,
|
|
71
|
-
__source: {
|
|
72
|
-
fileName: _jsxFileName,
|
|
73
|
-
lineNumber: 23,
|
|
74
|
-
columnNumber: 6
|
|
75
|
-
}
|
|
76
|
-
})), /*#__PURE__*/_react["default"].createElement("label", {
|
|
77
|
-
className: "checkbox__label",
|
|
78
|
-
htmlFor: unique,
|
|
79
|
-
__self: _this,
|
|
80
|
-
__source: {
|
|
81
|
-
fileName: _jsxFileName,
|
|
82
|
-
lineNumber: 31,
|
|
83
|
-
columnNumber: 6
|
|
84
|
-
}
|
|
85
|
-
}, label ? label : value), hint && /*#__PURE__*/_react["default"].createElement("span", {
|
|
86
|
-
className: "checkbox__hint",
|
|
87
|
-
__self: _this,
|
|
88
|
-
__source: {
|
|
89
|
-
fileName: _jsxFileName,
|
|
90
|
-
lineNumber: 34,
|
|
91
|
-
columnNumber: 15
|
|
92
|
-
}
|
|
93
|
-
}, hint))));
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
exports.Checkbox = Checkbox;
|
|
97
|
-
Checkbox.propTypes = {
|
|
98
|
-
name: _propTypes["default"].string.isRequired,
|
|
99
|
-
label: _propTypes["default"].node.isRequired,
|
|
100
|
-
value: _propTypes["default"].string,
|
|
101
|
-
inline: _propTypes["default"].bool,
|
|
102
|
-
error: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].bool]),
|
|
103
|
-
hint: _propTypes["default"].string
|
|
104
|
-
};
|
|
105
|
-
var _default = Checkbox;
|
|
106
|
-
exports["default"] = _default;
|
|
107
|
-
//# sourceMappingURL=Checkbox.js.map
|
package/lib/Checkbox.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.js","names":["Checkbox","props","error","inline","name","label","value","hint","rest","unique","classNames","classnames","checkbox","length","propTypes","PropTypes","string","isRequired","node","bool","oneOfType"],"sources":["../src/Checkbox.js"],"sourcesContent":["import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport classnames from \"classnames\";\n\nimport \"../scss/checkbox.scss\";\n\nexport const Checkbox = (props) => {\n\tconst { error, inline, name, label, value, hint, ...rest } = props;\n\tif (!value) return null;\n\tconst unique = name + \"_\" + value;\n\tconst classNames = classnames({\n\t\tcheckbox: true,\n\t\t\"checkbox--inline\": inline,\n\t\t\"checkbox--error\": error\n\t});\n\treturn (\n\t\t<>\n\t\t\t{error && error.length && (\n\t\t\t\t<p className=\"checkbox__error-message\">{error}</p>\n\t\t\t)}\n\t\t\t<div className={classNames}>\n\t\t\t\t<div>\n\t\t\t\t\t<input\n\t\t\t\t\t\ttype=\"checkbox\"\n\t\t\t\t\t\tclassName=\"checkbox__input\"\n\t\t\t\t\t\tid={unique}\n\t\t\t\t\t\tname={name}\n\t\t\t\t\t\tvalue={value}\n\t\t\t\t\t\t{...rest}\n\t\t\t\t\t/>\n\t\t\t\t\t<label className=\"checkbox__label\" htmlFor={unique}>\n\t\t\t\t\t\t{label ? label : value}\n\t\t\t\t\t</label>\n\t\t\t\t\t{hint && <span className=\"checkbox__hint\">{hint}</span>}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</>\n\t);\n};\n\nCheckbox.propTypes = {\n\tname: PropTypes.string.isRequired,\n\tlabel: PropTypes.node.isRequired,\n\tvalue: PropTypes.string,\n\tinline: PropTypes.bool,\n\terror: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),\n\thint: PropTypes.string\n};\n\nexport default Checkbox;\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;;;;;;AAEO,IAAMA,QAAQ,GAAG,SAAXA,QAAW,CAACC,KAAD,EAAW;EAClC,IAAQC,KAAR,GAA6DD,KAA7D,CAAQC,KAAR;EAAA,IAAeC,MAAf,GAA6DF,KAA7D,CAAeE,MAAf;EAAA,IAAuBC,IAAvB,GAA6DH,KAA7D,CAAuBG,IAAvB;EAAA,IAA6BC,KAA7B,GAA6DJ,KAA7D,CAA6BI,KAA7B;EAAA,IAAoCC,KAApC,GAA6DL,KAA7D,CAAoCK,KAApC;EAAA,IAA2CC,IAA3C,GAA6DN,KAA7D,CAA2CM,IAA3C;EAAA,IAAoDC,IAApD,kDAA6DP,KAA7D;EACA,IAAI,CAACK,KAAL,EAAY,OAAO,IAAP;EACZ,IAAMG,MAAM,GAAGL,IAAI,GAAG,GAAP,GAAaE,KAA5B;EACA,IAAMI,UAAU,GAAG,IAAAC,sBAAA,EAAW;IAC7BC,QAAQ,EAAE,IADmB;IAE7B,oBAAoBT,MAFS;IAG7B,mBAAmBD;EAHU,CAAX,CAAnB;EAKA,oBACC,kEACEA,KAAK,IAAIA,KAAK,CAACW,MAAf,iBACA;IAAG,SAAS,EAAC,yBAAb;IAAA;IAAA;MAAA;MAAA;MAAA;IAAA;EAAA,GAAwCX,KAAxC,CAFF,eAIC;IAAK,SAAS,EAAEQ,UAAhB;IAAA;IAAA;MAAA;MAAA;MAAA;IAAA;EAAA,gBACC;IAAA;IAAA;MAAA;MAAA;MAAA;IAAA;EAAA,gBACC;IACC,IAAI,EAAC,UADN;IAEC,SAAS,EAAC,iBAFX;IAGC,EAAE,EAAED,MAHL;IAIC,IAAI,EAAEL,IAJP;IAKC,KAAK,EAAEE;EALR,GAMKE,IANL;IAAA;IAAA;MAAA;MAAA;MAAA;IAAA;EAAA,GADD,eASC;IAAO,SAAS,EAAC,iBAAjB;IAAmC,OAAO,EAAEC,MAA5C;IAAA;IAAA;MAAA;MAAA;MAAA;IAAA;EAAA,GACEJ,KAAK,GAAGA,KAAH,GAAWC,KADlB,CATD,EAYEC,IAAI,iBAAI;IAAM,SAAS,EAAC,gBAAhB;IAAA;IAAA;MAAA;MAAA;MAAA;IAAA;EAAA,GAAkCA,IAAlC,CAZV,CADD,CAJD,CADD;AAuBA,CAhCM;;;AAkCPP,QAAQ,CAACc,SAAT,GAAqB;EACpBV,IAAI,EAAEW,qBAAA,CAAUC,MAAV,CAAiBC,UADH;EAEpBZ,KAAK,EAAEU,qBAAA,CAAUG,IAAV,CAAeD,UAFF;EAGpBX,KAAK,EAAES,qBAAA,CAAUC,MAHG;EAIpBb,MAAM,EAAEY,qBAAA,CAAUI,IAJE;EAKpBjB,KAAK,EAAEa,qBAAA,CAAUK,SAAV,CAAoB,CAACL,qBAAA,CAAUC,MAAX,EAAmBD,qBAAA,CAAUI,IAA7B,CAApB,CALa;EAMpBZ,IAAI,EAAEQ,qBAAA,CAAUC;AANI,CAArB;eASehB,Q"}
|
package/nds-checkbox.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
declare module "@nice-digital/nds-checkbox" {
|
|
2
|
-
import React = require("react");
|
|
3
|
-
|
|
4
|
-
export interface CheckboxProps {
|
|
5
|
-
/** Allow any additional props to be passed and applied to the checkbox */
|
|
6
|
-
[prop: string]: unknown;
|
|
7
|
-
/** The name attribute for the checkbox */
|
|
8
|
-
name: string;
|
|
9
|
-
/** The label for the checkbox. If none supplied will use the value */
|
|
10
|
-
label?: React.ReactNode;
|
|
11
|
-
/** The value for the checkbox */
|
|
12
|
-
value: string;
|
|
13
|
-
/** Add to checkboxes that you would like to display inline, left to right */
|
|
14
|
-
inline?: boolean;
|
|
15
|
-
/** Option for putting the checkbox into a visual error state. Set to true for error styling or supply a string for error styling and addional error text*/
|
|
16
|
-
error?: boolean | string;
|
|
17
|
-
/** Add hint text for extra context to the checkbox */
|
|
18
|
-
hint?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const Checkbox: React.FC<CheckboxProps>;
|
|
22
|
-
}
|