@ornikar/kitt-universal 9.3.0 → 9.4.0

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.
Files changed (44) hide show
  1. package/dist/definitions/Choices/ChoiceItem.d.ts +38 -0
  2. package/dist/definitions/Choices/ChoiceItem.d.ts.map +1 -0
  3. package/dist/definitions/Choices/ChoiceItemContainer.d.ts +10 -0
  4. package/dist/definitions/Choices/ChoiceItemContainer.d.ts.map +1 -0
  5. package/dist/definitions/Choices/Choices.d.ts +33 -0
  6. package/dist/definitions/Choices/Choices.d.ts.map +1 -0
  7. package/dist/definitions/forms/InputText/InputTextContainer.web.d.ts +1 -1
  8. package/dist/definitions/index.d.ts +3 -0
  9. package/dist/definitions/index.d.ts.map +1 -1
  10. package/dist/definitions/native-base/KittNativeBaseProvider.d.ts.map +1 -1
  11. package/dist/definitions/test-utils/TestWrapper.d.ts +7 -0
  12. package/dist/definitions/test-utils/TestWrapper.d.ts.map +1 -0
  13. package/dist/definitions/themes/default.d.ts +1 -0
  14. package/dist/definitions/themes/default.d.ts.map +1 -1
  15. package/dist/definitions/themes/late-ocean/choices.d.ts +35 -0
  16. package/dist/definitions/themes/late-ocean/choices.d.ts.map +1 -0
  17. package/dist/definitions/typography/Typography.d.ts +1 -0
  18. package/dist/definitions/typography/Typography.d.ts.map +1 -1
  19. package/dist/index-browser-all.es.android.js +385 -26
  20. package/dist/index-browser-all.es.android.js.map +1 -1
  21. package/dist/index-browser-all.es.ios.js +385 -26
  22. package/dist/index-browser-all.es.ios.js.map +1 -1
  23. package/dist/index-browser-all.es.js +385 -26
  24. package/dist/index-browser-all.es.js.map +1 -1
  25. package/dist/index-browser-all.es.web.js +384 -22
  26. package/dist/index-browser-all.es.web.js.map +1 -1
  27. package/dist/index-node-14.17.cjs.js +377 -8
  28. package/dist/index-node-14.17.cjs.js.map +1 -1
  29. package/dist/index-node-14.17.cjs.web.js +378 -8
  30. package/dist/index-node-14.17.cjs.web.js.map +1 -1
  31. package/dist/linaria-themes-browser-all.es.android.js +34 -0
  32. package/dist/linaria-themes-browser-all.es.android.js.map +1 -1
  33. package/dist/linaria-themes-browser-all.es.ios.js +34 -0
  34. package/dist/linaria-themes-browser-all.es.ios.js.map +1 -1
  35. package/dist/linaria-themes-browser-all.es.js +34 -0
  36. package/dist/linaria-themes-browser-all.es.js.map +1 -1
  37. package/dist/linaria-themes-browser-all.es.web.js +34 -0
  38. package/dist/linaria-themes-browser-all.es.web.js.map +1 -1
  39. package/dist/linaria-themes-node-14.17.cjs.js +34 -0
  40. package/dist/linaria-themes-node-14.17.cjs.js.map +1 -1
  41. package/dist/linaria-themes-node-14.17.cjs.web.js +34 -0
  42. package/dist/linaria-themes-node-14.17.cjs.web.js.map +1 -1
  43. package/dist/tsbuildinfo +1 -1
  44. package/package.json +4 -4
@@ -9,6 +9,7 @@ const react = require('react');
9
9
  const jsxRuntime = require('react/jsx-runtime');
10
10
  const nativeBase = require('native-base');
11
11
  const react$1 = require('@linaria/react');
12
+ const Animated = require('react-native-reanimated');
12
13
  const twemojiParser = require('twemoji-parser');
13
14
  const reactNativeSafeAreaContext = require('react-native-safe-area-context');
14
15
  const reactPortal = require('react-portal');
@@ -18,6 +19,7 @@ const addons = require('@storybook/addons');
18
19
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; }
19
20
 
20
21
  const styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
22
+ const Animated__default = /*#__PURE__*/_interopDefaultLegacy(Animated);
21
23
 
22
24
  const defaultIconSize = 20;
23
25
  const IconContainer$1 = /*#__PURE__*/styled__default(BabelPluginStyledComponentsReactNative.View).withConfig({
@@ -111,8 +113,14 @@ const TypographyColorContext = /*#__PURE__*/react.createContext('black');
111
113
  function useTypographyColor() {
112
114
  return react.useContext(TypographyColorContext);
113
115
  }
116
+ const TypographyDefaultColorContext = /*#__PURE__*/react.createContext(undefined);
117
+
118
+ function useTypographyDefaultColor() {
119
+ return react.useContext(TypographyDefaultColorContext);
120
+ }
114
121
  /** @deprecated use native-base instead for SSR compatibility */
115
122
 
123
+
116
124
  const getTypographyTypeConfigKey = theme => {
117
125
  const isMediumOrAbove = theme.responsive.matchWindowSize({
118
126
  minWidth: KittBreakpoints.MEDIUM
@@ -144,6 +152,11 @@ function createNativeBaseFontSize(type) {
144
152
  });
145
153
  return fontSizeForNativeBase;
146
154
  }
155
+
156
+ function getNBThemeColorFromColorProps(colorName) {
157
+ return colorName ? `kitt.typography.${colorName}` : undefined;
158
+ }
159
+
147
160
  function Typography({
148
161
  accessibilityRole,
149
162
  base: legacyBase,
@@ -163,6 +176,7 @@ function Typography({
163
176
  ...otherProps
164
177
  }) {
165
178
  const isHeaderTypographyInContext = react.useContext(IsHeaderTypographyContext);
179
+ const defaultColor = useTypographyDefaultColor();
166
180
  const hasTypographyAncestor = isHeaderTypographyInContext !== undefined;
167
181
  const baseOrDefaultToBody = hasTypographyAncestor ? type.base : type.base ?? 'body';
168
182
  const isHeader = isTypographyHeader(baseOrDefaultToBody, isHeaderTypographyInContext);
@@ -179,14 +193,16 @@ function Typography({
179
193
  });
180
194
  }
181
195
 
196
+ const currentColor = !color && !hasTypographyAncestor ? defaultColor : color;
197
+
182
198
  const text = /*#__PURE__*/jsxRuntime.jsx(nativeBase.Text, {
183
199
  accessibilityRole: accessibilityRole || undefined,
184
200
  fontSize: fontSizeForNativeBase,
185
- lineHeight: fontSizeForNativeBase,
201
+ lineHeight: hasTypographyAncestor ? undefined : fontSizeForNativeBase,
186
202
  fontWeight: isHeader ? `headers.${nonNullableVariant}` : `bodies.${nonNullableVariant}`,
187
203
  fontFamily: isHeader ? `headers.${nonNullableVariant}` : `bodies.${nonNullableVariant}`,
188
- color: color ? `kitt.typography.${color}` : undefined,
189
- textDecorationColor: color ? `kitt.typography.${color}` : undefined,
204
+ color: getNBThemeColorFromColorProps(currentColor),
205
+ textDecorationColor: getNBThemeColorFromColorProps(currentColor),
190
206
  ...otherProps
191
207
  });
192
208
 
@@ -230,6 +246,7 @@ const createHeading = (level, defaultBase) => {
230
246
  return TypographyHeading;
231
247
  };
232
248
 
249
+ Typography.SetDefaultColor = TypographyDefaultColorContext.Provider;
233
250
  Typography.Text = TypographyText;
234
251
  Typography.Paragraph = TypographyParagraph;
235
252
  Typography.Header1 = createHeading(1);
@@ -845,6 +862,320 @@ function Card({
845
862
  });
846
863
  }
847
864
 
865
+ function getCurrentTextColor({
866
+ isDisabled,
867
+ isSelected,
868
+ isPressed,
869
+ isHovered
870
+ }) {
871
+ if (isDisabled) return 'black-light';
872
+ if (isSelected && isHovered) return 'white';
873
+ if (isSelected || isPressed) return 'white';
874
+ return 'black';
875
+ }
876
+
877
+ function getBorderRadius(defaultRadius, variant) {
878
+ // The clean way to have the rounded effect would have been to know the children height since radius >= height * 0.5
879
+ // We don't control over the height of the rendered children we just go with a arbitrary really high value
880
+ if (variant === 'rounded') return 800;
881
+ return defaultRadius;
882
+ }
883
+
884
+ const DisabledBorder = /*#__PURE__*/styled__default(BabelPluginStyledComponentsReactNative.View).withConfig({
885
+ displayName: "ChoiceItem__DisabledBorder",
886
+ componentId: "kitt-universal__sc-wuv3y6-0"
887
+ })(["border-radius:", "px;", ";"], ({
888
+ theme,
889
+ $variant
890
+ }) => getBorderRadius(theme.kitt.choices.item.borderRadius, $variant), ({
891
+ theme
892
+ }) => {
893
+ const {
894
+ width,
895
+ color
896
+ } = theme.kitt.choices.item.disabled.border;
897
+ return styled.css(["border:", "px solid ", ";"], width, color);
898
+ });
899
+ const ChoiceItemView = /*#__PURE__*/styled__default(Animated__default.View).withConfig({
900
+ displayName: "ChoiceItem__ChoiceItemView",
901
+ componentId: "kitt-universal__sc-wuv3y6-1"
902
+ })(["position:relative;border-radius:", "px;background-color:", ";", ";", ""], ({
903
+ theme,
904
+ $variant
905
+ }) => getBorderRadius(theme.kitt.choices.item.borderRadius, $variant), ({
906
+ theme,
907
+ $isHovered,
908
+ $isPressed,
909
+ $isDisabled,
910
+ $isSelected
911
+ }) => {
912
+ const {
913
+ hoverWhenSelected,
914
+ hover,
915
+ disabled,
916
+ selected,
917
+ pressed,
918
+ default: defaultBackground
919
+ } = theme.kitt.choices.item.backgroundColor;
920
+ if ($isDisabled) return disabled;
921
+ if ($isSelected && $isHovered) return hoverWhenSelected;
922
+ if ($isPressed) return pressed;
923
+ if ($isHovered) return hover;
924
+ if ($isSelected) return selected;
925
+ return defaultBackground;
926
+ }, ({
927
+ theme
928
+ }) => {
929
+ const {
930
+ base,
931
+ small
932
+ } = theme.kitt.choices.item.padding;
933
+ return theme.responsive.ifWindowSizeMatches({
934
+ minWidth: KittBreakpoints.SMALL
935
+ }, styled.css(["padding:", "px;"], small), styled.css(["padding:", "px;"], base));
936
+ }, ({
937
+ theme
938
+ }) => {
939
+ const {
940
+ property,
941
+ duration,
942
+ timingFunction
943
+ } = theme.kitt.choices.item.transition;
944
+ return styled.css(["transition:", " ", "ms ", ";"], property, duration, timingFunction);
945
+ });
946
+ function ChoiceItem({
947
+ type = 'button',
948
+ value,
949
+ selected,
950
+ disabled,
951
+ variant,
952
+ children,
953
+ isPressedInternal,
954
+ isHoveredInternal,
955
+ onPress,
956
+ onChange,
957
+ onBlur,
958
+ onFocus
959
+ }) {
960
+ const theme = /*#__PURE__*/styled.useTheme();
961
+ const pressed = Animated.useSharedValue(Boolean(isPressedInternal));
962
+ const progress = Animated.useDerivedValue(function () {
963
+ const _f = function () {
964
+ return Animated.withTiming(pressed.value ? 1 : 0, {
965
+ duration: theme.kitt.choices.item.transition.duration
966
+ });
967
+ };
968
+
969
+ _f._closure = {
970
+ withTiming: Animated.withTiming,
971
+ pressed,
972
+ theme: {
973
+ kitt: {
974
+ choices: {
975
+ item: {
976
+ transition: {
977
+ duration: theme.kitt.choices.item.transition.duration
978
+ }
979
+ }
980
+ }
981
+ }
982
+ }
983
+ };
984
+ _f.asString = "function _f(){const{withTiming,pressed,theme}=jsThis._closure;{return withTiming(pressed.value?1:0,{duration:theme.kitt.choices.item.transition.duration});}}";
985
+ _f.__workletHash = 1120030177160;
986
+ _f.__location = "/home/circleci/repo/@ornikar/kitt-universal/src/Choices/ChoiceItem.tsx (180:35)";
987
+ return _f;
988
+ }());
989
+ Animated.useAnimatedStyle(function () {
990
+ const _f = function () {
991
+ const {
992
+ default: defaultBg,
993
+ pressed: pressedBg,
994
+ selected: selectedBg,
995
+ disabled: disabledBg
996
+ } = theme.kitt.choices.item.backgroundColor;
997
+ if (disabled) return {
998
+ backgroundColor: disabledBg
999
+ };
1000
+ if (selected) return {
1001
+ backgroundColor: selectedBg
1002
+ };
1003
+ return {
1004
+ backgroundColor: Animated.interpolateColor(progress.value, [0, 1], [defaultBg, pressedBg])
1005
+ };
1006
+ };
1007
+
1008
+ _f._closure = {
1009
+ theme: {
1010
+ kitt: {
1011
+ choices: {
1012
+ item: {
1013
+ backgroundColor: theme.kitt.choices.item.backgroundColor
1014
+ }
1015
+ }
1016
+ }
1017
+ },
1018
+ disabled,
1019
+ selected,
1020
+ interpolateColor: Animated.interpolateColor,
1021
+ progress
1022
+ };
1023
+ _f.asString = "function _f(){const{theme,disabled,selected,interpolateColor,progress}=jsThis._closure;{const{default:defaultBg,pressed:pressedBg,selected:selectedBg,disabled:disabledBg}=theme.kitt.choices.item.backgroundColor;if(disabled)return{backgroundColor:disabledBg};if(selected)return{backgroundColor:selectedBg};return{backgroundColor:interpolateColor(progress.value,[0,1],[defaultBg,pressedBg])};}}";
1024
+ _f.__workletHash = 15506726129309;
1025
+ _f.__location = "/home/circleci/repo/@ornikar/kitt-universal/src/Choices/ChoiceItem.tsx (184:44)";
1026
+ return _f;
1027
+ }());
1028
+
1029
+ const handleChange = () => {
1030
+ if (!onChange) return; // Checkbox can be toggled
1031
+
1032
+ if (type === 'checkbox') {
1033
+ onChange(selected ? undefined : value);
1034
+ return;
1035
+ }
1036
+
1037
+ onChange(value);
1038
+ };
1039
+
1040
+ return /*#__PURE__*/jsxRuntime.jsx(nativeBase.Pressable, {
1041
+ disabled: disabled,
1042
+ accessibilityRole: type,
1043
+ accessibilityState: {
1044
+ checked: selected
1045
+ },
1046
+ onBlur: onBlur,
1047
+ onFocus: onFocus,
1048
+ onPress: e => {
1049
+ if (onFocus) onFocus(e);
1050
+ if (onPress) onPress();
1051
+ handleChange();
1052
+ if (onBlur) onBlur(e);
1053
+ },
1054
+ onPressIn: () => {
1055
+ pressed.value = true;
1056
+ },
1057
+ onPressOut: () => {
1058
+ pressed.value = false;
1059
+ },
1060
+ children: ({
1061
+ isHovered,
1062
+ isPressed
1063
+ }) => /*#__PURE__*/jsxRuntime.jsxs(ChoiceItemView, {
1064
+ style: undefined,
1065
+ $isHovered: isHovered || isHoveredInternal,
1066
+ $isDisabled: disabled,
1067
+ $isSelected: selected,
1068
+ $isPressed: isPressed || isPressedInternal,
1069
+ $variant: variant,
1070
+ children: [/*#__PURE__*/jsxRuntime.jsx(Typography.SetDefaultColor, {
1071
+ value: getCurrentTextColor({
1072
+ isDisabled: disabled,
1073
+ isSelected: selected || isPressedInternal,
1074
+ isPressed,
1075
+ isHovered: isHovered || isHoveredInternal
1076
+ }),
1077
+ children: children
1078
+ }), disabled ? /*#__PURE__*/jsxRuntime.jsx(DisabledBorder, {
1079
+ $variant: variant,
1080
+ style: BabelPluginStyledComponentsReactNative.StyleSheet.absoluteFillObject
1081
+ }) : null]
1082
+ })
1083
+ });
1084
+ }
1085
+
1086
+ const ChoiceItemContainer = /*#__PURE__*/styled__default(BabelPluginStyledComponentsReactNative.View).withConfig({
1087
+ displayName: "ChoiceItemContainer",
1088
+ componentId: "kitt-universal__sc-17uuimx-0"
1089
+ })(["", ""], ({
1090
+ theme,
1091
+ $isLast,
1092
+ $direction
1093
+ }) => {
1094
+ const {
1095
+ row,
1096
+ column
1097
+ } = theme.kitt.choices.spacing;
1098
+
1099
+ if ($direction === 'row') {
1100
+ return styled.css(["margin-right:", "px;"], $isLast ? 0 : row);
1101
+ }
1102
+
1103
+ return styled.css(["margin-bottom:", "px;"], $isLast ? 0 : column);
1104
+ });
1105
+
1106
+ function ChoicesContainer({
1107
+ direction,
1108
+ ...props
1109
+ }) {
1110
+ if (direction === 'row') {
1111
+ return /*#__PURE__*/jsxRuntime.jsx(BabelPluginStyledComponentsReactNative.ScrollView, {
1112
+ horizontal: true,
1113
+ ...props
1114
+ });
1115
+ }
1116
+
1117
+ return /*#__PURE__*/jsxRuntime.jsx(BabelPluginStyledComponentsReactNative.View, { ...props
1118
+ });
1119
+ }
1120
+
1121
+ function Choices({
1122
+ id,
1123
+ testID,
1124
+ type,
1125
+ direction = 'column',
1126
+ disabled,
1127
+ children,
1128
+ value,
1129
+ variant,
1130
+ onPress,
1131
+ onChange,
1132
+ onFocus,
1133
+ onBlur
1134
+ }) {
1135
+ const [currentValue, setCurrentValue] = react.useState(value);
1136
+ const isForm = type && ['radio', 'checkbox'].includes(type);
1137
+ const childrenArray = react.Children.toArray(children);
1138
+ const sharedProps = {
1139
+ type,
1140
+ disabled,
1141
+ variant,
1142
+ onPress: !isForm ? onPress : undefined,
1143
+ onChange: isForm ? newValue => {
1144
+ setCurrentValue(newValue);
1145
+ if (onChange) onChange(newValue);
1146
+ } : undefined,
1147
+ onFocus,
1148
+ onBlur
1149
+ };
1150
+ return /*#__PURE__*/jsxRuntime.jsx(ChoicesContainer, {
1151
+ direction: direction,
1152
+ testID: testID,
1153
+ nativeID: id,
1154
+ children: childrenArray.map((child, index) => {
1155
+ const element = /*#__PURE__*/react.cloneElement(child, {
1156
+ selected: isForm ? child.props.value === currentValue : undefined,
1157
+ ...sharedProps
1158
+ });
1159
+ return /*#__PURE__*/jsxRuntime.jsx(ChoiceItemContainer, {
1160
+ $direction: direction,
1161
+ $isLast: index === childrenArray.length - 1,
1162
+ children: element
1163
+ }, child.key);
1164
+ })
1165
+ });
1166
+ }
1167
+
1168
+ Choices.Item = ChoiceItem;
1169
+ function createChoicesComponent() {
1170
+ return Choices;
1171
+ }
1172
+ const ButtonChoices = createChoicesComponent();
1173
+ Choices.ButtonChoices = ButtonChoices;
1174
+ const ChoicesElements = {
1175
+ Item: ChoiceItem,
1176
+ ButtonChoices
1177
+ };
1178
+
848
1179
  function Emoji({
849
1180
  emoji,
850
1181
  size,
@@ -1148,6 +1479,39 @@ const card = {
1148
1479
  }
1149
1480
  };
1150
1481
 
1482
+ const choices = {
1483
+ spacing: {
1484
+ row: 12,
1485
+ column: 12
1486
+ },
1487
+ item: {
1488
+ borderRadius: 10,
1489
+ padding: {
1490
+ base: 16,
1491
+ small: 24
1492
+ },
1493
+ backgroundColor: {
1494
+ default: lateOceanColorPalette.black50,
1495
+ disabled: colors.disabled,
1496
+ selected: colors.primary,
1497
+ pressed: lateOceanColorPalette.lateOceanLight1,
1498
+ hover: lateOceanColorPalette.black100,
1499
+ hoverWhenSelected: lateOceanColorPalette.lateOceanLight1
1500
+ },
1501
+ disabled: {
1502
+ border: {
1503
+ width: 2,
1504
+ color: lateOceanColorPalette.black100
1505
+ }
1506
+ },
1507
+ transition: {
1508
+ property: 'all',
1509
+ duration: 300,
1510
+ timingFunction: 'cubic-bezier(0.645, 0.045, 0.355, 1)'
1511
+ }
1512
+ }
1513
+ };
1514
+
1151
1515
  const feedbackMessage = {
1152
1516
  danger: {
1153
1517
  backgroundColor: colors.danger
@@ -1561,6 +1925,7 @@ const theme = {
1561
1925
  breakpoints,
1562
1926
  button,
1563
1927
  card,
1928
+ choices,
1564
1929
  feedbackMessage,
1565
1930
  forms,
1566
1931
  fullScreenModal,
@@ -3124,9 +3489,12 @@ const createKittSpaces = spacing => {
3124
3489
  }
3125
3490
 
3126
3491
  return sizes;
3127
- }; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type -- let typescript infer types
3492
+ }; // reset native-base to be able to set size / space as a number
3493
+ // https://docs.nativebase.io/next/default-theme#h2-size
3128
3494
 
3129
3495
 
3496
+ const overridenNativeBaseSizeandSpaceScale = Object.fromEntries([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 16, 20, 24, 32, 40, 48, 56, 64, 72, 80, 96, 0.5, 1.5, 2.5, 3.5].map(value => [value, value])); // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type -- let typescript infer types
3497
+
3130
3498
  const createKittNativeBaseCustomTheme = theme => {
3131
3499
  const spaces = createKittSpaces(theme.spacing);
3132
3500
  const extendedTheme = nativeBase.extendTheme({
@@ -3139,11 +3507,11 @@ const createKittNativeBaseCustomTheme = theme => {
3139
3507
  'kitt.borderRadius': theme.card.borderRadius
3140
3508
  },
3141
3509
  sizes: { ...spaces,
3142
- // reset native-base to be able to set size as number
3143
- // https://docs.nativebase.io/next/default-theme#h2-size
3144
- ...Object.fromEntries([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 16, 20, 24, 32, 40, 48, 56, 64, 78, 80, 96, 0.5, 1.5, 2.5, 3.5].map(value => [value, value]))
3510
+ ...overridenNativeBaseSizeandSpaceScale
3511
+ },
3512
+ space: { ...spaces,
3513
+ ...overridenNativeBaseSizeandSpaceScale
3145
3514
  },
3146
- space: spaces,
3147
3515
  breakpoints: {
3148
3516
  // kitt breakpoints
3149
3517
  base: KittBreakpoints.BASE,
@@ -4462,6 +4830,7 @@ exports.Avatar = Avatar;
4462
4830
  exports.Button = Button;
4463
4831
  exports.Card = Card;
4464
4832
  exports.Checkbox = Checkbox;
4833
+ exports.ChoicesElements = ChoicesElements;
4465
4834
  exports.DatePicker = DatePicker;
4466
4835
  exports.Emoji = Emoji;
4467
4836
  exports.ExternalAppLink = ExternalAppLink;
@@ -4522,6 +4891,7 @@ exports.TypographyIcon = TypographyIcon;
4522
4891
  exports.TypographyLink = TypographyLink;
4523
4892
  exports.VStack = VStack;
4524
4893
  exports.View = View;
4894
+ exports.createChoicesComponent = createChoicesComponent;
4525
4895
  exports.createWindowSizeHelper = createWindowSizeHelper;
4526
4896
  exports.hex2rgba = hex2rgba;
4527
4897
  exports.matchWindowSize = matchWindowSize;