Skip to content

Commit

Permalink
Remove AmplifyProvider custom components feature (#716)
Browse files Browse the repository at this point in the history
  • Loading branch information
reesscot authored Nov 15, 2021
1 parent b64d1ad commit e155ef0
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 46 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-cherries-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@aws-amplify/ui-react": minor
---

Remove AmplifyProvider custom components feature
2 changes: 1 addition & 1 deletion docs/src/pages/_app.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function MyApp({ Component, pageProps }) {
<title>Amplify UI</title>
<link rel="icon" type="image/svg+xml" href={favicon} />
</Head>
<AmplifyProvider components={{}} theme={theme} colorMode={colorMode}>
<AmplifyProvider theme={theme} colorMode={colorMode}>
<Header
platform={platform}
colorMode={colorMode}
Expand Down
2 changes: 1 addition & 1 deletion examples/next/pages/examples/listings/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import './styles.scss';
export const App = ({ children }) => {
const [colorMode, setColorMode] = useState<ColorMode>('system');
return (
<AmplifyProvider components={{}} theme={theme} colorMode={colorMode}>
<AmplifyProvider theme={theme} colorMode={colorMode}>
<header className="listing-app-header">
<Logo />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ import * as React from 'react';

import { defaultTheme, WebTheme } from '@aws-amplify/ui';

import * as primitives from '../../primitives/components';

interface AmplifyContextType {
components: Partial<typeof primitives>;
theme: WebTheme;
}

export const AmplifyContext = React.createContext<AmplifyContextType>({
components: primitives,
theme: defaultTheme,
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { render, screen } from '@testing-library/react';
import { useAmplify } from '../../../hooks';

import { AmplifyProvider } from '..';
import { AmplifyProvider } from '../index';
import { Heading } from '../../../primitives';

const App = () => {
const {
components: { Heading },
} = useAmplify();

return <Heading>Howdy</Heading>;
};

Expand All @@ -34,21 +30,4 @@ describe('AmplifyProvider', () => {
expect(wrapper).toBeInTheDocument();
expect(wrapper).toHaveAttribute('data-amplify-theme', 'default-theme');
});

it('accepts custom primitives as components', async () => {
render(
<AmplifyProvider
components={{
Heading({ children }) {
return <h1>Custom {children}</h1>;
},
}}
>
<App />
</AmplifyProvider>
);

const heading = await screen.getByText('Custom Howdy');
expect(heading.nodeName).toBe('H1');
});
});
8 changes: 2 additions & 6 deletions packages/react/src/components/AmplifyProvider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import { IdProvider } from '@radix-ui/react-id';
import * as React from 'react';
import { IdProvider } from '@radix-ui/react-id';

import { createTheme, defaultTheme, Theme as UiTheme } from '@aws-amplify/ui';

import { AmplifyContext } from './AmplifyContext';
import * as primitives from '../../primitives/components';

export type Theme = UiTheme;
export type ColorMode = 'system' | 'light' | 'dark';

interface AmplifyProviderProps {
children: React.ReactNode;
components?: Partial<typeof primitives>;
theme?: Theme;
colorMode?: ColorMode;
theme?: Theme;
}

export function AmplifyProvider({
children,
components,
colorMode,
theme = defaultTheme,
}: AmplifyProviderProps) {
Expand All @@ -27,7 +24,6 @@ export function AmplifyProvider({
return (
<AmplifyContext.Provider
value={{
components,
theme: webTheme,
}}
>
Expand Down
13 changes: 2 additions & 11 deletions packages/react/src/hooks/useAmplify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,14 @@ import * as React from 'react';
import { Theme } from '@aws-amplify/ui';

import { AmplifyContext } from '../components/AmplifyProvider/AmplifyContext';
import * as primitives from '../primitives/components';

interface UseAmplifyOutput {
components: typeof primitives;
theme: Theme;
}

export function useAmplify(): UseAmplifyOutput {
const context = React.useContext(AmplifyContext);
const { components: customComponents, theme } = context;
const components = React.useMemo(
() => ({
...primitives,
...customComponents,
}),
[customComponents]
);
const { theme } = context;

return { components, theme };
return { theme };
}

0 comments on commit e155ef0

Please sign in to comment.