Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pickers] Migrate PickersToolbarButton to emotion #25989

Merged
merged 24 commits into from
May 10, 2021
Merged
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
28dd1ac
migrate to emotion
siriwatknp Apr 26, 2021
b6bd7b4
run prettier
siriwatknp Apr 26, 2021
6331a25
Merge branch 'next' into pickers-toolbar-button-emotion
siriwatknp Apr 28, 2021
ceb4b76
add sx props
siriwatknp Apr 29, 2021
29755fe
Merge branch 'pickers-toolbar-button-emotion' of github.com:siriwatkn…
siriwatknp Apr 29, 2021
99cc435
remove TODO and fix ts error
siriwatknp Apr 29, 2021
546aa39
move classes to component file
siriwatknp Apr 29, 2021
74fb48e
Update packages/material-ui-lab/src/internal/pickers/PickersToolbarBu…
mnajdova Apr 29, 2021
2b01c78
Update packages/material-ui-lab/src/internal/pickers/PickersToolbarBu…
mnajdova Apr 29, 2021
e6cfdde
use generic
siriwatknp Apr 30, 2021
3044613
moved classes declaration before it's used
mnajdova Apr 30, 2021
1512211
sort asc
oliviertassinari May 2, 2021
5808511
remove unit per convention
oliviertassinari May 2, 2021
d81ad06
component name should match filename
oliviertassinari May 2, 2021
93f34e6
simplify
mnajdova May 3, 2021
8a39015
Update packages/material-ui-lab/src/internal/pickers/PickersToolbarBu…
mnajdova May 3, 2021
c1a5de6
Let's keep it minimal
eps1lon May 4, 2021
1967a29
Merge branch 'next' into pickers-toolbar-button-emotion
eps1lon May 4, 2021
d8eff0f
ToolbarButtonProps -> PickersToolbarButton
eps1lon May 4, 2021
2365534
Strip out customization
eps1lon May 4, 2021
8da9524
Merge branch 'next' into pickers-toolbar-button-emotion
eps1lon May 5, 2021
fd34778
Update packages/material-ui-lab/src/internal/pickers/PickersToolbarBu…
mnajdova May 7, 2021
3c96a51
Update packages/material-ui-lab/src/internal/pickers/PickersToolbarBu…
mnajdova May 10, 2021
7af8843
prettier
mnajdova May 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 75 additions & 40 deletions packages/material-ui-lab/src/internal/pickers/PickersToolbarButton.tsx
Original file line number Diff line number Diff line change
@@ -1,59 +1,94 @@
import * as React from 'react';
import clsx from 'clsx';
import Button, { ButtonProps } from '@material-ui/core/Button';
import { MuiStyles, WithStyles, withStyles } from '@material-ui/core/styles';
import { SxProps } from '@material-ui/system';
import {
experimentalStyled,
unstable_useThemeProps as useThemeProps,
Theme,
} from '@material-ui/core/styles';
import {
unstable_composeClasses as composeClasses,
generateUtilityClass,
generateUtilityClasses,
} from '@material-ui/unstyled';
import { TypographyProps } from '@material-ui/core/Typography';
import PickersToolbarText from './PickersToolbarText';
import { ExtendMui } from './typings/helpers';

export const pickersToolbarButtonClasses = generateUtilityClasses('MuiPickersToolbarButton', [
'root',
]);

export interface ToolbarButtonProps extends ExtendMui<ButtonProps, 'value' | 'variant'> {
align?: TypographyProps['align'];
classes?: typeof pickersToolbarButtonClasses;
selected: boolean;
typographyClassName?: string;
value: React.ReactNode;
variant: TypographyProps['variant'];
sx?: SxProps<Theme>;
}

export type PickersToolbarButtonClassKey = 'root';
export type PickersToolbarButtonClassKey = keyof typeof pickersToolbarButtonClasses;
mnajdova marked this conversation as resolved.
Show resolved Hide resolved

export const styles: MuiStyles<PickersToolbarButtonClassKey> = {
root: {
padding: 0,
minWidth: '16px',
textTransform: 'none',
},
};
export function getPickersToolbarButtonUtilityClass(slot: string) {
return generateUtilityClass('MuiPickersToolbarButton', slot);
}

const useUtilityClasses = (styleProps: ToolbarButtonProps) => {
const { classes } = styleProps;

const slots = {
root: ['root'],
};

const ToolbarButton: React.FunctionComponent<ToolbarButtonProps & WithStyles<typeof styles>> = (
props,
) => {
const {
align,
classes,
className,
selected,
typographyClassName,
value,
variant,
...other
} = props;

return (
<Button
data-mui-test="toolbar-button"
variant="text"
className={clsx(classes.root, className)}
{...other}
>
<PickersToolbarText
align={align}
className={typographyClassName}
variant={variant}
value={value}
selected={selected}
/>
</Button>
);
return composeClasses(slots, getPickersToolbarButtonUtilityClass, classes);
};

export default withStyles(styles, { name: 'MuiPickersToolbarButton' })(ToolbarButton);
const PickersToolbarButtonRoot = experimentalStyled(
Button,
{},
{
name: 'MuiPickersToolbarButton',
slot: 'Root',
overridesResolver: (props, styles: Record<PickersToolbarButtonClassKey, object>) => styles.root,
},
)({
padding: 0,
minWidth: '16px',
textTransform: 'none',
});

const ToolbarButton: React.FunctionComponent<ToolbarButtonProps> = React.forwardRef(
function PickersToolbarButton(inProps, ref) {
const props = useThemeProps<Theme, ToolbarButtonProps, 'MuiPickersToolbarButton'>({
props: inProps,
name: 'MuiPickersToolbarButton',
});
const { align, className, selected, typographyClassName, value, variant, ...other } = props;
const styleProps = { ...props };
const classes = useUtilityClasses(styleProps);

return (
<PickersToolbarButtonRoot
data-mui-test="toolbar-button"
variant="text"
ref={ref}
className={clsx(classes.root, className)}
styleProps={styleProps}
{...other}
>
<PickersToolbarText
align={align}
className={typographyClassName}
variant={variant}
value={value}
selected={selected}
/>
</PickersToolbarButtonRoot>
);
},
);

export default ToolbarButton;