lucid-ui
Version:
A UI component library from AppNexus.
100 lines • 7.12 kB
JavaScript
"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 __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 __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RadioButton = exports.defaultProps = 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 cx = style_helpers_1.lucidClassNames.bind('&-RadioButton');
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;
exports.defaultProps = {
isDisabled: false,
isSelected: false,
onSelect: lodash_1.default.noop,
};
var RadioButton = function (props) {
var className = props.className, isDisabled = props.isDisabled, isSelected = props.isSelected, onSelect = props.onSelect, style = props.style, passThroughs = __rest(props, ["className", "isDisabled", "isSelected", "onSelect", "style"]);
var nativeElement = react_1.default.createRef();
function handleClicked(event) {
if (!isDisabled && !isSelected) {
onSelect(true, { event: event, props: props });
if (nativeElement.current) {
nativeElement.current.focus();
}
}
}
function handleSpanClick(e) {
e.preventDefault();
}
return (react_1.default.createElement("span", { className: cx('&', {
'&-is-disabled': isDisabled,
'&-is-selected': isSelected,
}, className), onClick: handleClicked, style: style },
react_1.default.createElement("input", __assign({ onChange: lodash_1.default.noop }, component_types_1.omitProps(passThroughs, undefined, __spreadArrays(lodash_1.default.keys(exports.RadioButton.propTypes), [
'children',
'callbackId',
])), { checked: isSelected, className: cx('&-native'), disabled: isDisabled, ref: nativeElement, type: 'radio' })),
react_1.default.createElement("span", { onClick: handleSpanClick, className: cx('&-visualization-glow') }),
react_1.default.createElement("span", { onClick: handleSpanClick, className: cx('&-visualization-container') }),
react_1.default.createElement("span", { onClick: handleSpanClick, className: cx('&-visualization-dot') })));
};
exports.RadioButton = RadioButton;
exports.RadioButton.defaultProps = exports.defaultProps;
exports.RadioButton.displayName = 'RadioButton';
exports.RadioButton.peek = {
description: "\n\t\tRadioButton is a round two-state toggle used to create `RadioButtonLabeled`.\n\n\t\tIt uses a hidden native checkbox control under the hood but leverages\n\t\tother HTML elements to visualize its state.\n\t\t",
notes: {
overview: "\n\t\t\tRadioButton is a round two-state toggle. Use `RadioButtonLabeled` or `RadioGroup` in your applications.\n\t\t",
intendedUse: "\n\t\t\tUsed to create `RadioButtonLabeled` and `RadioGroup`. \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- Any props that are not explicitly defined in `propTypes` are passed to the native radio button control.\n\t\t",
},
categories: ['controls', 'toggles'],
};
exports.RadioButton.propTypes = {
className: string(templateObject_1 || (templateObject_1 = __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"]))),
isDisabled: bool(templateObject_2 || (templateObject_2 = __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_3 || (templateObject_3 = __makeTemplateObject(["\n\t\tIndicates that the component is in the \"selected\" state when true and in\n\t\tthe \"unselected\" state when false.\n\t"], ["\n\t\tIndicates that the component is in the \"selected\" state when true and in\n\t\tthe \"unselected\" state when false.\n\t"]))),
name: string(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n\tOptional name for the input element.\n\t"], ["\n\tOptional name for the input element.\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, and only called when the component\n\t\tis in the unselected state. Signature: `(true, { 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, and only called when the component\n\t\tis in the unselected state. Signature: \\`(true, { event, props }) => {}\\`\n\t"]))),
style: object(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n\t\tPassed through to the root element.\n\t"], ["\n\t\tPassed through to the root element.\n\t"]))),
};
exports.default = exports.RadioButton;
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6;
//# sourceMappingURL=RadioButton.js.map