-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
react-image: Migrate to simplified slots (#19745)
* Migrate to simplified slots * Fixed typo * Change files * Fixed root slot as and imageslots * Changed root type to IntrinsicShorthandProps Co-authored-by: André <[email protected]> * Updated api md * Fixed typo and change file Co-authored-by: André <[email protected]>
- Loading branch information
1 parent
e870763
commit 5fed6eb
Showing
8 changed files
with
65 additions
and
35 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-image-9142fc98-0dd2-4c38-8a21-7dccbbe21ae2.json
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "prerelease", | ||
"comment": "Migrate to simplified slots", | ||
"packageName": "@fluentui/react-image", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
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 |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import * as React from 'react'; | ||
import { getSlotsCompat } from '@fluentui/react-utilities'; | ||
import type { ImageState } from './Image.types'; | ||
import { getSlots } from '@fluentui/react-utilities'; | ||
import { ImageSlots, ImageState } from './Image.types'; | ||
import { imageShorthandProps } from './useImage'; | ||
|
||
/** | ||
* Define the render function. | ||
* Given the state of an image, renders it. | ||
*/ | ||
export const renderImage = (state: ImageState) => { | ||
const { slots, slotProps } = getSlotsCompat(state); | ||
const { slots, slotProps } = getSlots<ImageSlots>(state, imageShorthandProps); | ||
|
||
return <slots.root {...slotProps.root} />; | ||
}; |
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 |
---|---|---|
@@ -1,24 +1,30 @@ | ||
import * as React from 'react'; | ||
import { makeMergeProps, resolveShorthandProps, useMergedRefs } from '@fluentui/react-utilities'; | ||
import type { ImageProps, ImageState } from './Image.types'; | ||
import { getNativeElementProps } from '@fluentui/react-utilities'; | ||
import type { ImageProps, ImageSlots, ImageState } from './Image.types'; | ||
|
||
const mergeProps = makeMergeProps<ImageState>(); | ||
export const imageShorthandProps: Array<keyof ImageSlots> = ['root']; | ||
|
||
/** | ||
* Given user props, returns state and render function for an Image. | ||
*/ | ||
export const useImage = (props: ImageProps, ref: React.Ref<HTMLElement>, defaultProps?: ImageProps): ImageState => { | ||
const resolvedRef = useMergedRefs(ref, React.useRef(null)); | ||
const state = mergeProps( | ||
{ | ||
ref: resolvedRef, | ||
as: 'img', | ||
export const useImage = (props: ImageProps, ref: React.Ref<HTMLImageElement>): ImageState => { | ||
const { bordered, fit, fluid, circular, rounded } = props; | ||
const state: ImageState = { | ||
bordered, | ||
fit, | ||
fluid, | ||
circular, | ||
rounded, | ||
components: { | ||
root: 'img', | ||
}, | ||
defaultProps, | ||
resolveShorthandProps(props, []), | ||
); | ||
root: getNativeElementProps('img', { | ||
ref, | ||
...props, | ||
}), | ||
}; | ||
|
||
state['aria-hidden'] = state.alt || state['aria-label'] ? undefined : 'true'; | ||
state.root['aria-hidden'] = state.root.alt || state.root['aria-label'] ? undefined : 'true'; | ||
|
||
return state; | ||
}; |
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