-
Notifications
You must be signed in to change notification settings - Fork 123
Thulasizwe/en/form components width #4022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 45 commits
5a2086a
891b925
b7e5cb7
adbc29e
3ad5778
3873eb5
9bb8876
91ab91f
6eec4fd
0918b55
fde6d82
e0d53bd
f726afe
8d4d95c
b79190e
4a4a1ec
23e0fc3
ee63a2b
6cb1a9d
d4faaf0
9052ae8
4507c0d
c4e46a0
fe73db8
885135d
fa9d8f8
bd51999
05281eb
8c77ba5
3bf3c0e
b86b776
fde0b5b
56c3e74
e77fbbe
bc49dcb
e88a069
065c7bb
ef8e5b8
0012f3d
1879cc5
7ac4c4d
dca3479
d7e0a9e
0bd30d0
d30fd40
e313804
5e077b8
388420e
18ed5a1
90c9922
5a48159
1314e33
6df75ae
5b65e80
4deeb3a
58ff70b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,14 +5,15 @@ import { getPropertySettingsFromData } from '@/designer-components/_settings/uti | |||||
| import { SettingsControl, useShaFormInstance } from '@/index'; | ||||||
| import { IConfigurableFormItemChildFunc, IConfigurableFormItemProps } from './model'; | ||||||
| import { ConfigurableFormItemLive } from './configurableFormItemLive'; | ||||||
| import { useStyles } from './styles'; | ||||||
|
|
||||||
| export const ConfigurableFormItemSetting: FC<IConfigurableFormItemProps> = ({ | ||||||
| children, | ||||||
| model, | ||||||
| valuePropName, | ||||||
| }) => { | ||||||
| const { formData } = useShaFormInstance(); | ||||||
|
|
||||||
| const { styles } = useStyles(); | ||||||
| if (model.hidden) return null; | ||||||
|
|
||||||
| const { _mode: mode } = getPropertySettingsFromData(formData, model.propertyName); | ||||||
|
|
@@ -24,12 +25,13 @@ export const ConfigurableFormItemSetting: FC<IConfigurableFormItemProps> = ({ | |||||
| required: model.validate?.required, | ||||||
| tooltip: model.description || undefined, | ||||||
| hidden: model.hidden, | ||||||
| className: styles.formItem, | ||||||
| }; | ||||||
|
|
||||||
| if (typeof children === 'function') { | ||||||
| const childrenFunc = children as IConfigurableFormItemChildFunc; | ||||||
| return ( | ||||||
| <Form.Item {...formProps}> | ||||||
| <Form.Item {...formProps} className={styles.formItem}> | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Duplicate The Remove the duplicate: - <Form.Item {...formProps} className={styles.formItem}>
+ <Form.Item {...formProps}>📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| <SettingsControl propertyName={model.propertyName} mode={mode}> | ||||||
| {(value, onChange, propertyName) => childrenFunc(value, onChange, propertyName)} | ||||||
| </SettingsControl> | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||||||
| import { createStyles } from '@/styles'; | ||||||||||
|
|
||||||||||
| export const useStyles = createStyles(({ css, cx }, layout: 'vertical' | 'horizontal' | 'inline' | undefined) => { | ||||||||||
| const formItem = cx(css` | ||||||||||
| --ant-form-item-margin-bottom: 0px !important; | ||||||||||
| .ant-form-item-row { | ||||||||||
| height: 100%; | ||||||||||
| width: 100%; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| .ant-row .ant-form-item-control { | ||||||||||
| width: 100% !important; | ||||||||||
| height: 100% !important; | ||||||||||
| max-height: ${layout === 'vertical' ? 'calc(100% - 32px)' : '100%'}; | ||||||||||
| margin: auto; | ||||||||||
|
|
||||||||||
| .ant-form-item-control-input { | ||||||||||
| min-height : 0px !important; | ||||||||||
| height: 100%; | ||||||||||
| width: 100%; | ||||||||||
|
|
||||||||||
| .ant-form-item-control-input-content { | ||||||||||
| height: 100%; | ||||||||||
| width: 100%; | ||||||||||
| > div { | ||||||||||
| vertical-align: middle; | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
| `); | ||||||||||
|
Comment on lines
+36
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Remove extra blank line. Minor formatting cleanup - there's an unnecessary blank line before the closing backtick. }
}
-
-
`);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| return { | ||||||||||
| formItem, | ||||||||||
| }; | ||||||||||
| }); | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ import React, { | |
| } from 'react'; | ||
| import { createPortal } from 'react-dom'; | ||
| import ValidationIcon from './validationIcon'; | ||
| import { DataContextTopLevels, EditMode, IConfigurableFormComponent } from '@/providers'; | ||
| import { DataContextTopLevels, EditMode, IConfigurableFormComponent, useCanvas, useShaFormInstance } from '@/providers'; | ||
| import { | ||
| EditOutlined, | ||
| EyeInvisibleOutlined, | ||
|
|
@@ -21,10 +21,14 @@ import { isPropertySettings } from '@/designer-components/_settings/utils'; | |
| import { Show } from '@/components/show'; | ||
| import { Tooltip } from 'antd'; | ||
| import { ShaForm, useIsDrawingForm } from '@/providers/form'; | ||
| import { useFormDesignerState } from '@/providers/formDesigner'; | ||
| import { useFormDesignerState, useFormDesignerStateSelector } from '@/providers/formDesigner'; | ||
| import { useStyles } from '../styles/styles'; | ||
| import { ComponentProperties } from '../componentPropertiesPanel/componentProperties'; | ||
| import { useFormDesignerComponentGetter } from '@/providers/form/hooks'; | ||
| import { useFormComponentStyles } from '@/hooks/formComponentHooks'; | ||
| import { getComponentTypeInfo } from '../utils/componentTypeUtils'; | ||
| import { getComponentDimensions, getDeviceDimensions, getDeviceFlexBasis } from '../utils/dimensionUtils'; | ||
| import { createRootContainerStyle } from '../utils/stylingUtils'; | ||
|
|
||
| export interface IConfigurableFormComponentDesignerProps { | ||
| componentModel: IConfigurableFormComponent; | ||
|
|
@@ -43,11 +47,21 @@ const ConfigurableFormComponentDesignerInner: FC<IConfigurableFormComponentDesig | |
| componentEditMode, | ||
| }) => { | ||
| const { styles } = useStyles(); | ||
|
|
||
| const getToolboxComponent = useFormDesignerComponentGetter(); | ||
|
|
||
| const formSettings = useFormDesignerStateSelector((x) => x.formSettings); | ||
| const { formMode } = useShaFormInstance(); | ||
| const { activeDevice } = useCanvas(); | ||
|
|
||
| const component = getToolboxComponent(componentModel?.type); | ||
| const typeInfo = getComponentTypeInfo(component); | ||
| const { dimensionsStyles, stylingBoxAsCSS } = useFormComponentStyles({ ...componentModel, ...componentModel?.[activeDevice] }); | ||
| const { top, left, bottom, right } = formSettings?.formItemMargin || {}; | ||
| const desktopConfig = componentModel?.[activeDevice] || {}; | ||
| const originalDimensions = dimensionsStyles; | ||
| const originalStylingBox = stylingBoxAsCSS; | ||
|
|
||
| const hasLabel = componentModel.label && componentModel.label.toString().length > 0; | ||
| const isSelected = componentModel.id && selectedComponentId === componentModel.id; | ||
|
|
||
| const invalidConfiguration = componentModel.settingsValidationErrors && componentModel.settingsValidationErrors.length > 0; | ||
|
|
||
| const hiddenFx = isPropertySettings(componentModel.hidden); | ||
|
|
@@ -57,9 +71,9 @@ const ConfigurableFormComponentDesignerInner: FC<IConfigurableFormComponentDesig | |
| const actionText2 = (hiddenFx ? 'showing' : '') + (hiddenFx && componentEditModeFx ? '/' : '') + (componentEditModeFx ? 'enabled' : ''); | ||
|
|
||
| const settingsEditor = useMemo(() => { | ||
| const renderRerquired = isSelected && settingsPanelRef.current; | ||
| const renderRequired = isSelected && settingsPanelRef.current; | ||
|
|
||
| if (!renderRerquired) | ||
| if (!renderRequired) | ||
| return null; | ||
|
|
||
| const createPortalInner = true | ||
|
|
@@ -82,8 +96,57 @@ const ConfigurableFormComponentDesignerInner: FC<IConfigurableFormComponentDesig | |
| return result; | ||
| }, [isSelected]); | ||
|
|
||
| const { marginLeft = left, marginRight = right, marginBottom = bottom, marginTop = top } = stylingBoxAsCSS; | ||
|
|
||
| const stylingBoxPadding = useMemo(() => { | ||
| return { | ||
| paddingBottom: originalStylingBox.paddingBottom, | ||
| paddingLeft: originalStylingBox.paddingLeft, | ||
| paddingRight: originalStylingBox.paddingRight, | ||
| paddingTop: originalStylingBox.paddingTop, | ||
| }; | ||
| }, [formMode, originalStylingBox, desktopConfig.stylingBox]); | ||
|
|
||
| const stylingBoxMargin = useMemo(() => { | ||
| return { | ||
| marginTop: marginTop ? top : marginTop, | ||
| marginBottom: marginBottom ? bottom : marginBottom, | ||
| marginLeft: marginLeft ? left : marginLeft, | ||
| marginRight: marginRight ? right : marginRight, | ||
| }; | ||
| }, [formMode, originalStylingBox, desktopConfig.stylingBox]); | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const paddingStyles = JSON.stringify(stylingBoxPadding); | ||
| const marginStyles = JSON.stringify(stylingBoxMargin); | ||
|
|
||
| const componentDimensions = getComponentDimensions(typeInfo, dimensionsStyles); | ||
|
|
||
| const renderComponentModel = useMemo(() => { | ||
| const deviceDimensions = getDeviceDimensions(typeInfo, dimensionsStyles); | ||
|
|
||
| return { | ||
| ...componentModel, | ||
| [activeDevice]: { | ||
| ...desktopConfig, | ||
| dimensions: deviceDimensions, | ||
| }, | ||
| // ...(formMode === 'designer' ? {stylingBox: paddingStyles} : {stylingBox: JSON.stringify({...stylingBoxPadding, ...stylingBoxMargin})}), | ||
| flexBasis: getDeviceFlexBasis(dimensionsStyles), | ||
| }; | ||
| }, [componentModel, desktopConfig, paddingStyles, originalDimensions, formMode, typeInfo, activeDevice, dimensionsStyles]); | ||
|
|
||
| const rootContainerStyle = useMemo(() => { | ||
| return createRootContainerStyle( | ||
| componentDimensions, | ||
| { ...JSON.parse(marginStyles) }, | ||
| originalDimensions, | ||
| typeInfo.isInput, | ||
| ); | ||
| }, [componentDimensions, marginTop, marginBottom, marginLeft, marginRight, originalDimensions, hasLabel]); | ||
|
|
||
| return ( | ||
| <div | ||
| style={rootContainerStyle} | ||
| className={classNames(styles.shaComponent, { | ||
| "selected": isSelected, | ||
| 'has-config-errors': invalidConfiguration, | ||
|
|
@@ -107,6 +170,7 @@ const ConfigurableFormComponentDesignerInner: FC<IConfigurableFormComponentDesig | |
| <StopOutlined /> | ||
| </Tooltip> | ||
| </Show> | ||
|
|
||
| <Show when={!componentEditModeFx && componentEditMode === 'editable'}> | ||
| <Tooltip title="This component is always in Edit/Action mode"> | ||
| <EditOutlined /> | ||
|
|
@@ -115,10 +179,23 @@ const ConfigurableFormComponentDesignerInner: FC<IConfigurableFormComponentDesig | |
| </span> | ||
|
|
||
| {invalidConfiguration && <ValidationIcon validationErrors={componentModel.settingsValidationErrors} />} | ||
| <div> | ||
|
|
||
| <div style={{ | ||
| width: '100%', | ||
| height: '100%', | ||
| boxSizing: 'border-box', | ||
| }} | ||
| > | ||
| <DragWrapper componentId={componentModel.id} readOnly={readOnly}> | ||
| <div style={{ padding: '5px 3px' }}> | ||
| <FormComponent componentModel={componentModel} /> | ||
| <div style={{ | ||
| width: '100%', | ||
| height: '100%', | ||
| boxSizing: 'border-box', | ||
| }} | ||
| > | ||
| <FormComponent | ||
| componentModel={renderComponentModel} | ||
| /> | ||
| </div> | ||
| </DragWrapper> | ||
| </div> | ||
|
Comment on lines
+160
to
178
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Consider consolidating nested wrapper divs with identical styles. Two wrapper divs (lines 170-175 and 177-182) have identical inline styles ( const innerWrapperStyle: React.CSSProperties = {
width: '100%',
height: '100%',
boxSizing: 'border-box',
};
// Then use:
<div style={innerWrapperStyle}>
<DragWrapper componentId={componentModel.id} readOnly={readOnly}>
<FormComponent componentModel={renderComponentModel} />
</DragWrapper>
</div>🤖 Prompt for AI Agents |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { IConfigurableFormComponent, IToolboxComponent } from "@/interfaces"; | ||
|
|
||
| export interface ComponentTypeInfo { | ||
| isDataTableContext: boolean; | ||
| isInput: boolean; | ||
| } | ||
|
|
||
| export const getComponentTypeInfo = (component: IToolboxComponent<IConfigurableFormComponent>): ComponentTypeInfo => { | ||
| const isDataTableContext = component?.type === 'datatableContext'; | ||
| const isInput = component?.isInput || component?.type === 'button'; | ||
|
|
||
| return { | ||
| isDataTableContext, | ||
| isInput, | ||
| }; | ||
| }; |
Uh oh!
There was an error while loading. Please reload this page.