-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(react-tags): Add TagGroup with context #27886
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 all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b3ff666
Add dismiss handling
YuanboXue-Amber 866ab68
api
YuanboXue-Amber 06cbe94
add TagGroup
YuanboXue-Amber 7dae554
handle focus after dismiss
YuanboXue-Amber ab98a5f
new dismiss handling
YuanboXue-Amber f9b4fcd
add size
YuanboXue-Amber cfbc28a
remove dismiss change
YuanboXue-Amber c05c35d
Update packages/react-components/react-tags/src/components/TagGroup/r…
YuanboXue-Amber 342b236
TagGroupContextValue to TagGroupContextValuess
YuanboXue-Amber 2b9911b
api
YuanboXue-Amber 24f1dd2
Update packages/react-components/react-tags/src/components/TagGroup/u…
YuanboXue-Amber 56767eb
prettier after merge suggestion
YuanboXue-Amber a9d53fd
Merge branch 'master' into tag-temp
YuanboXue-Amber 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
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/TagGroup/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
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
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
11 changes: 11 additions & 0 deletions
11
packages/react-components/react-tags/src/components/TagGroup/TagGroup.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,11 @@ | ||
| import { TagGroup } from './TagGroup'; | ||
| import { isConformant } from '../../testing/isConformant'; | ||
|
|
||
| describe('TagGroup', () => { | ||
| isConformant({ | ||
| Component: TagGroup, | ||
| displayName: 'TagGroup', | ||
| }); | ||
|
|
||
| // TODO add more tests here, and create visual regression tests in /apps/vr-tests | ||
| }); |
19 changes: 19 additions & 0 deletions
19
packages/react-components/react-tags/src/components/TagGroup/TagGroup.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 { useTagGroup_unstable } from './useTagGroup'; | ||
| import { renderTagGroup_unstable } from './renderTagGroup'; | ||
| import { useTagGroupStyles_unstable } from './useTagGroupStyles.styles'; | ||
| import type { TagGroupProps } from './TagGroup.types'; | ||
| import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
| import { useTagGroupContextValues_unstable } from './useTagGroupContextValues'; | ||
|
|
||
| /** | ||
| * TagGroup component - TODO: add more docs | ||
| */ | ||
| export const TagGroup: ForwardRefComponent<TagGroupProps> = React.forwardRef((props, ref) => { | ||
| const state = useTagGroup_unstable(props, ref); | ||
|
|
||
| useTagGroupStyles_unstable(state); | ||
| return renderTagGroup_unstable(state, useTagGroupContextValues_unstable(state)); | ||
| }); | ||
|
|
||
| TagGroup.displayName = 'TagGroup'; |
23 changes: 23 additions & 0 deletions
23
packages/react-components/react-tags/src/components/TagGroup/TagGroup.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,23 @@ | ||
| import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
| import { TagSize } from '../Tag/Tag.types'; | ||
| import { TagGroupContextValue } from '../../contexts/TagGroupContext'; | ||
|
|
||
| export type TagGroupContextValues = { | ||
| tagGroup: TagGroupContextValue; | ||
| }; | ||
|
|
||
| export type TagGroupSlots = { | ||
| root: Slot<'div'>; | ||
| }; | ||
|
|
||
| /** | ||
| * TagGroup Props | ||
| */ | ||
| export type TagGroupProps = ComponentProps<TagGroupSlots> & { | ||
| size?: TagSize; | ||
| }; | ||
|
|
||
| /** | ||
| * State used in rendering TagGroup | ||
| */ | ||
| export type TagGroupState = ComponentState<TagGroupSlots> & Required<Pick<TagGroupProps, 'size'>>; | ||
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-tags/src/components/TagGroup/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 './TagGroup'; | ||
| export * from './TagGroup.types'; | ||
| export * from './renderTagGroup'; | ||
| export * from './useTagGroup'; | ||
| export * from './useTagGroupStyles.styles'; |
19 changes: 19 additions & 0 deletions
19
packages/react-components/react-tags/src/components/TagGroup/renderTagGroup.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 @@ | ||
| /** @jsxRuntime classic */ | ||
| /** @jsx createElement */ | ||
| import { createElement } from '@fluentui/react-jsx-runtime'; | ||
| import { getSlotsNext } from '@fluentui/react-utilities'; | ||
| import type { TagGroupState, TagGroupSlots, TagGroupContextValues } from './TagGroup.types'; | ||
| import { TagGroupContextProvider } from '../../contexts/TagGroupContext'; | ||
|
|
||
| /** | ||
| * Render the final JSX of TagGroup | ||
| */ | ||
| export const renderTagGroup_unstable = (state: TagGroupState, contextValue: TagGroupContextValues) => { | ||
| const { slots, slotProps } = getSlotsNext<TagGroupSlots>(state); | ||
|
|
||
| return ( | ||
| <TagGroupContextProvider value={contextValue.tagGroup}> | ||
| <slots.root {...slotProps.root} /> | ||
| </TagGroupContextProvider> | ||
| ); | ||
| }; |
28 changes: 28 additions & 0 deletions
28
packages/react-components/react-tags/src/components/TagGroup/useTagGroup.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,28 @@ | ||
| import * as React from 'react'; | ||
| import { getNativeElementProps } from '@fluentui/react-utilities'; | ||
| import type { TagGroupProps, TagGroupState } from './TagGroup.types'; | ||
|
|
||
| /** | ||
| * Create the state required to render TagGroup. | ||
| * | ||
| * The returned state can be modified with hooks such as useTagGroupStyles_unstable, | ||
| * before being passed to renderTagGroup_unstable. | ||
| * | ||
| * @param props - props from this instance of TagGroup | ||
| * @param ref - reference to root HTMLElement of TagGroup | ||
| */ | ||
| export const useTagGroup_unstable = (props: TagGroupProps, ref: React.Ref<HTMLElement>): TagGroupState => { | ||
| const { size = 'medium' } = props; | ||
|
|
||
| return { | ||
| size, | ||
| components: { | ||
| root: 'div', | ||
| }, | ||
| root: getNativeElementProps('div', { | ||
| ref, | ||
| ...props, | ||
| // TODO aria attributes | ||
| }), | ||
| }; | ||
| }; |
7 changes: 7 additions & 0 deletions
7
packages/react-components/react-tags/src/components/TagGroup/useTagGroupContextValues.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,7 @@ | ||
| import * as React from 'react'; | ||
| import type { TagGroupContextValues, TagGroupState } from './TagGroup.types'; | ||
|
|
||
| export function useTagGroupContextValues_unstable(state: TagGroupState): TagGroupContextValues { | ||
| const { size } = state; | ||
| return { tagGroup: React.useMemo(() => ({ size }), [size]) }; | ||
| } |
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.