@weni/unnnic-system 3.12.8-alpha.0 → 3.12.8

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.
Files changed (90) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/{es-52edeb71.mjs → es-62c1e8d3.mjs} +1 -1
  3. package/dist/{index-756fe685.mjs → index-ef197fd5.mjs} +52261 -55425
  4. package/dist/index.d.ts +1449 -5339
  5. package/dist/{pt-br-24583c8c.mjs → pt-br-198b147b.mjs} +1 -1
  6. package/dist/style.css +1 -1
  7. package/dist/unnnic.mjs +203 -233
  8. package/dist/unnnic.umd.js +44 -48
  9. package/package.json +2 -3
  10. package/src/assets/scss/scheme-colors.scss +223 -223
  11. package/src/assets/scss/tailwind.scss +0 -8
  12. package/src/components/Alert/__tests__/__snapshots__/Alert.spec.js.snap +1 -1
  13. package/src/components/Checkbox/Checkbox.vue +1 -1
  14. package/src/components/Drawer/Drawer.vue +269 -190
  15. package/src/components/Drawer/__tests__/Drawer.spec.js +46 -37
  16. package/src/components/Drawer/__tests__/__snapshots__/Drawer.spec.js.snap +19 -18
  17. package/src/components/FormElement/FormElement.vue +1 -1
  18. package/src/components/Input/BaseInput.vue +5 -25
  19. package/src/components/Input/Input.scss +3 -2
  20. package/src/components/Input/Input.vue +1 -24
  21. package/src/components/Input/TextInput.vue +25 -64
  22. package/src/components/Input/__test__/TextInput.spec.js +1 -1
  23. package/src/components/Input/__test__/__snapshots__/Input.spec.js.snap +1 -5
  24. package/src/components/Input/__test__/__snapshots__/TextInput.spec.js.snap +1 -7
  25. package/src/components/ModalDialog/ModalDialog.vue +148 -64
  26. package/src/components/ModalDialog/__tests__/ModalDialog.spec.js +221 -11
  27. package/src/components/ModalDialog/__tests__/__snapshots__/ModalDialog.spec.js.snap +22 -1
  28. package/src/components/MultiSelect/MultiSelect.vue +297 -0
  29. package/src/components/Radio/Radio.vue +1 -1
  30. package/src/components/Switch/Switch.vue +1 -1
  31. package/src/components/Tab/__test__/__snapshots__/Tab.spec.js.snap +1 -3
  32. package/src/components/TemplatePreview/TemplatePreview.vue +2 -2
  33. package/src/components/TemplatePreview/TemplatePreviewModal.vue +1 -1
  34. package/src/components/Toast/Toast.vue +9 -16
  35. package/src/components/ToolTip/ToolTip.vue +177 -25
  36. package/src/components/ToolTip/__tests__/ToolTip.spec.js +61 -339
  37. package/src/components/index.ts +6 -62
  38. package/src/components/ui/popover/PopoverContent.vue +4 -5
  39. package/src/components/ui/popover/PopoverOption.vue +0 -4
  40. package/src/components/ui/popover/PopoverTrigger.vue +1 -5
  41. package/src/locales/en.json +1 -3
  42. package/src/locales/es.json +1 -3
  43. package/src/locales/pt_br.json +1 -3
  44. package/src/stories/Drawer.stories.js +1 -1
  45. package/src/stories/Input.mdx +0 -3
  46. package/src/stories/ModalDialog.mdx +0 -3
  47. package/src/stories/ModalDialog.stories.js +1 -1
  48. package/src/stories/MultiSelect.stories.js +45 -143
  49. package/src/components/MultiSelect/MultSelectOption.vue +0 -49
  50. package/src/components/MultiSelect/__tests__/MultiSelect.spec.js +0 -557
  51. package/src/components/MultiSelect/__tests__/MultiSelectOption.spec.js +0 -229
  52. package/src/components/MultiSelect/__tests__/__snapshots__/MultiSelect.spec.js.snap +0 -87
  53. package/src/components/MultiSelect/__tests__/__snapshots__/MultiSelectOption.spec.js.snap +0 -51
  54. package/src/components/MultiSelect/index.vue +0 -265
  55. package/src/components/Select/__tests__/Select.spec.js +0 -422
  56. package/src/components/Select/__tests__/SelectItem.spec.js +0 -330
  57. package/src/components/Select/__tests__/__snapshots__/Popover.spec.js.snap +0 -8
  58. package/src/components/Select/__tests__/__snapshots__/Select.spec.js.snap +0 -71
  59. package/src/components/Select/__tests__/__snapshots__/SelectItem.spec.js.snap +0 -15
  60. package/src/components/Select/__tests__/__snapshots__/SelectOption.spec.js.snap +0 -25
  61. package/src/components/Select/__tests__/__snapshots__/SelectPopover.spec.js.snap +0 -8
  62. package/src/components/Select/index.vue +0 -308
  63. package/src/components/ui/dialog/Dialog.vue +0 -19
  64. package/src/components/ui/dialog/DialogClose.vue +0 -29
  65. package/src/components/ui/dialog/DialogContent.vue +0 -140
  66. package/src/components/ui/dialog/DialogFooter.vue +0 -50
  67. package/src/components/ui/dialog/DialogHeader.vue +0 -83
  68. package/src/components/ui/dialog/DialogTitle.vue +0 -38
  69. package/src/components/ui/dialog/DialogTrigger.vue +0 -16
  70. package/src/components/ui/dialog/index.ts +0 -7
  71. package/src/components/ui/drawer/Drawer.vue +0 -27
  72. package/src/components/ui/drawer/DrawerClose.vue +0 -31
  73. package/src/components/ui/drawer/DrawerContent.vue +0 -111
  74. package/src/components/ui/drawer/DrawerDescription.vue +0 -40
  75. package/src/components/ui/drawer/DrawerFooter.vue +0 -38
  76. package/src/components/ui/drawer/DrawerHeader.vue +0 -57
  77. package/src/components/ui/drawer/DrawerOverlay.vue +0 -33
  78. package/src/components/ui/drawer/DrawerTitle.vue +0 -37
  79. package/src/components/ui/drawer/DrawerTrigger.vue +0 -31
  80. package/src/components/ui/drawer/index.ts +0 -10
  81. package/src/components/ui/tooltip/Tooltip.vue +0 -21
  82. package/src/components/ui/tooltip/TooltipContent.vue +0 -74
  83. package/src/components/ui/tooltip/TooltipTrigger.vue +0 -26
  84. package/src/components/ui/tooltip/index.ts +0 -3
  85. package/src/lib/layer-manager.ts +0 -92
  86. package/src/stories/Dialog.stories.js +0 -832
  87. package/src/stories/DrawerNext.stories.js +0 -611
  88. package/src/stories/LayerManager.docs.mdx +0 -40
  89. package/src/stories/LayerManager.stories.js +0 -364
  90. package/src/stories/Select.stories.js +0 -161
@@ -1,27 +0,0 @@
1
- <script lang="ts" setup>
2
- import type { DrawerRootEmits, DrawerRootProps } from 'vaul-vue';
3
- import { useForwardPropsEmits } from 'reka-ui';
4
- import { DrawerRoot } from 'vaul-vue';
5
-
6
- defineOptions({
7
- name: 'UnnnicDrawerNext',
8
- });
9
-
10
- const props = withDefaults(defineProps<DrawerRootProps>(), {
11
- shouldScaleBackground: true,
12
- });
13
-
14
- const emits = defineEmits<DrawerRootEmits>();
15
-
16
- const forwarded = useForwardPropsEmits(props, emits);
17
- </script>
18
-
19
- <template>
20
- <DrawerRoot
21
- v-bind="forwarded"
22
- direction="right"
23
- handleOnly
24
- >
25
- <slot />
26
- </DrawerRoot>
27
- </template>
@@ -1,31 +0,0 @@
1
- <script setup lang="ts">
2
- import type { DrawerCloseProps } from 'vaul-vue';
3
- import { DrawerClose } from 'vaul-vue';
4
-
5
- defineOptions({
6
- name: 'UnnnicDrawerClose',
7
- });
8
-
9
- const props = withDefaults(defineProps<DrawerCloseProps>(), {
10
- asChild: true,
11
- });
12
- </script>
13
-
14
- <template>
15
- <DrawerClose
16
- v-bind="props"
17
- class="unnnic-drawer__close"
18
- >
19
- <slot />
20
- </DrawerClose>
21
- </template>
22
-
23
- <style lang="scss" scoped>
24
- @use '@/assets/scss/unnnic' as *;
25
-
26
- .unnnic-drawer__close {
27
- > * {
28
- width: 100%;
29
- }
30
- }
31
- </style>
@@ -1,111 +0,0 @@
1
- <script lang="ts" setup>
2
- import type { DialogContentEmits, DialogContentProps } from 'reka-ui';
3
- import { type HTMLAttributes } from 'vue';
4
- import { reactiveOmit } from '@vueuse/core';
5
- import { useForwardPropsEmits } from 'reka-ui';
6
- import { DrawerContent, DrawerPortal } from 'vaul-vue';
7
- import { cn } from '@/lib/utils';
8
- import { useLayerZIndex } from '@/lib/layer-manager';
9
- import DrawerOverlay from './DrawerOverlay.vue';
10
-
11
- defineOptions({
12
- name: 'UnnnicDrawerContent',
13
- });
14
-
15
- const props = withDefaults(
16
- defineProps<
17
- DialogContentProps & {
18
- class?: HTMLAttributes['class'];
19
- size?: 'medium' | 'large' | 'extra-large' | 'giant';
20
- showOverlay?: boolean;
21
- }
22
- >(),
23
- {
24
- class: undefined,
25
- size: 'medium',
26
- showOverlay: true,
27
- },
28
- );
29
- const emits = defineEmits<DialogContentEmits>();
30
-
31
- const delegatedProps = reactiveOmit(props, 'class');
32
- const forwardedProps = useForwardPropsEmits(delegatedProps, emits);
33
-
34
- const layerZIndex = useLayerZIndex('drawer');
35
- </script>
36
-
37
- <template>
38
- <DrawerPortal>
39
- <DrawerOverlay
40
- v-if="showOverlay"
41
- :style="{ zIndex: layerZIndex - 2 }"
42
- />
43
- <DrawerContent
44
- v-bind="forwardedProps"
45
- :class="
46
- cn(
47
- 'unnnic-drawer__content',
48
- `unnnic-drawer__content--${props.size}`,
49
- props.class,
50
- )
51
- "
52
- :style="{
53
- '--initial-transform': 'calc(100% + 8px)',
54
- zIndex: layerZIndex,
55
- }"
56
- >
57
- <slot />
58
- </DrawerContent>
59
- </DrawerPortal>
60
- </template>
61
-
62
- <style lang="scss" scoped>
63
- @use '@/assets/scss/unnnic' as *;
64
-
65
- $drawer-space: $unnnic-space-2;
66
-
67
- .unnnic-drawer__content {
68
- -webkit-user-select: unset;
69
- user-select: unset;
70
- will-change: unset;
71
-
72
- &::after {
73
- display: none;
74
- }
75
-
76
- position: fixed;
77
- top: $drawer-space;
78
- right: $drawer-space;
79
-
80
- display: flex;
81
- flex-direction: column;
82
-
83
- height: calc(100% - $drawer-space * 2);
84
-
85
- border-radius: $unnnic-radius-4;
86
- border: 1px solid $unnnic-color-border-soft;
87
- background-color: $unnnic-color-bg-base;
88
-
89
- &--medium {
90
- width: calc(100% / 3);
91
- }
92
-
93
- &--large {
94
- width: 50%;
95
- }
96
-
97
- &--extra-large {
98
- width: 66%;
99
- }
100
-
101
- &--giant {
102
- width: 75%;
103
- }
104
-
105
- &__body {
106
- overflow-y: auto;
107
- padding: $unnnic-space-6;
108
- flex: 1 0 0;
109
- }
110
- }
111
- </style>
@@ -1,40 +0,0 @@
1
- <script lang="ts" setup>
2
- import type { DrawerDescriptionProps } from 'vaul-vue';
3
- import type { HTMLAttributes } from 'vue';
4
- import { reactiveOmit } from '@vueuse/core';
5
- import { DrawerDescription } from 'vaul-vue';
6
- import { cn } from '@/lib/utils';
7
-
8
- defineOptions({
9
- name: 'UnnnicDrawerDescription',
10
- });
11
-
12
- const props = defineProps<
13
- DrawerDescriptionProps & { class?: HTMLAttributes['class'] }
14
- >();
15
-
16
- const delegatedProps = reactiveOmit(props, 'class');
17
- </script>
18
-
19
- <template>
20
- <DrawerDescription
21
- v-bind="delegatedProps"
22
- :class="cn('unnnic-drawer__description', props.class)"
23
- >
24
- <slot />
25
- </DrawerDescription>
26
- </template>
27
-
28
- <style lang="scss" scoped>
29
- @use '@/assets/scss/unnnic' as *;
30
-
31
- .unnnic-drawer__description {
32
- margin: 0;
33
-
34
- font: $unnnic-font-body;
35
- color: $unnnic-color-fg-base;
36
-
37
- grid-column: 1 / 3;
38
- grid-row: 2 / 3;
39
- }
40
- </style>
@@ -1,38 +0,0 @@
1
- <script lang="ts" setup>
2
- import { type HTMLAttributes } from 'vue';
3
- import { cn } from '@/lib/utils';
4
-
5
- defineOptions({
6
- name: 'UnnnicDrawerFooter',
7
- });
8
-
9
- const props = defineProps<{
10
- class?: HTMLAttributes['class'];
11
- }>();
12
- </script>
13
-
14
- <template>
15
- <footer :class="cn('unnnic-drawer__footer', props.class)">
16
- <slot />
17
- </footer>
18
- </template>
19
-
20
- <style lang="scss" scoped>
21
- @use '@/assets/scss/unnnic' as *;
22
-
23
- .unnnic-drawer__footer {
24
- border-top: 1px solid $unnnic-color-border-soft;
25
-
26
- margin-top: auto;
27
- padding: $unnnic-space-6;
28
-
29
- display: flex;
30
- justify-content: center;
31
- align-items: center;
32
- gap: $unnnic-space-2;
33
-
34
- > * {
35
- width: 100%;
36
- }
37
- }
38
- </style>
@@ -1,57 +0,0 @@
1
- <script lang="ts" setup>
2
- import { type HTMLAttributes } from 'vue';
3
- import { cn } from '@/lib/utils';
4
- import UnnnicButton from '@/components/Button/Button.vue';
5
- import DrawerClose from './DrawerClose.vue';
6
-
7
- defineOptions({
8
- name: 'UnnnicDrawerHeader',
9
- });
10
-
11
- const props = defineProps<{
12
- class?: HTMLAttributes['class'];
13
- }>();
14
- </script>
15
-
16
- <template>
17
- <header :class="cn('unnnic-drawer__header', props.class)">
18
- <slot />
19
-
20
- <template v-if="$slots.close">
21
- <slot
22
- name="close"
23
- class="unnnic-drawer__close-button"
24
- />
25
- </template>
26
- <template v-else>
27
- <DrawerClose>
28
- <UnnnicButton
29
- iconCenter="close"
30
- size="small"
31
- type="tertiary"
32
- class="unnnic-drawer__close-button"
33
- />
34
- </DrawerClose>
35
- </template>
36
- </header>
37
- </template>
38
-
39
- <style lang="scss" scoped>
40
- @use '@/assets/scss/unnnic' as *;
41
-
42
- .unnnic-drawer__header {
43
- display: grid;
44
- align-items: center;
45
- grid-template-columns: 1fr auto;
46
- padding: $unnnic-space-6;
47
-
48
- gap: $unnnic-space-1;
49
-
50
- border-bottom: 1px solid $unnnic-color-border-soft;
51
- }
52
-
53
- .unnnic-drawer__close-button {
54
- grid-column: 2 / 3;
55
- grid-row: 1 / 2;
56
- }
57
- </style>
@@ -1,33 +0,0 @@
1
- <script lang="ts" setup>
2
- import type { DialogOverlayProps } from 'reka-ui';
3
- import { type HTMLAttributes } from 'vue';
4
- import { reactiveOmit } from '@vueuse/core';
5
- import { DrawerOverlay } from 'vaul-vue';
6
- import { cn } from '@/lib/utils';
7
-
8
- defineOptions({
9
- name: 'UnnnicDrawerOverlay',
10
- });
11
-
12
- const props = defineProps<
13
- DialogOverlayProps & { class?: HTMLAttributes['class'] }
14
- >();
15
-
16
- const delegatedProps = reactiveOmit(props, 'class');
17
- </script>
18
-
19
- <template>
20
- <DrawerOverlay
21
- v-bind="delegatedProps"
22
- :class="cn('unnnic-drawer__overlay', props.class)"
23
- />
24
- </template>
25
-
26
- <style lang="scss" scoped>
27
- .unnnic-drawer__overlay {
28
- position: fixed;
29
- inset: 0;
30
-
31
- background: rgba(53, 57, 69, 0.65);
32
- }
33
- </style>
@@ -1,37 +0,0 @@
1
- <script lang="ts" setup>
2
- import type { DrawerTitleProps } from 'vaul-vue';
3
- import { type HTMLAttributes } from 'vue';
4
- import { reactiveOmit } from '@vueuse/core';
5
- import { DrawerTitle } from 'vaul-vue';
6
- import { cn } from '@/lib/utils';
7
-
8
- defineOptions({
9
- name: 'UnnnicDrawerTitle',
10
- });
11
-
12
- const props = defineProps<
13
- DrawerTitleProps & { class?: HTMLAttributes['class'] }
14
- >();
15
-
16
- const delegatedProps = reactiveOmit(props, 'class');
17
- </script>
18
-
19
- <template>
20
- <DrawerTitle
21
- v-bind="delegatedProps"
22
- :class="cn('unnnic-drawer__title', props.class)"
23
- >
24
- <slot />
25
- </DrawerTitle>
26
- </template>
27
-
28
- <style lang="scss" scoped>
29
- @use '@/assets/scss/unnnic' as *;
30
-
31
- .unnnic-drawer__title {
32
- margin: 0;
33
-
34
- color: $unnnic-color-fg-emphasized;
35
- font: $unnnic-font-display-2;
36
- }
37
- </style>
@@ -1,31 +0,0 @@
1
- <script setup lang="ts">
2
- import type { DrawerTriggerProps } from 'vaul-vue';
3
- import { DrawerTrigger } from 'vaul-vue';
4
-
5
- defineOptions({
6
- name: 'UnnnicDrawerTrigger',
7
- });
8
-
9
- const props = defineProps<DrawerTriggerProps>();
10
- </script>
11
-
12
- <template>
13
- <DrawerTrigger
14
- v-bind="props"
15
- class="unnnic-drawer__trigger"
16
- >
17
- <slot />
18
- </DrawerTrigger>
19
- </template>
20
-
21
- <style lang="scss" scoped>
22
- @use '@/assets/scss/unnnic' as *;
23
-
24
- .unnnic-drawer__trigger {
25
- border: none;
26
- background: none;
27
- padding: 0;
28
- margin: 0;
29
- cursor: pointer;
30
- }
31
- </style>
@@ -1,10 +0,0 @@
1
- export { default as Drawer } from './Drawer.vue';
2
- export { default as DrawerContent } from './DrawerContent.vue';
3
- export { default as DrawerDescription } from './DrawerDescription.vue';
4
- export { default as DrawerFooter } from './DrawerFooter.vue';
5
- export { default as DrawerHeader } from './DrawerHeader.vue';
6
- export { default as DrawerOverlay } from './DrawerOverlay.vue';
7
- export { default as DrawerTitle } from './DrawerTitle.vue';
8
- export { default as DrawerTrigger } from './DrawerTrigger.vue';
9
- export { default as DrawerClose } from './DrawerClose.vue';
10
- export { DrawerPortal } from 'vaul-vue';
@@ -1,21 +0,0 @@
1
- <script setup lang="ts">
2
- import type { TooltipRootEmits, TooltipRootProps } from 'reka-ui';
3
- import { TooltipRoot, useForwardPropsEmits } from 'reka-ui';
4
- import { TooltipProvider } from 'reka-ui';
5
-
6
- const props = defineProps<TooltipRootProps>();
7
- const emits = defineEmits<TooltipRootEmits>();
8
-
9
- const forwarded = useForwardPropsEmits(props, emits);
10
- </script>
11
-
12
- <template>
13
- <TooltipProvider
14
- :delayDuration="100"
15
- disableClosingTrigger
16
- >
17
- <TooltipRoot v-bind="forwarded">
18
- <slot />
19
- </TooltipRoot>
20
- </TooltipProvider>
21
- </template>
@@ -1,74 +0,0 @@
1
- <script setup lang="ts">
2
- import type { TooltipContentEmits, TooltipContentProps } from 'reka-ui';
3
- import type { HTMLAttributes } from 'vue';
4
- import { reactiveOmit } from '@vueuse/core';
5
- import {
6
- TooltipArrow,
7
- TooltipContent,
8
- TooltipPortal,
9
- useForwardPropsEmits,
10
- } from 'reka-ui';
11
- import { cn } from '@/lib/utils';
12
- import { useLayerZIndex } from '@/lib/layer-manager';
13
-
14
- defineOptions({
15
- inheritAttrs: false,
16
- });
17
-
18
- const props = withDefaults(
19
- defineProps<TooltipContentProps & { class?: HTMLAttributes['class'] }>(),
20
- {
21
- sideOffset: 0,
22
- },
23
- );
24
-
25
- const emits = defineEmits<TooltipContentEmits>();
26
-
27
- const delegatedProps = reactiveOmit(props, 'class');
28
-
29
- const forwarded = useForwardPropsEmits(delegatedProps, emits);
30
- const tooltipZIndex = useLayerZIndex('tooltip');
31
- </script>
32
-
33
- <template>
34
- <TooltipPortal>
35
- <TooltipContent
36
- v-bind="{ ...forwarded, ...$attrs }"
37
- :class="
38
- cn(
39
- 'tooltip__content',
40
- 'animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
41
- props.class,
42
- )
43
- "
44
- :style="{ zIndex: tooltipZIndex }"
45
- >
46
- <slot />
47
-
48
- <TooltipArrow class="tooltip__arrow" />
49
- </TooltipContent>
50
- </TooltipPortal>
51
- </template>
52
-
53
- <style lang="scss">
54
- @use '@/assets/scss/unnnic' as *;
55
-
56
- .tooltip__content {
57
- background-color: $unnnic-color-gray-900;
58
- color: $unnnic-color-white;
59
- border-radius: $unnnic-radius-1;
60
- padding: $unnnic-space-2;
61
- box-shadow: $unnnic-shadow-1;
62
- font: $unnnic-font-caption-2;
63
-
64
- overflow-wrap: break-word;
65
- }
66
-
67
- .tooltip__arrow {
68
- width: 10px;
69
- height: 10px;
70
- background-color: $unnnic-color-gray-900;
71
- fill: $unnnic-color-gray-900;
72
- transform: rotate(45deg) translate(-50%, -50%);
73
- }
74
- </style>
@@ -1,26 +0,0 @@
1
- <script setup lang="ts">
2
- import type { TooltipTriggerProps } from 'reka-ui';
3
- import { TooltipTrigger } from 'reka-ui';
4
-
5
- const props = defineProps<TooltipTriggerProps>();
6
- </script>
7
-
8
- <template>
9
- <TooltipTrigger
10
- v-bind="props"
11
- as="div"
12
- class="unnnic-tooltip-trigger"
13
- >
14
- <slot />
15
- </TooltipTrigger>
16
- </template>
17
-
18
- <style lang="scss" scoped>
19
- .unnnic-tooltip-trigger {
20
- display: inline-block;
21
-
22
- & > * {
23
- width: 100%;
24
- }
25
- }
26
- </style>
@@ -1,3 +0,0 @@
1
- export { default as Tooltip } from './Tooltip.vue';
2
- export { default as TooltipContent } from './TooltipContent.vue';
3
- export { default as TooltipTrigger } from './TooltipTrigger.vue';
@@ -1,92 +0,0 @@
1
- import { onBeforeUnmount, onMounted, ref, type Ref } from 'vue';
2
-
3
- export const layerScale = {
4
- hide: -1,
5
- base: 0,
6
- drawer: 1000,
7
- modal: 1100,
8
- popover: 1200,
9
- tooltip: 1300,
10
- toast: 1400,
11
- } as const;
12
-
13
- export type LayerToken = keyof typeof layerScale;
14
-
15
- const DEFAULT_STEP = 5;
16
-
17
- const activeValues: Record<LayerToken, number[]> = {
18
- hide: [],
19
- base: [],
20
- drawer: [],
21
- modal: [],
22
- popover: [],
23
- tooltip: [],
24
- toast: [],
25
- };
26
-
27
- interface Allocation {
28
- id: symbol;
29
- type: LayerToken;
30
- value: number;
31
- }
32
-
33
- const allocations = new Map<symbol, Allocation>();
34
-
35
- function acquire(type: LayerToken): Allocation {
36
- const id = Symbol('layer');
37
- const list = activeValues[type];
38
- const lastValue = list.length ? list[list.length - 1] : layerScale[type];
39
- const value = lastValue + DEFAULT_STEP;
40
- const allocation: Allocation = { id, type, value };
41
-
42
- list.push(value);
43
- allocations.set(id, allocation);
44
-
45
- return allocation;
46
- }
47
-
48
- function release(id: symbol) {
49
- const allocation = allocations.get(id);
50
- if (!allocation) {
51
- return;
52
- }
53
-
54
- allocations.delete(id);
55
- const list = activeValues[allocation.type];
56
- const index = list.indexOf(allocation.value);
57
-
58
- if (index !== -1) {
59
- list.splice(index, 1);
60
- }
61
- }
62
-
63
- export interface LayerZIndexOptions {
64
- offset?: number;
65
- }
66
-
67
- export function useLayerZIndex(
68
- type: LayerToken = 'base',
69
- options?: LayerZIndexOptions,
70
- ): Ref<number> {
71
- const initialValue = layerScale[type] + (options?.offset ?? 0);
72
- const zIndex = ref(initialValue);
73
-
74
- let allocationId: symbol | null = null;
75
-
76
- const allocate = () => {
77
- const allocation = acquire(type);
78
- allocationId = allocation.id;
79
- zIndex.value = allocation.value + (options?.offset ?? 0);
80
- };
81
-
82
- onMounted(allocate);
83
-
84
- onBeforeUnmount(() => {
85
- if (allocationId) {
86
- release(allocationId);
87
- allocationId = null;
88
- }
89
- });
90
-
91
- return zIndex;
92
- }