@ornikar/kitt-universal 2.1.0 → 2.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 (58) hide show
  1. package/dist/definitions/Button/Button.d.ts +6 -3
  2. package/dist/definitions/Button/Button.d.ts.map +1 -1
  3. package/dist/definitions/Button/{ButtonContainer.d.ts → ButtonPressable.d.ts} +3 -3
  4. package/dist/definitions/Button/{ButtonContainer.d.ts.map → ButtonPressable.d.ts.map} +1 -1
  5. package/dist/definitions/Emoji/Emoji.d.ts +8 -0
  6. package/dist/definitions/Emoji/Emoji.d.ts.map +1 -0
  7. package/dist/definitions/ExternalLink/ExternalLink.d.ts +18 -0
  8. package/dist/definitions/ExternalLink/ExternalLink.d.ts.map +1 -0
  9. package/dist/definitions/ExternalLink/ExternalLink.web.d.ts +4 -0
  10. package/dist/definitions/ExternalLink/ExternalLink.web.d.ts.map +1 -0
  11. package/dist/definitions/ExternalLink/ExternalLinkOpenLinkBehavior.d.ts +24 -0
  12. package/dist/definitions/ExternalLink/ExternalLinkOpenLinkBehavior.d.ts.map +1 -0
  13. package/dist/definitions/Tag/Tag.d.ts +6 -3
  14. package/dist/definitions/Tag/Tag.d.ts.map +1 -1
  15. package/dist/definitions/index.d.ts +9 -1
  16. package/dist/definitions/index.d.ts.map +1 -1
  17. package/dist/definitions/primitives/PrimitiveImage.d.ts +13 -0
  18. package/dist/definitions/primitives/PrimitiveImage.d.ts.map +1 -0
  19. package/dist/definitions/primitives/PrimitiveImage.web.d.ts +4 -0
  20. package/dist/definitions/primitives/PrimitiveImage.web.d.ts.map +1 -0
  21. package/dist/definitions/primitives/PrimitiveLink.d.ts +3 -1
  22. package/dist/definitions/primitives/PrimitiveLink.d.ts.map +1 -1
  23. package/dist/definitions/primitives/PrimitiveLink.web.d.ts +1 -1
  24. package/dist/definitions/primitives/PrimitiveLink.web.d.ts.map +1 -1
  25. package/dist/definitions/primitives/PrimitivePressable.d.ts +4 -1
  26. package/dist/definitions/primitives/PrimitivePressable.d.ts.map +1 -1
  27. package/dist/definitions/primitives/PrimitivePressable.web.d.ts.map +1 -1
  28. package/dist/definitions/primitives/PrimitiveView.d.ts +3 -0
  29. package/dist/definitions/primitives/PrimitiveView.d.ts.map +1 -1
  30. package/dist/definitions/primitives/PrimitiveView.web.d.ts +6 -2
  31. package/dist/definitions/primitives/PrimitiveView.web.d.ts.map +1 -1
  32. package/dist/definitions/story-components/StoryDecorator.d.ts +3 -3
  33. package/dist/definitions/story-components/StoryDecorator.d.ts.map +1 -1
  34. package/dist/definitions/themes/default.d.ts +30 -3
  35. package/dist/definitions/themes/default.d.ts.map +1 -1
  36. package/dist/definitions/themes/late-ocean/tagLateOceanTheme.d.ts +30 -3
  37. package/dist/definitions/themes/late-ocean/tagLateOceanTheme.d.ts.map +1 -1
  38. package/dist/definitions/typography/Typography.d.ts +3 -3
  39. package/dist/definitions/typography/Typography.d.ts.map +1 -1
  40. package/dist/definitions/typography/TypographyEmoji.d.ts +8 -0
  41. package/dist/definitions/typography/TypographyEmoji.d.ts.map +1 -0
  42. package/dist/definitions/typography/TypographyLink.d.ts +7 -4
  43. package/dist/definitions/typography/TypographyLink.d.ts.map +1 -1
  44. package/dist/definitions/utils/storybook/decorators/SafeAreaProviderDecorator.d.ts.map +1 -1
  45. package/dist/index-browser-all.es.android.js +329 -151
  46. package/dist/index-browser-all.es.android.js.map +1 -1
  47. package/dist/index-browser-all.es.ios.js +329 -151
  48. package/dist/index-browser-all.es.ios.js.map +1 -1
  49. package/dist/index-browser-all.es.js +279 -96
  50. package/dist/index-browser-all.es.js.map +1 -1
  51. package/dist/index-browser-all.es.web.js +383 -164
  52. package/dist/index-browser-all.es.web.js.map +1 -1
  53. package/dist/index-node-14.17.cjs.js +250 -66
  54. package/dist/index-node-14.17.cjs.js.map +1 -1
  55. package/dist/tsbuildinfo +1 -1
  56. package/package.json +5 -2
  57. package/dist/definitions/Button/useButton.d.ts +0 -6
  58. package/dist/definitions/Button/useButton.d.ts.map +0 -1
@@ -7,6 +7,8 @@ const kittIcons = require('@ornikar/kitt-icons');
7
7
  const React = require('react');
8
8
  const reactNative = require('react-native');
9
9
  const styled = require('styled-components');
10
+ const twemojiParser = require('twemoji-parser');
11
+ const WebBrowser = require('expo-web-browser');
10
12
  const reactNativeSafeAreaContext = require('react-native-safe-area-context');
11
13
  const Animated = require('react-native-reanimated');
12
14
  const addons = require('@storybook/addons');
@@ -277,43 +279,6 @@ function Avatar({
277
279
  })));
278
280
  }
279
281
 
280
- const PrimitivePressable = reactNative.Pressable;
281
-
282
- const ButtonContainer = /*#__PURE__*/styled__default(PrimitivePressable).withConfig({
283
- displayName: "ButtonContainer",
284
- componentId: "kitt-universal__sc-ofbpwm-0"
285
- })(["min-width:", ";max-width:", ";width:", ";min-height:", ";background-color:", ";padding:", ";flex-direction:row;align-self:flex-start;border-radius:", ";border-color:", ";border-width:", ";"], ({
286
- theme
287
- }) => theme.kitt.button.minWidth, ({
288
- theme,
289
- stretch
290
- }) => stretch ? 'auto' : theme.kitt.button.maxWidth, ({
291
- stretch
292
- }) => stretch ? '100%' : 'auto', ({
293
- theme
294
- }) => theme.kitt.button.minHeight, ({
295
- theme,
296
- isPressed,
297
- disabled,
298
- type
299
- }) => {
300
- if (disabled) {
301
- return theme.kitt.button[type].disabledBackgroundColor;
302
- }
303
-
304
- return isPressed ? theme.kitt.button[type].pressedBackgroundColor : theme.kitt.button[type].backgroundColor;
305
- }, ({
306
- theme
307
- }) => theme.kitt.button.contentPadding.default, ({
308
- theme
309
- }) => theme.kitt.button.borderRadius, ({
310
- theme,
311
- disabled,
312
- type
313
- }) => disabled ? theme.kitt.button[type].disabledBorderColor : 'transparent', ({
314
- theme
315
- }) => theme.kitt.button.borderWidth);
316
-
317
282
  function TypographyIconInheritColor(props) {
318
283
  const color = useTypographyColor();
319
284
  const theme = /*#__PURE__*/styled.useTheme();
@@ -459,14 +424,42 @@ function ButtonContent({
459
424
  })) : null);
460
425
  }
461
426
 
462
- const useButton = () => {
463
- const [isPressed, setIsPressed] = React.useState(false);
464
- return {
465
- isPressed,
466
- handleButtonPressIn: () => setIsPressed(true),
467
- handleButtonPressOut: () => setIsPressed(false)
468
- };
469
- };
427
+ const PrimitivePressable = reactNative.Pressable;
428
+
429
+ const ButtonPressable = /*#__PURE__*/styled__default(PrimitivePressable).withConfig({
430
+ displayName: "ButtonPressable",
431
+ componentId: "kitt-universal__sc-7ckel6-0"
432
+ })(["min-width:", ";max-width:", ";width:", ";min-height:", ";background-color:", ";padding:", ";flex-direction:row;align-self:flex-start;border-radius:", ";border-color:", ";border-width:", ";"], ({
433
+ theme
434
+ }) => theme.kitt.button.minWidth, ({
435
+ theme,
436
+ stretch
437
+ }) => stretch ? 'auto' : theme.kitt.button.maxWidth, ({
438
+ stretch
439
+ }) => stretch ? '100%' : 'auto', ({
440
+ theme
441
+ }) => theme.kitt.button.minHeight, ({
442
+ theme,
443
+ isPressed,
444
+ disabled,
445
+ type
446
+ }) => {
447
+ if (disabled) {
448
+ return theme.kitt.button[type].disabledBackgroundColor;
449
+ }
450
+
451
+ return isPressed ? theme.kitt.button[type].pressedBackgroundColor : theme.kitt.button[type].backgroundColor;
452
+ }, ({
453
+ theme
454
+ }) => theme.kitt.button.contentPadding.default, ({
455
+ theme
456
+ }) => theme.kitt.button.borderRadius, ({
457
+ theme,
458
+ disabled,
459
+ type
460
+ }) => disabled ? theme.kitt.button[type].disabledBorderColor : 'transparent', ({
461
+ theme
462
+ }) => theme.kitt.button.borderWidth);
470
463
 
471
464
  function Button({
472
465
  children,
@@ -476,29 +469,29 @@ function Button({
476
469
  iconSpin,
477
470
  stretch,
478
471
  disabled,
479
- onPress,
480
- testID
472
+ testID,
473
+ href,
474
+ hrefAttrs,
475
+ onPress
481
476
  }) {
482
- const {
483
- isPressed,
484
- handleButtonPressIn,
485
- handleButtonPressOut
486
- } = useButton();
477
+ const [isPressed, setIsPressed] = React.useState(false);
487
478
  const sharedProps = {
488
479
  type,
489
480
  stretch,
490
481
  disabled
491
482
  };
492
- return /*#__PURE__*/React__default.createElement(ButtonContainer // eslint-disable-next-line unicorn/expiring-todo-comments
483
+ return /*#__PURE__*/React__default.createElement(ButtonPressable // eslint-disable-next-line unicorn/expiring-todo-comments
493
484
  // TODO: When designs are defined, update with the proper onPress styles to mimic TouchableHighlight
494
485
  // underlayColor={globalTheme.button[type].pressedBackgroundColor}
495
486
  , _extends__default({}, sharedProps, {
496
487
  isPressed: isPressed,
497
488
  accessibilityRole: "button",
498
489
  testID: testID,
490
+ href: href,
491
+ hrefAttrs: hrefAttrs,
499
492
  onPress: onPress,
500
- onPressIn: handleButtonPressIn,
501
- onPressOut: handleButtonPressOut
493
+ onPressIn: () => setIsPressed(true),
494
+ onPressOut: () => setIsPressed(false)
502
495
  }), /*#__PURE__*/React__default.createElement(ButtonContent, _extends__default({}, sharedProps, {
503
496
  icon: icon,
504
497
  iconPosition: iconPosition,
@@ -531,6 +524,79 @@ function Card({
531
524
  }, children);
532
525
  }
533
526
 
527
+ const PrimitiveImage = reactNative.Image;
528
+
529
+ const StyledEmoji = /*#__PURE__*/styled__default(PrimitiveImage).withConfig({
530
+ displayName: "Emoji__StyledEmoji",
531
+ componentId: "kitt-universal__sc-ggl6wj-0"
532
+ })(["width:", "px;height:", "px;"], ({
533
+ size
534
+ }) => size, ({
535
+ size
536
+ }) => size);
537
+ function Emoji({
538
+ emoji,
539
+ size,
540
+ style,
541
+ className
542
+ }) {
543
+ const [emojiData] = React.useMemo(() => twemojiParser.parse(emoji, {
544
+ // on native plaforms, you can't display svg as Image
545
+ assetType: reactNative.Platform.OS === 'web' ? 'svg' : 'png'
546
+ }), [emoji]);
547
+ if (!emojiData) return null;
548
+ return /*#__PURE__*/React__default.createElement(StyledEmoji, {
549
+ size: size,
550
+ accessibilityLabel: emojiData.text,
551
+ source: {
552
+ uri: emojiData.url
553
+ },
554
+ style: style,
555
+ className: className
556
+ });
557
+ }
558
+
559
+ const defaultOpenLinkBehavior = {
560
+ native: 'openInModal',
561
+ web: 'targetBlank'
562
+ };
563
+
564
+ function ExternalLink({
565
+ as: Component,
566
+ href,
567
+ openLinkBehavior = defaultOpenLinkBehavior,
568
+ onPress,
569
+ ...rest
570
+ }) {
571
+ return /*#__PURE__*/React__default.createElement(Component, _extends__default({}, rest, {
572
+ onPress: () => {
573
+ if (onPress) onPress();
574
+ if (!href) return;
575
+
576
+ switch (openLinkBehavior.native) {
577
+ case 'openInModal':
578
+ case undefined:
579
+ reactNative.Linking.openURL(href).catch(err => {
580
+ console.error(`An error occurred while opening ${href}`, err);
581
+ });
582
+ break;
583
+
584
+ case 'openBrowserApp':
585
+ WebBrowser.openBrowserAsync(href).catch(err => {
586
+ console.error(`An error occurred while opening ${href}`, err);
587
+ });
588
+ break;
589
+
590
+ default:
591
+ if ((process.env.NODE_ENV !== "production")) {
592
+ throw new Error(`Invalid ExternalLink native behavior: ${openLinkBehavior.native}`);
593
+ }
594
+
595
+ }
596
+ }
597
+ }));
598
+ }
599
+
534
600
  const getColorFromState = state => {
535
601
  switch (state) {
536
602
  case 'invalid':
@@ -1942,23 +2008,57 @@ const StoryGrid = {
1942
2008
  const Container = /*#__PURE__*/styled__default(PrimitiveView).withConfig({
1943
2009
  displayName: "Tag__Container",
1944
2010
  componentId: "kitt-universal__sc-19jmowi-0"
1945
- })(["background-color:", ";padding:", ";border-radius:", ";align-self:flex-start;"], ({
2011
+ })(["background-color:", ";border-width:", ";border-color:", ";padding:", ";border-radius:", ";align-self:flex-start;"], ({
1946
2012
  theme,
1947
- type
1948
- }) => theme.kitt.tag[type].backgroundColor, ({
2013
+ type,
2014
+ variant
2015
+ }) => theme.kitt.tag[type][variant].backgroundColor, ({
2016
+ theme,
2017
+ type,
2018
+ variant
2019
+ }) => theme.kitt.tag[type][variant].borderWidth, ({
2020
+ theme,
2021
+ type,
2022
+ variant
2023
+ }) => theme.kitt.tag[type][variant].borderColor, ({
1949
2024
  theme
1950
2025
  }) => theme.kitt.tag.padding, ({
1951
2026
  theme
1952
2027
  }) => theme.kitt.tag.borderRadius);
2028
+ const getLabelColor = (type, variant) => {
2029
+ switch (type) {
2030
+ case 'danger':
2031
+ {
2032
+ return variant === 'outline' ? 'danger' : 'black';
2033
+ }
2034
+
2035
+ case 'primary':
2036
+ {
2037
+ return 'primary';
2038
+ }
2039
+
2040
+ case 'default':
2041
+ {
2042
+ return 'black';
2043
+ }
2044
+
2045
+ default:
2046
+ {
2047
+ return 'black';
2048
+ }
2049
+ }
2050
+ };
1953
2051
  function Tag({
1954
2052
  label,
1955
- type = 'default'
2053
+ type = 'default',
2054
+ variant = 'fill'
1956
2055
  }) {
1957
2056
  return /*#__PURE__*/React__default.createElement(Container, {
1958
- type: type
2057
+ type: type,
2058
+ variant: variant
1959
2059
  }, /*#__PURE__*/React__default.createElement(Typography.Text, {
1960
2060
  base: "body-xsmall",
1961
- color: type === 'primary' ? 'primary-light' : undefined
2061
+ color: getLabelColor(type, variant)
1962
2062
  }, label));
1963
2063
  }
1964
2064
 
@@ -2013,9 +2113,9 @@ const buttonLateOceanTheme = {
2013
2113
  disabledBorderColor: lateOceanColorPalette.black100
2014
2114
  },
2015
2115
  secondary: {
2016
- backgroundColor: lateOceanColorPalette.black50,
2116
+ backgroundColor: 'rgba(0, 0, 0, 0.05)',
2017
2117
  disabledBackgroundColor: lateOceanColorPalette.black50,
2018
- pressedBackgroundColor: lateOceanColorPalette.black100,
2118
+ pressedBackgroundColor: 'rgba(0, 0, 0, 0.1)',
2019
2119
  disabledBorderColor: lateOceanColorPalette.black100
2020
2120
  },
2021
2121
  subtle: {
@@ -2216,13 +2316,40 @@ const tagLateOceanTheme = {
2216
2316
  borderRadius: '10px',
2217
2317
  padding: '2px 12px',
2218
2318
  primary: {
2219
- backgroundColor: lateOceanColorPalette.moonPurpleLight1
2319
+ fill: {
2320
+ backgroundColor: lateOceanColorPalette.moonPurpleLight1,
2321
+ borderWidth: '0',
2322
+ borderColor: lateOceanColorPalette.transparent
2323
+ },
2324
+ outline: {
2325
+ backgroundColor: lateOceanColorPalette.transparent,
2326
+ borderWidth: '1px',
2327
+ borderColor: lateOceanColorPalette.lateOcean
2328
+ }
2220
2329
  },
2221
2330
  default: {
2222
- backgroundColor: lateOceanColorPalette.black50
2331
+ fill: {
2332
+ backgroundColor: lateOceanColorPalette.black50,
2333
+ borderWidth: '0',
2334
+ borderColor: lateOceanColorPalette.transparent
2335
+ },
2336
+ outline: {
2337
+ backgroundColor: lateOceanColorPalette.transparent,
2338
+ borderWidth: '1px',
2339
+ borderColor: lateOceanColorPalette.black1000
2340
+ }
2223
2341
  },
2224
2342
  danger: {
2225
- backgroundColor: lateOceanColorPalette.warmEmbrace
2343
+ fill: {
2344
+ backgroundColor: lateOceanColorPalette.warmEmbrace,
2345
+ borderWidth: '0',
2346
+ borderColor: lateOceanColorPalette.transparent
2347
+ },
2348
+ outline: {
2349
+ backgroundColor: lateOceanColorPalette.transparent,
2350
+ borderWidth: '1px',
2351
+ borderColor: colorsLateOceanTheme.danger
2352
+ }
2226
2353
  }
2227
2354
  };
2228
2355
 
@@ -2347,6 +2474,54 @@ function Tooltip({
2347
2474
  return /*#__PURE__*/React__default.createElement(PrimitiveView, null, children);
2348
2475
  }
2349
2476
 
2477
+ const isBody = value => {
2478
+ return ['body-large', 'body-medium', 'body', 'body-small', 'body-xsmall'].includes(value);
2479
+ };
2480
+
2481
+ function getDimensions(base, theme) {
2482
+ if (isBody(base)) {
2483
+ return theme.kitt.typography.types.bodies.configs[base];
2484
+ }
2485
+
2486
+ return theme.kitt.typography.types.headers.configs[base];
2487
+ }
2488
+
2489
+ const StyledTypographyEmoji = /*#__PURE__*/styled__default(Emoji).withConfig({
2490
+ displayName: "TypographyEmoji__StyledTypographyEmoji",
2491
+ componentId: "kitt-universal__sc-1if5guu-0"
2492
+ })(["align-self:center;", ""], ({
2493
+ size
2494
+ }) => {
2495
+ if (reactNative.Platform.OS !== 'web') return undefined;
2496
+ /* Style Twemoji: https://github.com/twitter/twemoji#inline-styles */
2497
+
2498
+ return `
2499
+ margin: 0 ${size / 20}px 0 ${size / 10}px;
2500
+ transform: translateY(${size / 10 * 2}px);
2501
+ `;
2502
+ });
2503
+ function TypographyEmoji({
2504
+ emoji,
2505
+ base = 'body'
2506
+ }) {
2507
+ const theme = /*#__PURE__*/styled.useTheme();
2508
+ const dimensions = getDimensions(base, theme);
2509
+ const {
2510
+ baseAndSmall: {
2511
+ fontSize
2512
+ }
2513
+ } = dimensions;
2514
+
2515
+ if ((process.env.NODE_ENV !== "production")) {
2516
+ if (!fontSize.endsWith('px')) throw new Error(`Unexpected font-size value: ${fontSize}`);
2517
+ }
2518
+
2519
+ return /*#__PURE__*/React__default.createElement(StyledTypographyEmoji, {
2520
+ size: parseInt(fontSize.slice(0, -2), 10),
2521
+ emoji: emoji
2522
+ });
2523
+ }
2524
+
2350
2525
  const StyledLink = /*#__PURE__*/styled__default(PrimitiveLink).withConfig({
2351
2526
  shouldForwardProp: prop => !['disabled', 'noUnderline'].includes(prop)
2352
2527
  }).withConfig({
@@ -2374,6 +2549,8 @@ function TypographyLink({
2374
2549
  children,
2375
2550
  disabled,
2376
2551
  noUnderline,
2552
+ href,
2553
+ hrefAttrs,
2377
2554
  onPress,
2378
2555
  ...otherProps
2379
2556
  }) {
@@ -2382,6 +2559,8 @@ function TypographyLink({
2382
2559
  }), /*#__PURE__*/React__default.createElement(StyledLink, {
2383
2560
  disabled: disabled,
2384
2561
  noUnderline: noUnderline,
2562
+ href: href,
2563
+ hrefAttrs: hrefAttrs,
2385
2564
  accessibilityRole: "link",
2386
2565
  onPress: disabled ? undefined : onPress
2387
2566
  }, children));
@@ -2480,6 +2659,8 @@ exports.useWindowSize = reactNative.useWindowDimensions;
2480
2659
  exports.Avatar = Avatar;
2481
2660
  exports.Button = Button;
2482
2661
  exports.Card = Card;
2662
+ exports.Emoji = Emoji;
2663
+ exports.ExternalLink = ExternalLink;
2483
2664
  exports.Flex = Flex;
2484
2665
  exports.FullScreenModal = FullScreenModal;
2485
2666
  exports.Icon = Icon;
@@ -2490,6 +2671,7 @@ exports.InputText = InputText;
2490
2671
  exports.KittBreakpoints = KittBreakpoints;
2491
2672
  exports.KittBreakpointsMax = KittBreakpointsMax;
2492
2673
  exports.KittThemeDecorator = KittThemeDecorator;
2674
+ exports.KittThemeProvider = KittThemeProvider;
2493
2675
  exports.Label = Label;
2494
2676
  exports.LargeLoader = LargeLoader;
2495
2677
  exports.ListItem = ListItem;
@@ -2498,6 +2680,7 @@ exports.MatchWindowSize = MatchWindowSize;
2498
2680
  exports.Message = Message;
2499
2681
  exports.Modal = Modal;
2500
2682
  exports.Notification = Notification;
2683
+ exports.PrimitiveImage = PrimitiveImage;
2501
2684
  exports.PrimitiveLink = PrimitiveLink;
2502
2685
  exports.PrimitivePressable = PrimitivePressable;
2503
2686
  exports.PrimitiveScrollView = PrimitiveScrollView;
@@ -2517,6 +2700,7 @@ exports.Tag = Tag;
2517
2700
  exports.TextArea = TextArea;
2518
2701
  exports.Tooltip = Tooltip;
2519
2702
  exports.Typography = Typography;
2703
+ exports.TypographyEmoji = TypographyEmoji;
2520
2704
  exports.TypographyIcon = TypographyIcon;
2521
2705
  exports.TypographyLink = TypographyLink;
2522
2706
  exports.createWindowSizeHelper = createWindowSizeHelper;