Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ const FormItem: FC<ISettingsFormItemProps> = (props) => {
childElement,
{
...childElement?.props,
readOnly: readOnly || hasCode,
readOnly: readOnly,
size: 'small',
disabled: readOnly || hasCode,
disabled: readOnly,
onChange: handleChange(onChange),
[valuePropName]: value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import { CodeEditorWithStandardConstants } from '../codeEditor/codeEditorWithConstants';
import { useConstantsEvaluator } from '../codeEditor/hooks/useConstantsEvaluator';
import { useResultTypeEvaluator } from '../codeEditor/hooks/useResultType';
import { Button } from 'antd';
import {
CodeOutlined, CodeFilled, FormOutlined
} from '@ant-design/icons';

export type SettingsControlChildrenType = (value: any, onChange: (val: any) => void, propertyName: string) => ReactElement;

Expand Down Expand Up @@ -61,7 +65,7 @@
const newMode = !!code ? 'code' : 'value' as IPropertySetting<Value>['_mode'];
props.setHasCode?.(newMode === 'code');
onInternalChange({ ...setting, _mode: newMode }, newMode);
}, [code]);

Check warning on line 68 in shesha-reactjs/src/designer-components/_settings/settingsControl.tsx

View workflow job for this annotation

GitHub Actions / build-and-test

React Hook useEffect has missing dependencies: 'onInternalChange', 'props', and 'setting'. Either include them or remove the dependency array. However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the useEffect call and refer to those specific props inside useEffect

const codeOnChange = (val: any) => {
const newValue = { ...setting, _code: val };
Expand All @@ -75,6 +79,11 @@
}
};

const onSwitchMode = () => {
const newMode = mode === 'code' ? 'value' : 'code';
onInternalChange(setting, newMode);
};


const propertyName = !!setting._code || setting._mode === 'code' ? `${props.propertyName}._value` : props.propertyName;
const functionName = `get${camelcase(props.propertyName, { pascalCase: true })}`;
Expand All @@ -94,7 +103,6 @@
},
type: 'text',
label: ' ',
className: `${styles.jsSwitch}`,
ghost: true,
exposedVariables: defaultExposedVariables,
hidden: !setting._code && props.readOnly,
Expand All @@ -107,8 +115,19 @@

return (
<div className={mode === 'code' ? styles.contentCode : styles.contentJs}>
{editor}
{!code && <div className={styles.jsContent} style={{ marginLeft: 0 }}>
<Button
hidden={props.readOnly}
className={`${styles.jsSwitch} inlineJS`}
type='text'
danger={mode === 'value' && !!code}
ghost
size='small'
icon={mode === 'code' ? <FormOutlined /> : !!code ? <CodeFilled /> : <CodeOutlined />}
color='lightslategrey'
onClick={onSwitchMode}
/>
{mode === 'code' && editor}
{mode === 'value' && <div className={styles.jsContent} style={{ marginLeft: 0 }}>
{props.children(setting?._value, valueOnChange, propertyName)}
</div>}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createStyles, sheshaStyles } from '@/styles';

export const useStyles = createStyles(({ css, cx, responsive, prefixCls, token }, hasCode) => {
export const useStyles = createStyles(({ css, cx, responsive, token }, hasCode) => {

const contentJs = cx(css`
position: relative;
Expand Down Expand Up @@ -51,7 +51,6 @@ export const useStyles = createStyles(({ css, cx, responsive, prefixCls, token }
top: -8px;
`);
const jsSwitch = cx(css`
&.${prefixCls}-btn {
position: absolute;
right: 0;
top: 4px;
Expand All @@ -74,14 +73,14 @@ export const useStyles = createStyles(({ css, cx, responsive, prefixCls, token }
.sidebar-container & {
right: 0;
left: auto;
top: ${hasCode ? '-35px' : '-25px'};
top: -25px;
}
.${sheshaStyles.verticalSettingsClass} & {
right: 0;
left: auto;
top: ${hasCode ? '-38px' : '-25px'};
}
}

`);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { readThemeColor } from "@/components/colorPicker";

export const getBorderStyle = (input: IBorderValue, jsStyle: React.CSSProperties, theme?: IConfigurableTheme): React.CSSProperties => {
if (!input) return {};

const style: React.CSSProperties = {};
const border = input.border || {};
const { all = {}, top = {}, right = {}, bottom = {}, left = {} } = border;
Expand Down Expand Up @@ -127,8 +127,8 @@ export const borderCorners = [
{ value: "bottomRight", icon: "RadiusBottomrightOutlined", title: "Bottom Right" }
];


const generateCode = (type: string, isCustom: boolean, isResponsive: boolean, path: string) => {

const devicePath = isResponsive ? 'data[`${contexts.canvasContext?.designerDevice || "desktop"}`]' : 'data';
return `return getSettingValue(${devicePath}${path ? '?.' + path : ''}?.border?.${type}) !== "${isCustom ? "custom" : "all"}";`;
};
Expand Down
2 changes: 1 addition & 1 deletion shesha-reactjs/src/designer-components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const ButtonComponent: IToolboxComponent<IButtonComponentProps> = {
...(['dashed', 'default'].includes(model.buttonType) && backgroundStyles),
...(['primary', 'default'].includes(model.buttonType) && shadowStyles),
...stylingBoxAsCSS,
...jsStyle
...jsStyle,
};

return (
Expand Down
12 changes: 8 additions & 4 deletions shesha-reactjs/src/designer-components/codeEditor/codeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import {
Tabs,
Typography
} from 'antd';
import classNames from 'classnames';
import { CodeEditor as BaseCodeEditor } from '@/components/codeEditor/codeEditor';
import { CodeFilled, CodeOutlined, ExclamationCircleFilled } from '@ant-design/icons';
import { CodeOutlined, ExclamationCircleFilled } from '@ant-design/icons';
import { CodeVariablesTables } from '@/components/codeVariablesTable';
import { ICodeEditorProps } from './interfaces';
import { Show } from '@/components';
Expand Down Expand Up @@ -146,8 +145,13 @@ export const CodeEditor: FC<ICodeEditorProps> = ({
? (<Typography.Text disabled>No Code</Typography.Text>)
: (
<>
<Button type={props.type ? props.type : hasValue ? 'primary' : 'default'} className={classNames(styles.button, props.className)} icon={hasValue ? <CodeFilled /> : <CodeOutlined />} onClick={openEditorDialog} size="small" style={{}}>
{props.label !== " " && (readOnly ? 'View Code' : '...')}
<Button
className={props.className}
size="small"
onClick={openEditorDialog}
style={hasValue ? { fontFamily: 'monospace', fontSize: '12px' } : undefined}
>
{hasValue ? <><CodeOutlined /> {value}</> : <><CodeOutlined /> ...</>}
</Button>
{showDialog && (
<Modal
Expand Down
12 changes: 12 additions & 0 deletions shesha-reactjs/src/designer-components/propertiesTabs/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ export const useStyles = createStyles(({ css, cx, }) => {
.ant-tabs-tab {
--ant-tabs-card-padding-sm: 0 8px;
}

.sha-toolbar-btn-configurable, .ant-btn {
display: flex;
align-items: center;
max-width: 100%;
span {
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
`);

return {
Expand Down
Loading