UNPKG

lucid-ui

Version:

A UI component library from Xandr.

149 lines 7.43 kB
"use strict"; 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("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: "Renders a `Label` for the `Checkbox`.", categories: ['controls', 'toggles'], madeFrom: ['Checkbox'], }; Label.propName = 'Label'; Label.propTypes = { /** Used to identify the purpose of this checkbox to the user -- can be any renderable content. */ children: node, }; /** Checkbox Labeled */ /** TODO: Remove the nonPassThroughs when the component is converted to a functional component */ var nonPassThroughs = [ 'isIndeterminate', 'isDisabled', 'isSelected', 'onSelect', 'className', 'style', 'Label', 'initialState', ]; 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((0, 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 }, lodash_1.default.omit(passThroughs, nonPassThroughs))), 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: "A square two-state toggle with a `Label`.", notes: { overview: "A square two-state toggle with a label that explains the action or selection. This is a composite of `Checkbox` and the native `label` element.", intendedUse: "Use 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`.", 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 of just typescript. exports.CheckboxLabeled.propTypes = { /** Indicates whether the component should appear in an "indeterminate" or "partially checked" state. This prop takes precedence over \`isSelected\`. */ isIndeterminate: bool, /** Indicates whether the component should appear and act disabled by having a "greyed out" palette and ignoring user interactions. */ isDisabled: bool, /** Indicates that the component is in the "selected" state when true and in the "unselected" state when false. This props is ignored if \`isIndeterminate\` is \`true\`. */ isSelected: bool, /** Called when the user clicks on the component or when they press the space key while the component is in focus. Signature: \`(isSelected, { event, props }) => {}\` */ onSelect: func, /** Appended to the component-specific class names set on the root element. */ className: string, /** Passed through to the root element. */ style: object, /** Child element whose children are used to identify the purpose of this checkbox to the user. */ Label: any, }; exports.CheckboxLabeled.Label = Label; exports.default = exports.CheckboxLabeled; //# sourceMappingURL=CheckboxLabeled.js.map