forked from microsoft/fluentui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-tag-picker): adds TagPickerOptionGroup component (microsof…
- Loading branch information
1 parent
fe01c03
commit fd38bbc
Showing
15 changed files
with
240 additions
and
5 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-tag-picker-preview-fe30a51d-a476-480c-b7b5-22c1285c35ad.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": "patch", | ||
"comment": "feat: adds TagPickerOptionGroup component", | ||
"packageName": "@fluentui/react-tag-picker-preview", | ||
"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
1 change: 1 addition & 0 deletions
1
packages/react-components/react-tag-picker-preview/src/TagPickerOptionGroup.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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './components/TagPickerOptionGroup/index'; |
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
21 changes: 21 additions & 0 deletions
21
...eact-tag-picker-preview/src/components/TagPickerOptionGroup/TagPickerOptionGroup.test.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { isConformant } from '../../testing/isConformant'; | ||
import { TagPickerOptionGroup } from './TagPickerOptionGroup'; | ||
|
||
describe('TagPickerOptionGroup', () => { | ||
isConformant({ | ||
Component: TagPickerOptionGroup, | ||
displayName: 'TagPickerOptionGroup', | ||
requiredProps: { | ||
label: 'label', | ||
}, | ||
}); | ||
|
||
// TODO add more tests here, and create visual regression tests in /apps/vr-tests | ||
|
||
it('renders a default state', () => { | ||
const result = render(<TagPickerOptionGroup>Default TagPickerOptionGroup</TagPickerOptionGroup>); | ||
expect(result.container).toMatchSnapshot(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
...nts/react-tag-picker-preview/src/components/TagPickerOptionGroup/TagPickerOptionGroup.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as React from 'react'; | ||
import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
import { useTagPickerOptionGroup } from './useTagPickerOptionGroup'; | ||
import { renderTagPickerOptionGroup } from './renderTagPickerOptionGroup'; | ||
import { useTagPickerOptionGroupStyles } from './useTagPickerOptionGroupStyles.styles'; | ||
import type { TagPickerOptionGroupProps } from './TagPickerOptionGroup.types'; | ||
|
||
/** | ||
* TagPickerOptionGroup component - TODO: add more docs | ||
*/ | ||
export const TagPickerOptionGroup: ForwardRefComponent<TagPickerOptionGroupProps> = React.forwardRef((props, ref) => { | ||
const state = useTagPickerOptionGroup(props, ref); | ||
|
||
useTagPickerOptionGroupStyles(state); | ||
return renderTagPickerOptionGroup(state); | ||
}); | ||
|
||
TagPickerOptionGroup.displayName = 'TagPickerOptionGroup'; |
13 changes: 13 additions & 0 deletions
13
...eact-tag-picker-preview/src/components/TagPickerOptionGroup/TagPickerOptionGroup.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { OptionGroupProps, OptionGroupSlots, OptionGroupState } from '@fluentui/react-combobox'; | ||
|
||
export type TagPickerOptionGroupSlots = OptionGroupSlots; | ||
|
||
/** | ||
* TagPickerOptionGroup Props | ||
*/ | ||
export type TagPickerOptionGroupProps = OptionGroupProps; | ||
|
||
/** | ||
* State used in rendering TagPickerOptionGroup | ||
*/ | ||
export type TagPickerOptionGroupState = OptionGroupState; |
12 changes: 12 additions & 0 deletions
12
...view/src/components/TagPickerOptionGroup/__snapshots__/TagPickerOptionGroup.test.tsx.snap
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,12 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`TagPickerOptionGroup renders a default state 1`] = ` | ||
<div> | ||
<div | ||
class="fui-TagPickerOptionGroup fui-OptionGroup" | ||
role="group" | ||
> | ||
Default TagPickerOptionGroup | ||
</div> | ||
</div> | ||
`; |
5 changes: 5 additions & 0 deletions
5
...es/react-components/react-tag-picker-preview/src/components/TagPickerOptionGroup/index.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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from './TagPickerOptionGroup'; | ||
export * from './TagPickerOptionGroup.types'; | ||
export * from './renderTagPickerOptionGroup'; | ||
export * from './useTagPickerOptionGroup'; | ||
export * from './useTagPickerOptionGroupStyles.styles'; |
10 changes: 10 additions & 0 deletions
10
...act-tag-picker-preview/src/components/TagPickerOptionGroup/renderTagPickerOptionGroup.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** @jsxRuntime automatic */ | ||
/** @jsxImportSource @fluentui/react-jsx-runtime */ | ||
|
||
import type { TagPickerOptionGroupState } from './TagPickerOptionGroup.types'; | ||
import { renderOptionGroup_unstable } from '@fluentui/react-combobox'; | ||
|
||
/** | ||
* Render the final JSX of TagPickerOptionGroup | ||
*/ | ||
export const renderTagPickerOptionGroup: (state: TagPickerOptionGroupState) => JSX.Element = renderOptionGroup_unstable; |
17 changes: 17 additions & 0 deletions
17
...s/react-tag-picker-preview/src/components/TagPickerOptionGroup/useTagPickerOptionGroup.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as React from 'react'; | ||
import type { TagPickerOptionGroupProps, TagPickerOptionGroupState } from './TagPickerOptionGroup.types'; | ||
import { useOptionGroup_unstable } from '@fluentui/react-combobox'; | ||
|
||
/** | ||
* Create the state required to render TagPickerOptionGroup. | ||
* | ||
* The returned state can be modified with hooks such as useTagPickerOptionGroupStyles_unstable, | ||
* before being passed to renderTagPickerOptionGroup_unstable. | ||
* | ||
* @param props - props from this instance of TagPickerOptionGroup | ||
* @param ref - reference to root HTMLDivElement of TagPickerOptionGroup | ||
*/ | ||
export const useTagPickerOptionGroup: ( | ||
props: TagPickerOptionGroupProps, | ||
ref: React.Ref<HTMLDivElement>, | ||
) => TagPickerOptionGroupState = useOptionGroup_unstable; |
23 changes: 23 additions & 0 deletions
23
...icker-preview/src/components/TagPickerOptionGroup/useTagPickerOptionGroupStyles.styles.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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { mergeClasses } from '@griffel/react'; | ||
import type { SlotClassNames } from '@fluentui/react-utilities'; | ||
import type { TagPickerOptionGroupSlots, TagPickerOptionGroupState } from './TagPickerOptionGroup.types'; | ||
import { useOptionGroupStyles_unstable } from '@fluentui/react-combobox'; | ||
|
||
export const tagPickerOptionGroupClassNames: SlotClassNames<TagPickerOptionGroupSlots> = { | ||
root: 'fui-TagPickerOptionGroup', | ||
label: 'fui-TagPickerOptionGroup__label', | ||
}; | ||
|
||
/** | ||
* Apply styling to the TagPickerOptionGroup slots based on the state | ||
*/ | ||
export const useTagPickerOptionGroupStyles = (state: TagPickerOptionGroupState): TagPickerOptionGroupState => { | ||
useOptionGroupStyles_unstable(state); | ||
state.root.className = mergeClasses(tagPickerOptionGroupClassNames.root, state.root.className); | ||
|
||
if (state.label) { | ||
state.label.className = mergeClasses(tagPickerOptionGroupClassNames.label, state.label.className); | ||
} | ||
|
||
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
71 changes: 71 additions & 0 deletions
71
.../react-components/react-tag-picker-preview/stories/TagPicker/TagPickerGrouped.stories.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import * as React from 'react'; | ||
import { | ||
TagPicker, | ||
TagPickerList, | ||
TagPickerInput, | ||
TagPickerControl, | ||
TagPickerProps, | ||
TagPickerOption, | ||
TagPickerGroup, | ||
TagPickerOptionGroup, | ||
} from '@fluentui/react-tag-picker-preview'; | ||
import { Tag, Avatar } from '@fluentui/react-components'; | ||
|
||
const managers = ['John Doe', 'Jane Doe', 'Max Mustermann', 'Erika Mustermann']; | ||
const devs = ['Pierre Dupont', 'Amelie Dupont', 'Mario Rossi', 'Maria Rossi']; | ||
|
||
export const Grouped = () => { | ||
const [selectedOptions, setSelectedOptions] = React.useState<string[]>([]); | ||
const onOptionSelect: TagPickerProps['onOptionSelect'] = (e, data) => { | ||
setSelectedOptions(data.selectedOptions); | ||
}; | ||
const unSelectedManagers = managers.filter(option => !selectedOptions.includes(option)); | ||
const unSelectedDevs = devs.filter(option => !selectedOptions.includes(option)); | ||
|
||
return ( | ||
<div style={{ maxWidth: 400 }}> | ||
<TagPicker onOptionSelect={onOptionSelect} selectedOptions={selectedOptions}> | ||
<TagPickerControl> | ||
<TagPickerGroup> | ||
{selectedOptions.map(option => ( | ||
<Tag key={option} shape="rounded" media={<Avatar name={option} color="colorful" />} value={option}> | ||
{option} | ||
</Tag> | ||
))} | ||
</TagPickerGroup> | ||
<TagPickerInput /> | ||
</TagPickerControl> | ||
<TagPickerList> | ||
{unSelectedManagers.length > 0 && ( | ||
<TagPickerOptionGroup label="Managers"> | ||
{unSelectedManagers.map(option => ( | ||
<TagPickerOption | ||
secondaryContent="Microsoft FTE" | ||
media={<Avatar name={option} color="colorful" />} | ||
value={option} | ||
key={option} | ||
> | ||
{option} | ||
</TagPickerOption> | ||
))} | ||
</TagPickerOptionGroup> | ||
)} | ||
{unSelectedDevs.length > 0 && ( | ||
<TagPickerOptionGroup label="Devs"> | ||
{unSelectedDevs.map(option => ( | ||
<TagPickerOption | ||
secondaryContent="Microsoft FTE" | ||
media={<Avatar name={option} color="colorful" />} | ||
value={option} | ||
key={option} | ||
> | ||
{option} | ||
</TagPickerOption> | ||
))} | ||
</TagPickerOptionGroup> | ||
)} | ||
</TagPickerList> | ||
</TagPicker> | ||
</div> | ||
); | ||
}; |
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