-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Remove asChild from the StudioButton component (#14038)
- Loading branch information
Showing
21 changed files
with
265 additions
and
130 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
39 changes: 26 additions & 13 deletions
39
...components/StudioPageHeader/StudioPageHeaderHeaderButton/StudioPageHeaderHeaderButton.tsx
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 |
---|---|---|
@@ -1,26 +1,39 @@ | ||
import React, { forwardRef, type ReactElement } from 'react'; | ||
import React, { type ElementType, forwardRef, type ReactElement } from 'react'; | ||
import classes from '../common.module.css'; | ||
import { StudioButton, type StudioButtonProps } from '../../StudioButton'; | ||
import { type StudioPageHeaderColor } from '../types/StudioPageHeaderColor'; | ||
import cn from 'classnames'; | ||
import { type StudioPageHeaderVariant } from '../types/StudioPageHeaderVariant'; | ||
import type { OverridableComponent } from '../../../types/OverridableComponent'; | ||
import type { OverridableComponentProps } from '../../../types/OverridableComponentProps'; | ||
import type { OverridableComponentRef } from '../../../types/OverridableComponentRef'; | ||
|
||
export type StudioPageHeaderHeaderButtonProps = { | ||
color: StudioPageHeaderColor; | ||
variant: StudioPageHeaderVariant; | ||
} & Omit<StudioButtonProps, 'color' | 'variant'>; | ||
|
||
export const StudioPageHeaderHeaderButton = forwardRef< | ||
HTMLButtonElement, | ||
StudioPageHeaderHeaderButtonProps | ||
>(({ color, variant, className: givenClass, ...rest }, ref): ReactElement => { | ||
return ( | ||
<StudioButton | ||
ref={ref} | ||
className={cn(classes.linkOrButton, classes[variant], classes[color], givenClass)} | ||
{...rest} | ||
/> | ||
); | ||
}); | ||
export const StudioPageHeaderHeaderButton: OverridableComponent< | ||
StudioPageHeaderHeaderButtonProps, | ||
HTMLButtonElement | ||
> = forwardRef( | ||
<As extends ElementType = 'button'>( | ||
{ | ||
color, | ||
variant, | ||
className: givenClass, | ||
...rest | ||
}: OverridableComponentProps<StudioPageHeaderHeaderButtonProps, As>, | ||
ref: OverridableComponentRef<As>, | ||
): ReactElement => { | ||
return ( | ||
<StudioButton | ||
ref={ref} | ||
className={cn(classes.linkOrButton, classes[variant], classes[color], givenClass)} | ||
{...rest} | ||
/> | ||
); | ||
}, | ||
); | ||
|
||
StudioPageHeaderHeaderButton.displayName = 'StudioPageHeader.HeaderButton'; |
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
10 changes: 3 additions & 7 deletions
10
frontend/libs/studio-components/src/types/OverridableComponent.ts
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 |
---|---|---|
@@ -1,11 +1,7 @@ | ||
import type { RefAttributes, FC, ElementType, ComponentPropsWithRef } from 'react'; | ||
import type { RefAttributes, FC, ElementType } from 'react'; | ||
import type { OverridableComponentProps } from './OverridableComponentProps'; | ||
|
||
export type OverridableComponent<ComponentProps, Element extends HTMLElement> = { | ||
(props: ComponentProps & RefAttributes<Element>): ReturnType<FC>; | ||
<As extends ElementType>( | ||
props: { | ||
as?: As; | ||
} & ComponentProps & | ||
Omit<ComponentPropsWithRef<As>, keyof ComponentProps>, | ||
): ReturnType<FC>; | ||
<As extends ElementType>(props: OverridableComponentProps<ComponentProps, As>): ReturnType<FC>; | ||
} & Pick<FC, 'displayName'>; |
6 changes: 6 additions & 0 deletions
6
frontend/libs/studio-components/src/types/OverridableComponentProps.ts
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,6 @@ | ||
import type { ComponentPropsWithRef, ElementType } from 'react'; | ||
|
||
export type OverridableComponentProps<ComponentProps, As extends ElementType> = { | ||
as?: As; | ||
} & ComponentPropsWithRef<As> & | ||
Omit<ComponentProps, keyof ComponentPropsWithRef<As>>; |
3 changes: 3 additions & 0 deletions
3
frontend/libs/studio-components/src/types/OverridableComponentRef.ts
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,3 @@ | ||
import type { ComponentPropsWithRef, ElementType } from 'react'; | ||
|
||
export type OverridableComponentRef<As extends ElementType> = ComponentPropsWithRef<As>['ref']; |
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
Oops, something went wrong.