Skip to content

Commit

Permalink
[material-next][ButtonGroup] Copy ButtonGroup to material next (#39739
Browse files Browse the repository at this point in the history
)

Signed-off-by: Lucas Hilgert <[email protected]>
Co-authored-by: Albert Yu <[email protected]>
  • Loading branch information
lhilgert9 and mj12albert authored Nov 7, 2023
1 parent a545acd commit 6bc9bab
Show file tree
Hide file tree
Showing 9 changed files with 940 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/mui-material-next/src/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
'use client';
import * as React from 'react';
import PropTypes from 'prop-types';
import { unstable_capitalize as capitalize } from '@mui/utils';
import clsx from 'clsx';
import {
unstable_capitalize as capitalize,
internal_resolveProps as resolveProps,
} from '@mui/utils';
import { useSlotProps } from '@mui/base/utils';
import { unstable_composeClasses as composeClasses } from '@mui/base/composeClasses';
import { useThemeProps, alpha, shouldForwardProp } from '@mui/system';
Expand All @@ -10,6 +14,8 @@ import { getButtonUtilityClass } from './buttonClasses';
import buttonBaseClasses from '../ButtonBase/buttonBaseClasses';
import { ButtonProps, ExtendButton, ButtonTypeMap, ButtonOwnerState } from './Button.types';
import ButtonBase from '../ButtonBase';
import ButtonGroupButtonContext from '../ButtonGroup/ButtonGroupButtonContext';
import ButtonGroupContext from '../ButtonGroup/ButtonGroupContext';

const useUtilityClasses = (ownerState: ButtonOwnerState) => {
const { classes, color, disableElevation, fullWidth, size, variant } = ownerState;
Expand Down Expand Up @@ -366,7 +372,10 @@ const ButtonEndIcon = styled('span', {
const Button = React.forwardRef(function Button<
BaseComponentType extends React.ElementType = ButtonTypeMap['defaultComponent'],
>(inProps: ButtonProps<BaseComponentType>, ref: React.ForwardedRef<any>) {
const props = useThemeProps({ props: inProps, name: 'MuiButton' });
const contextProps = React.useContext(ButtonGroupContext);
const buttonGroupButtonContextPositionClassName = React.useContext(ButtonGroupButtonContext);
const resolvedProps = resolveProps(contextProps as ButtonProps<BaseComponentType>, inProps);
const props = useThemeProps({ props: resolvedProps, name: 'MuiButton' });
const {
children,
classes: classesProp,
Expand All @@ -392,6 +401,8 @@ const Button = React.forwardRef(function Button<

const classes = useUtilityClasses(ownerState);

const positionClassName = buttonGroupButtonContextPositionClassName ?? '';

const rootProps = useSlotProps({
elementType: ButtonRoot,
externalForwardedProps: other,
Expand All @@ -401,6 +412,7 @@ const Button = React.forwardRef(function Button<
ref,
},
ownerState,
className: clsx(contextProps.className, positionClassName),
});

const startIcon = startIconProp && (
Expand Down
107 changes: 107 additions & 0 deletions packages/mui-material-next/src/ButtonGroup/ButtonGroup.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import * as React from 'react';
import { SxProps } from '@mui/system';
import { OverridableComponent, OverridableStringUnion, OverrideProps } from '@mui/types';
import { Theme } from '../styles';
import { ButtonGroupClasses } from './buttonGroupClasses';

export interface ButtonGroupPropsColorOverrides {}
export interface ButtonGroupPropsVariantOverrides {}
export interface ButtonGroupPropsSizeOverrides {}

export interface ButtonGroupOwnProps {
/**
* The content of the component.
*/
children?: React.ReactNode;
/**
* Override or extend the styles applied to the component.
*/
classes?: Partial<ButtonGroupClasses>;
/**
* The color of the component.
* It supports both default and custom theme colors, which can be added as shown in the
* [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
* @default 'primary'
*/
color?: OverridableStringUnion<
'inherit' | 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning',
ButtonGroupPropsColorOverrides
>;
/**
* If `true`, the component is disabled.
* @default false
*/
disabled?: boolean;
/**
* If `true`, no elevation is used.
* @default false
*/
disableElevation?: boolean;
/**
* If `true`, the button ripple effect is disabled.
* @default false
*/
disableRipple?: boolean;
/**
* If `true`, the touch ripple effect is disabled.
* @default false
*/
disableTouchRipple?: boolean;
/**
* If `true`, the buttons will take up the full width of its container.
* @default false
*/
fullWidth?: boolean;
/**
* The component orientation (layout flow direction).
* @default 'horizontal'
*/
orientation?: 'vertical' | 'horizontal';
/**
* The size of the component.
* `small` is equivalent to the dense button styling.
* @default 'medium'
*/
size?: OverridableStringUnion<'small' | 'medium' | 'large', ButtonGroupPropsSizeOverrides>;
/**
* The variant to use.
* @default 'outlined'
*/
variant?: OverridableStringUnion<
'text' | 'outlined' | 'contained',
ButtonGroupPropsVariantOverrides
>;
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx?: SxProps<Theme>;
}

export interface ButtonGroupTypeMap<
AdditionalProps = {},
RootComponent extends React.ElementType = 'div',
> {
props: AdditionalProps & ButtonGroupOwnProps;
defaultComponent: RootComponent;
}

/**
*
* Demos:
*
* - [Button Group](https://mui.com/material-ui/react-button-group/)
*
* API:
*
* - [ButtonGroup API](https://mui.com/material-ui/api/button-group/)
*/
declare const ButtonGroup: OverridableComponent<ButtonGroupTypeMap>;

export type ButtonGroupProps<
RootComponent extends React.ElementType = ButtonGroupTypeMap['defaultComponent'],
AdditionalProps = {},
> = OverrideProps<ButtonGroupTypeMap<AdditionalProps, RootComponent>, RootComponent> & {
component?: React.ElementType;
};

export default ButtonGroup;
Loading

0 comments on commit 6bc9bab

Please sign in to comment.