Repository navigation
ResponsiveWrapper: Convert to TypeScript - #46480
Conversation
|
Size Change: +27 B (0%) Total Size: 1.32 MB
ℹ️ View Unchanged
|
| const imageStyle = { | ||
| paddingBottom: | ||
| naturalWidth < containerWidth | ||
| naturalWidth < ( containerWidth ?? 0 ) |
There was a problem hiding this comment.
TS was not happy because containerWidth can potentially be null. (Apparently useResizeObserver() will return null for this value until after the first render.)
My code change here just makes explicit what was happening implicitly — a null will be interpreted as 0 when compared with the < operator. This maintains the current behavior while assuring TS that it's ok.
There was a problem hiding this comment.
Excellent explanation, saved a bunch of time on my end and will make it clear for anyone looking into the reasons behind this code change. Thank you!
| const imageStyle = { | ||
| paddingBottom: | ||
| naturalWidth < containerWidth | ||
| naturalWidth < ( containerWidth ?? 0 ) |
There was a problem hiding this comment.
Excellent explanation, saved a bunch of time on my end and will make it clear for anyone looking into the reasons behind this code change. Thank you!
| /** | ||
| * The element to wrap. | ||
| */ | ||
| children: React.ReactElement; |
There was a problem hiding this comment.
The choice of ReactElement seems correct. We can also broaden the type if necessary.
| */ | ||
| import ResponsiveWrapper from '..'; | ||
|
|
||
| const meta: ComponentMeta< typeof ResponsiveWrapper > = { |
There was a problem hiding this comment.
Should we hide children's control? It currently shows a react object, which is not really user-friendly to edit
| - `useBaseField`: Convert to TypeScript ([#45712](https://github.com/WordPress/gutenberg/pull/45712)). | ||
| - `Dashicon`: Convert to TypeScript ([#45924](https://github.com/WordPress/gutenberg/pull/45924)). | ||
| - `PaletteEdit`: add follow up changelog for #45681 and tests [#46095](https://github.com/WordPress/gutenberg/pull/46095). | ||
| - `ResponsiveWrapper`: Convert to TypeScript ([#46480](https://github.com/WordPress/gutenberg/pull/46480)). |
There was a problem hiding this comment.
May need repositioning after the last package release
|
Flaky tests detected in a70bf32. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3858579356
|
Part of #35744
What?
Add TypeScript types and documentation to the
ResponsiveWrappercomponent.Why?
So we can ship TS data with the wp-components package.
Testing Instructions
npm run storybook:devResponsiveWrappershould look good, and the prop descriptions should match the README.md.