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

Components: Add Menu #29645

Closed
wants to merge 8 commits into from
Closed
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
58 changes: 29 additions & 29 deletions package-lock.json

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

10 changes: 5 additions & 5 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
"@wordpress/primitives": "file:../primitives",
"@wordpress/rich-text": "file:../rich-text",
"@wordpress/warning": "file:../warning",
"@wp-g2/components": "^0.0.160",
"@wp-g2/context": "^0.0.160",
"@wp-g2/styles": "^0.0.160",
"@wp-g2/utils": "^0.0.160",
"@wp-g2/components": "^0.0.162",
"@wp-g2/context": "^0.0.162",
"@wp-g2/styles": "^0.0.162",
"@wp-g2/utils": "^0.0.162",
"classnames": "^2.2.5",
"dom-scroll-into-view": "^1.2.1",
"downshift": "^6.0.15",
Expand All @@ -62,7 +62,7 @@
"react-resize-aware": "^3.1.0",
"react-spring": "^8.0.20",
"react-use-gesture": "^9.0.0",
"reakit": "^1.3.5",
"reakit": "1.3.5",
"rememo": "^3.0.0",
"tinycolor2": "^1.4.2",
"uuid": "^8.3.0"
Expand Down
61 changes: 61 additions & 0 deletions packages/components/src/ui/menu/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* External dependencies
*/
import { contextConnect, useContextSystem } from '@wp-g2/context';
import { cx } from '@wp-g2/styles';

/**
* Internal dependencies
*/
import { View } from '../view';
import * as styles from './styles';

/**
* `Menu` is an actionable component that displays a list of actions, links, or informative content.
*
* @example
* ```jsx
* <Menu>
* <MenuItem>...</MenuItem>
* <MenuItem>...</MenuItem>
* <MenuItem>...</MenuItem>
* </Menu>
* ```
*
* @see https://reakit.io/docs/menu/#menu
*
* @param {import('@wp-g2/create-styles').ViewOwnProps<import('./types').Props, 'div'>} props
* @param {import('react').Ref<any>} forwardedRef
*/
function Menu( props, forwardedRef ) {
const { children, className, ...otherProps } = useContextSystem(
props,
'Menu'
);

const classes = cx( styles.Menu, className );

return (
<View { ...otherProps } className={ classes } ref={ forwardedRef }>
{ children }
</View>
);
}

/**
* `Menu` is an actionable component that displays a list of actions, links, or informative content.
*
* @example
* ```jsx
* <Menu>
* <MenuItem>...</MenuItem>
* <MenuItem>...</MenuItem>
* <MenuItem>...</MenuItem>
* </Menu>
* ```
*
* @see https://reakit.io/docs/menu/#menu
*/
const ConnectedMenu = contextConnect( Menu, 'Menu' );

export default ConnectedMenu;
8 changes: 8 additions & 0 deletions packages/components/src/ui/menu/context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* WordPress dependencies
*/
import { createContext, useContext } from '@wordpress/element';

/** @type {import('react').Context<{ menu?: import('reakit').MenuStateReturn }>} */
export const MenuContext = createContext( {} );
export const useMenuContext = () => useContext( MenuContext );
54 changes: 54 additions & 0 deletions packages/components/src/ui/menu/header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* External dependencies
*/
import { contextConnect, useContextSystem } from '@wp-g2/context';
import { cx } from '@wp-g2/styles';
import { pick } from 'lodash';

/**
* Internal dependencies
*/
import * as baseButtonStyles from '../base-button/styles';
import { Heading } from '../heading';
import * as styles from './styles';

const sizeStyles = pick( baseButtonStyles, [ 'large', 'small', 'xSmall' ] );

/**
* @typedef OwnProps
* @property {keyof sizeStyles} size Size of the menu header.
*/

/**
* @typedef {import('../heading').HeadingProps & OwnProps} Props
*/

/**
*
* @param {import('@wp-g2/create-styles').ViewOwnProps<Props, 'div'>} props
* @param {import('react').Ref<any>} forwardedRef
*/
function MenuHeader( props, forwardedRef ) {
const {
children,
className,
size,
level = 5,
...otherProps
} = useContextSystem( props, 'MenuHeader' );

const classes = cx( styles.MenuHeader, sizeStyles[ size ], className );

return (
<Heading
level={ level }
{ ...otherProps }
className={ classes }
ref={ forwardedRef }
>
{ children }
</Heading>
);
}

export default contextConnect( MenuHeader, 'MenuHeader' );
5 changes: 5 additions & 0 deletions packages/components/src/ui/menu/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export { default as Menu } from './component';
export { default as MenuHeader } from './header';
export { default as MenuItem } from './item';

export * from './context';
Loading