Skip to content

Commit

Permalink
Global Styles: Move prototype from G2
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Jul 13, 2021
1 parent dd4ce77 commit 636af05
Show file tree
Hide file tree
Showing 31 changed files with 1,728 additions and 8 deletions.
154 changes: 147 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/components/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export { HStack as __experimentalHStack } from './h-stack';
export { default as Icon } from './icon';
export { default as IconButton } from './button/deprecated';
export { default as __experimentalInputControl } from './input-control';
export { Item, ItemGroup } from './item-group';
export { default as KeyboardShortcuts } from './keyboard-shortcuts';
export { default as MenuGroup } from './menu-group';
export { default as MenuItem } from './menu-item';
Expand Down
7 changes: 7 additions & 0 deletions packages/components/src/item-group/context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* WordPress dependencies
*/
import { createContext, useContext } from '@wordpress/element';

export const ItemGroupContext = createContext( { size: 'medium' } );
export const useItemGroupContext = () => useContext( ItemGroupContext );
2 changes: 2 additions & 0 deletions packages/components/src/item-group/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as Item, useItem } from './item';
export { default as ItemGroup, useItemGroup } from './item-group';
31 changes: 31 additions & 0 deletions packages/components/src/item-group/item-group/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Internal dependencies
*/
import { contextConnect } from '../../ui/context';
import { ItemGroupContext, useItemGroupContext } from '../context';
import { useItemGroup } from './hook';
import { View } from '../../view';

function ItemGroup( props, ref ) {
const { bordered, separated, size: sizeProp, ...otherProps } = useItemGroup(
props
);

const { size: contextSize } = useItemGroupContext();

const spacedAround = ! bordered && ! separated;
const size = sizeProp || contextSize;

const contextValue = {
spacedAround,
size,
};

return (
<ItemGroupContext.Provider value={ contextValue }>
<View { ...otherProps } ref={ ref } />
</ItemGroupContext.Provider>
);
}

export default contextConnect( ItemGroup, 'ItemGroup' );
36 changes: 36 additions & 0 deletions packages/components/src/item-group/item-group/hook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* External dependencies
*/
import { cx } from 'emotion';

/**
* Internal dependencies
*/
import { useContextSystem } from '../../ui/context';
import * as styles from '../styles';

export function useItemGroup( props ) {
const {
bordered = false,
className,
role = 'list',
rounded = true,
separated = false,
...otherProps
} = useContextSystem( props, 'ItemGroup' );

const classes = cx(
bordered && styles.bordered,
( bordered || separated ) && styles.separated,
rounded && styles.rounded,
className
);

return {
bordered,
className: classes,
role,
separated,
...otherProps,
};
}
2 changes: 2 additions & 0 deletions packages/components/src/item-group/item-group/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './component';
export { useItemGroup } from './hook';
11 changes: 11 additions & 0 deletions packages/components/src/item-group/item/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Internal dependencies
*/
import { createComponent } from '../../ui/utils';
import { useItem } from './hook';

export default createComponent( {
useHook: useItem,
as: 'div',
name: 'Item',
} );
Loading

0 comments on commit 636af05

Please sign in to comment.