Skip to content

Commit

Permalink
chore: new buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Jun 18, 2024
1 parent 1e1411d commit cf136ed
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 26 deletions.
56 changes: 30 additions & 26 deletions src/components/Forms/Formik/FormikConfigFormFieldsArray.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { FieldArray, useFormikContext } from "formik";
import { get } from "lodash";
import React, { useMemo } from "react";
import { FaPlus, FaTrash } from "react-icons/fa";
import { FaTrash } from "react-icons/fa";
import { Button } from "../../../ui/Buttons/Button";
import { BsPlusCircleFill } from "react-icons/bs";
import clsx from "clsx";

type ConfigFormFieldProps = {
label: string;
containerClassName?: string;
className?: string;
hint?: string;
name: string;
/**
*
Expand All @@ -34,56 +37,57 @@ export default function FormikConfigFormFieldsArray({
fields,
label,
containerClassName = "flex flex-col space-y-2",
className = "flex flex-row w-full space-x-2"
className = "flex flex-row w-full space-x-2",
hint = ""
}: ConfigFormFieldProps) {
const { values } = useFormikContext<Record<string, any>>();

const fieldValue = useMemo(() => get(values, name), [name, values]);

return (
<div className={containerClassName}>
<label className="text-sm font-semibold">{label}</label>
<label className="text-sm font-semibold">{label} </label>
{hint && <p className="text-sm text-gray-500 py-1 p-1">{hint}</p>}

<FieldArray
name={name}
render={(arrayHelpers) => (
<div className={`flex flex-col space-y-2 p-4`}>
<div className={`flex flex-col space-y-1 `}>
{fieldValue &&
fieldValue.length > 0 &&
fieldValue.map((_: any, index: number) => (
<div className={className} key={index}>
{fields.length > 0 &&
fields.map(
({
name: fieldName,
label: fieldLabel,
fieldComponent: Field,
className
}) => (
<Field
key={fieldName}
name={
fields.length > 1
? `${name}.${index}.${fieldName}`
: `${name}.${index}`
}
label={fields.length > 1 ? fieldLabel : undefined}
className={className}
/>
)
)}
fields.map((field) => (
<field.fieldComponent
key={field.name}
name={
fields.length > 1
? `${name}.${index}.${field.name}`
: `${name}.${index}`
}
label={fields.length > 1 ? field.label : undefined}
className={clsx(
"text-xs",
"sm:text-xs",
field.className
)}
hint={field.hint}
/>
))}
<Button
onClick={() => arrayHelpers.remove(index)}
icon={<FaTrash />}
className="btn-white w-auto"
className="btn-icon pl-0"
/>
</div>
))}
<div className="flex flex-row flex-1">
<Button
onClick={() => arrayHelpers.push(fields.length === 1 ? "" : {})}
text={`Add`}
icon={<FaPlus />}
className="btn-white"
icon={<BsPlusCircleFill />}
className="btn-icon pl-1"
/>
</div>
</div>
Expand Down
24 changes: 24 additions & 0 deletions src/ui/Buttons/CardButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ReactNode } from "react";

export default function CardButton({
onClick,
icon,
text
}: {
onClick: () => Promise<void> | void;
icon: ReactNode;
text: string;
}) {
return (
<div className="flex flex-col flex-1/4 p-2 min-w-[25ch] max-w-[25ch]">
<div
role="button"
className="flex flex-col items-center space-y-2 justify-center p-2 border border-gray-300 hover:border-blue-200 hover:bg-gray-100 rounded-md text-center h-20"
onClick={(e) => onClick()}
>
<div className="flex flex-col items-center justify-center">{icon}</div>
<div>{text}</div>
</div>
</div>
);
}
22 changes: 22 additions & 0 deletions src/ui/Buttons/DialogButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { IconType } from "react-icons";

export default function DialogButton({
onClick,
icon
}: {
onClick: any;
icon: IconType;
}) {
const Icon = icon;
return (
<div className="flex pointer-events-none sm:pointer-events-auto">
<button
type="button"
className="text-gray-400 hover:text-gray-500 focus:outline-none"
onClick={onClick}
>
<Icon className="fill-gray-400 w-auto h-5" aria-hidden="true" />
</button>
</div>
);
}
15 changes: 15 additions & 0 deletions src/ui/Buttons/HelpLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { IoMdHelp } from "react-icons/io";

export default function HelpLink({ link }: { link: string }) {
return (
<a
title="Link to documentation"
href={`https://docs.flanksource.com/${link}`}
target="_blank"
rel="noopener noreferrer"
className="flex items-center justify-center text-gray-400 hover:text-gray-500 focus:outline-none"
>
<IoMdHelp size={22} className="inline-block" />
</a>
);
}
11 changes: 11 additions & 0 deletions src/ui/Code/CodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ window.MonacoEnvironment = {

interface Props {
value?: string;
lines?: number;
height?: string;
readOnly?: boolean;
onChange: (value: string | undefined, viewUpdate: unknown) => void;
/**
Expand All @@ -41,6 +43,8 @@ interface Props {

export function CodeEditor({
value,
lines,
height,
onChange,
readOnly = false,
schemaFileName,
Expand Down Expand Up @@ -136,6 +140,11 @@ export function CodeEditor({
}
}, [language, onChange, value]);

const lineHeight = 15;
if (lines) {
height = `${lines * lineHeight + 20}px`;
}

return (
<>
{enableSpecUnwrap && inlineSpec && (
Expand All @@ -158,11 +167,13 @@ export function CodeEditor({
language={language}
value={value}
onChange={onChange}
height={height}
width="100%"
options={{
renderLineHighlight: "none",
readOnly,
minimap: { enabled: false },
lineHeight: lineHeight,
scrollBeyondLastLine: false
}}
{...{
Expand Down

0 comments on commit cf136ed

Please sign in to comment.