@teambit/component 0.0.743 → 0.0.746

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/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.ui.runtime.d.ts +5 -8
  7. package/dist/component.ui.runtime.js +7 -9
  8. package/dist/component.ui.runtime.js.map +1 -1
  9. package/dist/section/section.d.ts +2 -2
  10. package/dist/section/section.js.map +1 -1
  11. package/dist/ui/component.js +14 -2
  12. package/dist/ui/component.js.map +1 -1
  13. package/dist/ui/menu/index.d.ts +1 -1
  14. package/dist/ui/menu/index.js +2 -2
  15. package/dist/ui/menu/index.js.map +1 -1
  16. package/dist/ui/menu/menu.d.ts +1 -1
  17. package/dist/ui/menu/menu.js +54 -30
  18. package/dist/ui/menu/menu.js.map +1 -1
  19. package/dist/ui/menu/mobile-menu-nav.js +7 -23
  20. package/dist/ui/menu/mobile-menu-nav.js.map +1 -1
  21. package/dist/ui/menu/nav-plugin.d.ts +2 -2
  22. package/dist/ui/menu/nav-plugin.js.map +1 -1
  23. package/dist/ui/top-bar-nav/top-bar-nav.d.ts +2 -2
  24. package/dist/ui/top-bar-nav/top-bar-nav.js +5 -18
  25. package/dist/ui/top-bar-nav/top-bar-nav.js.map +1 -1
  26. package/dist/ui/use-component-from-location.d.ts +1 -0
  27. package/dist/ui/use-component-from-location.js +31 -0
  28. package/dist/ui/use-component-from-location.js.map +1 -0
  29. package/dist/ui/use-component.d.ts +1 -1
  30. package/dist/ui/use-component.js +2 -17
  31. package/dist/ui/use-component.js.map +1 -1
  32. package/package-tar/teambit-component-0.0.746.tgz +0 -0
  33. package/package.json +24 -27
  34. package/{preview-1653708349111.js → preview-1653881205832.js} +2 -2
  35. package/section/section.tsx +2 -2
  36. package/ui/component.tsx +7 -3
  37. package/ui/menu/index.ts +1 -1
  38. package/ui/menu/menu.tsx +34 -17
  39. package/ui/menu/mobile-menu-nav.tsx +14 -15
  40. package/ui/menu/nav-plugin.tsx +2 -3
  41. package/ui/top-bar-nav/top-bar-nav.tsx +6 -8
  42. package/ui/use-component-from-location.tsx +12 -0
  43. package/ui/use-component.tsx +4 -10
  44. package/package-tar/teambit-component-0.0.743.tgz +0 -0
@@ -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