-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathVideoBackgroundEffectsPicker.tsx
More file actions
121 lines (105 loc) · 3.27 KB
/
VideoBackgroundEffectsPicker.tsx
File metadata and controls
121 lines (105 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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;
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>
);
};