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

feat(SegmentedControl): allow for passing stricter type for options #7051

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Prev Previous commit
rename to match others
  • Loading branch information
bvandercar-vt committed Jan 8, 2025
commit ee2ac5e43c431eaf851cfe9b9cdee54d395811ae
4 changes: 2 additions & 2 deletions packages/core/src/components/icon/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ export interface DefaultIconProps extends IntentProps, Props, DefaultSVGIconProp
}

/**
* Generic icon component type. This is essentially a type hack required to make forwardRef work with generic
* components. Note that this slows down TypeScript compilation, but it better than the alternative of globally
* Generic component type. This is essentially a type hack required to make forwardRef work with generic
* components. Note that this slows down TypeScript compilation, but is better than the alternative of globally
* augmenting "@types/react".
*
* @see https://stackoverflow.com/a/73795494/7406866
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,23 @@ export interface SegmentedControlProps<T extends string = string>
small?: boolean;
}

// This makes the react FC a generic, allowing the ability to pass a more strict
// type for `options`/`onValueChange` i.e. <SegmentedControl<Intent> />
interface SegmentedControlReactFC extends React.FC<SegmentedControlProps> {
<T extends string>(props: SegmentedControlProps<T>): ReturnType<React.FC<SegmentedControlProps<T>>>;
/**
* Generic component type. This is essentially a type hack required to make forwardRef work with generic
* components. Note that this slows down TypeScript compilation, but is better than the alternative of globally
* augmenting "@types/react".
*
* @see https://stackoverflow.com/a/73795494/7406866
*/
export interface SegmentedControlComponent extends React.FC<SegmentedControlProps> {
<T extends string>(props: SegmentedControlProps<T>): React.ReactElement | null;
}

/**
* Segmented control component.
*
* @see https://blueprintjs.com/docs/#core/components/segmented-control
*/
export const SegmentedControl: SegmentedControlReactFC = React.forwardRef(
export const SegmentedControl: SegmentedControlComponent = React.forwardRef(
<T extends string>(props: SegmentedControlProps<T>, ref: React.ForwardedRef<HTMLDivElement>) => {
const {
className,
Expand Down
4 changes: 2 additions & 2 deletions packages/icons/src/svgIconContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export type SVGIconContainerProps<T extends Element> = Omit<SVGIconProps<T>, "ch
};

/**
* Generic icon container component type. This is essentially a type hack required to make forwardRef work with generic
* components. Note that this slows down TypeScript compilation, but it better than the alternative of globally
* Generic component type. This is essentially a type hack required to make forwardRef work with generic
* components. Note that this slows down TypeScript compilation, but is better than the alternative of globally
* augmenting "@types/react".
*
* @see https://stackoverflow.com/a/73795494/7406866
Expand Down