@os-design/core 1.0.131 → 1.0.132

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,7 +23,7 @@ var _icons = require("@os-design/icons");
23
23
 
24
24
  var _getFocusableElements = _interopRequireDefault(require("./utils/getFocusableElements"));
25
25
 
26
- var _excluded = ["type", "left", "leftHasPadding", "right", "rightHasPadding", "disabled", "loading", "containerRef", "containerProps", "size", "onChange"];
26
+ var _excluded = ["type", "left", "leftHasPadding", "right", "rightHasPadding", "disabled", "loading", "containerRef", "containerProps", "size", "value", "onChange"];
27
27
 
28
28
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12;
29
29
 
@@ -126,6 +126,7 @@ var Input = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
126
126
  _ref$containerProps = _ref.containerProps,
127
127
  containerProps = _ref$containerProps === void 0 ? {} : _ref$containerProps,
128
128
  size = _ref.size,
129
+ value = _ref.value,
129
130
  _ref$onChange = _ref.onChange,
130
131
  _onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
131
132
  rest = _objectWithoutProperties(_ref, _excluded);
@@ -180,6 +181,7 @@ var Input = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
180
181
  disabled: disabled,
181
182
  hasLeft: !!left,
182
183
  hasRight: !!right,
184
+ value: value || '',
183
185
  onChange: function onChange(e) {
184
186
  return _onChange(e.target.value, e);
185
187
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/Input/index.tsx"],"names":["hoverStyles","p","disabled","css","theme","inputHoverColorBorder","focusStyles","inputFocusColorBorder","inputFocusColorShadow","disabledStyles","inputDisabledColorText","inputDisabledColorBg","inputDisabledColorBorder","inputDisabledColorPlaceholder","InputContainer","resetFocusStyles","baseHeight","inputColorBg","inputBorderWidth","inputColorBorder","borderRadius","sizeStyles","notHasLeftStyles","hasLeft","inputPaddingHorizontal","notHasRightStyles","hasRight","StyledInput","inputColorText","inputColorPlaceholder","Addon","LeftAddon","inputAddonPaddingHorizontal","hasPadding","RightAddon","Input","ref","type","left","leftHasPadding","right","rightHasPadding","loading","containerRef","containerProps","size","onChange","rest","innerContainerRef","mergedContainerRef","rightValue","rightHasPaddingValue","e","target","current","focusableElements","focus","document","inputFocusableElements","firstInputElementIsFocused","activeElement","key","shiftKey","inputContainerIndex","findIndex","el","elementBeforeInputContainer","buttonPaddingHorizontal","value","displayName"],"mappings":";;;;;;;;;AAAA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,IAAMA,WAAW,GAAG,SAAdA,WAAc,CAACC,CAAD;AAAA,SAClB,CAACA,CAAC,CAACC,QAAH,QACAC,WADA,sKAIsB,kBAAIF,CAAC,CAACG,KAAF,CAAQC,qBAAZ,CAJtB,CADkB;AAAA,CAApB;;AAUA,IAAMC,WAAW,GAAG,SAAdA,WAAc,CAACL,CAAD;AAAA,SAClB,CAACA,CAAC,CAACC,QAAH,QACAC,WADA,2KAGoB,kBAAIF,CAAC,CAACG,KAAF,CAAQG,qBAAZ,CAHpB,EAI+B,kBAAIN,CAAC,CAACG,KAAF,CAAQI,qBAAZ,CAJ/B,CADkB;AAAA,CAApB;;AASA,IAAMC,cAAc,GAAG,SAAjBA,cAAiB,CAACR,CAAD;AAAA,SACrBA,CAAC,CAACC,QAAF,QACAC,WADA,uSAGW,kBAAIF,CAAC,CAACG,KAAF,CAAQM,sBAAZ,CAHX,EAIsB,kBAAIT,CAAC,CAACG,KAAF,CAAQO,oBAAZ,CAJtB,EAKkB,kBAAIV,CAAC,CAACG,KAAF,CAAQQ,wBAAZ,CALlB,EAWe,kBAAIX,CAAC,CAACG,KAAF,CAAQS,6BAAZ,CAXf,CADqB;AAAA,CAAvB;;AAkBO,IAAMC,cAAc,GAAG,wBAC5B,KAD4B,EAE5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Content":["import React, { ChangeEvent, ForwardedRef, forwardRef, useMemo } from 'react';\nimport {\n resetFocusStyles,\n sizeStyles,\n transitionStyles,\n WithSize,\n} from '@os-design/styles';\nimport { omitEmotionProps, useForwardedRef } from '@os-design/utils';\nimport styled from '@emotion/styled';\nimport { clr, ThemeOverrider } from '@os-design/theming';\nimport { css } from '@emotion/react';\nimport { Loading } from '@os-design/icons';\nimport getFocusableElements from './utils/getFocusableElements';\n\ntype JsxInputProps = Omit<\n JSX.IntrinsicElements['input'],\n 'value' | 'onChange' | 'size' | 'ref'\n>;\nexport interface InputProps extends JsxInputProps, WithSize {\n /**\n * Type of the input.\n * @default text\n */\n type?: JsxInputProps['type'];\n /**\n * The component located on the left side.\n * @default undefined\n */\n left?: React.ReactNode;\n /**\n * Adds padding to the left component.\n * It can be useful when passing an icon or text in the left component.\n * @default false\n */\n leftHasPadding?: boolean;\n /**\n * The component located on the right side.\n * @default undefined\n */\n right?: React.ReactNode;\n /**\n * Adds padding to the right component.\n * It can be useful when passing an icon or text in the right component.\n * @default false\n */\n rightHasPadding?: boolean;\n /**\n * Whether the input is disabled.\n * @default false\n */\n disabled?: boolean;\n /**\n * Shows the loading status.\n * @default false\n */\n loading?: boolean;\n /**\n * The ref of the input container.\n * @default undefined\n */\n containerRef?: ForwardedRef<HTMLDivElement>;\n /**\n * The props of the input container.\n * @default undefined\n */\n containerProps?: JSX.IntrinsicElements['div'];\n /**\n * The input value.\n * @default undefined\n */\n value?: string;\n /**\n * The change event handler.\n * @default undefined\n */\n onChange?: (value: string, e: ChangeEvent<HTMLInputElement>) => void;\n}\n\nconst hoverStyles = (p) =>\n !p.disabled &&\n css`\n @media (hover: hover) {\n &:hover {\n border-color: ${clr(p.theme.inputHoverColorBorder)};\n }\n }\n `;\n\nconst focusStyles = (p) =>\n !p.disabled &&\n css`\n &:focus-within {\n border-color: ${clr(p.theme.inputFocusColorBorder)};\n box-shadow: 0 0 0 0.15em ${clr(p.theme.inputFocusColorShadow)};\n }\n `;\n\nconst disabledStyles = (p) =>\n p.disabled &&\n css`\n cursor: not-allowed;\n color: ${clr(p.theme.inputDisabledColorText)};\n background-color: ${clr(p.theme.inputDisabledColorBg)};\n border-color: ${clr(p.theme.inputDisabledColorBorder)};\n\n input,\n textarea {\n cursor: not-allowed;\n &::placeholder {\n color: ${clr(p.theme.inputDisabledColorPlaceholder)};\n }\n }\n `;\n\ntype InputContainerProps = Pick<InputProps, 'disabled' | 'size'>;\nexport const InputContainer = styled(\n 'div',\n omitEmotionProps('disabled', 'size')\n)<InputContainerProps>`\n ${resetFocusStyles};\n\n display: inline-flex;\n width: 100%;\n height: ${(p) => p.theme.baseHeight}em;\n box-sizing: border-box;\n background-color: ${(p) => clr(p.theme.inputColorBg)};\n\n border: ${(p) => p.theme.inputBorderWidth}px solid\n ${(p) => clr(p.theme.inputColorBorder)};\n border-radius: ${(p) => p.theme.borderRadius}em;\n\n ${hoverStyles};\n ${focusStyles};\n ${disabledStyles};\n ${sizeStyles};\n ${transitionStyles('border-color', 'box-shadow')};\n`;\n\nconst notHasLeftStyles = (p) =>\n !p.hasLeft &&\n css`\n padding-left: ${p.theme.inputPaddingHorizontal}em;\n `;\n\nconst notHasRightStyles = (p) =>\n !p.hasRight &&\n css`\n padding-right: ${p.theme.inputPaddingHorizontal}em;\n `;\n\ninterface StyledInputProps {\n hasLeft?: boolean;\n hasRight?: boolean;\n}\nexport const StyledInput = styled(\n 'input',\n omitEmotionProps('hasLeft', 'hasRight')\n)<StyledInputProps>`\n ${resetFocusStyles};\n appearance: none;\n border: none;\n font-size: 1em;\n flex: 1;\n overflow: hidden;\n\n color: ${(p) => clr(p.theme.inputColorText)};\n background-color: transparent;\n\n &::placeholder {\n color: ${(p) => clr(p.theme.inputColorPlaceholder)};\n }\n\n ${notHasLeftStyles};\n ${notHasRightStyles};\n`;\n\ninterface AddonProps {\n hasPadding: boolean;\n}\nconst Addon = styled('span', omitEmotionProps('hasPadding'))<AddonProps>`\n display: flex;\n align-items: center;\n user-select: none;\n color: ${(p) => clr(p.theme.inputColorPlaceholder)};\n\n svg {\n transform: scale(1.2);\n }\n`;\n\nconst LeftAddon = styled(Addon)`\n padding-right: ${(p) => p.theme.inputAddonPaddingHorizontal}em;\n ${(p) =>\n p.hasPadding &&\n css`\n padding-left: ${p.theme.inputPaddingHorizontal}em;\n `}\n`;\n\nconst RightAddon = styled(Addon)`\n padding-left: ${(p) => p.theme.inputAddonPaddingHorizontal}em;\n ${(p) =>\n p.hasPadding &&\n css`\n padding-right: ${p.theme.inputPaddingHorizontal}em;\n `}\n`;\n\n/**\n * The basic input component.\n */\nconst Input = forwardRef<HTMLInputElement, InputProps>(\n (\n {\n type = 'text',\n left,\n leftHasPadding = false,\n right,\n rightHasPadding = false,\n disabled = false,\n loading = false,\n containerRef,\n containerProps = {},\n size,\n onChange = () => {},\n ...rest\n },\n ref\n ) => {\n const [innerContainerRef, mergedContainerRef] =\n useForwardedRef(containerRef);\n\n const rightValue = useMemo(\n () => (loading ? <Loading /> : right),\n [loading, right]\n );\n\n const rightHasPaddingValue = useMemo(\n () => (loading ? true : rightHasPadding),\n [loading, rightHasPadding]\n );\n\n return (\n <InputContainer\n disabled={disabled}\n size={size}\n tabIndex={!disabled ? 0 : -1}\n onFocus={(e) => {\n // Focus the next element if the container element was focused.\n // The next element will be the input or button in the addon.\n if (disabled || e.target !== innerContainerRef.current) return;\n const focusableElements = getFocusableElements(\n innerContainerRef.current\n );\n focusableElements[0].focus();\n }}\n onKeyDown={(e) => {\n // Focus the previous element if the first element in the input\n // container is focused and the Shift + Tab combination is pressed.\n const focusableElements = getFocusableElements(document);\n const inputFocusableElements = innerContainerRef.current\n ? getFocusableElements(innerContainerRef.current)\n : [];\n const firstInputElementIsFocused =\n inputFocusableElements[0] === document.activeElement;\n if (firstInputElementIsFocused && e.key === 'Tab' && e.shiftKey) {\n const inputContainerIndex = focusableElements.findIndex(\n (el) => el === innerContainerRef.current\n );\n if (inputContainerIndex === 0) return;\n const elementBeforeInputContainer =\n focusableElements[inputContainerIndex - 1];\n elementBeforeInputContainer.focus();\n }\n }}\n ref={mergedContainerRef}\n {...containerProps}\n >\n {left && (\n <ThemeOverrider overrides={{ buttonPaddingHorizontal: 0.8 }}>\n <LeftAddon hasPadding={leftHasPadding}>{left}</LeftAddon>\n </ThemeOverrider>\n )}\n\n <StyledInput\n type={type}\n disabled={disabled}\n hasLeft={!!left}\n hasRight={!!right}\n onChange={(e) => onChange(e.target.value, e)}\n {...rest}\n ref={ref}\n />\n\n {rightValue && (\n <ThemeOverrider overrides={{ buttonPaddingHorizontal: 0.8 }}>\n <RightAddon hasPadding={rightHasPaddingValue}>\n {rightValue}\n </RightAddon>\n </ThemeOverrider>\n )}\n </InputContainer>\n );\n }\n);\n\nInput.displayName = 'Input';\n\nexport default Input;\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../src/Input/index.tsx"],"names":["hoverStyles","p","disabled","css","theme","inputHoverColorBorder","focusStyles","inputFocusColorBorder","inputFocusColorShadow","disabledStyles","inputDisabledColorText","inputDisabledColorBg","inputDisabledColorBorder","inputDisabledColorPlaceholder","InputContainer","resetFocusStyles","baseHeight","inputColorBg","inputBorderWidth","inputColorBorder","borderRadius","sizeStyles","notHasLeftStyles","hasLeft","inputPaddingHorizontal","notHasRightStyles","hasRight","StyledInput","inputColorText","inputColorPlaceholder","Addon","LeftAddon","inputAddonPaddingHorizontal","hasPadding","RightAddon","Input","ref","type","left","leftHasPadding","right","rightHasPadding","loading","containerRef","containerProps","size","value","onChange","rest","innerContainerRef","mergedContainerRef","rightValue","rightHasPaddingValue","e","target","current","focusableElements","focus","document","inputFocusableElements","firstInputElementIsFocused","activeElement","key","shiftKey","inputContainerIndex","findIndex","el","elementBeforeInputContainer","buttonPaddingHorizontal","displayName"],"mappings":";;;;;;;;;AAAA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,IAAMA,WAAW,GAAG,SAAdA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GAmCGN,IAAI,iBACH,gCAAC,uBAAD;AAAgB,IAAA,SAAS,EAAE;AAAE8B,MAAAA,uBAAuB,EAAE;AAA3B;AAA3B,kBACE,gCAAC,SAAD;AAAW,IAAA,UAAU,EAAE7B;AAAvB,KAAwCD,IAAxC,CADF,CApCJ,eAyCE,gCAAC,WAAD;AACE,IAAA,IAAI,EAAED,IADR;AAEE,IAAA,QAAQ,EAAEnC,QAFZ;AAGE,IAAA,OAAO,EAAE,CAAC,CAACoC,IAHb;AAIE,IAAA,QAAQ,EAAE,CAAC,CAACE,KAJd;AAKE,IAAA,KAAK,EAAEM,KAAK,IAAI,EALlB;AAME,IAAA,QAAQ,EAAE,kBAACO,CAAD;AAAA,aAAON,SAAQ,CAACM,CAAC,CAACC,MAAF,CAASR,KAAV,EAAiBO,CAAjB,CAAf;AAAA;AANZ,KAOML,IAPN;AAQE,IAAA,GAAG,EAAEZ;AARP,KAzCF,EAoDGe,UAAU,iBACT,gCAAC,uBAAD;AAAgB,IAAA,SAAS,EAAE;AAAEiB,MAAAA,uBAAuB,EAAE;AAA3B;AAA3B,kBACE,gCAAC,UAAD;AAAY,IAAA,UAAU,EAAEhB;AAAxB,KACGD,UADH,CADF,CArDJ,CADF;AA8DD,CA9FW,CAAd;AAiGAhB,KAAK,CAACkC,WAAN,GAAoB,OAApB;eAEelC,K","sourcesContent":["import React, { ChangeEvent, ForwardedRef, forwardRef, useMemo } from 'react';\nimport {\n resetFocusStyles,\n sizeStyles,\n transitionStyles,\n WithSize,\n} from '@os-design/styles';\nimport { omitEmotionProps, useForwardedRef } from '@os-design/utils';\nimport styled from '@emotion/styled';\nimport { clr, ThemeOverrider } from '@os-design/theming';\nimport { css } from '@emotion/react';\nimport { Loading } from '@os-design/icons';\nimport getFocusableElements from './utils/getFocusableElements';\n\ntype JsxInputProps = Omit<\n JSX.IntrinsicElements['input'],\n 'value' | 'onChange' | 'size' | 'ref'\n>;\nexport interface InputProps extends JsxInputProps, WithSize {\n /**\n * Type of the input.\n * @default text\n */\n type?: JsxInputProps['type'];\n /**\n * The component located on the left side.\n * @default undefined\n */\n left?: React.ReactNode;\n /**\n * Adds padding to the left component.\n * It can be useful when passing an icon or text in the left component.\n * @default false\n */\n leftHasPadding?: boolean;\n /**\n * The component located on the right side.\n * @default undefined\n */\n right?: React.ReactNode;\n /**\n * Adds padding to the right component.\n * It can be useful when passing an icon or text in the right component.\n * @default false\n */\n rightHasPadding?: boolean;\n /**\n * Whether the input is disabled.\n * @default false\n */\n disabled?: boolean;\n /**\n * Shows the loading status.\n * @default false\n */\n loading?: boolean;\n /**\n * The ref of the input container.\n * @default undefined\n */\n containerRef?: ForwardedRef<HTMLDivElement>;\n /**\n * The props of the input container.\n * @default undefined\n */\n containerProps?: JSX.IntrinsicElements['div'];\n /**\n * The input value.\n * @default undefined\n */\n value?: string;\n /**\n * The change event handler.\n * @default undefined\n */\n onChange?: (value: string, e: ChangeEvent<HTMLInputElement>) => void;\n}\n\nconst hoverStyles = (p) =>\n !p.disabled &&\n css`\n @media (hover: hover) {\n &:hover {\n border-color: ${clr(p.theme.inputHoverColorBorder)};\n }\n }\n `;\n\nconst focusStyles = (p) =>\n !p.disabled &&\n css`\n &:focus-within {\n border-color: ${clr(p.theme.inputFocusColorBorder)};\n box-shadow: 0 0 0 0.15em ${clr(p.theme.inputFocusColorShadow)};\n }\n `;\n\nconst disabledStyles = (p) =>\n p.disabled &&\n css`\n cursor: not-allowed;\n color: ${clr(p.theme.inputDisabledColorText)};\n background-color: ${clr(p.theme.inputDisabledColorBg)};\n border-color: ${clr(p.theme.inputDisabledColorBorder)};\n\n input,\n textarea {\n cursor: not-allowed;\n &::placeholder {\n color: ${clr(p.theme.inputDisabledColorPlaceholder)};\n }\n }\n `;\n\ntype InputContainerProps = Pick<InputProps, 'disabled' | 'size'>;\nexport const InputContainer = styled(\n 'div',\n omitEmotionProps('disabled', 'size')\n)<InputContainerProps>`\n ${resetFocusStyles};\n\n display: inline-flex;\n width: 100%;\n height: ${(p) => p.theme.baseHeight}em;\n box-sizing: border-box;\n background-color: ${(p) => clr(p.theme.inputColorBg)};\n\n border: ${(p) => p.theme.inputBorderWidth}px solid\n ${(p) => clr(p.theme.inputColorBorder)};\n border-radius: ${(p) => p.theme.borderRadius}em;\n\n ${hoverStyles};\n ${focusStyles};\n ${disabledStyles};\n ${sizeStyles};\n ${transitionStyles('border-color', 'box-shadow')};\n`;\n\nconst notHasLeftStyles = (p) =>\n !p.hasLeft &&\n css`\n padding-left: ${p.theme.inputPaddingHorizontal}em;\n `;\n\nconst notHasRightStyles = (p) =>\n !p.hasRight &&\n css`\n padding-right: ${p.theme.inputPaddingHorizontal}em;\n `;\n\ninterface StyledInputProps {\n hasLeft?: boolean;\n hasRight?: boolean;\n}\nexport const StyledInput = styled(\n 'input',\n omitEmotionProps('hasLeft', 'hasRight')\n)<StyledInputProps>`\n ${resetFocusStyles};\n appearance: none;\n border: none;\n font-size: 1em;\n flex: 1;\n overflow: hidden;\n\n color: ${(p) => clr(p.theme.inputColorText)};\n background-color: transparent;\n\n &::placeholder {\n color: ${(p) => clr(p.theme.inputColorPlaceholder)};\n }\n\n ${notHasLeftStyles};\n ${notHasRightStyles};\n`;\n\ninterface AddonProps {\n hasPadding: boolean;\n}\nconst Addon = styled('span', omitEmotionProps('hasPadding'))<AddonProps>`\n display: flex;\n align-items: center;\n user-select: none;\n color: ${(p) => clr(p.theme.inputColorPlaceholder)};\n\n svg {\n transform: scale(1.2);\n }\n`;\n\nconst LeftAddon = styled(Addon)`\n padding-right: ${(p) => p.theme.inputAddonPaddingHorizontal}em;\n ${(p) =>\n p.hasPadding &&\n css`\n padding-left: ${p.theme.inputPaddingHorizontal}em;\n `}\n`;\n\nconst RightAddon = styled(Addon)`\n padding-left: ${(p) => p.theme.inputAddonPaddingHorizontal}em;\n ${(p) =>\n p.hasPadding &&\n css`\n padding-right: ${p.theme.inputPaddingHorizontal}em;\n `}\n`;\n\n/**\n * The basic input component.\n */\nconst Input = forwardRef<HTMLInputElement, InputProps>(\n (\n {\n type = 'text',\n left,\n leftHasPadding = false,\n right,\n rightHasPadding = false,\n disabled = false,\n loading = false,\n containerRef,\n containerProps = {},\n size,\n value,\n onChange = () => {},\n ...rest\n },\n ref\n ) => {\n const [innerContainerRef, mergedContainerRef] =\n useForwardedRef(containerRef);\n\n const rightValue = useMemo(\n () => (loading ? <Loading /> : right),\n [loading, right]\n );\n\n const rightHasPaddingValue = useMemo(\n () => (loading ? true : rightHasPadding),\n [loading, rightHasPadding]\n );\n\n return (\n <InputContainer\n disabled={disabled}\n size={size}\n tabIndex={!disabled ? 0 : -1}\n onFocus={(e) => {\n // Focus the next element if the container element was focused.\n // The next element will be the input or button in the addon.\n if (disabled || e.target !== innerContainerRef.current) return;\n const focusableElements = getFocusableElements(\n innerContainerRef.current\n );\n focusableElements[0].focus();\n }}\n onKeyDown={(e) => {\n // Focus the previous element if the first element in the input\n // container is focused and the Shift + Tab combination is pressed.\n const focusableElements = getFocusableElements(document);\n const inputFocusableElements = innerContainerRef.current\n ? getFocusableElements(innerContainerRef.current)\n : [];\n const firstInputElementIsFocused =\n inputFocusableElements[0] === document.activeElement;\n if (firstInputElementIsFocused && e.key === 'Tab' && e.shiftKey) {\n const inputContainerIndex = focusableElements.findIndex(\n (el) => el === innerContainerRef.current\n );\n if (inputContainerIndex === 0) return;\n const elementBeforeInputContainer =\n focusableElements[inputContainerIndex - 1];\n elementBeforeInputContainer.focus();\n }\n }}\n ref={mergedContainerRef}\n {...containerProps}\n >\n {left && (\n <ThemeOverrider overrides={{ buttonPaddingHorizontal: 0.8 }}>\n <LeftAddon hasPadding={leftHasPadding}>{left}</LeftAddon>\n </ThemeOverrider>\n )}\n\n <StyledInput\n type={type}\n disabled={disabled}\n hasLeft={!!left}\n hasRight={!!right}\n value={value || ''}\n onChange={(e) => onChange(e.target.value, e)}\n {...rest}\n ref={ref}\n />\n\n {rightValue && (\n <ThemeOverrider overrides={{ buttonPaddingHorizontal: 0.8 }}>\n <RightAddon hasPadding={rightHasPaddingValue}>\n {rightValue}\n </RightAddon>\n </ThemeOverrider>\n )}\n </InputContainer>\n );\n }\n);\n\nInput.displayName = 'Input';\n\nexport default Input;\n"],"file":"index.js"}
@@ -122,6 +122,7 @@ const Input = /*#__PURE__*/forwardRef(({
122
122
  containerRef,
123
123
  containerProps = {},
124
124
  size,
125
+ value,
125
126
  onChange = () => {},
126
127
  ...rest
127
128
  }, ref) => {
@@ -165,6 +166,7 @@ const Input = /*#__PURE__*/forwardRef(({
165
166
  disabled: disabled,
166
167
  hasLeft: !!left,
167
168
  hasRight: !!right,
169
+ value: value || '',
168
170
  onChange: e => onChange(e.target.value, e)
169
171
  }, rest, {
170
172
  ref: ref
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/Input/index.tsx"],"names":["React","forwardRef","useMemo","resetFocusStyles","sizeStyles","transitionStyles","omitEmotionProps","useForwardedRef","styled","clr","ThemeOverrider","css","Loading","getFocusableElements","hoverStyles","p","disabled","theme","inputHoverColorBorder","focusStyles","inputFocusColorBorder","inputFocusColorShadow","disabledStyles","inputDisabledColorText","inputDisabledColorBg","inputDisabledColorBorder","inputDisabledColorPlaceholder","InputContainer","baseHeight","inputColorBg","inputBorderWidth","inputColorBorder","borderRadius","notHasLeftStyles","hasLeft","inputPaddingHorizontal","notHasRightStyles","hasRight","StyledInput","inputColorText","inputColorPlaceholder","Addon","LeftAddon","inputAddonPaddingHorizontal","hasPadding","RightAddon","Input","type","left","leftHasPadding","right","rightHasPadding","loading","containerRef","containerProps","size","onChange","rest","ref","innerContainerRef","mergedContainerRef","rightValue","rightHasPaddingValue","e","target","current","focusableElements","focus","document","inputFocusableElements","firstInputElementIsFocused","activeElement","key","shiftKey","inputContainerIndex","findIndex","el","elementBeforeInputContainer","buttonPaddingHorizontal","value","displayName"],"mappings":";;AAAA,OAAOA,KAAP,IAA2CC,UAA3C,EAAuDC,OAAvD,QAAsE,OAAtE;AACA,SACEC,gBADF,EAEEC,UAFF,EAGEC,gBAHF,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QAAAA,2BAA2B,CAACV,KAA5B;AACD;AACF,KA/BH;AAgCE,IAAA,GAAG,EAAEP;AAhCP,KAiCMN,cAjCN,GAmCGN,IAAI,iBACH,oBAAC,cAAD;AAAgB,IAAA,SAAS,EAAE;AAAE8B,MAAAA,uBAAuB,EAAE;AAA3B;AAA3B,kBACE,oBAAC,SAAD;AAAW,IAAA,UAAU,EAAE7B;AAAvB,KAAwCD,IAAxC,CADF,CApCJ,eAyCE,oBAAC,WAAD;AACE,IAAA,IAAI,EAAED,IADR;AAEE,IAAA,QAAQ,EAAE/B,QAFZ;AAGE,IAAA,OAAO,EAAE,CAAC,CAACgC,IAHb;AAIE,IAAA,QAAQ,EAAE,CAAC,CAACE,KAJd;AAKE,IAAA,QAAQ,EAAGa,CAAD,IAAOP,QAAQ,CAACO,CAAC,CAACC,MAAF,CAASe,KAAV,EAAiBhB,CAAjB;AAL3B,KAMMN,IANN;AAOE,IAAA,GAAG,EAAEC;AAPP,KAzCF,EAmDGG,UAAU,iBACT,oBAAC,cAAD;AAAgB,IAAA,SAAS,EAAE;AAAEiB,MAAAA,uBAAuB,EAAE;AAA3B;AAA3B,kBACE,oBAAC,UAAD;AAAY,IAAA,UAAU,EAAEhB;AAAxB,KACGD,UADH,CADF,CApDJ,CADF;AA6DD,CA5FqB,CAAxB;AA+FAf,KAAK,CAACkC,WAAN,GAAoB,OAApB;AAEA,eAAelC,KAAf","sourcesContent":["import React, { ChangeEvent, ForwardedRef, forwardRef, useMemo } from 'react';\nimport {\n resetFocusStyles,\n sizeStyles,\n transitionStyles,\n WithSize,\n} from '@os-design/styles';\nimport { omitEmotionProps, useForwardedRef } from '@os-design/utils';\nimport styled from '@emotion/styled';\nimport { clr, ThemeOverrider } from '@os-design/theming';\nimport { css } from '@emotion/react';\nimport { Loading } from '@os-design/icons';\nimport getFocusableElements from './utils/getFocusableElements';\n\ntype JsxInputProps = Omit<\n JSX.IntrinsicElements['input'],\n 'value' | 'onChange' | 'size' | 'ref'\n>;\nexport interface InputProps extends JsxInputProps, WithSize {\n /**\n * Type of the input.\n * @default text\n */\n type?: JsxInputProps['type'];\n /**\n * The component located on the left side.\n * @default undefined\n */\n left?: React.ReactNode;\n /**\n * Adds padding to the left component.\n * It can be useful when passing an icon or text in the left component.\n * @default false\n */\n leftHasPadding?: boolean;\n /**\n * The component located on the right side.\n * @default undefined\n */\n right?: React.ReactNode;\n /**\n * Adds padding to the right component.\n * It can be useful when passing an icon or text in the right component.\n * @default false\n */\n rightHasPadding?: boolean;\n /**\n * Whether the input is disabled.\n * @default false\n */\n disabled?: boolean;\n /**\n * Shows the loading status.\n * @default false\n */\n loading?: boolean;\n /**\n * The ref of the input container.\n * @default undefined\n */\n containerRef?: ForwardedRef<HTMLDivElement>;\n /**\n * The props of the input container.\n * @default undefined\n */\n containerProps?: JSX.IntrinsicElements['div'];\n /**\n * The input value.\n * @default undefined\n */\n value?: string;\n /**\n * The change event handler.\n * @default undefined\n */\n onChange?: (value: string, e: ChangeEvent<HTMLInputElement>) => void;\n}\n\nconst hoverStyles = (p) =>\n !p.disabled &&\n css`\n @media (hover: hover) {\n &:hover {\n border-color: ${clr(p.theme.inputHoverColorBorder)};\n }\n }\n `;\n\nconst focusStyles = (p) =>\n !p.disabled &&\n css`\n &:focus-within {\n border-color: ${clr(p.theme.inputFocusColorBorder)};\n box-shadow: 0 0 0 0.15em ${clr(p.theme.inputFocusColorShadow)};\n }\n `;\n\nconst disabledStyles = (p) =>\n p.disabled &&\n css`\n cursor: not-allowed;\n color: ${clr(p.theme.inputDisabledColorText)};\n background-color: ${clr(p.theme.inputDisabledColorBg)};\n border-color: ${clr(p.theme.inputDisabledColorBorder)};\n\n input,\n textarea {\n cursor: not-allowed;\n &::placeholder {\n color: ${clr(p.theme.inputDisabledColorPlaceholder)};\n }\n }\n `;\n\ntype InputContainerProps = Pick<InputProps, 'disabled' | 'size'>;\nexport const InputContainer = styled(\n 'div',\n omitEmotionProps('disabled', 'size')\n)<InputContainerProps>`\n ${resetFocusStyles};\n\n display: inline-flex;\n width: 100%;\n height: ${(p) => p.theme.baseHeight}em;\n box-sizing: border-box;\n background-color: ${(p) => clr(p.theme.inputColorBg)};\n\n border: ${(p) => p.theme.inputBorderWidth}px solid\n ${(p) => clr(p.theme.inputColorBorder)};\n border-radius: ${(p) => p.theme.borderRadius}em;\n\n ${hoverStyles};\n ${focusStyles};\n ${disabledStyles};\n ${sizeStyles};\n ${transitionStyles('border-color', 'box-shadow')};\n`;\n\nconst notHasLeftStyles = (p) =>\n !p.hasLeft &&\n css`\n padding-left: ${p.theme.inputPaddingHorizontal}em;\n `;\n\nconst notHasRightStyles = (p) =>\n !p.hasRight &&\n css`\n padding-right: ${p.theme.inputPaddingHorizontal}em;\n `;\n\ninterface StyledInputProps {\n hasLeft?: boolean;\n hasRight?: boolean;\n}\nexport const StyledInput = styled(\n 'input',\n omitEmotionProps('hasLeft', 'hasRight')\n)<StyledInputProps>`\n ${resetFocusStyles};\n appearance: none;\n border: none;\n font-size: 1em;\n flex: 1;\n overflow: hidden;\n\n color: ${(p) => clr(p.theme.inputColorText)};\n background-color: transparent;\n\n &::placeholder {\n color: ${(p) => clr(p.theme.inputColorPlaceholder)};\n }\n\n ${notHasLeftStyles};\n ${notHasRightStyles};\n`;\n\ninterface AddonProps {\n hasPadding: boolean;\n}\nconst Addon = styled('span', omitEmotionProps('hasPadding'))<AddonProps>`\n display: flex;\n align-items: center;\n user-select: none;\n color: ${(p) => clr(p.theme.inputColorPlaceholder)};\n\n svg {\n transform: scale(1.2);\n }\n`;\n\nconst LeftAddon = styled(Addon)`\n padding-right: ${(p) => p.theme.inputAddonPaddingHorizontal}em;\n ${(p) =>\n p.hasPadding &&\n css`\n padding-left: ${p.theme.inputPaddingHorizontal}em;\n `}\n`;\n\nconst RightAddon = styled(Addon)`\n padding-left: ${(p) => p.theme.inputAddonPaddingHorizontal}em;\n ${(p) =>\n p.hasPadding &&\n css`\n padding-right: ${p.theme.inputPaddingHorizontal}em;\n `}\n`;\n\n/**\n * The basic input component.\n */\nconst Input = forwardRef<HTMLInputElement, InputProps>(\n (\n {\n type = 'text',\n left,\n leftHasPadding = false,\n right,\n rightHasPadding = false,\n disabled = false,\n loading = false,\n containerRef,\n containerProps = {},\n size,\n onChange = () => {},\n ...rest\n },\n ref\n ) => {\n const [innerContainerRef, mergedContainerRef] =\n useForwardedRef(containerRef);\n\n const rightValue = useMemo(\n () => (loading ? <Loading /> : right),\n [loading, right]\n );\n\n const rightHasPaddingValue = useMemo(\n () => (loading ? true : rightHasPadding),\n [loading, rightHasPadding]\n );\n\n return (\n <InputContainer\n disabled={disabled}\n size={size}\n tabIndex={!disabled ? 0 : -1}\n onFocus={(e) => {\n // Focus the next element if the container element was focused.\n // The next element will be the input or button in the addon.\n if (disabled || e.target !== innerContainerRef.current) return;\n const focusableElements = getFocusableElements(\n innerContainerRef.current\n );\n focusableElements[0].focus();\n }}\n onKeyDown={(e) => {\n // Focus the previous element if the first element in the input\n // container is focused and the Shift + Tab combination is pressed.\n const focusableElements = getFocusableElements(document);\n const inputFocusableElements = innerContainerRef.current\n ? getFocusableElements(innerContainerRef.current)\n : [];\n const firstInputElementIsFocused =\n inputFocusableElements[0] === document.activeElement;\n if (firstInputElementIsFocused && e.key === 'Tab' && e.shiftKey) {\n const inputContainerIndex = focusableElements.findIndex(\n (el) => el === innerContainerRef.current\n );\n if (inputContainerIndex === 0) return;\n const elementBeforeInputContainer =\n focusableElements[inputContainerIndex - 1];\n elementBeforeInputContainer.focus();\n }\n }}\n ref={mergedContainerRef}\n {...containerProps}\n >\n {left && (\n <ThemeOverrider overrides={{ buttonPaddingHorizontal: 0.8 }}>\n <LeftAddon hasPadding={leftHasPadding}>{left}</LeftAddon>\n </ThemeOverrider>\n )}\n\n <StyledInput\n type={type}\n disabled={disabled}\n hasLeft={!!left}\n hasRight={!!right}\n onChange={(e) => onChange(e.target.value, e)}\n {...rest}\n ref={ref}\n />\n\n {rightValue && (\n <ThemeOverrider overrides={{ buttonPaddingHorizontal: 0.8 }}>\n <RightAddon hasPadding={rightHasPaddingValue}>\n {rightValue}\n </RightAddon>\n </ThemeOverrider>\n )}\n </InputContainer>\n );\n }\n);\n\nInput.displayName = 'Input';\n\nexport default Input;\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../src/Input/index.tsx"],"names":["React","forwardRef","useMemo","resetFocusStyles","sizeStyles","transitionStyles","omitEmotionProps","useForwardedRef","styled","clr","ThemeOverrider","css","Loading","getFocusableElements","hoverStyles","p","disabled","theme","inputHoverColorBorder","focusStyles","inputFocusColorBorder","inputFocusColorShadow","disabledStyles","inputDisabledColorText","inputDisabledColorBg","inputDisabledColorBorder","inputDisabledColorPlaceholder","InputContainer","baseHeight","inputColorBg","inputBorderWidth","inputColorBorder","borderRadius","notHasLeftStyles","hasLeft","inputPaddingHorizontal","notHasRightStyles","hasRight","StyledInput","inputColorText","inputColorPlaceholder","Addon","LeftAddon","inputAddonPaddingHorizontal","hasPadding","RightAddon","Input","type","left","leftHasPadding","right","rightHasPadding","loading","containerRef","containerProps","size","value","onChange","rest","ref","innerContainerRef","mergedContainerRef","rightValue","rightHasPaddingValue","e","target","current","focusableElements","focus","document","inputFocusableElements","firstInputElementIsFocused","activeElement","key","shiftKey","inputContainerIndex","findIndex","el","elementBeforeInputContainer","buttonPaddingHorizontal","displayName"],"mappings":";;AAAA,OAAOA,KAAP,IAA2CC,UAA3C,EAAuDC,OAAvD,QAAsE,OAAtE;AACA,SACEC,gBADF,EAEEC,UAFF,EAGEC,gBAHF,QAKO,mBALP;AAMA,SAASC,gBAAT,EAA2BC,eAA3B,QAAkD,kBAAlD;AACA,OAAOC,MAAP,MAAmB,iBAAnB;AACA,SAASC,GAAT,EAAcC,cAAd,QAAoC,oBAApC;AACA,SAASC,GAAT,QAAoB,gBAApB;AACA,SAASC,OAAT,QAAwB,kBAAxB;AACA,OAAOC,oBAAP,MAAiC,8BAAjC;;AAkEA,MAAMC,WAAW,GAAIC,CAAD,IAClB,CAACA,CAAC,CA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ApCJ,eAyCE,oBAAC,WAAD;AACE,IAAA,IAAI,EAAED,IADR;AAEE,IAAA,QAAQ,EAAE/B,QAFZ;AAGE,IAAA,OAAO,EAAE,CAAC,CAACgC,IAHb;AAIE,IAAA,QAAQ,EAAE,CAAC,CAACE,KAJd;AAKE,IAAA,KAAK,EAAEM,KAAK,IAAI,EALlB;AAME,IAAA,QAAQ,EAAGQ,CAAD,IAAOP,QAAQ,CAACO,CAAC,CAACC,MAAF,CAAST,KAAV,EAAiBQ,CAAjB;AAN3B,KAOMN,IAPN;AAQE,IAAA,GAAG,EAAEC;AARP,KAzCF,EAoDGG,UAAU,iBACT,oBAAC,cAAD;AAAgB,IAAA,SAAS,EAAE;AAAEiB,MAAAA,uBAAuB,EAAE;AAA3B;AAA3B,kBACE,oBAAC,UAAD;AAAY,IAAA,UAAU,EAAEhB;AAAxB,KACGD,UADH,CADF,CArDJ,CADF;AA8DD,CA9FqB,CAAxB;AAiGAhB,KAAK,CAACkC,WAAN,GAAoB,OAApB;AAEA,eAAelC,KAAf","sourcesContent":["import React, { ChangeEvent, ForwardedRef, forwardRef, useMemo } from 'react';\nimport {\n resetFocusStyles,\n sizeStyles,\n transitionStyles,\n WithSize,\n} from '@os-design/styles';\nimport { omitEmotionProps, useForwardedRef } from '@os-design/utils';\nimport styled from '@emotion/styled';\nimport { clr, ThemeOverrider } from '@os-design/theming';\nimport { css } from '@emotion/react';\nimport { Loading } from '@os-design/icons';\nimport getFocusableElements from './utils/getFocusableElements';\n\ntype JsxInputProps = Omit<\n JSX.IntrinsicElements['input'],\n 'value' | 'onChange' | 'size' | 'ref'\n>;\nexport interface InputProps extends JsxInputProps, WithSize {\n /**\n * Type of the input.\n * @default text\n */\n type?: JsxInputProps['type'];\n /**\n * The component located on the left side.\n * @default undefined\n */\n left?: React.ReactNode;\n /**\n * Adds padding to the left component.\n * It can be useful when passing an icon or text in the left component.\n * @default false\n */\n leftHasPadding?: boolean;\n /**\n * The component located on the right side.\n * @default undefined\n */\n right?: React.ReactNode;\n /**\n * Adds padding to the right component.\n * It can be useful when passing an icon or text in the right component.\n * @default false\n */\n rightHasPadding?: boolean;\n /**\n * Whether the input is disabled.\n * @default false\n */\n disabled?: boolean;\n /**\n * Shows the loading status.\n * @default false\n */\n loading?: boolean;\n /**\n * The ref of the input container.\n * @default undefined\n */\n containerRef?: ForwardedRef<HTMLDivElement>;\n /**\n * The props of the input container.\n * @default undefined\n */\n containerProps?: JSX.IntrinsicElements['div'];\n /**\n * The input value.\n * @default undefined\n */\n value?: string;\n /**\n * The change event handler.\n * @default undefined\n */\n onChange?: (value: string, e: ChangeEvent<HTMLInputElement>) => void;\n}\n\nconst hoverStyles = (p) =>\n !p.disabled &&\n css`\n @media (hover: hover) {\n &:hover {\n border-color: ${clr(p.theme.inputHoverColorBorder)};\n }\n }\n `;\n\nconst focusStyles = (p) =>\n !p.disabled &&\n css`\n &:focus-within {\n border-color: ${clr(p.theme.inputFocusColorBorder)};\n box-shadow: 0 0 0 0.15em ${clr(p.theme.inputFocusColorShadow)};\n }\n `;\n\nconst disabledStyles = (p) =>\n p.disabled &&\n css`\n cursor: not-allowed;\n color: ${clr(p.theme.inputDisabledColorText)};\n background-color: ${clr(p.theme.inputDisabledColorBg)};\n border-color: ${clr(p.theme.inputDisabledColorBorder)};\n\n input,\n textarea {\n cursor: not-allowed;\n &::placeholder {\n color: ${clr(p.theme.inputDisabledColorPlaceholder)};\n }\n }\n `;\n\ntype InputContainerProps = Pick<InputProps, 'disabled' | 'size'>;\nexport const InputContainer = styled(\n 'div',\n omitEmotionProps('disabled', 'size')\n)<InputContainerProps>`\n ${resetFocusStyles};\n\n display: inline-flex;\n width: 100%;\n height: ${(p) => p.theme.baseHeight}em;\n box-sizing: border-box;\n background-color: ${(p) => clr(p.theme.inputColorBg)};\n\n border: ${(p) => p.theme.inputBorderWidth}px solid\n ${(p) => clr(p.theme.inputColorBorder)};\n border-radius: ${(p) => p.theme.borderRadius}em;\n\n ${hoverStyles};\n ${focusStyles};\n ${disabledStyles};\n ${sizeStyles};\n ${transitionStyles('border-color', 'box-shadow')};\n`;\n\nconst notHasLeftStyles = (p) =>\n !p.hasLeft &&\n css`\n padding-left: ${p.theme.inputPaddingHorizontal}em;\n `;\n\nconst notHasRightStyles = (p) =>\n !p.hasRight &&\n css`\n padding-right: ${p.theme.inputPaddingHorizontal}em;\n `;\n\ninterface StyledInputProps {\n hasLeft?: boolean;\n hasRight?: boolean;\n}\nexport const StyledInput = styled(\n 'input',\n omitEmotionProps('hasLeft', 'hasRight')\n)<StyledInputProps>`\n ${resetFocusStyles};\n appearance: none;\n border: none;\n font-size: 1em;\n flex: 1;\n overflow: hidden;\n\n color: ${(p) => clr(p.theme.inputColorText)};\n background-color: transparent;\n\n &::placeholder {\n color: ${(p) => clr(p.theme.inputColorPlaceholder)};\n }\n\n ${notHasLeftStyles};\n ${notHasRightStyles};\n`;\n\ninterface AddonProps {\n hasPadding: boolean;\n}\nconst Addon = styled('span', omitEmotionProps('hasPadding'))<AddonProps>`\n display: flex;\n align-items: center;\n user-select: none;\n color: ${(p) => clr(p.theme.inputColorPlaceholder)};\n\n svg {\n transform: scale(1.2);\n }\n`;\n\nconst LeftAddon = styled(Addon)`\n padding-right: ${(p) => p.theme.inputAddonPaddingHorizontal}em;\n ${(p) =>\n p.hasPadding &&\n css`\n padding-left: ${p.theme.inputPaddingHorizontal}em;\n `}\n`;\n\nconst RightAddon = styled(Addon)`\n padding-left: ${(p) => p.theme.inputAddonPaddingHorizontal}em;\n ${(p) =>\n p.hasPadding &&\n css`\n padding-right: ${p.theme.inputPaddingHorizontal}em;\n `}\n`;\n\n/**\n * The basic input component.\n */\nconst Input = forwardRef<HTMLInputElement, InputProps>(\n (\n {\n type = 'text',\n left,\n leftHasPadding = false,\n right,\n rightHasPadding = false,\n disabled = false,\n loading = false,\n containerRef,\n containerProps = {},\n size,\n value,\n onChange = () => {},\n ...rest\n },\n ref\n ) => {\n const [innerContainerRef, mergedContainerRef] =\n useForwardedRef(containerRef);\n\n const rightValue = useMemo(\n () => (loading ? <Loading /> : right),\n [loading, right]\n );\n\n const rightHasPaddingValue = useMemo(\n () => (loading ? true : rightHasPadding),\n [loading, rightHasPadding]\n );\n\n return (\n <InputContainer\n disabled={disabled}\n size={size}\n tabIndex={!disabled ? 0 : -1}\n onFocus={(e) => {\n // Focus the next element if the container element was focused.\n // The next element will be the input or button in the addon.\n if (disabled || e.target !== innerContainerRef.current) return;\n const focusableElements = getFocusableElements(\n innerContainerRef.current\n );\n focusableElements[0].focus();\n }}\n onKeyDown={(e) => {\n // Focus the previous element if the first element in the input\n // container is focused and the Shift + Tab combination is pressed.\n const focusableElements = getFocusableElements(document);\n const inputFocusableElements = innerContainerRef.current\n ? getFocusableElements(innerContainerRef.current)\n : [];\n const firstInputElementIsFocused =\n inputFocusableElements[0] === document.activeElement;\n if (firstInputElementIsFocused && e.key === 'Tab' && e.shiftKey) {\n const inputContainerIndex = focusableElements.findIndex(\n (el) => el === innerContainerRef.current\n );\n if (inputContainerIndex === 0) return;\n const elementBeforeInputContainer =\n focusableElements[inputContainerIndex - 1];\n elementBeforeInputContainer.focus();\n }\n }}\n ref={mergedContainerRef}\n {...containerProps}\n >\n {left && (\n <ThemeOverrider overrides={{ buttonPaddingHorizontal: 0.8 }}>\n <LeftAddon hasPadding={leftHasPadding}>{left}</LeftAddon>\n </ThemeOverrider>\n )}\n\n <StyledInput\n type={type}\n disabled={disabled}\n hasLeft={!!left}\n hasRight={!!right}\n value={value || ''}\n onChange={(e) => onChange(e.target.value, e)}\n {...rest}\n ref={ref}\n />\n\n {rightValue && (\n <ThemeOverrider overrides={{ buttonPaddingHorizontal: 0.8 }}>\n <RightAddon hasPadding={rightHasPaddingValue}>\n {rightValue}\n </RightAddon>\n </ThemeOverrider>\n )}\n </InputContainer>\n );\n }\n);\n\nInput.displayName = 'Input';\n\nexport default Input;\n"],"file":"index.js"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src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1.0.131",
3
+ "version": "1.0.132",
4
4
  "license": "UNLICENSED",
5
5
  "repository": "git@gitlab.com:os-team/libs/os-design.git",
6
6
  "main": "dist/cjs/index.js",
@@ -56,5 +56,5 @@
56
56
  "react": ">=18",
57
57
  "react-dom": ">=18"
58
58
  },
59
- "gitHead": "afbec2e0a1f78f54c4e4adf75a30ed93e758665c"
59
+ "gitHead": "d81c7eedcdf14120ac9d0fa830a5eeb83abf01ac"
60
60
  }