1 | /*
|
2 | * Copyright 2017 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 |
|
17 | import classNames from "classnames";
|
18 | import * as React from "react";
|
19 | import { polyfill } from "react-lifecycles-compat";
|
20 |
|
21 | import { AbstractPureComponent2, Alignment, Classes } from "../../common";
|
22 | import { DISPLAYNAME_PREFIX, HTMLDivProps, Props } from "../../common/props";
|
23 |
|
24 | // eslint-disable-next-line deprecation/deprecation
|
25 | export type ButtonGroupProps = IButtonGroupProps;
|
26 | /** @deprecated use ButtonGroupProps */
|
27 | export interface IButtonGroupProps extends Props, HTMLDivProps {
|
28 | /**
|
29 | * Text alignment within button. By default, icons and text will be centered
|
30 | * within the button. Passing `"left"` or `"right"` will align the button
|
31 | * text to that side and push `icon` and `rightIcon` to either edge. Passing
|
32 | * `"center"` will center the text and icons together.
|
33 | */
|
34 | alignText?: Alignment;
|
35 |
|
36 | /**
|
37 | * Whether the button group should take up the full width of its container.
|
38 | *
|
39 | * @default false
|
40 | */
|
41 | fill?: boolean;
|
42 |
|
43 | /**
|
44 | * Whether the child buttons should appear with minimal styling.
|
45 | *
|
46 | * @default false
|
47 | */
|
48 | minimal?: boolean;
|
49 |
|
50 | /**
|
51 | * Whether the child buttons should appear with large styling.
|
52 | *
|
53 | * @default false
|
54 | */
|
55 | large?: boolean;
|
56 |
|
57 | /**
|
58 | * Whether the button group should appear with vertical styling.
|
59 | *
|
60 | * @default false
|
61 | */
|
62 | vertical?: boolean;
|
63 | }
|
64 |
|
65 | // this component is simple enough that tests would be purely tautological.
|
66 | /* istanbul ignore next */
|
67 |
|
68 | export class ButtonGroup extends AbstractPureComponent2<ButtonGroupProps> {
|
69 | public static displayName = `${DISPLAYNAME_PREFIX}.ButtonGroup`;
|
70 |
|
71 | public render() {
|
72 | const { alignText, className, fill, minimal, large, vertical, ...htmlProps } = this.props;
|
73 | const buttonGroupClasses = classNames(
|
74 | Classes.BUTTON_GROUP,
|
75 | {
|
76 | [Classes.FILL]: fill,
|
77 | [Classes.LARGE]: large,
|
78 | [Classes.MINIMAL]: minimal,
|
79 | [Classes.VERTICAL]: vertical,
|
80 | },
|
81 | Classes.alignmentClass(alignText),
|
82 | className,
|
83 | );
|
84 | return (
|
85 | <div {...htmlProps} className={buttonGroupClasses}>
|
86 | {this.props.children}
|
87 | </div>
|
88 | );
|
89 | }
|
90 | }
|