react-elegant-ui
Version:
Elegant UI components, made by BEM best practices for react
83 lines • 3.19 kB
JavaScript
var __assign = this && this.__assign || function () {
__assign = Object.assign || function (t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __read = this && this.__read || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o),
r,
ar = [],
e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
} catch (error) {
e = {
error: error
};
} finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
} finally {
if (e) throw e.error;
}
}
return ar;
};
import React, { useEffect, useRef, useState } from 'react';
import { useUniqueId } from '../../../hooks/useUniqueId';
import { Checkbox } from '../Checkbox.bundle/desktop';
var verbose = true;
export var CheckboxWithState = function (props) {
var _a = __read(useState(props.checked), 2),
isEnabled = _a[0],
setState = _a[1];
var toggleCounter = useRef(0);
useEffect(function () {
var _a;
if (!verbose) return;
// Skip init
if (toggleCounter.current++ === 0) return;
console.log("checkbox \"".concat((_a = props.label) !== null && _a !== void 0 ? _a : 'unknown', "\" toggle to"), isEnabled);
}, [isEnabled, props.label]);
return /*#__PURE__*/React.createElement(Checkbox, __assign({}, props, {
checked: !!isEnabled,
setChecked: setState
}));
};
export var BaseCheckbox = function () {
var liClass = useUniqueId('exampleList');
var style = "\n\t\t.".concat(liClass, " {\n\t\t\tlist-style: none;\n\t\t\tmargin: 0;\n\t\t\tpadding: 0;\n\t\t}\n\n\t\t.").concat(liClass, " li:not(:last-child) {\n\t\t\tmargin-bottom: .5rem;\n\t\t}\n\t");
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("style", null, style), /*#__PURE__*/React.createElement("ul", {
className: liClass
}, Array(4).fill(0).map(function (_, idx) {
var disabled = idx > 1;
return /*#__PURE__*/React.createElement("li", {
key: idx
}, /*#__PURE__*/React.createElement(CheckboxWithState, {
label: "Checkbox #".concat(idx + 1) + (disabled ? ' (disabled)' : ''),
disabled: disabled,
checked: (idx + 1) % 2 !== 0
}));
}), /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement(CheckboxWithState, {
label: /*#__PURE__*/React.createElement("span", null, "Some text ", /*#__PURE__*/React.createElement("strong", null, "as node")),
checked: true
})), /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement(CheckboxWithState, {
label: "Indeterminate checkbox",
indeterminate: true
}))));
};
export var CheckboxInlineExample = function () {
return /*#__PURE__*/React.createElement("div", null, "Choose between ", /*#__PURE__*/React.createElement(CheckboxWithState, {
label: "some value"
}), " and some", ' ', /*#__PURE__*/React.createElement(CheckboxWithState, {
label: "other value",
size: "s"
}));
};