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

[material-ui][FormControl] Convert to support CSS extraction #41613

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 27 additions & 15 deletions packages/mui-material/src/FormControl/FormControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import composeClasses from '@mui/utils/composeClasses';
import useThemeProps from '../styles/useThemeProps';
import styled from '../styles/styled';
import { styled, createUseThemeProps } from '../zero-styled';
import { isFilled, isAdornedStart } from '../InputBase/utils';
import capitalize from '../utils/capitalize';
import isMuiElement from '../utils/isMuiElement';
import FormControlContext from './FormControlContext';
import { getFormControlUtilityClasses } from './formControlClasses';

const useThemeProps = createUseThemeProps('MuiFormControl');

const useUtilityClasses = (ownerState) => {
const { classes, margin, fullWidth } = ownerState;
const slots = {
Expand All @@ -30,7 +31,7 @@ const FormControlRoot = styled('div', {
...(ownerState.fullWidth && styles.fullWidth),
};
},
})(({ ownerState }) => ({
})({
display: 'inline-flex',
flexDirection: 'column',
position: 'relative',
Expand All @@ -40,18 +41,29 @@ const FormControlRoot = styled('div', {
margin: 0,
border: 0,
verticalAlign: 'top', // Fix alignment issue on Safari.
...(ownerState.margin === 'normal' && {
marginTop: 16,
marginBottom: 8,
}),
...(ownerState.margin === 'dense' && {
marginTop: 8,
marginBottom: 4,
}),
...(ownerState.fullWidth && {
width: '100%',
}),
}));
variants: [
{
props: { margin: 'normal' },
style: {
marginTop: 16,
marginBottom: 8,
},
},
{
props: { margin: 'dense' },
style: {
marginTop: 8,
marginBottom: 4,
},
},
{
props: { fullWidth: true },
style: {
width: '100%',
},
},
],
});

/**
* Provides context such as filled/focused/error/required for form inputs.
Expand Down
48 changes: 32 additions & 16 deletions packages/mui-material/src/FormControlLabel/FormControlLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import clsx from 'clsx';
import refType from '@mui/utils/refType';
import composeClasses from '@mui/utils/composeClasses';
import { useFormControl } from '../FormControl';
import { styled, createUseThemeProps } from '../zero-styled';
import Stack from '../Stack';
import Typography from '../Typography';
import capitalize from '../utils/capitalize';
import styled from '../styles/styled';
import useThemeProps from '../styles/useThemeProps';
import formControlLabelClasses, {
getFormControlLabelUtilityClasses,
} from './formControlLabelClasses';
import formControlState from '../FormControl/formControlState';

const useThemeProps = createUseThemeProps('MuiFormControlLabel');

const useUtilityClasses = (ownerState) => {
const { classes, disabled, labelPlacement, error, required } = ownerState;
const slots = {
Expand Down Expand Up @@ -44,7 +45,7 @@ export const FormControlLabelRoot = styled('label', {
styles[`labelPlacement${capitalize(ownerState.labelPlacement)}`],
];
},
})(({ theme, ownerState }) => ({
})(({ theme }) => ({
display: 'inline-flex',
alignItems: 'center',
cursor: 'pointer',
Expand All @@ -56,24 +57,39 @@ export const FormControlLabelRoot = styled('label', {
[`&.${formControlLabelClasses.disabled}`]: {
cursor: 'default',
},
...(ownerState.labelPlacement === 'start' && {
flexDirection: 'row-reverse',
marginLeft: 16, // used for row presentation of radio/checkbox
marginRight: -11,
}),
...(ownerState.labelPlacement === 'top' && {
flexDirection: 'column-reverse',
marginLeft: 16,
}),
...(ownerState.labelPlacement === 'bottom' && {
flexDirection: 'column',
marginLeft: 16,
}),
[`& .${formControlLabelClasses.label}`]: {
[`&.${formControlLabelClasses.disabled}`]: {
color: (theme.vars || theme).palette.text.disabled,
},
},
variants: [
{
props: { labelPlacement: 'start' },
style: {
flexDirection: 'row-reverse',
marginRight: -11,
},
},
{
props: { labelPlacement: 'top' },
style: {
flexDirection: 'column-reverse',
},
},
{
props: { labelPlacement: 'bottom' },
style: {
flexDirection: 'column',
},
},
{
props: ({ labelPlacement }) =>
labelPlacement === 'start' || labelPlacement === 'top' || labelPlacement === 'bottom',
style: {
marginLeft: 16, // used for row presentation of radio/checkbox
},
},
],
}));

const AsteriskComponent = styled('span', {
Expand Down
Loading