171b1bf7dSAman Mittalimport { PropsWithChildren } from 'react';
2586106d6SBartłomiej Klocek
3e54a3f4bSCedric van Puttenimport { usePageMetadata } from '~/providers/page-metadata';
475c6c5cbSBartosz Kaszubowskiimport { Terminal } from '~/ui/components/Snippet';
55764a173SBartosz Kaszubowskiimport { A, P, DEMI } from '~/ui/components/Text';
6586106d6SBartłomiej Klocek
7cb5b8d03SBartosz Kaszubowskitype InstallSectionProps = PropsWithChildren<{
8586106d6SBartłomiej Klocek  packageName: string;
9586106d6SBartłomiej Klocek  hideBareInstructions?: boolean;
10586106d6SBartłomiej Klocek  cmd?: string[];
11586106d6SBartłomiej Klocek  href?: string;
121f61a071SBartosz Kaszubowski}>;
13586106d6SBartłomiej Klocek
1432aed8e5SCedric van Puttenconst getPackageLink = (packageNames: string) =>
151ebd0329SBrent Vatne  `https://github.com/expo/expo/tree/main/packages/${packageNames.split(' ')[0]}`;
1632aed8e5SCedric van Putten
175764a173SBartosz Kaszubowskiconst getInstallCmd = (packageName: string) => `$ npx expo install ${packageName}`;
1859a5dd8cSBrent Vatne
191f61a071SBartosz Kaszubowskiconst InstallSection = ({
20586106d6SBartłomiej Klocek  packageName,
21586106d6SBartłomiej Klocek  hideBareInstructions = false,
2259a5dd8cSBrent Vatne  cmd = [getInstallCmd(packageName)],
2332aed8e5SCedric van Putten  href = getPackageLink(packageName),
241f61a071SBartosz Kaszubowski}: InstallSectionProps) => {
25a69834b0SBrent Vatne  const { sourceCodeUrl } = usePageMetadata();
26a69834b0SBrent Vatne
27a69834b0SBrent Vatne  return (
28af644ed4SBartosz Kaszubowski    <>
297006d33cSBartosz Kaszubowski      <Terminal cmd={cmd} />
30586106d6SBartłomiej Klocek      {hideBareInstructions ? null : (
315764a173SBartosz Kaszubowski        <P>
32*06f6672eSAman Mittal          If you're installing this in a <A href="/bare/overview/">bare React Native app</A>, you
33*06f6672eSAman Mittal          should also follow{' '}
345764a173SBartosz Kaszubowski          <A href={sourceCodeUrl ?? href}>
355764a173SBartosz Kaszubowski            <DEMI>these additional installation instructions</DEMI>
36cb5b8d03SBartosz Kaszubowski          </A>
37586106d6SBartłomiej Klocek          .
385764a173SBartosz Kaszubowski        </P>
39586106d6SBartłomiej Klocek      )}
40af644ed4SBartosz Kaszubowski    </>
41586106d6SBartłomiej Klocek  );
42a69834b0SBrent Vatne};
43586106d6SBartłomiej Klocek
44586106d6SBartłomiej Klocekexport default InstallSection;
451580cc58SEvan Bacon
461f61a071SBartosz Kaszubowskiexport const APIInstallSection = (props: InstallSectionProps) => {
47e54a3f4bSCedric van Putten  const { packageName } = usePageMetadata();
48e54a3f4bSCedric van Putten  return <InstallSection {...props} packageName={props.packageName ?? packageName} />;
491580cc58SEvan Bacon};
50