Skip to content

Commit

Permalink
Merge pull request #29 from Exabyte-io/feature/SOF-6794
Browse files Browse the repository at this point in the history
SOF-6794: add more rjsf widgets
  • Loading branch information
zoomchik authored Oct 31, 2023
2 parents 0da2b30 + eb3e14a commit a7d64c1
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 0 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@codemirror/legacy-modes": "^6.3.1",
"@codemirror/lint": "^6.2.0",
"@mui/x-date-pickers": "6.11.1",
"@rjsf/mui": "^5.12.1",
"@rjsf/utils": "^5.1.0",
"@toast-ui/editor": "^3.2.2",
"@toast-ui/editor-plugin-code-syntax-highlight": "^3.1.0",
Expand Down
32 changes: 32 additions & 0 deletions src/other/rjsf/widgets/InputWithInfoPopover.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-disable react/jsx-props-no-spreading */
import Typography from "@mui/material/Typography";
import { Templates } from "@rjsf/mui";
import React from "react";

import InfoPopover from "../../../mui/components/popover/info-popover/InfoPopover";
import { PositionInfoPopover } from "./PositionInfoPopover.styled";
import { WidgetWithInfoPopoverProps } from "./types";

const { BaseInputTemplate } = Templates;

export default function InputWithInfoPopover(props: WidgetWithInfoPopoverProps) {
const { uiSchema = {} } = props;
const infoPopover = uiSchema["ui:options"] && uiSchema["ui:options"].infoPopover;

if (!BaseInputTemplate) return null;

return (
<>
<BaseInputTemplate {...props} size="small" />
<PositionInfoPopover>
<InfoPopover title={infoPopover?.title} iconSize="small">
<Typography
variant="body2"
pb={2}
dangerouslySetInnerHTML={{ __html: infoPopover?.content || "" }}
/>
</InfoPopover>
</PositionInfoPopover>
</>
);
}
10 changes: 10 additions & 0 deletions src/other/rjsf/widgets/PositionInfoPopover.styled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Box from "@mui/material/Box";
import { styled } from "@mui/material/styles";

export const PositionInfoPopover = styled(Box)(({ theme }) => ({
backgroundColor: theme.palette.background.paper,
position: "absolute",
borderRadius: "50%",
right: -14,
top: -14,
}));
30 changes: 30 additions & 0 deletions src/other/rjsf/widgets/SelectWithInfoPopover.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* eslint-disable react/jsx-props-no-spreading */
import Typography from "@mui/material/Typography";
import { Widgets } from "@rjsf/mui";
import React from "react";

import InfoPopover from "../../../mui/components/popover/info-popover/InfoPopover";
import { PositionInfoPopover } from "./PositionInfoPopover.styled";
import { WidgetWithInfoPopoverProps } from "./types";

const { SelectWidget } = Widgets;

export default function SelectWithInfoPopover(props: WidgetWithInfoPopoverProps) {
const { uiSchema = {} } = props;
const infoPopover = uiSchema["ui:options"] && uiSchema["ui:options"].infoPopover;

return (
<>
<SelectWidget {...props} size="small" />
<PositionInfoPopover>
<InfoPopover title={infoPopover?.title} iconSize="small">
<Typography
variant="body2"
pb={2}
dangerouslySetInnerHTML={{ __html: infoPopover?.content || "" }}
/>
</InfoPopover>
</PositionInfoPopover>
</>
);
}
45 changes: 45 additions & 0 deletions src/other/rjsf/widgets/TimePicker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Typography from "@mui/material/Typography";
import { AdapterMoment } from "@mui/x-date-pickers/AdapterMoment";
import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider";
import { TimePicker as MuiTimePicker } from "@mui/x-date-pickers/TimePicker";
import moment from "moment";
import React from "react";

import InfoPopover from "../../../mui/components/popover/info-popover/InfoPopover";
import { PositionInfoPopover } from "./PositionInfoPopover.styled";
import { WidgetWithInfoPopoverProps } from "./types";

export default function TimePicker(props: WidgetWithInfoPopoverProps) {
const { onChange, value, label } = props;
const { uiSchema = {}, options } = props;
const infoPopover = uiSchema["ui:options"] && uiSchema["ui:options"].infoPopover;

return (
<LocalizationProvider dateAdapter={AdapterMoment}>
<MuiTimePicker
onChange={(timeObj) => onChange(timeObj?.format("HH:mm:ss"))}
views={["hours", "minutes", "seconds"]}
format="HH:mm:ss"
ampm={false}
value={moment("1970-01-01 " + value)}
label={label}
disabled={options.disabled}
slotProps={{
textField: {
size: "small",
className: "timePickerInput",
},
}}
/>
<PositionInfoPopover>
<InfoPopover title={infoPopover?.title} iconSize="small">
<Typography
variant="body2"
pb={2}
dangerouslySetInnerHTML={{ __html: infoPopover?.content || "" }}
/>
</InfoPopover>
</PositionInfoPopover>
</LocalizationProvider>
);
}
13 changes: 13 additions & 0 deletions src/other/rjsf/widgets/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { WidgetProps } from "@rjsf/utils";

export type InfoPopoverOptions = { title: string; content: string };

type InfoPopoverUISchema = {
"ui:options"?: {
infoPopover?: InfoPopoverOptions;
};
};

export type WidgetWithInfoPopoverProps = WidgetProps & {
uiSchema?: InfoPopoverUISchema;
};

0 comments on commit a7d64c1

Please sign in to comment.