mirror of
https://github.com/vector-im/element-call.git
synced 2026-11-22 09:41:09 +08:00
Compare commits
1
Commits
main
...
robin/popover
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0eff661159 |
@@ -51,6 +51,7 @@
|
||||
"build-storybook": "storybook build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@base-ui/react": "^1.9.0",
|
||||
"@codecov/vite-plugin": "^1.3.0",
|
||||
"@fontsource/inconsolata": "^5.1.0",
|
||||
"@fontsource/inter": "^5.1.0",
|
||||
|
||||
Generated
+58
@@ -22,6 +22,9 @@ importers:
|
||||
|
||||
.:
|
||||
devDependencies:
|
||||
'@base-ui/react':
|
||||
specifier: ^1.9.0
|
||||
version: 1.9.0(@types/react@19.2.18)(react-dom@19.2.8(react@19.2.8))(react@19.2.8)
|
||||
'@codecov/vite-plugin':
|
||||
specifier: ^1.3.0
|
||||
version: 1.9.1(vite@8.2.4(@types/node@24.13.3)(esbuild@0.28.2)(jiti@2.7.0)(sass@1.103.1)(terser@5.46.1)(yaml@2.9.0))
|
||||
@@ -416,6 +419,33 @@ packages:
|
||||
resolution: {integrity: sha512-Vj1jF3cPfxg7OAfoI7QnVKLoILlm2JF9pnVHrX8qx7AHMiYWT+NDAA7jChlNgRS4WTLc/fD1lXLmPixluj+3Gg==}
|
||||
engines: {node: '>=6.9.0'}
|
||||
|
||||
'@base-ui/react@1.9.0':
|
||||
resolution: {integrity: sha512-S8CSYosASBKtpL8SWUfS78rFElfLijiCgA7oHOK22jCJ95FULsYyKwBNFOgudt0RA+/7yNc7F81bOvQnRgbBiQ==}
|
||||
engines: {node: '>=14.0.0'}
|
||||
peerDependencies:
|
||||
'@date-fns/tz': ^1.2.0
|
||||
'@types/react': ^17 || ^18 || ^19
|
||||
date-fns: ^4.0.0
|
||||
react: ^17 || ^18 || ^19
|
||||
react-dom: ^17 || ^18 || ^19
|
||||
peerDependenciesMeta:
|
||||
'@date-fns/tz':
|
||||
optional: true
|
||||
'@types/react':
|
||||
optional: true
|
||||
date-fns:
|
||||
optional: true
|
||||
|
||||
'@base-ui/utils@0.5.0':
|
||||
resolution: {integrity: sha512-dYGGcEttjkYiMoa5nHm8vLaJ2UcuTWxo3BFAwOYXeRg/q7UVVvA6cacEIXEs3FgBfK1CGtW1ptElqs7wsx+t9A==}
|
||||
peerDependencies:
|
||||
'@types/react': ^17 || ^18 || ^19
|
||||
react: ^17 || ^18 || ^19
|
||||
react-dom: ^17 || ^18 || ^19
|
||||
peerDependenciesMeta:
|
||||
'@types/react':
|
||||
optional: true
|
||||
|
||||
'@bcoe/v8-coverage@1.0.2':
|
||||
resolution: {integrity: sha512-6zABk/ECA/QYSCQ1NGiVwwbQerUCZ+TQbp64Q3AgmfNvurHH0j8TtXa1qbShXA6qqkpAj4V5W8pP6mLe1mcMqA==}
|
||||
engines: {node: '>=18'}
|
||||
@@ -5477,6 +5507,9 @@ packages:
|
||||
require-main-filename@2.0.0:
|
||||
resolution: {integrity: sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==}
|
||||
|
||||
reselect@5.3.0:
|
||||
resolution: {integrity: sha512-XGoLeRAVzUTcJ1qkxPQhDJyIZ5d6zzZD9nT7AEZOaaU9UbWclhycElmhO+VD5bFeLuzhPBaOV2oXC8uG35ZSpg==}
|
||||
|
||||
resolve-from@4.0.0:
|
||||
resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==}
|
||||
engines: {node: '>=4'}
|
||||
@@ -6432,6 +6465,29 @@ snapshots:
|
||||
'@babel/helper-string-parser': 7.29.7
|
||||
'@babel/helper-validator-identifier': 7.29.7
|
||||
|
||||
'@base-ui/react@1.9.0(@types/react@19.2.18)(react-dom@19.2.8(react@19.2.8))(react@19.2.8)':
|
||||
dependencies:
|
||||
'@babel/runtime': 8.0.8
|
||||
'@base-ui/utils': 0.5.0(@types/react@19.2.18)(react-dom@19.2.8(react@19.2.8))(react@19.2.8)
|
||||
'@floating-ui/react-dom': 2.1.9(react-dom@19.2.8(react@19.2.8))(react@19.2.8)
|
||||
'@floating-ui/utils': 0.2.12
|
||||
react: 19.2.8
|
||||
react-dom: 19.2.8(react@19.2.8)
|
||||
use-sync-external-store: 1.7.0(react@19.2.8)
|
||||
optionalDependencies:
|
||||
'@types/react': 19.2.18
|
||||
|
||||
'@base-ui/utils@0.5.0(@types/react@19.2.18)(react-dom@19.2.8(react@19.2.8))(react@19.2.8)':
|
||||
dependencies:
|
||||
'@babel/runtime': 8.0.8
|
||||
'@floating-ui/utils': 0.2.12
|
||||
react: 19.2.8
|
||||
react-dom: 19.2.8(react@19.2.8)
|
||||
reselect: 5.3.0
|
||||
use-sync-external-store: 1.7.0(react@19.2.8)
|
||||
optionalDependencies:
|
||||
'@types/react': 19.2.18
|
||||
|
||||
'@bcoe/v8-coverage@1.0.2': {}
|
||||
|
||||
'@blazediff/core@1.9.1': {}
|
||||
@@ -11310,6 +11366,8 @@ snapshots:
|
||||
|
||||
require-main-filename@2.0.0: {}
|
||||
|
||||
reselect@5.3.0: {}
|
||||
|
||||
resolve-from@4.0.0: {}
|
||||
|
||||
resolve@1.22.12:
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
Copyright 2026 Element Creations Ltd.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE in the repository root for full details.
|
||||
*/
|
||||
|
||||
.popover {
|
||||
position: relative;
|
||||
border-radius: var(--cpd-space-3x);
|
||||
background: var(--cpd-color-bg-canvas-default);
|
||||
box-shadow: var(--big-drop-shadow);
|
||||
padding: var(--cpd-space-5x);
|
||||
box-sizing: border-box;
|
||||
inline-size: 310px;
|
||||
max-inline-size: 90vw;
|
||||
|
||||
/* Draw an internal border */
|
||||
&::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
border: var(--cpd-border-width-1) solid
|
||||
var(--cpd-color-border-interactive-secondary);
|
||||
border-radius: inherit;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
transition:
|
||||
opacity 180ms,
|
||||
transform 180ms;
|
||||
|
||||
&[data-starting-style] {
|
||||
opacity: 0;
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
transform: translate(0, var(--cpd-space-3x));
|
||||
}
|
||||
}
|
||||
|
||||
&[data-ending-style] {
|
||||
transition-duration: 110ms;
|
||||
opacity: 0;
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
transform: translate(0, var(--cpd-space-2x));
|
||||
}
|
||||
}
|
||||
|
||||
p {
|
||||
font: var(--cpd-font-body-sm-regular);
|
||||
color: var(--cpd-color-text-secondary);
|
||||
margin-block-end: var(--cpd-space-4x);
|
||||
}
|
||||
}
|
||||
|
||||
.title {
|
||||
margin-block-end: var(--cpd-space-2x);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
Copyright 2026 Element Creations Ltd.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE in the repository root for full details.
|
||||
*/
|
||||
|
||||
import type { Meta, StoryObj } from "@storybook/react-vite";
|
||||
import { Popover } from "./Popover";
|
||||
import { Button } from "@vector-im/compound-web";
|
||||
import { VideoCallOffSolidIcon } from "@vector-im/compound-design-tokens/assets/web/icons";
|
||||
import { useState } from "react";
|
||||
|
||||
const meta = {
|
||||
component: Popover,
|
||||
} satisfies Meta<typeof Popover>;
|
||||
|
||||
export default meta;
|
||||
|
||||
export const Default: StoryObj = {
|
||||
render: () => {
|
||||
const [open, setOpen] = useState(true);
|
||||
return (
|
||||
<Popover
|
||||
title="Poor network connection"
|
||||
trigger={<Button>Open popover</Button>}
|
||||
open={open}
|
||||
onOpenChange={setOpen}
|
||||
>
|
||||
<p>Turn off all videos to improve call performance.</p>
|
||||
<Button
|
||||
size="md"
|
||||
Icon={VideoCallOffSolidIcon}
|
||||
style={{ width: "100%", marginBlockStart: 24 }}
|
||||
>
|
||||
Turn off all videos
|
||||
</Button>
|
||||
</Popover>
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
Copyright 2026 Element Creations Ltd.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { expect, test } from "vitest";
|
||||
import { axe } from "vitest-axe";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
|
||||
import { Popover } from "./Popover";
|
||||
|
||||
test("Popover renders", async () => {
|
||||
render(
|
||||
<Popover
|
||||
title="Example"
|
||||
trigger={<button>Open popover</button>}
|
||||
open
|
||||
onOpenChange={() => {}}
|
||||
>
|
||||
<p>This is an example of a popover.</p>
|
||||
</Popover>,
|
||||
);
|
||||
const button = screen.getByRole("button", { name: "Open popover" });
|
||||
const popover = screen.getByRole("dialog", { name: "Example" });
|
||||
expect(button).toMatchSnapshot("button");
|
||||
expect(popover).toMatchSnapshot("popover");
|
||||
expect(await axe(document.body)).toHaveNoViolations();
|
||||
});
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
Copyright 2026 Element Creations Ltd.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { type FC, type ReactElement, type ReactNode } from "react";
|
||||
import { Popover as BUIPopover } from "@base-ui/react/popover";
|
||||
|
||||
import styles from "./Popover.module.css";
|
||||
import { Heading } from "@vector-im/compound-web";
|
||||
import classNames from "classnames";
|
||||
|
||||
export interface PopoverProps {
|
||||
/**
|
||||
* The popover title.
|
||||
*/
|
||||
title: string;
|
||||
/**
|
||||
* The button that opens the popover. This must be a component that accepts a
|
||||
* ref and spreads props.
|
||||
*
|
||||
* https://base-ui.com/react/handbook/composition
|
||||
*/
|
||||
trigger: ReactElement;
|
||||
/**
|
||||
* Whether the popover is open.
|
||||
*/
|
||||
open: boolean;
|
||||
/**
|
||||
* Event handler called when the user tries to open or close the popover.
|
||||
*/
|
||||
onOpenChange: (open: boolean) => void;
|
||||
/**
|
||||
* The popover contents.
|
||||
*/
|
||||
children: ReactNode;
|
||||
className?: string;
|
||||
/**
|
||||
* The side of the trigger on which to place the popover. Note that the menu
|
||||
* may still end up on a different side than the one you request if there
|
||||
* isn't enough space.
|
||||
* @default bottom
|
||||
*/
|
||||
side?: "top" | "bottom" | "left" | "right" | "inline-end" | "inline-start";
|
||||
/**
|
||||
* The edge along which the popover and trigger will be aligned.
|
||||
* @default center
|
||||
*/
|
||||
align?: "start" | "center" | "end";
|
||||
}
|
||||
|
||||
/**
|
||||
* A popover opened by pressing a button.
|
||||
*/
|
||||
export const Popover: FC<PopoverProps> = ({
|
||||
title,
|
||||
trigger,
|
||||
open,
|
||||
onOpenChange,
|
||||
children,
|
||||
className,
|
||||
side,
|
||||
align,
|
||||
}) => {
|
||||
return (
|
||||
<BUIPopover.Root open={open} onOpenChange={onOpenChange}>
|
||||
<BUIPopover.Trigger render={trigger} />
|
||||
<BUIPopover.Portal>
|
||||
<BUIPopover.Positioner sideOffset={8} side={side} align={align}>
|
||||
<BUIPopover.Popup className={classNames(styles.popover, className)}>
|
||||
<BUIPopover.Title
|
||||
className={styles.title}
|
||||
render={
|
||||
<Heading as="h3" type="body" weight="semibold" size="lg">
|
||||
{title}
|
||||
</Heading>
|
||||
}
|
||||
/>
|
||||
{children}
|
||||
</BUIPopover.Popup>
|
||||
</BUIPopover.Positioner>
|
||||
</BUIPopover.Portal>
|
||||
</BUIPopover.Root>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`Popover renders > button 1`] = `
|
||||
<button
|
||||
aria-controls="_r_0_"
|
||||
aria-expanded="true"
|
||||
aria-haspopup="dialog"
|
||||
data-base-ui-click-trigger=""
|
||||
data-popup-open=""
|
||||
id="base-ui-_r_1_"
|
||||
tabindex="0"
|
||||
type="button"
|
||||
>
|
||||
Open popover
|
||||
</button>
|
||||
`;
|
||||
|
||||
exports[`Popover renders > popover 1`] = `
|
||||
<div
|
||||
aria-labelledby="base-ui-_r_4_"
|
||||
class="_popover_8e8188"
|
||||
data-align="center"
|
||||
data-base-ui-focusable=""
|
||||
data-open=""
|
||||
data-side="bottom"
|
||||
id="_r_0_"
|
||||
role="dialog"
|
||||
tabindex="-1"
|
||||
>
|
||||
<h3
|
||||
class="_typography_6v6n8_153 _font-body-lg-semibold_6v6n8_74 _title_8e8188"
|
||||
id="base-ui-_r_4_"
|
||||
>
|
||||
Example
|
||||
</h3>
|
||||
<p>
|
||||
This is an example of a popover.
|
||||
</p>
|
||||
</div>
|
||||
`;
|
||||
Reference in New Issue
Block a user