@tecsinapse/react-core 1.10.2 → 1.10.3

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.10.3](https://github.com/tecsinapse/design-system/compare/@tecsinapse/react-core@1.10.2...@tecsinapse/react-core@1.10.3) (2021-11-29)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * added method extractDigitsFromString ([76daa94](https://github.com/tecsinapse/design-system/commit/76daa943cc1be981b587830d0024c4a01c4df6e2))
12
+ * remove cursor css prop from avatar ([2f9ed15](https://github.com/tecsinapse/design-system/commit/2f9ed15bafb6697e2aee883b417574b4ee3275d5))
13
+
14
+
15
+
16
+
17
+
6
18
  ## [1.10.2](https://github.com/tecsinapse/design-system/compare/@tecsinapse/react-core@1.10.1...@tecsinapse/react-core@1.10.2) (2021-11-16)
7
19
 
8
20
 
@@ -22,9 +22,6 @@ const ContainerButtonAvatar = (0, _native.default)(_PressableSurface.PressableSu
22
22
  theme,
23
23
  size = 'mega'
24
24
  }) => theme.iconSize[size]};
25
- cursor: ${({
26
- onPress
27
- }) => onPress ? 'pointer' : 'default'};
28
25
  `;
29
26
  exports.ContainerButtonAvatar = ContainerButtonAvatar;
30
27
  const StyledAvatar = (0, _native.default)(_reactNative.Image)`
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/atoms/Avatar/styled.ts"],"names":["ContainerButtonAvatar","PressableSurface","theme","size","iconSize","onPress","StyledAvatar","Image","borderRadius","pill","StyledBackground","View","color","secondary","dark","getStyledTextComponent","component"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;;;AAIO,MAAMA,qBAAqB,GAAG,qBAAOC,kCAAP,CAEnC;AACF,WAAW,CAAC;AAAEC,EAAAA,KAAF;AAASC,EAAAA,IAAI,GAAG;AAAhB,CAAD,KACPD,KAAK,CAACE,QAAN,CAAeD,IAAf,CAAqB;AACzB,YAAY,CAAC;AAAED,EAAAA,KAAF;AAASC,EAAAA,IAAI,GAAG;AAAhB,CAAD,KACRD,KAAK,CAACE,QAAN,CAAeD,IAAf,CAAqB;AACzB,YAAY,CAAC;AAAEE,EAAAA;AAAF,CAAD,KAAkBA,OAAO,GAAG,SAAH,GAAe,SAAW;AAC/D,CARO;;AAUA,MAAMC,YAAY,GAAG,qBAAOC,kBAAP,CAAmC;AAC/D,mBAAmB,CAAC;AAAEL,EAAAA;AAAF,CAAD,KAA2BA,KAAK,CAACM,YAAN,CAAmBC,IAAK;AACtE;AACA;AACA;AACA,CALO;;AAOA,MAAMC,gBAAgB,GAAG,qBAAOC,iBAAP,CAAkC;AAClE,mBAAmB,CAAC;AAAET,EAAAA;AAAF,CAAD,KAA2BA,KAAK,CAACM,YAAN,CAAmBC,IAAK;AACtE,sBAAsB,CAAC;AAAEP,EAAAA;AAAF,CAAD,KAA2BA,KAAK,CAACU,KAAN,CAAYC,SAAZ,CAAsBC,IAAK;AAC5E;AACA;AACA;AACA;AACA;AACA;AACA,CATO;;;AAWA,MAAMC,sBAAsB,GAAIC,SAAD,IAA8B;AAClE,SAAO,qBAAOA,SAAP,CAAkB;AAC3B;AACA;AACA;AACA;AACA,GALE;AAMD,CAPM","sourcesContent":["import styled from '@emotion/native';\nimport { FC } from 'react';\nimport { Image, View } from 'react-native';\nimport { StyleProps } from '../../../types/defaults';\nimport { PressableSurface } from '../PressableSurface';\nimport { TextProps } from '../Text';\nimport { AvatarProps } from './Avatar';\n\nexport const ContainerButtonAvatar = styled(PressableSurface)<\n Partial<StyleProps & AvatarProps>\n>`\n width: ${({ theme, size = 'mega' }: StyleProps & Partial<AvatarProps>) =>\n theme.iconSize[size]};\n height: ${({ theme, size = 'mega' }: StyleProps & Partial<AvatarProps>) =>\n theme.iconSize[size]};\n cursor: ${({ onPress }) => (onPress ? 'pointer' : 'default')};\n`;\n\nexport const StyledAvatar = styled(Image)<Partial<StyleProps>>`\n border-radius: ${({ theme }: StyleProps) => theme.borderRadius.pill};\n overflow: hidden;\n width: 100%;\n height: 100%;\n`;\n\nexport const StyledBackground = styled(View)<Partial<StyleProps>>`\n border-radius: ${({ theme }: StyleProps) => theme.borderRadius.pill};\n background-color: ${({ theme }: StyleProps) => theme.color.secondary.dark};\n width: 100%;\n height: 100%;\n display: flex;\n align-items: center;\n justify-content: center;\n flex-direction: row;\n`;\n\nexport const getStyledTextComponent = (component: FC<TextProps>) => {\n return styled(component)`\n text-transform: uppercase;\n text-align: center;\n align-self: center;\n flex: 1;\n `;\n};\n"],"file":"styled.js"}
1
+ {"version":3,"sources":["../../../../src/components/atoms/Avatar/styled.ts"],"names":["ContainerButtonAvatar","PressableSurface","theme","size","iconSize","StyledAvatar","Image","borderRadius","pill","StyledBackground","View","color","secondary","dark","getStyledTextComponent","component"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;;;AAIO,MAAMA,qBAAqB,GAAG,qBAAOC,kCAAP,CAEnC;AACF,WAAW,CAAC;AAAEC,EAAAA,KAAF;AAASC,EAAAA,IAAI,GAAG;AAAhB,CAAD,KACPD,KAAK,CAACE,QAAN,CAAeD,IAAf,CAAqB;AACzB,YAAY,CAAC;AAAED,EAAAA,KAAF;AAASC,EAAAA,IAAI,GAAG;AAAhB,CAAD,KACRD,KAAK,CAACE,QAAN,CAAeD,IAAf,CAAqB;AACzB,CAPO;;AASA,MAAME,YAAY,GAAG,qBAAOC,kBAAP,CAAmC;AAC/D,mBAAmB,CAAC;AAAEJ,EAAAA;AAAF,CAAD,KAA2BA,KAAK,CAACK,YAAN,CAAmBC,IAAK;AACtE;AACA;AACA;AACA,CALO;;AAOA,MAAMC,gBAAgB,GAAG,qBAAOC,iBAAP,CAAkC;AAClE,mBAAmB,CAAC;AAAER,EAAAA;AAAF,CAAD,KAA2BA,KAAK,CAACK,YAAN,CAAmBC,IAAK;AACtE,sBAAsB,CAAC;AAAEN,EAAAA;AAAF,CAAD,KAA2BA,KAAK,CAACS,KAAN,CAAYC,SAAZ,CAAsBC,IAAK;AAC5E;AACA;AACA;AACA;AACA;AACA;AACA,CATO;;;AAWA,MAAMC,sBAAsB,GAAIC,SAAD,IAA8B;AAClE,SAAO,qBAAOA,SAAP,CAAkB;AAC3B;AACA;AACA;AACA;AACA,GALE;AAMD,CAPM","sourcesContent":["import styled from '@emotion/native';\nimport { FC } from 'react';\nimport { Image, View } from 'react-native';\nimport { StyleProps } from '../../../types/defaults';\nimport { PressableSurface } from '../PressableSurface';\nimport { TextProps } from '../Text';\nimport { AvatarProps } from './Avatar';\n\nexport const ContainerButtonAvatar = styled(PressableSurface)<\n Partial<StyleProps & AvatarProps>\n>`\n width: ${({ theme, size = 'mega' }: StyleProps & Partial<AvatarProps>) =>\n theme.iconSize[size]};\n height: ${({ theme, size = 'mega' }: StyleProps & Partial<AvatarProps>) =>\n theme.iconSize[size]};\n`;\n\nexport const StyledAvatar = styled(Image)<Partial<StyleProps>>`\n border-radius: ${({ theme }: StyleProps) => theme.borderRadius.pill};\n overflow: hidden;\n width: 100%;\n height: 100%;\n`;\n\nexport const StyledBackground = styled(View)<Partial<StyleProps>>`\n border-radius: ${({ theme }: StyleProps) => theme.borderRadius.pill};\n background-color: ${({ theme }: StyleProps) => theme.color.secondary.dark};\n width: 100%;\n height: 100%;\n display: flex;\n align-items: center;\n justify-content: center;\n flex-direction: row;\n`;\n\nexport const getStyledTextComponent = (component: FC<TextProps>) => {\n return styled(component)`\n text-transform: uppercase;\n text-align: center;\n align-self: center;\n flex: 1;\n `;\n};\n"],"file":"styled.js"}
@@ -30,7 +30,7 @@ const getMask = (value = '', mask) => {
30
30
 
31
31
  const useMask = (mask, defaultValue) => {
32
32
  const applyMask = (0, _react.useCallback)((value = '') => {
33
- const onlyNumbers = value ? String((0, _reactCore.extractNumbersFromString)(value)) : value;
33
+ const onlyNumbers = value ? (0, _reactCore.extractDigitsFromString)(value) : value;
34
34
  const selectedMask = getMask(onlyNumbers, mask);
35
35
  const formattedValue = mergeMask(onlyNumbers, selectedMask);
36
36
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/components/atoms/Input/hooks/useMask.ts"],"names":["mergeMask","value","mask","chars","formattedValue","iMask","iChars","length","charAt","getMask","useMask","defaultValue","applyMask","onlyNumbers","String","selectedMask","raw","formatted","setValue","converter","maskValue","handleChangeValue","oldValue"],"mappings":";;;;;;;AAAA;;AACA;;AAkBA,MAAMA,SAAS,GAAG,CAACC,KAAK,GAAG,EAAT,EAAaC,IAAb,KAA8B;AAC9C,QAAMC,KAAK,GAAG,KAAKF,KAAnB;AACA,MAAIG,cAAc,GAAG,EAArB;;AAEA,OACE,IAAIC,KAAK,GAAG,CAAZ,EAAeC,MAAM,GAAG,CAD1B,EAEED,KAAK,GAAGH,IAAI,CAACK,MAAb,IAAuBD,MAAM,GAAGH,KAAK,CAACI,MAFxC,EAGEF,KAAK,EAHP,EAIE;AACAD,IAAAA,cAAc,IACZF,IAAI,CAACM,MAAL,CAAYH,KAAZ,MAAuB,GAAvB,GAA6BF,KAAK,CAACK,MAAN,CAAaF,MAAM,EAAnB,CAA7B,GAAsDJ,IAAI,CAACM,MAAL,CAAYH,KAAZ,CADxD;AAED;;AACD,SAAOD,cAAP;AACD,CAbD;;AAqBA,MAAMK,OAAO,GAAG,CAACR,KAAK,GAAG,EAAT,EAAaC,IAAb,KAA+D;AAC7E,MAAI,OAAOA,IAAP,KAAgB,UAApB,EAAgC;AAC9B,WAAOA,IAAI,CAACD,KAAD,CAAX;AACD;;AACD,SAAOC,IAAP;AACD,CALD;;AAaO,MAAMQ,OAAO,GAAG,CACrBR,IADqB,EAErBS,YAFqB,KAGe;AACpC,QAAMC,SAAS,GAAG,wBAChB,CAACX,KAAK,GAAG,EAAT,KAA4B;AAC1B,UAAMY,WAAW,GAAGZ,KAAK,GACrBa,MAAM,CAAC,yCAAyBb,KAAzB,CAAD,CADe,GAErBA,KAFJ;AAGA,UAAMc,YAAY,GAAGN,OAAO,CAACI,WAAD,EAAcX,IAAd,CAA5B;AACA,UAAME,cAAc,GAAGJ,SAAS,CAACa,WAAD,EAAcE,YAAd,CAAhC;AAEA,WAAO;AACLC,MAAAA,GAAG,EAAEH,WADA;AAELI,MAAAA,SAAS,EAAEb;AAFN,KAAP;AAID,GAZe,EAahB,CAACF,IAAD,CAbgB,CAAlB;AAgBA,QAAM,CAACD,KAAD,EAAQiB,QAAR,IAAoB,qBAAgB;AACxCC,IAAAA,SAAS,EAAEP,SAD6B;AAExCQ,IAAAA,SAAS,EAAER,SAAS,CAACD,YAAD;AAFoB,GAAhB,CAA1B;AAKA,QAAMU,iBAAiB,GAAG,wBACvBpB,KAAD,IAAmB;AACjB,UAAM;AAAEe,MAAAA,GAAF;AAAOC,MAAAA;AAAP,QAAqBL,SAAS,CAACX,KAAD,CAApC;AACAiB,IAAAA,QAAQ,CAACI,QAAQ,KAAK,EACpB,GAAGA,QADiB;AAEpBF,MAAAA,SAAS,EAAE;AACTJ,QAAAA,GADS;AAETC,QAAAA;AAFS;AAFS,KAAL,CAAT,CAAR;AAOD,GAVuB,EAWxB,CAACL,SAAD,EAAYM,QAAZ,CAXwB,CAA1B;AAcA,SAAO,CAACjB,KAAD,EAAQoB,iBAAR,CAAP;AACD,CAxCM","sourcesContent":["import { useCallback, useState } from 'react';\nimport { extractNumbersFromString } from '@tecsinapse/react-core';\n\nexport interface IMaskValue {\n formatted?: string;\n raw?: any;\n}\n\nexport interface IMask {\n converter?: (raw?: string) => IMaskValue;\n maskValue?: IMaskValue;\n}\n\n/**\n * TODO:\n * @param value\n * @param mask\n * @returns\n */\nconst mergeMask = (value = '', mask: string) => {\n const chars = '' + value;\n let formattedValue = '';\n\n for (\n let iMask = 0, iChars = 0;\n iMask < mask.length && iChars < chars.length;\n iMask++\n ) {\n formattedValue +=\n mask.charAt(iMask) === '9' ? chars.charAt(iChars++) : mask.charAt(iMask);\n }\n return formattedValue;\n};\n\n/**\n * TODO:\n * @param value\n * @param mask\n * @returns\n */\nconst getMask = (value = '', mask: ((raw: any) => string) | string): string => {\n if (typeof mask === 'function') {\n return mask(value);\n }\n return mask;\n};\n\n/**\n * TODO:\n * @param mask\n * @param defaultValue\n * @returns\n */\nexport const useMask = (\n mask: ((raw: any) => string) | string,\n defaultValue?: string\n): [IMask, (text: string) => void] => {\n const applyMask = useCallback(\n (value = ''): IMaskValue => {\n const onlyNumbers = value\n ? String(extractNumbersFromString(value))\n : value;\n const selectedMask = getMask(onlyNumbers, mask);\n const formattedValue = mergeMask(onlyNumbers, selectedMask);\n\n return {\n raw: onlyNumbers,\n formatted: formattedValue,\n };\n },\n [mask]\n );\n\n const [value, setValue] = useState<IMask>({\n converter: applyMask,\n maskValue: applyMask(defaultValue),\n });\n\n const handleChangeValue = useCallback(\n (value: string) => {\n const { raw, formatted } = applyMask(value);\n setValue(oldValue => ({\n ...oldValue,\n maskValue: {\n raw,\n formatted,\n },\n }));\n },\n [applyMask, setValue]\n );\n\n return [value, handleChangeValue];\n};\n"],"file":"useMask.js"}
1
+ {"version":3,"sources":["../../../../../src/components/atoms/Input/hooks/useMask.ts"],"names":["mergeMask","value","mask","chars","formattedValue","iMask","iChars","length","charAt","getMask","useMask","defaultValue","applyMask","onlyNumbers","selectedMask","raw","formatted","setValue","converter","maskValue","handleChangeValue","oldValue"],"mappings":";;;;;;;AAAA;;AACA;;AAkBA,MAAMA,SAAS,GAAG,CAACC,KAAK,GAAG,EAAT,EAAaC,IAAb,KAA8B;AAC9C,QAAMC,KAAK,GAAG,KAAKF,KAAnB;AACA,MAAIG,cAAc,GAAG,EAArB;;AAEA,OACE,IAAIC,KAAK,GAAG,CAAZ,EAAeC,MAAM,GAAG,CAD1B,EAEED,KAAK,GAAGH,IAAI,CAACK,MAAb,IAAuBD,MAAM,GAAGH,KAAK,CAACI,MAFxC,EAGEF,KAAK,EAHP,EAIE;AACAD,IAAAA,cAAc,IACZF,IAAI,CAACM,MAAL,CAAYH,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FS,KAAL,CAAT,CAAR;AAOD,GAVuB,EAWxB,CAACJ,SAAD,EAAYK,QAAZ,CAXwB,CAA1B;AAcA,SAAO,CAAChB,KAAD,EAAQmB,iBAAR,CAAP;AACD,CAtCM","sourcesContent":["import { useCallback, useState } from 'react';\nimport { extractDigitsFromString } from '@tecsinapse/react-core';\n\nexport interface IMaskValue {\n formatted?: string;\n raw?: any;\n}\n\nexport interface IMask {\n converter?: (raw?: string) => IMaskValue;\n maskValue?: IMaskValue;\n}\n\n/**\n * TODO:\n * @param value\n * @param mask\n * @returns\n */\nconst mergeMask = (value = '', mask: string) => {\n const chars = '' + value;\n let formattedValue = '';\n\n for (\n let iMask = 0, iChars = 0;\n iMask < mask.length && iChars < chars.length;\n iMask++\n ) {\n formattedValue +=\n mask.charAt(iMask) === '9' ? chars.charAt(iChars++) : mask.charAt(iMask);\n }\n return formattedValue;\n};\n\n/**\n * TODO:\n * @param value\n * @param mask\n * @returns\n */\nconst getMask = (value = '', mask: ((raw: any) => string) | string): string => {\n if (typeof mask === 'function') {\n return mask(value);\n }\n return mask;\n};\n\n/**\n * TODO:\n * @param mask\n * @param defaultValue\n * @returns\n */\nexport const useMask = (\n mask: ((raw: any) => string) | string,\n defaultValue?: string\n): [IMask, (text: string) => void] => {\n const applyMask = useCallback(\n (value = ''): IMaskValue => {\n const onlyNumbers = value ? extractDigitsFromString(value) : value;\n const selectedMask = getMask(onlyNumbers, mask);\n const formattedValue = mergeMask(onlyNumbers, selectedMask);\n\n return {\n raw: onlyNumbers,\n formatted: formattedValue,\n };\n },\n [mask]\n );\n\n const [value, setValue] = useState<IMask>({\n converter: applyMask,\n maskValue: applyMask(defaultValue),\n });\n\n const handleChangeValue = useCallback(\n (value: string) => {\n const { raw, formatted } = applyMask(value);\n setValue(oldValue => ({\n ...oldValue,\n maskValue: {\n raw,\n formatted,\n },\n }));\n },\n [applyMask, setValue]\n );\n\n return [value, handleChangeValue];\n};\n"],"file":"useMask.js"}
@@ -12,7 +12,7 @@ const Masks = {
12
12
  CEP: '99999-999',
13
13
  PHONE: '(99) 9999-9999',
14
14
  PHONE_EXTENDED: '(99) 99999-9999',
15
- COMBINED_PHONE: value => value.length <= 10 ? Masks.PHONE : Masks.PHONE_EXTENDED
15
+ COMBINED_PHONE: value => (value === null || value === void 0 ? void 0 : value.length) <= 10 ? Masks.PHONE : Masks.PHONE_EXTENDED
16
16
  };
17
17
  exports.Masks = Masks;
18
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/components/atoms/Input/masks/index.ts"],"names":["Masks","CPF","CNPJ","DATE","MONTH_YEAR","CEP","PHONE","PHONE_EXTENDED","COMBINED_PHONE","value","length"],"mappings":";;;;;;AACO,MAAMA,KAAK,GAAG;AACnBC,EAAAA,GAAG,EAAE,gBADc;AAEnBC,EAAAA,IAAI,EAAE,oBAFa;AAGnBC,EAAAA,IAAI,EAAE,YAHa;AAInBC,EAAAA,UAAU,EAAE,SAJO;AAKnBC,EAAAA,GAAG,EAAE,WALc;AAMnBC,EAAAA,KAAK,EAAE,gBANY;AAOnBC,EAAAA,cAAc,EAAE,iBAPG;AAQnBC,EAAAA,cAAc,EAAGC,KAAD,IACdA,KAAK,CAACC,MAAN,IAAgB,EAAhB,GAAqBV,KAAK,CAACM,KAA3B,GAAmCN,KAAK,CAACO;AATxB,CAAd","sourcesContent":["// NOTE: Add here all individually masks, then you can use it on input components everywhere.\nexport const Masks = {\n CPF: '999.999.999-99',\n CNPJ: '99.999.999/9999-99',\n DATE: '99/99/9999',\n MONTH_YEAR: '99/9999',\n CEP: '99999-999',\n PHONE: '(99) 9999-9999',\n PHONE_EXTENDED: '(99) 99999-9999',\n COMBINED_PHONE: (value: string) =>\n value.length <= 10 ? Masks.PHONE : Masks.PHONE_EXTENDED,\n};\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../../src/components/atoms/Input/masks/index.ts"],"names":["Masks","CPF","CNPJ","DATE","MONTH_YEAR","CEP","PHONE","PHONE_EXTENDED","COMBINED_PHONE","value","length"],"mappings":";;;;;;AACO,MAAMA,KAAK,GAAG;AACnBC,EAAAA,GAAG,EAAE,gBADc;AAEnBC,EAAAA,IAAI,EAAE,oBAFa;AAGnBC,EAAAA,IAAI,EAAE,YAHa;AAInBC,EAAAA,UAAU,EAAE,SAJO;AAKnBC,EAAAA,GAAG,EAAE,WALc;AAMnBC,EAAAA,KAAK,EAAE,gBANY;AAOnBC,EAAAA,cAAc,EAAE,iBAPG;AAQnBC,EAAAA,cAAc,EAAGC,KAAD,IACd,CAAAA,KAAK,SAAL,IAAAA,KAAK,WAAL,YAAAA,KAAK,CAAEC,MAAP,KAAiB,EAAjB,GAAsBV,KAAK,CAACM,KAA5B,GAAoCN,KAAK,CAACO;AATzB,CAAd","sourcesContent":["// NOTE: Add here all individually masks, then you can use it on input components everywhere.\nexport const Masks = {\n CPF: '999.999.999-99',\n CNPJ: '99.999.999/9999-99',\n DATE: '99/99/9999',\n MONTH_YEAR: '99/9999',\n CEP: '99999-999',\n PHONE: '(99) 9999-9999',\n PHONE_EXTENDED: '(99) 99999-9999',\n COMBINED_PHONE: (value: string) =>\n value?.length <= 10 ? Masks.PHONE : Masks.PHONE_EXTENDED,\n};\n"],"file":"index.js"}
@@ -10,6 +10,7 @@ export interface SwitchProps {
10
10
  inactiveColorTone?: ColorGradationType;
11
11
  style?: StyleProp<ViewStyle>;
12
12
  dotStyle?: StyleProp<ViewStyle>;
13
+ disabled?: boolean;
13
14
  }
14
15
  declare const Switch: FC<SwitchProps>;
15
16
  export default Switch;
@@ -33,6 +33,7 @@ const Switch = ({
33
33
  inactiveColorTone = 'light',
34
34
  active,
35
35
  dotStyle,
36
+ disabled = false,
36
37
  ...rest
37
38
  }) => {
38
39
  const theme = (0, _react.useTheme)();
@@ -41,9 +42,13 @@ const Switch = ({
41
42
 
42
43
  const animatedColor = _react2.default.useRef(new _reactNative.Animated.Value(active ? 1 : 0)).current;
43
44
 
45
+ const getBackgroundColor = (color, variation) => {
46
+ return disabled ? (0, _utils.lightenDarkenColor)(color, variation) : color;
47
+ };
48
+
44
49
  const interpolateColor = animatedColor.interpolate({
45
50
  inputRange: [0, 1],
46
- outputRange: [theme.color[inactiveColor][inactiveColorTone], theme.color[activeColor][activeColorTone]]
51
+ outputRange: [getBackgroundColor(theme.color[inactiveColor][inactiveColorTone], 25), getBackgroundColor(theme.color[activeColor][activeColorTone], 50)]
47
52
  });
48
53
  const animatedStyle = {
49
54
  backgroundColor: interpolateColor
@@ -52,7 +57,7 @@ const Switch = ({
52
57
  onChange(!active);
53
58
  (0, _animation.transitionSwitch)(active, transitionValue, animatedColor);
54
59
  }, [active, onChange]);
55
- const stylesDefaut = {
60
+ const stylesDefault = {
56
61
  borderRadius: (0, _utils.extractNumbersFromString)(theme.borderRadius.pill),
57
62
  paddingHorizontal: (0, _utils.extractNumbersFromString)(theme.spacing.micro),
58
63
  paddingVertical: 0,
@@ -62,10 +67,11 @@ const Switch = ({
62
67
  };
63
68
  return _react2.default.createElement(_PressableSurface.PressableSurface, _extends({}, rest, {
64
69
  onPress: handleChange,
65
- effect: "none"
70
+ effect: "none",
71
+ disabled: disabled
66
72
  }), _react2.default.createElement(_reactNative.Animated.View, {
67
73
  style: { ...animatedStyle,
68
- ...stylesDefaut
74
+ ...stylesDefault
69
75
  }
70
76
  }, _react2.default.createElement(_styled.StyledSwitch, {
71
77
  style: [dotStyle, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/atoms/Switch/Switch.tsx"],"names":["Switch","onChange","activeColor","activeColorTone","inactiveColor","inactiveColorTone","active","dotStyle","rest","theme","transitionValue","React","useRef","Animated","Value","current","animatedColor","interpolateColor","interpolate","inputRange","outputRange","color","animatedStyle","backgroundColor","handleChange","stylesDefaut","borderRadius","pill","paddingHorizontal","spacing","micro","paddingVertical","justifyContent","width","height","transform","translateX"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AACA;;;;;;;;AAaA,MAAMA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AyBnB,KAAK,CAACoB,OAAN,CAAcC,KAAvC,CAFW;AAG9BC,IAAAA,eAAe,EAAE,CAHa;AAI9BC,IAAAA,cAAc,EAAE,QAJc;AAK9BC,IAAAA,KAAK,EAAE,EALuB;AAM9BC,IAAAA,MAAM,EAAE;AANsB,GAAhC;AASA,SACE,8BAAC,kCAAD,eAAsB1B,IAAtB;AAA4B,IAAA,OAAO,EAAEgB,YAArC;AAAmD,IAAA,MAAM,EAAC;AAA1D,MACE,8BAAC,qBAAD,CAAU,IAAV;AAAe,IAAA,KAAK,EAAE,EAAE,GAAGF,aAAL;AAAoB,SAAGG;AAAvB;AAAtB,KACE,8BAAC,oBAAD;AACE,IAAA,KAAK,EAAE,CAAClB,QAAD,EAAW;AAAE4B,MAAAA,SAAS,EAAE,CAAC;AAAEC,QAAAA,UAAU,EAAE1B;AAAd,OAAD;AAAb,KAAX;AADT,IADF,CADF,CADF;AASD,CArDD;;eAuDeV,M","sourcesContent":["import { useTheme } from '@emotion/react';\nimport React, { FC, useCallback } from 'react';\nimport { Animated, StyleProp, ViewStyle } from 'react-native';\nimport {\n ColorGradationType,\n ColorType,\n ThemeProp,\n} from '../../../types/defaults';\nimport { PressableSurface } from '../PressableSurface';\nimport { StyledSwitch } from './styled';\nimport { transitionSwitch } from './animation';\nimport { extractNumbersFromString } from '../../../utils';\n\nexport interface SwitchProps {\n onChange: (active: boolean) => void;\n active: boolean;\n activeColor?: ColorType;\n activeColorTone?: ColorGradationType;\n inactiveColor?: ColorType;\n inactiveColorTone?: ColorGradationType;\n style?: StyleProp<ViewStyle>;\n dotStyle?: StyleProp<ViewStyle>;\n}\n\nconst Switch: FC<SwitchProps> = ({\n onChange,\n activeColor = 'primary',\n activeColorTone = 'medium',\n inactiveColor = 'secondary',\n inactiveColorTone = 'light',\n active,\n dotStyle,\n ...rest\n}): JSX.Element => {\n const theme = useTheme() as ThemeProp;\n\n const transitionValue = React.useRef(new Animated.Value(active ? 16.5 : 0))\n .current;\n\n const animatedColor = React.useRef(new Animated.Value(active ? 1 : 0))\n .current;\n\n const interpolateColor = animatedColor.interpolate({\n inputRange: [0, 1],\n outputRange: [\n theme.color[inactiveColor][inactiveColorTone],\n theme.color[activeColor][activeColorTone],\n ],\n });\n\n const animatedStyle = {\n backgroundColor: interpolateColor,\n };\n\n const handleChange = useCallback(() => {\n onChange(!active);\n transitionSwitch(active, transitionValue, animatedColor);\n }, [active, onChange]);\n\n const stylesDefaut: ViewStyle = {\n borderRadius: extractNumbersFromString(theme.borderRadius.pill),\n paddingHorizontal: extractNumbersFromString(theme.spacing.micro),\n paddingVertical: 0,\n justifyContent: 'center',\n width: 40,\n height: 22,\n };\n\n return (\n <PressableSurface {...rest} onPress={handleChange} effect=\"none\">\n <Animated.View style={{ ...animatedStyle, ...stylesDefaut }}>\n <StyledSwitch\n style={[dotStyle, { transform: [{ translateX: transitionValue }] }]}\n />\n </Animated.View>\n </PressableSurface>\n );\n};\n\nexport default Switch;\n"],"file":"Switch.js"}
1
+ {"version":3,"sources":["../../../../src/components/atoms/Switch/Switch.tsx"],"names":["Switch","onChange","activeColor","activeColorTone","inactiveColor","inactiveColorTone","active","dotStyle","disabled","rest","theme","transitionValue","React","useRef","Animated","Value","current","animatedColor","getBackgroundColor","color","variation","interpolateColor","interpolate","inputRange","outputRange","animatedStyle","backgroundColor","handleChange","stylesDefault","borderRadius","pill","paddingHorizontal","spacing","micro","paddingVertical","justifyContent","width","height","transform","translateX"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AACA;;;;;;;;AAcA,MAAMA,MAAuB,GAAG,CAAC;AAC/BC,EAAAA,QAD+B;AAE/BC,EAAAA,WAAW,GAAG,SAFiB;AAG/BC,EAAAA,eAAe,GAAG,QAHa;AAI/BC,EAAAA,aAAa,GAAG,WAJe;AAK/BC,EAAAA,iBAAiB,GAAG,OALW;AAM/BC,EAAAA,MAN+B;AAO/BC,EAAAA,QAP+B;AAQ/BC,EAAAA,QAAQ,GAAG,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E,qCAAyBrB,KAAK,CAACsB,OAAN,CAAcC,KAAvC,CAFY;AAG/BC,IAAAA,eAAe,EAAE,CAHc;AAI/BC,IAAAA,cAAc,EAAE,QAJe;AAK/BC,IAAAA,KAAK,EAAE,EALwB;AAM/BC,IAAAA,MAAM,EAAE;AANuB,GAAjC;AASA,SACE,8BAAC,kCAAD,eACM5B,IADN;AAEE,IAAA,OAAO,EAAEkB,YAFX;AAGE,IAAA,MAAM,EAAC,MAHT;AAIE,IAAA,QAAQ,EAAEnB;AAJZ,MAME,8BAAC,qBAAD,CAAU,IAAV;AAAe,IAAA,KAAK,EAAE,EAAE,GAAGiB,aAAL;AAAoB,SAAGG;AAAvB;AAAtB,KACE,8BAAC,oBAAD;AACE,IAAA,KAAK,EAAE,CAACrB,QAAD,EAAW;AAAE+B,MAAAA,SAAS,EAAE,CAAC;AAAEC,QAAAA,UAAU,EAAE5B;AAAd,OAAD;AAAb,KAAX;AADT,IADF,CANF,CADF;AAcD,CA/DD;;eAiEeX,M","sourcesContent":["import { useTheme } from '@emotion/react';\nimport React, { FC, useCallback } from 'react';\nimport { Animated, StyleProp, ViewStyle } from 'react-native';\nimport {\n ColorGradationType,\n ColorType,\n ThemeProp,\n} from '../../../types/defaults';\nimport { PressableSurface } from '../PressableSurface';\nimport { StyledSwitch } from './styled';\nimport { transitionSwitch } from './animation';\nimport { extractNumbersFromString, lightenDarkenColor } from '../../../utils';\n\nexport interface SwitchProps {\n onChange: (active: boolean) => void;\n active: boolean;\n activeColor?: ColorType;\n activeColorTone?: ColorGradationType;\n inactiveColor?: ColorType;\n inactiveColorTone?: ColorGradationType;\n style?: StyleProp<ViewStyle>;\n dotStyle?: StyleProp<ViewStyle>;\n disabled?: boolean;\n}\n\nconst Switch: FC<SwitchProps> = ({\n onChange,\n activeColor = 'primary',\n activeColorTone = 'medium',\n inactiveColor = 'secondary',\n inactiveColorTone = 'light',\n active,\n dotStyle,\n disabled = false,\n ...rest\n}): JSX.Element => {\n const theme = useTheme() as ThemeProp;\n\n const transitionValue = React.useRef(new Animated.Value(active ? 16.5 : 0))\n .current;\n\n const animatedColor = React.useRef(new Animated.Value(active ? 1 : 0))\n .current;\n\n const getBackgroundColor = (color: string, variation: number) => {\n return disabled ? lightenDarkenColor(color, variation) : color;\n };\n\n const interpolateColor = animatedColor.interpolate({\n inputRange: [0, 1],\n outputRange: [\n getBackgroundColor(theme.color[inactiveColor][inactiveColorTone], 25),\n getBackgroundColor(theme.color[activeColor][activeColorTone], 50),\n ],\n });\n\n const animatedStyle = {\n backgroundColor: interpolateColor,\n };\n\n const handleChange = useCallback(() => {\n onChange(!active);\n transitionSwitch(active, transitionValue, animatedColor);\n }, [active, onChange]);\n\n const stylesDefault: ViewStyle = {\n borderRadius: extractNumbersFromString(theme.borderRadius.pill),\n paddingHorizontal: extractNumbersFromString(theme.spacing.micro),\n paddingVertical: 0,\n justifyContent: 'center',\n width: 40,\n height: 22,\n };\n\n return (\n <PressableSurface\n {...rest}\n onPress={handleChange}\n effect=\"none\"\n disabled={disabled}\n >\n <Animated.View style={{ ...animatedStyle, ...stylesDefault }}>\n <StyledSwitch\n style={[dotStyle, { transform: [{ translateX: transitionValue }] }]}\n />\n </Animated.View>\n </PressableSurface>\n );\n};\n\nexport default Switch;\n"],"file":"Switch.js"}
@@ -1 +1,2 @@
1
1
  export declare const extractNumbersFromString: (value: string) => number;
2
+ export declare const extractDigitsFromString: (value: string) => string;
@@ -3,9 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.extractNumbersFromString = void 0;
6
+ exports.extractDigitsFromString = exports.extractNumbersFromString = void 0;
7
7
 
8
8
  const extractNumbersFromString = value => Number(value.replace(/[^0-9]/g, ''));
9
9
 
10
10
  exports.extractNumbersFromString = extractNumbersFromString;
11
+
12
+ const extractDigitsFromString = value => value.replace(/[^0-9]/g, '');
13
+
14
+ exports.extractDigitsFromString = extractDigitsFromString;
11
15
  //# sourceMappingURL=extractNumbersFromString.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/extractNumbersFromString.ts"],"names":["extractNumbersFromString","value","Number","replace"],"mappings":";;;;;;;AAAO,MAAMA,wBAAwB,GAAIC,KAAD,IACtCC,MAAM,CAACD,KAAK,CAACE,OAAN,CAAc,SAAd,EAAyB,EAAzB,CAAD,CADD","sourcesContent":["export const extractNumbersFromString = (value: string): number =>\n Number(value.replace(/[^0-9]/g, ''));\n"],"file":"extractNumbersFromString.js"}
1
+ {"version":3,"sources":["../../src/utils/extractNumbersFromString.ts"],"names":["extractNumbersFromString","value","Number","replace","extractDigitsFromString"],"mappings":";;;;;;;AAAO,MAAMA,wBAAwB,GAAIC,KAAD,IACtCC,MAAM,CAACD,KAAK,CAACE,OAAN,CAAc,SAAd,EAAyB,EAAzB,CAAD,CADD;;;;AAMA,MAAMC,uBAAuB,GAAIH,KAAD,IACrCA,KAAK,CAACE,OAAN,CAAc,SAAd,EAAyB,EAAzB,CADK","sourcesContent":["export const extractNumbersFromString = (value: string): number =>\n Number(value.replace(/[^0-9]/g, ''));\n\n/*\n * implemented for the case: string numbers start with 0. Example: 012.345.678-91 Example: 012.345.678-91\n * */\nexport const extractDigitsFromString = (value: string): string =>\n value.replace(/[^0-9]/g, '');\n"],"file":"extractNumbersFromString.js"}
@@ -1,2 +1,2 @@
1
1
  export { lightenDarkenColor } from './lightenDarkenColor';
2
- export { extractNumbersFromString } from './extractNumbersFromString';
2
+ export { extractNumbersFromString, extractDigitsFromString, } from './extractNumbersFromString';
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "extractNumbersFromString", {
15
15
  return _extractNumbersFromString.extractNumbersFromString;
16
16
  }
17
17
  });
18
+ Object.defineProperty(exports, "extractDigitsFromString", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _extractNumbersFromString.extractDigitsFromString;
22
+ }
23
+ });
18
24
 
19
25
  var _lightenDarkenColor = require("./lightenDarkenColor");
20
26
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;AACA","sourcesContent":["export { lightenDarkenColor } from './lightenDarkenColor';\nexport { extractNumbersFromString } from './extractNumbersFromString';\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA","sourcesContent":["export { lightenDarkenColor } from './lightenDarkenColor';\nexport {\n extractNumbersFromString,\n extractDigitsFromString,\n} from './extractNumbersFromString';\n"],"file":"index.js"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tecsinapse/react-core",
3
3
  "description": "TecSinapse hybrid React components",
4
- "version": "1.10.2",
4
+ "version": "1.10.3",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -31,5 +31,5 @@
31
31
  "react-native": ">=0.64.0",
32
32
  "react-native-vector-icons": ">=8.1.0"
33
33
  },
34
- "gitHead": "fb3e15d84dc2e9d529dc3a00343751302c325c39"
34
+ "gitHead": "2608df0807f22cca02b657a64b3bfef334daf0e9"
35
35
  }
@@ -13,7 +13,6 @@ export const ContainerButtonAvatar = styled(PressableSurface)<
13
13
  theme.iconSize[size]};
14
14
  height: ${({ theme, size = 'mega' }: StyleProps & Partial<AvatarProps>) =>
15
15
  theme.iconSize[size]};
16
- cursor: ${({ onPress }) => (onPress ? 'pointer' : 'default')};
17
16
  `;
18
17
 
19
18
  export const StyledAvatar = styled(Image)<Partial<StyleProps>>`
@@ -1,5 +1,5 @@
1
1
  import { useCallback, useState } from 'react';
2
- import { extractNumbersFromString } from '@tecsinapse/react-core';
2
+ import { extractDigitsFromString } from '@tecsinapse/react-core';
3
3
 
4
4
  export interface IMaskValue {
5
5
  formatted?: string;
@@ -57,9 +57,7 @@ export const useMask = (
57
57
  ): [IMask, (text: string) => void] => {
58
58
  const applyMask = useCallback(
59
59
  (value = ''): IMaskValue => {
60
- const onlyNumbers = value
61
- ? String(extractNumbersFromString(value))
62
- : value;
60
+ const onlyNumbers = value ? extractDigitsFromString(value) : value;
63
61
  const selectedMask = getMask(onlyNumbers, mask);
64
62
  const formattedValue = mergeMask(onlyNumbers, selectedMask);
65
63
 
@@ -8,5 +8,5 @@ export const Masks = {
8
8
  PHONE: '(99) 9999-9999',
9
9
  PHONE_EXTENDED: '(99) 99999-9999',
10
10
  COMBINED_PHONE: (value: string) =>
11
- value.length <= 10 ? Masks.PHONE : Masks.PHONE_EXTENDED,
11
+ value?.length <= 10 ? Masks.PHONE : Masks.PHONE_EXTENDED,
12
12
  };
@@ -15,7 +15,7 @@ const Template: Story<SwitchProps> = args => {
15
15
  args.onChange(arg);
16
16
  };
17
17
 
18
- return <Switch active={active} onChange={onChange} />;
18
+ return <Switch active={active} onChange={onChange} disabled={args.disabled}/>;
19
19
  };
20
20
 
21
21
  export const Base = Template.bind({});
@@ -23,4 +23,5 @@ export const Base = Template.bind({});
23
23
  Base.args = {
24
24
  active: true,
25
25
  onChange: value => action('Cicked')(value),
26
+ disabled: false,
26
27
  };
@@ -9,7 +9,7 @@ import {
9
9
  import { PressableSurface } from '../PressableSurface';
10
10
  import { StyledSwitch } from './styled';
11
11
  import { transitionSwitch } from './animation';
12
- import { extractNumbersFromString } from '../../../utils';
12
+ import { extractNumbersFromString, lightenDarkenColor } from '../../../utils';
13
13
 
14
14
  export interface SwitchProps {
15
15
  onChange: (active: boolean) => void;
@@ -20,6 +20,7 @@ export interface SwitchProps {
20
20
  inactiveColorTone?: ColorGradationType;
21
21
  style?: StyleProp<ViewStyle>;
22
22
  dotStyle?: StyleProp<ViewStyle>;
23
+ disabled?: boolean;
23
24
  }
24
25
 
25
26
  const Switch: FC<SwitchProps> = ({
@@ -30,6 +31,7 @@ const Switch: FC<SwitchProps> = ({
30
31
  inactiveColorTone = 'light',
31
32
  active,
32
33
  dotStyle,
34
+ disabled = false,
33
35
  ...rest
34
36
  }): JSX.Element => {
35
37
  const theme = useTheme() as ThemeProp;
@@ -40,11 +42,15 @@ const Switch: FC<SwitchProps> = ({
40
42
  const animatedColor = React.useRef(new Animated.Value(active ? 1 : 0))
41
43
  .current;
42
44
 
45
+ const getBackgroundColor = (color: string, variation: number) => {
46
+ return disabled ? lightenDarkenColor(color, variation) : color;
47
+ };
48
+
43
49
  const interpolateColor = animatedColor.interpolate({
44
50
  inputRange: [0, 1],
45
51
  outputRange: [
46
- theme.color[inactiveColor][inactiveColorTone],
47
- theme.color[activeColor][activeColorTone],
52
+ getBackgroundColor(theme.color[inactiveColor][inactiveColorTone], 25),
53
+ getBackgroundColor(theme.color[activeColor][activeColorTone], 50),
48
54
  ],
49
55
  });
50
56
 
@@ -57,7 +63,7 @@ const Switch: FC<SwitchProps> = ({
57
63
  transitionSwitch(active, transitionValue, animatedColor);
58
64
  }, [active, onChange]);
59
65
 
60
- const stylesDefaut: ViewStyle = {
66
+ const stylesDefault: ViewStyle = {
61
67
  borderRadius: extractNumbersFromString(theme.borderRadius.pill),
62
68
  paddingHorizontal: extractNumbersFromString(theme.spacing.micro),
63
69
  paddingVertical: 0,
@@ -67,8 +73,13 @@ const Switch: FC<SwitchProps> = ({
67
73
  };
68
74
 
69
75
  return (
70
- <PressableSurface {...rest} onPress={handleChange} effect="none">
71
- <Animated.View style={{ ...animatedStyle, ...stylesDefaut }}>
76
+ <PressableSurface
77
+ {...rest}
78
+ onPress={handleChange}
79
+ effect="none"
80
+ disabled={disabled}
81
+ >
82
+ <Animated.View style={{ ...animatedStyle, ...stylesDefault }}>
72
83
  <StyledSwitch
73
84
  style={[dotStyle, { transform: [{ translateX: transitionValue }] }]}
74
85
  />
@@ -1,2 +1,8 @@
1
1
  export const extractNumbersFromString = (value: string): number =>
2
2
  Number(value.replace(/[^0-9]/g, ''));
3
+
4
+ /*
5
+ * implemented for the case: string numbers start with 0. Example: 012.345.678-91 Example: 012.345.678-91
6
+ * */
7
+ export const extractDigitsFromString = (value: string): string =>
8
+ value.replace(/[^0-9]/g, '');
@@ -1,2 +1,5 @@
1
1
  export { lightenDarkenColor } from './lightenDarkenColor';
2
- export { extractNumbersFromString } from './extractNumbersFromString';
2
+ export {
3
+ extractNumbersFromString,
4
+ extractDigitsFromString,
5
+ } from './extractNumbersFromString';