-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: automatically import and define Calcite Components when importi…
…ng their React wrapper (#7185) **Related Issue:** #6601 ## Summary Automatically imports and defines Calcite Components when importing the React wrappers. For example, here is a snippet from our React sample: ```jsx import '@esri/calcite-components/dist/components/calcite-button'; import '@esri/calcite-components/dist/components/calcite-icon'; import '@esri/calcite-components/dist/components/calcite-slider'; import { CalciteButton, CalciteIcon, CalciteSlider } from '@esri/calcite-components-react'; ``` The above snippet can now be simplified to the following: ```jsx import { CalciteButton, CalciteIcon, CalciteSlider } from '@esri/calcite-components-react'; ``` ### Note I had to patch the build because Stencil was generating an incorrect import path to the JSX type. I tested in our old output targets repo and it reproduced there as well, so this isn't related to the monorepo change.
- Loading branch information
Showing
6 changed files
with
39 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/calcite-components-react/support/patchImportPathJSX.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// patch needed due to Stencil creating the wrong import path to the JSX type | ||
(async function () { | ||
const { | ||
promises: { readFile, writeFile } | ||
} = await import("fs"); | ||
const { resolve } = await import("path"); | ||
|
||
try { | ||
const filePath = resolve(__dirname, "..", "src", "components.ts"); | ||
const contents = await readFile(filePath, { encoding: "utf8" }); | ||
await writeFile( | ||
filePath, | ||
contents.replace( | ||
"import type { JSX } from '@esri/calcite-components/dist/components'", | ||
"import type { JSX } from '@esri/calcite-components'" | ||
) | ||
); | ||
} catch (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters