Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Table Component #404

IHIutch started this conversation in Ideas
Mar 7, 2021 · 1 comments · 2 replies
Discussion options

Describe the solution you'd like
A table component, that supports the following props:

Table,
 Thead,
 Tbody,
 Tfoot,
 Tr,
 Th,
 Td,
 TableCaption

Describe alternatives you've considered
Normal HTML tags and v-chakra 😅

You must be logged in to vote

Replies: 1 comment 2 replies

Comment options

Thanks @IHIutch 😀❤️

This API is coming to the v1 version of the library as well. (https://chakra-ui.com/docs/data-display/table)

I could use something like this in v0 as well. Up until now, this is another component I wasn't sure about including to the core API for v0. But I'm open to us having a discussion around the API.

What would a good Table API look like?

There's two directions we could go with this:
1) The compound approach.
Pros:

  • Conforms to v1 API
  • Flexibility with layout
  • Flexibility with styling of table elements

Cons:

  • Markup dense.
  • Consumers have to handle the table data props themselves

Sample code

<c-table>
 <c-table-caption>Teddy bear collectors:</c-table-caption>
 <c-tr>
 <c-th scope="col">Last Name</c-th>
 <c-th scope="col">First Name</c-th>
 <c-th scope="col">City</c-th>
 </c-tr>
 <c-tr>
 <c-td>Phoenix</c-td>
 <c-td>Imari</c-td>
 <c-td>Henry</c-td>
 </c-tr>
 <c-tr>
 <c-td>Zeki</c-td>
 <c-td>Rome</c-td>
 <c-td>Min</c-td>
 </c-tr>
 <c-tr>
 <c-td>Apirka</td>
 <c-td>Kelly</c-td>
 <c-td>Brynn</c-td>
 </c-tr>
</c-table>

This would yield:
image

2. Simple approach
The second approach would be to create a single c-table component that can accept an array of objects for the table content. It could also provide a scoped slot for all the table data so it's children can manipulate the layout of the table's content.

Something similar to Buefy's table component here:
https://codepen.io/codebender828/pen/ExNMgpb?editors=101

Pros:

  • No declarative flexibility with styling of the table elements
  • Need to use a scoped slot to modify table styles

Cons:

  • Plug and play approach to creating a table. (Just bring the data)

Example code

<!-- Plug and play -->
<c-table :data="tableData" caption="My fancy table" />
<!-- With scoped slots to modify styles -->
<c-table #default="{ rows, columns }" v-chakra="{ 'th': { bg: 'gray.500' } }">
 <c-box v-for="(col, i) in columns" :key="i" as="th" bg="gray.50">
 {{ col }}
 </c-box>
</c-table>

I for one would prefer approach 1 since you get some flexibility with layouts and conforms with Chakra's design principles.

This will be implemented in pattern 1 for v1

Also since we're still kinda fleshing this out, it makes sense for us to make this issue a discussion instead 👍🏽

You must be logged in to vote
2 replies
Comment options

I was initially thinking about the 1st approach you laid out. I think that's what my expectation would be (since that also matches the React lib). I think that would easily allow you to add additional functionality or a table library that allows you to sort, filter, etc.

That being said, there is something very compelling about approach 2.

I agree with the priority here, and since 2 would rely on roughly the same markup, could probably be added later.

Comment options

Both approach would be nice! Sometimes we don't need too much customization and the simple approach worth enough

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
Converted from issue

This discussion was converted from issue #397 on March 14, 2021 12:15.

AltStyle によって変換されたページ (->オリジナル) /