Skip to content

Commit 2afd55e

Browse files
committed
refactor(ui-form-field): small layout fixes, simplify code
1 parent 0b7c79c commit 2afd55e

File tree

1 file changed

+15
-15
lines changed
  • packages/ui-form-field/src/FormFieldLayout

1 file changed

+15
-15
lines changed

packages/ui-form-field/src/FormFieldLayout/styles.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const generateGridLayout = (
4848
${hasMessages ? ' ". messages"' : ''}`
4949
}
5050
}
51+
// stacked layout -- in this case we could use a simple `Flex`
5152
if (hasNewErrorMsgAndIsGroup) {
5253
return `${hasVisibleLabel ? ' "label"' : ''}
5354
${hasMessages ? ' "messages"' : ''}
@@ -76,15 +77,14 @@ const generateStyle = (
7677
const { inline, layout, vAlign, labelAlign } = props
7778
const { hasMessages, hasVisibleLabel, hasNewErrorMsgAndIsGroup } = styleProps
7879
const isInlineLayout = layout === 'inline'
79-
const inlineContainerAndLabel = isInlineLayout && !inline
8080
// This is quite ugly, we should simplify it
8181
const gridTemplateAreas = generateGridLayout(
8282
isInlineLayout,
8383
hasNewErrorMsgAndIsGroup,
8484
hasVisibleLabel,
8585
hasMessages
8686
)
87-
let gridTemplateColumns = '100%' // stacked layout, could be a Flex
87+
let gridTemplateColumns = '100%' // stacked layout
8888
if (isInlineLayout) {
8989
gridTemplateColumns = '1fr 3fr'
9090
if (inline) {
@@ -101,18 +101,15 @@ const generateStyle = (
101101
fontSize: componentTheme.fontSize,
102102
lineHeight: componentTheme.lineHeight,
103103
margin: '0 0 0.75rem 0',
104-
...(isInlineLayout &&
105-
inline && {
106-
paddingRight: componentTheme.inlinePadding
107-
}),
108-
...(inlineContainerAndLabel && {
109-
paddingLeft: componentTheme.inlinePadding,
110-
paddingRight: componentTheme.inlinePadding
111-
}),
112-
[`@media screen and (min-width: ${componentTheme.stackedOrInlineBreakpoint})`]:
113-
{
114-
...(isInlineLayout && { textAlign: labelAlign })
115-
}
104+
...(isInlineLayout && {
105+
// when inline add a small padding between the label and the control
106+
paddingRight: componentTheme.inlinePadding,
107+
// and use the horizontal alignment prop
108+
[`@media screen and (min-width: ${componentTheme.stackedOrInlineBreakpoint})`]:
109+
{
110+
textAlign: labelAlign
111+
}
112+
})
116113
}
117114

118115
let alignItems = 'start'
@@ -169,7 +166,10 @@ const generateStyle = (
169166
formFieldChildren: {
170167
label: 'formFieldLayout__children',
171168
gridArea: 'controls',
172-
...(hasMessages && { marginBottom: '0.75rem' }),
169+
// add a small margin between the message and the controls
170+
...(hasMessages && hasNewErrorMsgAndIsGroup && { marginTop: '0.375rem' }),
171+
...(hasMessages &&
172+
!hasNewErrorMsgAndIsGroup && { marginBottom: '0.75rem' }),
173173
...(isInlineLayout &&
174174
inline && {
175175
[`@media screen and (min-width: ${componentTheme.stackedOrInlineBreakpoint})`]:

0 commit comments

Comments
 (0)