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

feat: new popover #2379

Merged
merged 35 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0c868ac
feat: refactored popover completely
nmerget Mar 21, 2024
88c967b
fix: remaining issues for vue and angular
nmerget Mar 21, 2024
ba29b0a
fix: issue with component tests
nmerget Mar 22, 2024
31614b6
Merge branch 'main' into feat-new-popover
nmerget Mar 22, 2024
fbefd4e
fix: issue with vue component test
nmerget Mar 22, 2024
7bf6a04
Merge remote-tracking branch 'origin/feat-new-popover' into feat-new-…
nmerget Mar 22, 2024
075868a
Merge branch 'main' into feat-new-popover
mfranzke Mar 26, 2024
3f51bf8
fix: issues from PR
nmerget Mar 27, 2024
5333c87
Merge branch 'main' into feat-new-popover
nmerget Mar 27, 2024
1c8fe2f
fix: issue with missing type
nmerget Mar 27, 2024
d1d7547
Merge branch 'main' into feat-new-popover
mfranzke Mar 28, 2024
0b21884
Update Angular.md
mfranzke Mar 28, 2024
f5c6d76
Update HTML.md
mfranzke Mar 28, 2024
86dd368
Update React.md
mfranzke Mar 28, 2024
ddcfb8b
Update Vue.md
mfranzke Mar 28, 2024
fa27eb9
Merge branch 'main' into feat-new-popover
nmerget Apr 2, 2024
14cc8b3
Update Angular.md
mfranzke Apr 2, 2024
6b3807f
Update HTML.md
mfranzke Apr 2, 2024
4ebe3a6
Update React.md
mfranzke Apr 2, 2024
3597641
Update Vue.md
mfranzke Apr 2, 2024
b69590b
refactor: moved that declaration
mfranzke Apr 2, 2024
8f55df8
Update _popover-component.scss
mfranzke Apr 2, 2024
8693cdc
Merge branch 'main' into feat-new-popover
mfranzke Apr 2, 2024
e663393
fix: all issues from PR
nmerget Apr 3, 2024
26838f6
Merge branch 'main' into feat-new-popover
nmerget Apr 3, 2024
6f71ebd
fix: issue with typescript
nmerget Apr 3, 2024
e3ad512
Merge remote-tracking branch 'origin/feat-new-popover' into feat-new-…
nmerget Apr 3, 2024
ac7d9d9
fix: issue with typescript
nmerget Apr 3, 2024
b577f9b
Update packages/components/src/components/tooltip/tooltip.lite.tsx
mfranzke Apr 3, 2024
d64c156
Revert "Update packages/components/src/components/tooltip/tooltip.lit…
mfranzke Apr 3, 2024
098af1d
fix: issue with angular tooltip typescript
nmerget Apr 3, 2024
848dd89
Update packages/components/src/components/tooltip/tooltip.lite.tsx
mfranzke Apr 3, 2024
90bf391
refactor: simplifications
mfranzke Apr 3, 2024
710ea13
Merge branch 'main' into feat-new-popover
mfranzke Apr 3, 2024
eb4b25f
Revert "refactor: simplifications"
mfranzke Apr 3, 2024
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion packages/components/scripts/post-build/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ const getComponents = () => [
},

{
name: 'popover'
name: 'popover',
overwrites: { angular: [{ from: 'mouseEnter', to: 'mouseenter' }] }
},

{
Expand Down
7 changes: 7 additions & 0 deletions packages/components/scripts/post-build/copy-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ module.exports = () => {
`./src/components/${name}/${name}.spec.tsx`,
`../../output/${resolvedFramework}/src/components/${name}/${name}.spec.tsx`
);
if (framework === 'vue') {
Replace({
files: `../../output/${resolvedFramework}/src/components/${name}/${name}.spec.tsx`,
from: ['{/*', '*/}'],
to: ''
});
}
}
Fse.copySync(
`./test/playwright/boilerplate`,
Expand Down
9 changes: 5 additions & 4 deletions packages/components/src/components/popover/docs/Angular.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import { DBPopover } from '@db-ui/ngx-components';

```html app.component.html
<!-- app.component.html -->
<db-button describedbyid="popover-01">
Hover on me to open Popover
<db-popover id="popover-01">Popover</db-popover>
</db-button>
<db-popover>
<db-button trigger> Hover on me to open Popover </db-button>
Use any html code here like e.g. a <code>button</code>:
<button type="button">Test</button>
</db-popover>
```
13 changes: 9 additions & 4 deletions packages/components/src/components/popover/docs/HTML.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ For general installation and configuration take a look at the [components](https
<!-- index.html -->
...
<body>
<button class="db-button" aria-describedby="popover-01">
Hover on me to open Popover
<i class="db-popover" id="popover-01">Popover</i>
</button>
<div class="db-popover">
<button aria-haspopup="true" class="db-button" type="button">
Hover on me to open Popover
</button>
<article class="db-popover-content">
Use any html code here like e.g. a <code>button</code>:
<button type="button">Test</button>
</article>
</div>
</body>
```
8 changes: 4 additions & 4 deletions packages/components/src/components/popover/docs/React.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ For general installation and configuration take a look at the [react-components]
import { DBPopover, DBButton } from "@db-ui/react-components";

const App = () => (
<DBButton describedbyid="popover-01">
Hover on me to open Popover
<DBPopover id="popover-01">Popover</DBPopover>
</DBButton>
<DBPopover slotTrigger={<DBButton>Hover on me to open Popover</DBButton>}>
Use any html code here like e.g. a <code>button</code>:
<button type="button">Test</button>
</DBPopover>
);

export default App;
Expand Down
11 changes: 7 additions & 4 deletions packages/components/src/components/popover/docs/Vue.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import { DBPopover, DBButton } from "@db-ui/v-components";
</script>

<template>
<DBButton describedbyid="popover-01">
Hover on me to open Popover
<DBPopover id="popover-01">Popover</DBPopover>
</DBButton>
<DBPopover>
<template v-slot:trigger>
<DBButton> Hover on me to open Popover </DBButton>
</template>
Use any html code here like e.g. a <code>button</code>:
<button type="button">Test</button>
</DBPopover>
</template>
```
10 changes: 9 additions & 1 deletion packages/components/src/components/popover/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import {
GapProps,
GlobalProps,
GlobalState,
InitializedState,
PlacementProps,
PopoverProps,
PopoverState,
SpacingProps
} from '../../shared/model';

Expand All @@ -13,6 +15,11 @@ export interface DBPopoverDefaultProps {
* Use open to disable the default hover/focus behaviour to use it on click or other trigger.
*/
open?: boolean;

/**
* The trigger to open the popover e.g. a button
*/
slotTrigger?: any;
}

export type DBPopoverProps = DBPopoverDefaultProps &
Expand All @@ -26,4 +33,5 @@ export interface DBPopoverDefaultState {}

export type DBPopoverState = DBPopoverDefaultState &
GlobalState &
ClickEventState<HTMLElement>;
PopoverState &
InitializedState;
63 changes: 45 additions & 18 deletions packages/components/src/components/popover/popover.lite.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { useMetadata, useRef, useStore } from '@builder.io/mitosis';
import {
onMount,
onUpdate,
Slot,
useMetadata,
useRef,
useStore
} from '@builder.io/mitosis';
import { DBPopoverProps, DBPopoverState } from './model';
import { cls } from '../../utils';
import { ClickEvent } from '../../shared/model';
import { cls, handleDataOutside } from '../../utils';

useMetadata({
isAttachedToShadowDom: true
Expand All @@ -11,29 +17,50 @@ export default function DBPopover(props: DBPopoverProps) {
const ref = useRef<HTMLDivElement>(null);
// jscpd:ignore-start
const state = useStore<DBPopoverState>({
handleClick: (event: ClickEvent<HTMLElement>) => {
event.stopPropagation();
initialized: false,
handleAutoPlacement: () => {
if (!ref) return;
const article = ref.querySelector('article');
if (!article) return;
handleDataOutside(article);
}
});

onMount(() => {
state.initialized = true;
});

onUpdate(() => {
if (ref && state.initialized) {
const children: Element[] = Array.from(ref.children);
if (children.length >= 2) {
children[0].ariaHasPopup = 'true';
}
state.initialized = false;
}
}, [ref, state.initialized]);

// jscpd:ignore-end

return (
<i
<div
ref={ref}
id={props.id}
class={cls('db-popover', props.className)}
data-spacing={props.spacing}
data-gap={props.gap}
data-animation={props.animation}
data-open={props.open}
data-delay={props.delay}
data-width={props.width}
data-placement={props.placement}
onClick={(event: ClickEvent<HTMLElement>) =>
state.handleClick(event)
}>
{props.children}
</i>
onFocus={() => state.handleAutoPlacement()}
onMouseEnter={() => state.handleAutoPlacement()}>
<Slot name="trigger" />
<article
class="db-popover-content"
data-spacing={props.spacing}
data-gap={props.gap}
data-animation={props.animation}
data-open={props.open}
data-delay={props.delay}
data-width={props.width}
data-placement={props.placement}>
{props.children}
</article>
</div>
);
}
36 changes: 24 additions & 12 deletions packages/components/src/components/popover/popover.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,34 @@
@use "../../styles/popover-component";

.db-popover {
@extend %default-popover;
position: relative;

&,
&[data-spacing="small"] {
padding: variables.$db-spacing-fixed-sm;
&:hover,
&:focus-within {
& > article {
@extend %show-popover;
}
}

&[data-spacing="medium"] {
padding: variables.$db-spacing-fixed-md;
}
& > article {
@extend %popover-center;
@extend %default-popover;

&[data-spacing="none"] {
padding: 0;
}
&,
&[data-spacing="small"] {
padding: variables.$db-spacing-fixed-sm;
}

&[data-spacing="medium"] {
padding: variables.$db-spacing-fixed-md;
}

&[data-spacing="none"] {
padding: 0;
}

&[data-open="true"] {
@extend %show-popover;
&[data-open="true"] {
@extend %show-popover;
}
}
}
28 changes: 23 additions & 5 deletions packages/components/src/components/popover/popover.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ import { DBPopover } from './index';
import { DEFAULT_VIEWPORT } from '../../shared/constants.ts';
import { DBButton } from '../button';

const comp = (
<DBButton describedbyid="popover-01">
Button
<DBPopover open={true} animation="disabled" id="popover-01">
// template v-slot is used for vue component tests
const comp: any = (
<div className="padding-box">
<DBPopover
animation="disabled"
data-testid="popover"
slotTrigger={<DBButton data-testid="button">Button</DBButton>}>
{/*<template v-slot:trigger>
<DBButton data-testid="button">Button</DBButton>
</template>*/}
mfranzke marked this conversation as resolved.
Show resolved Hide resolved
Test
</DBPopover>
</DBButton>
</div>
);

const testComponent = () => {
Expand All @@ -25,6 +31,18 @@ const testComponent = () => {
const component = await mount(comp);
await expect(component).toHaveScreenshot();
});

test('should open', async ({ mount }) => {
const component = await mount(comp);
await component.getByTestId('button').focus();
await expect(component.getByTestId('popover')).toBeVisible();
});

test('after open should match screenshot', async ({ mount }) => {
const component = await mount(comp);
await component.getByTestId('button').focus();
await expect(component).toHaveScreenshot();
});
};

test.describe('DBPopover', () => {
Expand Down
8 changes: 6 additions & 2 deletions packages/components/src/components/tooltip/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import {
EmphasisProps,
GlobalProps,
GlobalState,
InitializedState,
PlacementProps,
PopoverProps
PopoverProps,
PopoverState
} from '../../shared/model';

export interface DBTooltipDefaultProps {
Expand All @@ -21,4 +23,6 @@ export interface DBTooltipDefaultState {}

export type DBTooltipState = DBTooltipDefaultState &
GlobalState &
ClickEventState<HTMLElement>;
ClickEventState<HTMLElement> &
PopoverState &
InitializedState;
34 changes: 32 additions & 2 deletions packages/components/src/components/tooltip/tooltip.lite.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { useMetadata, useRef, useStore } from '@builder.io/mitosis';
import {
onMount,
onUpdate,
useMetadata,
useRef,
useStore
} from '@builder.io/mitosis';
import { DBTooltipProps, DBTooltipState } from './model';
import { cls } from '../../utils';
import { cls, handleDataOutside } from '../../utils';
import { ClickEvent } from '../../shared/model';

useMetadata({
Expand All @@ -11,10 +17,34 @@ export default function DBTooltip(props: DBTooltipProps) {
const ref = useRef<HTMLDivElement>(null);
// jscpd:ignore-start
const state = useStore<DBTooltipState>({
initialized: false,
handleClick: (event: ClickEvent<HTMLElement>) => {
event.stopPropagation();
},
handleAutoPlacement: () => {
if (ref) handleDataOutside(ref);
}
});

onMount(() => {
state.initialized = true;
});

onUpdate(() => {
if (ref && state.initialized) {
const parent = ref.parentElement;
if (parent) {
['mouseenter', 'focus'].forEach((event) => {
parent.addEventListener(event, () =>
state.handleAutoPlacement()
);
});
}

state.initialized = false;
}
}, [ref, state.initialized]);

// jscpd:ignore-end

// TODO: Shall we check if only <span>, <p> or direct text was passed as children?
Expand Down
Loading
Loading