lucid-ui
Version:
A UI component library from Xandr.
126 lines • 5.62 kB
JavaScript
;
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 = __importStar(require("lodash"));
var react_1 = __importStar(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('&-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 = (0, 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 }, (0, lodash_1.omit)(passThroughs, [
'className',
'isDisabled',
'isSelected',
'onSelect',
'style',
'isIncludeExclude',
].concat(['initialState', 'callbackId', 'children'])), { 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: "A toggle -- a component that is in one of two particular states at any given moment in time -- that uses a visualization of a physical on/off switch made popular by smartphone OSes to reflect its current state. It uses a hidden native check box control under the hood but leverages other `HTML` elements to visualize its state.",
categories: ['controls', 'toggles'],
};
exports.Switch.propTypes = {
/**
Appended to the component-specific class names set on the root element.
*/
className: string,
/**
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.
*/
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,
/**
Offers a red/green styling to the switch.
*/
isIncludeExclude: bool,
};
exports.default = exports.Switch;
//# sourceMappingURL=Switch.js.map