Skip to content

Commit

Permalink
refactor: Add Override type (#14248)
Browse files Browse the repository at this point in the history
Co-authored-by: andreastanderen <71079896+standeren@users.noreply.github.com>
  • Loading branch information
TomasEng and standeren authored Dec 9, 2024
1 parent 02612f1 commit 61f7546
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ import type { OverridableComponent } from '../../types/OverridableComponent';
import type { IconPlacement } from '../../types/IconPlacement';
import type { OverridableComponentRef } from '../../types/OverridableComponentRef';
import type { OverridableComponentProps } from '../../types/OverridableComponentProps';
import type { Override } from '../../types/Override';

export type StudioButtonProps = Omit<ButtonProps, 'icon' | 'color' | 'asChild'> & {
icon?: ReactNode;
iconPlacement?: IconPlacement;
color?: ButtonProps['color'] | 'inverted';
};
export type StudioButtonProps = Override<
{
icon?: ReactNode;
iconPlacement?: IconPlacement;
color?: ButtonProps['color'] | 'inverted';
},
Omit<ButtonProps, 'asChild'>
>;

const StudioButton: OverridableComponent<StudioButtonProps, HTMLButtonElement> = forwardRef(
<As extends ElementType = 'button'>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import React, {
} from 'react';
import { convertNumberToString, convertStringToNumber, isStringValidDecimalNumber } from './utils';
import { type StudioTextfieldProps, StudioTextfield } from '../StudioTextfield';
import type { Override } from '../../types/Override';

export interface StudioDecimalInputProps extends Omit<StudioTextfieldProps, 'onChange'> {
description?: string;
onChange: (value: number) => void;
value?: number;
validationErrorMessage: string;
}
export type StudioDecimalInputProps = Override<
{
description?: string;
onChange: (value: number) => void;
value?: number;
validationErrorMessage: string;
},
StudioTextfieldProps
>;

export const StudioDecimalInput = forwardRef(
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ import React, { forwardRef, useCallback } from 'react';
import type { TextResource } from '../../types/TextResource';
import type { StudioComboboxProps } from '../StudioCombobox';
import { StudioCombobox } from '../StudioCombobox';

export type StudioTextResourcePickerProps = Omit<StudioComboboxProps, keyof OverriddenProps> &
OverriddenProps &
AdditionalProps;

type OverriddenProps = {
onValueChange: (id: string) => void;
value?: string;
};

type AdditionalProps = {
emptyListText: string;
textResources: TextResource[];
};
import type { Override } from '../../types/Override';

export type StudioTextResourcePickerProps = Override<
{
emptyListText: string;
onValueChange: (id: string) => void;
textResources: TextResource[];
value?: string;
},
StudioComboboxProps
>;

export const StudioTextResourcePicker = forwardRef<HTMLInputElement, StudioTextResourcePickerProps>(
({ textResources, onSelect, onValueChange, emptyListText, value, ...rest }, ref) => {
Expand Down
1 change: 1 addition & 0 deletions frontend/libs/studio-components/src/types/Override.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Override<Primary, Secondary> = Primary & Omit<Secondary, keyof Primary>;

0 comments on commit 61f7546

Please sign in to comment.