import * as React from 'react';
import { useRouter } from 'next/router';
import {
MdOutlineChecklist,
MdOutlineWidgets,
MdOutlineAutoAwesome,
MdWebAssetOff,
MdOutlineArticle,
MdOutlinePower,
} from 'react-icons/md';
import {
Text,
Flex,
Collection,
Expander,
ExpanderItem,
useTheme,
} from '@aws-amplify/ui-react';
import {
ComponentNavItem,
connectedComponents,
guides,
theming,
gettingStarted,
primitiveComponents,
} from '../../data/links';
import Link from 'next/link';
import { FrameworkChooser } from './FrameworkChooser';
import { LogoLink } from './LogoLink';
import { MenuButton } from './MenuButton';
const NavLinks = ({
items,
onClick,
}: {
items: ComponentNavItem[];
onClick?: () => void;
}) => (
{({ href, label, tertiary }) => (
{label}
)}
);
const NavLink = ({
href,
children,
onClick,
tertiary = false,
platforms = [],
}) => {
const {
query: { platform = 'react' },
pathname,
} = useRouter();
const isCurrent = pathname.replace('/[platform]', '') === href;
const classNames = `${
tertiary ? 'docs-tertiary-nav-link' : 'docs-secondary-nav-link'
} ${isCurrent ? 'current' : ''}`;
if (platforms.length && !platforms.includes(platform)) {
return null;
}
return (
{children}
);
};
const NavLinkComponentsSection = ({ heading, components, ...props }) => {
const { query } = useRouter();
const { tokens } = useTheme();
const { platform = 'react' } = query;
const platformComponents = components.filter((component) => {
if (component.platforms) {
return component.platforms.includes(platform);
}
return true;
});
if (!platformComponents.length) {
return null;
}
return (
<>
{heading ? (
{heading}
) : null}
>
);
};
const ExpanderTitle = ({ Icon, text }) => {
const { tokens } = useTheme();
return (
{text}
);
};
// TODO: clean up this logic
const SecondaryNav = (props) => {
const { pathname } = useRouter();
const { platform } = props;
// Extract section from URL (/section/... => section)
let section = pathname.split('/')[2];
const [value, setValue] = React.useState([section]);
const isFlutter = platform === 'flutter';
const isReactNative = platform === 'react-native';
const isAndroid = platform === 'android';
const isSwift = platform === 'swift';
const hideTheming = isAndroid || isSwift;
const hideGuidesExpander = isFlutter || isReactNative || isAndroid || isSwift;
return (
{
}
value="getting-started"
>
{gettingStarted.map(({ label, ...rest }) => (
{label}
))}
}
{platform === 'react' ? (
}
value="components"
>
{primitiveComponents.map(({ heading, components }, i) => (
))}
) : null}
}
value="connected-components"
>
{connectedComponents.map(({ label, href, ...rest }) => (
{label}
))}
{/* Android and Swift don't have theming at this time */}
{hideTheming ? null : (
}
value="theming"
>
{theming.map(({ label, ...rest }) => (
{label}
))}
)}
{/* Flutter, React Native, Android, and Swift don't have guides at this time */}
{hideGuidesExpander ? null : (
}
value="guides"
>
{guides.map(({ label, ...rest }) => (
{label}
))}
)}
);
};
export const Sidebar = ({ expanded, setExpanded, platform }) => {
const onClick = () => setExpanded(false);
return (
);
};