Skip to content

feat(tabs): add fill, justified and active class props (closes #3053, #2518) #3061

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
81dd8bf
feat(tabs): add `fill`, `justified` and `active-class` props
jacobmllr95 Apr 9, 2019
1c5be33
Merge branch 'dev' into feat-tabs-fill-justified-active-class-props
tmorehouse Apr 9, 2019
b7d02ef
Update README.md
jacobmllr95 Apr 9, 2019
5b04bd7
Merge branch 'feat-tabs-fill-justified-active-class-props' of https:/…
jacobmllr95 Apr 9, 2019
50f1ca0
Merge branch 'dev' into feat-tabs-fill-justified-active-class-props
jacobmllr95 Apr 9, 2019
edc24b5
use `<b-nav>` in `<b-tabs>`
jacobmllr95 Apr 9, 2019
df4de5a
improve `<b-nav>` prop sharing
jacobmllr95 Apr 9, 2019
7dd9813
fix `align` prop handling
jacobmllr95 Apr 9, 2019
8f4a2b1
Update README.md
jacobmllr95 Apr 9, 2019
be70f6d
Update README.md
jacobmllr95 Apr 9, 2019
d04f599
improve nav class handling
jacobmllr95 Apr 9, 2019
791aeca
Merge branch 'dev' into feat-tabs-fill-justified-active-class-props
jacobmllr95 Apr 11, 2019
9821e6e
add test for new features
jacobmllr95 Apr 11, 2019
e7576d2
Merge branch 'dev' into feat-tabs-fill-justified-active-class-props
jacobmllr95 Apr 11, 2019
7fd2c18
Merge branch 'dev' into feat-tabs-fill-justified-active-class-props
tmorehouse Apr 12, 2019
6043f12
Merge branch 'dev' into feat-tabs-fill-justified-active-class-props
jacobmllr95 Apr 13, 2019
c4242f7
Merge branch 'dev' into feat-tabs-fill-justified-active-class-props
jacobmllr95 Apr 14, 2019
a27f96b
Merge branch 'dev' into feat-tabs-fill-justified-active-class-props
jacobmllr95 Apr 15, 2019
c5f340e
Use `pluckProps()` util
jacobmllr95 Apr 15, 2019
7f130b4
Merge branch 'dev' into feat-tabs-fill-justified-active-class-props
jacobmllr95 Apr 15, 2019
d85ebc8
Update tabs.js
tmorehouse Apr 15, 2019
10029c2
Update nav.js
tmorehouse Apr 15, 2019
8ebd67a
Update navbar-nav.js
tmorehouse Apr 15, 2019
3ba6976
Merge branch 'dev' into feat-tabs-fill-justified-active-class-props
jacobmllr95 Apr 15, 2019
5f531d2
Merge branch 'dev' into feat-tabs-fill-justified-active-class-props
jacobmllr95 Apr 15, 2019
643ac04
Separate `activeNavItemClass` and `activeTabClass`
jacobmllr95 Apr 15, 2019
661d371
Update yarn.lock
jacobmllr95 Apr 15, 2019
892bb88
Update tabs.spec.js
tmorehouse Apr 16, 2019
9c2c9ca
Update tabs.spec.js
tmorehouse Apr 16, 2019
e774612
Update tabs.spec.js
tmorehouse Apr 16, 2019
694a2a0
Merge branch 'dev' into feat-tabs-fill-justified-active-class-props
jacobmllr95 Apr 16, 2019
8a16106
Merge branch 'dev' into feat-tabs-fill-justified-active-class-props
jacobmllr95 Apr 16, 2019
eba23e6
Add docs for catice classes
jacobmllr95 Apr 16, 2019
3dd10b2
Add `enhanced` flags
jacobmllr95 Apr 16, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 42 additions & 7 deletions src/components/nav/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ variants are mutually exclusive - use only one style or the other.

### Tab style

Make the nav look like tabs by setting the prop `tabs`.
Make the nav look like tabs by setting the `tabs` prop.

```html
<div>
Expand All @@ -47,7 +47,7 @@ Make the nav look like tabs by setting the prop `tabs`.

### Pill style

Use the pill style by setting the prop `pills`.
Use the pill style by setting the `pills` prop.

```html
<div>
Expand All @@ -62,9 +62,26 @@ Use the pill style by setting the prop `pills`.
<!-- b-nav-pills.vue -->
```

### Small

Make the nav smaller by setting the `small` prop.

```html
<div>
<b-nav small>
<b-nav-item active>Active</b-nav-item>
<b-nav-item>Link</b-nav-item>
<b-nav-item>Another Link</b-nav-item>
<b-nav-item disabled>Disabled</b-nav-item>
</b-nav>
</div>

<!-- b-nav-small.vue -->
```

## Fill and justify

Force your `b-nav` content to extend the full available width.
Force your `<b-nav>` content to extend the full available width.

### Fill

Expand All @@ -73,7 +90,7 @@ prop. Notice that all horizontal space is occupied, but not every nav item has t

```html
<div>
<b-nav fill tabs>
<b-nav tabs fill>
<b-nav-item active>Active</b-nav-item>
<b-nav-item>Link</b-nav-item>
<b-nav-item>Link with a long name </b-nav-item>
Expand All @@ -86,12 +103,12 @@ prop. Notice that all horizontal space is occupied, but not every nav item has t

### Justified

For equal-width elements, set prop `justified` instead. All horizontal space will be occupied by nav
links, but unlike `fill` above, every `<b-nav-item>` will be the same width.
For equal-width elements, set the `justified` prop instead. All horizontal space will be occupied by
nav links, but unlike `fill` above, every `<b-nav-item>` will be the same width.

```html
<div>
<b-nav justified tabs>
<b-nav tabs justified>
<b-nav-item active>Active</b-nav-item>
<b-nav-item>Link</b-nav-item>
<b-nav-item>Link with a long name </b-nav-item>
Expand All @@ -102,6 +119,24 @@ links, but unlike `fill` above, every `<b-nav-item>` will be the same width.
<!-- b-nav-justified.vue -->
```

## Alignment

To align your `<b-nav-item>` components, use the `align` prop. Available values are `left`, `center`
and `right`.

```html
<div>
<b-nav tabs align="center">
<b-nav-item active>Active</b-nav-item>
<b-nav-item>Link</b-nav-item>
<b-nav-item>Link with a long name </b-nav-item>
<b-nav-item disabled>Disabled</b-nav-item>
</b-nav>
</div>

<!-- b-nav-alignment.vue -->
```

## Vertical variation

By default `<b-nav>` appear on a horizontal line. Stack your navigation by setting the `vertical`
Expand Down
11 changes: 3 additions & 8 deletions src/components/nav/nav-form.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import Vue from 'vue'
import BForm, { props as BFormProps } from '../form/form'
import { mergeData } from 'vue-functional-data-merge'
import copyProps from '../../utils/copy-props'

const formProps = copyProps(BFormProps)
delete formProps.inline
import BForm, { props as BFormProps } from '../form/form'
import { omit } from '../../utils/object'

export const props = {
...formProps
}
export const props = omit(BFormProps, ['inline'])

// @vue/component
export default Vue.extend({
Expand Down
37 changes: 29 additions & 8 deletions src/components/nav/nav.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import Vue from 'vue'
import { mergeData } from 'vue-functional-data-merge'
import warn from '../../utils/warn'

// -- Constants --

const DEPRECATED_MSG =
'Setting prop "is-nav-bar" is deprecated. Use the <b-navbar-nav> component instead.'

export const props = {
tag: {
Expand All @@ -15,6 +19,10 @@ export const props = {
type: Boolean,
default: false
},
align: {
type: String,
default: null
},
tabs: {
type: Boolean,
default: false
Expand All @@ -27,22 +35,33 @@ export const props = {
type: Boolean,
default: false
},
isNavBar: {
small: {
type: Boolean,
default: false
},
isNavBar: {
type: Boolean,
default: false,
// `deprecated` -> Don't use this prop
// `deprecation` -> Refers to a change in prop usage
deprecated: DEPRECATED_MSG
}
}

// -- Utils --

const computeJustifyContent = value => {
// Normalize value
value = value === 'left' ? 'start' : value === 'right' ? 'end' : value
return `justify-content-${value}`
}

// @vue/component
export default Vue.extend({
name: 'BNav',
functional: true,
props,
render(h, { props, data, children }) {
if (props.isNavBar) {
/* istanbul ignore next */
warn("b-nav: Prop 'is-nav-bar' is deprecated. Please use component '<b-navbar-nav>' instead.")
}
return h(
props.tag,
mergeData(data, {
Expand All @@ -52,8 +71,10 @@ export default Vue.extend({
'nav-tabs': props.tabs && !props.isNavBar,
'nav-pills': props.pills && !props.isNavBar,
'flex-column': props.vertical && !props.isNavBar,
'nav-fill': props.fill,
'nav-justified': props.justified
'nav-fill': !props.vertical && props.fill,
'nav-justified': !props.vertical && props.justified,
[computeJustifyContent(props.align)]: !props.vertical && props.align,
small: props.small
}
}),
children
Expand Down
130 changes: 129 additions & 1 deletion src/components/nav/nav.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ describe('nav', () => {
expect(wrapper.text()).toBe('foobar')
})

it('supports "is-navbar-nav" mode', async () => {
const wrapper = mount(BNav, {
propsData: {
isNavBar: true
}
})

expect(wrapper.is('ul')).toBe(true)
expect(wrapper.classes()).toContain('navbar-nav')
expect(wrapper.classes().length).toBe(1)
expect(wrapper.text()).toBe('')
})

it('applies pill style', async () => {
const wrapper = mount(BNav, {
propsData: {
Expand All @@ -51,6 +64,20 @@ describe('nav', () => {
expect(wrapper.text()).toBe('')
})

it("doesn't apply pill style when in 'is-navbar-nav' mode", async () => {
const wrapper = mount(BNav, {
propsData: {
pills: true,
isNavBar: true
}
})

expect(wrapper.is('ul')).toBe(true)
expect(wrapper.classes()).toContain('navbar-nav')
expect(wrapper.classes().length).toBe(1)
expect(wrapper.text()).toBe('')
})

it('applies tab style', async () => {
const wrapper = mount(BNav, {
propsData: {
Expand All @@ -65,7 +92,21 @@ describe('nav', () => {
expect(wrapper.text()).toBe('')
})

it('applies flex-column style when vertical', async () => {
it("doesn't apply tab style when in 'is-navbar-nav' mode", async () => {
const wrapper = mount(BNav, {
propsData: {
tabs: true,
isNavBar: true
}
})

expect(wrapper.is('ul')).toBe(true)
expect(wrapper.classes()).toContain('navbar-nav')
expect(wrapper.classes().length).toBe(1)
expect(wrapper.text()).toBe('')
})

it('applies vertical style', async () => {
const wrapper = mount(BNav, {
propsData: {
vertical: true
Expand All @@ -79,6 +120,20 @@ describe('nav', () => {
expect(wrapper.text()).toBe('')
})

it("doesn't apply vertical style when in 'is-navbar-nav' mode", async () => {
const wrapper = mount(BNav, {
propsData: {
vertical: true,
isNavBar: true
}
})

expect(wrapper.is('ul')).toBe(true)
expect(wrapper.classes()).toContain('navbar-nav')
expect(wrapper.classes().length).toBe(1)
expect(wrapper.text()).toBe('')
})

it('applies justify style when justified', async () => {
const wrapper = mount(BNav, {
propsData: {
Expand All @@ -93,6 +148,21 @@ describe('nav', () => {
expect(wrapper.text()).toBe('')
})

it("doesn't apply justify style when vertical", async () => {
const wrapper = mount(BNav, {
propsData: {
justified: true,
vertical: true
}
})

expect(wrapper.is('ul')).toBe(true)
expect(wrapper.classes()).toContain('nav')
expect(wrapper.classes()).toContain('flex-column')
expect(wrapper.classes().length).toBe(2)
expect(wrapper.text()).toBe('')
})

it('applies fill style style when fill set', async () => {
const wrapper = mount(BNav, {
propsData: {
Expand All @@ -106,4 +176,62 @@ describe('nav', () => {
expect(wrapper.classes().length).toBe(2)
expect(wrapper.text()).toBe('')
})

it("doesn't apply fill style when vertical", async () => {
const wrapper = mount(BNav, {
propsData: {
fill: true,
vertical: true
}
})

expect(wrapper.is('ul')).toBe(true)
expect(wrapper.classes()).toContain('nav')
expect(wrapper.classes()).toContain('flex-column')
expect(wrapper.classes().length).toBe(2)
expect(wrapper.text()).toBe('')
})

it('applies alignment correctly', async () => {
const wrapper = mount(BNav, {
propsData: {
align: 'center'
}
})

expect(wrapper.is('ul')).toBe(true)
expect(wrapper.classes()).toContain('nav')
expect(wrapper.classes()).toContain('justify-content-center')
expect(wrapper.classes().length).toBe(2)
expect(wrapper.text()).toBe('')
})

it("doesn't apply alignment when vertical", async () => {
const wrapper = mount(BNav, {
propsData: {
align: 'center',
vertical: true
}
})

expect(wrapper.is('ul')).toBe(true)
expect(wrapper.classes()).toContain('nav')
expect(wrapper.classes()).toContain('flex-column')
expect(wrapper.classes().length).toBe(2)
expect(wrapper.text()).toBe('')
})

it('applies small style', async () => {
const wrapper = mount(BNav, {
propsData: {
small: true
}
})

expect(wrapper.is('ul')).toBe(true)
expect(wrapper.classes()).toContain('nav')
expect(wrapper.classes()).toContain('small')
expect(wrapper.classes().length).toBe(2)
expect(wrapper.text()).toBe('')
})
})
1 change: 1 addition & 0 deletions src/components/nav/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"meta": {
"title": "Nav",
"enhanced": true,
"description": "Navigation components that share general markup and styles, from the base <b-nav> class to the active and disabled states. Swap modifier props to switch between each style.",
"plugins": [
"Dropdown"
Expand Down
Loading