diff --git a/.changeset/chilled-crabs-bow.md b/.changeset/chilled-crabs-bow.md new file mode 100644 index 00000000000..b508afeeddb --- /dev/null +++ b/.changeset/chilled-crabs-bow.md @@ -0,0 +1,5 @@ +--- +'@primer/react': minor +--- + +Modules under an internal export pattern are not able to be imported from outside @primer/react diff --git a/contributor-docs/adrs/adr-016-internal-modules.md b/contributor-docs/adrs/adr-016-internal-modules.md index cc91c68e3f3..eadc8c9d053 100644 --- a/contributor-docs/adrs/adr-016-internal-modules.md +++ b/contributor-docs/adrs/adr-016-internal-modules.md @@ -5,7 +5,7 @@ | Stage | Status | | -------- | ------ | | Approved | ✅ | -| Adopted | 🚧 | +| Adopted | ✅ | ## Context @@ -13,17 +13,17 @@ Currently all files live under the `src` directory. In the `npm` package for `@p ```json5 { - "exports": { + exports: { // ... - "./lib-esm/*": { - "import": [ + './lib-esm/*': { + import: [ // ... ], - "require": [ + require: [ // ... - ] - } - } + ], + }, + }, } ``` @@ -37,10 +37,10 @@ In the `"exports"` field of our `npm` package, we can then add the following pat ```json5 { - "exports": { + exports: { // ... - "./lib-esm/internal/*": null - } + './lib-esm/internal/*': null, + }, } ``` @@ -57,7 +57,6 @@ This pattern would remove any files and folders within `src/internal` from the p } ``` - ### Impact - Update the `"exports"` field in `package.json` to exclude `./lib-esm/internal` from usage diff --git a/generated/components.json b/generated/components.json index cd2307492bd..5b0b4a5f931 100644 --- a/generated/components.json +++ b/generated/components.json @@ -243,6 +243,7 @@ { "name": "direction", "type": "'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'nw'", + "defaultValue": "n", "description": "Sets where the tooltip renders in relation to the target." }, { diff --git a/package.json b/package.json index 9c4f28e2b9f..0f68fa657a0 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "./lib/*.js", "./lib/*/index.js" ] - } + }, + "./lib-esm/internal/*": null }, "typings": "lib/index.d.ts", "sideEffects": false, diff --git a/src/DataTable/Table.tsx b/src/DataTable/Table.tsx index b3857e0721e..bfa899e2be2 100644 --- a/src/DataTable/Table.tsx +++ b/src/DataTable/Table.tsx @@ -11,7 +11,7 @@ import {Column, CellAlignment} from './column' import {UniqueRow} from './row' import {SortDirection} from './sorting' import {useTableLayout} from './useTable' -import {useOverflow} from '../hooks/useOverflow' +import {useOverflow} from '../internal/hooks/useOverflow' // ---------------------------------------------------------------------------- // Table diff --git a/src/PageLayout/PageLayout.tsx b/src/PageLayout/PageLayout.tsx index 13b181e448e..fe50d009a0b 100644 --- a/src/PageLayout/PageLayout.tsx +++ b/src/PageLayout/PageLayout.tsx @@ -8,7 +8,7 @@ import {useSlots} from '../hooks/useSlots' import {BetterSystemStyleObject, merge, SxProp} from '../sx' import {Theme} from '../ThemeProvider' import {canUseDOM} from '../utils/environment' -import {useOverflow} from '../utils/useOverflow' +import {useOverflow} from '../internal/hooks/useOverflow' import {warning} from '../utils/warning' import VisuallyHidden from '../_VisuallyHidden' import {useStickyPaneHeight} from './useStickyPaneHeight' diff --git a/src/hooks/useOverflow.ts b/src/internal/hooks/useOverflow.ts similarity index 100% rename from src/hooks/useOverflow.ts rename to src/internal/hooks/useOverflow.ts diff --git a/src/utils/useOverflow.ts b/src/utils/useOverflow.ts deleted file mode 100644 index c54e00a134d..00000000000 --- a/src/utils/useOverflow.ts +++ /dev/null @@ -1,24 +0,0 @@ -import {useEffect, useState} from 'react' - -export function useOverflow(ref: React.RefObject) { - const [hasOverflow, setHasOverflow] = useState(false) - - useEffect(() => { - if (ref.current === null) return - - const observer = new ResizeObserver(entries => { - for (const entry of entries) { - setHasOverflow( - entry.target.scrollHeight > entry.target.clientHeight || entry.target.scrollWidth > entry.target.clientWidth, - ) - } - }) - - observer.observe(ref.current) - return () => { - observer.disconnect() - } - }, [ref]) - - return hasOverflow -}