UNPKG

lucid-ui

Version:

A UI component library from AppNexus.

109 lines 9.09 kB
"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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; 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.CheckboxLabeled = 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 Checkbox_1 = __importStar(require("../Checkbox/Checkbox")); var cx = style_helpers_1.lucidClassNames.bind('&-CheckboxLabeled'); var any = prop_types_1.default.any, node = prop_types_1.default.node, object = prop_types_1.default.object, string = prop_types_1.default.string, bool = prop_types_1.default.bool, func = prop_types_1.default.func; var Label = function (props) { return null; }; Label.displayName = 'CheckboxLabeled.Label'; Label.peek = { description: "\n\t\tRenders a `label` for the `Checkbox`\n\t", categories: ['controls', 'toggles'], madeFrom: ['Checkbox'], }; Label.propName = 'Label'; Label.propTypes = { children: node(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n\t\tUsed to identify the purpose of this checkbox to the user -- can be\n\t\tany renderable content.\n\t"], ["\n\t\tUsed to identify the purpose of this checkbox to the user -- can be\n\t\tany renderable content.\n\t"]))), }; var CheckboxLabeled = function (props) { var className = props.className, isIndeterminate = props.isIndeterminate, isDisabled = props.isDisabled, isSelected = props.isSelected, onSelect = props.onSelect, style = props.style, passThroughs = __rest(props, ["className", "isIndeterminate", "isDisabled", "isSelected", "onSelect", "style"]); var labelChildProps = lodash_1.default.first(lodash_1.default.map(component_types_1.findTypes(props, exports.CheckboxLabeled.Label), 'props')); return (react_1.default.createElement("label", { className: cx('&', { '&-is-disabled': isDisabled, '&-is-selected': isIndeterminate || isSelected, }, className), style: style }, react_1.default.createElement(Checkbox_1.default, __assign({ className: cx('&-Checkbox', className), isDisabled: isDisabled, isIndeterminate: isIndeterminate, isSelected: isSelected, onSelect: onSelect }, component_types_1.omitProps(passThroughs, undefined, lodash_1.default.keys(exports.CheckboxLabeled.propTypes), false))), react_1.default.createElement("div", __assign({}, labelChildProps, { className: cx('&-label', lodash_1.default.get(labelChildProps, 'className', null)) })))); }; exports.CheckboxLabeled = CheckboxLabeled; exports.CheckboxLabeled.displayName = 'CheckboxLabeled'; exports.CheckboxLabeled.peek = { description: "\n\t", notes: { overview: "\n\t\t\tA square two-state toggle with a label that explains the action or selection. This is a composite of `Checkbox` and the native\n\t\t\t`label` element.\n\t\t", intendedUse: "\n\t\t\tUse checkboxes to allow users to select one or more items. Commonly used to select filters or settings. For interactions where users can only select one option, use `RadioButtonLabeled`.\n\t\t", technicalRecommendations: "\n\t\t\t- Use the styles on the `CheckboxLabeled` parent container to ensure only the checkboxes and their labels are clickable.\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\t- You can have the label as a child or a prop depending on the needs of your application. \n\t\t", }, categories: ['controls', 'toggles'], madeFrom: ['Checkbox'], }; exports.CheckboxLabeled.defaultProps = Checkbox_1.defaultProps; // Can't just `...Checkbox.propTypes` anymore because of the way we have to // handle default props. They are duplicated here on purpose which is okay // since in the future we'll be removing proptypes in favor is just typescript. exports.CheckboxLabeled.propTypes = { 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"]))), className: string(templateObject_6 || (templateObject_6 = __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"]))), style: object(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n\t\tPassed through to the root element.\n\t"], ["\n\t\tPassed through to the root element.\n\t"]))), Label: any(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n\t\tChild element whose children are used to identify the purpose of this\n\t\tcheckbox to the user.\n\t"], ["\n\t\tChild element whose children are used to identify the purpose of this\n\t\tcheckbox to the user.\n\t"]))), }; exports.CheckboxLabeled.Label = Label; exports.default = exports.CheckboxLabeled; var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8; //# sourceMappingURL=CheckboxLabeled.js.map