-
Notifications
You must be signed in to change notification settings - Fork 2.9k
react-avatar: Creating AvatarGroupItem component #23287
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
sopranopillow
merged 7 commits into
microsoft:master
from
sopranopillow:avatargroupitem-scaffold
May 27, 2022
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8c71358
Creating AvatarGroupItem component.
sopranopillow d5c35af
Change file
sopranopillow 1343fa5
fixing dependency mismatch
sopranopillow 7ba2914
adding overwritten comment
sopranopillow 3532396
Merge branch 'master' of https://github.com/microsoft/fluentui into a…
sopranopillow fdf33de
removing long comment
sopranopillow 84bd8c2
disabling tests
sopranopillow 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-avatar-e8465a99-82a6-47aa-a896-aed41ea0000f.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": "prerelease", | ||
| "comment": "Creating AvatarGroupItem component.", | ||
| "packageName": "@fluentui/react-avatar", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } |
2 changes: 1 addition & 1 deletion
2
packages/react-components/react-avatar/config/api-extractor.local.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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", | ||
| "extends": "./api-extractor.json", | ||
| "mainEntryPointFilePath": "<projectFolder>/dist/packages/react-components/<unscopedPackageName>/src/index.d.ts" | ||
| "mainEntryPointFilePath": "<projectFolder>/dist/types/packages/react-components/<unscopedPackageName>/src/index.d.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './components/AvatarGroupItem/index'; |
19 changes: 19 additions & 0 deletions
19
...ges/react-components/react-avatar/src/components/AvatarGroupItem/AvatarGroupItem.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,19 @@ | ||
| import * as React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
| import { AvatarGroupItem } from './AvatarGroupItem'; | ||
| import { isConformant } from '../../common/isConformant'; | ||
|
|
||
| describe('AvatarGroupItem', () => { | ||
| isConformant({ | ||
| Component: AvatarGroupItem, | ||
| displayName: 'AvatarGroupItem', | ||
| disabledTests: ['component-has-static-classname', 'component-has-static-classname-exported'], | ||
| }); | ||
|
|
||
| // TODO add more tests here, and create visual regression tests in /apps/vr-tests | ||
|
|
||
| it('renders a default state', () => { | ||
| const result = render(<AvatarGroupItem>Default AvatarGroupItem</AvatarGroupItem>); | ||
| expect(result.container).toMatchSnapshot(); | ||
| }); | ||
| }); |
18 changes: 18 additions & 0 deletions
18
packages/react-components/react-avatar/src/components/AvatarGroupItem/AvatarGroupItem.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,18 @@ | ||
| import * as React from 'react'; | ||
| import { useAvatarGroupItem_unstable } from './useAvatarGroupItem'; | ||
| import { renderAvatarGroupItem_unstable } from './renderAvatarGroupItem'; | ||
| import { useAvatarGroupItemStyles_unstable } from './useAvatarGroupItemStyles'; | ||
| import type { AvatarGroupItemProps } from './AvatarGroupItem.types'; | ||
| import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
|
|
||
| /** | ||
| * AvatarGroupItem component - TODO: add more docs | ||
| */ | ||
| export const AvatarGroupItem: ForwardRefComponent<AvatarGroupItemProps> = React.forwardRef((props, ref) => { | ||
| const state = useAvatarGroupItem_unstable(props, ref); | ||
|
|
||
| useAvatarGroupItemStyles_unstable(state); | ||
| return renderAvatarGroupItem_unstable(state); | ||
| }); | ||
|
|
||
| AvatarGroupItem.displayName = 'AvatarGroupItem'; |
15 changes: 15 additions & 0 deletions
15
...ges/react-components/react-avatar/src/components/AvatarGroupItem/AvatarGroupItem.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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
|
|
||
| export type AvatarGroupItemSlots = { | ||
| root: Slot<'div'>; | ||
| }; | ||
|
|
||
| /** | ||
| * AvatarGroupItem Props | ||
| */ | ||
| export type AvatarGroupItemProps = ComponentProps<AvatarGroupItemSlots> & {}; | ||
|
|
||
| /** | ||
| * State used in rendering AvatarGroupItem | ||
| */ | ||
| export type AvatarGroupItemState = ComponentState<AvatarGroupItemSlots>; |
11 changes: 11 additions & 0 deletions
11
...s/react-avatar/src/components/AvatarGroupItem/__snapshots__/AvatarGroupItem.test.tsx.snap
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,11 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`AvatarGroupItem renders a default state 1`] = ` | ||
| <div> | ||
| <div | ||
| class="fui-AvatarGroupItem" | ||
| > | ||
| Default AvatarGroupItem | ||
| </div> | ||
| </div> | ||
| `; |
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-avatar/src/components/AvatarGroupItem/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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export * from './AvatarGroupItem'; | ||
| export * from './AvatarGroupItem.types'; | ||
| export * from './renderAvatarGroupItem'; | ||
| export * from './useAvatarGroupItem'; | ||
| export * from './useAvatarGroupItemStyles'; |
13 changes: 13 additions & 0 deletions
13
...es/react-components/react-avatar/src/components/AvatarGroupItem/renderAvatarGroupItem.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,13 @@ | ||
| import * as React from 'react'; | ||
| import { getSlots } from '@fluentui/react-utilities'; | ||
| import type { AvatarGroupItemState, AvatarGroupItemSlots } from './AvatarGroupItem.types'; | ||
|
|
||
| /** | ||
| * Render the final JSX of AvatarGroupItem | ||
| */ | ||
| export const renderAvatarGroupItem_unstable = (state: AvatarGroupItemState) => { | ||
| const { slots, slotProps } = getSlots<AvatarGroupItemSlots>(state); | ||
|
|
||
| // TODO Add additional slots in the appropriate place | ||
| return <slots.root {...slotProps.root} />; | ||
| }; |
31 changes: 31 additions & 0 deletions
31
packages/react-components/react-avatar/src/components/AvatarGroupItem/useAvatarGroupItem.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,31 @@ | ||
| import * as React from 'react'; | ||
| import { getNativeElementProps } from '@fluentui/react-utilities'; | ||
| import type { AvatarGroupItemProps, AvatarGroupItemState } from './AvatarGroupItem.types'; | ||
|
|
||
| /** | ||
| * Create the state required to render AvatarGroupItem. | ||
| * | ||
| * The returned state can be modified with hooks such as useAvatarGroupItemStyles_unstable, | ||
| * before being passed to renderAvatarGroupItem_unstable. | ||
| * | ||
| * @param props - props from this instance of AvatarGroupItem | ||
| * @param ref - reference to root HTMLElement of AvatarGroupItem | ||
| */ | ||
| export const useAvatarGroupItem_unstable = ( | ||
| props: AvatarGroupItemProps, | ||
| ref: React.Ref<HTMLElement>, | ||
| ): AvatarGroupItemState => { | ||
| return { | ||
| // TODO add appropriate props/defaults | ||
| components: { | ||
| // TODO add each slot's element type or component | ||
| root: 'div', | ||
| }, | ||
| // TODO add appropriate slots, for example: | ||
| // mySlot: resolveShorthand(props.mySlot), | ||
| root: getNativeElementProps('div', { | ||
| ref, | ||
| ...props, | ||
| }), | ||
| }; | ||
| }; |
33 changes: 33 additions & 0 deletions
33
.../react-components/react-avatar/src/components/AvatarGroupItem/useAvatarGroupItemStyles.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,33 @@ | ||
| import { makeStyles, mergeClasses } from '@griffel/react'; | ||
| import type { AvatarGroupItemSlots, AvatarGroupItemState } from './AvatarGroupItem.types'; | ||
| import type { SlotClassNames } from '@fluentui/react-utilities'; | ||
|
|
||
| export const avatarGroupItemClassNames: SlotClassNames<AvatarGroupItemSlots> = { | ||
| root: 'fui-AvatarGroupItem', | ||
| // TODO: add class names for all slots on AvatarGroupItemSlots. | ||
| // Should be of the form `<slotName>: 'fui-AvatarGroupItem__<slotName>` | ||
| }; | ||
|
|
||
| /** | ||
| * Styles for the root slot | ||
| */ | ||
| const useStyles = makeStyles({ | ||
| root: { | ||
| // TODO Add default styles for the root element | ||
| }, | ||
|
|
||
| // TODO add additional classes for different states and/or slots | ||
| }); | ||
|
|
||
| /** | ||
| * Apply styling to the AvatarGroupItem slots based on the state | ||
| */ | ||
| export const useAvatarGroupItemStyles_unstable = (state: AvatarGroupItemState): AvatarGroupItemState => { | ||
| const styles = useStyles(); | ||
| state.root.className = mergeClasses(avatarGroupItemClassNames.root, styles.root, state.root.className); | ||
|
|
||
| // TODO Add class names to slots, for example: | ||
| // state.mySlot.className = mergeClasses(styles.mySlot, state.mySlot.className); | ||
|
|
||
| return state; | ||
| }; |
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
18 changes: 18 additions & 0 deletions
18
packages/react-components/react-avatar/src/stories/AvatarGroupItem.stories.beta.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,18 @@ | ||
| import { AvatarGroupItem } from '../index'; | ||
|
|
||
| import descriptionMd from './AvatarGroupItemDescription.md'; | ||
| import bestPracticesMd from './AvatarGroupItemBestPractices.md'; | ||
|
|
||
| export { Default } from './AvatarGroupItemDefault.stories'; | ||
|
|
||
| export default { | ||
| title: 'Components/AvatarGroupItem', | ||
| component: AvatarGroupItem, | ||
| parameters: { | ||
| docs: { | ||
| description: { | ||
| component: [descriptionMd, bestPracticesMd].join('\n'), | ||
| }, | ||
| }, | ||
| }, | ||
| }; |
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-avatar/src/stories/AvatarGroupItemBestPractices.md
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,5 @@ | ||
| ## Best practices | ||
|
|
||
| ### Do | ||
|
|
||
| ### Don't |
4 changes: 4 additions & 0 deletions
4
packages/react-components/react-avatar/src/stories/AvatarGroupItemDefault.stories.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,4 @@ | ||
| import * as React from 'react'; | ||
| import { AvatarGroupItem, AvatarGroupItemProps } from '../index'; | ||
|
|
||
| export const Default = (props: Partial<AvatarGroupItemProps>) => <AvatarGroupItem {...props} />; |
Empty file.
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.
Out of curiosity, why is this change needed in this PR?
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.
create-componentadded it, it doesn't seem to affect anything though. I can remove it just in case?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.
I'm not really sure what this actually does. But if it was added by create-component, and it doesn't break things, then it should be fine.