Skip to content

Make it easy to pass className props down #2

@djgrant

Description

@djgrant

Instead of writing:

export const MyComponent = (props: { className: string }) => {
  return (
    <div className={props.className}>
      <div className="pt-10 pb-14 px-8" />
    </div>
  );
};

I could write:

export const MyComponent = classy.div(() => {
  return <div className="pt-10 pb-14 px-8">;
});

Or:

const MyDiv = classy.div();

export const MyComponent = MyDiv.extend(() => {
    return <div className="pt-10 pb-14 px-8">;
});

This would introduce two API changes:

  1. If the argument type is a function, classy creates a wrapped component.
  2. Classy components can be extended by calling an extend method. If a classnames object is the argument, it is merged with the original classnames object. If a function is the argument, the original component is wrapped, as per 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions