Skip to content

Commit

Permalink
chore: migrate flex (#5835)
Browse files Browse the repository at this point in the history
* chore: migrate flex

* chore: migrate flex component

* prettier
  • Loading branch information
mikeldking authored Dec 27, 2024
1 parent c3444e3 commit da551d7
Show file tree
Hide file tree
Showing 107 changed files with 312 additions and 275 deletions.
13 changes: 9 additions & 4 deletions app/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,27 @@ module.exports = {
{
name: "Button",
module: "@arizeai/components",
use: "@phoenix/components/button",
use: "@phoenix/components",
},
{
name: "Icon",
module: "@arizeai/components",
use: "@phoenix/components/icon",
use: "@phoenix/components",
},
{
name: "Icons",
module: "@arizeai/components",
use: "@phoenix/components/icon",
use: "@phoenix/components",
},
{
name: "View",
module: "@arizeai/components",
use: "@phoenix/components/view",
use: "@phoenix/components",
},
{
name: "Flex",
module: "@arizeai/components",
use: "@phoenix/components",
},
],
"no-duplicate-imports": "error",
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/ConfirmNavigation.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { ReactNode } from "react";
import { Blocker } from "react-router";

import { Dialog, DialogContainer, Flex, Text } from "@arizeai/components";
import { Dialog, DialogContainer, Text } from "@arizeai/components";

import { Button, View } from "@phoenix/components";
import { Button, Flex, View } from "@phoenix/components";

function ConfirmNavigationDialogFooter({ blocker }: { blocker: Blocker }) {
return (
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { ReactNode } from "react";
import { css } from "@emotion/react";

import { EmptyGraphic, Flex } from "@arizeai/components";
import { EmptyGraphic } from "@arizeai/components";

import { View } from "@phoenix/components";
import { Flex, View } from "@phoenix/components";

import { ExternalLink } from "./ExternalLink";
type ErrorBoundaryProps = { children: ReactNode };
Expand Down
4 changes: 1 addition & 3 deletions app/src/components/ViewSummaryAside.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React, { PropsWithChildren } from "react";

import { Flex } from "@arizeai/components";

import { View, ViewProps } from "@phoenix/components";
import { Flex, View, ViewProps } from "@phoenix/components";

type ViewSummaryAsideProps = PropsWithChildren<{
width?: ViewProps["width"];
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/annotation/AnnotationLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from "react";
import { css } from "@emotion/react";

import { Flex, Text } from "@arizeai/components";
import { Text } from "@arizeai/components";

import { Icon, Icons } from "@phoenix/components";
import { Flex, Icon, Icons } from "@phoenix/components";
import { assertUnreachable } from "@phoenix/typeUtils";
import { formatFloat } from "@phoenix/utils/numberFormatUtils";

Expand Down
3 changes: 1 addition & 2 deletions app/src/components/annotation/AnnotationTooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import React, { CSSProperties, ReactNode } from "react";

import {
Flex,
HelpTooltip,
Text,
TooltipTrigger,
TriggerWrap,
} from "@arizeai/components";

import { View } from "@phoenix/components";
import { Flex, View } from "@phoenix/components";
import { floatFormatter } from "@phoenix/utils/numberFormatUtils";

import { Annotation } from "./types";
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/auth/CreateAPIKeyDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Controller, useForm } from "react-hook-form";
import { Form } from "react-router-dom";
import { isValid as dateIsValid, parseISO } from "date-fns";

import { Dialog, Flex, TextArea, TextField } from "@arizeai/components";
import { Dialog, TextArea, TextField } from "@arizeai/components";

import { Button, View } from "@phoenix/components";
import { Button, Flex, View } from "@phoenix/components";

export type APIKeyFormParams = {
name: string;
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/auth/DeleteAPIKeyButton.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { ReactNode, useState } from "react";

import { Dialog, DialogContainer, Flex, Text } from "@arizeai/components";
import { Dialog, DialogContainer, Text } from "@arizeai/components";

import { Button, Icon, Icons, View } from "@phoenix/components";
import { Button, Flex, Icon, Icons, View } from "@phoenix/components";

export function DeleteAPIKeyButton({
handleDelete,
Expand Down
11 changes: 2 additions & 9 deletions app/src/components/auth/OneTimeAPIKeyDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import React from "react";
import { css } from "@emotion/react";

import {
Alert,
Dialog,
Flex,
Heading,
Text,
TextField,
} from "@arizeai/components";
import { Alert, Dialog, Heading, Text, TextField } from "@arizeai/components";

import { ExternalLink, View } from "@phoenix/components";
import { ExternalLink, Flex, View } from "@phoenix/components";
import { CodeWrap, PythonBlockWithCopy } from "@phoenix/components/code";
import { CopyToClipboardButton } from "@phoenix/components/CopyToClipboardButton";

Expand Down
4 changes: 2 additions & 2 deletions app/src/components/dataset/DatasetForm.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from "react";
import { Controller, useForm } from "react-hook-form";

import { Flex, Form, TextArea, TextField } from "@arizeai/components";
import { Form, TextArea, TextField } from "@arizeai/components";

import { Button, View } from "@phoenix/components";
import { Button, Flex, View } from "@phoenix/components";
import { CodeEditorFieldWrapper, JSONEditor } from "@phoenix/components/code";
import { isJSONObjectString } from "@phoenix/utils/jsonUtils";

Expand Down
4 changes: 3 additions & 1 deletion app/src/components/dataset/DatasetPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from "react";
import { graphql, useLazyLoadQuery } from "react-relay";

import { Flex, Item, Picker, PickerProps, Text } from "@arizeai/components";
import { Item, Picker, PickerProps, Text } from "@arizeai/components";

import { Flex } from "@phoenix/components";

import { DatasetPickerQuery } from "./__generated__/DatasetPickerQuery.graphql";

Expand Down
3 changes: 1 addition & 2 deletions app/src/components/experiment/ExperimentActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import {
ActionMenuProps,
Dialog,
DialogContainer,
Flex,
Item,
Text,
} from "@arizeai/components";

import { Icon, Icons } from "@phoenix/components";
import { Flex, Icon, Icons } from "@phoenix/components";
import { JSONBlock } from "@phoenix/components/code";
import { useNotifySuccess } from "@phoenix/contexts";
import { assertUnreachable } from "@phoenix/typeUtils";
Expand Down
4 changes: 3 additions & 1 deletion app/src/components/generative/ToolChoiceSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from "react";

import { Flex, Item, Label, Picker } from "@arizeai/components";
import { Item, Label, Picker } from "@arizeai/components";

import { Flex } from "@phoenix/components";

type DefaultToolChoice = Extract<ToolChoice, "auto" | "required" | "none">;

Expand Down
1 change: 1 addition & 0 deletions app/src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * from "./combobox";
export * from "./button";
export * from "./icon";
export * from "./view";
export * from "./layout";
105 changes: 105 additions & 0 deletions app/src/components/layout/Flex.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import React, { forwardRef, ReactNode, Ref } from "react";
import { filterDOMProps } from "@react-aria/utils";
import { css } from "@emotion/react";

import { DOMProps, FlexStyleProps } from "@phoenix/components/types";
import {
passthroughStyle,
responsiveDimensionValue,
StyleHandlers,
useStyleProps,
} from "@phoenix/components/utils";

export interface FlexProps extends DOMProps, FlexStyleProps {
/** Children of the flex container. */
children: ReactNode;
}

const flexCSS = css`
display: flex;
`;

const flexStyleProps: StyleHandlers = {
direction: ["flexDirection", passthroughStyle],
wrap: ["flexWrap", flexWrapValue],
justifyContent: ["justifyContent", flexAlignValue],
alignItems: ["alignItems", flexAlignValue],
alignContent: ["alignContent", flexAlignValue],
};

function Flex(props: FlexProps, ref: Ref<HTMLDivElement>) {
const { children, ...otherProps } = props;

const matchedBreakpoints = ["base"];
const { styleProps } = useStyleProps(otherProps);
const { styleProps: flexStyle } = useStyleProps(otherProps, flexStyleProps);

// If no gaps, or native support exists, then we only need to render a single div.
const style = {
...styleProps.style,
...flexStyle.style,
};

if (props.gap != null) {
style.gap = responsiveDimensionValue(props.gap, matchedBreakpoints);
}

if (props.columnGap != null) {
style.columnGap = responsiveDimensionValue(
props.columnGap,
matchedBreakpoints
);
}

if (props.rowGap != null) {
style.rowGap = responsiveDimensionValue(props.rowGap, matchedBreakpoints);
}

return (
<div
css={flexCSS}
{...filterDOMProps(otherProps)}
className="flex"
style={style}
ref={ref}
>
{children}
</div>
);
}

/**
* Normalize 'start' and 'end' alignment values to 'flex-start' and 'flex-end'
* in flex containers for browser compatibility.
*/

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function flexAlignValue(value: any) {
if (value === "start") {
return "flex-start";
}

if (value === "end") {
return "flex-end";
}

return value;
}

/**
* Takes a boolean and translates it to flex wrap or nowrap.
*/
function flexWrapValue(value: boolean | "wrap" | "nowrap") {
if (typeof value === "boolean") {
return value ? "wrap" : "nowrap";
}

return value;
}

/**
* A layout container using flexbox. Provides dimension values, and supports the gap
* property to define consistent spacing between items.
*/
const _Flex = forwardRef(Flex);
export { _Flex as Flex };
1 change: 1 addition & 0 deletions app/src/components/layout/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Flex";
3 changes: 2 additions & 1 deletion app/src/components/pointcloud/ClusterItem.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useMemo } from "react";
import { css } from "@emotion/react";

import { Flex, Heading, Text } from "@arizeai/components";
import { Heading, Text } from "@arizeai/components";

import { Flex } from "@phoenix/components";
import { InferencesRole } from "@phoenix/types";
import { numberFormatter } from "@phoenix/utils/numberFormatUtils";

Expand Down
4 changes: 2 additions & 2 deletions app/src/components/settings/UserForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from "react";
import { Controller, useForm } from "react-hook-form";
import { css } from "@emotion/react";

import { Flex, Form, TextField } from "@arizeai/components";
import { Form, TextField } from "@arizeai/components";

import { Button, View } from "@phoenix/components";
import { Button, Flex, View } from "@phoenix/components";
import { UserRole } from "@phoenix/constants";

import { RolePicker } from "./RolePicker";
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/trace/AnnotationActionMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react";

import { ActionMenu, Flex, Item, Text } from "@arizeai/components";
import { ActionMenu, Item, Text } from "@arizeai/components";

import { Icon, Icons } from "@phoenix/components";
import { Flex, Icon, Icons } from "@phoenix/components";

type AnnotationActionMenuProps = {
onDelete: () => void;
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/trace/LatencyText.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useMemo } from "react";

import { Flex, Text, TextProps } from "@arizeai/components";
import { Text, TextProps } from "@arizeai/components";

import { Icon, Icons } from "@phoenix/components";
import { Flex, Icon, Icons } from "@phoenix/components";
import { formatFloat } from "@phoenix/utils/numberFormatUtils";
export function LatencyText({
latencyMs,
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/trace/SpanAnnotationActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import React, {
} from "react";
import { graphql, useMutation } from "react-relay";

import { Dialog, DialogContainer, Flex, Text } from "@arizeai/components";
import { Dialog, DialogContainer, Text } from "@arizeai/components";
import { NoticeConfig } from "@arizeai/components/dist/notification/types";

import { Button, View } from "@phoenix/components";
import { Button, Flex, View } from "@phoenix/components";

import { SpanAnnotationActionMenuDeleteMutation } from "./__generated__/SpanAnnotationActionMenuDeleteMutation.graphql";
import { AnnotationActionMenu } from "./AnnotationActionMenu";
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/trace/SpanAnnotationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React, { useCallback } from "react";
import { Controller, useForm } from "react-hook-form";
import { css } from "@emotion/react";

import { Flex, Form, TextArea, TextField } from "@arizeai/components";
import { Form, TextArea, TextField } from "@arizeai/components";

import { Button, View } from "@phoenix/components";
import { Button, Flex, View } from "@phoenix/components";
export type AnnotationFormData = {
name: string;
score?: number | null;
Expand Down
3 changes: 1 addition & 2 deletions app/src/components/trace/TokenCount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import React from "react";
import { css } from "@emotion/react";

import {
Flex,
Text,
TextProps,
Tooltip,
TooltipTrigger,
TriggerWrap,
} from "@arizeai/components";

import { Icon, Icons } from "@phoenix/components";
import { Flex, Icon, Icons } from "@phoenix/components";

type TokenCountProps = {
/**
Expand Down
3 changes: 1 addition & 2 deletions app/src/components/trace/TraceTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import { css } from "@emotion/react";

import {
classNames,
Flex,
Tooltip,
TooltipTrigger,
TriggerWrap,
} from "@arizeai/components";

import { Button, Icon, Icons, View } from "@phoenix/components";
import { Button, Flex, Icon, Icons, View } from "@phoenix/components";
import { TokenCount } from "@phoenix/components/trace/TokenCount";
import { usePreferencesContext } from "@phoenix/contexts/PreferencesContext";

Expand Down
Loading

0 comments on commit da551d7

Please sign in to comment.