-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: replace ToolbarRadio implementation by usage of toggle button as Radio #25343
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6be1fb0
feat: replace ToolbarRadio implementation by usage of toggle button a…
chpalac d32993f
chore: add changes
chpalac c2a7475
chore: remove and update api
chpalac 49066ed
chore: update handler types
chpalac 577c64a
chore: delete line
chpalac cfd0b82
chore: update checked items type
chpalac 886d59e
chore: rename
chpalac c868f4a
chore: update api and remove disable flag from handle radio
chpalac bb31c85
Merge branch 'master' of https://github.com/microsoft/fluentui into f…
chpalac c172851
chore: update snapshot
chpalac baa788e
chore: update stories
chpalac 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-toolbar-87c0c30d-e652-4dd1-8f2c-27bb19adcbe5.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": "none", | ||
| "comment": "feat: replace ToolbarRadio implementation by usage of toggle button as radio", | ||
| "packageName": "@fluentui/react-toolbar", | ||
| "email": "chassunc@microsoft.com", | ||
| "dependentChangeType": "none" | ||
| } |
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
1 change: 0 additions & 1 deletion
1
packages/react-components/react-toolbar/src/ToolbarRadioGroup.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
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
3 changes: 2 additions & 1 deletion
3
packages/react-components/react-toolbar/src/components/Toolbar/useToolbarContextValues.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
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
14 changes: 7 additions & 7 deletions
14
packages/react-components/react-toolbar/src/components/ToolbarRadio/ToolbarRadio.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 |
|---|---|---|
| @@ -1,18 +1,18 @@ | ||
| import * as React from 'react'; | ||
| import type { ToolbarRadioProps } from './ToolbarRadio.types'; | ||
| import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
| import { useRadio_unstable, renderRadio_unstable } from '@fluentui/react-radio'; | ||
| import { renderToggleButton_unstable } from '@fluentui/react-button'; | ||
| import { useToolbarRadio_unstable } from './useToolbarRadio'; | ||
| import { useToolbarRadioStyles_unstable } from './useToolbarRadioStyles'; | ||
| import { useToolbarContext_unstable } from '../Toolbar/ToolbarContext'; | ||
|
|
||
| /** | ||
| * ToolbarRadio component is a Radio to be used inside Toolbar | ||
| * ToolbarToggleButton component | ||
| */ | ||
| export const ToolbarRadio: ForwardRefComponent<ToolbarRadioProps> = React.forwardRef((props, ref) => { | ||
|
chpalac marked this conversation as resolved.
Outdated
|
||
| const size = useToolbarContext_unstable(ctx => ctx.size); | ||
| const state = useRadio_unstable(props, ref); | ||
| useToolbarRadioStyles_unstable({ size, ...state }); | ||
| return renderRadio_unstable(state); | ||
| const state = useToolbarRadio_unstable(props, ref); | ||
|
|
||
| useToolbarRadioStyles_unstable(state); | ||
| return renderToggleButton_unstable(state); | ||
| }) as ForwardRefComponent<ToolbarRadioProps>; | ||
|
|
||
| ToolbarRadio.displayName = 'ToolbarRadio'; | ||
23 changes: 14 additions & 9 deletions
23
packages/react-components/react-toolbar/src/components/ToolbarRadio/ToolbarRadio.types.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,20 @@ | ||
| import { RadioState, RadioProps } from '@fluentui/react-radio'; | ||
| import type { ComponentProps, ComponentState } from '@fluentui/react-utilities'; | ||
| import { ToggleButtonProps, ButtonSlots, ToggleButtonState } from '@fluentui/react-button'; | ||
|
|
||
| /** | ||
| * ToolbarRadio Props | ||
| * ToolbarToggleButton Props | ||
|
chpalac marked this conversation as resolved.
Outdated
|
||
| */ | ||
| export type ToolbarRadioProps = RadioProps & { | ||
| size?: 'small' | 'medium'; | ||
| }; | ||
| export type ToolbarRadioProps = ComponentProps<ButtonSlots> & | ||
| Partial<Pick<ToggleButtonProps, 'disabled' | 'disabledFocusable' | 'size'>> & { | ||
| appearance?: 'primary' | 'subtle'; | ||
| name: string; | ||
| value: string; | ||
| }; | ||
|
|
||
| /** | ||
| * State used in rendering ToolbarRadio | ||
| * State used in rendering ToolbarToggleButton | ||
| */ | ||
| export type ToolbarRadioState = RadioState & { | ||
| size?: 'small' | 'medium'; | ||
| }; | ||
| export type ToolbarRadioState = ComponentState<Partial<ButtonSlots>> & | ||
| ToggleButtonState & | ||
| Required<Pick<ToggleButtonProps, 'checked'>> & | ||
| Pick<ToolbarRadioProps, 'name' | 'value'>; | ||
34 changes: 0 additions & 34 deletions
34
...onents/react-toolbar/src/components/ToolbarRadio/__snapshots__/ToolbarRadio.test.tsx.snap
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
packages/react-components/react-toolbar/src/components/ToolbarRadio/useToolbarRadio.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 |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import * as React from 'react'; | ||
| import { useToggleButton_unstable } from '@fluentui/react-button'; | ||
| import { useToolbarContext_unstable } from '../Toolbar/ToolbarContext'; | ||
| import { ToolbarRadioProps, ToolbarRadioState } from './ToolbarRadio.types'; | ||
|
|
||
| /** | ||
| * Given user props, defines default props for the ToggleButton, calls useButtonState and useChecked, and returns | ||
| * processed state. | ||
| * @param props - User provided props to the ToggleButton component. | ||
| * @param ref - User provided ref to be passed to the ToggleButton component. | ||
| */ | ||
| export const useToolbarRadio_unstable = ( | ||
| props: ToolbarRadioProps, | ||
| ref: React.Ref<HTMLButtonElement | HTMLAnchorElement>, | ||
| ): ToolbarRadioState => { | ||
| const handleRadio = useToolbarContext_unstable(ctx => ctx.handleRadio); | ||
| const checked = useToolbarContext_unstable(ctx => !!ctx.checkedValues[props.name]?.includes(props.value)); | ||
| const size = useToolbarContext_unstable(ctx => ctx.size); | ||
|
|
||
| const { onClick: onClickOriginal } = props; | ||
| const toggleButtonState = useToggleButton_unstable({ size, checked, ...props }, ref); | ||
| const state: ToolbarRadioState = { | ||
| ...toggleButtonState, | ||
| name: props.name, | ||
| value: props.value, | ||
| }; | ||
|
|
||
| const handleOnClick = ( | ||
|
chpalac marked this conversation as resolved.
Outdated
|
||
| e: React.MouseEvent<HTMLButtonElement, MouseEvent> & React.MouseEvent<HTMLAnchorElement, MouseEvent>, | ||
| ) => { | ||
| if (state.disabled) { | ||
| e.preventDefault(); | ||
| e.stopPropagation(); | ||
| return; | ||
| } | ||
|
|
||
| handleRadio?.(e, state.name, state.value, state.checked); | ||
| onClickOriginal?.(e); | ||
| }; | ||
|
|
||
| state.root.onClick = handleOnClick; | ||
| return state; | ||
| }; | ||
38 changes: 10 additions & 28 deletions
38
packages/react-components/react-toolbar/src/components/ToolbarRadio/useToolbarRadioStyles.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,38 +1,20 @@ | ||
| import { makeStyles, mergeClasses, shorthands } from '@griffel/react'; | ||
| import { useRadioStyles_unstable } from '@fluentui/react-radio'; | ||
| import { tokens } from '@fluentui/react-theme'; | ||
| import { makeStyles, mergeClasses } from '@griffel/react'; | ||
| import { useToggleButtonStyles_unstable } from '@fluentui/react-button'; | ||
| import { ToolbarRadioState } from './ToolbarRadio.types'; | ||
|
|
||
| const useBaseStyles = makeStyles({ | ||
| root: { | ||
| ...shorthands.padding('0px'), | ||
| }, | ||
| }); | ||
|
|
||
| const useSmallStyles = makeStyles({ | ||
| label: { | ||
| fontSize: 'var(--fontSizeBase200)', | ||
| }, | ||
| root: { | ||
| columnGap: '8px', | ||
| selected: { | ||
| color: tokens.colorBrandForeground1, | ||
| }, | ||
| }); | ||
|
|
||
| /** | ||
| * Apply styling to the ToolbarRadio slots based on the state | ||
| * Apply styling to the ToolbarToggleButton slots based on the state | ||
| */ | ||
| export const useToolbarRadioStyles_unstable = (state: ToolbarRadioState) => { | ||
| useRadioStyles_unstable(state); | ||
| const baseToolbarRadioStyles = useBaseStyles(); | ||
| const toolbarRadioSmallStyles = useSmallStyles(); | ||
| if (state.label) { | ||
| state.label.className = mergeClasses( | ||
| state.label.className, | ||
| state.size === 'small' && toolbarRadioSmallStyles.label, | ||
| ); | ||
| } | ||
| state.root.className = mergeClasses( | ||
| state.root.className, | ||
| baseToolbarRadioStyles.root, | ||
| state.size === 'small' && toolbarRadioSmallStyles.root, | ||
| ); | ||
| useToggleButtonStyles_unstable(state); | ||
| const toggleButtonStyles = useBaseStyles(); | ||
|
|
||
| state.root.className = mergeClasses(state.root.className, state.checked && toggleButtonStyles.selected); | ||
| }; |
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.