Skip to content

feat(button): add new squared prop for making buttons with square corners #3387

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
merged 9 commits into from
May 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
57 changes: 43 additions & 14 deletions src/components/button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,14 @@ Fancy larger or smaller buttons? Specify `lg` or `sm` via the `size` prop.
<!-- b-button-sizes.vue -->
```

### Block level buttons

Create block level buttons — those that span the full width of a parent — by setting the `block`
prop.

```html
<div>
<b-button block variant="primary">Block Level Button</b-button>
</div>

<!-- b-button-block.vue -->
```

## Contextual variants

Use the `variant` prop to generate the various Bootstrap contextual button variants.

By default `<b-button>` will render with the `secondary` variant.

The `variant` prop adds the Bootstrap V4.3 class `.btn-<variant>` on the rendered button.

### Solid color variants

`primary`, `secondary`, `success`, `danger`, `warning`, `info`, `light` and `dark`.
Expand Down Expand Up @@ -124,6 +113,22 @@ padding and size of a button.
<!-- b-button-link.vue -->
```

**Tip:** remove the hover underline from a link variant button by adding the Bootstrap V4.3 utility
class `text-decoration-none` to `<b-button>`.

## Block level buttons

Create block level buttons — those that span the full width of a parent — by setting the `block`
prop.

```html
<div>
<b-button block variant="primary">Block Level Button</b-button>
</div>

<!-- b-button-block.vue -->
```

## Pill style

<span class="badge badge-info small">NEW in 2.0.0-rc.20</span>
Expand All @@ -143,10 +148,34 @@ Prefer buttons with a more rounded-pill style? Just set the prop `pill` to true.
<!-- b-button-pill.vue -->
```

This prop adds the Bootstrap V4.3 utility class `.rounded-pill` on the rendered button.

## Squared style

<span class="badge badge-info small">NEW in 2.0.0-rc.22</span>

Prefer buttons with a more square corner style? Just set the prop `squared` to true.

```html
<div>
<b-button squared>Button</b-button>
<b-button squared variant="primary">Button</b-button>
<b-button squared variant="outline-secondary">Button</b-button>
<b-button squared variant="success">Button</b-button>
<b-button squared variant="outline-danger">Button</b-button>
<b-button squared variant="info">Button</b-button>
</div>

<!-- b-button-square.vue -->
```

The `squared` prop adds the Bootstrap V4.3 utility class `.rounded-0` on the rendered button. The
`pill` prop takes precedence over the `squared` prop.

## Disabled state

Set the `disabled` prop to disable button default functionality. `disabled` also works with buttons
rendered as `<a>` elements and `<router-link>`.
rendered as `<a>` elements and `<router-link>` (i.e. with the `href` or `to` prop set).

```html
<div>
Expand Down
5 changes: 5 additions & 0 deletions src/components/button/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const btnProps = {
type: Boolean,
default: false
},
squared: {
type: Boolean,
default: false
},
pressed: {
// tri-state prop: true, false or null
// => on, off, not a toggle
Expand Down Expand Up @@ -96,6 +100,7 @@ const computeClass = props => [
[`btn-${props.size}`]: Boolean(props.size),
'btn-block': props.block,
'rounded-pill': props.pill,
'rounded-0': props.squared && !props.pill,
disabled: props.disabled,
active: props.pressed
}
Expand Down
18 changes: 17 additions & 1 deletion src/components/button/button.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('button', () => {
expect(wrapper.classes().length).toBe(3)
})

it('applies pill class', async () => {
it('applies rounded-pill class when pill prop set', async () => {
const wrapper = mount(BButton, {
propsData: {
pill: true
Expand All @@ -106,6 +106,22 @@ describe('button', () => {
expect(wrapper.classes().length).toBe(3)
})

it('applies rounded-0 class when squared prop set', async () => {
const wrapper = mount(BButton, {
propsData: {
squared: true
}
})

expect(wrapper.is('button')).toBe(true)
expect(wrapper.attributes('type')).toBeDefined()
expect(wrapper.attributes('type')).toBe('button')
expect(wrapper.classes()).toContain('btn')
expect(wrapper.classes()).toContain('btn-secondary')
expect(wrapper.classes()).toContain('rounded-0')
expect(wrapper.classes().length).toBe(3)
})

it('renders custom root element', async () => {
const wrapper = mount(BButton, {
propsData: {
Expand Down