Skip to content

Commit

Permalink
fix(ui): typing improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Nov 8, 2024
1 parent bef541d commit 7ec16b1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Spinner } from "../Spinner/index"
import { flip, offset, shift, size } from "@floating-ui/react-dom"
import { usePortalRef } from "../PortalProvider/index"
import { createPortal } from "react-dom"
import { ComboBoxOptionProps } from "../ComboBoxOption/index"
import { ComboBoxOptionProps } from "../ComboBoxOption/ComboBoxOption.component"

// STYLES

Expand Down Expand Up @@ -455,7 +455,7 @@ export type ComboBoxWidth = "full" | "auto"
//eslint-disable-next-line no-unused-vars
type OnChangeHandler = (value: string) => void

export type ComboBoxProps = {
export interface ComboBoxProps {
/** The aria-label of the ComboBox. Defaults to the label if label was passed. */
ariaLabel?: string
/** The children to Render. Use `ComboBox.Option` elements. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,18 @@ export default {
],
}

const Template = ({ children, ...args }: TemplateProps) => {
const Template = ({ children, ...args }: ComboBoxProps) => {
return <ComboBox {...args}>{children}</ComboBox>
}

// define prop types fro Template
type TemplateProps = {
children: React.ReactNode
} & ComboBoxProps

const ConstrainedWidthTemplate = ({ children, ...args }: ConstrainedWidthTemplateProps) => {
const ConstrainedWidthTemplate = ({ children, ...args }: ComboBoxProps) => {
return (
<div style={{ width: "300px" }}>
<ComboBox {...args}>{children}</ComboBox>
</div>
)
}

// define prop types for ConstrainedWidthTemplate
type ConstrainedWidthTemplateProps = {
children: React.ReactNode
} & ComboBoxProps

const ControlledTemplate = ({ value, children }: ControlledTemplateProps) => {
const [v, setV] = useState(value)

Expand All @@ -70,10 +60,9 @@ const ControlledTemplate = ({ value, children }: ControlledTemplateProps) => {
}

// define prop types for ControlledTemplate
type ControlledTemplateProps = {
interface ControlledTemplateProps extends ComboBoxProps {
value: string
children: React.ReactNode
} & ComboBoxProps
}

export const Default = {
render: Template,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ export const ComboBoxOption = ({
)
}

export type ComboBoxOptionProps = {
export interface ComboBoxOptionProps extends React.HTMLProps<HTMLLIElement> {
children?: string
disabled?: boolean
value?: string
label?: string
className?: string
} & React.HTMLProps<HTMLLIElement>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
* SPDX-License-Identifier: Apache-2.0
*/

export { ComboBoxOption, type ComboBoxOptionProps } from "./ComboBoxOption.component"
export { ComboBoxOption } from "./ComboBoxOption.component"

0 comments on commit 7ec16b1

Please sign in to comment.