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

Add Bootstrap v5 support for ButtonGroup #1540

Merged
merged 1 commit into from
Jun 7, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
68 changes: 51 additions & 17 deletions addon/components/bs-button-group/button.hbs
Original file line number Diff line number Diff line change
@@ -1,17 +1,51 @@
<button
disabled={{this.__disabled}}
type={{this.buttonType}}
class="btn {{if this.active "active"}} {{if this.block "btn-block"}} {{bs-size-class "btn" @size}} {{bs-type-class "btn" @type default=(if (macroCondition (macroGetOwnConfig "isBS3")) "default" "secondary") outline=@outline}}"
...attributes
{{on "click" this.handleClick}}
{{did-update this.resetState @reset}}
>
{{#if this.icon}}<i class={{this.icon}}></i> {{/if}}{{this.text}}{{yield
(hash
isFulfilled=this.isFulfilled
isPending=this.isPending
isRejected=this.isRejected
isSettled=this.isSettled
)
}}
</button>
{{#if this.isBS5ToggleButton}}
<input
type={{@buttonGroupType}}
class="btn-check"
id={{this.formId}}
autocomplete="off"
checked={{this.active}}
...attributes
{{on "click" this.handleClick}}
{{did-update this.resetState @reset}}
>
<label
class="btn {{bs-size-class "btn" @size}} {{bs-type-class "btn" @type default="secondary" outline=@outline}}"
for={{this.formId}}
>
{{#if this.icon}}
<i class={{this.icon}}></i>
{{/if}}
{{this.text}}
{{yield
(hash
isFulfilled=this.isFulfilled
isPending=this.isPending
isRejected=this.isRejected
isSettled=this.isSettled
)
}}
</label>
{{else}}
<button
disabled={{this.__disabled}}
type={{this.buttonType}}
class="btn {{if this.active "active"}} {{if this.block "btn-block"}} {{bs-size-class "btn" @size}} {{bs-type-class "btn" @type default=(if (macroCondition (macroGetOwnConfig "isBS3")) "default" "secondary") outline=@outline}}"
...attributes
{{on "click" this.handleClick}}
{{did-update this.resetState @reset}}
>
{{#if this.icon}}
<i class={{this.icon}}></i>
{{/if}}
{{this.text}}
{{yield
(hash
isFulfilled=this.isFulfilled
isPending=this.isPending
isRejected=this.isRejected
isSettled=this.isSettled
)
}}
</button>
{{/if}}
12 changes: 12 additions & 0 deletions addon/components/bs-button-group/button.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { isArray } from '@ember/array';
import Button from 'ember-bootstrap/components/bs-button';
import { guidFor } from '@ember/object/internals';
import { getOwnConfig, macroCondition } from '@embroider/macros';

/**
Internal component for button-group buttons
Expand All @@ -12,6 +14,8 @@ import Button from 'ember-bootstrap/components/bs-button';
export default class ButtonGroupButton extends Button {
'__ember-bootstrap_subclass' = true;

formId = guidFor(this);

/**
* @property groupValue
* @private
Expand Down Expand Up @@ -40,4 +44,12 @@ export default class ButtonGroupButton extends Button {
}
return false;
}

get isBS5ToggleButton() {
if (macroCondition(getOwnConfig().isBS5)) {
return this.args.buttonGroupType === 'radio' || this.args.buttonGroupType === 'checkbox';
} else {
return false;
}
}
}
2 changes: 1 addition & 1 deletion addon/components/bs-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ export default class Button extends Component {
/**
* Property to create outline buttons (BS4+ only)
*
* @property disabled
* @property outline
* @type boolean
* @default false
* @public
Expand Down