-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
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
[SwitchBase] Replace IconButton with ButtonBase #26460
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b5ce5ba
replace IconButton with ButtonBase in internal SwitchBase
siriwatknp ba67912
run proptype and docs:api
siriwatknp eb2a388
add breaking change docs
siriwatknp 39274e2
add edge to SwitchBase
siriwatknp 5aa1703
add diff to breaking change docs and focus ripple
siriwatknp a3175f4
fix propTypes and run prettier
siriwatknp 2e24ad2
Update docs/src/pages/guides/migration-v4/migration-v4.md
mnajdova 6e84694
Update docs/src/pages/guides/migration-v4/migration-v4.md
mnajdova 916f702
Update docs/src/pages/guides/migration-v4/migration-v4.md
mnajdova File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,27 +3,37 @@ import PropTypes from 'prop-types'; | |
import clsx from 'clsx'; | ||
import { refType } from '@material-ui/utils'; | ||
import { unstable_composeClasses as composeClasses } from '@material-ui/unstyled'; | ||
import capitalize from '../utils/capitalize'; | ||
import experimentalStyled from '../styles/experimentalStyled'; | ||
import useControlled from '../utils/useControlled'; | ||
import useFormControl from '../FormControl/useFormControl'; | ||
import IconButton from '../IconButton'; | ||
import ButtonBase from '../ButtonBase'; | ||
import { getSwitchBaseUtilityClass } from './switchBaseClasses'; | ||
|
||
const useUtilityClasses = (styleProps) => { | ||
const { classes, checked, disabled } = styleProps; | ||
const { classes, checked, disabled, edge } = styleProps; | ||
|
||
const slots = { | ||
root: ['root', checked && 'checked', disabled && 'disabled'], | ||
root: ['root', checked && 'checked', disabled && 'disabled', edge && `edge${capitalize(edge)}`], | ||
input: ['input'], | ||
}; | ||
|
||
return composeClasses(slots, getSwitchBaseUtilityClass, classes); | ||
}; | ||
|
||
const SwitchBaseRoot = experimentalStyled(IconButton, { skipSx: true })({ | ||
const SwitchBaseRoot = experimentalStyled(ButtonBase, { skipSx: true })(({ styleProps }) => ({ | ||
/* Styles applied to the root element. */ | ||
padding: 9, | ||
}); | ||
borderRadius: '50%', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's funny that this was the only thing required from the |
||
/* Styles applied to the root element if `edge="start"`. */ | ||
...(styleProps.edge === 'start' && { | ||
marginLeft: styleProps.size === 'small' ? -3 : -12, | ||
}), | ||
/* Styles applied to the root element if `edge="end"`. */ | ||
...(styleProps.edge === 'end' && { | ||
marginRight: styleProps.size === 'small' ? -3 : -12, | ||
}), | ||
})); | ||
|
||
const SwitchBaseInput = experimentalStyled('input', { skipSx: true })({ | ||
/* Styles applied to the internal input element. */ | ||
|
@@ -50,6 +60,7 @@ const SwitchBase = React.forwardRef(function SwitchBase(props, ref) { | |
className, | ||
defaultChecked, | ||
disabled: disabledProp, | ||
edge = false, | ||
icon, | ||
id, | ||
inputProps, | ||
|
@@ -121,6 +132,7 @@ const SwitchBase = React.forwardRef(function SwitchBase(props, ref) { | |
...props, | ||
checked, | ||
disabled, | ||
edge, | ||
}; | ||
|
||
const classes = useUtilityClasses(styleProps); | ||
|
@@ -193,6 +205,14 @@ SwitchBase.propTypes = { | |
* If `true`, the component is disabled. | ||
*/ | ||
disabled: PropTypes.bool, | ||
/** | ||
* If given, uses a negative margin to counteract the padding on one | ||
* side (this is often helpful for aligning the left or right | ||
* side of the icon with content above or below, without ruining the border | ||
* size and shape). | ||
* @default false | ||
*/ | ||
edge: PropTypes.oneOf(['end', 'start', false]), | ||
/** | ||
* The icon to display when the component is unchecked. | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would propose showing a
diff
with the changes.