Skip to content

Commit

Permalink
[4110] Add layout capabilities for form widgets
Browse files Browse the repository at this point in the history
Bug: #4110
Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
Signed-off-by: Florian ROUËNÉ <florian.rouene@obeosoft.com>
  • Loading branch information
lfasani authored and frouene committed Nov 12, 2024
1 parent a077fef commit bc7dc25
Show file tree
Hide file tree
Showing 115 changed files with 13,002 additions and 2,120 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

=== Breaking changes


- https://github.com/eclipse-sirius/sirius-web/issues/4110[#4110] [view] CheckboxDescriptionStyle.labelPlacement is replaced by Grid layout properties

=== Dependency update

Expand All @@ -28,7 +28,7 @@

=== New Features


- https://github.com/eclipse-sirius/sirius-web/issues/4110[#4110] [form] Add layout capabilities for form widgets

=== Improvements

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022, 2023 Obeo.
* Copyright (c) 2022, 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -16,6 +16,7 @@

import org.eclipse.sirius.components.forms.CheckboxStyle;
import org.eclipse.sirius.components.forms.CheckboxStyle.Builder;
import org.eclipse.sirius.components.forms.WidgetGridLayout;
import org.eclipse.sirius.components.view.FixedColor;
import org.eclipse.sirius.components.view.form.CheckboxDescriptionStyle;

Expand All @@ -34,8 +35,18 @@ public CheckboxStyleProvider(CheckboxDescriptionStyle viewStyle) {
}

public CheckboxStyle build() {
WidgetGridLayout widgetGridLayout = WidgetGridLayout.newWidgetGridLayout()
.gridTemplateColumns(this.viewStyle.getGridTemplateColumns())
.gridTemplateRows(this.viewStyle.getGridTemplateRows())
.labelGridColumn(this.viewStyle.getLabelGridColumn())
.labelGridRow(this.viewStyle.getLabelGridRow())
.widgetGridColumn(this.viewStyle.getWidgetGridColumn())
.widgetGridRow(this.viewStyle.getWidgetGridRow())
.gap(this.viewStyle.getGap())
.build();

Builder checkboxStyleBuilder = CheckboxStyle.newCheckboxStyle()
.labelPlacement(this.viewStyle.getLabelPlacement().getLiteral());
.widgetGridLayout(widgetGridLayout);

if (this.viewStyle.getColor() instanceof FixedColor fixedColor) {
String color = fixedColor.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.eclipse.sirius.components.forms.DateTimeStyle;
import org.eclipse.sirius.components.forms.DateTimeStyle.Builder;
import org.eclipse.sirius.components.forms.WidgetGridLayout;
import org.eclipse.sirius.components.view.FixedColor;
import org.eclipse.sirius.components.view.form.DateTimeDescriptionStyle;

Expand Down Expand Up @@ -52,10 +53,20 @@ public DateTimeStyle build() {

boolean italic = this.viewStyle.isItalic();
boolean bold = this.viewStyle.isBold();
WidgetGridLayout widgetGridLayout = WidgetGridLayout.newWidgetGridLayout()
.gridTemplateColumns(this.viewStyle.getGridTemplateColumns())
.gridTemplateRows(this.viewStyle.getGridTemplateRows())
.labelGridColumn(this.viewStyle.getLabelGridColumn())
.labelGridRow(this.viewStyle.getLabelGridRow())
.widgetGridColumn(this.viewStyle.getWidgetGridColumn())
.widgetGridRow(this.viewStyle.getWidgetGridRow())
.gap(this.viewStyle.getGap())
.build();

return dateTimeStyleBuilder
.italic(italic)
.bold(bold)
.widgetGridLayout(widgetGridLayout)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022, 2023 Obeo.
* Copyright (c) 2022, 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -16,6 +16,7 @@

import org.eclipse.sirius.components.forms.MultiSelectStyle;
import org.eclipse.sirius.components.forms.MultiSelectStyle.Builder;
import org.eclipse.sirius.components.forms.WidgetGridLayout;
import org.eclipse.sirius.components.view.FixedColor;
import org.eclipse.sirius.components.view.form.MultiSelectDescriptionStyle;

Expand Down Expand Up @@ -56,6 +57,15 @@ public MultiSelectStyle build() {
boolean underline = this.viewStyle.isUnderline();
boolean strikeThrough = this.viewStyle.isStrikeThrough();
boolean isShowIcon = this.viewStyle.isShowIcon();
WidgetGridLayout widgetGridLayout = WidgetGridLayout.newWidgetGridLayout()
.gridTemplateColumns(this.viewStyle.getGridTemplateColumns())
.gridTemplateRows(this.viewStyle.getGridTemplateRows())
.labelGridColumn(this.viewStyle.getLabelGridColumn())
.labelGridRow(this.viewStyle.getLabelGridRow())
.widgetGridColumn(this.viewStyle.getWidgetGridColumn())
.widgetGridRow(this.viewStyle.getWidgetGridRow())
.gap(this.viewStyle.getGap())
.build();

// @formatter:off
return multiSelectStyleBuilder
Expand All @@ -65,6 +75,7 @@ public MultiSelectStyle build() {
.underline(underline)
.strikeThrough(strikeThrough)
.showIcon(isShowIcon)
.widgetGridLayout(widgetGridLayout)
.build();
// @formatter:on
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022, 2023 Obeo.
* Copyright (c) 2022, 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -16,6 +16,7 @@

import org.eclipse.sirius.components.forms.SelectStyle;
import org.eclipse.sirius.components.forms.SelectStyle.Builder;
import org.eclipse.sirius.components.forms.WidgetGridLayout;
import org.eclipse.sirius.components.view.FixedColor;
import org.eclipse.sirius.components.view.form.SelectDescriptionStyle;

Expand Down Expand Up @@ -56,6 +57,15 @@ public SelectStyle build() {
boolean underline = this.viewStyle.isUnderline();
boolean strikeThrough = this.viewStyle.isStrikeThrough();
boolean isShowIcon = this.viewStyle.isShowIcon();
WidgetGridLayout widgetGridLayout = WidgetGridLayout.newWidgetGridLayout()
.gridTemplateColumns(this.viewStyle.getGridTemplateColumns())
.gridTemplateRows(this.viewStyle.getGridTemplateRows())
.labelGridColumn(this.viewStyle.getLabelGridColumn())
.labelGridRow(this.viewStyle.getLabelGridRow())
.widgetGridColumn(this.viewStyle.getWidgetGridColumn())
.widgetGridRow(this.viewStyle.getWidgetGridRow())
.gap(this.viewStyle.getGap())
.build();

// @formatter:off
return selectStyleBuilder
Expand All @@ -65,6 +75,7 @@ public SelectStyle build() {
.underline(underline)
.strikeThrough(strikeThrough)
.showIcon(isShowIcon)
.widgetGridLayout(widgetGridLayout)
.build();
// @formatter:on
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022, 2023 Obeo.
* Copyright (c) 2022, 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -16,6 +16,7 @@

import org.eclipse.sirius.components.forms.TextareaStyle;
import org.eclipse.sirius.components.forms.TextareaStyle.Builder;
import org.eclipse.sirius.components.forms.WidgetGridLayout;
import org.eclipse.sirius.components.view.FixedColor;
import org.eclipse.sirius.components.view.form.TextareaDescriptionStyle;

Expand Down Expand Up @@ -55,6 +56,15 @@ public TextareaStyle build() {
boolean bold = this.viewStyle.isBold();
boolean underline = this.viewStyle.isUnderline();
boolean strikeThrough = this.viewStyle.isStrikeThrough();
WidgetGridLayout widgetGridLayout = WidgetGridLayout.newWidgetGridLayout()
.gridTemplateColumns(this.viewStyle.getGridTemplateColumns())
.gridTemplateRows(this.viewStyle.getGridTemplateRows())
.labelGridColumn(this.viewStyle.getLabelGridColumn())
.labelGridRow(this.viewStyle.getLabelGridRow())
.widgetGridColumn(this.viewStyle.getWidgetGridColumn())
.widgetGridRow(this.viewStyle.getWidgetGridRow())
.gap(this.viewStyle.getGap())
.build();

// @formatter:off
return textareaStyleBuilder
Expand All @@ -63,6 +73,7 @@ public TextareaStyle build() {
.bold(bold)
.underline(underline)
.strikeThrough(strikeThrough)
.widgetGridLayout(widgetGridLayout)
.build();
// @formatter:on
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022, 2023 Obeo.
* Copyright (c) 2022, 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -16,6 +16,7 @@

import org.eclipse.sirius.components.forms.TextfieldStyle;
import org.eclipse.sirius.components.forms.TextfieldStyle.Builder;
import org.eclipse.sirius.components.forms.WidgetGridLayout;
import org.eclipse.sirius.components.view.FixedColor;
import org.eclipse.sirius.components.view.form.TextfieldDescriptionStyle;

Expand Down Expand Up @@ -55,6 +56,15 @@ public TextfieldStyle build() {
boolean bold = this.viewStyle.isBold();
boolean underline = this.viewStyle.isUnderline();
boolean strikeThrough = this.viewStyle.isStrikeThrough();
WidgetGridLayout widgetGridLayout = WidgetGridLayout.newWidgetGridLayout()
.gridTemplateColumns(this.viewStyle.getGridTemplateColumns())
.gridTemplateRows(this.viewStyle.getGridTemplateRows())
.labelGridColumn(this.viewStyle.getLabelGridColumn())
.labelGridRow(this.viewStyle.getLabelGridRow())
.widgetGridColumn(this.viewStyle.getWidgetGridColumn())
.widgetGridRow(this.viewStyle.getWidgetGridRow())
.gap(this.viewStyle.getGap())
.build();

// @formatter:off
return textfieldStyleBuilder
Expand All @@ -63,6 +73,7 @@ public TextfieldStyle build() {
.bold(bold)
.underline(underline)
.strikeThrough(strikeThrough)
.widgetGridLayout(widgetGridLayout)
.build();
// @formatter:on
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,53 @@ import { getCSSColor, useSelection } from '@eclipse-sirius/sirius-components-cor
import { CheckboxStyleProps } from '@eclipse-sirius/sirius-components-forms';
import HelpOutlineOutlined from '@mui/icons-material/HelpOutlineOutlined';
import Checkbox from '@mui/material/Checkbox';
import FormControlLabel from '@mui/material/FormControlLabel';
import FormControl from '@mui/material/FormControl';
import Typography from '@mui/material/Typography';
import { useEffect, useRef, useState } from 'react';
import { makeStyles } from 'tss-react/mui';
import { CheckboxWidgetProps } from './WidgetEntry.types';

const useStyles = makeStyles<CheckboxStyleProps>()((theme, { color }) => ({
style: {
color: color ? getCSSColor(color, theme) : theme.palette.primary.light,
'&.Mui-checked': {
const useStyles = makeStyles<CheckboxStyleProps>()((theme, { color, gridProps }) => {
const { gridTemplateColumns, gridTemplateRows, labelGridColumn, labelGridRow, widgetGridColumn, widgetGridRow, gap } =
{
...gridProps,
};
return {
style: {
color: color ? getCSSColor(color, theme) : theme.palette.primary.light,
'&.Mui-checked': {
color: color ? getCSSColor(color, theme) : theme.palette.primary.light,
},
},
},
selected: {
color: theme.palette.primary.main,
},
propertySectionLabel: {
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
},
}));
selected: {
color: theme.palette.primary.main,
},
propertySection: {
display: 'grid',
gridTemplateColumns: gridTemplateColumns ?? 'min-content 1fr',
gridTemplateRows,
alignItems: 'center',
gap: gap ?? '',
},
propertySectionLabel: {
gridColumn: labelGridColumn ?? '2/3',
gridRow: labelGridRow,
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
},
propertySectionWidget: {
gridColumn: widgetGridColumn,
gridRow: widgetGridRow ?? '1/2',
},
};
});

export const CheckboxWidget = ({ widget }: CheckboxWidgetProps) => {
const props: CheckboxStyleProps = {
color: widget.style?.color ?? null,
gridProps: widget.style?.widgetGridLayout ?? null,
};
const { classes } = useStyles(props);

Expand All @@ -58,19 +79,14 @@ export const CheckboxWidget = ({ widget }: CheckboxWidgetProps) => {
}, [selection, widget]);

return (
<FormControlLabel
labelPlacement={widget.style?.labelPlacement ?? 'end'}
label={
<div className={classes.propertySectionLabel}>
<Typography variant="subtitle2" className={selected ? classes.selected : ''}>
{widget.label}
</Typography>
{widget.hasHelpText ? (
<HelpOutlineOutlined color="secondary" style={{ marginLeft: 8, fontSize: 16 }} />
) : null}
</div>
}
control={
<FormControl classes={{ root: classes.propertySection }}>
<div className={classes.propertySectionLabel}>
<Typography variant="subtitle2" className={selected ? classes.selected : ''}>
{widget.label}
</Typography>
{widget.hasHelpText ? <HelpOutlineOutlined color="secondary" style={{ marginLeft: 8, fontSize: 16 }} /> : null}
</div>
<div className={classes.propertySectionWidget}>
<Checkbox
data-testid={widget.label}
checked
Expand All @@ -79,7 +95,7 @@ export const CheckboxWidget = ({ widget }: CheckboxWidgetProps) => {
onBlur={() => setSelected(false)}
classes={{ root: classes.style }}
/>
}
/>
</div>
</FormControl>
);
};
Loading

0 comments on commit bc7dc25

Please sign in to comment.