Skip to content

Commit 8bc0ac3

Browse files
committed
✨ Add Popover component
1 parent 2a5e7eb commit 8bc0ac3

File tree

9 files changed

+578
-1
lines changed

9 files changed

+578
-1
lines changed

src/components/Modal/modal.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.modal {
44
@include transition();
55
@include position(fixed, 't50%', 'l50%');
6-
@include spacing(0, p-default);
6+
@include spacing(m0, p-default);
77
@include layer(modal);
88
@include visibility(block, 0);
99
@include border(primary-50);

src/components/Popover/Popover.astro

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
import type { PopoverProps } from './popover'
3+
import styles from './popover.module.scss'
4+
5+
interface Props extends PopoverProps {}
6+
7+
const {
8+
id,
9+
className
10+
} = Astro.props
11+
12+
const classes = [
13+
styles.popover,
14+
className
15+
]
16+
---
17+
18+
<dialog
19+
class:list={classes}
20+
id={id}
21+
>
22+
<slot />
23+
</dialog>

src/components/Popover/Popover.svelte

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script lang="ts">
2+
import type { PopoverProps } from './popover'
3+
4+
import styles from './popover.module.scss'
5+
import { classNames } from '../../utils/classNames'
6+
7+
export let id: PopoverProps['id'] = ''
8+
export let className: PopoverProps['className'] = ''
9+
10+
const classes = classNames([
11+
styles.popover,
12+
className
13+
])
14+
</script>
15+
16+
<dialog
17+
class={classes}
18+
id={id}
19+
>
20+
<slot />
21+
</dialog>

src/components/Popover/Popover.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react'
2+
import type { ReactPopoverProps } from './popover'
3+
4+
import styles from './popover.module.scss'
5+
import { classNames } from '../../utils/classNames'
6+
7+
const Popover = ({
8+
id,
9+
className,
10+
children
11+
}: ReactPopoverProps) => {
12+
const classes = classNames([
13+
styles.popover,
14+
className
15+
])
16+
17+
return (
18+
<dialog
19+
className={classes}
20+
id={id}
21+
>
22+
{children}
23+
</dialog>
24+
)
25+
}
26+
27+
export default Popover
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
@import '../../scss/config.scss';
2+
3+
.popover {
4+
@include spacing(m0, p-default);
5+
@include layer(modal);
6+
@include visibility(block, 0);
7+
@include border(primary-50);
8+
@include background(primary-70);
9+
@include typography(primary);
10+
@include border-radius(md);
11+
@include size(w300px);
12+
13+
transform: translateY(-5px);
14+
pointer-events: none;
15+
16+
&[data-show] {
17+
@include transition();
18+
}
19+
20+
&[data-show="true"] {
21+
@include visibility(1);
22+
23+
transform: translateY(0);
24+
pointer-events: all;
25+
}
26+
27+
&[data-position="top"] {
28+
transform: translateY(5px);
29+
30+
&[data-show="true"] {
31+
transform: translate(0);
32+
}
33+
}
34+
35+
&[data-position="left"] {
36+
transform: translateY(0) translateX(5px);
37+
38+
&[data-show="true"] {
39+
transform: translate(0);
40+
}
41+
}
42+
43+
44+
&[data-position="right"] {
45+
transform: translateY(0) translateX(-5px);
46+
47+
&[data-show="true"] {
48+
transform: translate(0);
49+
}
50+
}
51+
}

src/components/Popover/popover.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export type PopoverProps = {
2+
id?: string
3+
className?: string
4+
}
5+
6+
export type ReactPopoverProps = {
7+
children?: React.ReactNode
8+
} & PopoverProps

src/pages/index.astro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ const tabItems = [{
149149
<CardWrapper title="Modal" href="/modal">
150150
<Button theme="outline">Trigger Modal</Button>
151151
</CardWrapper>
152+
<CardWrapper title="Popover" href="/popover">
153+
<Button theme="outline">Open Popover</Button>
154+
</CardWrapper>
152155
<CardWrapper title="Progress" href="/progress">
153156
<Progress value={33} />
154157
</CardWrapper>

0 commit comments

Comments
 (0)