Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1281] Add support for Link widget in Form Description editor.
Bug: #1281 Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
- Loading branch information
1 parent
043cecf
commit 9a334e3
Showing
5 changed files
with
86 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
60 changes: 60 additions & 0 deletions
60
...rmdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/LinkWidget.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,60 @@ | ||
/******************************************************************************* | ||
* 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 Link from '@material-ui/core/Link'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import { useEffect, useRef, useState } from 'react'; | ||
import { WidgetProps } from './WidgetEntry.types'; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
selected: { | ||
color: theme.palette.primary.main, | ||
}, | ||
})); | ||
|
||
export const LinkWidget = ({ 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> | ||
<Link | ||
ref={ref} | ||
style={{ color: 'inherit' }} | ||
onFocus={() => setSelected(true)} | ||
onBlur={() => setSelected(false)} | ||
tabIndex={0} | ||
href="#" | ||
rel="noopener noreferrer" | ||
target="_blank" | ||
> | ||
noopener noreferrer | ||
</Link> | ||
</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