webcoreui 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -1
- package/astro.d.ts +12 -0
- package/astro.js +12 -0
- package/components/Accordion/accordion.module.scss +1 -2
- package/components/Alert/Alert.tsx +4 -1
- package/components/Alert/alert.module.scss +3 -3
- package/components/Avatar/avatar.module.scss +2 -0
- package/components/Badge/badge.module.scss +1 -1
- package/components/Button/button.module.scss +2 -2
- package/components/Button/button.ts +1 -1
- package/components/Card/card.module.scss +0 -1
- package/components/Checkbox/checkbox.module.scss +4 -4
- package/components/Collapsible/Collapsible.astro +63 -0
- package/components/Collapsible/Collapsible.svelte +48 -0
- package/components/Collapsible/Collapsible.tsx +54 -0
- package/components/Collapsible/collapsible.module.scss +29 -0
- package/components/Collapsible/collapsible.ts +14 -0
- package/components/Icon/map.ts +2 -0
- package/components/Input/input.module.scss +2 -2
- package/components/Menu/Menu.astro +7 -3
- package/components/Menu/Menu.svelte +11 -3
- package/components/Menu/Menu.tsx +7 -1
- package/components/Menu/menu.module.scss +4 -1
- package/components/Menu/menu.ts +1 -0
- package/components/Modal/Modal.astro +70 -0
- package/components/Modal/Modal.svelte +71 -0
- package/components/Modal/Modal.tsx +76 -0
- package/components/Modal/modal.module.scss +103 -0
- package/components/Modal/modal.ts +18 -0
- package/components/Popover/Popover.astro +23 -0
- package/components/Popover/Popover.svelte +21 -0
- package/components/Popover/Popover.tsx +27 -0
- package/components/Popover/popover.module.scss +51 -0
- package/components/Popover/popover.ts +8 -0
- package/components/Progress/progress.module.scss +3 -3
- package/components/Radio/radio.module.scss +1 -2
- package/components/Rating/Rating.astro +2 -2
- package/components/Rating/Rating.svelte +2 -2
- package/components/Rating/Rating.tsx +2 -2
- package/components/Rating/rating.module.scss +1 -1
- package/components/Sheet/Sheet.astro +29 -0
- package/components/Sheet/Sheet.svelte +24 -0
- package/components/Sheet/Sheet.tsx +32 -0
- package/components/Sheet/sheet.module.scss +68 -0
- package/components/Sheet/sheet.ts +10 -0
- package/components/Slider/Slider.astro +44 -0
- package/components/Slider/Slider.svelte +42 -0
- package/components/Slider/Slider.tsx +48 -0
- package/components/Slider/slider.module.scss +68 -0
- package/components/Slider/slider.ts +20 -0
- package/components/Switch/switch.module.scss +1 -1
- package/components/Table/Table.astro +6 -1
- package/components/Table/Table.svelte +3 -1
- package/components/Table/Table.tsx +7 -1
- package/components/Table/table.module.scss +11 -1
- package/components/Table/table.ts +1 -0
- package/components/Tabs/tabs.module.scss +6 -1
- package/components/Textarea/Textarea.astro +44 -0
- package/components/Textarea/Textarea.svelte +45 -0
- package/components/Textarea/Textarea.tsx +50 -0
- package/components/Textarea/textarea.module.scss +36 -0
- package/components/Textarea/textarea.ts +18 -0
- package/components/ThemeSwitcher/ThemeSwitcher.astro +1 -0
- package/components/ThemeSwitcher/ThemeSwitcher.svelte +2 -1
- package/components/ThemeSwitcher/ThemeSwitcher.tsx +2 -1
- package/components/Timeline/timeline.module.scss +4 -4
- package/components/TimelineItem/TimelineItem.tsx +1 -6
- package/components/TimelineItem/timelineitem.module.scss +2 -3
- package/components/TimelineItem/timelineitem.ts +5 -0
- package/components/Toast/Toast.svelte +11 -6
- package/icons/close.svg +3 -0
- package/icons.d.ts +1 -0
- package/icons.js +1 -0
- package/index.d.ts +69 -0
- package/index.js +4 -0
- package/package.json +2 -1
- package/react.d.ts +14 -2
- package/react.js +12 -0
- package/scss/config/color-palette.scss +1 -0
- package/scss/config/mixins.scss +152 -155
- package/scss/config/typography.scss +8 -9
- package/scss/global/theme.scss +71 -38
- package/scss/global/tooltip.scss +5 -3
- package/scss/global/utility.scss +76 -58
- package/scss/resets.scss +10 -5
- package/scss/setup.scss +2 -2
- package/svelte.d.ts +12 -0
- package/svelte.js +12 -0
- package/utils/debounce.ts +24 -0
- package/utils/interpolate.ts +23 -0
- package/utils/modal.ts +59 -0
- package/utils/popover.ts +201 -0
- package/utils/toast.ts +0 -6
package/scss/global/utility.scss
CHANGED
|
@@ -1,88 +1,106 @@
|
|
|
1
|
+
@use 'sass:string';
|
|
2
|
+
@use 'sass:meta';
|
|
3
|
+
@use 'sass:list';
|
|
4
|
+
@use 'sass:map';
|
|
1
5
|
@use '../config' as *;
|
|
2
6
|
|
|
7
|
+
$breakpointMap: (
|
|
8
|
+
'xs': 3,
|
|
9
|
+
'sm': 4,
|
|
10
|
+
'md': 6,
|
|
11
|
+
'lg': 8
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
$alignments: (
|
|
15
|
+
'items-center': center,
|
|
16
|
+
'items-start': flex-start,
|
|
17
|
+
'items-end': flex-end,
|
|
18
|
+
'items-baseline': baseline,
|
|
19
|
+
'items-stretch': stretch,
|
|
20
|
+
|
|
21
|
+
'justify-center': center,
|
|
22
|
+
'justify-start': flex-start,
|
|
23
|
+
'justify-end': flex-end,
|
|
24
|
+
'justify-between': space-between,
|
|
25
|
+
'justify-around': space-around,
|
|
26
|
+
'justify-evenly': space-evenly,
|
|
27
|
+
'justify-stretch': stretch
|
|
28
|
+
);
|
|
29
|
+
|
|
3
30
|
@mixin utility() {
|
|
4
31
|
.container {
|
|
5
|
-
|
|
32
|
+
@include spacing(auto-none, px-default);
|
|
6
33
|
max-width: 1200px;
|
|
7
|
-
padding: 0 20px;
|
|
8
34
|
}
|
|
9
35
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
36
|
+
// Gaps
|
|
37
|
+
.flex, .grid {
|
|
38
|
+
@each $key, $value in $spacing {
|
|
39
|
+
$numberList: ('2', '3', '4', '5');
|
|
40
|
+
$firstLetter: string.slice($key, 1, 1);
|
|
41
|
+
$class: $key;
|
|
42
|
+
|
|
43
|
+
@if (list.index($numberList, $firstLetter)) {
|
|
44
|
+
$class: string.slice($key, 2, -1) + $firstLetter;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
&.#{$class} { gap: $value; }
|
|
16
48
|
}
|
|
17
49
|
}
|
|
18
50
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
&.xs {
|
|
28
|
-
gap: 5px;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
&.sm {
|
|
32
|
-
gap: 10px;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
&.wrap {
|
|
36
|
-
flex-wrap: wrap;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
&.center {
|
|
40
|
-
justify-content: center;
|
|
41
|
-
align-items: center;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
&.justify-center {
|
|
45
|
-
justify-content: center;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
&.items-center {
|
|
49
|
-
align-items: center;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
&.items-start {
|
|
53
|
-
align-items: flex-start;
|
|
51
|
+
// Alignments
|
|
52
|
+
@each $key, $value in $alignments {
|
|
53
|
+
.#{$key} {
|
|
54
|
+
@if (string.index($key, 'items')) {
|
|
55
|
+
align-items: $value;
|
|
56
|
+
} @else {
|
|
57
|
+
justify-content: $value;
|
|
58
|
+
}
|
|
54
59
|
}
|
|
55
60
|
}
|
|
56
61
|
|
|
57
|
-
.
|
|
58
|
-
|
|
62
|
+
.flex.center,
|
|
63
|
+
.grid.center {
|
|
64
|
+
justify-content: center;
|
|
65
|
+
align-items: center;
|
|
59
66
|
}
|
|
60
67
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
64
|
-
}
|
|
68
|
+
.flex {
|
|
69
|
+
@include layout(flex, default);
|
|
65
70
|
|
|
66
|
-
|
|
67
|
-
|
|
71
|
+
@each $direction in $flexDirectionValues {
|
|
72
|
+
&.#{$direction} {
|
|
73
|
+
flex-direction: $direction;
|
|
74
|
+
}
|
|
68
75
|
}
|
|
69
76
|
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
@each $wrap in $flexWrapValues {
|
|
78
|
+
&.#{$wrap} {
|
|
79
|
+
flex-wrap: $wrap;
|
|
80
|
+
}
|
|
72
81
|
}
|
|
73
82
|
}
|
|
74
83
|
|
|
75
|
-
|
|
76
|
-
|
|
84
|
+
.grid {
|
|
85
|
+
@include layout(grid, default);
|
|
86
|
+
|
|
87
|
+
&.col-2 {
|
|
77
88
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
78
89
|
}
|
|
79
90
|
|
|
80
|
-
|
|
91
|
+
&.col-3 {
|
|
81
92
|
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
82
93
|
}
|
|
94
|
+
}
|
|
83
95
|
|
|
84
|
-
|
|
85
|
-
|
|
96
|
+
// Grid columns
|
|
97
|
+
@each $key, $value in $breakpoints {
|
|
98
|
+
@include media($key) {
|
|
99
|
+
@for $i from 2 to map.get($breakpointMap, $key) + 1 {
|
|
100
|
+
.grid.#{$key}-#{$i} {
|
|
101
|
+
grid-template-columns: repeat($i, minmax(0, 1fr));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
86
104
|
}
|
|
87
105
|
}
|
|
88
106
|
}
|
package/scss/resets.scss
CHANGED
|
@@ -53,11 +53,11 @@
|
|
|
53
53
|
pre {
|
|
54
54
|
@include border(primary-50);
|
|
55
55
|
@include border-radius(md);
|
|
56
|
-
@include typography(
|
|
56
|
+
@include typography(md);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
code {
|
|
60
|
-
@include spacing(
|
|
60
|
+
@include spacing(px-sm);
|
|
61
61
|
display: inline-block;
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
figcaption {
|
|
76
|
-
@include typography(
|
|
76
|
+
@include typography(md, primary-20);
|
|
77
77
|
|
|
78
78
|
a {
|
|
79
79
|
@include typography(primary-20);
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
p, ul, ol {
|
|
88
|
-
@include typography(
|
|
88
|
+
@include typography(hlg);
|
|
89
89
|
@include spacing(my-default);
|
|
90
90
|
}
|
|
91
91
|
|
|
@@ -94,8 +94,13 @@
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
blockquote {
|
|
97
|
-
@include typography(md);
|
|
98
97
|
@include spacing(my-default, mx-none, pl-default);
|
|
99
98
|
@include border(2px, left, primary-30);
|
|
100
99
|
}
|
|
100
|
+
|
|
101
|
+
hr {
|
|
102
|
+
@include size('w100%', h1px);
|
|
103
|
+
@include border(0);
|
|
104
|
+
@include background(primary-50);
|
|
105
|
+
}
|
|
101
106
|
}
|
package/scss/setup.scss
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
$config: (
|
|
4
4
|
includeResets: true,
|
|
5
|
-
|
|
5
|
+
includeUtilities: true,
|
|
6
6
|
includeTooltip: true,
|
|
7
7
|
includeScrollbarStyles: true
|
|
8
8
|
);
|
|
@@ -25,7 +25,7 @@ body {
|
|
|
25
25
|
@include resets();
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
@if (config('
|
|
28
|
+
@if (config('includeUtilities')) {
|
|
29
29
|
@include utility();
|
|
30
30
|
}
|
|
31
31
|
|
package/svelte.d.ts
CHANGED
|
@@ -5,17 +5,23 @@ import type { SvelteBadgeProps } from './components/Badge/badge'
|
|
|
5
5
|
import type { SvelteButtonProps } from './components/Button/button'
|
|
6
6
|
import type { CardProps } from './components/Card/card'
|
|
7
7
|
import type { SvelteCheckboxProps } from './components/Checkbox/checkbox'
|
|
8
|
+
import type { CollapsibleProps } from './components/Collapsible/collapsible'
|
|
8
9
|
import type { ConditionalWrapperProps } from './components/ConditionalWrapper/conditionalwrapper'
|
|
9
10
|
import type { IconProps } from './components/Icon/icon'
|
|
10
11
|
import type { SvelteInputProps } from './components/Input/input'
|
|
11
12
|
import type { MenuProps } from './components/Menu/menu'
|
|
13
|
+
import type { ModalProps } from './components/Modal/modal'
|
|
14
|
+
import type { PopoverProps } from './components/Popover/popover'
|
|
12
15
|
import type { ProgressProps } from './components/Progress/progress'
|
|
13
16
|
import type { SvelteRadioProps } from './components/Radio/radio'
|
|
14
17
|
import type { RatingProps } from './components/Rating/rating'
|
|
18
|
+
import type { SheetProps } from './components/Sheet/sheet'
|
|
19
|
+
import type { SvelteSliderProps } from './components/Slider/slider'
|
|
15
20
|
import type { SpinnerProps } from './components/Spinner/spinner'
|
|
16
21
|
import type { SvelteSwitchProps } from './components/Switch/switch'
|
|
17
22
|
import type { TableProps } from './components/Table/table'
|
|
18
23
|
import type { TabsProps } from './components/Tabs/tabs'
|
|
24
|
+
import type { SvelteTextareaProps } from './components/Textarea/textarea'
|
|
19
25
|
import type { ThemeSwitcherProps } from './components/ThemeSwitcher/themeswitcher'
|
|
20
26
|
import type { TimelineProps } from './components/Timeline/timeline'
|
|
21
27
|
import type { TimelineItemProps } from './components/TimelineItem/timelineitem'
|
|
@@ -29,17 +35,23 @@ declare module 'webcoreui/svelte' {
|
|
|
29
35
|
export function Button(_props: SvelteButtonProps): any
|
|
30
36
|
export function Card(_props: CardProps): any
|
|
31
37
|
export function Checkbox(_props: SvelteCheckboxProps): any
|
|
38
|
+
export function Collapsible(_props: CollapsibleProps): any
|
|
32
39
|
export function ConditionalWrapper(_props: ConditionalWrapperProps): any
|
|
33
40
|
export function Icon(_props: IconProps): any
|
|
34
41
|
export function Input(_props: SvelteInputProps): any
|
|
35
42
|
export function Menu(_props: MenuProps): any
|
|
43
|
+
export function Modal(_props: ModalProps): any
|
|
44
|
+
export function Popover(_props: PopoverProps): any
|
|
36
45
|
export function Progress(_props: ProgressProps): any
|
|
37
46
|
export function Radio(_props: SvelteRadioProps): any
|
|
38
47
|
export function Rating(_props: RatingProps): any
|
|
48
|
+
export function Sheet(_props: SheetProps): any
|
|
49
|
+
export function Slider(_props: SvelteSliderProps): any
|
|
39
50
|
export function Spinner(_props: SpinnerProps): any
|
|
40
51
|
export function Switch(_props: SvelteSwitchProps): any
|
|
41
52
|
export function Table(_props: TableProps): any
|
|
42
53
|
export function Tabs(_props: TabsProps): any
|
|
54
|
+
export function Textarea(_props: SvelteTextareaProps): any
|
|
43
55
|
export function ThemeSwitcher(_props: ThemeSwitcherProps): any
|
|
44
56
|
export function Timeline(_props: TimelineProps): any
|
|
45
57
|
export function TimelineItem(_props: TimelineItemProps): any
|
package/svelte.js
CHANGED
|
@@ -5,17 +5,23 @@ import BadgeComponent from './components/Badge/Badge.svelte'
|
|
|
5
5
|
import ButtonComponent from './components/Button/Button.svelte'
|
|
6
6
|
import CardComponent from './components/Card/Card.svelte'
|
|
7
7
|
import CheckboxComponent from './components/Checkbox/Checkbox.svelte'
|
|
8
|
+
import CollapsibleComponent from './components/Collapsible/Collapsible.svelte'
|
|
8
9
|
import ConditionalWrapperComponent from './components/ConditionalWrapper/ConditionalWrapper.svelte'
|
|
9
10
|
import IconComponent from './components/Icon/Icon.svelte'
|
|
10
11
|
import InputComponent from './components/Input/Input.svelte'
|
|
11
12
|
import MenuComponent from './components/Menu/Menu.svelte'
|
|
13
|
+
import ModalComponent from './components/Modal/Modal.svelte'
|
|
14
|
+
import PopoverComponent from './components/Popover/Popover.svelte'
|
|
12
15
|
import ProgressComponent from './components/Progress/Progress.svelte'
|
|
13
16
|
import RadioComponent from './components/Radio/Radio.svelte'
|
|
14
17
|
import RatingComponent from './components/Rating/Rating.svelte'
|
|
18
|
+
import SheetComponent from './components/Sheet/Sheet.svelte'
|
|
19
|
+
import SliderComponent from './components/Slider/Slider.svelte'
|
|
15
20
|
import SpinnerComponent from './components/Spinner/Spinner.svelte'
|
|
16
21
|
import SwitchComponent from './components/Switch/Switch.svelte'
|
|
17
22
|
import TableComponent from './components/Table/Table.svelte'
|
|
18
23
|
import TabsComponent from './components/Tabs/Tabs.svelte'
|
|
24
|
+
import TextareaComponent from './components/Textarea/Textarea.svelte'
|
|
19
25
|
import ThemeSwitcherComponent from './components/ThemeSwitcher/ThemeSwitcher.svelte'
|
|
20
26
|
import TimelineComponent from './components/Timeline/Timeline.svelte'
|
|
21
27
|
import TimelineItemComponent from './components/TimelineItem/TimelineItem.svelte'
|
|
@@ -28,17 +34,23 @@ export const Badge = BadgeComponent
|
|
|
28
34
|
export const Button = ButtonComponent
|
|
29
35
|
export const Card = CardComponent
|
|
30
36
|
export const Checkbox = CheckboxComponent
|
|
37
|
+
export const Collapsible = CollapsibleComponent
|
|
31
38
|
export const ConditionalWrapper = ConditionalWrapperComponent
|
|
32
39
|
export const Icon = IconComponent
|
|
33
40
|
export const Input = InputComponent
|
|
34
41
|
export const Menu = MenuComponent
|
|
42
|
+
export const Modal = ModalComponent
|
|
43
|
+
export const Popover = PopoverComponent
|
|
35
44
|
export const Progress = ProgressComponent
|
|
36
45
|
export const Radio = RadioComponent
|
|
37
46
|
export const Rating = RatingComponent
|
|
47
|
+
export const Sheet = SheetComponent
|
|
48
|
+
export const Slider = SliderComponent
|
|
38
49
|
export const Spinner = SpinnerComponent
|
|
39
50
|
export const Switch = SwitchComponent
|
|
40
51
|
export const Table = TableComponent
|
|
41
52
|
export const Tabs = TabsComponent
|
|
53
|
+
export const Textarea = TextareaComponent
|
|
42
54
|
export const ThemeSwitcher = ThemeSwitcherComponent
|
|
43
55
|
export const Timeline = TimelineComponent
|
|
44
56
|
export const TimelineItem = TimelineItemComponent
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const debounce = (fn: any, waitFor = 100) => {
|
|
2
|
+
let timeout: ReturnType<typeof setTimeout> | null
|
|
3
|
+
|
|
4
|
+
const clear = () => {
|
|
5
|
+
if (timeout !== null) {
|
|
6
|
+
clearTimeout(timeout)
|
|
7
|
+
timeout = null
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const debouncedFn = (...args: any[]) => {
|
|
12
|
+
clear()
|
|
13
|
+
|
|
14
|
+
timeout = setTimeout(() => {
|
|
15
|
+
fn(...args)
|
|
16
|
+
}, waitFor)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
debouncedFn.cancel = () => {
|
|
20
|
+
clear()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return debouncedFn
|
|
24
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const clamp = (
|
|
2
|
+
num: number,
|
|
3
|
+
min: number,
|
|
4
|
+
max: number
|
|
5
|
+
) => Math.min(Math.max(num, min), max)
|
|
6
|
+
|
|
7
|
+
export const lerp = (
|
|
8
|
+
x: number,
|
|
9
|
+
y: number,
|
|
10
|
+
z: number
|
|
11
|
+
) => x * (1 - z) + y * z
|
|
12
|
+
|
|
13
|
+
export const invlerp = (
|
|
14
|
+
x: number,
|
|
15
|
+
y: number,
|
|
16
|
+
z: number
|
|
17
|
+
) => clamp((z - x) / (y - x), 0, 1)
|
|
18
|
+
|
|
19
|
+
export const interpolate = (
|
|
20
|
+
value: number,
|
|
21
|
+
input: [x: number, y: number],
|
|
22
|
+
output: [x: number, y: number],
|
|
23
|
+
) => lerp(output[0], output[1], invlerp(input[0], input[1], value))
|
package/utils/modal.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export const modal = (element: string) => {
|
|
2
|
+
const htmlElement = document.querySelector(element) as HTMLElement
|
|
3
|
+
|
|
4
|
+
if (htmlElement) {
|
|
5
|
+
const handleClose = {
|
|
6
|
+
icon: () => {
|
|
7
|
+
const close = htmlElement.querySelector('[data-id="close"]')
|
|
8
|
+
|
|
9
|
+
const listener = () => {
|
|
10
|
+
htmlElement.dataset.show = ''
|
|
11
|
+
|
|
12
|
+
close?.removeEventListener('click', listener)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
close?.addEventListener('click', listener)
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
esc: () => {
|
|
19
|
+
const listener = (event: KeyboardEvent) => {
|
|
20
|
+
if (event.key === 'Escape') {
|
|
21
|
+
htmlElement.dataset.show = ''
|
|
22
|
+
|
|
23
|
+
document.removeEventListener('keydown', listener)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
document.addEventListener('keydown', listener)
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
overlay: () => {
|
|
31
|
+
const close = htmlElement.nextElementSibling
|
|
32
|
+
|
|
33
|
+
const listener = () => {
|
|
34
|
+
htmlElement.dataset.show = ''
|
|
35
|
+
|
|
36
|
+
close?.removeEventListener('click', listener)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
close?.addEventListener('click', listener)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const closeOptions = htmlElement.dataset.close?.split(',')
|
|
44
|
+
|
|
45
|
+
htmlElement.dataset.show = 'true'
|
|
46
|
+
|
|
47
|
+
closeOptions?.forEach(option => {
|
|
48
|
+
handleClose[option as keyof typeof handleClose]()
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const closeModal = (element: string) => {
|
|
54
|
+
const htmlElement = document.querySelector(element) as HTMLElement
|
|
55
|
+
|
|
56
|
+
if (htmlElement) {
|
|
57
|
+
htmlElement.dataset.show = ''
|
|
58
|
+
}
|
|
59
|
+
}
|
package/utils/popover.ts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { closeModal } from './modal'
|
|
2
|
+
import { debounce } from './debounce'
|
|
3
|
+
|
|
4
|
+
type PopoverPosition = 'top'
|
|
5
|
+
| 'top-start'
|
|
6
|
+
| 'top-end'
|
|
7
|
+
| 'left'
|
|
8
|
+
| 'left-start'
|
|
9
|
+
| 'left-end'
|
|
10
|
+
| 'right'
|
|
11
|
+
| 'right-start'
|
|
12
|
+
| 'right-end'
|
|
13
|
+
| 'bottom'
|
|
14
|
+
| 'bottom-start'
|
|
15
|
+
| 'bottom-end'
|
|
16
|
+
|
|
17
|
+
type Popover = {
|
|
18
|
+
trigger: string
|
|
19
|
+
popover: string
|
|
20
|
+
position?: PopoverPosition
|
|
21
|
+
offset?: number
|
|
22
|
+
closeOnBlur?: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const popover = ({
|
|
26
|
+
trigger,
|
|
27
|
+
popover,
|
|
28
|
+
position,
|
|
29
|
+
offset = 10,
|
|
30
|
+
closeOnBlur = true
|
|
31
|
+
}: Popover) => {
|
|
32
|
+
const triggerDOM = document.querySelector(trigger) as HTMLElement
|
|
33
|
+
const popoverDOM = document.querySelector(popover) as HTMLElement
|
|
34
|
+
|
|
35
|
+
if (triggerDOM && popover) {
|
|
36
|
+
document.body.appendChild(popoverDOM)
|
|
37
|
+
|
|
38
|
+
if (position) {
|
|
39
|
+
popoverDOM.dataset.position = position.split('-')[0]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const handleOpen = () => {
|
|
43
|
+
const triggerPosition = triggerDOM.getBoundingClientRect()
|
|
44
|
+
const popoverPosition = popoverDOM.getBoundingClientRect()
|
|
45
|
+
|
|
46
|
+
const topSide = triggerPosition.top
|
|
47
|
+
+ window.scrollY
|
|
48
|
+
- popoverPosition.height
|
|
49
|
+
- offset
|
|
50
|
+
|
|
51
|
+
const bottomSide = triggerPosition.top
|
|
52
|
+
+ window.scrollY
|
|
53
|
+
+ triggerPosition.height
|
|
54
|
+
+ offset
|
|
55
|
+
|
|
56
|
+
const leftSide = triggerPosition.left
|
|
57
|
+
- popoverPosition.width
|
|
58
|
+
- offset
|
|
59
|
+
|
|
60
|
+
const rightSide = triggerPosition.left
|
|
61
|
+
+ triggerPosition.width
|
|
62
|
+
+ offset
|
|
63
|
+
|
|
64
|
+
const hcenter = triggerPosition.left
|
|
65
|
+
- ((popoverPosition.width - triggerPosition.width) / 2)
|
|
66
|
+
|
|
67
|
+
const hEnd = triggerPosition.left
|
|
68
|
+
- (popoverPosition.width - triggerPosition.width)
|
|
69
|
+
|
|
70
|
+
const vcenter = triggerPosition.top
|
|
71
|
+
+ window.scrollY
|
|
72
|
+
- ((popoverPosition.height - triggerPosition.height) / 2)
|
|
73
|
+
|
|
74
|
+
const vStart = triggerPosition.top + window.scrollY
|
|
75
|
+
const vEnd = triggerPosition.top
|
|
76
|
+
+ window.scrollY
|
|
77
|
+
- (popoverPosition.height - triggerPosition.height)
|
|
78
|
+
|
|
79
|
+
const positions = {
|
|
80
|
+
'top-start': {
|
|
81
|
+
top: topSide,
|
|
82
|
+
left: triggerPosition.left
|
|
83
|
+
},
|
|
84
|
+
'top': {
|
|
85
|
+
top: topSide,
|
|
86
|
+
left: hcenter
|
|
87
|
+
},
|
|
88
|
+
'top-end': {
|
|
89
|
+
top: topSide,
|
|
90
|
+
left: hEnd
|
|
91
|
+
},
|
|
92
|
+
'left-start': {
|
|
93
|
+
top: vStart,
|
|
94
|
+
left: leftSide
|
|
95
|
+
},
|
|
96
|
+
'left': {
|
|
97
|
+
top: vcenter,
|
|
98
|
+
left: leftSide
|
|
99
|
+
},
|
|
100
|
+
'left-end': {
|
|
101
|
+
top: vEnd,
|
|
102
|
+
left: leftSide
|
|
103
|
+
},
|
|
104
|
+
'right-start': {
|
|
105
|
+
top: vStart,
|
|
106
|
+
left: rightSide
|
|
107
|
+
},
|
|
108
|
+
'right': {
|
|
109
|
+
top: vcenter,
|
|
110
|
+
left: rightSide
|
|
111
|
+
},
|
|
112
|
+
'right-end': {
|
|
113
|
+
top: vEnd,
|
|
114
|
+
left: rightSide
|
|
115
|
+
},
|
|
116
|
+
'bottom-start': {
|
|
117
|
+
top: bottomSide,
|
|
118
|
+
left: triggerPosition.left
|
|
119
|
+
},
|
|
120
|
+
'bottom': {
|
|
121
|
+
top: bottomSide,
|
|
122
|
+
left: hcenter
|
|
123
|
+
},
|
|
124
|
+
'bottom-end': {
|
|
125
|
+
top: bottomSide,
|
|
126
|
+
left: hEnd
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const { top, left } = positions[position as keyof typeof positions] || positions.bottom
|
|
131
|
+
|
|
132
|
+
popoverDOM.style.top = `${top}px`
|
|
133
|
+
popoverDOM.style.left = `${left}px`
|
|
134
|
+
|
|
135
|
+
setTimeout(() => {
|
|
136
|
+
popoverDOM.dataset.show = popoverDOM.dataset.show === 'true'
|
|
137
|
+
? ''
|
|
138
|
+
: 'true'
|
|
139
|
+
}, 0)
|
|
140
|
+
|
|
141
|
+
setTimeout(() => {
|
|
142
|
+
if (!popoverDOM.dataset.show) {
|
|
143
|
+
popoverDOM.removeAttribute('data-show')
|
|
144
|
+
}
|
|
145
|
+
}, 300)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const handleClose = (event: MouseEvent) => {
|
|
149
|
+
const target = event.target as HTMLElement
|
|
150
|
+
const hidePopover = !popoverDOM.contains(target)
|
|
151
|
+
&& !triggerDOM.contains(target)
|
|
152
|
+
&& popoverDOM.dataset.show
|
|
153
|
+
|
|
154
|
+
if (hidePopover) {
|
|
155
|
+
popoverDOM.dataset.show = ''
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
setTimeout(() => {
|
|
159
|
+
if (!popoverDOM.dataset.show) {
|
|
160
|
+
popoverDOM.removeAttribute('data-show')
|
|
161
|
+
}
|
|
162
|
+
}, 300)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const removeOnResize = debounce(() => {
|
|
166
|
+
popoverDOM.dataset.show = ''
|
|
167
|
+
|
|
168
|
+
setTimeout(() => {
|
|
169
|
+
if (!popoverDOM.dataset.show) {
|
|
170
|
+
popoverDOM.removeAttribute('data-show')
|
|
171
|
+
}
|
|
172
|
+
}, 300)
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
const observer = new ResizeObserver(() => {
|
|
176
|
+
if (popoverDOM.dataset.show) {
|
|
177
|
+
removeOnResize()
|
|
178
|
+
}
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
triggerDOM.addEventListener('click', handleOpen)
|
|
182
|
+
observer.observe(document.body)
|
|
183
|
+
|
|
184
|
+
if (closeOnBlur) {
|
|
185
|
+
document.addEventListener('click', handleClose)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
remove() {
|
|
190
|
+
triggerDOM.removeEventListener('click', handleOpen);
|
|
191
|
+
observer.disconnect()
|
|
192
|
+
|
|
193
|
+
if (closeOnBlur) {
|
|
194
|
+
document.removeEventListener('click', handleClose)
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export const closePopover = closeModal
|
package/utils/toast.ts
CHANGED
|
@@ -6,7 +6,6 @@ type Toast = {
|
|
|
6
6
|
timeout?: number
|
|
7
7
|
title?: AlertProps['title']
|
|
8
8
|
content?: string
|
|
9
|
-
theme?: AlertProps['theme']
|
|
10
9
|
position?: ToastProps['position']
|
|
11
10
|
}
|
|
12
11
|
|
|
@@ -23,17 +22,12 @@ export const toast = (config: Toast | string) => {
|
|
|
23
22
|
timeout,
|
|
24
23
|
title,
|
|
25
24
|
content,
|
|
26
|
-
theme,
|
|
27
25
|
position
|
|
28
26
|
} = (typeof config === 'string' ? {} : config) as Toast
|
|
29
27
|
|
|
30
28
|
const htmlElement = document.querySelector(element) as HTMLElement
|
|
31
29
|
|
|
32
30
|
if (htmlElement) {
|
|
33
|
-
if (theme) {
|
|
34
|
-
htmlElement.dataset.theme = theme
|
|
35
|
-
}
|
|
36
|
-
|
|
37
31
|
if (position) {
|
|
38
32
|
htmlElement.dataset.position = position
|
|
39
33
|
}
|