Skip to content

Add Gen1 banner to getting started pages #7839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/components/Callout/Callout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@ import { Message, View } from '@aws-amplify/ui-react';
interface CalloutProps {
info?: boolean;
warning?: boolean;
backgroundColor?: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of changing how the callout component is currently being used I've exposed the backgroundColor property of the underlying Message component. If both backgroundColor and the warning flag are used, the backgroundColor property will win out for backgroundColor styling

children?: React.ReactNode;
}

export const Callout = ({ warning, children }: CalloutProps) => {
export const Callout = ({
warning,
backgroundColor,
children
}: CalloutProps) => {
return (
<Message variation="filled" colorTheme={warning ? 'warning' : 'info'}>
<Message
variation="filled"
colorTheme={warning ? 'warning' : 'info'}
backgroundColor={backgroundColor}
>
<View>{children}</View>
</Message>
);
Expand Down
13 changes: 13 additions & 0 deletions src/components/Callout/__tests__/Callout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,17 @@ describe('Callout', () => {

consoleErrorFn.mockRestore();
});

it('should pass the backgroundColor through to the Message component', async () => {
const child = <div>Callout Child</div>;
const ele = render(
<Callout info={true} backgroundColor={'red'}>
{child}
</Callout>
);

const styles = getComputedStyle(ele.container.children[0]);
console.log(styles);
expect(styles.backgroundColor).toBe('red');
});
});
20 changes: 20 additions & 0 deletions src/components/Gen1Banner/Gen1Banner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Callout } from '@/components/Callout';
import Link from 'next/link';
import classNames from 'classnames';

export const Gen1Banner = ({ currentPlatform }) => {
return (
<Callout backgroundColor="background.error">
For new Amplify apps, we recommend using Amplify Gen 2. You can learn more
in our{' '}
<Link
href={`/${currentPlatform}/start/quickstart`}
passHref
className={classNames('amplify-link')}
>
Gen 2 Docs
</Link>
.
</Callout>
);
};
1 change: 1 addition & 0 deletions src/components/Gen1Banner/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Gen1Banner } from './Gen1Banner';
11 changes: 11 additions & 0 deletions src/components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
NEXT_PREVIOUS_SECTIONS
} from '@/components/NextPrevious';
import { Modal } from '@/components/Modal';
import { Gen1Banner } from '@/components/Gen1Banner';

export const Layout = ({
children,
Expand Down Expand Up @@ -127,6 +128,13 @@ export const Layout = ({
}
}, 20);

const isGen1GettingStarted = /\/gen1\/\w+\/start\/getting-started\//.test(
asPathWithNoHash
);
const isGen1HowAmplifyWorks = /\/gen1\/\w+\/how-amplify-works\//.test(
asPathWithNoHash
);

useEffect(() => {
const headings: HeadingInterface[] = [];

Expand Down Expand Up @@ -254,6 +262,9 @@ export const Layout = ({
{useCustomTitle ? null : (
<Heading level={1}>{pageTitle}</Heading>
)}
{(isGen1GettingStarted || isGen1HowAmplifyWorks) && (
<Gen1Banner currentPlatform={currentPlatform} />
)}
{children}
{showNextPrev && <NextPrevious />}
</Flex>
Expand Down