| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | */ |
| 7 | |
| 8 | import * as stylex from '@stylexjs/stylex'; |
| 9 | |
| 10 | export type ReactProps<T extends HTMLElement> = React.DetailedHTMLProps<React.HTMLAttributes<T>, T>; |
| 11 | |
| 12 | /** |
| 13 | * Like stylex.props(), but also adds in extra classNames. |
| 14 | * Useful since `{...stylex.props()}` sets className, |
| 15 | * and either overwrites or is overwritten by other `className="..."` props. |
| 16 | */ |
| 17 | export function stylexPropsWithClassName( |
| 18 | style: stylex.StyleXStyles, |
| 19 | ...names: Array<string | undefined> |
| 20 | ) { |
| 21 | const {className, ...rest} = stylex.props(style); |
| 22 | return {...rest, className: className + ' ' + names.filter(name => name != null).join(' ')}; |
| 23 | } |
| 24 | |
| 25 | export function findParentWithClassName( |
| 26 | start: HTMLElement, |
| 27 | className: string, |
| 28 | ): HTMLElement | undefined { |
| 29 | let el = start as HTMLElement | null; |
| 30 | while (el) { |
| 31 | if (el.classList?.contains(className)) { |
| 32 | return el; |
| 33 | } else { |
| 34 | el = el.parentElement; |
| 35 | } |
| 36 | } |
| 37 | return undefined; |
| 38 | } |
| 39 | |