Skip to content
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

feat: combo row模式组件支持选择宽度 #11310

Merged
merged 2 commits into from
Dec 4, 2024
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
21 changes: 16 additions & 5 deletions packages/amis-core/src/renderers/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1814,22 +1814,33 @@ export default class Form extends React.Component<FormProps, object> {

return (
<div className={cx('Form-row')}>
{children.map((control, key) =>
~['hidden', 'formula'].indexOf((control as any).type) ||
(control as any).mode === 'inline' ? (
{children.map((control, key) => {
const split = control.colSize?.split('/');
const colSize =
split?.[0] && split?.[1]
? (split[0] / split[1]) * 100 + '%'
: control.colSize;
return ~['hidden', 'formula'].indexOf((control as any).type) ||
(control as any).mode === 'inline' ? (
this.renderChild(control, key, otherProps)
) : (
<div
key={key}
className={cx(`Form-col`, (control as Schema).columnClassName)}
style={{
flex:
colSize && !['1', 'auto'].includes(colSize)
? `0 0 ${colSize}`
: '1'
}}
>
{this.renderChild(control, '', {
...otherProps,
mode: 'row'
})}
</div>
)
)}
);
})}
</div>
);
}
Expand Down
1 change: 0 additions & 1 deletion packages/amis-editor/src/plugin/Form/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ export class CheckboxControlPlugin extends BasePlugin {
body: [
getSchemaTpl('collapseGroup', [
getSchemaTpl('theme:formItem', {
hidSize: true,
schema: [
{
type: 'select',
Expand Down
1 change: 0 additions & 1 deletion packages/amis-editor/src/plugin/Form/Checkboxes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ export class CheckboxesControlPlugin extends BasePlugin {
body: [
getSchemaTpl('collapseGroup', [
getSchemaTpl('theme:formItem', {
hidSize: true,
schema: [
getSchemaTpl('switch', {
label: '一行选项显示',
Expand Down
5 changes: 2 additions & 3 deletions packages/amis-editor/src/plugin/Form/Radios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ export class RadiosControlPlugin extends BasePlugin {
body: [
getSchemaTpl('collapseGroup', [
getSchemaTpl('theme:formItem', {
hidSize: true,
schema: [
getSchemaTpl('switch', {
label: '一行选项显示',
Expand Down Expand Up @@ -298,14 +297,14 @@ export class RadiosControlPlugin extends BasePlugin {
{
label: '隐藏勾选框',
type: 'switch',
name: 'themeCss.radiosShowClassName.display',
name: 'themeCss?.radiosShowClassName.display',
trueValue: 'none'
},
...inputStateTpl('themeCss.radiosClassName', '', {
hideFont: true,
hideMargin: true,
hidePadding: true,
hiddenOn: 'themeCss.radiosShowClassName.display === "none"',
hiddenOn: 'themeCss?.radiosShowClassName.display === "none"',
backgroundToken: (state: string) => {
const s = state.split('-');
if (s[0] === 'checked' && s[1] !== 'disabled') {
Expand Down
55 changes: 38 additions & 17 deletions packages/amis-editor/src/renderer/style-control/ColSize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,17 @@ const ColSize: React.FC<FormControlProps> = props => {
const parent = store.getNodeById(node.parentId);
const isFlex = parent?.schema?.mode === 'flex';

const value = isFlex ? props.data.colSize : props.data.size;
// combo的row模式
const type = parent?.schema?.type;
const multiLine = parent?.schema?.multiLine;
const tabsMode = parent?.schema?.tabsMode;
const isComboRow = type === 'combo' && !multiLine && !tabsMode;

const value = isFlex || isComboRow ? props.data.colSize : props.data.size;

function handleColSizeChange(value: string) {
if (
!colSizeMap[length].includes(value) ||
!colSizeMap[length]?.includes(value) ||
node?.schema?.$$dragMode === 'hv'
) {
return;
Expand Down Expand Up @@ -77,6 +83,14 @@ const ColSize: React.FC<FormControlProps> = props => {
return item;
});
}
} else if (isComboRow) {
const colSize = getColSize(value, length - 1);
list = list.map((item: any) => {
if (item.$$id !== node.id) {
item.colSize = colSize;
}
return item;
});
}

const schema = JSONUpdate(store.schema, node.parentId, {
Expand All @@ -91,22 +105,29 @@ const ColSize: React.FC<FormControlProps> = props => {
props.setValue(value, 'size');
}

return isFlex ? (
return isFlex || isComboRow ? (
<div className="ColSize">
{baseColSize.map(n => (
<div
className={cx(
'ColSize-item',
value === n && 'is-active',
!colSizeMap[length]?.includes(n) && 'is-disabled',
node.schema.$$dragMode === 'hv' && 'is-disabled'
)}
key={n}
onClick={() => handleColSizeChange(n)}
>
{n}
</div>
))}
{baseColSize
.filter(n => {
if (type === 'combo' && !multiLine && n === '1') {
return false;
}
return true;
})
.map(n => (
<div
className={cx(
'ColSize-item',
value === n && 'is-active',
!colSizeMap[length]?.includes(n) && 'is-disabled',
node.schema.$$dragMode === 'hv' && 'is-disabled'
)}
key={n}
onClick={() => handleColSizeChange(n)}
>
{n}
</div>
))}
</div>
) : (
props.render('size', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ exports[`Renderer:combo with addable & addattop & addBtn & addButtonText & addBu
>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down Expand Up @@ -206,6 +207,7 @@ exports[`Renderer:combo with addable & addattop & addBtn & addButtonText & addBu
>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down Expand Up @@ -268,6 +270,7 @@ exports[`Renderer:combo with addable & addattop & addBtn & addButtonText & addBu
>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down Expand Up @@ -377,6 +380,7 @@ exports[`Renderer:combo with addable & addattop & addBtn & addButtonText & addBu
>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down Expand Up @@ -439,6 +443,7 @@ exports[`Renderer:combo with addable & addattop & addBtn & addButtonText & addBu
>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down Expand Up @@ -1183,6 +1188,7 @@ exports[`Renderer:combo with draggable 1`] = `
>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down Expand Up @@ -1214,6 +1220,7 @@ exports[`Renderer:combo with draggable 1`] = `
</div>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down Expand Up @@ -1301,6 +1308,7 @@ exports[`Renderer:combo with draggable 1`] = `
>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down Expand Up @@ -1332,6 +1340,7 @@ exports[`Renderer:combo with draggable 1`] = `
</div>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down Expand Up @@ -1763,6 +1772,7 @@ exports[`Renderer:combo with removable & deleteBtn & deleteApi & deleteConfirmTe
>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down Expand Up @@ -1866,6 +1876,7 @@ exports[`Renderer:combo with removable & deleteBtn & deleteApi & deleteConfirmTe
>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down Expand Up @@ -1977,6 +1988,7 @@ exports[`Renderer:combo with removable & deleteBtn & deleteApi & deleteConfirmTe
>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ exports[`Renderer:inputArray 1`] = `
>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down Expand Up @@ -289,6 +290,7 @@ exports[`Renderer:inputArray with draggable & draggableTip 1`] = `
>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down Expand Up @@ -364,6 +366,7 @@ exports[`Renderer:inputArray with draggable & draggableTip 1`] = `
>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down Expand Up @@ -439,6 +442,7 @@ exports[`Renderer:inputArray with draggable & draggableTip 1`] = `
>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down Expand Up @@ -627,6 +631,7 @@ exports[`Renderer:inputArray with minLength & maxLength 1`] = `
>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down Expand Up @@ -679,6 +684,7 @@ exports[`Renderer:inputArray with minLength & maxLength 1`] = `
>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down Expand Up @@ -852,6 +858,7 @@ exports[`Renderer:inputArray with removable & addable & addButtonText: false 1`]
>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down Expand Up @@ -904,6 +911,7 @@ exports[`Renderer:inputArray with removable & addable & addButtonText: false 1`]
>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down Expand Up @@ -1064,6 +1072,7 @@ exports[`Renderer:inputArray with removable & addable & addButtonText: false 2`]
>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,7 @@ exports[`Renderer:input-table with combo column 1`] = `
>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down Expand Up @@ -1728,6 +1729,7 @@ exports[`Renderer:input-table with combo column 1`] = `
</div>
<div
class="cxd-Form-col"
style="flex: 1;"
>
<div
class="cxd-Form-item cxd-Form-item--row"
Expand Down
Loading