@ornikar/kitt-universal 9.3.2 → 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 (43) 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/test-utils/TestWrapper.d.ts +7 -0
  11. package/dist/definitions/test-utils/TestWrapper.d.ts.map +1 -0
  12. package/dist/definitions/themes/default.d.ts +1 -0
  13. package/dist/definitions/themes/default.d.ts.map +1 -1
  14. package/dist/definitions/themes/late-ocean/choices.d.ts +35 -0
  15. package/dist/definitions/themes/late-ocean/choices.d.ts.map +1 -0
  16. package/dist/definitions/typography/Typography.d.ts +1 -0
  17. package/dist/definitions/typography/Typography.d.ts.map +1 -1
  18. package/dist/index-browser-all.es.android.js +376 -20
  19. package/dist/index-browser-all.es.android.js.map +1 -1
  20. package/dist/index-browser-all.es.ios.js +376 -20
  21. package/dist/index-browser-all.es.ios.js.map +1 -1
  22. package/dist/index-browser-all.es.js +376 -20
  23. package/dist/index-browser-all.es.js.map +1 -1
  24. package/dist/index-browser-all.es.web.js +375 -16
  25. package/dist/index-browser-all.es.web.js.map +1 -1
  26. package/dist/index-node-14.17.cjs.js +368 -2
  27. package/dist/index-node-14.17.cjs.js.map +1 -1
  28. package/dist/index-node-14.17.cjs.web.js +369 -2
  29. package/dist/index-node-14.17.cjs.web.js.map +1 -1
  30. package/dist/linaria-themes-browser-all.es.android.js +34 -0
  31. package/dist/linaria-themes-browser-all.es.android.js.map +1 -1
  32. package/dist/linaria-themes-browser-all.es.ios.js +34 -0
  33. package/dist/linaria-themes-browser-all.es.ios.js.map +1 -1
  34. package/dist/linaria-themes-browser-all.es.js +34 -0
  35. package/dist/linaria-themes-browser-all.es.js.map +1 -1
  36. package/dist/linaria-themes-browser-all.es.web.js +34 -0
  37. package/dist/linaria-themes-browser-all.es.web.js.map +1 -1
  38. package/dist/linaria-themes-node-14.17.cjs.js +34 -0
  39. package/dist/linaria-themes-node-14.17.cjs.js.map +1 -1
  40. package/dist/linaria-themes-node-14.17.cjs.web.js +34 -0
  41. package/dist/linaria-themes-node-14.17.cjs.web.js.map +1 -1
  42. package/dist/tsbuildinfo +1 -1
  43. package/package.json +2 -2
@@ -121,8 +121,14 @@ const TypographyColorContext = /*#__PURE__*/React.createContext('black');
121
121
  function useTypographyColor() {
122
122
  return React.useContext(TypographyColorContext);
123
123
  }
124
+ const TypographyDefaultColorContext = /*#__PURE__*/React.createContext(undefined);
125
+
126
+ function useTypographyDefaultColor() {
127
+ return React.useContext(TypographyDefaultColorContext);
128
+ }
124
129
  /** @deprecated use native-base instead for SSR compatibility */
125
130
 
131
+
126
132
  const getTypographyTypeConfigKey = theme => {
127
133
  const isMediumOrAbove = theme.responsive.matchWindowSize({
128
134
  minWidth: KittBreakpoints.MEDIUM
@@ -154,6 +160,11 @@ function createNativeBaseFontSize(type) {
154
160
  });
155
161
  return fontSizeForNativeBase;
156
162
  }
163
+
164
+ function getNBThemeColorFromColorProps(colorName) {
165
+ return colorName ? `kitt.typography.${colorName}` : undefined;
166
+ }
167
+
157
168
  function Typography({
158
169
  accessibilityRole,
159
170
  base: legacyBase,
@@ -173,6 +184,7 @@ function Typography({
173
184
  ...otherProps
174
185
  }) {
175
186
  const isHeaderTypographyInContext = React.useContext(IsHeaderTypographyContext);
187
+ const defaultColor = useTypographyDefaultColor();
176
188
  const hasTypographyAncestor = isHeaderTypographyInContext !== undefined;
177
189
  const baseOrDefaultToBody = hasTypographyAncestor ? type.base : type.base ?? 'body';
178
190
  const isHeader = isTypographyHeader(baseOrDefaultToBody, isHeaderTypographyInContext);
@@ -189,14 +201,16 @@ function Typography({
189
201
  });
190
202
  }
191
203
 
204
+ const currentColor = !color && !hasTypographyAncestor ? defaultColor : color;
205
+
192
206
  const text = /*#__PURE__*/jsxRuntime.jsx(nativeBase.Text, {
193
207
  accessibilityRole: accessibilityRole || undefined,
194
208
  fontSize: fontSizeForNativeBase,
195
209
  lineHeight: hasTypographyAncestor ? undefined : fontSizeForNativeBase,
196
210
  fontWeight: isHeader ? `headers.${nonNullableVariant}` : `bodies.${nonNullableVariant}`,
197
211
  fontFamily: isHeader ? `headers.${nonNullableVariant}` : `bodies.${nonNullableVariant}`,
198
- color: color ? `kitt.typography.${color}` : undefined,
199
- textDecorationColor: color ? `kitt.typography.${color}` : undefined,
212
+ color: getNBThemeColorFromColorProps(currentColor),
213
+ textDecorationColor: getNBThemeColorFromColorProps(currentColor),
200
214
  ...otherProps
201
215
  });
202
216
 
@@ -240,6 +254,7 @@ const createHeading = (level, defaultBase) => {
240
254
  return TypographyHeading;
241
255
  };
242
256
 
257
+ Typography.SetDefaultColor = TypographyDefaultColorContext.Provider;
243
258
  Typography.Text = TypographyText;
244
259
  Typography.Paragraph = TypographyParagraph;
245
260
  Typography.Header1 = createHeading(1);
@@ -833,6 +848,321 @@ function Card({
833
848
  });
834
849
  }
835
850
 
851
+ function getCurrentTextColor({
852
+ isDisabled,
853
+ isSelected,
854
+ isPressed,
855
+ isHovered
856
+ }) {
857
+ if (isDisabled) return 'black-light';
858
+ if (isSelected && isHovered) return 'white';
859
+ if (isSelected || isPressed) return 'white';
860
+ return 'black';
861
+ }
862
+
863
+ function getBorderRadius(defaultRadius, variant) {
864
+ // The clean way to have the rounded effect would have been to know the children height since radius >= height * 0.5
865
+ // We don't control over the height of the rendered children we just go with a arbitrary really high value
866
+ if (variant === 'rounded') return 800;
867
+ return defaultRadius;
868
+ }
869
+
870
+ const DisabledBorder = /*#__PURE__*/styled__default(reactNative.View).withConfig({
871
+ displayName: "ChoiceItem__DisabledBorder",
872
+ componentId: "kitt-universal__sc-wuv3y6-0"
873
+ })(["border-radius:", "px;", ";"], ({
874
+ theme,
875
+ $variant
876
+ }) => getBorderRadius(theme.kitt.choices.item.borderRadius, $variant), ({
877
+ theme
878
+ }) => {
879
+ const {
880
+ width,
881
+ color
882
+ } = theme.kitt.choices.item.disabled.border;
883
+ return styled.css(["border:", "px solid ", ";"], width, color);
884
+ });
885
+ const ChoiceItemView = /*#__PURE__*/styled__default(Animated__default.View).withConfig({
886
+ displayName: "ChoiceItem__ChoiceItemView",
887
+ componentId: "kitt-universal__sc-wuv3y6-1"
888
+ })(["position:relative;border-radius:", "px;background-color:", ";", ";", ""], ({
889
+ theme,
890
+ $variant
891
+ }) => getBorderRadius(theme.kitt.choices.item.borderRadius, $variant), ({
892
+ theme,
893
+ $isHovered,
894
+ $isPressed,
895
+ $isDisabled,
896
+ $isSelected
897
+ }) => {
898
+ const {
899
+ hoverWhenSelected,
900
+ hover,
901
+ disabled,
902
+ selected,
903
+ pressed,
904
+ default: defaultBackground
905
+ } = theme.kitt.choices.item.backgroundColor;
906
+ if ($isDisabled) return disabled;
907
+ if ($isSelected && $isHovered) return hoverWhenSelected;
908
+ if ($isPressed) return pressed;
909
+ if ($isHovered) return hover;
910
+ if ($isSelected) return selected;
911
+ return defaultBackground;
912
+ }, ({
913
+ theme
914
+ }) => {
915
+ const {
916
+ base,
917
+ small
918
+ } = theme.kitt.choices.item.padding;
919
+ return theme.responsive.ifWindowSizeMatches({
920
+ minWidth: KittBreakpoints.SMALL
921
+ }, styled.css(["padding:", "px;"], small), styled.css(["padding:", "px;"], base));
922
+ }, ({
923
+ theme
924
+ }) => {
925
+ if (reactNative.Platform.OS !== 'web') return undefined;
926
+ const {
927
+ property,
928
+ duration,
929
+ timingFunction
930
+ } = theme.kitt.choices.item.transition;
931
+ return styled.css(["transition:", " ", "ms ", ";"], property, duration, timingFunction);
932
+ });
933
+ function ChoiceItem({
934
+ type = 'button',
935
+ value,
936
+ selected,
937
+ disabled,
938
+ variant,
939
+ children,
940
+ isPressedInternal,
941
+ isHoveredInternal,
942
+ onPress,
943
+ onChange,
944
+ onBlur,
945
+ onFocus
946
+ }) {
947
+ const theme = /*#__PURE__*/styled.useTheme();
948
+ const pressed = Animated.useSharedValue(Boolean(isPressedInternal));
949
+ const progress = Animated.useDerivedValue(function () {
950
+ const _f = function () {
951
+ return Animated.withTiming(pressed.value ? 1 : 0, {
952
+ duration: theme.kitt.choices.item.transition.duration
953
+ });
954
+ };
955
+
956
+ _f._closure = {
957
+ withTiming: Animated.withTiming,
958
+ pressed,
959
+ theme: {
960
+ kitt: {
961
+ choices: {
962
+ item: {
963
+ transition: {
964
+ duration: theme.kitt.choices.item.transition.duration
965
+ }
966
+ }
967
+ }
968
+ }
969
+ }
970
+ };
971
+ _f.asString = "function _f(){const{withTiming,pressed,theme}=jsThis._closure;{return withTiming(pressed.value?1:0,{duration:theme.kitt.choices.item.transition.duration});}}";
972
+ _f.__workletHash = 1120030177160;
973
+ _f.__location = "/home/circleci/repo/@ornikar/kitt-universal/src/Choices/ChoiceItem.tsx (180:35)";
974
+ return _f;
975
+ }());
976
+ const backgroundStyles = Animated.useAnimatedStyle(function () {
977
+ const _f = function () {
978
+ const {
979
+ default: defaultBg,
980
+ pressed: pressedBg,
981
+ selected: selectedBg,
982
+ disabled: disabledBg
983
+ } = theme.kitt.choices.item.backgroundColor;
984
+ if (disabled) return {
985
+ backgroundColor: disabledBg
986
+ };
987
+ if (selected) return {
988
+ backgroundColor: selectedBg
989
+ };
990
+ return {
991
+ backgroundColor: Animated.interpolateColor(progress.value, [0, 1], [defaultBg, pressedBg])
992
+ };
993
+ };
994
+
995
+ _f._closure = {
996
+ theme: {
997
+ kitt: {
998
+ choices: {
999
+ item: {
1000
+ backgroundColor: theme.kitt.choices.item.backgroundColor
1001
+ }
1002
+ }
1003
+ }
1004
+ },
1005
+ disabled,
1006
+ selected,
1007
+ interpolateColor: Animated.interpolateColor,
1008
+ progress
1009
+ };
1010
+ _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])};}}";
1011
+ _f.__workletHash = 15506726129309;
1012
+ _f.__location = "/home/circleci/repo/@ornikar/kitt-universal/src/Choices/ChoiceItem.tsx (184:44)";
1013
+ return _f;
1014
+ }());
1015
+
1016
+ const handleChange = () => {
1017
+ if (!onChange) return; // Checkbox can be toggled
1018
+
1019
+ if (type === 'checkbox') {
1020
+ onChange(selected ? undefined : value);
1021
+ return;
1022
+ }
1023
+
1024
+ onChange(value);
1025
+ };
1026
+
1027
+ return /*#__PURE__*/jsxRuntime.jsx(nativeBase.Pressable, {
1028
+ disabled: disabled,
1029
+ accessibilityRole: type,
1030
+ accessibilityState: {
1031
+ checked: selected
1032
+ },
1033
+ onBlur: onBlur,
1034
+ onFocus: onFocus,
1035
+ onPress: e => {
1036
+ if (onFocus) onFocus(e);
1037
+ if (onPress) onPress();
1038
+ handleChange();
1039
+ if (onBlur) onBlur(e);
1040
+ },
1041
+ onPressIn: () => {
1042
+ pressed.value = true;
1043
+ },
1044
+ onPressOut: () => {
1045
+ pressed.value = false;
1046
+ },
1047
+ children: ({
1048
+ isHovered,
1049
+ isPressed
1050
+ }) => /*#__PURE__*/jsxRuntime.jsxs(ChoiceItemView, {
1051
+ style: reactNative.Platform.OS !== 'web' ? [backgroundStyles] : undefined,
1052
+ $isHovered: isHovered || isHoveredInternal,
1053
+ $isDisabled: disabled,
1054
+ $isSelected: selected,
1055
+ $isPressed: isPressed || isPressedInternal,
1056
+ $variant: variant,
1057
+ children: [/*#__PURE__*/jsxRuntime.jsx(Typography.SetDefaultColor, {
1058
+ value: getCurrentTextColor({
1059
+ isDisabled: disabled,
1060
+ isSelected: selected || isPressedInternal,
1061
+ isPressed,
1062
+ isHovered: isHovered || isHoveredInternal
1063
+ }),
1064
+ children: children
1065
+ }), disabled ? /*#__PURE__*/jsxRuntime.jsx(DisabledBorder, {
1066
+ $variant: variant,
1067
+ style: reactNative.StyleSheet.absoluteFillObject
1068
+ }) : null]
1069
+ })
1070
+ });
1071
+ }
1072
+
1073
+ const ChoiceItemContainer = /*#__PURE__*/styled__default(reactNative.View).withConfig({
1074
+ displayName: "ChoiceItemContainer",
1075
+ componentId: "kitt-universal__sc-17uuimx-0"
1076
+ })(["", ""], ({
1077
+ theme,
1078
+ $isLast,
1079
+ $direction
1080
+ }) => {
1081
+ const {
1082
+ row,
1083
+ column
1084
+ } = theme.kitt.choices.spacing;
1085
+
1086
+ if ($direction === 'row') {
1087
+ return styled.css(["margin-right:", "px;"], $isLast ? 0 : row);
1088
+ }
1089
+
1090
+ return styled.css(["margin-bottom:", "px;"], $isLast ? 0 : column);
1091
+ });
1092
+
1093
+ function ChoicesContainer({
1094
+ direction,
1095
+ ...props
1096
+ }) {
1097
+ if (direction === 'row') {
1098
+ return /*#__PURE__*/jsxRuntime.jsx(reactNative.ScrollView, {
1099
+ horizontal: true,
1100
+ ...props
1101
+ });
1102
+ }
1103
+
1104
+ return /*#__PURE__*/jsxRuntime.jsx(reactNative.View, { ...props
1105
+ });
1106
+ }
1107
+
1108
+ function Choices({
1109
+ id,
1110
+ testID,
1111
+ type,
1112
+ direction = 'column',
1113
+ disabled,
1114
+ children,
1115
+ value,
1116
+ variant,
1117
+ onPress,
1118
+ onChange,
1119
+ onFocus,
1120
+ onBlur
1121
+ }) {
1122
+ const [currentValue, setCurrentValue] = React.useState(value);
1123
+ const isForm = type && ['radio', 'checkbox'].includes(type);
1124
+ const childrenArray = React.Children.toArray(children);
1125
+ const sharedProps = {
1126
+ type,
1127
+ disabled,
1128
+ variant,
1129
+ onPress: !isForm ? onPress : undefined,
1130
+ onChange: isForm ? newValue => {
1131
+ setCurrentValue(newValue);
1132
+ if (onChange) onChange(newValue);
1133
+ } : undefined,
1134
+ onFocus,
1135
+ onBlur
1136
+ };
1137
+ return /*#__PURE__*/jsxRuntime.jsx(ChoicesContainer, {
1138
+ direction: direction,
1139
+ testID: testID,
1140
+ nativeID: id,
1141
+ children: childrenArray.map((child, index) => {
1142
+ const element = /*#__PURE__*/React.cloneElement(child, {
1143
+ selected: isForm ? child.props.value === currentValue : undefined,
1144
+ ...sharedProps
1145
+ });
1146
+ return /*#__PURE__*/jsxRuntime.jsx(ChoiceItemContainer, {
1147
+ $direction: direction,
1148
+ $isLast: index === childrenArray.length - 1,
1149
+ children: element
1150
+ }, child.key);
1151
+ })
1152
+ });
1153
+ }
1154
+
1155
+ Choices.Item = ChoiceItem;
1156
+ function createChoicesComponent() {
1157
+ return Choices;
1158
+ }
1159
+ const ButtonChoices = createChoicesComponent();
1160
+ Choices.ButtonChoices = ButtonChoices;
1161
+ const ChoicesElements = {
1162
+ Item: ChoiceItem,
1163
+ ButtonChoices
1164
+ };
1165
+
836
1166
  function Emoji({
837
1167
  emoji,
838
1168
  size,
@@ -1159,6 +1489,39 @@ const card = {
1159
1489
  }
1160
1490
  };
1161
1491
 
1492
+ const choices = {
1493
+ spacing: {
1494
+ row: 12,
1495
+ column: 12
1496
+ },
1497
+ item: {
1498
+ borderRadius: 10,
1499
+ padding: {
1500
+ base: 16,
1501
+ small: 24
1502
+ },
1503
+ backgroundColor: {
1504
+ default: lateOceanColorPalette.black50,
1505
+ disabled: colors.disabled,
1506
+ selected: colors.primary,
1507
+ pressed: lateOceanColorPalette.lateOceanLight1,
1508
+ hover: lateOceanColorPalette.black100,
1509
+ hoverWhenSelected: lateOceanColorPalette.lateOceanLight1
1510
+ },
1511
+ disabled: {
1512
+ border: {
1513
+ width: 2,
1514
+ color: lateOceanColorPalette.black100
1515
+ }
1516
+ },
1517
+ transition: {
1518
+ property: 'all',
1519
+ duration: 300,
1520
+ timingFunction: 'cubic-bezier(0.645, 0.045, 0.355, 1)'
1521
+ }
1522
+ }
1523
+ };
1524
+
1162
1525
  const feedbackMessage = {
1163
1526
  danger: {
1164
1527
  backgroundColor: colors.danger
@@ -1572,6 +1935,7 @@ const theme = {
1572
1935
  breakpoints,
1573
1936
  button,
1574
1937
  card,
1938
+ choices,
1575
1939
  feedbackMessage,
1576
1940
  forms,
1577
1941
  fullScreenModal,
@@ -5103,6 +5467,7 @@ exports.Avatar = Avatar;
5103
5467
  exports.Button = Button;
5104
5468
  exports.Card = Card;
5105
5469
  exports.Checkbox = Checkbox;
5470
+ exports.ChoicesElements = ChoicesElements;
5106
5471
  exports.DatePicker = DatePicker;
5107
5472
  exports.Emoji = Emoji;
5108
5473
  exports.ExternalAppLink = ExternalAppLink;
@@ -5163,6 +5528,7 @@ exports.TypographyIcon = TypographyIcon;
5163
5528
  exports.TypographyLink = TypographyLink;
5164
5529
  exports.VStack = VStack;
5165
5530
  exports.View = View;
5531
+ exports.createChoicesComponent = createChoicesComponent;
5166
5532
  exports.createWindowSizeHelper = createWindowSizeHelper;
5167
5533
  exports.hex2rgba = hex2rgba;
5168
5534
  exports.matchWindowSize = matchWindowSize;