Socket
Socket
Sign inDemoInstall

@os-design/core

Package Overview
Dependencies
Maintainers
1
Versions
478
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@os-design/core - npm Package Compare versions

Comparing version 1.0.186 to 1.0.187

46

dist/cjs/Input/index.js

@@ -112,2 +112,24 @@ "use strict";

}, [loading, rightHasPadding]);
var onFocus = (0, _react.useCallback)(function (e) {
// Focus the next element if the container element was focused.
// The next element will be the input or button in the addon.
if (disabled || e.target !== innerContainerRef.current) return;
var focusableElements = (0, _getFocusableElements["default"])(innerContainerRef.current);
focusableElements[0].focus();
}, [disabled, innerContainerRef]);
var onKeyDown = (0, _react.useCallback)(function (e) {
// Focus the previous element if the first element in the input
// container is focused and the Shift + Tab combination is pressed.
var focusableElements = (0, _getFocusableElements["default"])(document);
var inputFocusableElements = innerContainerRef.current ? (0, _getFocusableElements["default"])(innerContainerRef.current) : [];
var firstInputElementIsFocused = inputFocusableElements[0] === document.activeElement;
if (firstInputElementIsFocused && e.key === 'Tab' && e.shiftKey) {
var inputContainerIndex = focusableElements.findIndex(function (el) {
return el === innerContainerRef.current;
});
if (inputContainerIndex === 0) return;
var elementBeforeInputContainer = focusableElements[inputContainerIndex - 1];
elementBeforeInputContainer.focus();
}
}, [innerContainerRef]);
return /*#__PURE__*/_react["default"].createElement(InputContainer, _extends({

@@ -117,24 +139,4 @@ disabled: disabled,

tabIndex: !disabled ? 0 : -1,
onFocus: function onFocus(e) {
// Focus the next element if the container element was focused.
// The next element will be the input or button in the addon.
if (disabled || e.target !== innerContainerRef.current) return;
var focusableElements = (0, _getFocusableElements["default"])(innerContainerRef.current);
focusableElements[0].focus();
},
onKeyDown: function onKeyDown(e) {
// Focus the previous element if the first element in the input
// container is focused and the Shift + Tab combination is pressed.
var focusableElements = (0, _getFocusableElements["default"])(document);
var inputFocusableElements = innerContainerRef.current ? (0, _getFocusableElements["default"])(innerContainerRef.current) : [];
var firstInputElementIsFocused = inputFocusableElements[0] === document.activeElement;
if (firstInputElementIsFocused && e.key === 'Tab' && e.shiftKey) {
var inputContainerIndex = focusableElements.findIndex(function (el) {
return el === innerContainerRef.current;
});
if (inputContainerIndex === 0) return;
var elementBeforeInputContainer = focusableElements[inputContainerIndex - 1];
elementBeforeInputContainer.focus();
}
},
onFocus: onFocus,
onKeyDown: onKeyDown,
ref: mergedContainerRef

@@ -141,0 +143,0 @@ }, containerProps), left && /*#__PURE__*/_react["default"].createElement(_theming.ThemeOverrider, {

@@ -8,11 +8,22 @@ "use strict";

exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _react = require("@emotion/react");
var _styled = _interopRequireDefault(require("@emotion/styled"));
var _icons = require("@os-design/icons");
var _theming = require("@os-design/theming");
var _utils = require("@os-design/utils");
var _react2 = _interopRequireWildcard(require("react"));
var _Input = require("../Input");
var _excluded = ["disabled", "size", "onChange"];
var _templateObject, _templateObject2;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var _getFocusableElements = _interopRequireDefault(require("../Input/utils/getFocusableElements"));
var _excluded = ["left", "leftHasPadding", "right", "rightHasPadding", "disabled", "loading", "containerRef", "containerProps", "size", "value", "onChange"];
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7;
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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 _extends.apply(this, arguments); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
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; }

@@ -24,3 +35,3 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

});
var TextAreaField = (0, _styled["default"])(_Input.StyledInput.withComponent('textarea'))(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n padding-top: ", "em;\n padding-bottom: ", "em;\n line-height: ", ";\n"])), function (p) {
var TextAreaField = (0, _styled["default"])(_Input.StyledInput.withComponent('textarea'))(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n padding-top: ", "em;\n padding-bottom: ", "em;\n line-height: ", ";\n resize: none;\n"])), function (p) {
return p.theme.textAreaPaddingVertical;

@@ -32,2 +43,15 @@ }, function (p) {

});
var Addon = (0, _styled["default"])('span', (0, _utils.omitEmotionProps)('hasPadding'))(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n display: flex;\n align-items: center;\n user-select: none;\n color: ", ";\n\n svg {\n transform: scale(1.2);\n }\n"])), function (p) {
return (0, _theming.clr)(p.theme.inputColorPlaceholder);
});
var LeftAddon = (0, _styled["default"])(Addon)(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n padding-right: ", "em;\n ", "\n"])), function (p) {
return p.theme.inputAddonPaddingHorizontal;
}, function (p) {
return p.hasPadding && (0, _react.css)(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n padding-left: ", "em;\n "])), p.theme.inputPaddingHorizontal);
});
var RightAddon = (0, _styled["default"])(Addon)(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n padding-left: ", "em;\n ", "\n"])), function (p) {
return p.theme.inputAddonPaddingHorizontal;
}, function (p) {
return p.hasPadding && (0, _react.css)(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n padding-right: ", "em;\n "])), p.theme.inputPaddingHorizontal);
});

@@ -37,14 +61,71 @@ /**

*/
var TextArea = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
var _ref$disabled = _ref.disabled,
var TextArea = /*#__PURE__*/(0, _react2.forwardRef)(function (_ref, ref) {
var left = _ref.left,
_ref$leftHasPadding = _ref.leftHasPadding,
leftHasPadding = _ref$leftHasPadding === void 0 ? false : _ref$leftHasPadding,
right = _ref.right,
_ref$rightHasPadding = _ref.rightHasPadding,
rightHasPadding = _ref$rightHasPadding === void 0 ? false : _ref$rightHasPadding,
_ref$disabled = _ref.disabled,
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
_ref$loading = _ref.loading,
loading = _ref$loading === void 0 ? false : _ref$loading,
containerRef = _ref.containerRef,
_ref$containerProps = _ref.containerProps,
containerProps = _ref$containerProps === void 0 ? {} : _ref$containerProps,
size = _ref.size,
value = _ref.value,
_ref$onChange = _ref.onChange,
_onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
rest = _objectWithoutProperties(_ref, _excluded);
return /*#__PURE__*/_react["default"].createElement(TextAreaContainer, {
var _useForwardedRef = (0, _utils.useForwardedRef)(containerRef),
_useForwardedRef2 = _slicedToArray(_useForwardedRef, 2),
innerContainerRef = _useForwardedRef2[0],
mergedContainerRef = _useForwardedRef2[1];
var rightValue = (0, _react2.useMemo)(function () {
return loading ? /*#__PURE__*/_react2["default"].createElement(_icons.Loading, null) : right;
}, [loading, right]);
var rightHasPaddingValue = (0, _react2.useMemo)(function () {
return loading ? true : rightHasPadding;
}, [loading, rightHasPadding]);
var onFocus = (0, _react2.useCallback)(function (e) {
// Focus the next element if the container element was focused.
// The next element will be the input or button in the addon.
if (disabled || e.target !== innerContainerRef.current) return;
var focusableElements = (0, _getFocusableElements["default"])(innerContainerRef.current);
focusableElements[0].focus();
}, [disabled, innerContainerRef]);
var onKeyDown = (0, _react2.useCallback)(function (e) {
// Focus the previous element if the first element in the input
// container is focused and the Shift + Tab combination is pressed.
var focusableElements = (0, _getFocusableElements["default"])(document);
var inputFocusableElements = innerContainerRef.current ? (0, _getFocusableElements["default"])(innerContainerRef.current) : [];
var firstInputElementIsFocused = inputFocusableElements[0] === document.activeElement;
if (firstInputElementIsFocused && e.key === 'Tab' && e.shiftKey) {
var inputContainerIndex = focusableElements.findIndex(function (el) {
return el === innerContainerRef.current;
});
if (inputContainerIndex === 0) return;
var elementBeforeInputContainer = focusableElements[inputContainerIndex - 1];
elementBeforeInputContainer.focus();
}
}, [innerContainerRef]);
return /*#__PURE__*/_react2["default"].createElement(TextAreaContainer, _extends({
disabled: disabled,
size: size
}, /*#__PURE__*/_react["default"].createElement(TextAreaField, _extends({
size: size,
tabIndex: !disabled ? 0 : -1,
onFocus: onFocus,
onKeyDown: onKeyDown,
ref: mergedContainerRef
}, containerProps), left && /*#__PURE__*/_react2["default"].createElement(_theming.ThemeOverrider, {
overrides: {
buttonPaddingHorizontal: 0.8
}
}, /*#__PURE__*/_react2["default"].createElement(LeftAddon, {
hasPadding: leftHasPadding
}, left)), /*#__PURE__*/_react2["default"].createElement(TextAreaField, _extends({
disabled: disabled,
hasLeft: !!left,
hasRight: !!right,
value: value || '',
onChange: function onChange(e) {

@@ -55,3 +136,9 @@ return _onChange(e.target.value, e);

ref: ref
})));
})), rightValue && /*#__PURE__*/_react2["default"].createElement(_theming.ThemeOverrider, {
overrides: {
buttonPaddingHorizontal: 0.8
}
}, /*#__PURE__*/_react2["default"].createElement(RightAddon, {
hasPadding: rightHasPaddingValue
}, rightValue)));
});

@@ -58,0 +145,0 @@ TextArea.displayName = 'TextArea';

function _extends() { _extends = Object.assign ? Object.assign.bind() : 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 _extends.apply(this, arguments); }
import React, { forwardRef, useMemo } from 'react';
import React, { forwardRef, useCallback, useMemo } from 'react';
import { resetFocusStyles, sizeStyles, transitionStyles } from '@os-design/styles';

@@ -124,2 +124,22 @@ import { omitEmotionProps, useForwardedRef } from '@os-design/utils';

const rightHasPaddingValue = useMemo(() => loading ? true : rightHasPadding, [loading, rightHasPadding]);
const onFocus = useCallback(e => {
// Focus the next element if the container element was focused.
// The next element will be the input or button in the addon.
if (disabled || e.target !== innerContainerRef.current) return;
const focusableElements = getFocusableElements(innerContainerRef.current);
focusableElements[0].focus();
}, [disabled, innerContainerRef]);
const onKeyDown = useCallback(e => {
// Focus the previous element if the first element in the input
// container is focused and the Shift + Tab combination is pressed.
const focusableElements = getFocusableElements(document);
const inputFocusableElements = innerContainerRef.current ? getFocusableElements(innerContainerRef.current) : [];
const firstInputElementIsFocused = inputFocusableElements[0] === document.activeElement;
if (firstInputElementIsFocused && e.key === 'Tab' && e.shiftKey) {
const inputContainerIndex = focusableElements.findIndex(el => el === innerContainerRef.current);
if (inputContainerIndex === 0) return;
const elementBeforeInputContainer = focusableElements[inputContainerIndex - 1];
elementBeforeInputContainer.focus();
}
}, [innerContainerRef]);
return /*#__PURE__*/React.createElement(InputContainer, _extends({

@@ -129,22 +149,4 @@ disabled: disabled,

tabIndex: !disabled ? 0 : -1,
onFocus: e => {
// Focus the next element if the container element was focused.
// The next element will be the input or button in the addon.
if (disabled || e.target !== innerContainerRef.current) return;
const focusableElements = getFocusableElements(innerContainerRef.current);
focusableElements[0].focus();
},
onKeyDown: e => {
// Focus the previous element if the first element in the input
// container is focused and the Shift + Tab combination is pressed.
const focusableElements = getFocusableElements(document);
const inputFocusableElements = innerContainerRef.current ? getFocusableElements(innerContainerRef.current) : [];
const firstInputElementIsFocused = inputFocusableElements[0] === document.activeElement;
if (firstInputElementIsFocused && e.key === 'Tab' && e.shiftKey) {
const inputContainerIndex = focusableElements.findIndex(el => el === innerContainerRef.current);
if (inputContainerIndex === 0) return;
const elementBeforeInputContainer = focusableElements[inputContainerIndex - 1];
elementBeforeInputContainer.focus();
}
},
onFocus: onFocus,
onKeyDown: onKeyDown,
ref: mergedContainerRef

@@ -151,0 +153,0 @@ }, containerProps), left && /*#__PURE__*/React.createElement(ThemeOverrider, {

function _extends() { _extends = Object.assign ? Object.assign.bind() : 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 _extends.apply(this, arguments); }
import React, { forwardRef } from 'react';
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import { Loading } from '@os-design/icons';
import { clr, ThemeOverrider } from '@os-design/theming';
import { omitEmotionProps, useForwardedRef } from '@os-design/utils';
import React, { forwardRef, useCallback, useMemo } from 'react';
import { InputContainer, StyledInput } from '../Input';
import getFocusableElements from '../Input/utils/getFocusableElements';
const TextAreaContainer = styled(InputContainer)`

@@ -12,4 +17,27 @@ height: ${p => p.theme.textAreaHeight}em;

line-height: ${p => p.theme.lineHeight};
resize: none;
`;
const Addon = styled('span', omitEmotionProps('hasPadding'))`
display: flex;
align-items: center;
user-select: none;
color: ${p => clr(p.theme.inputColorPlaceholder)};
svg {
transform: scale(1.2);
}
`;
const LeftAddon = styled(Addon)`
padding-right: ${p => p.theme.inputAddonPaddingHorizontal}em;
${p => p.hasPadding && css`
padding-left: ${p.theme.inputPaddingHorizontal}em;
`}
`;
const RightAddon = styled(Addon)`
padding-left: ${p => p.theme.inputAddonPaddingHorizontal}em;
${p => p.hasPadding && css`
padding-right: ${p.theme.inputPaddingHorizontal}em;
`}
`;
/**

@@ -19,17 +47,69 @@ * The multiline input component.

const TextArea = /*#__PURE__*/forwardRef(({
left,
leftHasPadding = false,
right,
rightHasPadding = false,
disabled = false,
loading = false,
containerRef,
containerProps = {},
size,
value,
onChange = () => {},
...rest
}, ref) => /*#__PURE__*/React.createElement(TextAreaContainer, {
disabled: disabled,
size: size
}, /*#__PURE__*/React.createElement(TextAreaField, _extends({
disabled: disabled,
onChange: e => onChange(e.target.value, e)
}, rest, {
ref: ref
}))));
}, ref) => {
const [innerContainerRef, mergedContainerRef] = useForwardedRef(containerRef);
const rightValue = useMemo(() => loading ? /*#__PURE__*/React.createElement(Loading, null) : right, [loading, right]);
const rightHasPaddingValue = useMemo(() => loading ? true : rightHasPadding, [loading, rightHasPadding]);
const onFocus = useCallback(e => {
// Focus the next element if the container element was focused.
// The next element will be the input or button in the addon.
if (disabled || e.target !== innerContainerRef.current) return;
const focusableElements = getFocusableElements(innerContainerRef.current);
focusableElements[0].focus();
}, [disabled, innerContainerRef]);
const onKeyDown = useCallback(e => {
// Focus the previous element if the first element in the input
// container is focused and the Shift + Tab combination is pressed.
const focusableElements = getFocusableElements(document);
const inputFocusableElements = innerContainerRef.current ? getFocusableElements(innerContainerRef.current) : [];
const firstInputElementIsFocused = inputFocusableElements[0] === document.activeElement;
if (firstInputElementIsFocused && e.key === 'Tab' && e.shiftKey) {
const inputContainerIndex = focusableElements.findIndex(el => el === innerContainerRef.current);
if (inputContainerIndex === 0) return;
const elementBeforeInputContainer = focusableElements[inputContainerIndex - 1];
elementBeforeInputContainer.focus();
}
}, [innerContainerRef]);
return /*#__PURE__*/React.createElement(TextAreaContainer, _extends({
disabled: disabled,
size: size,
tabIndex: !disabled ? 0 : -1,
onFocus: onFocus,
onKeyDown: onKeyDown,
ref: mergedContainerRef
}, containerProps), left && /*#__PURE__*/React.createElement(ThemeOverrider, {
overrides: {
buttonPaddingHorizontal: 0.8
}
}, /*#__PURE__*/React.createElement(LeftAddon, {
hasPadding: leftHasPadding
}, left)), /*#__PURE__*/React.createElement(TextAreaField, _extends({
disabled: disabled,
hasLeft: !!left,
hasRight: !!right,
value: value || '',
onChange: e => onChange(e.target.value, e)
}, rest, {
ref: ref
})), rightValue && /*#__PURE__*/React.createElement(ThemeOverrider, {
overrides: {
buttonPaddingHorizontal: 0.8
}
}, /*#__PURE__*/React.createElement(RightAddon, {
hasPadding: rightHasPaddingValue
}, rightValue)));
});
TextArea.displayName = 'TextArea';
export default TextArea;
//# sourceMappingURL=index.js.map

@@ -1,6 +0,13 @@

import React, { ChangeEvent } from 'react';
import { WithSize } from '@os-design/styles';
import React, { ChangeEvent, ForwardedRef } from 'react';
type JsxTextAreaProps = Omit<JSX.IntrinsicElements['textarea'], 'value' | 'onChange' | 'ref'>;
export interface TextAreaProps extends JsxTextAreaProps, WithSize {
left?: React.ReactNode;
leftHasPadding?: boolean;
right?: React.ReactNode;
rightHasPadding?: boolean;
disabled?: boolean;
loading?: boolean;
containerRef?: ForwardedRef<HTMLDivElement>;
containerProps?: JSX.IntrinsicElements['div'];
value?: string;

@@ -7,0 +14,0 @@ onChange?: (value: string, e: ChangeEvent<HTMLTextAreaElement>) => void;

{
"name": "@os-design/core",
"version": "1.0.186",
"version": "1.0.187",
"license": "UNLICENSED",

@@ -61,3 +61,3 @@ "repository": "git@gitlab.com:os-team/libs/os-design.git",

},
"gitHead": "2dbd5dc78c987a313373c4f7e5e72061ab73a514"
"gitHead": "5a682a07301c596be544275f4ce4864e02e08010"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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