@@ -12,12 +12,29 @@ import { Check, Information } from '@strapi/icons';
1212import { Layouts } from '@strapi/strapi/admin' ;
1313import React from 'react' ;
1414import { useIntl } from 'react-intl' ;
15+ import styled from 'styled-components' ;
1516import { NavigationSchema } from '../../../../api/validators' ;
1617import { getTrad } from '../../../../translations' ;
1718import { Effect } from '../../../../types' ;
18- import { useConfig } from '../../hooks' ;
19+ import { useConfig , usePluginMediaQuery } from '../../hooks' ;
1920import { useNavigationManager } from './hooks' ;
2021
22+ const StyledGridItem = styled ( Grid . Item ) < {
23+ orderInitial ?: number ;
24+ orderSmall ?: number ;
25+ orderMedium ?: number ;
26+ } > `
27+ order: ${ ( { orderInitial } ) => orderInitial ?? 'unset' } ;
28+
29+ @media (min-width: 520px) {
30+ order: ${ ( { orderSmall } ) => orderSmall ?? 'unset' } ;
31+ }
32+
33+ @media (min-width: 768px) {
34+ order: ${ ( { orderMedium } ) => orderMedium ?? 'unset' } ;
35+ }
36+ ` ;
37+
2138const submitIcon = < Check /> ;
2239
2340interface Props {
@@ -55,27 +72,41 @@ export const NavigationHeader: React.FC<Props> = ({
5572 const { formatMessage } = useIntl ( ) ;
5673 const { openNavigationManagerModal, navigationManagerModal } = useNavigationManager ( ) ;
5774
58- const hasLocalizations = ! ! locale . restLocale ;
75+ const configQuery = useConfig ( ) ;
76+
77+ const hasLocalizations = ! ! locale . restLocale ?. length ;
78+ const hasCache = configQuery . data ?. isCacheEnabled ;
5979
6080 const { canUpdate } = permissions ;
6181
62- const configQuery = useConfig ( ) ;
82+ const { isDesktop , isMobile , isLargeDesktop } = usePluginMediaQuery ( ) ;
6383
6484 return (
6585 < >
6686 < Layouts . Header
6787 title = { formatMessage ( getTrad ( 'header.title' , 'UI Navigation' ) ) }
68- subtitle = { formatMessage ( getTrad ( 'header.description' ) ) }
88+ subtitle = { isLargeDesktop && formatMessage ( getTrad ( 'header.description' ) ) }
6989 primaryAction = {
70- < Flex direction = "row" size = { 2 } >
71- < Box >
90+ < Flex
91+ direction = "row"
92+ size = { 2 }
93+ width = { isLargeDesktop ? 'auto' : ! isMobile ? '728px' : '100%' }
94+ >
95+ < Box width = "100%" >
7296 < Grid . Root
73- gap = { 4 }
97+ gap = { { initial : 2 , medium : 4 } }
98+ width = "100%"
7499 style = { configQuery . data ?. isCacheEnabled ? { display : 'flex' } : undefined }
75100 >
76- { ! hasLocalizations ? < Grid . Item col = { 2 } /> : null }
101+ { ! hasLocalizations && isLargeDesktop ? < Grid . Item m = { 2 } xs = { 0 } /> : null }
77102 { canUpdate && (
78- < Grid . Item col = { 3 } >
103+ < StyledGridItem
104+ m = { 3 }
105+ xs = { hasCache ? 4 : 6 }
106+ orderInitial = { 3 }
107+ orderSmall = { 3 }
108+ orderMedium = { 1 }
109+ >
79110 < Button
80111 onClick = { openNavigationManagerModal }
81112 startIcon = { null }
@@ -86,9 +117,15 @@ export const NavigationHeader: React.FC<Props> = ({
86117 >
87118 { formatMessage ( getTrad ( 'header.action.manage' ) ) }
88119 </ Button >
89- </ Grid . Item >
120+ </ StyledGridItem >
90121 ) }
91- < Grid . Item col = { canUpdate ? 4 : 10 } >
122+ < StyledGridItem
123+ m = { canUpdate ? 4 : 10 }
124+ xs = { hasLocalizations ? 9 : 12 }
125+ orderInitial = { 1 }
126+ orderSmall = { 1 }
127+ orderMedium = { 2 }
128+ >
92129 < Field . Root width = "100%" >
93130 < SingleSelect
94131 type = "select"
@@ -116,29 +153,37 @@ export const NavigationHeader: React.FC<Props> = ({
116153 ) ) }
117154 </ SingleSelect >
118155 </ Field . Root >
119- </ Grid . Item >
156+ </ StyledGridItem >
120157 { hasLocalizations ? (
121- < Grid . Item col = { 2 } >
122- < SingleSelect
123- type = "select"
124- placeholder = { formatMessage (
125- getTrad ( 'pages.main.header.localization.select.placeholder' )
126- ) }
127- name = "navigationLocalizationSelect"
128- onChange = { handleLocalizationSelection }
129- value = { currentLocale }
130- size = "S"
131- >
132- { [ locale . defaultLocale , ...locale . restLocale ] . map ( ( code ) => (
133- < SingleSelectOption key = { code } value = { code } >
134- { code }
135- </ SingleSelectOption >
136- ) ) }
137- </ SingleSelect >
138- </ Grid . Item >
158+ < StyledGridItem m = { 2 } xs = { 3 } orderInitial = { 2 } orderSmall = { 2 } orderMedium = { 3 } >
159+ < Field . Root width = "100%" >
160+ < SingleSelect
161+ type = "select"
162+ placeholder = { formatMessage (
163+ getTrad ( 'pages.main.header.localization.select.placeholder' )
164+ ) }
165+ name = "navigationLocalizationSelect"
166+ onChange = { handleLocalizationSelection }
167+ value = { currentLocale }
168+ size = "S"
169+ >
170+ { [ locale . defaultLocale , ...locale . restLocale ] . map ( ( code ) => (
171+ < SingleSelectOption key = { code } value = { code } >
172+ { code }
173+ </ SingleSelectOption >
174+ ) ) }
175+ </ SingleSelect >
176+ </ Field . Root >
177+ </ StyledGridItem >
139178 ) : null }
140179 { canUpdate && (
141- < Grid . Item col = { 3 } >
180+ < StyledGridItem
181+ m = { 3 }
182+ xs = { hasCache ? 4 : 6 }
183+ orderInitial = { 4 }
184+ orderSmall = { 4 }
185+ orderMedium = { 4 }
186+ >
142187 < Button
143188 onClick = { handleSave }
144189 startIcon = { submitIcon }
@@ -149,36 +194,43 @@ export const NavigationHeader: React.FC<Props> = ({
149194 >
150195 { formatMessage ( getTrad ( 'submit.cta.save' ) ) }
151196 </ Button >
152- </ Grid . Item >
197+ </ StyledGridItem >
153198 ) }
154- { configQuery . data ?. isCacheEnabled && (
155- < Grid . Item col = { 3 } >
156- < Button
157- onClick = { handleCachePurge }
158- startIcon = { submitIcon }
159- variant = "danger"
160- type = "submit"
161- fullWidth
162- size = "S"
163- >
164- { formatMessage ( getTrad ( 'submit.cta.cache.purge' ) ) }
165- </ Button >
166- </ Grid . Item >
199+ { hasCache && (
200+ < >
201+ { isDesktop && (
202+ < StyledGridItem m = { 9 } orderInitial = { 5 } orderSmall = { 5 } orderMedium = { 5 } />
203+ ) }
204+ < StyledGridItem m = { 3 } xs = { 4 } orderInitial = { 6 } orderSmall = { 6 } orderMedium = { 6 } >
205+ < Button
206+ onClick = { handleCachePurge }
207+ startIcon = { submitIcon }
208+ variant = "danger"
209+ type = "submit"
210+ fullWidth
211+ size = "S"
212+ >
213+ { formatMessage ( getTrad ( 'submit.cta.cache.purge' ) ) }
214+ </ Button >
215+ </ StyledGridItem >
216+ </ >
167217 ) }
168218 </ Grid . Root >
169219 </ Box >
170220 { canUpdate && navigationManagerModal }
171221 </ Flex >
172222 }
173223 secondaryAction = {
174- < Tag icon = { < Information aria-hidden = { true } /> } >
175- { activeNavigation
176- ? formatMessage ( getTrad ( 'header.meta' ) , {
177- id : activeNavigation ?. documentId ,
178- key : activeNavigation ?. slug ,
179- } )
180- : null }
181- </ Tag >
224+ ! isMobile && (
225+ < Tag icon = { < Information aria-hidden = { true } /> } >
226+ { activeNavigation
227+ ? formatMessage ( getTrad ( 'header.meta' ) , {
228+ id : activeNavigation ?. documentId ,
229+ key : activeNavigation ?. slug ,
230+ } )
231+ : null }
232+ </ Tag >
233+ )
182234 }
183235 />
184236 </ >
0 commit comments