Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrollable: refactor away from the createComponent function #34922

Merged
merged 1 commit into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/components/src/scrollable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This feature is still experimental. “Experimental” means this is an early im
## Usage

```jsx
import {__experimentalScrollable as Scrollable } from '@wordpress/components/ui';
import {__experimentalScrollable as Scrollable } from '@wordpress/components';

function Example() {
return (
Expand Down
23 changes: 15 additions & 8 deletions packages/components/src/scrollable/component.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
/**
* Internal dependencies
*/
import { createComponent } from '../ui/utils';
import { contextConnect } from '../ui/context';
import { View } from '../view';
import { useScrollable } from './hook';

/**
* @param {import('../ui/context').WordPressComponentProps<import('./types').Props, 'div'>} props
* @param {import('react').Ref<any>} forwardedRef
*/
function Scrollable( props, forwardedRef ) {
const scrollableProps = useScrollable( props );

return <View { ...scrollableProps } ref={ forwardedRef } />;
}

/**
* `Scrollable` is a layout component that content in a scrollable container.
*
* @example
* ```jsx
* import { __experimentalScrollable as Scrollable } from `@wordpress/components/ui`;
* import { __experimentalScrollable as Scrollable } from `@wordpress/components`;
*
* function Example() {
* return (
Expand All @@ -21,10 +32,6 @@ import { useScrollable } from './hook';
* ```
*/

const Scrollable = createComponent( {
as: 'div',
useHook: useScrollable,
name: 'Scrollable',
} );
const ConnectedScrollable = contextConnect( Scrollable, 'Scrollable' );

export default Scrollable;
export default ConnectedScrollable;