@teambit/component 0.0.741 → 0.0.744

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 (46) hide show
  1. package/aspect.section.tsx +1 -1
  2. package/component.ui.runtime.tsx +10 -11
  3. package/dist/aspect.section.d.ts +1 -1
  4. package/dist/aspect.section.js +1 -1
  5. package/dist/aspect.section.js.map +1 -1
  6. package/dist/component-factory.d.ts +6 -0
  7. package/dist/component-factory.js.map +1 -1
  8. package/dist/component.ui.runtime.d.ts +5 -8
  9. package/dist/component.ui.runtime.js +7 -9
  10. package/dist/component.ui.runtime.js.map +1 -1
  11. package/dist/section/section.d.ts +2 -2
  12. package/dist/section/section.js.map +1 -1
  13. package/dist/ui/component.js +14 -2
  14. package/dist/ui/component.js.map +1 -1
  15. package/dist/ui/menu/index.d.ts +1 -1
  16. package/dist/ui/menu/index.js +2 -2
  17. package/dist/ui/menu/index.js.map +1 -1
  18. package/dist/ui/menu/menu.d.ts +1 -1
  19. package/dist/ui/menu/menu.js +54 -30
  20. package/dist/ui/menu/menu.js.map +1 -1
  21. package/dist/ui/menu/mobile-menu-nav.js +7 -23
  22. package/dist/ui/menu/mobile-menu-nav.js.map +1 -1
  23. package/dist/ui/menu/nav-plugin.d.ts +2 -2
  24. package/dist/ui/menu/nav-plugin.js.map +1 -1
  25. package/dist/ui/top-bar-nav/top-bar-nav.d.ts +2 -2
  26. package/dist/ui/top-bar-nav/top-bar-nav.js +5 -18
  27. package/dist/ui/top-bar-nav/top-bar-nav.js.map +1 -1
  28. package/dist/ui/use-component-from-location.d.ts +1 -0
  29. package/dist/ui/use-component-from-location.js +31 -0
  30. package/dist/ui/use-component-from-location.js.map +1 -0
  31. package/dist/ui/use-component.d.ts +1 -1
  32. package/dist/ui/use-component.js +2 -17
  33. package/dist/ui/use-component.js.map +1 -1
  34. package/package-tar/teambit-component-0.0.744.tgz +0 -0
  35. package/package.json +29 -32
  36. package/{preview-1653494536947.js → preview-1653827208409.js} +2 -2
  37. package/section/section.tsx +2 -2
  38. package/ui/component.tsx +7 -3
  39. package/ui/menu/index.ts +1 -1
  40. package/ui/menu/menu.tsx +34 -17
  41. package/ui/menu/mobile-menu-nav.tsx +14 -15
  42. package/ui/menu/nav-plugin.tsx +2 -3
  43. package/ui/top-bar-nav/top-bar-nav.tsx +6 -8
  44. package/ui/use-component-from-location.tsx +12 -0
  45. package/ui/use-component.tsx +4 -10
  46. package/package-tar/teambit-component-0.0.741.tgz +0 -0
@@ -1,9 +1,8 @@
1
1
  import React, { useMemo } from 'react';
2
- import { Switch, Route, useRouteMatch } from 'react-router-dom';
2
+ import { Routes, Route } from 'react-router-dom';
3
3
  import classnames from 'classnames';
4
4
  import { Icon } from '@teambit/design.elements.icon';
5
5
  import { Dropdown } from '@teambit/design.inputs.dropdown';
6
- import { extendPath } from '@teambit/ui-foundation.ui.react-router.extend-path';
7
6
  import { TopBarNav } from '../top-bar-nav';
8
7
  import styles from './menu.module.scss';
9
8
  import mobileStyles from './mobile-menu-nav.module.scss';
@@ -18,7 +17,6 @@ export function MobileMenuNav({
18
17
  widgetSlot: OrderedNavigationSlot;
19
18
  className?: string;
20
19
  }) {
21
- const { url } = useRouteMatch();
22
20
  const totalSlots = useMemo(
23
21
  () => [...navigationSlot.toArray().sort(sortFn), ...widgetSlot.toArray().sort(sortFn)],
24
22
  [navigationSlot, widgetSlot]
@@ -27,7 +25,7 @@ export function MobileMenuNav({
27
25
  return (
28
26
  <Dropdown
29
27
  // @ts-ignore - mismatch between @types/react
30
- placeholder={<Placeholder slots={totalSlots} baseUrl={url} />}
28
+ placeholder={<Placeholder slots={totalSlots} />}
31
29
  className={classnames(styles.navigation, styles.mobileNav, className)}
32
30
  dropClass={mobileStyles.mobileMenu}
33
31
  >
@@ -63,19 +61,20 @@ type PlaceholderProps = {
63
61
  baseUrl?: string;
64
62
  } & React.HTMLAttributes<HTMLDivElement>;
65
63
 
66
- function Placeholder({ slots, baseUrl = '', ...rest }: PlaceholderProps) {
64
+ function Placeholder({ slots, ...rest }: PlaceholderProps) {
67
65
  return (
68
66
  <div {...rest} className={mobileStyles.placeholder}>
69
- <Switch>
70
- {slots?.map(([id, menuItem]) => {
71
- const path = extendPath(baseUrl, menuItem?.props?.href);
72
- return (
73
- <Route key={id} exact path={path}>
74
- {typeof menuItem?.props?.children === 'string' ? menuItem?.props?.children : menuItem?.props?.displayName}
75
- </Route>
76
- );
77
- })}
78
- </Switch>
67
+ <Routes>
68
+ {slots?.map(([id, menuItem]) => (
69
+ <Route
70
+ key={id}
71
+ path={menuItem?.props?.href}
72
+ element={
73
+ typeof menuItem?.props?.children === 'string' ? menuItem?.props?.children : menuItem?.props?.displayName
74
+ }
75
+ />
76
+ ))}
77
+ </Routes>
79
78
  <Icon of="fat-arrow-down" />
80
79
  </div>
81
80
  );
@@ -1,13 +1,12 @@
1
- // import { ReactNode } from 'react';
2
1
  import { SlotRegistry } from '@teambit/harmony';
3
- import { NavLinkProps } from '@teambit/base-ui.routing.nav-link';
2
+ import type { LinkProps } from '@teambit/base-react.navigation.link';
4
3
  import type { ConsumeMethod } from '@teambit/ui-foundation.ui.use-box.menu';
5
4
  import { LaneModel } from '@teambit/lanes.ui.lanes';
6
5
  import { ComponentModel } from '../../ui';
7
6
 
8
7
  export type NavPluginProps = {
9
8
  displayName?: string;
10
- } & NavLinkProps;
9
+ } & LinkProps;
11
10
 
12
11
  export type NavPlugin = {
13
12
  props: NavPluginProps;
@@ -1,27 +1,25 @@
1
1
  import React from 'react';
2
2
  import classnames from 'classnames';
3
- import { useRouteMatch, useLocation } from 'react-router-dom';
4
- import { NavLink, NavLinkProps } from '@teambit/base-ui.routing.nav-link';
5
- import { extendPath } from '@teambit/ui-foundation.ui.react-router.extend-path';
3
+ import { useLocation } from 'react-router-dom';
4
+ import { Link, LinkProps } from '@teambit/base-react.navigation.link';
6
5
 
7
6
  import styles from './top-bar-nav.module.scss';
8
7
 
9
- export type TopBarNavProps = {} & NavLinkProps;
8
+ export type TopBarNavProps = {} & LinkProps;
10
9
 
11
10
  export function TopBarNav({ href, className, activeClassName, children, ...rest }: TopBarNavProps) {
12
- const { url } = useRouteMatch();
13
11
  const { search } = useLocation(); // sticky query params
14
12
 
15
- const target = `${extendPath(url, href)}${search}`;
13
+ const target = `${href}${search}`;
16
14
 
17
15
  return (
18
- <NavLink
16
+ <Link
19
17
  {...rest}
20
18
  className={classnames(className, styles.topBarLink)}
21
19
  activeClassName={classnames(activeClassName, styles.active)}
22
20
  href={target}
23
21
  >
24
22
  <div>{children}</div>
25
- </NavLink>
23
+ </Link>
26
24
  );
27
25
  }
@@ -0,0 +1,12 @@
1
+ import { useParams } from 'react-router-dom';
2
+
3
+ /** component url is comprised of letters, numbers, "_", "-", "/" but should not include trailing "/", and should not include "~" */
4
+ const componentRegex = /^[\w/-]*[\w-]/;
5
+ export function useIdFromLocation() {
6
+ const params = useParams();
7
+ const splat = params['*'];
8
+ if (!splat) return undefined;
9
+
10
+ const match = componentRegex.exec(splat);
11
+ return match?.[0];
12
+ }
@@ -1,4 +1,3 @@
1
- import { useRouteMatch } from 'react-router-dom';
2
1
  import { ComponentID } from '@teambit/component-id';
3
2
  import { useQuery } from '@teambit/ui-foundation.ui.react-router.use-query';
4
3
  import { ComponentDescriptor } from '@teambit/component-descriptor';
@@ -13,18 +12,13 @@ export type Component = {
13
12
  componentDescriptor?: ComponentDescriptor;
14
13
  };
15
14
 
16
- type ComponentRoute = {
17
- componentId?: string;
18
- };
19
-
20
- export function useComponent(host: string, id?: ComponentID): Component {
21
- const {
22
- params: { componentId },
23
- } = useRouteMatch<ComponentRoute>();
15
+ export function useComponent(host: string, id?: string | ComponentID): Component {
24
16
  const query = useQuery();
25
17
  const version = query.get('version') || undefined;
26
18
  const lanesContext = useLanesContext();
27
- const targetId = id?.toString({ ignoreVersion: true }) || componentId;
19
+
20
+ const targetId =
21
+ (typeof id === 'string' && id) || (typeof id !== 'undefined' && id.toString({ ignoreVersion: true }));
28
22
  if (!targetId) throw new TypeError('useComponent received no component id');
29
23
  const currentLane = lanesContext?.viewedLane;
30
24
  // when on a lane, always fetch all the logs starting from the 'head' version