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';
20 import classNames from 'classnames';
21 import { Theme, alpha } from '@mui/material/styles';
22 import { WithStyles } from '@mui/styles';
23 import withStyles from '@mui/styles/withStyles';
24 import createStyles from '@mui/styles/createStyles';
25 import ButtonBase from '@mui/material/ButtonBase';
28 export const styles = (theme: Theme) => createStyles({
29 /* Styles applied to the root element. */
31 ...theme.typography.button,
35 padding: `${theme.spacing(1 - 4)} ${theme.spacing(1.5)}`,
37 willChange: 'opacity',
38 color: alpha(theme.palette.action.active, 0.38),
40 textDecoration: 'none',
41 // Reset on mouse devices
42 backgroundColor: alpha(theme.palette.text.primary, 0.12),
43 '@media (hover: none)': {
44 backgroundColor: 'transparent',
47 backgroundColor: 'transparent',
50 '&:not(:first-child)': {
51 borderTopLeftRadius: 0,
52 borderBottomLeftRadius: 0,
54 '&:not(:last-child)': {
55 borderTopRightRadius: 0,
56 borderBottomRightRadius: 0,
59 /* Styles applied to the root element if `disabled={true}`. */
61 color: alpha(theme.palette.action.disabled, 0.12),
63 /* Styles applied to the root element if `selected={true}`. */
65 color: theme.palette.action.active,
71 borderRadius: 'inherit',
76 pointerEvents: 'none',
78 backgroundColor: 'currentColor',
90 pointerEvents: 'none',
92 backgroundColor: 'currentColor',
96 /* Styles applied to the `label` wrapper element. */
100 alignItems: 'inherit',
101 justifyContent: 'inherit',
105 export type ToggleButtonClassKey = 'disabled' | 'root' | 'label' | 'selected';
107 interface IToggleButtonProps extends WithStyles<typeof styles> {
109 component?: React.ReactType<IToggleButtonProps>;
111 disableFocusRipple?: boolean;
112 disableRipple?: boolean;
116 onClick?: (event: React.FormEvent<HTMLElement>, value?: any) => void;
117 onChange?: (event: React.FormEvent<HTMLElement>, value?: any) => void;
120 class ToggleButtonComponent extends React.Component<IToggleButtonProps> {
121 handleChange = (event: React.FormEvent<HTMLElement>) => {
122 const { onChange, onClick, value } = this.props;
124 event.stopPropagation();
126 onClick(event, value);
127 if (event.isDefaultPrevented()) {
133 onChange(event, value);
135 event.preventDefault();
141 className: classNameProp,
149 const className = classNames(
152 [classes.disabled]: disabled,
153 [classes.selected]: selected,
160 className={className}
162 focusRipple={!disableFocusRipple}
163 onClick={this.handleChange}
167 <span className={classes.label}>{children}</span>
171 public static defaultProps = {
173 disableFocusRipple: false,
174 disableRipple: false,
177 public static muiName = 'ToggleButton';
180 export const ToggleButton = withStyles(styles, { name: 'MuiToggleButton' })(ToggleButtonComponent);
181 export default ToggleButton;