@chayns-components/core 5.0.0-beta.264 → 5.0.0-beta.267

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.
@@ -86,9 +86,7 @@ const Input = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
86
86
  initial: false,
87
87
  layout: true,
88
88
  style: {
89
- ...labelPosition,
90
- originX: 1,
91
- originY: 1
89
+ ...labelPosition
92
90
  },
93
91
  transition: {
94
92
  type: 'tween'
@@ -1 +1 @@
1
- {"version":3,"file":"Input.js","names":["_react","_interopRequireWildcard","require","_Icon","_interopRequireDefault","_Input","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","Input","forwardRef","_ref","ref","iconElement","isDisabled","onBlur","onChange","onFocus","onKeyDown","placeholder","placeholderElement","shouldShowClearIcon","type","value","shouldUseAutoFocus","hasValue","setHasValue","useState","inputRef","useRef","handleClearIconClick","useCallback","current","target","handleInputFieldChange","event","useImperativeHandle","focus","_inputRef$current","useEffect","labelPosition","useMemo","bottom","right","left","top","createElement","StyledInput","className","StyledInputIconWrapper","StyledInputContent","StyledInputField","disabled","autoFocus","StyledMotionInputLabel","animate","scale","initial","layout","style","originX","originY","transition","StyledMotionInputClearIcon","opacity","onClick","icons","displayName","_default","exports"],"sources":["../../../src/components/input/Input.tsx"],"sourcesContent":["import React, {\n ChangeEvent,\n ChangeEventHandler,\n FocusEventHandler,\n forwardRef,\n HTMLInputTypeAttribute,\n KeyboardEventHandler,\n ReactNode,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport Icon from '../icon/Icon';\nimport {\n StyledInput,\n StyledInputContent,\n StyledInputField,\n StyledInputIconWrapper,\n StyledMotionInputClearIcon,\n StyledMotionInputLabel,\n} from './Input.styles';\n\nexport type InputRef = {\n focus: VoidFunction;\n};\n\nexport type InputProps = {\n /**\n * Icon element to be displayed on the left side of the input field\n */\n iconElement?: ReactNode;\n /**\n * Disables the input so that it cannot be changed anymore\n */\n isDisabled?: boolean;\n /**\n * Function that is executed when the input field loses focus\n */\n onBlur?: FocusEventHandler<HTMLInputElement>;\n /**\n * Function that is executed when the text of the input changes\n */\n onChange?: ChangeEventHandler<HTMLInputElement>;\n /**\n * Function that is executed when the input field is focused\n */\n onFocus?: FocusEventHandler<HTMLInputElement>;\n /**\n * Function that is executed when a letter is pressed\n */\n onKeyDown?: KeyboardEventHandler<HTMLInputElement>;\n /**\n * Placeholder for the input field\n */\n placeholder?: string;\n /**\n * Element to be displayed next to or instead of the \"placeholder\"\n */\n placeholderElement?: ReactNode;\n /**\n * If true, a clear icon is displayed at the end of the input field\n */\n shouldShowClearIcon?: boolean;\n /**\n * Input type set for input element (e.g. 'text', 'number' or 'password')\n */\n type?: HTMLInputTypeAttribute;\n /**\n * Value if the input field should be controlled\n */\n value?: string;\n /**\n * If true, the input field is focused when the component is mounted\n */\n shouldUseAutoFocus?: boolean;\n};\n\nconst Input = forwardRef<InputRef, InputProps>(\n (\n {\n iconElement,\n isDisabled,\n onBlur,\n onChange,\n onFocus,\n onKeyDown,\n placeholder,\n placeholderElement,\n shouldShowClearIcon = false,\n type = 'text',\n value,\n shouldUseAutoFocus = false,\n },\n ref\n ) => {\n const [hasValue, setHasValue] = useState(typeof value === 'string' && value !== '');\n\n const inputRef = useRef<HTMLInputElement>(null);\n\n const handleClearIconClick = useCallback(() => {\n if (inputRef.current) {\n inputRef.current.value = '';\n\n if (typeof onChange === 'function') {\n onChange({ target: inputRef.current } as ChangeEvent<HTMLInputElement>);\n }\n }\n }, [onChange]);\n\n const handleInputFieldChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n setHasValue(event.target.value !== '');\n\n if (typeof onChange === 'function') {\n onChange(event);\n }\n },\n [onChange]\n );\n\n useImperativeHandle(\n ref,\n () => ({\n focus: () => inputRef.current?.focus(),\n }),\n []\n );\n\n useEffect(() => {\n if (typeof value === 'string') {\n setHasValue(value !== '');\n }\n }, [value]);\n\n const labelPosition = useMemo(() => {\n if (hasValue) {\n return { bottom: -8, right: -6 };\n }\n\n return { left: 0, top: 0 };\n }, [hasValue]);\n\n return (\n <StyledInput className=\"beta-chayns-input\" isDisabled={isDisabled}>\n {iconElement && <StyledInputIconWrapper>{iconElement}</StyledInputIconWrapper>}\n <StyledInputContent>\n <StyledInputField\n disabled={isDisabled}\n onBlur={onBlur}\n onChange={handleInputFieldChange}\n onFocus={onFocus}\n onKeyDown={onKeyDown}\n ref={inputRef}\n type={type}\n value={value}\n autoFocus={shouldUseAutoFocus}\n />\n <StyledMotionInputLabel\n animate={{ scale: hasValue ? 0.6 : 1 }}\n initial={false}\n layout\n style={{ ...labelPosition, originX: 1, originY: 1 }}\n transition={{ type: 'tween' }}\n >\n {placeholderElement}\n {placeholder}\n </StyledMotionInputLabel>\n </StyledInputContent>\n {shouldShowClearIcon && (\n <StyledMotionInputClearIcon\n animate={{ opacity: hasValue ? 1 : 0 }}\n initial={false}\n onClick={handleClearIconClick}\n transition={{ type: 'tween' }}\n >\n <Icon icons={['fa fa-times']} />\n </StyledMotionInputClearIcon>\n )}\n </StyledInput>\n );\n }\n);\n\nInput.displayName = 'Input';\n\nexport default Input;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAeA,IAAAC,KAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAOwB,SAAAE,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAA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;MAAExC,IAAI,EAAE;IAAQ;EAAE,GAE7BF,kBAAkB,EAClBD,WACmB,CACR,CAAC,EACpBE,mBAAmB,iBAChBxC,MAAA,CAAAQ,OAAA,CAAAyD,aAAA,CAAC5D,MAAA,CAAA6E,0BAA0B;IACvBR,OAAO,EAAE;MAAES,OAAO,EAAEvC,QAAQ,GAAG,CAAC,GAAG;IAAE,CAAE;IACvCgC,OAAO,EAAE,KAAM;IACfQ,OAAO,EAAEnC,oBAAqB;IAC9BgC,UAAU,EAAE;MAAExC,IAAI,EAAE;IAAQ;EAAE,gBAE9BzC,MAAA,CAAAQ,OAAA,CAAAyD,aAAA,CAAC9D,KAAA,CAAAK,OAAI;IAAC6E,KAAK,EAAE,CAAC,aAAa;EAAE,CAAE,CACP,CAEvB,CAAC;AAEtB,CACJ,CAAC;AAEDzD,KAAK,CAAC0D,WAAW,GAAG,OAAO;AAAC,IAAAC,QAAA,GAEb3D,KAAK;AAAA4D,OAAA,CAAAhF,OAAA,GAAA+E,QAAA"}
1
+ {"version":3,"file":"Input.js","names":["_react","_interopRequireWildcard","require","_Icon","_interopRequireDefault","_Input","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","Input","forwardRef","_ref","ref","iconElement","isDisabled","onBlur","onChange","onFocus","onKeyDown","placeholder","placeholderElement","shouldShowClearIcon","type","value","shouldUseAutoFocus","hasValue","setHasValue","useState","inputRef","useRef","handleClearIconClick","useCallback","current","target","handleInputFieldChange","event","useImperativeHandle","focus","_inputRef$current","useEffect","labelPosition","useMemo","bottom","right","left","top","createElement","StyledInput","className","StyledInputIconWrapper","StyledInputContent","StyledInputField","disabled","autoFocus","StyledMotionInputLabel","animate","scale","initial","layout","style","transition","StyledMotionInputClearIcon","opacity","onClick","icons","displayName","_default","exports"],"sources":["../../../src/components/input/Input.tsx"],"sourcesContent":["import React, {\n ChangeEvent,\n ChangeEventHandler,\n FocusEventHandler,\n forwardRef,\n HTMLInputTypeAttribute,\n KeyboardEventHandler,\n ReactNode,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport Icon from '../icon/Icon';\nimport {\n StyledInput,\n StyledInputContent,\n StyledInputField,\n StyledInputIconWrapper,\n StyledMotionInputClearIcon,\n StyledMotionInputLabel,\n} from './Input.styles';\n\nexport type InputRef = {\n focus: VoidFunction;\n};\n\nexport type InputProps = {\n /**\n * Icon element to be displayed on the left side of the input field\n */\n iconElement?: ReactNode;\n /**\n * Disables the input so that it cannot be changed anymore\n */\n isDisabled?: boolean;\n /**\n * Function that is executed when the input field loses focus\n */\n onBlur?: FocusEventHandler<HTMLInputElement>;\n /**\n * Function that is executed when the text of the input changes\n */\n onChange?: ChangeEventHandler<HTMLInputElement>;\n /**\n * Function that is executed when the input field is focused\n */\n onFocus?: FocusEventHandler<HTMLInputElement>;\n /**\n * Function that is executed when a letter is pressed\n */\n onKeyDown?: KeyboardEventHandler<HTMLInputElement>;\n /**\n * Placeholder for the input field\n */\n placeholder?: string;\n /**\n * Element to be displayed next to or instead of the \"placeholder\"\n */\n placeholderElement?: ReactNode;\n /**\n * If true, a clear icon is displayed at the end of the input field\n */\n shouldShowClearIcon?: boolean;\n /**\n * Input type set for input element (e.g. 'text', 'number' or 'password')\n */\n type?: HTMLInputTypeAttribute;\n /**\n * Value if the input field should be controlled\n */\n value?: string;\n /**\n * If true, the input field is focused when the component is mounted\n */\n shouldUseAutoFocus?: boolean;\n};\n\nconst Input = forwardRef<InputRef, InputProps>(\n (\n {\n iconElement,\n isDisabled,\n onBlur,\n onChange,\n onFocus,\n onKeyDown,\n placeholder,\n placeholderElement,\n shouldShowClearIcon = false,\n type = 'text',\n value,\n shouldUseAutoFocus = false,\n },\n ref\n ) => {\n const [hasValue, setHasValue] = useState(typeof value === 'string' && value !== '');\n\n const inputRef = useRef<HTMLInputElement>(null);\n\n const handleClearIconClick = useCallback(() => {\n if (inputRef.current) {\n inputRef.current.value = '';\n\n if (typeof onChange === 'function') {\n onChange({ target: inputRef.current } as ChangeEvent<HTMLInputElement>);\n }\n }\n }, [onChange]);\n\n const handleInputFieldChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n setHasValue(event.target.value !== '');\n\n if (typeof onChange === 'function') {\n onChange(event);\n }\n },\n [onChange]\n );\n\n useImperativeHandle(\n ref,\n () => ({\n focus: () => inputRef.current?.focus(),\n }),\n []\n );\n\n useEffect(() => {\n if (typeof value === 'string') {\n setHasValue(value !== '');\n }\n }, [value]);\n\n const labelPosition = useMemo(() => {\n if (hasValue) {\n return { bottom: -8, right: -6 };\n }\n\n return { left: 0, top: 0 };\n }, [hasValue]);\n\n return (\n <StyledInput className=\"beta-chayns-input\" isDisabled={isDisabled}>\n {iconElement && <StyledInputIconWrapper>{iconElement}</StyledInputIconWrapper>}\n <StyledInputContent>\n <StyledInputField\n disabled={isDisabled}\n onBlur={onBlur}\n onChange={handleInputFieldChange}\n onFocus={onFocus}\n onKeyDown={onKeyDown}\n ref={inputRef}\n type={type}\n value={value}\n autoFocus={shouldUseAutoFocus}\n />\n <StyledMotionInputLabel\n animate={{ scale: hasValue ? 0.6 : 1 }}\n initial={false}\n layout\n style={{ ...labelPosition }}\n transition={{ type: 'tween' }}\n >\n {placeholderElement}\n {placeholder}\n </StyledMotionInputLabel>\n </StyledInputContent>\n {shouldShowClearIcon && (\n <StyledMotionInputClearIcon\n animate={{ opacity: hasValue ? 1 : 0 }}\n initial={false}\n onClick={handleClearIconClick}\n transition={{ type: 'tween' }}\n >\n <Icon icons={['fa fa-times']} />\n </StyledMotionInputClearIcon>\n )}\n </StyledInput>\n );\n }\n);\n\nInput.displayName = 'Input';\n\nexport default Input;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAeA,IAAAC,KAAA,GAAAC,sBAAA,C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AAA,CAAAyD,aAAA,CAAC5D,MAAA,CAAAoE,sBAAsB;IACnBC,OAAO,EAAE;MAAEC,KAAK,EAAE/B,QAAQ,GAAG,GAAG,GAAG;IAAE,CAAE;IACvCgC,OAAO,EAAE,KAAM;IACfC,MAAM;IACNC,KAAK,EAAE;MAAE,GAAGnB;IAAc,CAAE;IAC5BoB,UAAU,EAAE;MAAEtC,IAAI,EAAE;IAAQ;EAAE,GAE7BF,kBAAkB,EAClBD,WACmB,CACR,CAAC,EACpBE,mBAAmB,iBAChBxC,MAAA,CAAAQ,OAAA,CAAAyD,aAAA,CAAC5D,MAAA,CAAA2E,0BAA0B;IACvBN,OAAO,EAAE;MAAEO,OAAO,EAAErC,QAAQ,GAAG,CAAC,GAAG;IAAE,CAAE;IACvCgC,OAAO,EAAE,KAAM;IACfM,OAAO,EAAEjC,oBAAqB;IAC9B8B,UAAU,EAAE;MAAEtC,IAAI,EAAE;IAAQ;EAAE,gBAE9BzC,MAAA,CAAAQ,OAAA,CAAAyD,aAAA,CAAC9D,KAAA,CAAAK,OAAI;IAAC2E,KAAK,EAAE,CAAC,aAAa;EAAE,CAAE,CACP,CAEvB,CAAC;AAEtB,CACJ,CAAC;AAEDvD,KAAK,CAACwD,WAAW,GAAG,OAAO;AAAC,IAAAC,QAAA,GAEbzD,KAAK;AAAA0D,OAAA,CAAA9E,OAAA,GAAA6E,QAAA"}
@@ -99,6 +99,7 @@ const NumberInput = _ref => {
99
99
  handleChange(number);
100
100
  }, [handleChange, number]);
101
101
  return /*#__PURE__*/_react.default.createElement(_Input.default, {
102
+ type: "number",
102
103
  onChange: onChange,
103
104
  value: stringValue,
104
105
  placeholder: placeholder,
@@ -1 +1 @@
1
- {"version":3,"file":"NumberInput.js","names":["_react","_interopRequireWildcard","require","_Input","_interopRequireDefault","_number","_number2","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","NumberInput","_ref","isDecimalInput","isMoneyInput","maxNumber","Infinity","number","placeholder","onNumberChange","isDisabled","stringValue","setStringValue","useState","handleChange","useCallback","newValue","arguments","length","undefined","parsedValue","parseFloatAndRound","toString","formateNumber","onChange","event","target","value","sanitizedValue","replace","NUMBER_CLEAR_REGEX","trim","DECIMAL_TEST","test","parsedNumber","MONEY_TEST","decimals","INTEGER_TEST","Number","onBlur","onFocus","replaceAll","useEffect","createElement","displayName","_default","exports"],"sources":["../../../src/components/number-input/NumberInput.tsx"],"sourcesContent":["import React, { ChangeEvent, FC, useCallback, useEffect, useState } from 'react';\nimport Input from '../input/Input';\nimport { DECIMAL_TEST, INTEGER_TEST, MONEY_TEST, NUMBER_CLEAR_REGEX } from './constants/number';\nimport { formateNumber, parseFloatAndRound } from './utils/number';\n\nexport type NumberInputProps = {\n /**\n * Whether the user can add decimal places. Enables the user to input a zero as first number\n */\n isDecimalInput?: boolean;\n /**\n * Applies rules for money input.\n * Rules: only two decimal places, one leading zero\n */\n isMoneyInput?: boolean;\n /**\n * Limits the number to this value\n */\n maxNumber?: number;\n /**\n * The number that should be displayed formatted in the input field. NOTE: A zero as number is not allowed\n */\n number: number | null;\n /**\n * The placeholder that should be in the input\n */\n placeholder?: string;\n /**\n * Callback function that is called when the input gets out of focus\n */\n onNumberChange: (newNumber: number | null) => void;\n /**\n * Whether the input is disabled\n */\n isDisabled?: boolean;\n};\n\nconst NumberInput: FC<NumberInputProps> = (\n {\n isDecimalInput,\n isMoneyInput,\n maxNumber = Infinity,\n number,\n placeholder,\n onNumberChange,\n isDisabled\n }) => {\n const [stringValue, setStringValue] = useState<string>('');\n\n const handleChange = useCallback((newValue: number | null = null) => {\n if (typeof newValue !== 'number') {\n setStringValue('');\n\n return;\n }\n\n const parsedValue = parseFloatAndRound({ stringValue: newValue?.toString() });\n\n setStringValue(formateNumber({ number: parsedValue, isMoneyInput }));\n }, [isMoneyInput]);\n\n const onChange = (event: ChangeEvent<HTMLInputElement>) => {\n const newValue = event.target.value;\n\n const sanitizedValue = newValue\n // Removes everything except numbers and commas (decimals should be indicated with a comma)\n .replace(NUMBER_CLEAR_REGEX, '')\n // Calculations need points for decimal indication\n .replace(',', '.');\n\n if (sanitizedValue.trim().length > 0) {\n\n // Allows numbers, a comma and any number of decimal places\n if (isDecimalInput && DECIMAL_TEST.test(sanitizedValue)) {\n const parsedNumber = parseFloatAndRound({ stringValue: sanitizedValue });\n\n if (parsedNumber > maxNumber) {\n return;\n }\n\n setStringValue(sanitizedValue.replace('.', ','));\n\n return;\n }\n\n // Allows numbers, a comma and 2 numbers of decimal places\n if (isMoneyInput && MONEY_TEST.test(sanitizedValue)) {\n const parsedNumber = parseFloatAndRound({\n stringValue: sanitizedValue,\n decimals: 2,\n });\n\n if (parsedNumber > maxNumber) {\n return;\n }\n\n setStringValue(sanitizedValue.replace('.', ','));\n\n return;\n }\n\n // Allows numbers but excludes numbers with leading 0\n if (INTEGER_TEST.test(sanitizedValue)) {\n const parsedNumber = Number(sanitizedValue);\n\n if (parsedNumber > maxNumber) {\n return;\n }\n\n setStringValue(sanitizedValue);\n }\n } else {\n setStringValue('');\n }\n };\n\n const onBlur = () => {\n const sanitizedValue = stringValue.length === 0 ? '0' : stringValue;\n const parsedValue = parseFloatAndRound({ stringValue: sanitizedValue });\n\n setStringValue(\n stringValue.length === 0\n ? ''\n : formateNumber({\n number: parsedValue,\n isMoneyInput\n })\n );\n\n onNumberChange(parsedValue === 0 ? null : parsedValue);\n };\n\n const onFocus = () => {\n setStringValue(stringValue.replaceAll('.', ''));\n };\n\n useEffect(() => {\n handleChange(number);\n }, [handleChange, number]);\n\n return (\n <Input\n onChange={onChange}\n value={stringValue}\n placeholder={placeholder}\n onBlur={onBlur}\n onFocus={onFocus}\n isDisabled={isDisabled}\n />\n );\n};\n\nNumberInput.displayName = 'NumberInput';\n\nexport default NumberInput;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GA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CAAC;IAEDK,cAAc,CAACW,WAAW,KAAK,CAAC,GAAG,IAAI,GAAGA,WAAW,CAAC;EAC1D,CAAC;EAED,MAAMoB,OAAO,GAAGA,CAAA,KAAM;IAClB5B,cAAc,CAACD,WAAW,CAAC8B,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;EACnD,CAAC;EAED,IAAAC,gBAAS,EAAC,MAAM;IACZ5B,YAAY,CAACP,MAAM,CAAC;EACxB,CAAC,EAAE,CAACO,YAAY,EAAEP,MAAM,CAAC,CAAC;EAE1B,oBACInC,MAAA,CAAAS,OAAA,CAAA8D,aAAA,CAACpE,MAAA,CAAAM,OAAK;IACF2C,QAAQ,EAAEA,QAAS;IACnBG,KAAK,EAAEhB,WAAY;IACnBH,WAAW,EAAEA,WAAY;IACzB+B,MAAM,EAAEA,MAAO;IACfC,OAAO,EAAEA,OAAQ;IACjB9B,UAAU,EAAEA;EAAW,CAC1B,CAAC;AAEV,CAAC;AAEDT,WAAW,CAAC2C,WAAW,GAAG,aAAa;AAAC,IAAAC,QAAA,GAEzB5C,WAAW;AAAA6C,OAAA,CAAAjE,OAAA,GAAAgE,QAAA"}
1
+ {"version":3,"file":"NumberInput.js","names":["_react","_interopRequireWildcard","require","_Input","_interopRequireDefault","_number","_number2","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","NumberInput","_ref","isDecimalInput","isMoneyInput","maxNumber","Infinity","number","placeholder","onNumberChange","isDisabled","stringValue","setStringValue","useState","handleChange","useCallback","newValue","arguments","length","undefined","parsedValue","parseFloatAndRound","toString","formateNumber","onChange","event","target","value","sanitizedValue","replace","NUMBER_CLEAR_REGEX","trim","DECIMAL_TEST","test","parsedNumber","MONEY_TEST","decimals","INTEGER_TEST","Number","onBlur","onFocus","replaceAll","useEffect","createElement","type","displayName","_default","exports"],"sources":["../../../src/components/number-input/NumberInput.tsx"],"sourcesContent":["import React, { ChangeEvent, FC, useCallback, useEffect, useState } from 'react';\nimport Input from '../input/Input';\nimport { DECIMAL_TEST, INTEGER_TEST, MONEY_TEST, NUMBER_CLEAR_REGEX } from './constants/number';\nimport { formateNumber, parseFloatAndRound } from './utils/number';\n\nexport type NumberInputProps = {\n /**\n * Whether the user can add decimal places. Enables the user to input a zero as first number\n */\n isDecimalInput?: boolean;\n /**\n * Applies rules for money input.\n * Rules: only two decimal places, one leading zero\n */\n isMoneyInput?: boolean;\n /**\n * Limits the number to this value\n */\n maxNumber?: number;\n /**\n * The number that should be displayed formatted in the input field. NOTE: A zero as number is not allowed\n */\n number: number | null;\n /**\n * The placeholder that should be in the input\n */\n placeholder?: string;\n /**\n * Callback function that is called when the input gets out of focus\n */\n onNumberChange: (newNumber: number | null) => void;\n /**\n * Whether the input is disabled\n */\n isDisabled?: boolean;\n};\n\nconst NumberInput: FC<NumberInputProps> = ({\n isDecimalInput,\n isMoneyInput,\n maxNumber = Infinity,\n number,\n placeholder,\n onNumberChange,\n isDisabled,\n}) => {\n const [stringValue, setStringValue] = useState<string>('');\n\n const handleChange = useCallback(\n (newValue: number | null = null) => {\n if (typeof newValue !== 'number') {\n setStringValue('');\n\n return;\n }\n\n const parsedValue = parseFloatAndRound({ stringValue: newValue?.toString() });\n\n setStringValue(formateNumber({ number: parsedValue, isMoneyInput }));\n },\n [isMoneyInput]\n );\n\n const onChange = (event: ChangeEvent<HTMLInputElement>) => {\n const newValue = event.target.value;\n\n const sanitizedValue = newValue\n // Removes everything except numbers and commas (decimals should be indicated with a comma)\n .replace(NUMBER_CLEAR_REGEX, '')\n // Calculations need points for decimal indication\n .replace(',', '.');\n\n if (sanitizedValue.trim().length > 0) {\n // Allows numbers, a comma and any number of decimal places\n if (isDecimalInput && DECIMAL_TEST.test(sanitizedValue)) {\n const parsedNumber = parseFloatAndRound({ stringValue: sanitizedValue });\n\n if (parsedNumber > maxNumber) {\n return;\n }\n\n setStringValue(sanitizedValue.replace('.', ','));\n\n return;\n }\n\n // Allows numbers, a comma and 2 numbers of decimal places\n if (isMoneyInput && MONEY_TEST.test(sanitizedValue)) {\n const parsedNumber = parseFloatAndRound({\n stringValue: sanitizedValue,\n decimals: 2,\n });\n\n if (parsedNumber > maxNumber) {\n return;\n }\n\n setStringValue(sanitizedValue.replace('.', ','));\n\n return;\n }\n\n // Allows numbers but excludes numbers with leading 0\n if (INTEGER_TEST.test(sanitizedValue)) {\n const parsedNumber = Number(sanitizedValue);\n\n if (parsedNumber > maxNumber) {\n return;\n }\n\n setStringValue(sanitizedValue);\n }\n } else {\n setStringValue('');\n }\n };\n\n const onBlur = () => {\n const sanitizedValue = stringValue.length === 0 ? '0' : stringValue;\n const parsedValue = parseFloatAndRound({ stringValue: sanitizedValue });\n\n setStringValue(\n stringValue.length === 0\n ? ''\n : formateNumber({\n number: parsedValue,\n isMoneyInput,\n })\n );\n\n onNumberChange(parsedValue === 0 ? null : parsedValue);\n };\n\n const onFocus = () => {\n setStringValue(stringValue.replaceAll('.', ''));\n };\n\n useEffect(() => {\n handleChange(number);\n }, [handleChange, number]);\n\n return (\n <Input\n type=\"number\"\n onChange={onChange}\n value={stringValue}\n placeholder={placeholder}\n onBlur={onBlur}\n onFocus={onFocus}\n isDisabled={isDisabled}\n />\n );\n};\n\nNumberInput.displayName = 'NumberInput';\n\nexport default NumberInput;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAAmE,SAAAE,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,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AAEP,MAAM,CAAC,CAAC;EAE1B,oBACInC,MAAA,CAAAS,OAAA,CAAA8D,aAAA,CAACpE,MAAA,CAAAM,OAAK;IACF+D,IAAI,EAAC,QAAQ;IACbpB,QAAQ,EAAEA,QAAS;IACnBG,KAAK,EAAEhB,WAAY;IACnBH,WAAW,EAAEA,WAAY;IACzB+B,MAAM,EAAEA,MAAO;IACfC,OAAO,EAAEA,OAAQ;IACjB9B,UAAU,EAAEA;EAAW,CAC1B,CAAC;AAEV,CAAC;AAEDT,WAAW,CAAC4C,WAAW,GAAG,aAAa;AAAC,IAAAC,QAAA,GAEzB7C,WAAW;AAAA8C,OAAA,CAAAlE,OAAA,GAAAiE,QAAA"}
@@ -1,4 +1,4 @@
1
- import { ChangeEventHandler, CSSProperties, FC, FocusEventHandler } from 'react';
1
+ import { ChangeEventHandler, CSSProperties, FC, FocusEventHandler, ReactElement } from 'react';
2
2
  export type TextAreaProps = {
3
3
  /**
4
4
  * The maximum height of the text area.
@@ -15,7 +15,7 @@ export type TextAreaProps = {
15
15
  /**
16
16
  * Placeholder for the text area field.
17
17
  */
18
- placeholder?: string;
18
+ placeholder?: string | ReactElement;
19
19
  /**
20
20
  * Value if the text area should be controlled.
21
21
  */
@@ -58,13 +58,12 @@ const TextArea = _ref => {
58
58
  return (0, _react.useMemo)(() => /*#__PURE__*/_react.default.createElement(_TextArea.StyledTextArea, null, /*#__PURE__*/_react.default.createElement(_TextArea.StyledTextAreaInput, {
59
59
  ref: textareaRef,
60
60
  value: displayedValue,
61
- placeholder: placeholder,
62
61
  onBlur: onBlur,
63
62
  onChange: handleChange,
64
63
  maxHeight: maxHeight,
65
64
  isOverflowing: isOverflowing,
66
65
  rows: 1
67
- })), [displayedValue, handleChange, isOverflowing, maxHeight, onBlur, placeholder]);
66
+ }), !displayedValue && /*#__PURE__*/_react.default.createElement(_TextArea.StyledTextAreaLabel, null, placeholder)), [displayedValue, handleChange, isOverflowing, maxHeight, onBlur, placeholder]);
68
67
  };
69
68
  TextArea.displayName = 'TextArea';
70
69
  var _default = TextArea;
@@ -1 +1 @@
1
- {"version":3,"file":"TextArea.js","names":["_react","_interopRequireWildcard","require","_TextArea","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","TextArea","_ref","placeholder","value","onChange","onBlur","maxHeight","displayedValue","setDisplayedValue","useState","isOverflowing","setIsOverflowing","textareaRef","useRef","adjustTextareaHeight","useCallback","current","style","height","scrollHeight","parseInt","toString","useEffect","length","handleChange","event","target","useMemo","createElement","StyledTextArea","StyledTextAreaInput","ref","rows","displayName","_default","exports"],"sources":["../../../src/components/text-area/TextArea.tsx"],"sourcesContent":["import React, {\n ChangeEvent,\n ChangeEventHandler,\n CSSProperties,\n FC,\n FocusEventHandler,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { StyledTextArea, StyledTextAreaInput } from './TextArea.styles';\n\nexport type TextAreaProps = {\n /**\n * The maximum height of the text area.\n */\n maxHeight?: CSSProperties['maxHeight'];\n /**\n * Function that is executed when the text area loses focus.\n */\n onBlur?: FocusEventHandler<HTMLTextAreaElement>;\n /**\n * Function that is executed when the text of the text area changes.\n */\n onChange?: ChangeEventHandler<HTMLTextAreaElement>;\n /**\n * Placeholder for the text area field.\n */\n placeholder?: string;\n /**\n * Value if the text area should be controlled.\n */\n value?: string;\n};\n\nconst TextArea: FC<TextAreaProps> = ({\n placeholder,\n value,\n onChange,\n onBlur,\n maxHeight = '120px',\n}) => {\n const [displayedValue, setDisplayedValue] = useState('');\n const [isOverflowing, setIsOverflowing] = useState(false);\n\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n\n const adjustTextareaHeight = useCallback(() => {\n if (textareaRef.current) {\n textareaRef.current.style.height = 'auto';\n textareaRef.current.style.height = `${textareaRef.current.scrollHeight}px`;\n\n setIsOverflowing(textareaRef.current.scrollHeight > parseInt(maxHeight.toString(), 10));\n }\n }, [maxHeight]);\n\n /**\n * This hook calculates the height of the TextArea after the displayValue is changed and the content is inside the \"textareaRef\".\n * To maintain the functionality while clearing the input, the length need to be greater than -1.\n */\n useEffect(() => {\n if (displayedValue.length > -1) {\n adjustTextareaHeight();\n }\n }, [adjustTextareaHeight, displayedValue]);\n\n /**\n * This function sets the external value\n */\n useEffect(() => {\n if (typeof value === 'string') {\n setDisplayedValue(value);\n }\n }, [value]);\n\n /**\n * This function updates the value\n */\n const handleChange = useCallback(\n (event: ChangeEvent<HTMLTextAreaElement>) => {\n setDisplayedValue(event.target.value);\n\n if (onChange) {\n onChange(event);\n }\n },\n [onChange]\n );\n\n return useMemo(\n () => (\n <StyledTextArea>\n <StyledTextAreaInput\n ref={textareaRef}\n value={displayedValue}\n placeholder={placeholder}\n onBlur={onBlur}\n onChange={handleChange}\n maxHeight={maxHeight}\n isOverflowing={isOverflowing}\n rows={1}\n />\n </StyledTextArea>\n ),\n [displayedValue, handleChange, isOverflowing, maxHeight, onBlur, placeholder]\n );\n};\n\nTextArea.displayName = 'TextArea';\n\nexport default TextArea;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAYA,IAAAC,SAAA,GAAAD,OAAA;AAAwE,SAAAE,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAJ,wBAAAQ,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,O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BI,aAAa,EAAEA,aAAc;IAC7BsB,IAAI,EAAE;EAAE,CACX,CACW,CACnB,EACD,CAACzB,cAAc,EAAEiB,YAAY,EAAEd,aAAa,EAAEJ,SAAS,EAAED,MAAM,EAAEH,WAAW,CAChF,CAAC;AACL,CAAC;AAEDF,QAAQ,CAACiC,WAAW,GAAG,UAAU;AAAC,IAAAC,QAAA,GAEnBlC,QAAQ;AAAAmC,OAAA,CAAAlD,OAAA,GAAAiD,QAAA"}
1
+ {"version":3,"file":"TextArea.js","names":["_react","_interopRequireWildcard","require","_TextArea","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","TextArea","_ref","placeholder","value","onChange","onBlur","maxHeight","displayedValue","setDisplayedValue","useState","isOverflowing","setIsOverflowing","textareaRef","useRef","adjustTextareaHeight","useCallback","current","style","height","scrollHeight","parseInt","toString","useEffect","length","handleChange","event","target","useMemo","createElement","StyledTextArea","StyledTextAreaInput","ref","rows","StyledTextAreaLabel","displayName","_default","exports"],"sources":["../../../src/components/text-area/TextArea.tsx"],"sourcesContent":["import React, {\n ChangeEvent,\n ChangeEventHandler,\n CSSProperties,\n FC,\n FocusEventHandler,\n ReactElement,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { StyledTextArea, StyledTextAreaInput, StyledTextAreaLabel } from './TextArea.styles';\n\nexport type TextAreaProps = {\n /**\n * The maximum height of the text area.\n */\n maxHeight?: CSSProperties['maxHeight'];\n /**\n * Function that is executed when the text area loses focus.\n */\n onBlur?: FocusEventHandler<HTMLTextAreaElement>;\n /**\n * Function that is executed when the text of the text area changes.\n */\n onChange?: ChangeEventHandler<HTMLTextAreaElement>;\n /**\n * Placeholder for the text area field.\n */\n placeholder?: string | ReactElement;\n /**\n * Value if the text area should be controlled.\n */\n value?: string;\n};\n\nconst TextArea: FC<TextAreaProps> = ({\n placeholder,\n value,\n onChange,\n onBlur,\n maxHeight = '120px',\n}) => {\n const [displayedValue, setDisplayedValue] = useState('');\n const [isOverflowing, setIsOverflowing] = useState(false);\n\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n\n const adjustTextareaHeight = useCallback(() => {\n if (textareaRef.current) {\n textareaRef.current.style.height = 'auto';\n textareaRef.current.style.height = `${textareaRef.current.scrollHeight}px`;\n\n setIsOverflowing(textareaRef.current.scrollHeight > parseInt(maxHeight.toString(), 10));\n }\n }, [maxHeight]);\n\n /**\n * This hook calculates the height of the TextArea after the displayValue is changed and the content is inside the \"textareaRef\".\n * To maintain the functionality while clearing the input, the length need to be greater than -1.\n */\n useEffect(() => {\n if (displayedValue.length > -1) {\n adjustTextareaHeight();\n }\n }, [adjustTextareaHeight, displayedValue]);\n\n /**\n * This function sets the external value\n */\n useEffect(() => {\n if (typeof value === 'string') {\n setDisplayedValue(value);\n }\n }, [value]);\n\n /**\n * This function updates the value\n */\n const handleChange = useCallback(\n (event: ChangeEvent<HTMLTextAreaElement>) => {\n setDisplayedValue(event.target.value);\n\n if (onChange) {\n onChange(event);\n }\n },\n [onChange]\n );\n\n return useMemo(\n () => (\n <StyledTextArea>\n <StyledTextAreaInput\n ref={textareaRef}\n value={displayedValue}\n onBlur={onBlur}\n onChange={handleChange}\n maxHeight={maxHeight}\n isOverflowing={isOverflowing}\n rows={1}\n />\n {!displayedValue && <StyledTextAreaLabel>{placeholder}</StyledTextAreaLabel>}\n </StyledTextArea>\n ),\n [displayedValue, handleChange, isOverflowing, maxHeight, onBlur, placeholder]\n );\n};\n\nTextArea.displayName = 'TextArea';\n\nexport default TextArea;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAaA,IAAAC,SAAA,GAAAD,OAAA;AAA6F,SAAAE,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,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AAAuB,cAAO,EACV,mBACIrD,MAAA,CAAAW,OAAA,CAAA2C,aAAA,CAACnD,SAAA,CAAAoD,cAAc,qBACXvD,MAAA,CAAAW,OAAA,CAAA2C,aAAA,CAACnD,SAAA,CAAAqD,mBAAmB;IAChBC,GAAG,EAAEnB,WAAY;IACjBT,KAAK,EAAEI,cAAe;IACtBF,MAAM,EAAEA,MAAO;IACfD,QAAQ,EAAEoB,YAAa;IACvBlB,SAAS,EAAEA,SAAU;IACrBI,aAAa,EAAEA,aAAc;IAC7BsB,IAAI,EAAE;EAAE,CACX,CAAC,EACD,CAACzB,cAAc,iBAAIjC,MAAA,CAAAW,OAAA,CAAA2C,aAAA,CAACnD,SAAA,CAAAwD,mBAAmB,QAAE/B,WAAiC,CAC/D,CACnB,EACD,CAACK,cAAc,EAAEiB,YAAY,EAAEd,aAAa,EAAEJ,SAAS,EAAED,MAAM,EAAEH,WAAW,CAChF,CAAC;AACL,CAAC;AAEDF,QAAQ,CAACkC,WAAW,GAAG,UAAU;AAAC,IAAAC,QAAA,GAEnBnC,QAAQ;AAAAoC,OAAA,CAAAnD,OAAA,GAAAkD,QAAA"}
@@ -6,3 +6,6 @@ export declare const StyledTextAreaInput: import("styled-components").StyledComp
6
6
  } & {
7
7
  theme: import("../color-scheme-provider/ColorSchemeProvider").Theme;
8
8
  }, never>;
9
+ export declare const StyledTextAreaLabel: import("styled-components").StyledComponent<"label", any, {
10
+ theme: import("../color-scheme-provider/ColorSchemeProvider").Theme;
11
+ }, never>;
@@ -3,31 +3,43 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.StyledTextAreaInput = exports.StyledTextArea = void 0;
6
+ exports.StyledTextAreaLabel = exports.StyledTextAreaInput = exports.StyledTextArea = void 0;
7
7
  var _styledComponents = _interopRequireDefault(require("styled-components"));
8
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- const StyledTextArea = _styledComponents.default.div``;
9
+ const StyledTextArea = _styledComponents.default.div`
10
+ display: flex;
11
+ flex: 1 1 auto;
12
+ min-width: 0;
13
+ margin: 8px 10px;
14
+ position: relative;
15
+ `;
10
16
  exports.StyledTextArea = StyledTextArea;
11
17
  const StyledTextAreaInput = _styledComponents.default.textarea`
12
18
  border-radius: 3px;
13
19
  border: 1px solid rgba(160, 160, 160, 0.3);
14
- color: ${_ref => {
20
+ background-color: ${_ref => {
15
21
  let {
16
22
  theme
17
23
  } = _ref;
18
- return theme['006'];
24
+ return theme['100'];
25
+ }};
26
+ color: ${_ref2 => {
27
+ let {
28
+ theme
29
+ } = _ref2;
30
+ return theme.text;
19
31
  }};
20
32
  resize: none;
21
- overflow-y: ${_ref2 => {
33
+ overflow-y: ${_ref3 => {
22
34
  let {
23
35
  isOverflowing
24
- } = _ref2;
36
+ } = _ref3;
25
37
  return isOverflowing ? 'scroll' : 'hidden';
26
38
  }};
27
- max-height: ${_ref3 => {
39
+ max-height: ${_ref4 => {
28
40
  let {
29
41
  maxHeight
30
- } = _ref3;
42
+ } = _ref4;
31
43
  return maxHeight;
32
44
  }};
33
45
  width: 100%;
@@ -43,4 +55,23 @@ const StyledTextAreaInput = _styledComponents.default.textarea`
43
55
  }
44
56
  `;
45
57
  exports.StyledTextAreaInput = StyledTextAreaInput;
58
+ const StyledTextAreaLabel = _styledComponents.default.label`
59
+ color: ${_ref5 => {
60
+ let {
61
+ theme
62
+ } = _ref5;
63
+ return theme['006'];
64
+ }};
65
+ left: 10px;
66
+ top: 11px;
67
+ align-items: baseline;
68
+ display: flex;
69
+ flex: 0 0 auto;
70
+ gap: 4px;
71
+ line-height: 1.3;
72
+ pointer-events: none;
73
+ position: absolute;
74
+ user-select: none;
75
+ `;
76
+ exports.StyledTextAreaLabel = StyledTextAreaLabel;
46
77
  //# sourceMappingURL=TextArea.styles.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TextArea.styles.js","names":["_styledComponents","_interopRequireDefault","require","obj","__esModule","default","StyledTextArea","styled","div","exports","StyledTextAreaInput","textarea","_ref","theme","_ref2","isOverflowing","_ref3","maxHeight"],"sources":["../../../src/components/text-area/TextArea.styles.ts"],"sourcesContent":["import type { CSSProperties } from 'react';\nimport styled from 'styled-components';\nimport type { WithTheme } from '../color-scheme-provider/ColorSchemeProvider';\n\nexport const StyledTextArea = styled.div``;\n\ntype StyledTextAreaInputProps = WithTheme<{\n maxHeight: CSSProperties['maxHeight'];\n isOverflowing: boolean;\n}>;\n\nexport const StyledTextAreaInput = styled.textarea<StyledTextAreaInputProps>`\n border-radius: 3px;\n border: 1px solid rgba(160, 160, 160, 0.3);\n color: ${({ theme }: StyledTextAreaInputProps) => theme['006']};\n resize: none;\n overflow-y: ${({ isOverflowing }) => (isOverflowing ? 'scroll' : 'hidden')};\n max-height: ${({ maxHeight }: StyledTextAreaInputProps) => maxHeight};\n width: 100%;\n padding: 8px 10px;\n\n &::-webkit-scrollbar {\n width: 5px;\n }\n\n &::-webkit-scrollbar-thumb {\n background: rgba(160, 160, 160, 1);\n border-radius: 3px;\n }\n`;\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAuC,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAGhC,MAAMG,cAAc,GAAGC,yBAAM,CAACC,GAAI,EAAC;AAACC,OAAA,CAAAH,cAAA,GAAAA,cAAA;AAOpC,MAAMI,mBAAmB,GAAGH,yBAAM,CAACI,QAAmC;AAC7E;AACA;AACA,aAAaC,IAAA;EAAA,IAAC;IAAEC;EAAgC,CAAC,GAAAD,IAAA;EAAA,OAAKC,KAAK,CAAC,KAAK,CAAC;AAAA,CAAC;AACnE;AACA,kBAAkBC,KAAA;EAAA,IAAC;IAAEC;EAAc,CAAC,GAAAD,KAAA;EAAA,OAAMC,aAAa,GAAG,QAAQ,GAAG,QAAQ;AAAA,CAAE;AAC/E,kBAAkBC,KAAA;EAAA,IAAC;IAAEC;EAAoC,CAAC,GAAAD,KAAA;EAAA,OAAKC,SAAS;AAAA,CAAC;AACzE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAACR,OAAA,CAAAC,mBAAA,GAAAA,mBAAA"}
1
+ {"version":3,"file":"TextArea.styles.js","names":["_styledComponents","_interopRequireDefault","require","obj","__esModule","default","StyledTextArea","styled","div","exports","StyledTextAreaInput","textarea","_ref","theme","_ref2","text","_ref3","isOverflowing","_ref4","maxHeight","StyledTextAreaLabel","label","_ref5"],"sources":["../../../src/components/text-area/TextArea.styles.ts"],"sourcesContent":["import type { CSSProperties } from 'react';\nimport styled from 'styled-components';\nimport type { WithTheme } from '../color-scheme-provider/ColorSchemeProvider';\nimport { motion } from 'framer-motion';\n\nexport const StyledTextArea = styled.div`\n display: flex;\n flex: 1 1 auto;\n min-width: 0;\n margin: 8px 10px;\n position: relative;\n`;\n\ntype StyledTextAreaInputProps = WithTheme<{\n maxHeight: CSSProperties['maxHeight'];\n isOverflowing: boolean;\n}>;\n\nexport const StyledTextAreaInput = styled.textarea<StyledTextAreaInputProps>`\n border-radius: 3px;\n border: 1px solid rgba(160, 160, 160, 0.3);\n background-color: ${({ theme }: StyledTextAreaInputProps) => theme['100']};\n color: ${({ theme }: StyledTextAreaInputProps) => theme.text};\n resize: none;\n overflow-y: ${({ isOverflowing }) => (isOverflowing ? 'scroll' : 'hidden')};\n max-height: ${({ maxHeight }: StyledTextAreaInputProps) => maxHeight};\n width: 100%;\n padding: 8px 10px;\n\n &::-webkit-scrollbar {\n width: 5px;\n }\n\n &::-webkit-scrollbar-thumb {\n background: rgba(160, 160, 160, 1);\n border-radius: 3px;\n }\n`;\n\ntype StyledTextAreaLabelProps = WithTheme<unknown>;\n\nexport const StyledTextAreaLabel = styled.label<StyledTextAreaLabelProps>`\n color: ${({ theme }: StyledTextAreaLabelProps) => theme['006']};\n left: 10px;\n top: 11px;\n align-items: baseline;\n display: flex;\n flex: 0 0 auto;\n gap: 4px;\n line-height: 1.3;\n pointer-events: none;\n position: absolute;\n user-select: none;\n`;\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAuC,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAIhC,MAAMG,cAAc,GAAGC,yBAAM,CAACC,GAAI;AACzC;AACA;AACA;AACA;AACA;AACA,CAAC;AAACC,OAAA,CAAAH,cAAA,GAAAA,cAAA;AAOK,MAAMI,mBAAmB,GAAGH,yBAAM,CAACI,QAAmC;AAC7E;AACA;AACA,wBAAwBC,IAAA;EAAA,IAAC;IAAEC;EAAgC,CAAC,GAAAD,IAAA;EAAA,OAAKC,KAAK,CAAC,KAAK,CAAC;AAAA,CAAC;AAC9E,aAAaC,KAAA;EAAA,IAAC;IAAED;EAAgC,CAAC,GAAAC,KAAA;EAAA,OAAKD,KAAK,CAACE,IAAI;AAAA,CAAC;AACjE;AACA,kBAAkBC,KAAA;EAAA,IAAC;IAAEC;EAAc,CAAC,GAAAD,KAAA;EAAA,OAAMC,aAAa,GAAG,QAAQ,GAAG,QAAQ;AAAA,CAAE;AAC/E,kBAAkBC,KAAA;EAAA,IAAC;IAAEC;EAAoC,CAAC,GAAAD,KAAA;EAAA,OAAKC,SAAS;AAAA,CAAC;AACzE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAACV,OAAA,CAAAC,mBAAA,GAAAA,mBAAA;AAIK,MAAMU,mBAAmB,GAAGb,yBAAM,CAACc,KAAgC;AAC1E,aAAaC,KAAA;EAAA,IAAC;IAAET;EAAgC,CAAC,GAAAS,KAAA;EAAA,OAAKT,KAAK,CAAC,KAAK,CAAC;AAAA,CAAC;AACnE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAACJ,OAAA,CAAAW,mBAAA,GAAAA,mBAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chayns-components/core",
3
- "version": "5.0.0-beta.264",
3
+ "version": "5.0.0-beta.267",
4
4
  "description": "A set of beautiful React components for developing your own applications with chayns.",
5
5
  "keywords": [
6
6
  "chayns",
@@ -65,5 +65,5 @@
65
65
  "publishConfig": {
66
66
  "access": "public"
67
67
  },
68
- "gitHead": "ce944d4bc9dfe5d8e8465e3a84684f7d7f479b5c"
68
+ "gitHead": "4bb858649b43e62c569eee7dbd575b2278660d3a"
69
69
  }