Skip to content

Commit

Permalink
Scrollable: refactor away from the createComponent function (#34922)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo authored Sep 20, 2021
1 parent b858660 commit 0915035
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
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;

0 comments on commit 0915035

Please sign in to comment.