diff --git a/apps/website/src/pages/docs/popover.mdx b/apps/website/src/pages/docs/popover.mdx new file mode 100644 index 00000000000..11abbe88287 --- /dev/null +++ b/apps/website/src/pages/docs/popover.mdx @@ -0,0 +1,63 @@ +--- +title: Popover +description: An overlay dialog placed next to a trigger element. +layout: ./_layout.astro +group: utilities +thumbnail: #TODO +--- + +import PropsTable from '~/components/PropsTable.astro'; +import LiveExample from '~/components/LiveExample.astro'; +import * as AllExamples from 'examples'; + +Popover is a utility component for displaying overlay content in a dialog that is placed relative to a trigger element. + + + + + +By default, Popover does not add any styling. The `applyBackground` prop can be used to add the recommended background, box-shadow, border, etc. + +## Usage + +The content shown inside the Popover is passed using the `content` prop. The trigger element is specified by the child element that Popover wraps around. + +For everything to work correctly, the trigger element must: + +- be a button +- forward its ref +- delegate (spread) any arbitrary props + +If you use a native ` + + + + } + > + + + + + ); +}; diff --git a/examples/Popover.main.tsx b/examples/Popover.main.tsx new file mode 100644 index 00000000000..ac2a8f66879 --- /dev/null +++ b/examples/Popover.main.tsx @@ -0,0 +1,18 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Bentley Systems, Incorporated. All rights reserved. + * See LICENSE.md in the project root for license terms and full copyright notice. + *--------------------------------------------------------------------------------------------*/ +import * as React from 'react'; +import { Button, Popover } from '@itwin/itwinui-react'; + +export default () => { + return ( + + + + ); +}; diff --git a/examples/Popover.placement.tsx b/examples/Popover.placement.tsx new file mode 100644 index 00000000000..f83900c23d4 --- /dev/null +++ b/examples/Popover.placement.tsx @@ -0,0 +1,46 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Bentley Systems, Incorporated. All rights reserved. + * See LICENSE.md in the project root for license terms and full copyright notice. + *--------------------------------------------------------------------------------------------*/ +import * as React from 'react'; +import { Button, LabeledSelect, Popover } from '@itwin/itwinui-react'; + +export default () => { + const [placement, setPlacement] = + React.useState<(typeof placements)[number]>('bottom-start'); + + return ( + + ({ value: p, label: p }))} + value={placement} + onChange={setPlacement} + style={{ minWidth: '20ch' }} + /> + + } + applyBackground + placement={placement} + > + + + ); +}; + +const placements = [ + 'bottom', + 'bottom-start', + 'bottom-end', + 'top', + 'top-start', + 'top-end', + 'left', + 'left-start', + 'left-end', + 'right', + 'right-start', + 'right-end', +] as const; diff --git a/examples/index.tsx b/examples/index.tsx index c2a663384d8..3e33d39c09c 100644 --- a/examples/index.tsx +++ b/examples/index.tsx @@ -822,6 +822,19 @@ export { OverlaySubExample }; // ---------------------------------------------------------------------------- +import { default as PopoverMainExampleRaw } from './Popover.main'; +export const PopoverMainExample = withThemeProvider(PopoverMainExampleRaw); + +import { default as PopoverPlacementExampleRaw } from './Popover.placement'; +export const PopoverPlacementExample = withThemeProvider( + PopoverPlacementExampleRaw, +); + +import { default as PopoverFocusExampleRaw } from './Popover.focus'; +export const PopoverFocusExample = withThemeProvider(PopoverFocusExampleRaw); + +// ---------------------------------------------------------------------------- + import { default as ProgressLinearMainExampleRaw } from './ProgressLinear.main'; const ProgressLinearMainExample = withThemeProvider( ProgressLinearMainExampleRaw,