Page MenuHomePhabricator

[web] Introduce common `Tabs` component
ClosedPublic

Authored by jacek on Mar 8 2022, 4:16 AM.
Tags
None
Referenced Files
Unknown Object (File)
Nov 16 2024, 7:52 PM
Unknown Object (File)
Nov 16 2024, 7:34 PM
Unknown Object (File)
Nov 16 2024, 7:31 PM
Unknown Object (File)
Nov 5 2024, 9:41 PM
Unknown Object (File)
Oct 22 2024, 8:45 PM
Unknown Object (File)
Oct 21 2024, 11:10 AM
Unknown Object (File)
Oct 20 2024, 8:30 PM
Unknown Object (File)
Oct 20 2024, 8:29 PM

Details

Summary

Introduce Tab component for displaying interface in tabs. It is not used yet. It will be used in Thread Members Modal.
In the next diff, I'll replace "Thread List tabs" with this component.
The component receives tabs, information about active tab and tab setter from parent - it doesn't keep the state with current active tab itself.

Test Plan

Testing the component will be possible when it will be used in Thread Members Modal in one of next diffs.

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

In the future, we can consider replacing existing "Thread List tabs" with this component.

I think the best way to start something like this is to factor out the existing logic ("Thread List tabs"), instead of duplicating it. Of course sometimes this can be hard if there are significant differences.

Can you explain your reasoning for duplicating the code instead of factoring it out?

benschac added inline comments.
web/components/tabs.css
12 ↗(On Diff #10138)

I know we've used this short hand a bit: https://stackoverflow.com/questions/37386244/what-does-flex-1-mean

I always find myself forgetting what flex: 1 is. Does anyone else have this issue, or is it just me: @atul @palys-swm

web/components/tabs.react.js
10 ↗(On Diff #10138)
declare type React$Node =
  | null
  | boolean
  | number
  | string
  | React$Element<any>
  | React$Portal
  | Iterable<?React$Node>;

React node can be a string. We don't need add it here too.

28 ↗(On Diff #10138)

could css.backgroundTabHeader be added to css.tabHeader? then we only need to toggle one class for active and inactive.

This revision now requires changes to proceed.Mar 8 2022, 11:30 AM
web/components/tabs.css
12 ↗(On Diff #10138)

I like to use this shorthand as it is really useful in most of the cases: when you want to split available space according to some proportion. The only confusion might be about flex-basis, but in this use-case having flex-basis: 0 is reasonable. So the exact meaning of flex: 1 isn't usually that important because its behavior is intuitive.

Introduced Tabs.Container and Tabs.Item following Tomek solution in D3341. Updated CSS following review comments

jacek edited the summary of this revision. (Show Details)
In D3369#90935, @ashoat wrote:

In the future, we can consider replacing existing "Thread List tabs" with this component.

I think the best way to start something like this is to factor out the existing logic ("Thread List tabs"), instead of duplicating it. Of course sometimes this can be hard if there are significant differences.

Can you explain your reasoning for duplicating the code instead of factoring it out?

I created the following diff (D3373), that replaces "Thread List Tabs" with this component.

benschac added inline comments.
web/components/tabs.react.js
34 ↗(On Diff #10300)

nit: could currentTab?.props.children ?? null be an option?

This revision is now accepted and ready to land.Mar 11 2022, 7:41 AM

Use generic types to support passing passing functions with string literal union.

I created the following diff (D3373), that replaces "Thread List Tabs" with this component.

Okay, in this case let's leave it as-is. But in the future, instead of having two diffs 1. copy-paste into new place, 2. replace in old place... it is alway better to structure as 1. factor out of old place, 2. use in new place.

tomek requested changes to this revision.Mar 14 2022, 7:25 AM
tomek added inline comments.
web/components/tabs.css
28

If only the color changes, we can use more specific property

web/components/tabs.react.js
24–26

I don't think this is a good idea to use lambda here. Instead we should use a callback, which might be more complicated in a loop. So to fix the issue, we can e.g. create a new component Header which takes id and setTab as props and sets onClick to be a callback depending on these.

This revision now requires changes to proceed.Mar 14 2022, 7:25 AM

excluded part of TabsContainer component into TabsHeader

This revision is now accepted and ready to land.Mar 15 2022, 7:49 AM
This revision was automatically updated to reflect the committed changes.