Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SWUI-20][DOCS] - Add Popover to SwaprUI Website #17

Merged
merged 5 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions apps/website/app/ui/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
ButtonLink,
} from "swapr-ui";

import { ThemeSwitch } from "@/components";
import { PopoverSection, Section, ThemeSwitch } from "@/components";

const colorsKeysBanList = ["transparent", "inherit"];
const fullConfig = resolveConfig(tailwindConfig);
Expand Down Expand Up @@ -877,15 +877,11 @@ export default function UI() {
))}
</div>
</Section>
<PopoverSection />
</div>
</main>
);
}

const Section = ({ children }: PropsWithChildren) => {
return <section className="space-y-4 py-12 border-b">{children}</section>;
};

interface ButtonSectionProps extends PropsWithChildren {
btnList: {
headers: Array<string>;
Expand Down
37 changes: 37 additions & 0 deletions apps/website/components/PopoverSection/PopoverSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Section } from "@/components";
import {
PopoverBasic,
PopoverSlippageSettings,
PopoverWithHeader,
} from "./examples";

interface PopoverList {
headers: Array<string>;
examples: Array<() => JSX.Element>;
}

const popoverList: PopoverList = {
headers: ["Basic", "With Header", "Settings example"],
examples: [PopoverBasic, PopoverWithHeader, PopoverSlippageSettings],
};

export const PopoverSection = () => (
<Section>
<h2 className="text-2xl font-semibold">Popovers</h2>
<div className="grid items-center space-y-2.5 lg:space-y-0 lg:grid-cols-3 lg:gap-4">
{popoverList.headers.map((header, index) => (
<div
key={index}
className="hidden uppercase text-xs lg:block font-semibold bg-gray-200 text-center"
>
{header}
</div>
))}
{popoverList.examples.map((Example, index) => (
<div key={index} className="flex items-center justify-center">
<Example />
</div>
))}
</div>
</Section>
);
87 changes: 87 additions & 0 deletions apps/website/components/PopoverSection/examples.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import {
Button,
ChipButton,
Icon,
IconButton,
Popover,
PopoverContent,
PopoverContentHeader,
PopoverTrigger,
TabGroup,
TabHeader,
TabStyled,
} from "swapr-ui";
import { Root as Separator } from "@radix-ui/react-separator";

const SettingsPopoverContent = () => (
<div className="space-y-2">
<div className="flex items-center mx-4 text-text-low-em">
<p className="font-bold text-xs">MAX SLIPPAGE</p>
<Icon className="ml-1 text-text-low-em" name="info-fill" size={14} />
</div>
<TabGroup
as="div"
onChange={(index: number) =>
console.log("Changed selected tab to:", index)
}
className="mx-4"
>
<TabHeader className="overflow-x-auto md:overflow-x-visible last:right-0 flex justify-between">
<div className="flex space-x-3">
<TabStyled>Auto</TabStyled>
<TabStyled>0.1%</TabStyled>
<TabStyled>0.5%</TabStyled>
</div>
<ChipButton>3 %</ChipButton>
</TabHeader>
</TabGroup>
<p className="font-semibold mt-4 mx-4 text-text-primary-main text-sm">
Custom slippage: 3%
</p>
<div className="bg-surface-danger-accent-1 font-semibold mx-4 px-3 py-2 rounded-8 text-text-danger-em text-sm">
The slippage you selected is greater than what is required to perform this
transaction. We recommend selecting the Auto Slippage option for this
transaction.
</div>
<Separator decorative className="h-[1px] bg-outline-base-em" />
<div className="flex items-center mx-4 text-text-low-em">
<p className="font-bold text-xs">TRANSACTION DEADLINE</p>
<Icon className="ml-1 text-text-low-em" name="info-fill" size={14} />
</div>
<ChipButton className="mx-4">10 mins</ChipButton>
</div>
);

export const PopoverBasic = () => (
<Popover>
<PopoverTrigger>
<Button>Open Popup</Button>
</PopoverTrigger>
<PopoverContent>
<p>This is a basic content example</p>
</PopoverContent>
</Popover>
);

export const PopoverWithHeader = () => (
<Popover>
<PopoverTrigger>
<Button>With header</Button>
</PopoverTrigger>
<PopoverContent className="max-w-md px-0">
<PopoverContentHeader title="Settings" />
<SettingsPopoverContent />
</PopoverContent>
</Popover>
);

export const PopoverSlippageSettings = () => (
<Popover>
<PopoverTrigger>
<IconButton name="settings" />
</PopoverTrigger>
<PopoverContent className="max-w-md px-0">
<SettingsPopoverContent />
</PopoverContent>
</Popover>
);
1 change: 1 addition & 0 deletions apps/website/components/PopoverSection/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./PopoverSection";
5 changes: 5 additions & 0 deletions apps/website/components/Section.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { PropsWithChildren } from "react";

export const Section = ({ children }: PropsWithChildren) => (
<section className="space-y-4 py-12 border-b">{children}</section>
);
2 changes: 2 additions & 0 deletions apps/website/components/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from "./PopoverSection";
export * from "./Section";
export * from "./ThemeSwitch";