Skip to content

Commit 004963d

Browse files
authored
feat(button): add new squared prop for making buttons with square corners (bootstrap-vue#3387)
1 parent c4a8edb commit 004963d

File tree

3 files changed

+65
-15
lines changed

3 files changed

+65
-15
lines changed

src/components/button/README.md

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,14 @@ Fancy larger or smaller buttons? Specify `lg` or `sm` via the `size` prop.
5050
<!-- b-button-sizes.vue -->
5151
```
5252

53-
### Block level buttons
54-
55-
Create block level buttons — those that span the full width of a parent — by setting the `block`
56-
prop.
57-
58-
```html
59-
<div>
60-
<b-button block variant="primary">Block Level Button</b-button>
61-
</div>
62-
63-
<!-- b-button-block.vue -->
64-
```
65-
6653
## Contextual variants
6754

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

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

59+
The `variant` prop adds the Bootstrap V4.3 class `.btn-<variant>` on the rendered button.
60+
7261
### Solid color variants
7362

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

116+
**Tip:** remove the hover underline from a link variant button by adding the Bootstrap V4.3 utility
117+
class `text-decoration-none` to `<b-button>`.
118+
119+
## Block level buttons
120+
121+
Create block level buttons — those that span the full width of a parent — by setting the `block`
122+
prop.
123+
124+
```html
125+
<div>
126+
<b-button block variant="primary">Block Level Button</b-button>
127+
</div>
128+
129+
<!-- b-button-block.vue -->
130+
```
131+
127132
## Pill style
128133

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

151+
This prop adds the Bootstrap V4.3 utility class `.rounded-pill` on the rendered button.
152+
153+
## Squared style
154+
155+
<span class="badge badge-info small">NEW in 2.0.0-rc.22</span>
156+
157+
Prefer buttons with a more square corner style? Just set the prop `squared` to true.
158+
159+
```html
160+
<div>
161+
<b-button squared>Button</b-button>
162+
<b-button squared variant="primary">Button</b-button>
163+
<b-button squared variant="outline-secondary">Button</b-button>
164+
<b-button squared variant="success">Button</b-button>
165+
<b-button squared variant="outline-danger">Button</b-button>
166+
<b-button squared variant="info">Button</b-button>
167+
</div>
168+
169+
<!-- b-button-square.vue -->
170+
```
171+
172+
The `squared` prop adds the Bootstrap V4.3 utility class `.rounded-0` on the rendered button. The
173+
`pill` prop takes precedence over the `squared` prop.
174+
146175
## Disabled state
147176

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

151180
```html
152181
<div>

src/components/button/button.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ const btnProps = {
4141
type: Boolean,
4242
default: false
4343
},
44+
squared: {
45+
type: Boolean,
46+
default: false
47+
},
4448
pressed: {
4549
// tri-state prop: true, false or null
4650
// => on, off, not a toggle
@@ -96,6 +100,7 @@ const computeClass = props => [
96100
[`btn-${props.size}`]: Boolean(props.size),
97101
'btn-block': props.block,
98102
'rounded-pill': props.pill,
103+
'rounded-0': props.squared && !props.pill,
99104
disabled: props.disabled,
100105
active: props.pressed
101106
}

src/components/button/button.spec.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe('button', () => {
9090
expect(wrapper.classes().length).toBe(3)
9191
})
9292

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

109+
it('applies rounded-0 class when squared prop set', async () => {
110+
const wrapper = mount(BButton, {
111+
propsData: {
112+
squared: true
113+
}
114+
})
115+
116+
expect(wrapper.is('button')).toBe(true)
117+
expect(wrapper.attributes('type')).toBeDefined()
118+
expect(wrapper.attributes('type')).toBe('button')
119+
expect(wrapper.classes()).toContain('btn')
120+
expect(wrapper.classes()).toContain('btn-secondary')
121+
expect(wrapper.classes()).toContain('rounded-0')
122+
expect(wrapper.classes().length).toBe(3)
123+
})
124+
109125
it('renders custom root element', async () => {
110126
const wrapper = mount(BButton, {
111127
propsData: {

0 commit comments

Comments
 (0)