-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
react-card - Migrate Card to new prop merging / root as a slot #20111
Merged
andrefcdias
merged 6 commits into
microsoft:master
from
andrefcdias:card-prop-merge-simplification
Oct 6, 2021
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b10d811
Migrate Card to new prop merging
andrefcdias fe4e942
Change files
andrefcdias 43bde50
Migrate CardFooter
andrefcdias 18f2bcf
Convert interfaces to types
andrefcdias 6177c71
Update API
andrefcdias d517ffc
Update snapshots
andrefcdias 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-card-1715b99c-f9b2-4638-b765-5ef2f6ef34aa.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 Card to new prop merging", | ||
"packageName": "@fluentui/react-card", | ||
"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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,23 @@ | ||
import * as React from 'react'; | ||
import type { ComponentPropsCompat, ComponentStateCompat } from '@fluentui/react-utilities'; | ||
import type { ComponentProps, ComponentState, IntrinsicShorthandProps } from '@fluentui/react-utilities'; | ||
|
||
/** | ||
* Card Props | ||
*/ | ||
export interface CardProps extends ComponentPropsCompat, React.HTMLAttributes<HTMLElement> { | ||
export type CardSlots = { | ||
root: IntrinsicShorthandProps<'div'>; | ||
}; | ||
|
||
export type CardCommons = { | ||
/* | ||
* TODO Add props and slots here | ||
* Any slot property should be listed in the cardShorthandProps array below | ||
* Any property that has a default value should be listed in CardDefaultedProps as e.g. 'size' | 'icon' | ||
*/ | ||
} | ||
}; | ||
|
||
/** | ||
* Names of the shorthand properties in CardProps | ||
*/ | ||
export type CardShorthandProps = never; // TODO add shorthand property names | ||
|
||
/** | ||
* Names of CardProps that have a default value in useCard | ||
* Card Props | ||
*/ | ||
export type CardDefaultedProps = never; // TODO add names of properties with default values | ||
export type CardProps = ComponentProps<CardSlots> & Partial<CardCommons>; | ||
|
||
/** | ||
* State used in rendering Card | ||
*/ | ||
export interface CardState extends CardProps, ComponentStateCompat<CardProps, CardShorthandProps, CardDefaultedProps> { | ||
/** | ||
* Ref to the root element | ||
*/ | ||
ref: React.Ref<HTMLElement>; | ||
} | ||
export type CardState = ComponentState<CardSlots> & CardCommons; |
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,12 +1,12 @@ | ||
import * as React from 'react'; | ||
import { getSlotsCompat } from '@fluentui/react-utilities'; | ||
import type { CardState } from './Card.types'; | ||
import { getSlots } from '@fluentui/react-utilities'; | ||
import type { CardSlots, CardState } from './Card.types'; | ||
|
||
/** | ||
* Render the final JSX of Card | ||
*/ | ||
export const renderCard = (state: CardState) => { | ||
const { slots, slotProps } = getSlotsCompat(state); | ||
const { slots, slotProps } = getSlots<CardSlots>(state); | ||
|
||
return <slots.root {...slotProps.root}>{state.children}</slots.root>; | ||
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
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
33 changes: 8 additions & 25 deletions
33
packages/react-card/src/components/CardFooter/CardFooter.types.ts
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,33 +1,16 @@ | ||
import * as React from 'react'; | ||
import type { ComponentPropsCompat, ComponentStateCompat, ShorthandPropsCompat } from '@fluentui/react-utilities'; | ||
import type { ComponentProps, ComponentState, IntrinsicShorthandProps } from '@fluentui/react-utilities'; | ||
|
||
/** | ||
* CardFooter Props | ||
*/ | ||
export interface CardFooterProps extends ComponentPropsCompat, React.HTMLAttributes<HTMLElement> { | ||
/** | ||
* Actions slot | ||
*/ | ||
action?: ShorthandPropsCompat<React.HTMLAttributes<HTMLElement>>; | ||
} | ||
|
||
/** | ||
* Names of the shorthand properties in CardFooterProps | ||
*/ | ||
export type CardFooterShorthandProps = 'action'; // TODO add shorthand property names | ||
export type CardFooterSlots = { | ||
root: IntrinsicShorthandProps<'div'>; | ||
action?: IntrinsicShorthandProps<'div'>; | ||
}; | ||
|
||
/** | ||
* Names of CardFooterProps that have a default value in useCardFooter | ||
* CardFooter props | ||
*/ | ||
export type CardFooterDefaultedProps = never; | ||
export type CardFooterProps = ComponentProps<CardFooterSlots>; | ||
|
||
/** | ||
* State used in rendering CardFooter | ||
*/ | ||
export interface CardFooterState | ||
extends ComponentStateCompat<CardFooterProps, CardFooterShorthandProps, CardFooterDefaultedProps> { | ||
/** | ||
* Ref to the root element | ||
*/ | ||
ref: React.Ref<HTMLElement>; | ||
} | ||
export type CardFooterState = ComponentState<CardFooterSlots>; |
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
8 changes: 4 additions & 4 deletions
8
packages/react-card/src/components/CardFooter/renderCardFooter.tsx
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
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.
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.
Intended change, action slot can contain any kind of elements so it should not be a
span