Skip to content

Commit

Permalink
Improvements (#196)
Browse files Browse the repository at this point in the history
* chore: upgrade dependencies

* fix: improve token input and asset withdraw token

* feat: add OverlaysManager
  • Loading branch information
yyyyaaa authored Jul 22, 2024
1 parent ac4a909 commit d88a3bd
Show file tree
Hide file tree
Showing 18 changed files with 264 additions and 288 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
"@babel/preset-env": "^7.24.7",
"@babel/preset-react": "^7.24.7",
"@babel/preset-typescript": "^7.24.7",
"@builder.io/eslint-plugin-mitosis": "^0.0.15",
"@builder.io/mitosis-cli": "0.1.6",
"@builder.io/eslint-plugin-mitosis": "^0.0.16",
"@builder.io/mitosis": "0.3.11",
"@builder.io/mitosis-cli": "0.3.11",
"@formkit/auto-animate": "^0.8.2",
"@parcel/packager-ts": "^2.12.0",
"@parcel/transformer-typescript-types": "^2.12.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/react/.storybook/WithThemeDecorator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ThemeProvider,
Select,
SelectOption,
OverlaysManager,
useTheme,
} from "../src";
import { DEFAULT_ACCENTS, Accent } from "../src/styles/tokens";
Expand Down Expand Up @@ -109,6 +110,7 @@ const WithThemeDecorator = (props) => {
// }}
>
<ThemeShell {...props} />
<OverlaysManager />
</ThemeProvider>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import {
import Box from "@/ui/box";
import ChainSwapInput from "@/ui/chain-swap-input";
import ChainListItem from "@/ui/chain-list-item";
import { closestBodyElement } from "@/helpers/platform";

import * as styles from "./chain-swap-combobox.css";
import type { ChainListItemProps } from "@/ui/chain-list-item/chain-list-item.types";
import type { Sprinkles } from "@/styles/rainbow-sprinkles.css";
import { overlays } from "@/ui/overlays-manager/overlays";
import useTheme from "@/ui/hooks/use-theme";

interface ItemProps {
Expand Down Expand Up @@ -212,7 +212,7 @@ export default function ChainSwapCombobox(props: ChainSwapComboboxProps) {
return setMountRoot(props.rootNode);
}

setMountRoot(closestBodyElement(containerRef.current));
setMountRoot(overlays.getOrCreateOverlayRoot(containerRef.current));
}, []);

return (
Expand Down
17 changes: 16 additions & 1 deletion packages/react/scaffolds/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import clx from "clsx";
import React, { cloneElement, forwardRef } from "react";
import useTheme from "../hooks/use-theme";
import { overlays } from "@/ui/overlays-manager/overlays";
import * as styles from "./modal.css";

interface DialogOptions {
Expand Down Expand Up @@ -149,6 +150,10 @@ const Modal = forwardRef<HTMLDivElement, ModalProps>((props, forwardedRef) => {
childrenClassName,
} = props;

const [defaultRoot, setDefaultRoot] = React.useState<HTMLElement | null>(
null,
);

const dialog = useDialog({
initialOpen,
open: isOpen,
Expand All @@ -166,6 +171,16 @@ const Modal = forwardRef<HTMLDivElement, ModalProps>((props, forwardedRef) => {

const { styles: transitionStyles } = useTransitionStyles(dialog.context);

React.useEffect(() => {
// User-provided root
if (root) {
return;
}

// Default lib root
setDefaultRoot(overlays.getOrCreateOverlayRoot(window.document));
}, []);

React.useEffect(() => {
dialog.setLabelId(id);
return () => dialog.setLabelId(undefined);
Expand All @@ -186,7 +201,7 @@ const Modal = forwardRef<HTMLDivElement, ModalProps>((props, forwardedRef) => {
{typeof renderTrigger === "function" ? renderTrigger(triggerProps) : null}

{dialog.open && (
<FloatingPortal root={root}>
<FloatingPortal root={root ? root : defaultRoot}>
<FloatingOverlay
className={clx(themeClassName)}
lockScroll={preventScroll}
Expand Down
12 changes: 11 additions & 1 deletion packages/react/scaffolds/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
selectFullWidth,
} from "./select.css";
import { Item, SelectContext, SelectContextValue } from "./select.context";
import { overlays } from "@/ui/overlays-manager/overlays";

const DEFAULT_LIST_WIDTH = "220";

Expand Down Expand Up @@ -142,6 +143,15 @@ export default function Select(props: SelectProps) {
[elementsRef, handleSelect],
);

const [defaultRoot, setDefaultRoot] = React.useState<HTMLElement | null>(
null,
);

React.useEffect(() => {
// Default lib root
setDefaultRoot(overlays.getOrCreateOverlayRoot(window.document));
}, []);

React.useEffect(() => {
if (!!props.defaultSelectedItem) {
handleSelect(props.defaultSelectedItem);
Expand Down Expand Up @@ -235,7 +245,7 @@ export default function Select(props: SelectProps) {
</div>

<SelectContext.Provider value={selectContext}>
<FloatingPortal>
<FloatingPortal root={defaultRoot}>
<div
ref={refs.setFloating}
tabIndex={-1}
Expand Down
11 changes: 8 additions & 3 deletions packages/react/stories/TokenInput.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useState } from "react";
import type { Meta, StoryObj } from "@storybook/react";
import { asset_list, assets } from "@chain-registry/osmosis";
import { getAssetByDenom } from "@chain-registry/utils";
import { Asset as OsmosisAsset } from "@chain-registry/types";

import TokenInput from "../src/ui/token-input";
Expand All @@ -18,14 +17,14 @@ export default meta;
type Story = StoryObj<typeof meta>;

const osmosisAssets: OsmosisAsset[] = [...assets.assets, ...asset_list.assets];
const OSMO = getAssetByDenom(osmosisAssets, "uosmo");
const OSMO = osmosisAssets.find((asset) => asset.symbol === "OSMO")!;

/* This is primary TokenInput */
export const Primary: Story = {
args: {
symbol: OSMO.symbol,
name: OSMO.name,
available: 0.71263,
available: 23345.44,
priceDisplayAmount: 0.5,
tokenIcon: OSMO.logo_URIs?.png,
onAmountChange: (value) => {
Expand All @@ -34,14 +33,20 @@ export const Primary: Story = {
},
render: (props) => {
const [progress, setProgress] = useState(50);
const [amount, setAmount] = useState(0);

const onProgressChange = (value) => {
console.log("onProgressChange", value);
setProgress(value);
};

return (
<TokenInput
{...props}
amount={amount}
onAmountChange={(value) => {
setAmount(value);
}}
progress={progress}
onProgressChange={onProgressChange}
/>
Expand Down
4 changes: 2 additions & 2 deletions packages/react/stories/asset/AssetDeposit.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const DepositAsset: Story = {
available: 25.89,
amount: "",
priceDisplayAmount: 0.5,
timeEstimateLabel: "20 seconds",
timeEstimateLabel: "30 seconds",
onChange: (value) => {
console.log("onChange", value);
},
Expand Down Expand Up @@ -104,7 +104,7 @@ export const DepositModalView: Story = {
available: 25.89,
amount: "",
priceDisplayAmount: 0.5,
timeEstimateLabel: "20 seconds",
timeEstimateLabel: "30 seconds",
onChange: (value) => {
console.log("onChange", value);
},
Expand Down
Loading

0 comments on commit d88a3bd

Please sign in to comment.