-
Notifications
You must be signed in to change notification settings - Fork 14
AR-1672, AR-1909 Add tr
and column-level th
/td
customization to Table
#247
Conversation
f6462c6
to
d412ee3
Compare
tr
customization to Table
tr
and column-level th
/td
customization to Table
tr
and column-level th
/td
customization to Table
tr
and column-level th
/td
customization to Table
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one little thought, not positive it's better but left the comment there for your perusal :D
I wonder if createElementFromAs
might be a nice util to have, but that seems like something that would be best suited for another PR anyways :)
function createElementFromAs(as: As): React.ReactElement { | ||
return React.isValidElement(as) | ||
? as | ||
: typeof as === "string" | ||
? React.createElement(as) | ||
: assertUnreachable(as); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NBD
Was trying to think of a way for this to also handle the object as
const bodyTrElement = React.isValidElement(trAs)
? trAs
: typeof trAs === "string"
? React.createElement(trAs)
: createElementFromAs(trAs.body || "tr");
Something like this
function createElementFromAs(as: As): React.ReactElement { | |
return React.isValidElement(as) | |
? as | |
: typeof as === "string" | |
? React.createElement(as) | |
: assertUnreachable(as); | |
} | |
function createElementFromAs<Key extends string>( | |
as: As | { [key in Key]?: As } | undefined, | |
defaultValue: As, | |
key?: Key | |
): React.ReactElement { | |
return React.isValidElement(as) | |
? as | |
: typeof as === "string" | |
? React.createElement(as) | |
: createElementFromAs((key && as?.[key]) ?? defaultValue, defaultValue); | |
} |
would let use change that to
const bodyTrElement = createElementFromAs(trAs, "tr", "body");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this suggestion! I'm happy the conversation was hot to better handle the object or value instead of should we even have an object or a value 😃 I'm not sure what the right abstraction here would be yet; and I would love to have one because I'd much rather inline the element generation. I'm going to leave this as it is for now and keep thinking about it 😃
Something else I didn't add, but we might want in the future, is another option in As
to make the element a function of the row props for the tr
, the field props for td
, and the column config (?) for the th
. Def a use case we can figure out when we need it!
🚀 PR was released in |
Add config for
tr
,td
, andth
inTable
. Review commit-by-commit with whitespace turned off. I replaced thecss=
prop with the jsx pragma inTable
with theClassNames
component to explicitly allow me to usecx
to merge class names.Resolves issues https://apollographql.atlassian.net/browse/AR-1672 and https://apollographql.atlassian.net/browse/AR-1909
Release Notes
Allow
tr
s in theTable
component to be customized. You can pass a singletrAs
prop that acceptskeyof JSX.IntrinsicElements
, like"tr"
, or aReact.ReactElement
that will be cloned withReact.cloneElement
.This configuration accepts a single value that can be applied to both the
thead > tr
element and totbody > tr
elements. You can also configure them separately withtrAs={{ head: ..., body: ... }}
, of which both keys are optional (you can exclude either of them and the default of "tr" will be used).Allow each
column
'std
andth
to be customizedSee the tests and storybook story docs for usage examples.
📦 Published PR as canary version:
7.18.1-canary.247.5724.0
✨ Test out this PR locally via:
npm install @apollo/space-kit@7.18.1-canary.247.5724.0 # or yarn add @apollo/space-kit@7.18.1-canary.247.5724.0