UNPKG

lucid-ui

Version:

A UI component library from AppNexus.

103 lines 7.03 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.Switch = void 0; var lodash_1 = __importDefault(require("lodash")); var react_1 = __importStar(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('&-Switch'); 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; var defaultProps = { isDisabled: false, isSelected: false, onSelect: lodash_1.default.noop, isIncludeExclude: false, }; var Switch = function (props) { var className = props.className, isDisabled = props.isDisabled, isSelected = props.isSelected, style = props.style, isIncludeExclude = props.isIncludeExclude, onSelect = props.onSelect, passThroughs = __rest(props, ["className", "isDisabled", "isSelected", "style", "isIncludeExclude", "onSelect"]); var nativeElement = react_1.createRef(); function handleClicked(event) { event.preventDefault(); if (!isDisabled) { onSelect(!isSelected, { event: event, props: props }); if (nativeElement.current) { nativeElement.current.focus(); } } } return (react_1.default.createElement("span", { className: cx('&', { '&-is-disabled': isDisabled, '&-is-selected': isSelected, '&-is-include-exclude': isIncludeExclude, }, className), onClick: handleClicked, onTouchEnd: handleClicked, style: style }, react_1.default.createElement("input", __assign({ onChange: lodash_1.default.noop }, component_types_1.omitProps(passThroughs, undefined, ['children'].concat(lodash_1.default.keys(exports.Switch.propTypes))), { checked: isSelected, className: cx('&-native'), disabled: isDisabled, ref: nativeElement, type: 'checkbox' })), react_1.default.createElement("span", { className: cx('&-visualization-container') }), react_1.default.createElement("span", { className: cx('&-visualization-handle') }))); }; exports.Switch = Switch; exports.Switch.defaultProps = defaultProps; exports.Switch.displayName = 'Switch'; exports.Switch.peek = { description: "\n\t\t\t\tThis is a toggle -- a component that is in one of two particular states\n\t\t\t\tat any given moment in time -- that uses a visualization of a physical\n\t\t\t\ton/off switch made popular by smartphone OSes to reflect its current\n\t\t\t\tstate.\n\n\t\t\t\tIt uses a hidden native check box control under the hood but leverages\n\t\t\t\tother HTML elements to visualize its state.\n\t\t\t", categories: ['controls', 'toggles'], }; exports.Switch.propTypes = { className: string(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n\t\t\tAppended to the component-specific class names set on the root element.\n\t\t"], ["\n\t\t\tAppended to the component-specific class names set on the root element.\n\t\t"]))), isDisabled: bool(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n\t\t\tIndicates whether the component should appear and act disabled by having\n\t\t\ta \"greyed out\" palette and ignoring user interactions.\n\t\t"], ["\n\t\t\tIndicates whether the component should appear and act disabled by having\n\t\t\ta \"greyed out\" palette and ignoring user interactions.\n\t\t"]))), isSelected: bool(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n\t\t\tIndicates that the component is in the \"selected\" state when true and in\n\t\t\tthe \"unselected\" state when false.\n\t\t"], ["\n\t\t\tIndicates that the component is in the \"selected\" state when true and in\n\t\t\tthe \"unselected\" state when false.\n\t\t"]))), onSelect: func(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n\t\t\tCalled when the user clicks on the component or when they press the space\n\t\t\tkey while the component is in focus. Signature:\n\t\t\t`(isSelected, { event, props }) => {}`\n\t\t"], ["\n\t\t\tCalled when the user clicks on the component or when they press the space\n\t\t\tkey while the component is in focus. Signature:\n\t\t\t\\`(isSelected, { event, props }) => {}\\`\n\t\t"]))), style: object(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n\t\t\tPassed through to the root element.\n\t\t"], ["\n\t\t\tPassed through to the root element.\n\t\t"]))), isIncludeExclude: bool(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n\t\t\tOffers a red/green styling to the switch.\n\t\t"], ["\n\t\t\tOffers a red/green styling to the switch.\n\t\t"]))), }; exports.default = exports.Switch; var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6; //# sourceMappingURL=Switch.js.map