Skip to content

Commit

Permalink
adding visibility controls to interactive items
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodes committed Aug 19, 2024
1 parent 3b702ac commit 6670ac2
Show file tree
Hide file tree
Showing 12 changed files with 274 additions and 236 deletions.
86 changes: 44 additions & 42 deletions addon/components/button.hbs
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
<span class="btn-wrapper {{@wrapperClass}} inline-flex rounded-md {{if this.isNotSecondary 'shadow-sm'}} {{if @isLoading 'is-loading'}}" {{did-insert this.setupComponent}}>
<button
class="btn {{if @isLoading 'btn-is-loading'}} {{if @outline 'btn-outline'}} btn-{{or @type 'default'}} btn-{{or @size 'sm'}}"
disabled={{this.isDisabled}}
...attributes
type={{or @buttonType "button"}}
{{on "click" this.onClick}}
>
{{#if @isLoading}}
<span class="btn-icon-wrapper btn-loading-icon-wrapper" data-icon-prefix={{@iconPrefix}}>
<Spinner @width={{or @loaderWidth 14}} @height={{or @loaderHeight 14}} />
</span>
{{#if this.visible}}
<span class="btn-wrapper {{@wrapperClass}} inline-flex rounded-md {{if this.isNotSecondary 'shadow-sm'}} {{if @isLoading 'is-loading'}}" {{did-insert this.setupComponent}}>
<button
class="btn {{if @isLoading 'btn-is-loading'}} {{if @outline 'btn-outline'}} btn-{{or @type 'default'}} btn-{{or @size 'sm'}}"
disabled={{this.isDisabled}}
...attributes
type={{or @buttonType "button"}}
{{on "click" this.onClick}}
>
{{#if @isLoading}}
<span class="btn-icon-wrapper btn-loading-icon-wrapper" data-icon-prefix={{@iconPrefix}}>
<Spinner @width={{or @loaderWidth 14}} @height={{or @loaderHeight 14}} />
</span>
{{/if}}
{{#if this.showIcon}}
<span class="btn-icon-wrapper" data-icon-prefix={{@iconPrefix}}>
<FaIcon
@prefix={{@iconPrefix}}
@icon={{@icon}}
@size={{@iconSize}}
@rotation={{@iconRotation}}
@flip={{@iconFlip}}
@spin={{@iconSpin}}
class="{{if @text 'mr-2'}} {{@iconClass}}"
/>
</span>
{{/if}}
{{#if @text}}
<span class="{{@textClass}} {{if @responsive 'sm:hidden'}}">
{{@text}}
</span>
{{/if}}
{{yield}}
</button>
{{#if this.disabledByPermission}}
<Attach::Tooltip @class="clean" @animation="scale" @placement={{or @tooltipPlacement "top"}}>
<InputInfo @text={{t "common.unauthorized"}} />
</Attach::Tooltip>
{{else if @helpText}}
<Attach::Tooltip @class="clean" @animation="scale" @placement={{or @tooltipPlacement "top"}}>
<InputInfo @text={{@helpText}} @exampleText={{@exampleText}} />
</Attach::Tooltip>
{{/if}}
{{#if this.showIcon}}
<span class="btn-icon-wrapper" data-icon-prefix={{@iconPrefix}}>
<FaIcon
@prefix={{@iconPrefix}}
@icon={{@icon}}
@size={{@iconSize}}
@rotation={{@iconRotation}}
@flip={{@iconFlip}}
@spin={{@iconSpin}}
class="{{if @text 'mr-2'}} {{@iconClass}}"
/>
</span>
{{/if}}
{{#if @text}}
<span class="{{@textClass}} {{if @responsive 'sm:hidden'}}">
{{@text}}
</span>
{{/if}}
{{yield}}
</button>
{{#if this.disabledByPermission}}
<Attach::Tooltip @class="clean" @animation="scale" @placement={{or @tooltipPlacement "top"}}>
<InputInfo @text={{t "common.unauthorized"}} />
</Attach::Tooltip>
{{else if @helpText}}
<Attach::Tooltip @class="clean" @animation="scale" @placement={{or @tooltipPlacement "top"}}>
<InputInfo @text={{@helpText}} @exampleText={{@exampleText}} />
</Attach::Tooltip>
{{/if}}
</span>
</span>
{{/if}}
10 changes: 9 additions & 1 deletion addon/components/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,23 @@ export default class ButtonComponent extends Component {
*/
@tracked disabledByPermission = false;

/**
* Determines the visibility of the button
*
* @memberof ButtonComponent
*/
@tracked visible = true;

/**
* Creates an instance of ButtonComponent.
* @param {*} owner
* @param {*} { permission = null }
* @memberof ButtonComponent
*/
constructor(owner, { permission = null, disabled = false }) {
constructor(owner, { permission = null, disabled = false, visible = true }) {
super(...arguments);
this.permissionRequired = permission;
this.visible = true;
if (!disabled) {
this.disabledByPermission = permission && this.abilities.cannot(permission);
}
Expand Down
152 changes: 77 additions & 75 deletions addon/components/dropdown-button.hbs
Original file line number Diff line number Diff line change
@@ -1,75 +1,77 @@
<BasicDropdown
id={{@dropdownId}}
class={{@wrapperClass}}
@renderInPlace={{@renderInPlace}}
@registerAPI={{this.onRegisterAPI}}
@horizontalPosition={{@horizontalPosition}}
@verticalPosition={{@verticalPosition}}
@calculatePosition={{@calculatePosition}}
@defaultClass={{@defaultClass}}
@matchTriggerWidth={{@matchTriggerWidth}}
@onOpen={{@onOpen}}
@onClose={{@onClose}}
@disabled={{this.disabled}}
{{did-insert this.onInsert}}
as |dd|
>
<dd.Trigger class={{@triggerClass}} {{did-insert this.onTriggerInsert}}>
{{#if @buttonComponent}}
{{component
@buttonComponent
buttonComponentArgs=this.buttonComponentArgs
text=@text
class=(concat @buttonClass (if dd.isOpen " dd-is-open"))
wrapperClass=@buttonWrapperClass
type=this.type
active=@active
size=this.buttonSize
isLoading=@isLoading
disabled=this.disabled
textClass=@textClass
helpText=@helpText
tooltipPlacement=@tooltipPlacement
img=@img
imgClass=@imgClass
alt=@alt
}}
{{else}}
<Button
title={{@text}}
class="{{@buttonClass}} {{if dd.isOpen 'dd-is-open'}}"
@wrapperClass={{@buttonWrapperClass}}
@type={{this.type}}
@active={{@active}}
@size={{this.buttonSize}}
@isLoading={{@isLoading}}
disabled={{this.disabled}}
{{did-insert this.onButtonInsert}}
...attributes
>
{{#if @icon}}
<FaIcon @icon={{@icon}} @prefix={{@iconPrefix}} @size={{@iconSize}} class="{{@iconClass}} {{if @text 'mr-2'}}" />
{{/if}}
{{#if @img}}
<img src={{@img}} class={{@imgClass}} alt={{or @alt "image"}} />
{{/if}}
{{#if (and (not this.doesntHavePermissions) @helpText)}}
<Attach::Tooltip @class="clean" @animation="scale" @placement={{or @tooltipPlacement "top"}}>
<InputInfo @text={{@helpText}} />
</Attach::Tooltip>
{{/if}}
<div class="{{@textClass}} truncate">
{{@text}}
</div>
</Button>
{{/if}}
{{#if this.doesntHavePermissions}}
<Attach::Tooltip @class="clean" @animation="scale" @placement={{or @tooltipPlacement "top"}}>
<InputInfo @text={{t "common.unauthorized"}} />
</Attach::Tooltip>
{{/if}}
</dd.Trigger>
<dd.Content class={{@contentClass}} @overlay={{@overlay}}>
{{yield dd}}
</dd.Content>
</BasicDropdown>
{{#if this.visible}}
<BasicDropdown
id={{@dropdownId}}
class={{@wrapperClass}}
@renderInPlace={{@renderInPlace}}
@registerAPI={{this.onRegisterAPI}}
@horizontalPosition={{@horizontalPosition}}
@verticalPosition={{@verticalPosition}}
@calculatePosition={{@calculatePosition}}
@defaultClass={{@defaultClass}}
@matchTriggerWidth={{@matchTriggerWidth}}
@onOpen={{@onOpen}}
@onClose={{@onClose}}
@disabled={{this.disabled}}
{{did-insert this.onInsert}}
as |dd|
>
<dd.Trigger class={{@triggerClass}} {{did-insert this.onTriggerInsert}}>
{{#if @buttonComponent}}
{{component
@buttonComponent
buttonComponentArgs=this.buttonComponentArgs
text=@text
class=(concat @buttonClass (if dd.isOpen " dd-is-open"))
wrapperClass=@buttonWrapperClass
type=this.type
active=@active
size=this.buttonSize
isLoading=@isLoading
disabled=this.disabled
textClass=@textClass
helpText=@helpText
tooltipPlacement=@tooltipPlacement
img=@img
imgClass=@imgClass
alt=@alt
}}
{{else}}
<Button
title={{@text}}
class="{{@buttonClass}} {{if dd.isOpen 'dd-is-open'}}"
@wrapperClass={{@buttonWrapperClass}}
@type={{this.type}}
@active={{@active}}
@size={{this.buttonSize}}
@isLoading={{@isLoading}}
disabled={{this.disabled}}
{{did-insert this.onButtonInsert}}
...attributes
>
{{#if @icon}}
<FaIcon @icon={{@icon}} @prefix={{@iconPrefix}} @size={{@iconSize}} class="{{@iconClass}} {{if @text 'mr-2'}}" />
{{/if}}
{{#if @img}}
<img src={{@img}} class={{@imgClass}} alt={{or @alt "image"}} />
{{/if}}
{{#if (and (not this.doesntHavePermissions) @helpText)}}
<Attach::Tooltip @class="clean" @animation="scale" @placement={{or @tooltipPlacement "top"}}>
<InputInfo @text={{@helpText}} />
</Attach::Tooltip>
{{/if}}
<div class="{{@textClass}} truncate">
{{@text}}
</div>
</Button>
{{/if}}
{{#if this.doesntHavePermissions}}
<Attach::Tooltip @class="clean" @animation="scale" @placement={{or @tooltipPlacement "top"}}>
<InputInfo @text={{t "common.unauthorized"}} />
</Attach::Tooltip>
{{/if}}
</dd.Trigger>
<dd.Content class={{@contentClass}} @overlay={{@overlay}}>
{{yield dd}}
</dd.Content>
</BasicDropdown>
{{/if}}
4 changes: 3 additions & 1 deletion addon/components/dropdown-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default class DropdownButtonComponent extends Component {
@tracked _onTriggerInsertFired = false;
@tracked _onButtonInsertFired = false;
@tracked disabled = false;
@tracked visible = true;
@tracked permissionRequired = false;
@tracked doesntHavePermissions = false;

Expand All @@ -21,14 +22,15 @@ export default class DropdownButtonComponent extends Component {
* @param {Object} { type = 'default', size = 'md', buttonComponentArgs = {}}
* @memberof DropdownButtonComponent
*/
constructor(owner, { type = 'default', size = 'md', buttonComponentArgs = {}, permission = null, disabled = false }) {
constructor(owner, { type = 'default', size = 'md', buttonComponentArgs = {}, permission = null, disabled = false, visible = true }) {
super(...arguments);

this.type = type;
this.buttonSize = size;
this.buttonComponentArgs = buttonComponentArgs;
this.permissionRequired = permission;
this.disabled = disabled;
this.visible = true;
// If no permissions disable
if (!disabled) {
this.disabled = this.doesntHavePermissions = permission && this.abilities.cannot(permission);
Expand Down
1 change: 0 additions & 1 deletion addon/components/layout/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ export default class LayoutHeaderComponent extends Component {
{
href: 'javascript:;',
text: 'Changelog',
disabled: true,
action: 'viewChangelog',
},
];
Expand Down
8 changes: 4 additions & 4 deletions addon/components/layout/header/dropdown/item.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{#if this.isTextOnly}}
<div class={{if @item.overwriteWrapperClass @item.wrapperClass (concat @item.wrapperClass " px-1 flex flex-row")}}>
<div class={{if @item.overwriteWrapperClass @item.wrapperClass (concat @item.wrapperClass " next-header-dd-menu-item px-1 flex flex-row")}}>
{{#if @item.icon}}
<FaIcon @icon={{@item.icon}} @size={{or @item.iconSize "sm"}} class={{or @item.iconClass "mr-2"}} />
{{/if}}
Expand All @@ -17,7 +17,7 @@

{{#if this.isLink}}
<div class={{if @item.overwriteWrapperClass @item.wrapperClass (concat @item.wrapperClass " px-1")}}>
<LinkTo @route={{@item.route}} disabled={{@item.disabled}} class="next-dd-item {{@item.class}}">
<LinkTo @route={{@item.route}} disabled={{@item.disabled}} class="next-header-dd-menu-item next-dd-item {{@item.class}}">
{{#if @item.icon}}
<FaIcon @icon={{@item.icon}} @size={{or @item.iconSize "sm"}} class={{or @item.iconClass "mr-2"}} />
{{/if}}
Expand All @@ -30,7 +30,7 @@
<div class={{if @item.overwriteWrapperClass @item.wrapperClass (concat @item.wrapperClass " px-1")}}>
<a
href={{@item.href}}
class="next-dd-item {{if @item.disabled 'disabled'}} {{@item.class}}"
class="next-header-dd-menu-item next-dd-item {{if @item.disabled 'disabled'}} {{@item.class}}"
target={{@item.target}}
disabled={{@item.disabled}}
{{on "click" (fn @onAction @item.action @item.params)}}
Expand All @@ -45,7 +45,7 @@

{{#if this.isInteractive}}
<div class={{if @item.overwriteWrapperClass @item.wrapperClass (concat @item.wrapperClass " px-1")}}>
<a href="javascript:;" class="next-dd-item {{if this.active 'active'}}" disabled={{@item.disabled}} {{on "click" @item.onClick}} ...attributes>
<a href="javascript:;" class="next-header-dd-menu-item next-dd-item {{if this.active 'active'}}" disabled={{@item.disabled}} {{on "click" @item.onClick}} ...attributes>
{{#if @item.icon}}
<FaIcon @icon={{@item.icon}} @size={{or @item.iconSize "sm"}} class={{or @item.iconClass "mr-2"}} />
{{/if}}
Expand Down
Loading

0 comments on commit 6670ac2

Please sign in to comment.