Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Tab): Add vertical tabbing #1894

Merged
merged 8 commits into from
Aug 18, 2017

Conversation

mclarentgp
Copy link
Contributor

In the current implementation it's impossible to set tabs to be in a vertical format.
This pr changes this.

@codecov-io
Copy link

codecov-io commented Jul 23, 2017

Codecov Report

Merging #1894 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1894      +/-   ##
==========================================
+ Coverage   99.75%   99.75%   +<.01%     
==========================================
  Files         145      145              
  Lines        2477     2484       +7     
==========================================
+ Hits         2471     2478       +7     
  Misses          6        6
Impacted Files Coverage Δ
src/collections/Grid/GridColumn.js 100% <100%> (ø) ⬆️
src/modules/Tab/Tab.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 02daf0f...fcc71d3. Read the comment docs.

Copy link
Member

@layershifter layershifter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mclarentgp Thanks for PR, I've left some comments, but I need time to pay more attention to this PR.

@@ -81,7 +81,7 @@ export interface MenuProps {
stackable?: boolean;

/** A menu can be formatted to show tabs of information. */
tabular?: boolean | 'right';
tabular?: boolean | 'right' | 'left';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify necessity of left value? There is no special CSS for it, so it's left by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, sorry you are correct this doesn't need to be changed. Will undo changes.

@@ -112,4 +113,11 @@ GridColumn.propTypes = {
width: PropTypes.oneOf(SUI.WIDTHS),
}

GridColumn.create = createShorthandFactory(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createShorthandFactory accepts only two agruments, in this case correct usage is:

createShorthandFactory(GridColumn,  children => ({ children }))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update this to the correct usage.

@mclarentgp
Copy link
Contributor Author

@DENSENDEW Sorry I don't quite understand? I'm still fairly new to some of this and it's my first PR.

@@ -96,19 +102,42 @@ class Tab extends Component {
})
}

renderColumn(columnProps) {
return GridColumn.create(columnProps)
}
Copy link
Member

@levithomason levithomason Jul 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a pass-through method, let's just call GridColumn.create instead of this.renderColumn and drop this method.

@@ -64,7 +69,8 @@ class Tab extends Component {
]

static defaultProps = {
menu: { attached: true, tabular: true },
menu: { attached: true, tabular: true, vertical: false, fluid: false },
grid: { segmentWidth: 12, tabWidth: 4 },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In keeping with the Tab terminology, let's go with paneWidth instead of segmentWidth.

{menu.props.tabular !== 'right' && this.renderColumn({ width: grid.tabWidth, children: menu })}
{this.renderColumn({
width: grid.segmentWidth,
children: _.invoke(_.get(panes, `[${activeIndex}]`), 'render', this.props),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line:

_.invoke(_.get(panes, `[${activeIndex}]`), 'render', this.props)

is duplicated in the main render() method. Let's pull this line into a method like renderActivePane() to contain it.

{this.renderColumn({
width: grid.segmentWidth,
children: _.invoke(_.get(panes, `[${activeIndex}]`), 'render', this.props),
stretched: true }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing curly on the same line as the closing paren and wrapping curly please.

-  stretched: true }
-})
+  stretched: true,
+})}

@@ -64,7 +69,8 @@ class Tab extends Component {
]

static defaultProps = {
menu: { attached: true, tabular: true },
menu: { attached: true, tabular: true, vertical: false, fluid: false },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add vertical: false, fluid: false as these are not set by default.

@@ -37,6 +39,9 @@ class Tab extends Component {
/** Shorthand props for the Menu. */
menu: PropTypes.object,

/** Shorthand props for the Grid. */
grid: PropTypes.object,
Copy link
Member

@levithomason levithomason Jul 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shorthand can be a string, number, props object, or an element. It is then passed to a shorthand factory, such as Grid.create(grid).

In this case, the user cannot pass normal Grid props such as celled or padded because this object is not used in a shorthand factory for the Grid. This is some kind of configuration rather than shorthand.

I'd like to reserve the grid prop for actual Grid props so users can control that if needed. That said, I'm not so sure of the best API for these values. Here are some ideas, would love feedback:

Top level props

Make paneWidth and tabWidth top level props rather than nested in grid. This makes room for grid to be true shorthand, however, those props are only applicable if menu.vertical is set so it might be a bit odd as well.

Omit and use rest for shorthand

The current grid object needs to be spread on the Grid in order to be true Grid props. We could leave it as is and just omit paneWidth and tabWidth from the grid value before spreading it:

const { paneWidth, tabWidth, ...gridProps } = grid

<Grid {...gridProps>
  {GridColumn.create({ width: tabWidth })}
  {GridColumn.create({ width: paneWidth })}
</Grid>

I think I'm leaning toward the omit/rest approach, what are your ideas?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I like the idea of omit/rest as it appears to give the best solution to maintaining the true grid props and the pane/tab width props

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@levithomason I went ahead and made the omit/rest change. Let me know if you decide you want to use a different approach.

{menu.props.attached !== 'bottom' && menu}
{_.invoke(_.get(panes, `[${activeIndex}]`), 'render', this.props)}
{menu.props.attached === 'bottom' && menu}
{menu.props.vertical === true && grid}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The vertical menu prop makes the case for two clean return values here. We can also avoid creating a null grid in the case of non-vertical menus:

if (menu.props.vertical) {
  return <ElementType {...rest}>{this.renderVertical(menu)}<ElementType>
}

// ...the old return value as-is

@levithomason
Copy link
Member

I've pushed a minor update and will merge on pass.

@levithomason levithomason merged commit 86bd8b5 into Semantic-Org:master Aug 18, 2017
@levithomason
Copy link
Member

Whoops, sorry for the delay!

@levithomason
Copy link
Member

Released in semantic-ui-react@0.71.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants