@@ -29,6 +29,35 @@ import type {
2929} from './props'
3030import type { FormFieldLayoutTheme } from '@instructure/shared-types'
3131
32+ const generateGridLayout = (
33+ isInlineLayout : boolean ,
34+ hasNewErrorMsgAndIsGroup : boolean ,
35+ hasVisibleLabel : boolean ,
36+ hasMessages : boolean
37+ ) => {
38+ if ( isInlineLayout ) {
39+ if ( hasNewErrorMsgAndIsGroup ) {
40+ if ( hasMessages ) {
41+ return `${ hasVisibleLabel ? ' "label messages"' : '. messages' }
42+ ". controls"`
43+ } else {
44+ return `${ hasVisibleLabel ? ' "label controls"' : '. controls' } `
45+ }
46+ } else {
47+ return `${ hasVisibleLabel ? ' "label controls"' : '. controls' }
48+ ${ hasMessages ? ' ". messages"' : '' } `
49+ }
50+ }
51+ if ( hasNewErrorMsgAndIsGroup ) {
52+ return `${ hasVisibleLabel ? ' "label"' : '' }
53+ ${ hasMessages ? ' "messages"' : '' }
54+ "controls"`
55+ } else {
56+ return `${ hasVisibleLabel ? ' "label"' : '' }
57+ "controls"
58+ ${ hasMessages ? ' "messages"' : '' } `
59+ }
60+ }
3261/**
3362 * ---
3463 * private: true
@@ -45,28 +74,23 @@ const generateStyle = (
4574 styleProps : FormFieldStyleProps
4675) : FormFieldLayoutStyle => {
4776 const { inline, layout, vAlign, labelAlign } = props
48- const { hasMessages, hasVisibleLabel } = styleProps
49- // This is quite ugly, we should simplify it
50- const inlineContainerAndLabel = layout === 'inline' && ! inline
77+ const { hasMessages, hasVisibleLabel, hasNewErrorMsgAndIsGroup } = styleProps
5178 const isInlineLayout = layout === 'inline'
52- let gridTemplateColumns = '100%'
53- // stacked layout
54- let gridTemplateAreas = `${ hasVisibleLabel ? ' "label"' : '' }
55- "controls"
56- ${ hasMessages ? ' "messages"' : '' } `
79+ const inlineContainerAndLabel = isInlineLayout && ! inline
80+ // This is quite ugly, we should simplify it
81+ const gridTemplateAreas = generateGridLayout (
82+ isInlineLayout ,
83+ hasNewErrorMsgAndIsGroup ,
84+ hasVisibleLabel ,
85+ hasMessages
86+ )
87+ let gridTemplateColumns = '100%' // stacked layout, could be a Flex
5788 if ( isInlineLayout ) {
5889 gridTemplateColumns = '1fr 3fr'
59- gridTemplateAreas = `${ hasVisibleLabel ? ' "label controls"' : '. controls' }
60- ${ hasMessages ? '"messages messages"' : '' } `
6190 if ( inline ) {
6291 gridTemplateColumns = 'auto 3fr'
6392 }
6493 }
65- if ( inlineContainerAndLabel ) {
66- gridTemplateAreas = `${ hasVisibleLabel ? ' "label controls"' : '. controls' }
67- ${ hasMessages ? ' ". messages"' : '' } `
68- }
69-
7094 const labelStyles = {
7195 all : 'initial' ,
7296 display : 'block' ,
@@ -77,7 +101,6 @@ const generateStyle = (
77101 fontSize : componentTheme . fontSize ,
78102 lineHeight : componentTheme . lineHeight ,
79103 margin : '0 0 0.75rem 0' ,
80- textAlign : inlineContainerAndLabel ? 'end' : 'start' ,
81104 ...( isInlineLayout &&
82105 inline && {
83106 paddingRight : componentTheme . inlinePadding
@@ -88,9 +111,7 @@ const generateStyle = (
88111 } ) ,
89112 [ `@media screen and (min-width: ${ componentTheme . stackedOrInlineBreakpoint } )` ] :
90113 {
91- ...( isInlineLayout && {
92- textAlign : labelAlign
93- } )
114+ ...( isInlineLayout && { textAlign : labelAlign } )
94115 }
95116 }
96117
@@ -121,12 +142,13 @@ const generateStyle = (
121142 [ `@media screen and (max-width: ${ componentTheme . stackedOrInlineBreakpoint } )` ] :
122143 {
123144 // for small screens use the stacked layout
124- ...( isInlineLayout && {
125- gridTemplateAreas : `"label"
126- "controls"
127- ${ hasMessages ? '"messages"' : '' } ` ,
128- gridTemplateColumns : '100%'
129- } )
145+ gridTemplateColumns : '100%' ,
146+ gridTemplateAreas : generateGridLayout (
147+ false ,
148+ hasNewErrorMsgAndIsGroup ,
149+ hasVisibleLabel ,
150+ hasMessages
151+ )
130152 } ,
131153 columnGap : '0.375rem' ,
132154 width : '100%' ,
0 commit comments