Skip to content

Commit

Permalink
Add expanded state for disclosure and dropdown buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
bertdeblock committed Dec 20, 2023
1 parent c0ff7e3 commit 32238f3
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion addon/components/velvet-alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface VelvetAlertSignature {
};
Blocks: {
/// The content of the alert.
content?: [];
content: [];
/// The icon of the alert.
icon?: [{ class: "velvet-alert-icon" }];
/// The title of the alert.
Expand Down
8 changes: 7 additions & 1 deletion addon/components/velvet-button.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
(concat "velvet-button-" (or @variant "primary"))
(if @isPill "velvet-button-pill")
(if @isDisabled "velvet-button-disabled")
(if @isDisclosure (if @isExpanded "velvet-button-expanded"))
)
as |className|
}}
{{#if @isRenderless}}
{{yield (hash class=className)}}
{{else}}
<button
aria-expanded={{if @isDisclosure (if @isExpanded "true" "false") null}}
class={{className}}
disabled={{@isDisabled}}
type={{or @type "button"}}
Expand All @@ -24,7 +26,11 @@
{{/if}}
{{yield (hash class=className)}}
{{#if @isDisclosure}}
<this.VelvetIconChevronDown class="velvet-button-disclosure-icon" />
{{#if @isExpanded}}
<this.VelvetIconXMark class="velvet-button-disclosure-icon" />
{{else}}
<this.VelvetIconChevronDown class="velvet-button-disclosure-icon" />
{{/if}}
{{/if}}
</button>
{{/if}}
Expand Down
5 changes: 5 additions & 0 deletions addon/components/velvet-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Component from "@glimmer/component";
import type { ModifierLike } from "@glint/template";
import type { TriggerSignature } from "velvet-thunder/components/velvet-dropdown";
import VelvetIconChevronDown from "velvet-thunder/components/velvet-icon/chevron-down";
import VelvetIconXMark from "velvet-thunder/components/velvet-icon/x-mark";

interface VelvetButtonSignature {
Args: {
Expand All @@ -11,6 +12,9 @@ interface VelvetButtonSignature {
/// Indicate if the button discloses content.
/// @default [false]
isDisclosure?: boolean;
/// Indicate if the button's disclosed content is expanded.
/// @default [false]
isExpanded?: boolean;
/// Indicate if the button should render a loading state.
/// @default [false]
isLoading?: boolean;
Expand Down Expand Up @@ -44,6 +48,7 @@ interface VelvetButtonSignature {

export default class VelvetButton extends Component<VelvetButtonSignature> {
VelvetIconChevronDown = VelvetIconChevronDown;
VelvetIconXMark = VelvetIconXMark;

clickHandler = (event: MouseEvent) => {
const { isDisabled, onClick } = this.args;
Expand Down
1 change: 1 addition & 0 deletions addon/components/velvet-disclosure.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Button=(component
(ensure-safe-component this.VelvetButton)
isDisclosure=true
isExpanded=this.isShown
onClick=this.toggle
)
IconButton=(component
Expand Down
5 changes: 4 additions & 1 deletion addon/components/velvet-disclosure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ interface VelvetDisclosureSignature {
/// The trigger of the disclosure.
trigger: [
publicAPI: PublicAPI & {
Button: WithBoundArgs<typeof VelvetButton, "isDisclosure" | "onClick">;
Button: WithBoundArgs<
typeof VelvetButton,
"isDisclosure" | "isExpanded" | "onClick"
>;
IconButton: WithBoundArgs<typeof VelvetIconButton, "onClick">;
},
];
Expand Down
1 change: 1 addition & 0 deletions addon/components/velvet-dropdown.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Button=(component
(ensure-safe-component this.VelvetButton)
isDisclosure=true
isExpanded=this.isShown
privateDropdownTrigger=this.trigger
)
Content=(component
Expand Down
2 changes: 1 addition & 1 deletion docs/components/disclosure/demo/disabling-animations.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Use the `@shouldAnimate` argument to enable/disable animations.
```hbs template
<DemoSpaceY>
<VelvetSwitch @isChecked={{this.shouldAnimate}} @onChange={{this.onChange}}>
Should Animate
Animate
</VelvetSwitch>
<VelvetDisclosure @shouldAnimate={{this.shouldAnimate}}>
Expand Down
2 changes: 1 addition & 1 deletion tailwind/components/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = () => ({
},

"&-disclosure-icon": {
"@apply ml-2": {},
"@apply h-4 ml-2 w-4": {},
},

".velvet-spinner": {
Expand Down

0 comments on commit 32238f3

Please sign in to comment.