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

fix(person-card): fix placement to top if not enough space on bottom #1375

Merged
merged 1 commit into from
Feb 14, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/good-pumpkins-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@equinor/fusion-wc-person': patch
---

Fix placement to top if there is no space on bottom
5 changes: 5 additions & 0 deletions .changeset/tame-plants-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@equinor/fusion-wc-storybook': patch
---

Add story for person-avatar to show avatar in each corner
37 changes: 29 additions & 8 deletions packages/person/src/components/avatar/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IntersectionController } from '@lit-labs/observers/intersection-control
import { AvatarData, PersonAvatarElementProps } from './types';
import { PersonAccountType, PersonAvailability } from '../../types';
import '../card';
import { computePosition, flip, shift, offset } from '@floating-ui/dom';
import { computePosition, shift, offset, autoPlacement, autoUpdate } from '@floating-ui/dom';
import style from './element.css';
import { PersonInfoControllerHost, PersonInfoTask } from '../../tasks/person-info-task';
import { PersonPhotoControllerHost, PersonPhotoTask } from '../../tasks/person-photo-task';
Expand Down Expand Up @@ -160,19 +160,40 @@ export class PersonAvatarElement
*/
static openedPersonAvatars: PersonAvatarElement[] = [];

async updated(props: PropertyValues) {
if (props.has('isFloatingOpen') && this.isFloatingOpen && (await this.floating) instanceof HTMLElement) {
await this.updateComplete;
computePosition(await this.root, await this.floating, {
async handleFloatingUi(): Promise<VoidFunction> {
const root = await this.root;
const floating = await this.floating;

const update = () => {
computePosition(root, floating, {
placement: 'bottom-start',
middleware: [offset(5), flip(), shift({ padding: 5 })],
middleware: [
offset(5),
autoPlacement({
allowedPlacements: ['bottom-start', 'top-start'],
}),
shift({ padding: 5 }),
],
}).then(async ({ x, y }) => {
// use 3d translate
Object.assign((await this.floating).style, {
Object.assign(floating.style, {
left: `${x}px`,
top: `${y}px`,
});
});
};
return autoUpdate(root, floating, update);
}

cleanup?: () => void;

async updated(props: PropertyValues) {
if (props.has('isFloatingOpen')) {
if (this.isFloatingOpen) {
this.cleanup = await this.handleFloatingUi();
} else if (this.cleanup) {
this.cleanup();
delete this.cleanup;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/person/src/components/avatar/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export type PersonAvatarElementProps = PersonInfoControllerHostAttributes & {
clickable?: boolean;
disabled?: boolean;
pictureSrc?: string;
trigger: PersonAvatarShowCardOnType;
};
12 changes: 12 additions & 0 deletions storybook/stories/person/person-avatar.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,16 @@ export const Disabled: Story = {
render: (props) => render({ ...props, disabled: true }),
};

export const CornerPositions: Story = {
...Default,
render: (props) => html`
<div style="height: 85vh;">
<div style="display: flex; justify-content: space-between;">${render(props)}${render(props)}</div>
<div style="display: flex; justify-content: space-between; height: 100%; align-items: flex-end;">
${render(props)}${render(props)}
</div>
</div>
`,
};

export default meta;
Loading