diff --git a/packages/react-core/README.md b/packages/react-core/README.md index 4e683b47282..1de353f7db0 100644 --- a/packages/react-core/README.md +++ b/packages/react-core/README.md @@ -1,3 +1,3 @@ # Amplify UI React Core -`@aws-amplify/ui-react-core` is a React platform agnostic utility library for Amplify UI internal usage in the `@aws-amplify/ui-react` and `@aws-amplify/ui-react-native` packages. +`@aws-amplify/ui-react-core` is a React platform agnostic utility library for Amplify UI internal usage in `@aws-amplify/ui-react*` and `@aws-amplify/ui-react-native*` namespaced packages. diff --git a/packages/react-core/elements/package.json b/packages/react-core/elements/package.json new file mode 100644 index 00000000000..878c2bf69e2 --- /dev/null +++ b/packages/react-core/elements/package.json @@ -0,0 +1,7 @@ +{ + "name": "@aws-amplify/ui-react-core/elements", + "main": "../dist/elements.js", + "module": "../dist/esm/elements/index.mjs", + "sideEffects": false, + "types": "../dist/types/elements/index.d.ts" +} diff --git a/packages/react-core/package.json b/packages/react-core/package.json index 8f6eb9df69e..72e9a5efece 100644 --- a/packages/react-core/package.json +++ b/packages/react-core/package.json @@ -10,6 +10,12 @@ "require": "./dist/index.js", "types": "./dist/types/index.d.ts" }, + "./elements": { + "import": "./dist/esm/elements/index.mjs", + "require": "./dist/elements.js", + "types": "./dist/types/elements/index.d.ts", + "react-native": "./src/elements/index.ts" + }, "./package.json": "./package.json" }, "types": "dist/types/index.d.ts", diff --git a/packages/react-core/rollup.config.ts b/packages/react-core/rollup.config.ts index 1aa5fec3e74..cf4a7f4eb4d 100644 --- a/packages/react-core/rollup.config.ts +++ b/packages/react-core/rollup.config.ts @@ -3,7 +3,9 @@ import typescript from '@rollup/plugin-typescript'; import externals from 'rollup-plugin-node-externals'; // common config settings -const input = ['src/index.ts']; + +// { OUTPUT_PATH: INPUT_PATH } +const input = { index: 'src/index.ts', elements: 'src/elements/index.ts' }; const sourceMap = false; const tsconfig = 'tsconfig.dist.json'; diff --git a/packages/react/src/context/elements/ElementsContext.tsx b/packages/react-core/src/elements/ElementsContext.tsx similarity index 86% rename from packages/react/src/context/elements/ElementsContext.tsx rename to packages/react-core/src/elements/ElementsContext.tsx index f5fe001150e..4287d175dfd 100644 --- a/packages/react/src/context/elements/ElementsContext.tsx +++ b/packages/react-core/src/elements/ElementsContext.tsx @@ -1,12 +1,19 @@ import React from 'react'; import { ElementDisplayName } from './types'; +/** + * @internal @unstable + */ export interface Elements extends Partial> {} -const ElementsContext = React.createContext(undefined); +export const ElementsContext = React.createContext( + undefined +); /** + * @internal @unstable + * * `ElementsProvider` and its coresponding `useElement` hook provide * access to the values of the nearest ancestral `ElementsContext` * value. @@ -64,10 +71,3 @@ export function ElementsProvider({ }): React.JSX.Element { return ; } - -export const useElement = ( - name: T -): Elements[T] | undefined => { - const context = React.useContext(ElementsContext); - return context?.[name]; -}; diff --git a/packages/react/src/context/elements/__tests__/ElementsContext.spec.tsx b/packages/react-core/src/elements/__tests__/ElementsContext.spec.tsx similarity index 51% rename from packages/react/src/context/elements/__tests__/ElementsContext.spec.tsx rename to packages/react-core/src/elements/__tests__/ElementsContext.spec.tsx index 95f3a027135..02eafafab23 100644 --- a/packages/react/src/context/elements/__tests__/ElementsContext.spec.tsx +++ b/packages/react-core/src/elements/__tests__/ElementsContext.spec.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { renderHook } from '@testing-library/react-hooks'; -import { ElementsProvider, useElement } from '../ElementsContext'; +import { ElementsProvider, ElementsContext } from '../ElementsContext'; const ButtonElement = () =>