-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(react-divider): add base hooks #35634
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
dmytrokirpa
merged 4 commits into
microsoft:master
from
dmytrokirpa:feat/base-divider-hooks
Jan 14, 2026
Merged
Changes from all commits
Commits
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-divider-ae589058-df1f-4fef-bec7-06fb3b3c8f39.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": "minor", | ||
| "comment": "feat: add base hooks", | ||
| "packageName": "@fluentui/react-divider", | ||
| "email": "dmytrokirpa@microsoft.com", | ||
| "dependentChangeType": "patch" | ||
| } | ||
9 changes: 8 additions & 1 deletion
9
packages/react-components/react-divider/library/src/Divider.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,8 +1,15 @@ | ||
| export type { DividerProps, DividerSlots, DividerState } from './components/Divider/index'; | ||
| export type { | ||
| DividerBaseProps, | ||
Hotell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| DividerProps, | ||
| DividerSlots, | ||
| DividerBaseState, | ||
| DividerState, | ||
| } from './components/Divider/index'; | ||
| export { | ||
| Divider, | ||
| dividerClassNames, | ||
| renderDivider_unstable, | ||
| useDividerStyles_unstable, | ||
| useDivider_unstable, | ||
| useDividerBase_unstable, | ||
| } from './components/Divider/index'; | ||
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-divider/library/src/components/Divider/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,5 +1,6 @@ | ||
| export { Divider } from './Divider'; | ||
| export type { DividerProps, DividerSlots, DividerState } from './Divider.types'; | ||
| export type { DividerBaseProps, DividerProps, DividerSlots, DividerBaseState, DividerState } from './Divider.types'; | ||
| export { renderDivider_unstable } from './renderDivider'; | ||
| export { useDivider_unstable } from './useDivider'; | ||
| export { useDividerBase_unstable } from './useDividerBase'; | ||
| export { dividerClassNames, useDividerStyles_unstable } from './useDividerStyles.styles'; |
40 changes: 10 additions & 30 deletions
40
packages/react-components/react-divider/library/src/components/Divider/useDivider.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,48 +1,28 @@ | ||
| 'use client'; | ||
|
|
||
| import * as React from 'react'; | ||
| import { getIntrinsicElementProps, useId, slot } from '@fluentui/react-utilities'; | ||
| import type { DividerProps, DividerState } from './Divider.types'; | ||
| import { useDividerBase_unstable } from './useDividerBase'; | ||
|
|
||
| /** | ||
| * Returns the props and state required to render the component | ||
| * @param props - User-provided props to the Divider component. | ||
| * @param ref - User-provided ref to be passed to the Divider component. | ||
| */ | ||
| export const useDivider_unstable = (props: DividerProps, ref: React.Ref<HTMLElement>): DividerState => { | ||
| const { alignContent = 'center', appearance = 'default', inset = false, vertical = false, wrapper } = props; | ||
| const dividerId = useId('divider-'); | ||
| const { alignContent = 'center', appearance = 'default', inset = false, vertical = false, ...rest } = props; | ||
|
|
||
| const state = useDividerBase_unstable(rest, ref); | ||
|
|
||
| return { | ||
| // Props passed at the top-level | ||
| alignContent, | ||
| appearance, | ||
| inset, | ||
| vertical, | ||
|
|
||
| // Slots definition | ||
| components: { | ||
| root: 'div', | ||
| wrapper: 'div', | ||
| ...state, | ||
| root: { | ||
| ...state.root, | ||
| 'aria-orientation': vertical ? 'vertical' : 'horizontal', | ||
| }, | ||
|
|
||
| root: slot.always( | ||
| getIntrinsicElementProps('div', { | ||
| role: 'separator', | ||
| 'aria-orientation': vertical ? 'vertical' : 'horizontal', | ||
| 'aria-labelledby': props.children ? dividerId : undefined, | ||
| ...props, | ||
| // FIXME: | ||
| // `ref` is wrongly assigned to be `HTMLElement` instead of `HTMLDivElement` | ||
| // but since it would be a breaking change to fix it, we are casting ref to it's proper type | ||
| ref: ref as React.Ref<HTMLDivElement>, | ||
| } as const), | ||
| { elementType: 'div' }, | ||
| ), | ||
| wrapper: slot.always(wrapper, { | ||
| defaultProps: { | ||
| id: dividerId, | ||
| children: props.children, | ||
| }, | ||
| elementType: 'div', | ||
| }), | ||
| }; | ||
| }; |
41 changes: 41 additions & 0 deletions
41
packages/react-components/react-divider/library/src/components/Divider/useDividerBase.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,41 @@ | ||
| import * as React from 'react'; | ||
| import { getIntrinsicElementProps, useId, slot } from '@fluentui/react-utilities'; | ||
| import type { DividerBaseProps, DividerBaseState } from './Divider.types'; | ||
|
|
||
| /** | ||
| * Returns the props and state required to render the component | ||
| * @param props - User-provided props to the Divider component. | ||
| * @param ref - User-provided ref to be passed to the Divider component. | ||
| */ | ||
| export const useDividerBase_unstable = (props: DividerBaseProps, ref: React.Ref<HTMLElement>): DividerBaseState => { | ||
| const { wrapper } = props; | ||
| const dividerId = useId('divider-'); | ||
|
|
||
| return { | ||
| // Slots definition | ||
| components: { | ||
| root: 'div', | ||
| wrapper: 'div', | ||
| }, | ||
| root: slot.always( | ||
| getIntrinsicElementProps('div', { | ||
| role: 'separator', | ||
| // 'aria-orientation': vertical ? 'vertical' : 'horizontal', | ||
| 'aria-labelledby': props.children ? dividerId : undefined, | ||
| ...props, | ||
| // FIXME: | ||
| // `ref` is wrongly assigned to be `HTMLElement` instead of `HTMLDivElement` | ||
| // but since it would be a breaking change to fix it, we are casting ref to it's proper type | ||
| ref: ref as React.Ref<HTMLDivElement>, | ||
| } as const), | ||
| { elementType: 'div' }, | ||
| ), | ||
| wrapper: slot.always(wrapper, { | ||
| defaultProps: { | ||
| id: dividerId, | ||
| children: props.children, | ||
| }, | ||
| elementType: 'div', | ||
| }), | ||
| }; | ||
| }; |
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
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.