lucid-ui
Version:
A UI component library from AppNexus.
95 lines • 7.88 kB
JavaScript
"use strict";
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
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 __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Checkbox = exports.defaultProps = void 0;
var lodash_1 = __importDefault(require("lodash"));
var react_1 = __importDefault(require("react"));
var prop_types_1 = __importDefault(require("react-peek/prop-types"));
var style_helpers_1 = require("../../util/style-helpers");
var component_types_1 = require("../../util/component-types");
var cx = style_helpers_1.lucidClassNames.bind('&-Checkbox');
var bool = prop_types_1.default.bool, func = prop_types_1.default.func, object = prop_types_1.default.object, string = prop_types_1.default.string;
exports.defaultProps = {
isIndeterminate: false,
isDisabled: false,
isSelected: false,
onSelect: lodash_1.default.noop,
};
var Checkbox = function (props) {
var className = props.className, isIndeterminate = props.isIndeterminate, isSelected = props.isSelected, isDisabled = props.isDisabled, style = props.style, title = props.title, onSelect = props.onSelect, passThroughs = __rest(props, ["className", "isIndeterminate", "isSelected", "isDisabled", "style", "title", "onSelect"]);
var nativeElement = react_1.default.createRef();
function handleSpanClick(e) {
e.preventDefault();
}
function handleClicked(event) {
if (!isDisabled && onSelect) {
onSelect(!isSelected, { event: event, props: props });
if (nativeElement.current) {
nativeElement.current.focus();
}
}
}
return (react_1.default.createElement("div", { className: cx('&', {
'&-is-disabled': isDisabled,
'&-is-selected': isIndeterminate || isSelected,
}, className), onClick: handleClicked, style: style, title: title },
react_1.default.createElement("input", __assign({ onChange: lodash_1.default.noop }, component_types_1.omitProps(passThroughs, undefined, ['children'].concat(lodash_1.default.keys(exports.Checkbox.propTypes))), { checked: isSelected, className: cx('&-native'), disabled: isDisabled, ref: nativeElement, title: title, type: 'checkbox' })),
react_1.default.createElement("span", { onClick: handleSpanClick, className: cx('&-visualization-glow') }),
react_1.default.createElement("span", { onClick: handleSpanClick, className: cx('&-visualization-container') }),
isIndeterminate ? (react_1.default.createElement("span", { onClick: handleSpanClick, className: cx('&-visualization-indeterminate') },
react_1.default.createElement("span", { className: cx('&-visualization-indeterminate-line') }))) : (react_1.default.createElement("span", { onClick: handleSpanClick, className: cx('&-visualization-checkmark') },
react_1.default.createElement("span", { className: cx('&-visualization-checkmark-stem') }),
react_1.default.createElement("span", { className: cx('&-visualization-checkmark-kick') })))));
};
exports.Checkbox = Checkbox;
exports.Checkbox.displayName = 'Checkbox';
exports.Checkbox.peek = {
description: "\n\t\tCheckbox is a square two-state toggle used to create `CheckboxLabeled`.\n\n\t\tIt uses a hidden native checkbox control under the hood but leverages\n\t\tother HTML elements to visualize its state.\n\t",
notes: {
overview: "\n\t\t\tCheckbox is a square two-state toggle. Use `CheckboxLabeled` in your applications.\n\t\t",
intendedUse: "\n\t\t\tUsed to create `CheckboxLabeled`. \t\t\t\n\t\t",
technicalRecommendations: "\n\t\t\t- Use the Selected state when a filter or setting will be applied.\n\t\t\t- Use the Unselected state when a filter or setting will not be applied.\n\t\t\t- Use the Indeterminate state for parent checkboxes where some of the child checkboxes are Selected and some are Unselected. For example, the master checkbox in the header row of the interactive table example in `DataTable`.\n\t\t",
},
categories: ['controls', 'toggles'],
};
exports.Checkbox.defaultProps = exports.defaultProps;
exports.Checkbox.propTypes = {
className: string(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n\t\tAppended to the component-specific class names set on the root element.\n\t"], ["\n\t\tAppended to the component-specific class names set on the root element.\n\t"]))),
isIndeterminate: bool(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n\t\tIndicates whether the component should appear in an \"indeterminate\" or\n\t\t\"partially checked\" state. This prop takes precedence over\n\t\t`isSelected`.\n\t"], ["\n\t\tIndicates whether the component should appear in an \"indeterminate\" or\n\t\t\"partially checked\" state. This prop takes precedence over\n\t\t\\`isSelected\\`.\n\t"]))),
isDisabled: bool(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n\t\tIndicates whether the component should appear and act disabled by having\n\t\ta \"greyed out\" palette and ignoring user interactions.\n\t"], ["\n\t\tIndicates whether the component should appear and act disabled by having\n\t\ta \"greyed out\" palette and ignoring user interactions.\n\t"]))),
isSelected: bool(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n\t\tIndicates that the component is in the \"selected\" state when true and in\n\t\tthe \"unselected\" state when false. This props is ignored if\n\t\t`isIndeterminate` is `true`.\n\t"], ["\n\t\tIndicates that the component is in the \"selected\" state when true and in\n\t\tthe \"unselected\" state when false. This props is ignored if\n\t\t\\`isIndeterminate\\` is \\`true\\`.\n\t"]))),
onSelect: func(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n\t\tCalled when the user clicks on the component or when they press the space\n\t\tkey while the component is in focus. Signature:\n\t\t`(isSelected, { event, props }) => {}`\n\t"], ["\n\t\tCalled when the user clicks on the component or when they press the space\n\t\tkey while the component is in focus. Signature:\n\t\t\\`(isSelected, { event, props }) => {}\\`\n\t"]))),
style: object(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n\t\tPassed through to the root element.\n\t"], ["\n\t\tPassed through to the root element.\n\t"]))),
title: string(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n\t\tA string title that is displayed on hover.\n\t"], ["\n\t\tA string title that is displayed on hover.\n\t"]))),
};
exports.default = exports.Checkbox;
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7;
//# sourceMappingURL=Checkbox.js.map