UNPKG

lucid-ui

Version:

A UI component library from Xandr.

128 lines 6.34 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 __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("prop-types")); var style_helpers_1 = require("../../util/style-helpers"); 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; /** TODO: Remove nonPassThroughs when the component is converted to a functional component */ var nonPassThroughs = [ 'children', 'className', 'isIndeterminate', 'isDisabled', 'isSelected', 'onSelect', 'style', 'title', ]; 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 }, lodash_1.default.omit(passThroughs, nonPassThroughs), { 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: "`Checkbox` is a square two-state toggle used to create `CheckboxLabeled`. It uses a hidden native `Checkbox` control under the hood but leverages other `HTML` elements to visualize its state.", 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 = { /** Appended to the component-specific class names set on the root element. */ className: string, /** 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, /** Passed through to the root element. */ style: object, /** A string title that is displayed on hover. */ title: string, }; exports.default = exports.Checkbox; //# sourceMappingURL=Checkbox.js.map