Allow flex component to take child containers props

So that we can set attributes on the container
midhun/memberlist-redesign-accessibility
R Midhun Suresh 2025-01-06 23:47:20 +05:30
parent 2bf96cc7b0
commit a629d79fef
No known key found for this signature in database
1 changed files with 7 additions and 7 deletions

View File

@ -7,14 +7,14 @@ Please see LICENSE files in the repository root for full details.
*/ */
import classNames from "classnames"; import classNames from "classnames";
import React, { useEffect, useRef } from "react"; import React, { ComponentProps, JSXElementConstructor, useEffect, useRef } from "react";
type FlexProps = { type FlexProps<T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>> = {
/** /**
* The type of the HTML element * The type of the HTML element
* @default div * @default div
*/ */
as?: string; as?: T;
/** /**
* The CSS class name. * The CSS class name.
*/ */
@ -30,7 +30,7 @@ type FlexProps = {
*/ */
direction?: "row" | "column" | "row-reverse" | "column-reverse"; direction?: "row" | "column" | "row-reverse" | "column-reverse";
/** /**
* The alingment of the flex children * The alignment of the flex children
* @default start * @default start
*/ */
align?: "start" | "center" | "end" | "baseline" | "stretch"; align?: "start" | "center" | "end" | "baseline" | "stretch";
@ -48,12 +48,12 @@ type FlexProps = {
* the on click event callback * the on click event callback
*/ */
onClick?: (e: React.MouseEvent) => void; onClick?: (e: React.MouseEvent) => void;
}; } & ComponentProps<T>;
/** /**
* A flexbox container helper * A flexbox container helper
*/ */
export function Flex({ export function Flex<T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any> = "div">({
as = "div", as = "div",
display = "flex", display = "flex",
direction = "row", direction = "row",
@ -63,7 +63,7 @@ export function Flex({
className, className,
children, children,
...props ...props
}: React.PropsWithChildren<FlexProps>): JSX.Element { }: React.PropsWithChildren<FlexProps<T>>): JSX.Element {
const ref = useRef<HTMLElement>(); const ref = useRef<HTMLElement>();
useEffect(() => { useEffect(() => {