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

refactor(components): only use css stylable props #5977

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 7 additions & 7 deletions app/src/components/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import {
Button as AriaButton,
ButtonProps as AriaButtonProps,
} from "react-aria-components";
import { css } from "@emotion/react";

import {
SizingProps,
StyleProps,
StylableProps,
VarianceProps,
} from "@phoenix/components/types";
import { useStyleProps } from "@phoenix/components/utils";

import { buttonCSS } from "./styles";

interface ButtonProps
extends Omit<AriaButtonProps, "className">,
extends AriaButtonProps,
SizingProps,
VarianceProps,
StyleProps {
StylableProps {
/**
* An optional prefixed icon for the button
*/
Expand All @@ -30,18 +30,18 @@ function Button(props: ButtonProps, ref: Ref<HTMLButtonElement>) {
variant = "default",
icon,
children,
css: propCSS,
...otherProps
} = props;
const { styleProps } = useStyleProps<StyleProps>(otherProps);

return (
<AriaButton
{...otherProps}
ref={ref}
data-size={size}
data-variant={variant}
data-childless={!children}
css={buttonCSS}
style={styleProps.style}
css={css(buttonCSS, propCSS)}
>
{icon}
<>{children}</>
Expand Down
12 changes: 5 additions & 7 deletions app/src/components/disclosure/Disclosure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ import {
type DisclosureProps as AriaDisclosureProps,
Heading,
} from "react-aria-components";
import { css, SerializedStyles } from "@emotion/react";
import { css } from "@emotion/react";

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

import { FlexStyleProps, SizingProps } from "../types";
import { FlexStyleProps, SizingProps, StylableProps } from "../types";

import { disclosureCSS, disclosureGroupCSS } from "./styles";

export type DisclosureGroupProps = AriaDisclosureGroupProps & {
css?: SerializedStyles;
};
export type DisclosureGroupProps = AriaDisclosureGroupProps & StylableProps;

/**
* Wrap multiple Disclosure components in a DisclosureGroup to control
Expand All @@ -29,14 +27,14 @@ export type DisclosureGroupProps = AriaDisclosureGroupProps & {
*/
export const DisclosureGroup = ({
className,
css: cssProp,
css: propCSS,
...props
}: DisclosureGroupProps) => {
return (
<AriaDisclosureGroup
allowsMultipleExpanded
className={classNames("ac-disclosure-group", className)}
css={css(disclosureGroupCSS, cssProp)}
css={css(disclosureGroupCSS, propCSS)}
{...props}
/>
);
Expand Down
13 changes: 13 additions & 0 deletions app/src/components/types/style.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SerializedStyles } from "@emotion/react";

export type ColorValue =
| "grey-50"
| "grey-75"
Expand Down Expand Up @@ -584,3 +586,14 @@ export type TextColorValue =
| "text-300"
| "inherit"
| ColorValue;

/**
* Makes a component stylable with emotion in addition to the component's styles.
* To be used sparingly when a component needs to be styled for very specific use cases.
*/
export interface StylableProps {
/**
* Take an emotion css prop to be merged after the component's styles.
*/
css?: SerializedStyles;
}
5 changes: 4 additions & 1 deletion app/src/pages/prompt/DeletePromptVersionTagButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import { graphql, useMutation } from "react-relay";
import { css } from "@emotion/react";

import {
Button,
Expand Down Expand Up @@ -58,7 +59,9 @@ export function DeletePromptVersionTagButton({
</Text>
</View>
<Button
width="100%"
css={css`
width: 100%;
`}
variant="danger"
size="S"
onPress={() =>
Expand Down
5 changes: 4 additions & 1 deletion app/src/pages/prompt/TagPromptVersionButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Suspense, useState } from "react";
import { graphql, useLazyLoadQuery, useMutation } from "react-relay";
import { useParams } from "react-router";
import { css } from "@emotion/react";

import {
Button,
Expand Down Expand Up @@ -64,7 +65,9 @@ export function TagPromptVersionButton() {
<Button
icon={<Icon svg={<Icons.PlusOutline />} />}
size="S"
width="100%"
css={css`
width: 100%;
`}
onPress={() => setShowNewTagDialog(true)}
>
New Tag
Expand Down
11 changes: 11 additions & 0 deletions app/stories/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import { Meta, StoryFn } from "@storybook/react";
import { css } from "@emotion/react";

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

Expand All @@ -26,3 +27,13 @@ export const Default = Template.bind({});
Default.args = {
children: "Button",
};

export const CustomCSS = Template.bind({});

CustomCSS.args = {
css: css`
/* TODO: we need to make it simpler to not have to make styles more specific */
border-color: var(--ac-global-color-primary) !important;
`,
children: "Custom",
};
Loading