Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tds/core-checkbox

Package Overview
Dependencies
Maintainers
6
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tds/core-checkbox - npm Package Compare versions

Comparing version 1.1.3 to 1.1.4

LICENSE

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

## [1.1.4](https://github.com/telusdigital/tds/compare/@tds/core-checkbox@1.1.3...@tds/core-checkbox@1.1.4) (2019-02-06)
**Note:** Version bump only for package @tds/core-checkbox
<a name="1.1.3"></a>

@@ -8,0 +16,0 @@ ## [1.1.3](https://github.com/telusdigital/tds/compare/@tds/core-checkbox@1.1.2...@tds/core-checkbox@1.1.3) (2018-12-19)

444

dist/index.cjs.js

@@ -7,2 +7,3 @@ 'use strict';

var PropTypes = _interopDefault(require('prop-types'));
var DecorativeIcon = _interopDefault(require('@tds/core-decorative-icon'));
var Text = _interopDefault(require('@tds/core-text'));

@@ -12,45 +13,61 @@ var Paragraph = _interopDefault(require('@tds/core-paragraph'));

var InputFeedback = _interopDefault(require('@tds/core-input-feedback'));
var DecorativeIcon = _interopDefault(require('@tds/core-decorative-icon'));
var classCallCheck = function (instance, Constructor) {
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
}
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
var _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
return obj;
}
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
}
return target;
};
return target;
};
var inherits = function (subClass, superClass) {
return _extends.apply(this, arguments);
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
throw new TypeError("Super expression must either be null or a function");
}

@@ -61,3 +78,2 @@

value: subClass,
enumerable: false,
writable: true,

@@ -67,29 +83,78 @@ configurable: true

});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};
if (superClass) _setPrototypeOf(subClass, superClass);
}
var objectWithoutProperties = function (obj, keys) {
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (var i in obj) {
if (keys.indexOf(i) >= 0) continue;
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
target[i] = obj[i];
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
};
}
var possibleConstructorReturn = function (self, call) {
if (!self) {
function _objectWithoutProperties(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for (i = 0; i < sourceSymbolKeys.length; i++) {
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
};
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
}
return _assertThisInitialized(self);
}
var safeRest = (function (_ref) {
var style = _ref.style,
className = _ref.className,
props = objectWithoutProperties(_ref, ["style", "className"]);
props = _objectWithoutProperties(_ref, ["style", "className"]);
return props;

@@ -99,3 +164,3 @@ });

var joinClassNames = function joinClassNames() {
for (var _len = arguments.length, classes = Array(_len), _key = 0; _key < _len; _key++) {
for (var _len = arguments.length, classes = new Array(_len), _key = 0; _key < _len; _key++) {
classes[_key] = arguments[_key];

@@ -110,6 +175,6 @@ }

var capitalize = function capitalize(string) {
return "" + string.charAt(0).toUpperCase() + string.slice(1);
return "".concat(string.charAt(0).toUpperCase()).concat(string.slice(1));
};
var styles = { "column": "TDS_Flexbox-modules__column___1vj4G", "row": "TDS_Flexbox-modules__row___5CSCg", "justifyContentSpaceBetween": "TDS_Flexbox-modules__justifyContentSpaceBetween___3eG3e" };
var styles = {"column":"TDS_Flexbox-modules__column___1vj4G","row":"TDS_Flexbox-modules__row___5CSCg","justifyContentSpaceBetween":"TDS_Flexbox-modules__justifyContentSpaceBetween___3eG3e"};

@@ -121,11 +186,8 @@ var Flexbox = function Flexbox(_ref) {

children = _ref.children,
rest = objectWithoutProperties(_ref, ['direction', 'justifyContent', 'dangerouslyAddClassName', 'children']);
rest = _objectWithoutProperties(_ref, ["direction", "justifyContent", "dangerouslyAddClassName", "children"]);
var classNames = joinClassNames(styles[direction], justifyContent && styles['justifyContent' + capitalize(justifyContent)], dangerouslyAddClassName);
return React.createElement(
'div',
_extends({}, safeRest(rest), { className: classNames }),
children
);
var classNames = joinClassNames(styles[direction], justifyContent && styles["justifyContent".concat(capitalize(justifyContent))], dangerouslyAddClassName);
return React.createElement("div", _extends({}, safeRest(rest), {
className: classNames
}), children);
};

@@ -139,3 +201,2 @@

};
Flexbox.defaultProps = {

@@ -146,12 +207,15 @@ justifyContent: undefined,

var ColoredTextProvider = function (_React$Component) {
inherits(ColoredTextProvider, _React$Component);
var ColoredTextProvider =
/*#__PURE__*/
function (_React$Component) {
_inherits(ColoredTextProvider, _React$Component);
function ColoredTextProvider() {
classCallCheck(this, ColoredTextProvider);
return possibleConstructorReturn(this, (ColoredTextProvider.__proto__ || Object.getPrototypeOf(ColoredTextProvider)).apply(this, arguments));
_classCallCheck(this, ColoredTextProvider);
return _possibleConstructorReturn(this, _getPrototypeOf(ColoredTextProvider).apply(this, arguments));
}
createClass(ColoredTextProvider, [{
key: 'getChildContext',
_createClass(ColoredTextProvider, [{
key: "getChildContext",
value: function getChildContext() {

@@ -163,13 +227,14 @@ return {

}, {
key: 'render',
key: "render",
value: function render() {
var _props = this.props,
colorClassName = _props.colorClassName,
tag = _props.tag,
children = _props.children;
return React.createElement(tag, { className: colorClassName }, children);
var _this$props = this.props,
colorClassName = _this$props.colorClassName,
tag = _this$props.tag,
children = _this$props.children;
return React.createElement(tag, {
className: colorClassName
}, children);
}
}]);
return ColoredTextProvider;

@@ -183,7 +248,5 @@ }(React.Component);

};
ColoredTextProvider.defaultProps = {
tag: 'div'
};
ColoredTextProvider.childContextTypes = {

@@ -200,3 +263,3 @@ inheritColor: PropTypes.bool

var generateId = function generateId() {
for (var _len = arguments.length, choices = Array(_len), _key = 0; _key < _len; _key++) {
for (var _len = arguments.length, choices = new Array(_len), _key = 0; _key < _len; _key++) {
choices[_key] = arguments[_key];

@@ -208,3 +271,2 @@ }

}));
return {

@@ -215,3 +277,3 @@ identity: function identity() {

postfix: function postfix(value) {
return id + '_' + sanitize(value);
return "".concat(id, "_").concat(sanitize(value));
}

@@ -221,5 +283,5 @@ };

var styles$1 = { "alignCenter": "TDS_Choice-modules__alignCenter___1M8FG", "alignFlexStart": "TDS_Choice-modules__alignFlexStart___1zDGw", "flexOne": "TDS_Choice-modules__flexOne___1SrBe", "fakeInput": "TDS_Choice-modules__fakeInput___3I1CX TDS_Borders-modules__thin___1JHOl", "fakeCheckbox": "TDS_Choice-modules__fakeCheckbox___1Buqb TDS_Choice-modules__fakeInput___3I1CX TDS_Borders-modules__thin___1JHOl TDS_Borders-modules__rounded___3df1Q", "fakeRadio": "TDS_Choice-modules__fakeRadio___1H3I- TDS_Choice-modules__fakeInput___3I1CX TDS_Borders-modules__thin___1JHOl TDS_Borders-modules__circular___OppHT", "unchecked": "TDS_Choice-modules__unchecked___3Zyro", "focused": "TDS_Choice-modules__focused___2KPRk", "error": "TDS_Choice-modules__error___1Vlds", "hiddenInput": "TDS_Choice-modules__hiddenInput___3S8As" };
var styles$1 = {"alignCenter":"TDS_Choice-modules__alignCenter___1M8FG","alignFlexStart":"TDS_Choice-modules__alignFlexStart___1zDGw","flexOne":"TDS_Choice-modules__flexOne___1SrBe","fakeInput":"TDS_Choice-modules__fakeInput___3I1CX TDS_Borders-modules__thin___1JHOl","fakeCheckbox":"TDS_Choice-modules__fakeCheckbox___1Buqb TDS_Choice-modules__fakeInput___3I1CX TDS_Borders-modules__thin___1JHOl TDS_Borders-modules__rounded___3df1Q","fakeRadio":"TDS_Choice-modules__fakeRadio___1H3I- TDS_Choice-modules__fakeInput___3I1CX TDS_Borders-modules__thin___1JHOl TDS_Borders-modules__circular___OppHT","unchecked":"TDS_Choice-modules__unchecked___3Zyro","focused":"TDS_Choice-modules__focused___2KPRk","error":"TDS_Choice-modules__error___1Vlds","hiddenInput":"TDS_Choice-modules__hiddenInput___3S8As"};
var messagingStyles = { "default": "TDS_Messaging-modules__default___2B8Di", "success": "TDS_Messaging-modules__success___3kyw2", "error": "TDS_Messaging-modules__error___3NArF", "errorText": "TDS_Messaging-modules__errorText___IDcbb", "disabledText": "TDS_Messaging-modules__disabledText___1bjON" };
var messagingStyles = {"default":"TDS_Messaging-modules__default___2B8Di","success":"TDS_Messaging-modules__success___3kyw2","error":"TDS_Messaging-modules__error___3NArF","errorText":"TDS_Messaging-modules__errorText___IDcbb","disabledText":"TDS_Messaging-modules__disabledText___1bjON"};

@@ -239,3 +301,4 @@ var getId = function getId(id, name, value) {

var className = void 0;
var className;
if (checked) {

@@ -253,28 +316,19 @@ className = inputTypeStyles.checked;

var renderColoredLabel = function renderColoredLabel(color, content) {
return React.createElement(
ColoredTextProvider,
{ colorClassName: color },
React.createElement(
Flexbox,
{ direction: 'row', dangerouslyAddClassName: styles$1.alignFlexStart },
content
)
);
return React.createElement(ColoredTextProvider, {
colorClassName: color
}, React.createElement(Flexbox, {
direction: "row",
dangerouslyAddClassName: styles$1.alignFlexStart
}, content));
};
var renderLabel = function renderLabel(label, description, feedback, checked, disabled) {
var content = React.createElement(
Box,
{ between: 2, dangerouslyAddClassName: styles$1.flexOne },
React.createElement(
Text,
{ size: 'medium' },
label
),
description && React.createElement(
Text,
{ size: 'small' },
description
)
);
var content = React.createElement(Box, {
between: 2,
dangerouslyAddClassName: styles$1.flexOne
}, React.createElement(Text, {
size: "medium"
}, label), description && React.createElement(Text, {
size: "small"
}, description));

@@ -293,40 +347,42 @@ if (feedback === 'error' && !checked) {

var renderError = function renderError(error, errorId) {
return React.createElement(
InputFeedback,
{ id: errorId, feedback: 'error' },
React.createElement(
Paragraph,
{ size: 'small' },
error
)
);
return React.createElement(InputFeedback, {
id: errorId,
feedback: "error"
}, React.createElement(Paragraph, {
size: "small"
}, error));
};
var Choice = function (_React$Component) {
inherits(Choice, _React$Component);
var Choice =
/*#__PURE__*/
function (_React$Component) {
_inherits(Choice, _React$Component);
function Choice() {
var _ref;
var _getPrototypeOf2;
var _temp, _this, _ret;
var _this;
classCallCheck(this, Choice);
_classCallCheck(this, Choice);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = Choice.__proto__ || Object.getPrototypeOf(Choice)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Choice)).call.apply(_getPrototypeOf2, [this].concat(args)));
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "state", {
checked: _this.props.checked,
focus: false
}, _this.onChange = function (event) {
});
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onChange", function (event) {
var onChange = _this.props.onChange;
event.persist();
_this.setState(function (_ref2) {
var checked = _ref2.checked;
return { checked: !checked };
_this.setState(function (_ref) {
var checked = _ref.checked;
return {
checked: !checked
};
}, function () {

@@ -337,25 +393,33 @@ if (onChange) {

});
}, _this.onFocus = function (event) {
});
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onFocus", function (event) {
var onFocus = _this.props.onFocus;
_this.setState({
focus: true
});
_this.setState({ focus: true });
if (onFocus) {
onFocus(event);
}
}, _this.onBlur = function (event) {
});
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onBlur", function (event) {
var onBlur = _this.props.onBlur;
_this.setState({
focus: false
});
_this.setState({ focus: false });
if (onBlur) {
onBlur(event);
}
}, _temp), possibleConstructorReturn(_this, _ret);
});
return _this;
}
createClass(Choice, [{
key: 'componentWillReceiveProps',
_createClass(Choice, [{
key: "componentWillReceiveProps",
value: function componentWillReceiveProps(nextProps) {

@@ -369,56 +433,47 @@ if (this.state.checked !== nextProps.checked) {

}, {
key: 'render',
key: "render",
value: function render() {
var _props = this.props,
label = _props.label,
name = _props.name,
value = _props.value,
description = _props.description,
feedback = _props.feedback,
error = _props.error,
type = _props.type,
inputTypeStyles = _props.inputTypeStyles,
children = _props.children,
rest = objectWithoutProperties(_props, ['label', 'name', 'value', 'description', 'feedback', 'error', 'type', 'inputTypeStyles', 'children']);
var _this$props = this.props,
label = _this$props.label,
name = _this$props.name,
value = _this$props.value,
description = _this$props.description,
feedback = _this$props.feedback,
error = _this$props.error,
type = _this$props.type,
inputTypeStyles = _this$props.inputTypeStyles,
children = _this$props.children,
rest = _objectWithoutProperties(_this$props, ["label", "name", "value", "description", "feedback", "error", "type", "inputTypeStyles", "children"]);
var choiceId = getId(rest.id, name, value);
var errorId = error && generateId(choiceId).postfix('error-message');
var fakeInputClassNames = joinClassNames(type === 'radio' ? styles$1.fakeRadio : styles$1.fakeCheckbox, getClassNames(inputTypeStyles, this.state.checked, this.state.focus, feedback, rest.disabled));
return React.createElement(
Box,
{ between: 2 },
feedback === 'error' && error && renderError(error, errorId),
React.createElement(
'label',
{ htmlFor: choiceId },
React.createElement(
Box,
{ tag: 'span', inline: true, between: 3, dangerouslyAddClassName: styles$1.alignFlexStart },
React.createElement(
'span',
{ className: fakeInputClassNames, 'data-testid': 'fake-input' },
React.createElement('input', _extends({}, safeRest(rest), {
id: choiceId,
type: type,
name: name,
value: value,
checked: this.state.checked,
className: styles$1.hiddenInput,
'aria-invalid': feedback === 'error',
'aria-describedby': errorId || undefined,
onChange: this.onChange,
onFocus: this.onFocus,
onBlur: this.onBlur
})),
children(this.state.checked, rest.disabled)
),
renderLabel(label, description, feedback, this.state.checked, rest.disabled)
)
)
);
return React.createElement(Box, {
between: 2
}, feedback === 'error' && error && renderError(error, errorId), React.createElement("label", {
htmlFor: choiceId
}, React.createElement(Box, {
tag: "span",
inline: true,
between: 3,
dangerouslyAddClassName: styles$1.alignFlexStart
}, React.createElement("span", {
className: fakeInputClassNames,
"data-testid": "fake-input"
}, React.createElement("input", _extends({}, safeRest(rest), {
id: choiceId,
type: type,
name: name,
value: value,
checked: this.state.checked,
className: styles$1.hiddenInput,
"aria-invalid": feedback === 'error',
"aria-describedby": errorId || undefined,
onChange: this.onChange,
onFocus: this.onFocus,
onBlur: this.onBlur
})), children(this.state.checked, rest.disabled)), renderLabel(label, description, feedback, this.state.checked, rest.disabled))));
}
}]);
return Choice;

@@ -442,3 +497,2 @@ }(React.Component);

};
Choice.defaultProps = {

@@ -453,3 +507,3 @@ description: undefined,

var styles$2 = { "disabled": "TDS_Checkbox-modules__disabled___n4wmX", "disabledChecked": "TDS_Checkbox-modules__disabledChecked___3xdD5", "checked": "TDS_Checkbox-modules__checked___14e9v" };
var styles$2 = {"disabled":"TDS_Checkbox-modules__disabled___n4wmX","disabledChecked":"TDS_Checkbox-modules__disabledChecked___3xdD5","checked":"TDS_Checkbox-modules__checked___14e9v"};

@@ -459,10 +513,14 @@ /**

*/
var Checkbox = function Checkbox(props) {
return React.createElement(
Choice,
_extends({}, props, { type: 'checkbox', inputTypeStyles: styles$2 }),
function (checked) {
return checked && React.createElement(DecorativeIcon, { symbol: 'checkmark', size: 16, variant: 'inverted' });
}
);
return React.createElement(Choice, _extends({}, props, {
type: "checkbox",
inputTypeStyles: styles$2
}), function (checked) {
return checked && React.createElement(DecorativeIcon, {
symbol: "checkmark",
size: 16,
variant: "inverted"
});
});
};

@@ -475,2 +533,3 @@

label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
/**

@@ -480,2 +539,3 @@ * Associate this checkbox with a group. Set as the HTML name attribute.

name: PropTypes.string.isRequired,
/**

@@ -485,2 +545,3 @@ * The value. Must be unique within the group.

value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]).isRequired,
/**

@@ -490,2 +551,3 @@ * The checked state

checked: PropTypes.bool,
/**

@@ -495,2 +557,3 @@ * A feedback state.

feedback: PropTypes.oneOf(['error']),
/**

@@ -500,2 +563,3 @@ * An error message.

error: PropTypes.string,
/**

@@ -507,2 +571,3 @@ * A callback function to be invoked when the checkbox is checked or unchecked.

onChange: PropTypes.func,
/**

@@ -514,2 +579,3 @@ * A callback function to be invoked when the checkbox receives focus.

onFocus: PropTypes.func,
/**

@@ -522,3 +588,2 @@ * A callback function to be invoked when the checkbox loses focus.

};
Checkbox.defaultProps = {

@@ -534,2 +599,1 @@ checked: false,

module.exports = Checkbox;
//# sourceMappingURL=index.cjs.js.map
import React from 'react';
import PropTypes from 'prop-types';
import DecorativeIcon from '@tds/core-decorative-icon';
import Text from '@tds/core-text';

@@ -7,45 +8,61 @@ import Paragraph from '@tds/core-paragraph';

import InputFeedback from '@tds/core-input-feedback';
import DecorativeIcon from '@tds/core-decorative-icon';
var classCallCheck = function (instance, Constructor) {
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
}
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
var _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
return obj;
}
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
}
return target;
};
return target;
};
var inherits = function (subClass, superClass) {
return _extends.apply(this, arguments);
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
throw new TypeError("Super expression must either be null or a function");
}

@@ -56,3 +73,2 @@

value: subClass,
enumerable: false,
writable: true,

@@ -62,29 +78,78 @@ configurable: true

});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};
if (superClass) _setPrototypeOf(subClass, superClass);
}
var objectWithoutProperties = function (obj, keys) {
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (var i in obj) {
if (keys.indexOf(i) >= 0) continue;
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
target[i] = obj[i];
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
};
}
var possibleConstructorReturn = function (self, call) {
if (!self) {
function _objectWithoutProperties(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for (i = 0; i < sourceSymbolKeys.length; i++) {
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
};
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
}
return _assertThisInitialized(self);
}
var safeRest = (function (_ref) {
var style = _ref.style,
className = _ref.className,
props = objectWithoutProperties(_ref, ["style", "className"]);
props = _objectWithoutProperties(_ref, ["style", "className"]);
return props;

@@ -94,3 +159,3 @@ });

var joinClassNames = function joinClassNames() {
for (var _len = arguments.length, classes = Array(_len), _key = 0; _key < _len; _key++) {
for (var _len = arguments.length, classes = new Array(_len), _key = 0; _key < _len; _key++) {
classes[_key] = arguments[_key];

@@ -105,6 +170,6 @@ }

var capitalize = function capitalize(string) {
return "" + string.charAt(0).toUpperCase() + string.slice(1);
return "".concat(string.charAt(0).toUpperCase()).concat(string.slice(1));
};
var styles = { "column": "TDS_Flexbox-modules__column___1vj4G", "row": "TDS_Flexbox-modules__row___5CSCg", "justifyContentSpaceBetween": "TDS_Flexbox-modules__justifyContentSpaceBetween___3eG3e" };
var styles = {"column":"TDS_Flexbox-modules__column___1vj4G","row":"TDS_Flexbox-modules__row___5CSCg","justifyContentSpaceBetween":"TDS_Flexbox-modules__justifyContentSpaceBetween___3eG3e"};

@@ -116,11 +181,8 @@ var Flexbox = function Flexbox(_ref) {

children = _ref.children,
rest = objectWithoutProperties(_ref, ['direction', 'justifyContent', 'dangerouslyAddClassName', 'children']);
rest = _objectWithoutProperties(_ref, ["direction", "justifyContent", "dangerouslyAddClassName", "children"]);
var classNames = joinClassNames(styles[direction], justifyContent && styles['justifyContent' + capitalize(justifyContent)], dangerouslyAddClassName);
return React.createElement(
'div',
_extends({}, safeRest(rest), { className: classNames }),
children
);
var classNames = joinClassNames(styles[direction], justifyContent && styles["justifyContent".concat(capitalize(justifyContent))], dangerouslyAddClassName);
return React.createElement("div", _extends({}, safeRest(rest), {
className: classNames
}), children);
};

@@ -134,3 +196,2 @@

};
Flexbox.defaultProps = {

@@ -141,12 +202,15 @@ justifyContent: undefined,

var ColoredTextProvider = function (_React$Component) {
inherits(ColoredTextProvider, _React$Component);
var ColoredTextProvider =
/*#__PURE__*/
function (_React$Component) {
_inherits(ColoredTextProvider, _React$Component);
function ColoredTextProvider() {
classCallCheck(this, ColoredTextProvider);
return possibleConstructorReturn(this, (ColoredTextProvider.__proto__ || Object.getPrototypeOf(ColoredTextProvider)).apply(this, arguments));
_classCallCheck(this, ColoredTextProvider);
return _possibleConstructorReturn(this, _getPrototypeOf(ColoredTextProvider).apply(this, arguments));
}
createClass(ColoredTextProvider, [{
key: 'getChildContext',
_createClass(ColoredTextProvider, [{
key: "getChildContext",
value: function getChildContext() {

@@ -158,13 +222,14 @@ return {

}, {
key: 'render',
key: "render",
value: function render() {
var _props = this.props,
colorClassName = _props.colorClassName,
tag = _props.tag,
children = _props.children;
return React.createElement(tag, { className: colorClassName }, children);
var _this$props = this.props,
colorClassName = _this$props.colorClassName,
tag = _this$props.tag,
children = _this$props.children;
return React.createElement(tag, {
className: colorClassName
}, children);
}
}]);
return ColoredTextProvider;

@@ -178,7 +243,5 @@ }(React.Component);

};
ColoredTextProvider.defaultProps = {
tag: 'div'
};
ColoredTextProvider.childContextTypes = {

@@ -195,3 +258,3 @@ inheritColor: PropTypes.bool

var generateId = function generateId() {
for (var _len = arguments.length, choices = Array(_len), _key = 0; _key < _len; _key++) {
for (var _len = arguments.length, choices = new Array(_len), _key = 0; _key < _len; _key++) {
choices[_key] = arguments[_key];

@@ -203,3 +266,2 @@ }

}));
return {

@@ -210,3 +272,3 @@ identity: function identity() {

postfix: function postfix(value) {
return id + '_' + sanitize(value);
return "".concat(id, "_").concat(sanitize(value));
}

@@ -216,5 +278,5 @@ };

var styles$1 = { "alignCenter": "TDS_Choice-modules__alignCenter___1M8FG", "alignFlexStart": "TDS_Choice-modules__alignFlexStart___1zDGw", "flexOne": "TDS_Choice-modules__flexOne___1SrBe", "fakeInput": "TDS_Choice-modules__fakeInput___3I1CX TDS_Borders-modules__thin___1JHOl", "fakeCheckbox": "TDS_Choice-modules__fakeCheckbox___1Buqb TDS_Choice-modules__fakeInput___3I1CX TDS_Borders-modules__thin___1JHOl TDS_Borders-modules__rounded___3df1Q", "fakeRadio": "TDS_Choice-modules__fakeRadio___1H3I- TDS_Choice-modules__fakeInput___3I1CX TDS_Borders-modules__thin___1JHOl TDS_Borders-modules__circular___OppHT", "unchecked": "TDS_Choice-modules__unchecked___3Zyro", "focused": "TDS_Choice-modules__focused___2KPRk", "error": "TDS_Choice-modules__error___1Vlds", "hiddenInput": "TDS_Choice-modules__hiddenInput___3S8As" };
var styles$1 = {"alignCenter":"TDS_Choice-modules__alignCenter___1M8FG","alignFlexStart":"TDS_Choice-modules__alignFlexStart___1zDGw","flexOne":"TDS_Choice-modules__flexOne___1SrBe","fakeInput":"TDS_Choice-modules__fakeInput___3I1CX TDS_Borders-modules__thin___1JHOl","fakeCheckbox":"TDS_Choice-modules__fakeCheckbox___1Buqb TDS_Choice-modules__fakeInput___3I1CX TDS_Borders-modules__thin___1JHOl TDS_Borders-modules__rounded___3df1Q","fakeRadio":"TDS_Choice-modules__fakeRadio___1H3I- TDS_Choice-modules__fakeInput___3I1CX TDS_Borders-modules__thin___1JHOl TDS_Borders-modules__circular___OppHT","unchecked":"TDS_Choice-modules__unchecked___3Zyro","focused":"TDS_Choice-modules__focused___2KPRk","error":"TDS_Choice-modules__error___1Vlds","hiddenInput":"TDS_Choice-modules__hiddenInput___3S8As"};
var messagingStyles = { "default": "TDS_Messaging-modules__default___2B8Di", "success": "TDS_Messaging-modules__success___3kyw2", "error": "TDS_Messaging-modules__error___3NArF", "errorText": "TDS_Messaging-modules__errorText___IDcbb", "disabledText": "TDS_Messaging-modules__disabledText___1bjON" };
var messagingStyles = {"default":"TDS_Messaging-modules__default___2B8Di","success":"TDS_Messaging-modules__success___3kyw2","error":"TDS_Messaging-modules__error___3NArF","errorText":"TDS_Messaging-modules__errorText___IDcbb","disabledText":"TDS_Messaging-modules__disabledText___1bjON"};

@@ -234,3 +296,4 @@ var getId = function getId(id, name, value) {

var className = void 0;
var className;
if (checked) {

@@ -248,28 +311,19 @@ className = inputTypeStyles.checked;

var renderColoredLabel = function renderColoredLabel(color, content) {
return React.createElement(
ColoredTextProvider,
{ colorClassName: color },
React.createElement(
Flexbox,
{ direction: 'row', dangerouslyAddClassName: styles$1.alignFlexStart },
content
)
);
return React.createElement(ColoredTextProvider, {
colorClassName: color
}, React.createElement(Flexbox, {
direction: "row",
dangerouslyAddClassName: styles$1.alignFlexStart
}, content));
};
var renderLabel = function renderLabel(label, description, feedback, checked, disabled) {
var content = React.createElement(
Box,
{ between: 2, dangerouslyAddClassName: styles$1.flexOne },
React.createElement(
Text,
{ size: 'medium' },
label
),
description && React.createElement(
Text,
{ size: 'small' },
description
)
);
var content = React.createElement(Box, {
between: 2,
dangerouslyAddClassName: styles$1.flexOne
}, React.createElement(Text, {
size: "medium"
}, label), description && React.createElement(Text, {
size: "small"
}, description));

@@ -288,40 +342,42 @@ if (feedback === 'error' && !checked) {

var renderError = function renderError(error, errorId) {
return React.createElement(
InputFeedback,
{ id: errorId, feedback: 'error' },
React.createElement(
Paragraph,
{ size: 'small' },
error
)
);
return React.createElement(InputFeedback, {
id: errorId,
feedback: "error"
}, React.createElement(Paragraph, {
size: "small"
}, error));
};
var Choice = function (_React$Component) {
inherits(Choice, _React$Component);
var Choice =
/*#__PURE__*/
function (_React$Component) {
_inherits(Choice, _React$Component);
function Choice() {
var _ref;
var _getPrototypeOf2;
var _temp, _this, _ret;
var _this;
classCallCheck(this, Choice);
_classCallCheck(this, Choice);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = Choice.__proto__ || Object.getPrototypeOf(Choice)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Choice)).call.apply(_getPrototypeOf2, [this].concat(args)));
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "state", {
checked: _this.props.checked,
focus: false
}, _this.onChange = function (event) {
});
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onChange", function (event) {
var onChange = _this.props.onChange;
event.persist();
_this.setState(function (_ref2) {
var checked = _ref2.checked;
return { checked: !checked };
_this.setState(function (_ref) {
var checked = _ref.checked;
return {
checked: !checked
};
}, function () {

@@ -332,25 +388,33 @@ if (onChange) {

});
}, _this.onFocus = function (event) {
});
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onFocus", function (event) {
var onFocus = _this.props.onFocus;
_this.setState({
focus: true
});
_this.setState({ focus: true });
if (onFocus) {
onFocus(event);
}
}, _this.onBlur = function (event) {
});
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onBlur", function (event) {
var onBlur = _this.props.onBlur;
_this.setState({
focus: false
});
_this.setState({ focus: false });
if (onBlur) {
onBlur(event);
}
}, _temp), possibleConstructorReturn(_this, _ret);
});
return _this;
}
createClass(Choice, [{
key: 'componentWillReceiveProps',
_createClass(Choice, [{
key: "componentWillReceiveProps",
value: function componentWillReceiveProps(nextProps) {

@@ -364,56 +428,47 @@ if (this.state.checked !== nextProps.checked) {

}, {
key: 'render',
key: "render",
value: function render() {
var _props = this.props,
label = _props.label,
name = _props.name,
value = _props.value,
description = _props.description,
feedback = _props.feedback,
error = _props.error,
type = _props.type,
inputTypeStyles = _props.inputTypeStyles,
children = _props.children,
rest = objectWithoutProperties(_props, ['label', 'name', 'value', 'description', 'feedback', 'error', 'type', 'inputTypeStyles', 'children']);
var _this$props = this.props,
label = _this$props.label,
name = _this$props.name,
value = _this$props.value,
description = _this$props.description,
feedback = _this$props.feedback,
error = _this$props.error,
type = _this$props.type,
inputTypeStyles = _this$props.inputTypeStyles,
children = _this$props.children,
rest = _objectWithoutProperties(_this$props, ["label", "name", "value", "description", "feedback", "error", "type", "inputTypeStyles", "children"]);
var choiceId = getId(rest.id, name, value);
var errorId = error && generateId(choiceId).postfix('error-message');
var fakeInputClassNames = joinClassNames(type === 'radio' ? styles$1.fakeRadio : styles$1.fakeCheckbox, getClassNames(inputTypeStyles, this.state.checked, this.state.focus, feedback, rest.disabled));
return React.createElement(
Box,
{ between: 2 },
feedback === 'error' && error && renderError(error, errorId),
React.createElement(
'label',
{ htmlFor: choiceId },
React.createElement(
Box,
{ tag: 'span', inline: true, between: 3, dangerouslyAddClassName: styles$1.alignFlexStart },
React.createElement(
'span',
{ className: fakeInputClassNames, 'data-testid': 'fake-input' },
React.createElement('input', _extends({}, safeRest(rest), {
id: choiceId,
type: type,
name: name,
value: value,
checked: this.state.checked,
className: styles$1.hiddenInput,
'aria-invalid': feedback === 'error',
'aria-describedby': errorId || undefined,
onChange: this.onChange,
onFocus: this.onFocus,
onBlur: this.onBlur
})),
children(this.state.checked, rest.disabled)
),
renderLabel(label, description, feedback, this.state.checked, rest.disabled)
)
)
);
return React.createElement(Box, {
between: 2
}, feedback === 'error' && error && renderError(error, errorId), React.createElement("label", {
htmlFor: choiceId
}, React.createElement(Box, {
tag: "span",
inline: true,
between: 3,
dangerouslyAddClassName: styles$1.alignFlexStart
}, React.createElement("span", {
className: fakeInputClassNames,
"data-testid": "fake-input"
}, React.createElement("input", _extends({}, safeRest(rest), {
id: choiceId,
type: type,
name: name,
value: value,
checked: this.state.checked,
className: styles$1.hiddenInput,
"aria-invalid": feedback === 'error',
"aria-describedby": errorId || undefined,
onChange: this.onChange,
onFocus: this.onFocus,
onBlur: this.onBlur
})), children(this.state.checked, rest.disabled)), renderLabel(label, description, feedback, this.state.checked, rest.disabled))));
}
}]);
return Choice;

@@ -437,3 +492,2 @@ }(React.Component);

};
Choice.defaultProps = {

@@ -448,3 +502,3 @@ description: undefined,

var styles$2 = { "disabled": "TDS_Checkbox-modules__disabled___n4wmX", "disabledChecked": "TDS_Checkbox-modules__disabledChecked___3xdD5", "checked": "TDS_Checkbox-modules__checked___14e9v" };
var styles$2 = {"disabled":"TDS_Checkbox-modules__disabled___n4wmX","disabledChecked":"TDS_Checkbox-modules__disabledChecked___3xdD5","checked":"TDS_Checkbox-modules__checked___14e9v"};

@@ -454,10 +508,14 @@ /**

*/
var Checkbox = function Checkbox(props) {
return React.createElement(
Choice,
_extends({}, props, { type: 'checkbox', inputTypeStyles: styles$2 }),
function (checked) {
return checked && React.createElement(DecorativeIcon, { symbol: 'checkmark', size: 16, variant: 'inverted' });
}
);
return React.createElement(Choice, _extends({}, props, {
type: "checkbox",
inputTypeStyles: styles$2
}), function (checked) {
return checked && React.createElement(DecorativeIcon, {
symbol: "checkmark",
size: 16,
variant: "inverted"
});
});
};

@@ -470,2 +528,3 @@

label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
/**

@@ -475,2 +534,3 @@ * Associate this checkbox with a group. Set as the HTML name attribute.

name: PropTypes.string.isRequired,
/**

@@ -480,2 +540,3 @@ * The value. Must be unique within the group.

value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]).isRequired,
/**

@@ -485,2 +546,3 @@ * The checked state

checked: PropTypes.bool,
/**

@@ -490,2 +552,3 @@ * A feedback state.

feedback: PropTypes.oneOf(['error']),
/**

@@ -495,2 +558,3 @@ * An error message.

error: PropTypes.string,
/**

@@ -502,2 +566,3 @@ * A callback function to be invoked when the checkbox is checked or unchecked.

onChange: PropTypes.func,
/**

@@ -509,2 +574,3 @@ * A callback function to be invoked when the checkbox receives focus.

onFocus: PropTypes.func,
/**

@@ -517,3 +583,2 @@ * A callback function to be invoked when the checkbox loses focus.

};
Checkbox.defaultProps = {

@@ -529,2 +594,1 @@ checked: false,

export default Checkbox;
//# sourceMappingURL=index.es.js.map
{
"name": "@tds/core-checkbox",
"version": "1.1.3",
"version": "1.1.4",
"main": "index.cjs.js",

@@ -27,13 +27,14 @@ "module": "index.es.js",

"dependencies": {
"@tds/core-box": "^1.0.1",
"@tds/core-decorative-icon": "^1.0.0",
"@tds/core-input-feedback": "^1.0.2",
"@tds/core-paragraph": "^1.0.4",
"@tds/core-text": "^1.0.4",
"@tds/core-box": "^1.0.2",
"@tds/core-decorative-icon": "^1.0.1",
"@tds/core-input-feedback": "^1.0.3",
"@tds/core-paragraph": "^1.0.5",
"@tds/core-text": "^1.0.5",
"prop-types": "^15.5.10"
},
"devDependencies": {
"@tds/core-colours": "^1.0.0",
"@tds/shared-choice": "^1.1.1"
}
"@tds/core-colours": "^1.0.1",
"@tds/shared-choice": "^1.1.2"
},
"gitHead": "79839daf9cc90e531bdfe4e5202edfd4b7348342"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc