Skip to content

Commit

Permalink
feat(frontend-react): Default Widget Padding
Browse files Browse the repository at this point in the history
Add a default padding to the widget layout, suitable for most widgets.
This can be disabled by setting `borderless: true` in the `Widget` object.
  • Loading branch information
pklaschka committed Dec 7, 2024
1 parent 7617fc3 commit 686ee3d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.alert {
height: 100%;
margin: 0;
margin: -0rem;
overflow-y: auto;
}
3 changes: 2 additions & 1 deletion frontend-react/src/lib/widget/component/error-fallback.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Alert, AlertHeading, Button } from 'react-bootstrap';
import styles from './error-fallback.module.css';
import { clsx } from 'clsx';

export function ErrorFallback({
error,
Expand All @@ -9,7 +10,7 @@ export function ErrorFallback({
resetErrorBoundary: () => void;
}) {
return (
<Alert variant="danger" className={styles.alert}>
<Alert variant="danger" className={clsx(styles.alert)}>
<AlertHeading>Widget Error</AlertHeading>
<p>
Unfortunately, the widget encountered an error and cannot be displayed.
Expand Down
6 changes: 5 additions & 1 deletion frontend-react/src/lib/widget/component/widget-renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { getUserData } from '../../user-data';
import styles from './widget-renderer.module.css';
import { ErrorBoundary } from 'react-error-boundary';
import { ErrorFallback } from './error-fallback.tsx';
import { clsx } from 'clsx';

export interface WidgetRendererProps {
widgetInstanceId: string;
borderless: boolean;
}

export const WidgetConfigContext = createContext<unknown>(undefined);
Expand Down Expand Up @@ -36,9 +38,11 @@ registerWidget({
});
`;

const isBorderless = widget?.borderless;

return (
<div
className={styles.widgetRenderer}
className={clsx(styles.widgetRenderer, !isBorderless && 'p-3')}
style={{ '--id': CSS.escape(widgetInstanceId) }}
>
{widget ? (
Expand Down
4 changes: 4 additions & 0 deletions frontend-react/src/lib/widget/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ export interface Widget<
* A configuration element that is used to configure the widget.
*/
configElement: ReactNode;
/**
* If `true`, the widget gets rendered without a default padding.
*/
borderless?: boolean;
}

0 comments on commit 686ee3d

Please sign in to comment.