Skip to content

Commit

Permalink
Merge pull request #649 from takenet/bugfix/sidebar-events
Browse files Browse the repository at this point in the history
fix(sidebar): adding events sidebar status & fixing width prop
  • Loading branch information
lucasMurtaVI authored Jul 31, 2023
2 parents 3df6757 + c72f993 commit 00c563e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2117,6 +2117,10 @@ export interface BdsSelectOptionCustomEvent<T> extends CustomEvent<T> {
detail: T;
target: HTMLBdsSelectOptionElement;
}
export interface BdsSidebarCustomEvent<T> extends CustomEvent<T> {
detail: T;
target: HTMLBdsSidebarElement;
}
export interface BdsSwitchCustomEvent<T> extends CustomEvent<T> {
detail: T;
target: HTMLBdsSwitchElement;
Expand Down Expand Up @@ -4551,6 +4555,10 @@ declare namespace LocalJSX {
* If true, a lateral margin will apear in the content.
*/
"margin"?: boolean;
/**
* Emitted when the isOpen has changed.
*/
"onBdsToggle"?: (event: BdsSidebarCustomEvent<any>) => void;
/**
* sidebar position. Used to position the sidebar. Either on the left or on the right.
*/
Expand Down
9 changes: 8 additions & 1 deletion src/components/sidebar/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@
| `margin` | `margin` | If true, a lateral margin will apear in the content. | `boolean` | `true` |
| `sidebarPosition` | `sidebar-position` | sidebar position. Used to position the sidebar. Either on the left or on the right. | `"left" \| "right"` | `'left'` |
| `type` | `type` | sidebar type. Used to define how open. | `"fixed" \| "over"` | `'over'` |
| `width` | `width` | Width, number to define sidebar width. | `number` | `undefined` |
| `width` | `width` | Width, number to define sidebar width. | `number` | `360` |


## Events

| Event | Description | Type |
| ----------- | ------------------------------------ | ------------------ |
| `bdsToggle` | Emitted when the isOpen has changed. | `CustomEvent<any>` |


## Methods
Expand Down
3 changes: 2 additions & 1 deletion src/components/sidebar/sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@
align-content: center;
justify-content: space-between;
padding: 24px;

& .content {
display: flex;
width: 100%;
align-items: center;
position: relative;
color: $color-content-default;
Expand Down
11 changes: 9 additions & 2 deletions src/components/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, h, State, Prop, Method, Watch, Element } from '@stencil/core';
import { Component, h, State, Prop, EventEmitter, Event, Method, Watch, Element } from '@stencil/core';

export type sidebarPosition = 'left' | 'right';
export type sidebarType = 'over' | 'fixed';
Expand Down Expand Up @@ -39,20 +39,26 @@ export class Sidebar {
/**
* Width, number to define sidebar width.
*/
@Prop() width?: number;
@Prop() width?: number = 360;

/**
* Width, number to define sidebar width.
*/
@Prop() background?: sidebarBackground = 'surface-2';

/**
* Emitted when the isOpen has changed.
*/
@Event() bdsToggle!: EventEmitter;

@Method()
async toggle() {
this.isOpen = !this.isOpen;
}

@Watch('isOpen')
isOpenChanged(newValue: boolean): void {
this.bdsToggle.emit({ value: newValue });
if (newValue === true) {
document.addEventListener('keyup', this.listiner, false);
} else {
Expand Down Expand Up @@ -94,6 +100,7 @@ export class Sidebar {
[`position_${this.sidebarPosition}`]: true,
[`background_${this.background}`]: true,
}}
style={{ width: `${this.width < 144 ? 144 : this.width}px` }}
>
{this.hasHeaderSlot && (
<div class={{ header: true }}>
Expand Down

0 comments on commit 00c563e

Please sign in to comment.