2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt odlux
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
19 import * as React from 'react';
\r
20 import classNames from 'classnames';
\r
21 import { withStyles, WithStyles, Theme, createStyles } from '@material-ui/core/styles';
\r
22 import { fade } from '@material-ui/core/styles/colorManipulator';
\r
23 import ButtonBase from '@material-ui/core/ButtonBase';
\r
26 export const styles = (theme: Theme) => createStyles({
\r
27 /* Styles applied to the root element. */
\r
29 ...theme.typography.button,
\r
33 padding: `${theme.spacing.unit - 4}px ${theme.spacing.unit * 1.5}px`,
\r
35 willChange: 'opacity',
\r
36 color: fade(theme.palette.action.active, 0.38),
\r
38 textDecoration: 'none',
\r
39 // Reset on mouse devices
\r
40 backgroundColor: fade(theme.palette.text.primary, 0.12),
\r
41 '@media (hover: none)': {
\r
42 backgroundColor: 'transparent',
\r
45 backgroundColor: 'transparent',
\r
48 '&:not(:first-child)': {
\r
49 borderTopLeftRadius: 0,
\r
50 borderBottomLeftRadius: 0,
\r
52 '&:not(:last-child)': {
\r
53 borderTopRightRadius: 0,
\r
54 borderBottomRightRadius: 0,
\r
57 /* Styles applied to the root element if `disabled={true}`. */
\r
59 color: fade(theme.palette.action.disabled, 0.12),
\r
61 /* Styles applied to the root element if `selected={true}`. */
\r
63 color: theme.palette.action.active,
\r
67 position: 'absolute',
\r
69 borderRadius: 'inherit',
\r
74 pointerEvents: 'none',
\r
76 backgroundColor: 'currentColor',
\r
82 position: 'absolute',
\r
88 pointerEvents: 'none',
\r
90 backgroundColor: 'currentColor',
\r
94 /* Styles applied to the `label` wrapper element. */
\r
98 alignItems: 'inherit',
\r
99 justifyContent: 'inherit',
\r
103 export type ToggleButtonClassKey = 'disabled' | 'root' | 'label' | 'selected';
\r
105 interface IToggleButtonProps extends WithStyles<typeof styles> {
\r
106 className?: string;
\r
107 component?: React.ReactType<IToggleButtonProps>;
\r
108 disabled?: boolean;
\r
109 disableFocusRipple?: boolean;
\r
110 disableRipple?: boolean;
\r
111 selected?: boolean;
\r
114 onClick?: (event: React.FormEvent<HTMLElement>, value?: any) => void;
\r
115 onChange?: (event: React.FormEvent<HTMLElement>, value?: any) => void;
\r
118 class ToggleButtonComponent extends React.Component<IToggleButtonProps> {
\r
119 handleChange = (event: React.FormEvent<HTMLElement>) => {
\r
120 const { onChange, onClick, value } = this.props;
\r
123 onClick(event, value);
\r
124 if (event.isDefaultPrevented()) {
\r
130 onChange(event, value);
\r
137 className: classNameProp,
\r
139 disableFocusRipple,
\r
145 const className = classNames(
\r
148 [classes.disabled]: disabled,
\r
149 [classes.selected]: selected,
\r
156 className={className}
\r
157 disabled={disabled}
\r
158 focusRipple={!disableFocusRipple}
\r
159 onClick={this.handleChange}
\r
162 <span className={classes.label}>{children}</span>
\r
166 public static defaultProps = {
\r
168 disableFocusRipple: false,
\r
169 disableRipple: false,
\r
172 public static muiName = 'ToggleButton';
\r
175 export const ToggleButton = withStyles(styles, { name: 'MuiToggleButton' })(ToggleButtonComponent);
\r
176 export default ToggleButton;