fix(ui): fix field title styling

This commit is contained in:
psychedelicious 2023-12-30 09:13:23 +11:00 committed by Kent Keirsey
parent 966919ea4a
commit 2a41fd0b29
5 changed files with 82 additions and 92 deletions

View File

@ -6,7 +6,7 @@ import {
forwardRef, forwardRef,
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import { InvControlGroupContext } from 'common/components/InvControl/InvControlGroup'; import { InvControlGroupContext } from 'common/components/InvControl/InvControlGroup';
import { memo, useContext } from 'react'; import { memo, useContext, useMemo } from 'react';
import { InvLabel } from './InvLabel'; import { InvLabel } from './InvLabel';
import type { InvControlProps } from './types'; import type { InvControlProps } from './types';
@ -18,9 +18,9 @@ export const InvControl = memo(
children, children,
helperText, helperText,
feature, feature,
orientation, orientation: _orientation,
renderInfoPopoverInPortal = true, renderInfoPopoverInPortal = true,
isDisabled, isDisabled: _isDisabled,
labelProps, labelProps,
label, label,
error, error,
@ -29,15 +29,24 @@ export const InvControl = memo(
const ctx = useContext(InvControlGroupContext); const ctx = useContext(InvControlGroupContext);
const orientation = useMemo(
() => _orientation ?? ctx.orientation,
[_orientation, ctx.orientation]
);
const isDisabled = useMemo(
() => _isDisabled ?? ctx.isDisabled,
[_isDisabled, ctx.isDisabled]
);
return ( return (
<ChakraFormControl <ChakraFormControl
ref={ref} ref={ref}
variant="withHelperText" orientation={orientation}
orientation={orientation ?? ctx.orientation} isDisabled={isDisabled}
isDisabled={isDisabled ?? ctx.isDisabled}
{...formControlProps} {...formControlProps}
> >
<Flex> <Flex className="invcontrol-label-input-wrapper">
{label && ( {label && (
<InvLabel <InvLabel
feature={feature} feature={feature}
@ -55,26 +64,6 @@ export const InvControl = memo(
{error && <ChakraFormErrorMessage>{error}</ChakraFormErrorMessage>} {error && <ChakraFormErrorMessage>{error}</ChakraFormErrorMessage>}
</ChakraFormControl> </ChakraFormControl>
); );
return (
<ChakraFormControl
ref={ref}
isDisabled={isDisabled ?? ctx.isDisabled}
orientation={orientation ?? ctx.orientation}
{...formControlProps}
>
{label && (
<InvLabel
feature={feature}
renderInfoPopoverInPortal={renderInfoPopoverInPortal}
{...labelProps}
>
{label}
</InvLabel>
)}
{children}
</ChakraFormControl>
);
} }
) )
); );

View File

@ -13,29 +13,22 @@ const {
defineMultiStyleConfig: defineFormMultiStyleConfig, defineMultiStyleConfig: defineFormMultiStyleConfig,
} = createMultiStyleConfigHelpers(formParts.keys); } = createMultiStyleConfigHelpers(formParts.keys);
const formBaseStyle = defineFormPartsStyle((props) => { const formBaseStyle = defineFormPartsStyle((props) => ({
return {
container: { container: {
flexDirection: 'column',
alignItems: 'flex-start',
gap: 4,
h: 'unset',
'> .invcontrol-label-input-wrapper': {
display: 'flex', display: 'flex',
flexDirection: props.orientation === 'vertical' ? 'column' : 'row', flexDirection: props.orientation === 'vertical' ? 'column' : 'row',
alignItems: props.orientation === 'vertical' ? 'flex-start' : 'center', alignItems: props.orientation === 'vertical' ? 'flex-start' : 'center',
gap: props.orientation === 'vertical' ? 2 : 4, gap: props.orientation === 'vertical' ? 2 : 4,
}, minH: 8,
};
});
const withHelperText = defineFormPartsStyle(() => ({
container: {
flexDirection: 'column',
gap: 0,
h: 'unset',
'> div': {
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
gap: 4,
h: 8,
w: 'full', w: 'full',
_invalid: {
color: 'error.300',
},
}, },
}, },
helperText: { helperText: {
@ -48,9 +41,6 @@ const withHelperText = defineFormPartsStyle(() => ({
export const formTheme = defineFormMultiStyleConfig({ export const formTheme = defineFormMultiStyleConfig({
baseStyle: formBaseStyle, baseStyle: formBaseStyle,
variants: {
withHelperText,
},
}); });
const formLabelBaseStyle = defineStyle(() => { const formLabelBaseStyle = defineStyle(() => {
@ -65,6 +55,8 @@ const formLabelBaseStyle = defineStyle(() => {
transitionDuration: 'normal', transitionDuration: 'normal',
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
userSelect: 'none', userSelect: 'none',
h: 'full',
alignItems: 'center',
_disabled: { _disabled: {
opacity: 0.4, opacity: 0.4,
}, },

View File

@ -8,17 +8,20 @@ const { definePartsStyle, defineMultiStyleConfig } =
createMultiStyleConfigHelpers(parts.keys); createMultiStyleConfigHelpers(parts.keys);
const baseStylePreview = defineStyle({ const baseStylePreview = defineStyle({
fontSize: 'md', fontSize: 'sm',
borderRadius: 'md', borderRadius: 'md',
py: '1', py: '1',
transitionProperty: 'common', transitionProperty: 'common',
transitionDuration: 'normal', transitionDuration: 'normal',
color: 'base.100', color: 'base.100',
_invalid: {
color: 'error.300'
}
}); });
const baseStyleInput = defineStyle(() => ({ const baseStyleInput = defineStyle(() => ({
color: 'base.100', color: 'base.100',
fontSize: 'md', fontSize: 'sm',
borderRadius: 'md', borderRadius: 'md',
py: '1', py: '1',
transitionProperty: 'common', transitionProperty: 'common',

View File

@ -77,7 +77,11 @@ const EditableFieldTitle = forwardRef((props: Props, ref) => {
} }
openDelay={HANDLE_TOOLTIP_OPEN_DELAY} openDelay={HANDLE_TOOLTIP_OPEN_DELAY}
> >
<Flex <Editable
value={localTitle}
onChange={handleChange}
onSubmit={handleSubmit}
as={Flex}
ref={ref} ref={ref}
position="relative" position="relative"
overflow="hidden" overflow="hidden"
@ -85,25 +89,16 @@ const EditableFieldTitle = forwardRef((props: Props, ref) => {
justifyContent="flex-start" justifyContent="flex-start"
gap={1} gap={1}
h="full" h="full"
>
<Editable
value={localTitle}
onChange={handleChange}
onSubmit={handleSubmit}
as={Flex}
position="relative"
alignItems="center"
h="full"
> >
<EditablePreview <EditablePreview
fontWeight={isMissingInput ? 'bold' : 'normal'} fontWeight="semibold"
sx={editablePreviewStyles} sx={editablePreviewStyles}
noOfLines={1} noOfLines={1}
color={isMissingInput ? 'error.300' : 'base.300'}
/> />
<EditableInput className="nodrag" sx={editableInputStyles} /> <EditableInput className="nodrag" sx={editableInputStyles} />
<EditableControls /> <EditableControls />
</Editable> </Editable>
</Flex>
</InvTooltip> </InvTooltip>
); );
}); });

View File

@ -79,29 +79,41 @@ const InputField = ({ nodeId, fieldName }: Props) => {
); );
} }
if (fieldTemplate.input === 'connection') {
return (
<InputFieldWrapper shouldDim={shouldDim}>
<InvControl isInvalid={isMissingInput} isDisabled={isConnected} px={2}>
<EditableFieldTitle
nodeId={nodeId}
fieldName={fieldName}
kind="input"
isMissingInput={isMissingInput}
withTooltip
/>
</InvControl>
<FieldHandle
fieldTemplate={fieldTemplate}
handleType="target"
isConnectionInProgress={isConnectionInProgress}
isConnectionStartField={isConnectionStartField}
connectionError={connectionError}
/>
</InputFieldWrapper>
);
}
return ( return (
<InputFieldWrapper shouldDim={shouldDim}> <InputFieldWrapper shouldDim={shouldDim}>
<FieldContextMenu nodeId={nodeId} fieldName={fieldName} kind="input"> <FieldContextMenu nodeId={nodeId} fieldName={fieldName} kind="input">
{(ref) => ( {(ref) => (
<InvControl <InvControl
ref={ref}
isInvalid={isMissingInput} isInvalid={isMissingInput}
isDisabled={isConnected} isDisabled={isConnected}
orientation="vertical"
ps={fieldTemplate.input === 'direct' ? 0 : 2} ps={fieldTemplate.input === 'direct' ? 0 : 2}
alignItems="stretch" pe={2}
justifyContent="space-between"
flexDir="column"
gap={2}
h="full"
w="full"
>
<InvLabel
ref={ref}
display="flex"
alignItems="center"
mb={0}
px={1}
gap={2}
h="full"
> >
<EditableFieldTitle <EditableFieldTitle
nodeId={nodeId} nodeId={nodeId}
@ -110,7 +122,6 @@ const InputField = ({ nodeId, fieldName }: Props) => {
isMissingInput={isMissingInput} isMissingInput={isMissingInput}
withTooltip withTooltip
/> />
</InvLabel>
<InputFieldRenderer nodeId={nodeId} fieldName={fieldName} /> <InputFieldRenderer nodeId={nodeId} fieldName={fieldName} />
</InvControl> </InvControl>
)} )}