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

Sheet: allow expansion with attribute #625

Merged
merged 4 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sixty-fishes-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ithaka/pharos': patch
---

allow expansion with attribute in sheet
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ export const WithClose = {
),
};

export const Expanded = {
render: () => (
<PharosSheet id="my-sheet" label="Pharos sheet" expanded>
<div>Lorem ipsum dolor sit amet</div>
</PharosSheet>
),
};

export const LongContent = {
render: () => (
<PharosSheet id="my-sheet" label="Pharos sheet">
Expand Down
6 changes: 0 additions & 6 deletions packages/pharos/src/components/sheet/pharos-sheet.scss
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,3 @@
margin-right: 1.25rem;
}
}

:host([expanded]) {
.sheet__content {
height: 95%;
}
}
16 changes: 13 additions & 3 deletions packages/pharos/src/components/sheet/pharos-sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class PharosSheet extends ScopedRegistryMixin(PharosElement) {
* Indicates if the sheet is expanded.
* @attr expanded
*/
@property({ type: Boolean, reflect: true })
@property({ type: Boolean, reflect: true, attribute: 'expanded' })
public expanded = false;

/**
Expand Down Expand Up @@ -111,7 +111,9 @@ export class PharosSheet extends ScopedRegistryMixin(PharosElement) {
if (changedProperties.has('open')) {
if (this.open) {
const sheetContent = this.shadowRoot?.querySelector(`.sheet__content`) as HTMLDivElement;
sheetContent.style.height = this.MIN_EXPAND_PERCENTAGE;
sheetContent.style.height = this.expanded
? this.MAX_EXPAND_PERCENTAGE
: this.MIN_EXPAND_PERCENTAGE;
this._focusContents();
} else {
this._returnTriggerFocus();
Expand All @@ -121,6 +123,12 @@ export class PharosSheet extends ScopedRegistryMixin(PharosElement) {
this._emitVisibilityChange();
}
}
if (changedProperties.has('expanded')) {
if (this.expanded) {
const sheetContent = this.shadowRoot?.querySelector(`.sheet__content`) as HTMLDivElement;
sheetContent.style.height = this.MAX_EXPAND_PERCENTAGE;
}
}
}

override connectedCallback(): void {
Expand Down Expand Up @@ -182,7 +190,9 @@ export class PharosSheet extends ScopedRegistryMixin(PharosElement) {
) {
this.open = true;
const sheetContent = this.shadowRoot?.querySelector(`.sheet__content`) as HTMLDivElement;
sheetContent.style.height = this.MIN_EXPAND_PERCENTAGE;
sheetContent.style.height = this.expanded
? this.MAX_EXPAND_PERCENTAGE
: this.MIN_EXPAND_PERCENTAGE;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ export const WithClose = {
`,
};

export const Expanded = {
render: () =>
html`
<div>
<storybook-pharos-button id="my-button" data-sheet-id="my-sheet" icon-right="chevron-down">
Click Me
</storybook-pharos-button>
<storybook-pharos-sheet id="my-sheet" label="Pharos sheet" expanded>
<div>Lorem ipsum dolor sit amet</div>
</storybook-pharos-sheet>
</div>
`,
};

export const LongContent = {
render: () =>
html`
Expand Down