@chayns-components/core 5.0.0-beta.270 → 5.0.0-beta.272

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.
@@ -14,7 +14,7 @@ export type NumberInputProps = {
14
14
  */
15
15
  maxNumber?: number;
16
16
  /**
17
- * The number that should be displayed formatted in the input field. NOTE: A zero as number is not allowed
17
+ * The number that should be displayed formatted in the input field. NOTE: The number has to match the mode (integer, decimal or money)
18
18
  */
19
19
  number: number | null;
20
20
  /**
@@ -24,7 +24,11 @@ export type NumberInputProps = {
24
24
  /**
25
25
  * Callback function that is called when the input gets out of focus
26
26
  */
27
- onNumberChange: (newNumber: number | null) => void;
27
+ onBlur?: (newNumber: number | null) => void;
28
+ /**
29
+ * Callback function that is called when the input changes
30
+ */
31
+ onChange?: (newNumber: number | null) => void;
28
32
  /**
29
33
  * Whether the input is disabled
30
34
  */
@@ -18,12 +18,18 @@ const NumberInput = _ref => {
18
18
  maxNumber = Infinity,
19
19
  number,
20
20
  placeholder,
21
- onNumberChange,
22
- isDisabled
21
+ onBlur,
22
+ isDisabled,
23
+ onChange
23
24
  } = _ref;
24
25
  const [stringValue, setStringValue] = (0, _react.useState)('');
26
+ const [hasFocus, setHasFocus] = (0, _react.useState)(false);
27
+ const localPlaceholder = placeholder !== null && placeholder !== void 0 ? placeholder : isMoneyInput ? '€' : undefined;
25
28
  const handleChange = (0, _react.useCallback)(function () {
26
29
  let newValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
30
+ if (hasFocus) {
31
+ return;
32
+ }
27
33
  if (typeof newValue !== 'number') {
28
34
  setStringValue('');
29
35
  return;
@@ -35,53 +41,67 @@ const NumberInput = _ref => {
35
41
  number: parsedValue,
36
42
  isMoneyInput
37
43
  }));
38
- }, [isMoneyInput]);
39
- const onChange = event => {
44
+ }, [hasFocus, isMoneyInput]);
45
+ const onLocalChange = event => {
40
46
  const newValue = event.target.value;
41
47
  const sanitizedValue = newValue
42
- // Removes everything except numbers and commas (decimals should be indicated with a comma)
48
+ // Removes everything except numbers, commas and points
43
49
  .replace(_number.NUMBER_CLEAR_REGEX, '')
44
50
  // Calculations need points for decimal indication
45
51
  .replace(',', '.');
46
- if (sanitizedValue.trim().length > 0) {
47
- // Allows numbers, a comma and any number of decimal places
48
- if (isDecimalInput && _number.DECIMAL_TEST.test(sanitizedValue)) {
49
- const parsedNumber = (0, _number2.parseFloatAndRound)({
50
- stringValue: sanitizedValue
51
- });
52
- if (parsedNumber > maxNumber) {
53
- return;
54
- }
55
- setStringValue(sanitizedValue.replace('.', ','));
52
+ if (sanitizedValue.length === 0) {
53
+ setStringValue('');
54
+ if (typeof onChange === 'function') {
55
+ onChange === null || onChange === void 0 || onChange(null);
56
+ }
57
+ return;
58
+ }
59
+
60
+ // Allows numbers, one (comma/point) and any number of decimal places
61
+ if (isDecimalInput && _number.DECIMAL_TEST.test(sanitizedValue)) {
62
+ const parsedNumber = (0, _number2.parseFloatAndRound)({
63
+ stringValue: sanitizedValue
64
+ });
65
+ if (parsedNumber > maxNumber) {
56
66
  return;
57
67
  }
68
+ setStringValue(sanitizedValue.replace('.', ','));
69
+ if (typeof onChange === 'function') {
70
+ onChange(parsedNumber);
71
+ }
72
+ return;
73
+ }
58
74
 
59
- // Allows numbers, a comma and 2 numbers of decimal places
60
- if (isMoneyInput && _number.MONEY_TEST.test(sanitizedValue)) {
61
- const parsedNumber = (0, _number2.parseFloatAndRound)({
62
- stringValue: sanitizedValue,
63
- decimals: 2
64
- });
65
- if (parsedNumber > maxNumber) {
66
- return;
67
- }
68
- setStringValue(sanitizedValue.replace('.', ','));
75
+ // Allows numbers, one (comma/point) and 2 numbers of decimal places
76
+ if (isMoneyInput && _number.MONEY_TEST.test(sanitizedValue)) {
77
+ const parsedNumber = (0, _number2.parseFloatAndRound)({
78
+ stringValue: sanitizedValue,
79
+ decimals: 2
80
+ });
81
+ if (parsedNumber > maxNumber) {
69
82
  return;
70
83
  }
84
+ setStringValue(sanitizedValue.replace('.', ','));
85
+ if (typeof onChange === 'function') {
86
+ onChange(parsedNumber);
87
+ }
88
+ return;
89
+ }
71
90
 
72
- // Allows numbers but excludes numbers with leading 0
73
- if (_number.INTEGER_TEST.test(sanitizedValue)) {
74
- const parsedNumber = Number(sanitizedValue);
75
- if (parsedNumber > maxNumber) {
76
- return;
77
- }
78
- setStringValue(sanitizedValue);
91
+ // Allows numbers but excludes numbers with leading 0
92
+ if (_number.INTEGER_TEST.test(sanitizedValue)) {
93
+ const parsedNumber = Number(sanitizedValue);
94
+ if (parsedNumber > maxNumber) {
95
+ return;
96
+ }
97
+ setStringValue(sanitizedValue);
98
+ if (typeof onChange === 'function') {
99
+ onChange(parsedNumber);
79
100
  }
80
- } else {
81
- setStringValue('');
82
101
  }
83
102
  };
84
- const onBlur = () => {
103
+ const onLocalBlur = () => {
104
+ setHasFocus(false);
85
105
  const sanitizedValue = stringValue.length === 0 ? '0' : stringValue;
86
106
  const parsedValue = (0, _number2.parseFloatAndRound)({
87
107
  stringValue: sanitizedValue
@@ -90,9 +110,12 @@ const NumberInput = _ref => {
90
110
  number: parsedValue,
91
111
  isMoneyInput
92
112
  }));
93
- onNumberChange(parsedValue === 0 ? null : parsedValue);
113
+ if (typeof onBlur === 'function') {
114
+ onBlur(parsedValue === 0 ? null : parsedValue);
115
+ }
94
116
  };
95
117
  const onFocus = () => {
118
+ setHasFocus(true);
96
119
  setStringValue(stringValue.replaceAll('.', ''));
97
120
  };
98
121
  (0, _react.useEffect)(() => {
@@ -100,10 +123,10 @@ const NumberInput = _ref => {
100
123
  }, [handleChange, number]);
101
124
  return /*#__PURE__*/_react.default.createElement(_Input.default, {
102
125
  inputMode: "decimal",
103
- onChange: onChange,
126
+ onChange: onLocalChange,
104
127
  value: stringValue,
105
- placeholder: placeholder,
106
- onBlur: onBlur,
128
+ placeholder: localPlaceholder,
129
+ onBlur: onLocalBlur,
107
130
  onFocus: onFocus,
108
131
  isDisabled: isDisabled
109
132
  });
@@ -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","inputMode","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 inputMode=\"decimal\"\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,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAV,wBAAAM,GAAA,EAAAI,WAAA,SAAAA,WAAA,IAAAJ,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAQ,KAAA,GAAAL,wBAAA,CAAAC,WAAA,OAAAI,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAT,GAAA,YAAAQ,KAAA,CAAAE,GAAA,CAAAV,GAAA,SAAAW,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAhB,GAAA,QAAAgB,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAnB,GAAA,EAAAgB,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAf,GAAA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,WAAW,GAAG,IAAAC,2BAAkB,EAAC;MAAEV,WAAW,EAAEiB;IAAe,CAAC,CAAC;IAEvEhB,cAAc,CACVD,WAAW,CAACO,MAAM,KAAK,CAAC,GAClB,EAAE,GACF,IAAAK,sBAAa,EAAC;MACVhB,MAAM,EAAEa,WAAW;MACnBhB;IACJ,CAAC,CACX,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;IACF+D,SAAS,EAAC,SAAS;IACnBpB,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
+ {"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","onBlur","isDisabled","onChange","stringValue","setStringValue","useState","hasFocus","setHasFocus","localPlaceholder","undefined","handleChange","useCallback","newValue","arguments","length","parsedValue","parseFloatAndRound","toString","formateNumber","onLocalChange","event","target","value","sanitizedValue","replace","NUMBER_CLEAR_REGEX","DECIMAL_TEST","test","parsedNumber","MONEY_TEST","decimals","INTEGER_TEST","Number","onLocalBlur","onFocus","replaceAll","useEffect","createElement","inputMode","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: The number has to match the mode (integer, decimal or money)\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 onBlur?: (newNumber: number | null) => void;\n /**\n * Callback function that is called when the input changes\n */\n onChange?: (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 onBlur,\n isDisabled,\n onChange\n }) => {\n const [stringValue, setStringValue] = useState<string>('');\n const [hasFocus, setHasFocus] = useState<boolean>(false);\n\n const localPlaceholder = placeholder ?? (isMoneyInput ? '€' : undefined);\n\n const handleChange = useCallback(\n (newValue: number | null = null) => {\n if (hasFocus) {\n return;\n }\n\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 [hasFocus, isMoneyInput]\n );\n\n const onLocalChange = (event: ChangeEvent<HTMLInputElement>) => {\n const newValue = event.target.value;\n\n const sanitizedValue = newValue\n // Removes everything except numbers, commas and points\n .replace(NUMBER_CLEAR_REGEX, '')\n // Calculations need points for decimal indication\n .replace(',', '.');\n\n if (sanitizedValue.length === 0) {\n setStringValue('');\n\n if (typeof onChange === 'function') {\n onChange?.(null);\n }\n\n return;\n }\n\n // Allows numbers, one (comma/point) 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 if (typeof onChange === 'function') {\n onChange(parsedNumber);\n }\n\n return;\n }\n\n // Allows numbers, one (comma/point) 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 if (typeof onChange === 'function') {\n onChange(parsedNumber);\n }\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 if (typeof onChange === 'function') {\n onChange(parsedNumber);\n }\n }\n };\n\n const onLocalBlur = () => {\n setHasFocus(false);\n\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 if (typeof onBlur === 'function') {\n onBlur(parsedValue === 0 ? null : parsedValue);\n }\n };\n\n const onFocus = () => {\n setHasFocus(true);\n\n setStringValue(stringValue.replaceAll('.', ''));\n };\n\n useEffect(() => {\n handleChange(number);\n }, [handleChange, number]);\n\n return (\n <Input\n inputMode=\"decimal\"\n onChange={onLocalChange}\n value={stringValue}\n placeholder={localPlaceholder}\n onBlur={onLocalBlur}\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,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAV,wBAAAM,GAAA,EAAAI,WAAA,SAAAA,WAAA,IAAAJ,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAQ,KAAA,GAAAL,wBAAA,CAAAC,WAAA,OAAAI,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAT,GAAA,YAAAQ,KAAA,CAAAE,GAAA,CAAAV,GAAA,SAAAW,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAhB,GAAA,QAAAg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AW,CAACgC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;EACnD,CAAC;EAED,IAAAC,gBAAS,EAAC,MAAM;IACZ1B,YAAY,CAACZ,MAAM,CAAC;EACxB,CAAC,EAAE,CAACY,YAAY,EAAEZ,MAAM,CAAC,CAAC;EAE1B,oBACInC,MAAA,CAAAS,OAAA,CAAAiE,aAAA,CAACvE,MAAA,CAAAM,OAAK;IACFkE,SAAS,EAAC,SAAS;IACnBpC,QAAQ,EAAEiB,aAAc;IACxBG,KAAK,EAAEnB,WAAY;IACnBJ,WAAW,EAAES,gBAAiB;IAC9BR,MAAM,EAAEiC,WAAY;IACpBC,OAAO,EAAEA,OAAQ;IACjBjC,UAAU,EAAEA;EAAW,CAC1B,CAAC;AAEV,CAAC;AAEDT,WAAW,CAAC+C,WAAW,GAAG,aAAa;AAAC,IAAAC,QAAA,GAEzBhD,WAAW;AAAAiD,OAAA,CAAArE,OAAA,GAAAoE,QAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chayns-components/core",
3
- "version": "5.0.0-beta.270",
3
+ "version": "5.0.0-beta.272",
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": "461af323dcc561f3d26eaa731bede9f56818da78"
68
+ "gitHead": "2c406539247224520a4e429c5488ed1cbd37c2f3"
69
69
  }