-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1275] Add support for Label widget in Form Description Editor
Bug: #1275 Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
- Loading branch information
1 parent
2d64ee5
commit 6f916f8
Showing
5 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...mdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/LabelWidget.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 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 | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import { WidgetProps } from './WidgetEntry.types'; | ||
import { useEffect, useRef, useState } from 'react'; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
selected: { | ||
color: theme.palette.primary.main, | ||
}, | ||
})); | ||
|
||
export const LabelWidget = ({ widget, selection }: WidgetProps) => { | ||
const classes = useStyles(); | ||
|
||
const [selected, setSelected] = useState<boolean>(false); | ||
|
||
const ref = useRef<HTMLInputElement | null>(null); | ||
|
||
useEffect(() => { | ||
if (ref.current && selection.entries.find((entry) => entry.id === widget.id)) { | ||
ref.current.focus(); | ||
setSelected(true); | ||
} else { | ||
setSelected(false); | ||
} | ||
}, [selection, widget]); | ||
|
||
return ( | ||
<div> | ||
<Typography variant="subtitle2" className={selected ? classes.selected : ''}> | ||
{widget.label} | ||
</Typography> | ||
<Typography ref={ref} onFocus={() => setSelected(true)} onBlur={() => setSelected(false)} tabIndex={0}> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit | ||
</Typography> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters