-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import React, { HTMLAttributes } from "react"; | ||
import cx from "classnames"; | ||
|
||
interface Options extends HTMLAttributes<HTMLElement> { | ||
className?: string; | ||
} | ||
interface Options extends HTMLAttributes<HTMLElement> {} | ||
|
||
export const applyTheme = <T extends Options>( | ||
Component: React.FC<T>, | ||
{ className }: Options | ||
options: T | ||
) => (props: T) => { | ||
return <Component {...props} className={cx([className, props.className])} />; | ||
return ( | ||
<Component | ||
{...props} | ||
className={cx([options.className, props.className])} | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
matt-hardman
Author
Contributor
|
||
/> | ||
); | ||
}; | ||
|
||
export default applyTheme; |
Hi @matt-hardman , we are hoping to enshrine certain practices in the construction of Components, and one of them is that parent Components should feel free to pass styles into children. That is the purpose of destructuring out
className
as a named input (it is part of the HTMLAttributes interface, so safe to do).The other question here is about the use of the
HTMLElement
generic passed to theHTMLAttributes
interface. Idealy people would pass the specific HTML element so that they could get the methods for that element - e.g. form inputs haveonChange
, etcOtherwise, I like the idea of passing in a generic to make this more typeable.