-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #211 from wri/feat/add_modal_design
Feat/Edit Modal Component and Add Modal Types
- Loading branch information
Showing
21 changed files
with
1,286 additions
and
45 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import Text from "@/components/elements/Text/Text"; | ||
|
||
import { ModalProps as Props } from "./Modal"; | ||
import Component from "./ModalAdd"; | ||
|
||
const meta: Meta<typeof Component> = { | ||
title: "Components/Extensive/Modal/ModalAdd", | ||
component: Component | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Component>; | ||
|
||
export const Default: Story = { | ||
render: (args: Props) => ( | ||
<div className="flex items-center justify-center bg-primary-400 p-8"> | ||
<Component onCLose={() => {}} {...args} /> | ||
</div> | ||
), | ||
args: { | ||
title: "Add Polygons", | ||
descriptionInput: "Drag and drop a GeoJSON, Shapefile, or KML for your site Tannous/Brayton Road.", | ||
descriptionList: ( | ||
<div className="mt-9 flex"> | ||
<Text variant="text-12-bold">TerraMatch upload limits: </Text> | ||
<Text variant="text-12-light">50 MB per upload</Text> | ||
</div> | ||
), | ||
onCLose: () => {}, | ||
content: "Start by adding polygons to your site.", | ||
primaryButtonText: "Close", | ||
primaryButtonProps: { className: "px-8 py-3", variant: "primary", onClick: () => {} } | ||
} | ||
}; |
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,156 @@ | ||
import { remove } from "lodash"; | ||
import React, { FC, ReactNode, useEffect, useState } from "react"; | ||
import { When } from "react-if"; | ||
import { twMerge } from "tailwind-merge"; | ||
|
||
import Button from "@/components/elements/Button/Button"; | ||
import FileInput from "@/components/elements/Inputs/FileInput/FileInput"; | ||
import { | ||
FileInputVariant, | ||
VARIANT_FILE_INPUT_MODAL_ADD | ||
} from "@/components/elements/Inputs/FileInput/FileInputVariants"; | ||
import Status from "@/components/elements/Status/Status"; | ||
import Text from "@/components/elements/Text/Text"; | ||
import { FileType, UploadedFile } from "@/types/common"; | ||
|
||
import Icon, { IconNames } from "../Icon/Icon"; | ||
import { ModalBaseProps, ModalProps } from "./Modal"; | ||
|
||
export const ModalAddBase: FC<ModalBaseProps> = ({ children, className, ...rest }) => { | ||
return ( | ||
<div | ||
{...rest} | ||
className={twMerge( | ||
"margin-4 z-50 m-auto flex h-[80%] max-h-full w-[776px] flex-col items-center justify-start overflow-y-auto rounded-lg border-2 border-neutral-100 bg-white", | ||
className | ||
)} | ||
> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
export interface ModalAddProps extends ModalProps { | ||
primaryButtonText?: string; | ||
secondaryButtonText?: string; | ||
descriptionInput?: string; | ||
descriptionList?: ReactNode; | ||
variantFileInput?: FileInputVariant; | ||
descriptionListStatus?: string; | ||
acceptedTYpes?: FileType[]; | ||
status?: "under-review" | "approved" | "draft" | "submitted"; | ||
onCLose?: () => void; | ||
setFile?: (file: UploadedFile[]) => void; | ||
} | ||
|
||
const ModalAdd: FC<ModalAddProps> = ({ | ||
iconProps, | ||
title, | ||
content, | ||
primaryButtonProps, | ||
primaryButtonText, | ||
secondaryButtonProps, | ||
secondaryButtonText, | ||
descriptionInput, | ||
descriptionList, | ||
descriptionListStatus, | ||
acceptedTYpes, | ||
variantFileInput = VARIANT_FILE_INPUT_MODAL_ADD, | ||
children, | ||
status, | ||
setFile, | ||
onCLose, | ||
...rest | ||
}) => { | ||
const [files, setFiles] = useState<UploadedFile[]>([]); | ||
|
||
useEffect(() => { | ||
if (setFile && files) { | ||
console.log("gets here", files); | ||
setFile(files); | ||
} | ||
}, [files]); | ||
|
||
return ( | ||
<ModalAddBase {...rest}> | ||
<header className="flex w-full items-center justify-between border-b border-b-neutral-200 px-8 py-5"> | ||
<Icon name={IconNames.WRI_LOGO} width={108} height={30} className="min-w-[108px]" /> | ||
<div className="flex items-center"> | ||
<When condition={status}> | ||
<Status status={status ? status : "draft"} className="rounded px-2 py-[2px]" textVariant="text-14-bold" /> | ||
</When> | ||
<button onClick={onCLose} className="ml-2 rounded p-1 hover:bg-grey-800"> | ||
<Icon name={IconNames.CLEAR} width={16} height={16} className="text-darkCustom-100" /> | ||
</button> | ||
</div> | ||
</header> | ||
<div className="max-h-[100%] w-full overflow-auto px-8 py-8"> | ||
<When condition={!!iconProps}> | ||
<Icon | ||
{...iconProps!} | ||
width={iconProps?.width || 40} | ||
className={twMerge("mb-8", iconProps?.className)} | ||
style={{ minHeight: iconProps?.height || iconProps?.width || 40 }} | ||
/> | ||
</When> | ||
<div className="flex items-center justify-between"> | ||
<Text variant="text-24-bold">{title}</Text> | ||
</div> | ||
<When condition={!!content}> | ||
<Text variant="text-12-light" className="mt-1 mb-4"> | ||
{content} | ||
</Text> | ||
</When> | ||
<FileInput | ||
descriptionInput={descriptionInput} | ||
descriptionList={descriptionList} | ||
descriptionListStatus={descriptionListStatus} | ||
variant={variantFileInput} | ||
accept={acceptedTYpes} | ||
onDelete={file => | ||
setFiles(state => { | ||
const tmp = [...state]; | ||
remove(tmp, f => f.uuid === file.uuid); | ||
return tmp; | ||
}) | ||
} | ||
onChange={files => | ||
setFiles(f => [ | ||
...f, | ||
...files.map(file => ({ | ||
title: file.name, | ||
file_name: file.name, | ||
mime_type: file.type, | ||
collection_name: "storybook", | ||
size: file.size, | ||
url: "https://google.com", | ||
created_at: "now", | ||
uuid: file.name, | ||
is_public: true, | ||
rawFile: file | ||
})) | ||
]) | ||
} | ||
files={files} | ||
/> | ||
{children} | ||
</div> | ||
<div className="flex w-full justify-end gap-3 px-8 py-4"> | ||
<When condition={!!secondaryButtonProps}> | ||
<Button {...secondaryButtonProps!} variant="white-page-admin"> | ||
<Text variant="text-14-bold" className="capitalize"> | ||
{secondaryButtonText} | ||
</Text> | ||
</Button> | ||
</When> | ||
<Button {...primaryButtonProps}> | ||
<Text variant="text-14-bold" className="capitalize text-white"> | ||
{primaryButtonText} | ||
</Text> | ||
</Button> | ||
</div> | ||
</ModalAddBase> | ||
); | ||
}; | ||
|
||
export default ModalAdd; |
Oops, something went wrong.