-
Notifications
You must be signed in to change notification settings - Fork 78
[Component and Story] Add background picker component #2792
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
Changes from 10 commits
4ee8245
cf3a51b
1eb3c47
d144bd3
329ed8d
bcf03ee
0f8eb9e
b404553
200600c
f8ca7aa
626ed53
442935f
5b40a79
439b971
21df880
b1376b1
fe20d40
5e22ac2
b06d8d2
7c6d15f
544838d
5ac9ba2
b2ab508
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "Add Video background effects picker component", | ||
| "packageName": "@azure/communication-react", | ||
| "email": "2684369+JamesBurnside@users.noreply.github.com", | ||
| "dependentChangeType": "patch" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "Add video background effect choice items for upcoming background picker", | ||
| "packageName": "@azure/communication-react", | ||
| "email": "2684369+JamesBurnside@users.noreply.github.com", | ||
| "dependentChangeType": "patch" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "Add Video background effects picker component", | ||
| "packageName": "@azure/communication-react", | ||
| "email": "2684369+JamesBurnside@users.noreply.github.com", | ||
| "dependentChangeType": "patch" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "Add video background effect choice items for upcoming background picker", | ||
| "packageName": "@azure/communication-react", | ||
| "email": "2684369+JamesBurnside@users.noreply.github.com", | ||
| "dependentChangeType": "patch" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import React from 'react'; | ||
| import { _VideoEffectsItem, _VideoEffectsItemProps } from './VideoEffectsItem'; | ||
|
|
||
| /** | ||
| * 'None' Video Effects Item. | ||
| * | ||
| * @internal | ||
| */ | ||
| export const _VideoEffectsItemNone = (props: _VideoEffectsItemProps): JSX.Element => { | ||
| const iconProps = props.iconProps ?? { | ||
| iconName: 'VideoEffectsNone' | ||
| }; | ||
| const title = props.title ?? 'None'; | ||
| const tooltipProps = props.tooltipProps ?? { | ||
| content: props.title ?? 'Remove Background' | ||
| }; | ||
|
|
||
| return <_VideoEffectsItem {...props} iconProps={iconProps} title={title} tooltipProps={tooltipProps} />; | ||
| }; | ||
|
|
||
| /** | ||
| * 'Blur' Video Effects Item. | ||
| * | ||
| * @internal | ||
| */ | ||
| export const _VideoEffectsItemBlur = (props: _VideoEffectsItemProps): JSX.Element => { | ||
| const iconProps = props.iconProps ?? { | ||
| iconName: 'VideoEffectsBlur' | ||
| }; | ||
| const title = props.title ?? 'Blurred'; | ||
| const tooltipProps = props.tooltipProps ?? { | ||
| content: props.title ?? 'Blur Background' | ||
| }; | ||
|
|
||
| return <_VideoEffectsItem {...props} iconProps={iconProps} title={title} tooltipProps={tooltipProps} />; | ||
| }; | ||
|
|
||
| /** | ||
| * 'Add Image' Video Effects Item. | ||
| * | ||
| * @internal | ||
| */ | ||
| export const _VideoEffectsItemAddImage = (props: _VideoEffectsItemProps): JSX.Element => { | ||
| const iconProps = props.iconProps ?? { | ||
| iconName: 'VideoEffectsAddImage' | ||
| }; | ||
| const title = props.title ?? 'Image'; | ||
| const tooltipProps = props.tooltipProps ?? { | ||
| content: props.title ?? 'Upload Background Image' | ||
| }; | ||
|
|
||
| return <_VideoEffectsItem {...props} iconProps={iconProps} title={title} tooltipProps={tooltipProps} />; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import { IStyle, Label, mergeStyles, Stack } from '@fluentui/react'; | ||
| import React from 'react'; | ||
| import { chunk } from '../utils'; | ||
| import { _VideoEffectsItem, _VideoEffectsItemProps } from './VideoEffectsItem'; | ||
|
|
||
| /** | ||
| * Props for {@link _VideoBackgroundEffectsPicker} | ||
| * @internal | ||
| */ | ||
| export interface _VideoBackgroundEffectsPickerProps { | ||
| /** | ||
| * The options to display in the picker. | ||
| */ | ||
| options: _VideoBackgroundEffectChoiceOption[]; | ||
|
|
||
| /** | ||
| * The key of the current selected Video Background Effect. | ||
| * If you provide this, you must maintain selection state by observing onChange events and passing a new value in when changed. | ||
| */ | ||
| selectedEffectKey?: string; | ||
|
|
||
| /** | ||
| * Callback to invoke when a Video Background Effect is selected. | ||
| * @param effectKey - The key of the Video Background Effect that was selected. | ||
| */ | ||
| onChange?: (effectKey: string) => void; | ||
|
|
||
| /** | ||
| * The label to display for the picker. | ||
| */ | ||
| label?: string; | ||
|
|
||
| /** | ||
| * The number of items to display per row. | ||
| * @default 3 | ||
| */ | ||
| itemsPerRow?: 'wrap' | number; | ||
|
|
||
| /** | ||
| * Styles for the picker. | ||
| */ | ||
| styles?: _VideoBackgroundEffectsPickerStyles; | ||
| } | ||
|
|
||
| /** | ||
| * Option for the {@link _VideoBackgroundEffectsPicker}. | ||
| * @internal | ||
| */ | ||
| export type _VideoBackgroundEffectChoiceOption = _VideoEffectsItemProps; | ||
|
|
||
| /** | ||
| * Styles for the {@link _VideoBackgroundEffectsPicker}. | ||
| * @internal | ||
| */ | ||
| export interface _VideoBackgroundEffectsPickerStyles { | ||
| /** | ||
| * Styles for the root element. | ||
| */ | ||
| root?: IStyle; | ||
|
|
||
| /** | ||
| * Styles for the label. | ||
| */ | ||
| label?: IStyle; | ||
|
|
||
| /** | ||
| * Styles for the root of each row element. | ||
| */ | ||
| rowRoot?: IStyle; | ||
| } | ||
|
|
||
| /** | ||
| * Picker for choosing a Video Background Effect. | ||
| * | ||
| * @remarks | ||
| * This functions similar to a radio group of buttons, where the user can select one of the options. | ||
| * | ||
| * @internal | ||
| */ | ||
| export const _VideoBackgroundEffectsPicker = (props: _VideoBackgroundEffectsPickerProps): JSX.Element => { | ||
| const [componentControlledSelectedEffectKey, setComponentControlledSelectedEffectKey] = React.useState< | ||
| string | undefined | ||
| >(props.selectedEffectKey); | ||
|
|
||
| const selectedEffect = props.selectedEffectKey ?? componentControlledSelectedEffectKey; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the selectedEffect provided is not present/removed should we console warn like when a pinned participant id is not one of the remote participants as shown here?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an excellent comment! Added. This also pointed me to this: https://github.com/microsoft/fluentui/blob/306fe5e1e38b36e84daf48a23817704416be2bb4/packages/utilities/src/warn/warnControlledUsage.ts#L31. Turns out fluent exports a component for warning against bad controlled component use! It has other warnings too in |
||
| const setSelectedEffect = (selectedEffectKey: string): void => { | ||
| setComponentControlledSelectedEffectKey(selectedEffectKey); | ||
| props.onChange?.(selectedEffectKey); | ||
| }; | ||
|
|
||
| const convertedOptions: _VideoEffectsItemProps[] = props.options.map((option) => ({ | ||
| isSelected: option.key === selectedEffect, | ||
| onSelect: () => setSelectedEffect(option.key), | ||
| ...option | ||
| })); | ||
|
|
||
| const optionsByRow = | ||
| props.itemsPerRow === 'wrap' ? [convertedOptions] : chunk(convertedOptions, props.itemsPerRow ?? 3); | ||
|
|
||
| return ( | ||
| <Stack tokens={{ childrenGap: '0.5rem' }}> | ||
| <Label className={mergeStyles(props.styles?.label)}>{props.label}</Label> | ||
| {optionsByRow.map((options, rowIndex) => ( | ||
| <Stack | ||
| className={mergeStyles(props.styles?.rowRoot)} | ||
| wrap={props.itemsPerRow === 'wrap'} | ||
| horizontal | ||
| key={rowIndex} | ||
| tokens={{ childrenGap: '0.5rem' }} | ||
| > | ||
| {options.map((option) => ( | ||
| <_VideoEffectsItem {...option} key={option.key} /> | ||
| ))} | ||
| </Stack> | ||
| ))} | ||
| </Stack> | ||
| ); | ||
| }; | ||
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.
Nice controlled component concept such that if this is not defined the component will manage the state but if defined the user must manage the state through the onChange event.