UNPKG

2.17 kBTypeScriptView Raw
1/*
2 * Copyright 2015 Palantir Technologies, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import classNames from "classnames";
18import * as React from "react";
19import { polyfill } from "react-lifecycles-compat";
20
21import { AbstractPureComponent2, Classes, IRef } from "../../common";
22import { DISPLAYNAME_PREFIX, Props } from "../../common/props";
23import { MenuDivider } from "./menuDivider";
24// this cyclic import can be removed in v4.0 (https://github.com/palantir/blueprint/issues/3829)
25// eslint-disable-next-line import/no-cycle
26import { MenuItem } from "./menuItem";
27
28// eslint-disable-next-line deprecation/deprecation
29export type MenuProps = IMenuProps;
30/** @deprecated use MenuProps */
31export interface IMenuProps extends Props, React.HTMLAttributes<HTMLUListElement> {
32 /** Whether the menu items in this menu should use a large appearance. */
33 large?: boolean;
34
35 /** Ref handler that receives the HTML `<ul>` element backing this component. */
36 ulRef?: IRef<HTMLUListElement>;
37}
38
39@polyfill
40export class Menu extends AbstractPureComponent2<MenuProps> {
41 public static displayName = `${DISPLAYNAME_PREFIX}.Menu`;
42
43 /** @deprecated use MenuDivider */
44 public static Divider = MenuDivider;
45
46 /** @deprecated use MenuItem*/
47 public static Item = MenuItem;
48
49 public render() {
50 const { className, children, large, ulRef, ...htmlProps } = this.props;
51 const classes = classNames(Classes.MENU, { [Classes.LARGE]: large }, className);
52 return (
53 <ul {...htmlProps} className={classes} ref={ulRef}>
54 {children}
55 </ul>
56 );
57 }
58}