@@ -4,43 +4,22 @@ import cloneDeep from "lodash/cloneDeep";
4
4
5
5
import {
6
6
Box ,
7
- ButtonContent ,
8
- ComponentEventHandler ,
9
- ObjectShorthandCollection ,
10
- Position ,
11
7
PropsOfElement ,
12
8
ProviderConsumer as FluentUIThemeConsumer ,
13
- ShorthandCollection ,
14
9
Toolbar as FluentUIToolbar ,
15
- ToolbarItemProps ,
16
- ToolbarItemShorthandKinds ,
17
- Tooltip ,
18
- TreeItemProps ,
19
- tooltipAsLabelBehavior ,
20
10
teamsTheme ,
21
11
} from "@fluentui/react-northstar" ;
22
12
23
13
import { SiteVariablesPrepared } from "@fluentui/styles" ;
24
-
25
- import { TAction , TActions } from "../../common/model/TAction" ;
26
-
27
14
import { ToolbarFilter } from "./ToolbarFilter" ;
28
15
import { ToolbarFind } from "./ToolbarFind" ;
29
16
import { ToolbarTheme } from "./ToolbarTheme" ;
30
17
31
18
import "./toolbar.css" ;
32
19
import { Icon } from "office-ui-fabric-react/lib/components/Icon/Icon" ;
33
-
34
- type TToolbarItems = ShorthandCollection <
35
- ToolbarItemProps ,
36
- ToolbarItemShorthandKinds
37
- > ;
38
-
39
- export type TActionGroups = {
40
- [ slug : string ] : TActions ;
41
- } ;
42
-
43
- export type TFilters = ObjectShorthandCollection < TreeItemProps , never > ;
20
+ import { InFlowToolbarItem , toolbarMenuProps } from "./InFlowToolbarItem" ;
21
+ import styles from "./Toolbar.module.scss" ;
22
+ import { flattenedActions , getInFlowToolbarItems , getOverflowToolbarItems , TActionGroups , TFilters , TToolbarItems , TToolbarLayout } from "./ToolbarActionsUtils" ;
44
23
45
24
export interface IToolbarProps extends PropsOfElement < "div" > {
46
25
actionGroups : TActionGroups ;
@@ -49,116 +28,8 @@ export interface IToolbarProps extends PropsOfElement<"div"> {
49
28
filtersSingleSelect ?: boolean ;
50
29
onSelectedFiltersChange ?: ( selectedFilters : string [ ] ) => string [ ] ;
51
30
onFindQueryChange ?: ( findQuery : string ) => string ;
52
- __internal_callbacks__ ?: {
53
- [ callbackId : string ] : ComponentEventHandler < ToolbarItemProps > ;
54
- } ;
55
31
}
56
32
57
- export type TToolbarLayout = "compact" | "verbose" ;
58
-
59
- const slugSeparator = "__" ;
60
-
61
- const toolbarMenuProps = {
62
- offset : [ 0 , 4 ] as [ number , number ] ,
63
- position : "below" as Position ,
64
- } ;
65
-
66
- const toolbarActionTooltipProps = ( ( ) => {
67
- const props = cloneDeep ( toolbarMenuProps ) ;
68
- props . offset [ 1 ] += 10 ;
69
- return props ;
70
- } ) ( ) ;
71
-
72
- const toolbarButtonStyles = {
73
- padding : ".5rem" ,
74
- borderWidth : "1px" ,
75
- marginTop : 0 ,
76
- marginBottom : 0 ,
77
- height : "3rem" ,
78
- minWidth : 0 ,
79
- "&:focus:before" : {
80
- top : "calc(.5rem - 1px)" ,
81
- bottom : "calc(.5rem - 1px)" ,
82
- } ,
83
- "&:focus:after" : {
84
- top : "calc(.5rem - 1px)" ,
85
- bottom : "calc(.5rem - 1px)" ,
86
- } ,
87
- } ;
88
-
89
- function flattenedActions ( actionGroups : TActionGroups ) : TActions {
90
- return Object . keys ( actionGroups ) . reduce (
91
- ( acc_i : TActions , actionGroupSlug : string ) => {
92
- const actionGroup = actionGroups [ actionGroupSlug ] ;
93
- return Object . keys ( actionGroup ) . reduce ( ( acc_j , actionSlug ) => {
94
- const action = actionGroup [ actionSlug ] ;
95
- acc_j [ `${ actionGroupSlug } ${ slugSeparator } ${ actionSlug } ` ] = action ;
96
- return acc_j ;
97
- } , acc_i ) ;
98
- } ,
99
- { }
100
- ) ;
101
- }
102
-
103
- function needsSeparator (
104
- actionSlug : string ,
105
- index : number ,
106
- actionSlugs : string [ ]
107
- ) : boolean {
108
- if ( index === 0 ) {
109
- return false ;
110
- }
111
- else if ( actionSlugs [ index - 1 ] ) {
112
- return actionSlugs [ index - 1 ] . split ( slugSeparator ) [ 0 ] !==
113
- actionSlug . split ( slugSeparator ) [ 0 ] ;
114
- }
115
- }
116
-
117
- interface IInFlowToolbarItemProps {
118
- action : TAction ;
119
- layout : TToolbarLayout ;
120
- }
121
-
122
- const InFlowToolbarItem = ( { action, layout } : IInFlowToolbarItemProps ) => {
123
- const { iconName, title } = action ;
124
- const contentIcon = iconName && (
125
- < Box
126
- styles = { {
127
- width : "1rem" ,
128
- display : "inline-flex" ,
129
- justifyContent : "center" ,
130
- alignItems : "center" ,
131
- "@media (min-width: 640px)" : {
132
- marginRight : ".5rem" ,
133
- } ,
134
- } }
135
- className = "extended-toolbar__near-side__item__icon"
136
- >
137
- < Icon iconName = { iconName } />
138
- </ Box >
139
- ) ;
140
-
141
- switch ( layout ) {
142
- case "verbose" :
143
- return (
144
- < >
145
- { contentIcon }
146
- < ButtonContent content = { title } />
147
- </ >
148
- ) ;
149
- default :
150
- case "compact" :
151
- return (
152
- < Tooltip
153
- { ...toolbarActionTooltipProps }
154
- trigger = { contentIcon }
155
- content = { title }
156
- accessibility = { tooltipAsLabelBehavior }
157
- />
158
- ) ;
159
- }
160
- } ;
161
-
162
33
export const Toolbar = ( props : IToolbarProps ) => {
163
34
const { actionGroups, filters, filtersSingleSelect, find } = props ;
164
35
@@ -189,57 +60,10 @@ export const Toolbar = (props: IToolbarProps) => {
189
60
} ;
190
61
} ) ;
191
62
192
- const inFlowToolbarItems : TToolbarItems = Object . keys ( allActions ) . reduce (
193
- ( acc : TToolbarItems , actionSlug , index , actionSlugs ) => {
194
- const action = allActions [ actionSlug ] ;
195
- acc . push ( {
196
- ...action ,
197
- key : actionSlug ,
198
- children : < InFlowToolbarItem action = { action } layout = { layout } /> ,
199
- title : action . title ,
200
- "aria-label" : action . title ,
201
- className : "extended-toolbar__near-side__item" ,
202
- styles : {
203
- ...toolbarButtonStyles ,
204
- flex : "0 0 auto" ,
205
- margin : "0 .0625rem" ,
206
- display : "inline-flex" ,
207
- justifyContent : "center" ,
208
- alignItems : "center" ,
209
- } ,
210
- } ) ;
211
- if ( needsSeparator ( actionSlug , index , actionSlugs ) )
212
- acc . push ( {
213
- key : `divider${ slugSeparator } ${ index } ` ,
214
- kind : "divider" ,
215
- } ) ;
216
- return acc ;
217
- } ,
218
- [ ]
219
- ) ;
220
-
221
- const overflowToolbarItems : TToolbarItems = Object . keys ( allActions ) . reduce (
222
- ( acc : TToolbarItems , actionSlug , index , actionSlugs ) => {
223
- const action = allActions [ actionSlug ] ;
224
- acc . push ( {
225
- key : actionSlug ,
226
- content : action . title ,
227
- icon : < Icon iconName = { action . iconName } /> ,
228
- title : action . title ,
229
- "aria-label" : action . title ,
230
- styles : { padding : ".375rem .5rem" } ,
231
- } ) ;
232
- if ( needsSeparator ( actionSlug , index , actionSlugs ) )
233
- acc . push ( {
234
- key : `divider${ slugSeparator } ${ index } ` ,
235
- kind : "divider" ,
236
- styles : { margin : ".25rem 0" , "&:first-child" : { display : "none" } } ,
237
- } ) ;
238
- return acc ;
239
- } ,
240
- [ ]
241
- ) ;
63
+ const inFlowToolbarItems : TToolbarItems = getInFlowToolbarItems ( allActions , ( action ) => < InFlowToolbarItem action = { action } layout = { layout } /> ) ;
242
64
65
+ const overflowToolbarItems : TToolbarItems = getOverflowToolbarItems ( allActions , ( action ) => < Icon iconName = { action . iconName } /> ) ;
66
+
243
67
const displayFindOnly = find && layout === "compact" && findActive ;
244
68
245
69
return (
@@ -277,14 +101,13 @@ export const Toolbar = (props: IToolbarProps) => {
277
101
{ ! displayFindOnly && (
278
102
< FluentUIToolbar
279
103
aria-label = "Extended toolbar"
280
- className = "extended-toolbar__near-side"
104
+ className = { "extended-toolbar__near-side " + styles . toolbarButtonStyles }
281
105
items = { inFlowToolbarItems }
282
106
overflow
283
107
overflowOpen = { overflowOpen }
284
108
overflowItem = { {
285
109
title : "More" ,
286
110
menu : toolbarMenuProps ,
287
- styles : toolbarButtonStyles ,
288
111
} }
289
112
onOverflowOpenChange = { ( event , changeProps ) => {
290
113
if ( changeProps && changeProps . overflowOpen ) {
@@ -324,14 +147,15 @@ export const Toolbar = (props: IToolbarProps) => {
324
147
onOpenChange = { ( _e , changeProps ) => {
325
148
if ( changeProps . open ) {
326
149
setFiltersOpen ( changeProps . open ) ;
327
- if ( changeProps . open ) {
328
- setOverflowOpen ( false ) ;
329
- }
150
+ setOverflowOpen ( false ) ;
151
+ }
152
+ else {
153
+ setFiltersOpen ( false ) ;
154
+ setOverflowOpen ( ! false ) ;
330
155
}
331
156
} }
332
157
onSelectedFiltersChange = { props . onSelectedFiltersChange }
333
158
toolbarMenuProps = { toolbarMenuProps }
334
- toolbarButtonStyles = { toolbarButtonStyles }
335
159
/>
336
160
) }
337
161
{ find && (
@@ -340,7 +164,6 @@ export const Toolbar = (props: IToolbarProps) => {
340
164
layout,
341
165
findActive,
342
166
setFindActive,
343
- toolbarButtonStyles,
344
167
onFindQueryChange : props . onFindQueryChange ,
345
168
} }
346
169
/>
0 commit comments