-
Notifications
You must be signed in to change notification settings - Fork 2.9k
refactor(react-button): streamline button component base hook and remove unused base hooks #35689
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
Open
dmytrokirpa
wants to merge
4
commits into
microsoft:master
Choose a base branch
from
dmytrokirpa:refactor/button-state-hooks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
02eb71c
refactor(react-button): streamline button component base hook and rem…
dmytrokirpa f3e596c
Update change/@fluentui-react-button-e83c949c-d849-4636-b94e-c16be2c6…
dmytrokirpa 23c0a10
apply review suggestions
dmytrokirpa bfea038
Merge branch 'master' into refactor/button-state-hooks
dmytrokirpa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-button-e83c949c-d849-4636-b94e-c16be2c6079b.json
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "fix: prevent custom props from leaking to the DOM ", | ||
| "packageName": "@fluentui/react-button", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-carousel-a96cffaf-5ba5-4437-9832-432901335262.json
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "fix: prevent custom props from leaking to the DOM", | ||
| "packageName": "@fluentui/react-carousel", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } |
9 changes: 1 addition & 8 deletions
9
packages/react-components/react-button/library/src/CompoundButton.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -1,15 +1,8 @@ | ||
| export type { | ||
| CompoundButtonBaseProps, | ||
| CompoundButtonProps, | ||
| CompoundButtonSlots, | ||
| CompoundButtonBaseState, | ||
| CompoundButtonState, | ||
| } from './components/CompoundButton/index'; | ||
| export type { CompoundButtonProps, CompoundButtonSlots, CompoundButtonState } from './components/CompoundButton/index'; | ||
| export { | ||
| CompoundButton, | ||
| compoundButtonClassNames, | ||
| renderCompoundButton_unstable, | ||
| useCompoundButtonStyles_unstable, | ||
| useCompoundButton_unstable, | ||
| useCompoundButtonBase_unstable, | ||
| } from './components/CompoundButton/index'; |
9 changes: 1 addition & 8 deletions
9
packages/react-components/react-button/library/src/MenuButton.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -1,15 +1,8 @@ | ||
| export type { | ||
| MenuButtonBaseProps, | ||
| MenuButtonProps, | ||
| MenuButtonSlots, | ||
| MenuButtonBaseState, | ||
| MenuButtonState, | ||
| } from './components/MenuButton/index'; | ||
| export type { MenuButtonProps, MenuButtonSlots, MenuButtonState } from './components/MenuButton/index'; | ||
| export { | ||
| MenuButton, | ||
| menuButtonClassNames, | ||
| renderMenuButton_unstable, | ||
| useMenuButtonStyles_unstable, | ||
| useMenuButton_unstable, | ||
| useMenuButtonBase_unstable, | ||
| } from './components/MenuButton/index'; |
9 changes: 1 addition & 8 deletions
9
packages/react-components/react-button/library/src/SplitButton.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -1,15 +1,8 @@ | ||
| export type { | ||
| SplitButtonBaseProps, | ||
| SplitButtonProps, | ||
| SplitButtonSlots, | ||
| SplitButtonBaseState, | ||
| SplitButtonState, | ||
| } from './components/SplitButton/index'; | ||
| export type { SplitButtonProps, SplitButtonSlots, SplitButtonState } from './components/SplitButton/index'; | ||
| export { | ||
| SplitButton, | ||
| renderSplitButton_unstable, | ||
| splitButtonClassNames, | ||
| useSplitButtonStyles_unstable, | ||
| useSplitButton_unstable, | ||
| useSplitButtonBase_unstable, | ||
| } from './components/SplitButton/index'; |
2 changes: 1 addition & 1 deletion
2
packages/react-components/react-button/library/src/ToggleButton.ts
This file contains hidden or 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 hidden or 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 hidden or 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
86 changes: 86 additions & 0 deletions
86
packages/react-components/react-button/library/src/components/Button/useButton.test.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import * as React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
| import { renderHook } from '@testing-library/react-hooks'; | ||
| import '@testing-library/jest-dom'; | ||
| import { useButtonBase_unstable } from './useButton'; | ||
| import { renderButton_unstable } from './renderButton'; | ||
| import type { ButtonState, ButtonBaseProps } from './Button.types'; | ||
| import { mergeClasses } from '@griffel/react'; | ||
|
|
||
| describe('useButtonBase_unstable', () => { | ||
| it('returns default state when no props are provided', () => { | ||
| const { result } = renderHook(() => useButtonBase_unstable({}, React.createRef())); | ||
| expect(result.current).toEqual( | ||
| expect.objectContaining({ | ||
| disabled: false, | ||
| disabledFocusable: false, | ||
| iconPosition: 'before', | ||
| iconOnly: false, | ||
| components: { root: 'button', icon: 'span' }, | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it('sets disabled and disabledFocusable correctly', () => { | ||
| const { result } = renderHook(() => | ||
| useButtonBase_unstable({ disabled: true, disabledFocusable: true }, React.createRef()), | ||
| ); | ||
| expect(result.current.disabled).toBe(true); | ||
| expect(result.current.disabledFocusable).toBe(true); | ||
| }); | ||
|
|
||
| it('sets iconPosition and iconOnly correctly', () => { | ||
| const { result } = renderHook(() => | ||
| useButtonBase_unstable({ iconPosition: 'after', icon: 'icon' }, React.createRef()), | ||
| ); | ||
| expect(result.current.iconPosition).toBe('after'); | ||
| expect(result.current.iconOnly).toBe(true); | ||
| }); | ||
|
|
||
| it('handles absence of icon and children correctly', () => { | ||
| const { result } = renderHook(() => useButtonBase_unstable({}, React.createRef())); | ||
| expect(result.current.iconOnly).toBe(false); | ||
| }); | ||
|
|
||
| describe('Recomposition', () => { | ||
| type CustomButtonProps = ButtonBaseProps & { appearance?: '1' | '2' | '3' }; | ||
|
|
||
| const CustomButton = React.forwardRef<HTMLButtonElement, CustomButtonProps>( | ||
| ({ appearance = '1', ...props }, ref) => { | ||
| const state = useButtonBase_unstable(props, ref); | ||
|
|
||
| state.root.className = mergeClasses('custom-button', `appearance-${appearance}`, state.root.className); | ||
|
|
||
| return renderButton_unstable(state as ButtonState); | ||
| }, | ||
| ); | ||
|
|
||
| it('renders as a button element', () => { | ||
| const { getByRole } = render(<CustomButton>Button</CustomButton>); | ||
| expect(getByRole('button')).toMatchInlineSnapshot(` | ||
| <button | ||
| class="custom-button appearance-1" | ||
| type="button" | ||
| > | ||
| Button | ||
| </button> | ||
| `); | ||
| }); | ||
|
|
||
| it('renders as an anchor element', () => { | ||
| const { getByRole } = render( | ||
| <CustomButton as="a" href="#"> | ||
| Link | ||
| </CustomButton>, | ||
| ); | ||
| expect(getByRole('link')).toMatchInlineSnapshot(` | ||
| <a | ||
| class="custom-button appearance-1" | ||
| href="#" | ||
| > | ||
| Link | ||
| </a> | ||
| `); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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
36 changes: 0 additions & 36 deletions
36
packages/react-components/react-button/library/src/components/Button/useButtonBase.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
9 changes: 1 addition & 8 deletions
9
packages/react-components/react-button/library/src/components/CompoundButton/index.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -1,12 +1,5 @@ | ||
| export { CompoundButton } from './CompoundButton'; | ||
| export type { | ||
| CompoundButtonBaseProps, | ||
| CompoundButtonProps, | ||
| CompoundButtonSlots, | ||
| CompoundButtonBaseState, | ||
| CompoundButtonState, | ||
| } from './CompoundButton.types'; | ||
| export type { CompoundButtonProps, CompoundButtonSlots, CompoundButtonState } from './CompoundButton.types'; | ||
| export { renderCompoundButton_unstable } from './renderCompoundButton'; | ||
| export { useCompoundButton_unstable } from './useCompoundButton'; | ||
| export { useCompoundButtonBase_unstable } from './useCompoundButtonBase'; | ||
| export { compoundButtonClassNames, useCompoundButtonStyles_unstable } from './useCompoundButtonStyles.styles'; |
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
🕵🏾♀️ visual changes to review in the Visual Change Report
vr-tests-react-components/Charts-DonutChart 1 screenshots
vr-tests-react-components/Positioning 1 screenshots
vr-tests-react-components/TagPicker 3 screenshots
There were 3 duplicate changes discarded. Check the build logs for more information.