vue-composable-ui 0.0.1
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/.github/workflows/deploy.yml +21 -0
- package/.github/workflows/docs.yml +62 -0
- package/.vscode/extensions.json +7 -0
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/docs/.vitepress/config.mts +40 -0
- package/docs/.vitepress/theme/index.js +4 -0
- package/docs/.vitepress/theme/style.scss +155 -0
- package/docs/components/combobox.md +174 -0
- package/docs/components/demos/combobox.vue +142 -0
- package/docs/components/demos/combobox_autocomplete.vue +75 -0
- package/docs/components/demos/combobox_tags.vue +127 -0
- package/docs/components/demos/input.vue +35 -0
- package/docs/components/demos/listbox.vue +64 -0
- package/docs/components/demos/menu.vue +93 -0
- package/docs/components/demos/popover.vue +16 -0
- package/docs/components/demos/tabs.vue +59 -0
- package/docs/components/demos/tooltip.vue +27 -0
- package/docs/components/listbox.md +9 -0
- package/docs/components/menu.md +121 -0
- package/docs/components/popover.md +82 -0
- package/docs/components/tabs.md +9 -0
- package/docs/components/tooltip.md +78 -0
- package/docs/composables/form-control.md +130 -0
- package/docs/composables/list-option.md +47 -0
- package/docs/composables/list.md +192 -0
- package/docs/composables/popover.md +90 -0
- package/docs/index.md +24 -0
- package/docs/intro.md +0 -0
- package/package.json +35 -0
- package/src/components/combobox/combobox.vue +229 -0
- package/src/components/combobox/comboboxFormInput.vue +33 -0
- package/src/components/combobox/comboboxOption.vue +52 -0
- package/src/components/combobox/comboboxOptions.vue +17 -0
- package/src/components/injectionKeys.ts +50 -0
- package/src/components/listbox/listbox.vue +91 -0
- package/src/components/listbox/listboxOption.vue +37 -0
- package/src/components/menu/menu.vue +100 -0
- package/src/components/menu/menuItem.vue +86 -0
- package/src/components/menu/menuItems.vue +51 -0
- package/src/components/popover/popover.vue +68 -0
- package/src/components/popover/popoverDialog.vue +35 -0
- package/src/components/tabs/tab.vue +35 -0
- package/src/components/tabs/tabContainer.vue +50 -0
- package/src/components/tabs/tabList.vue +52 -0
- package/src/components/tabs/tabPanel.vue +36 -0
- package/src/components/tooltip.vue +115 -0
- package/src/composables/formControl.ts +144 -0
- package/src/composables/list.ts +326 -0
- package/src/composables/listOption.ts +80 -0
- package/src/composables/popover.ts +306 -0
- package/src/main.ts +65 -0
- package/src/utils/element.ts +19 -0
- package/src/utils/id.ts +5 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +27 -0
- package/tsconfig.node.json +10 -0
- package/vite.config.ts +28 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import PopoverDemo from './demos/popover.vue'
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
# Popover Component
|
|
6
|
+
|
|
7
|
+
Popover is a floating container that appears next to its activator element above the main document flow.
|
|
8
|
+
|
|
9
|
+
No event listeners are attached to the activating element to give the user full control over the way the popover is triggered.
|
|
10
|
+
|
|
11
|
+
Based on:
|
|
12
|
+
|
|
13
|
+
- [usePopover](/composables/popover)
|
|
14
|
+
|
|
15
|
+
## Demo
|
|
16
|
+
|
|
17
|
+
<PopoverDemo />
|
|
18
|
+
|
|
19
|
+
::: details Code
|
|
20
|
+
<<< ./demos/popover.vue
|
|
21
|
+
:::
|
|
22
|
+
|
|
23
|
+
## Popover
|
|
24
|
+
|
|
25
|
+
The root component.
|
|
26
|
+
|
|
27
|
+
### Properties
|
|
28
|
+
|
|
29
|
+
| Property | Required | Description | Type | Default |
|
|
30
|
+
| ----------------------- | -------- | ---------------------------------------------------- | --------------------------------------------------------------------------- | -------------- |
|
|
31
|
+
| **id** | false | The ID of the popover dialog. | `string` | Auto-generated |
|
|
32
|
+
| **activatorId** | false | The ID of the activator element. | `string` | Auto-generated |
|
|
33
|
+
| **direction** | false | The direction of the popover. | `'up'` \| `'down'` \| `'left'` \| `'right'` | `'down'` |
|
|
34
|
+
| **align** | false | The alignment of the popover. | `'top'` \| `'bottom'` \| `'left'` \| `'right'` \| `'center'` \| `'stretch'` | `'left'` |
|
|
35
|
+
| **position** | false | CSS position of the popover dialog. | `'fixed'` \| `'absolute'` | `'fixed'` |
|
|
36
|
+
| **closeOnOutsideClick** | false | Close the popover on an click outside of the dialog. | `boolean` | `true` |
|
|
37
|
+
| **closeOnInsideClick** | false | Close the popover on an click inside of the dialog. | `boolean` | `false` |
|
|
38
|
+
| **role** | false | The ARIA role of the popover | `'dialog'` \| `'listbox'` \| `'menu'` \| `'tree'` \| `'grid'` | `'dialog'` |
|
|
39
|
+
|
|
40
|
+
### Slots
|
|
41
|
+
|
|
42
|
+
#### default
|
|
43
|
+
|
|
44
|
+
The `default` slot is used to provide an activating element and a [PopoverDialog](#popoverdialog). The slot passes the following properties:
|
|
45
|
+
|
|
46
|
+
| Property | Description | Type |
|
|
47
|
+
| -------- | ------------------------------------------------------------ | -------------- |
|
|
48
|
+
| attrs | Required attributes that **must** be binded to the activator | `object` |
|
|
49
|
+
| isOpen | The status of the popover | `Ref<boolean>` |
|
|
50
|
+
| toggle | Toggle the popover | `() => void` |
|
|
51
|
+
| open | Open the popover and place focus on it | `() => void` |
|
|
52
|
+
| close | Close the popover and return focus to the activator | `() => void` |
|
|
53
|
+
|
|
54
|
+
```vue-html
|
|
55
|
+
<Popover v-slot="{ attrs, toggle, close }">
|
|
56
|
+
<button @click="toggle" v-bind="attrs">Toggle</button>
|
|
57
|
+
|
|
58
|
+
<PopoverDialog>
|
|
59
|
+
<button @click="close()" >Close</button>
|
|
60
|
+
</PopoverDialog>
|
|
61
|
+
</Popover>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### ARIA roles and attributes
|
|
65
|
+
|
|
66
|
+
The following attributes are managed for the activator:
|
|
67
|
+
|
|
68
|
+
- [aria-controls](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-controls)
|
|
69
|
+
- [aria-haspopup](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-haspopup)
|
|
70
|
+
- [aria-expanded](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-expanded)
|
|
71
|
+
|
|
72
|
+
## PopoverDialog
|
|
73
|
+
|
|
74
|
+
### Keyboard interactions
|
|
75
|
+
|
|
76
|
+
- `Escape` - Closes the popover and returns focus to the activating element.
|
|
77
|
+
|
|
78
|
+
### ARIA roles and attributes
|
|
79
|
+
|
|
80
|
+
The popover container has the role provided in the popover properties and automatically manages the following attributes:
|
|
81
|
+
|
|
82
|
+
- [aria-labelledby](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-labelledby)
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import TooltipDemo from './demos/tooltip.vue'
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
# Tooltip Component
|
|
6
|
+
|
|
7
|
+
A tooltip is a contextual text bubble that displays a description for an element that appears on pointer hover or keyboard focus.
|
|
8
|
+
|
|
9
|
+
A tooltip activator can be provided in the default slot:
|
|
10
|
+
|
|
11
|
+
```vue
|
|
12
|
+
<Tooltip text="Tooltip text" v-slot="{ attrs }">
|
|
13
|
+
<button v-bind="attrs">Activator</button>
|
|
14
|
+
</Tooltip>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Or by setting a tooltip id and using it in the `aria-describedby` attribute on the activator:
|
|
18
|
+
|
|
19
|
+
```vue
|
|
20
|
+
<Tooltip id="tooltip-example" text="Tooltip text" />
|
|
21
|
+
<button aria-describedby="tooltip-example">Activator</button>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Based on:
|
|
25
|
+
|
|
26
|
+
- [usePopover](/composables/popover)
|
|
27
|
+
|
|
28
|
+
## Demo
|
|
29
|
+
|
|
30
|
+
<TooltipDemo />
|
|
31
|
+
|
|
32
|
+
::: details Code
|
|
33
|
+
<<< ./demos/tooltip.vue
|
|
34
|
+
:::
|
|
35
|
+
|
|
36
|
+
## Tooltip
|
|
37
|
+
|
|
38
|
+
### Properties
|
|
39
|
+
|
|
40
|
+
| Property | Required | Description | Type | Default |
|
|
41
|
+
| ------------- | -------- | ----------------------------------------------------- | ------------------------------------------- | -------------- |
|
|
42
|
+
| **text** | false | Tooltip text. | `string` | `undefined` |
|
|
43
|
+
| **delay** | false | The delay before showing the tooltip in milliseconds. | `number` \| `string` | `undefined` |
|
|
44
|
+
| **direction** | false | The direction of the tooltip. | `'up'` \| `'down'` \| `'left'` \| `'right'` | `'up'` |
|
|
45
|
+
| **id** | false | The ID of the tooltip. | `string` | auto-generated |
|
|
46
|
+
|
|
47
|
+
### Slots
|
|
48
|
+
|
|
49
|
+
#### default
|
|
50
|
+
|
|
51
|
+
The `default` slot can be used to provide an activator. The slot provides the `attrs` attribute that must be binded to the activating element.
|
|
52
|
+
|
|
53
|
+
```vue
|
|
54
|
+
<Tooltip text="Tooltip text" v-slot="{ attrs }">
|
|
55
|
+
<button v-bind="attrs">Activator</button>
|
|
56
|
+
</Tooltip>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
#### content
|
|
60
|
+
|
|
61
|
+
The `content` slot can be used to provide any custom html content for the tooltip.
|
|
62
|
+
|
|
63
|
+
```vue
|
|
64
|
+
<Tooltip>
|
|
65
|
+
<template #content>
|
|
66
|
+
Any custom html content
|
|
67
|
+
<img src="..." />
|
|
68
|
+
</template>
|
|
69
|
+
</Tooltip>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Keyboard interactions
|
|
73
|
+
|
|
74
|
+
- `Escape` - Hides the tooltip without preventing the default action.
|
|
75
|
+
|
|
76
|
+
### ARIA roles and attributes
|
|
77
|
+
|
|
78
|
+
Tooltips have the [tooltip](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/tooltip_role) role.
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# useFormControl
|
|
2
|
+
|
|
3
|
+
`useFormControl` utilizes [Constraint Validation API](https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation) to enable custom validation constrains for a form control.
|
|
4
|
+
|
|
5
|
+
## Basic Usage
|
|
6
|
+
|
|
7
|
+
```vue
|
|
8
|
+
<script setup>
|
|
9
|
+
import { ref } from "vue";
|
|
10
|
+
import { useFormControl } from "vue-composable-ui";
|
|
11
|
+
|
|
12
|
+
const codeInput = ref();
|
|
13
|
+
|
|
14
|
+
const code = ref("");
|
|
15
|
+
const country = ref("");
|
|
16
|
+
|
|
17
|
+
const validateCode = (value) => {
|
|
18
|
+
const constraints = {
|
|
19
|
+
ch: [
|
|
20
|
+
"^(CH-)?\\d{4}$",
|
|
21
|
+
"Swiss postal codes must have exactly 4 digits: e.g. CH-1950 or 1950",
|
|
22
|
+
],
|
|
23
|
+
fr: [
|
|
24
|
+
"^(F-)?\\d{5}$",
|
|
25
|
+
"French postal codes must have exactly 5 digits: e.g. F-75012 or 75012",
|
|
26
|
+
],
|
|
27
|
+
de: [
|
|
28
|
+
"^(D-)?\\d{5}$",
|
|
29
|
+
"German postal codes must have exactly 5 digits: e.g. D-12345 or 12345",
|
|
30
|
+
],
|
|
31
|
+
nl: [
|
|
32
|
+
"^(NL-)?\\d{4}\\s*([A-RT-Z][A-Z]|S[BCE-RT-Z])$",
|
|
33
|
+
"Dutch postal codes must have exactly 4 digits, followed by 2 letters except SA, SD and SS",
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const constraint = new RegExp(constraints[country.value][0], "");
|
|
38
|
+
|
|
39
|
+
// Check it!
|
|
40
|
+
if (constraint.test(code.value)) {
|
|
41
|
+
// The postal code follows the constraint, we use the ConstraintAPI to tell it
|
|
42
|
+
return true;
|
|
43
|
+
} else {
|
|
44
|
+
// The postal code doesn't follow the constraint, we use the ConstraintAPI to
|
|
45
|
+
// give a message about the format required for this country
|
|
46
|
+
return constraints[country.value][1];
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const { validate } = useFormControl(codeInput, [validateCode]);
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<template>
|
|
54
|
+
<form>
|
|
55
|
+
<label for="postal-code">Postal Code: </label>
|
|
56
|
+
<input ref="codeInput" v-model="code" id="postal-code" />
|
|
57
|
+
<label for="country">Country: </label>
|
|
58
|
+
<select v-model="country" id="country">
|
|
59
|
+
<option value="ch">Switzerland</option>
|
|
60
|
+
<option value="fr">France</option>
|
|
61
|
+
<option value="de">Germany</option>
|
|
62
|
+
<option value="nl">The Netherlands</option>
|
|
63
|
+
</select>
|
|
64
|
+
<button type="button" @click="validate">Validate</button>
|
|
65
|
+
</form>
|
|
66
|
+
</template>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Type Declarations
|
|
70
|
+
|
|
71
|
+
### Composable
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
type FormElement = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* A validating function must return `true` or a string describing the error
|
|
78
|
+
*/
|
|
79
|
+
export type FormValidator = (value: string) => boolean | string;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Utilizes Constraint Validation API to enable custom validation constrains for a form control
|
|
83
|
+
*
|
|
84
|
+
* @param el A template ref or a CSS selector
|
|
85
|
+
* @param validators An array of validating functions
|
|
86
|
+
* @param showValidationError Whether to show the default browser validation error (true by default)
|
|
87
|
+
*
|
|
88
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation}
|
|
89
|
+
*/
|
|
90
|
+
export declare function useFormControl(
|
|
91
|
+
el: TemplateRefOrSelector<FormElement>,
|
|
92
|
+
validators?: MaybeRef<FormValidator[]>,
|
|
93
|
+
showValidationError?: MaybeRef<boolean>
|
|
94
|
+
): useFormControlReturn;
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Return Type
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
export interface useFormControlReturn {
|
|
101
|
+
/**
|
|
102
|
+
* Focus the form control
|
|
103
|
+
*/
|
|
104
|
+
focus: () => void;
|
|
105
|
+
/**
|
|
106
|
+
* Validate the form control
|
|
107
|
+
*
|
|
108
|
+
* @returns Validation result
|
|
109
|
+
*/
|
|
110
|
+
validate: () => boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Whether the form control is valid. A shorthand for `validity.valid`, but can be manually overriden.
|
|
113
|
+
*/
|
|
114
|
+
isValid: Ref<boolean>;
|
|
115
|
+
/**
|
|
116
|
+
* The validity state of the form control
|
|
117
|
+
*
|
|
118
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/ValidityState}
|
|
119
|
+
*/
|
|
120
|
+
validity: Readonly<Ref<ValidityState | undefined>>;
|
|
121
|
+
/**
|
|
122
|
+
* A string representing a localized message that describes the validation constraints that the control does not satisfy (if any)
|
|
123
|
+
*/
|
|
124
|
+
validationMessage: Readonly<Ref<string>>;
|
|
125
|
+
/**
|
|
126
|
+
* Whether the value has been changed since the form control was mounted
|
|
127
|
+
*/
|
|
128
|
+
isChanged: Ref<boolean>;
|
|
129
|
+
}
|
|
130
|
+
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# useListOption
|
|
2
|
+
|
|
3
|
+
`useListOption` is meant to be used in a child component representing a list item inside a parent component that uses the [`useList`](/composables/list) composable.
|
|
4
|
+
|
|
5
|
+
See the [Basic Usage](/composables/list#basic-usage) example.
|
|
6
|
+
|
|
7
|
+
## Type Declarations
|
|
8
|
+
|
|
9
|
+
### Composable
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
/**
|
|
13
|
+
* Registers an HTML element and an associated value in the list created in the parent component
|
|
14
|
+
*
|
|
15
|
+
* @param el A template ref or a CSS selector
|
|
16
|
+
* @param value A value of any type to associate with the HTML element
|
|
17
|
+
* @param disabled Whether the item is disabled (false by default)
|
|
18
|
+
*/
|
|
19
|
+
export declare function useListOption(
|
|
20
|
+
el: HTMLElementType,
|
|
21
|
+
value: ItemValue,
|
|
22
|
+
disabled?: MaybeRef<boolean>
|
|
23
|
+
): UseListOptionReturn;
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Return Type
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
interface UseListOptionReturn {
|
|
30
|
+
/**
|
|
31
|
+
* Whether the item is selected
|
|
32
|
+
*/
|
|
33
|
+
isSelected: ComputedRef<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the item is active
|
|
36
|
+
*/
|
|
37
|
+
isActive: ComputedRef<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Select the item
|
|
40
|
+
*/
|
|
41
|
+
select: () => void;
|
|
42
|
+
/**
|
|
43
|
+
* Activate the item
|
|
44
|
+
*/
|
|
45
|
+
activate: () => void;
|
|
46
|
+
}
|
|
47
|
+
```
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# useList
|
|
2
|
+
|
|
3
|
+
The composable implements single/multi-selection and navigation functionality for a list of HTML elements. It can be used to power a wide range of components: tabs, button groups, radio groups, comboboxes and all kinds of components where user has to select one or more values from a list.
|
|
4
|
+
|
|
5
|
+
`useList` is meant to be used in conjunction with the [`useListOption`](/composables/list-option) composable.
|
|
6
|
+
|
|
7
|
+
## Basic Usage
|
|
8
|
+
|
|
9
|
+
::: code-group
|
|
10
|
+
|
|
11
|
+
```vue [example.vue]
|
|
12
|
+
<script setup>
|
|
13
|
+
import { ref } from 'vue'
|
|
14
|
+
|
|
15
|
+
const value = ref()
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<template>
|
|
19
|
+
Selected value: {{value}}
|
|
20
|
+
<List v-model="value">
|
|
21
|
+
<Item value="1">Item 1</Item>
|
|
22
|
+
<Item value="2">Item 2</Item>
|
|
23
|
+
<Item value="3" :disabled="true">Item 3</Item>
|
|
24
|
+
<List>
|
|
25
|
+
</template>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```vue [list.vue]
|
|
29
|
+
<script setup>
|
|
30
|
+
import { useList } from "vue-composable-ui";
|
|
31
|
+
|
|
32
|
+
const model = defineModel();
|
|
33
|
+
const list = useList(model);
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<template>
|
|
37
|
+
<div>
|
|
38
|
+
<slot />
|
|
39
|
+
</div>
|
|
40
|
+
</template>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```vue [item.vue]
|
|
44
|
+
<script setup>
|
|
45
|
+
import { useListOption } from "vue-composable-ui";
|
|
46
|
+
import { ref } from "vue";
|
|
47
|
+
|
|
48
|
+
const props = defineProps<{
|
|
49
|
+
value: any;
|
|
50
|
+
disabled?: boolean;
|
|
51
|
+
}>()
|
|
52
|
+
|
|
53
|
+
const itemEl = ref<HTMLElement>()
|
|
54
|
+
const option = useListOption(itemEl, props.value, props.disabled);
|
|
55
|
+
|
|
56
|
+
const onClick = () => option.select();
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<template>
|
|
60
|
+
<div ref="itemEl" @click="onClick">
|
|
61
|
+
<slot />
|
|
62
|
+
</div>
|
|
63
|
+
</template>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
:::
|
|
67
|
+
|
|
68
|
+
## Type Declarations
|
|
69
|
+
|
|
70
|
+
### Composable
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
/**
|
|
74
|
+
* Creates a reactive list of HTML elements with assigned values.
|
|
75
|
+
*
|
|
76
|
+
* @param value A ref to store the list value. Set to an array to enable multiselection.
|
|
77
|
+
*/
|
|
78
|
+
export declare function useList(value: Ref<unknown>): UseListReturn;
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Return Type
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
export type ItemValue = unknown;
|
|
85
|
+
export interface Item {
|
|
86
|
+
id: number;
|
|
87
|
+
element: Ref<HTMLElement | undefined>;
|
|
88
|
+
value: ItemValue;
|
|
89
|
+
disabled: MaybeRef<boolean>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
interface ActivationOptions {
|
|
93
|
+
/**
|
|
94
|
+
* Focus the corresponding HTML element
|
|
95
|
+
*
|
|
96
|
+
* @defaultValue false
|
|
97
|
+
*/
|
|
98
|
+
focus?: boolean;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
interface NavigationOptions {
|
|
102
|
+
/**
|
|
103
|
+
* Infinitely cycle throught the items
|
|
104
|
+
*
|
|
105
|
+
* @defaultValue false
|
|
106
|
+
*/
|
|
107
|
+
loop?: boolean;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface UseListReturn {
|
|
111
|
+
/**
|
|
112
|
+
* Array of items
|
|
113
|
+
*/
|
|
114
|
+
items: Readonly<ShallowRef<Item[]>>;
|
|
115
|
+
/**
|
|
116
|
+
* Multiselection flag
|
|
117
|
+
*/
|
|
118
|
+
isMultiselectable: Readonly<Ref<boolean>>;
|
|
119
|
+
/**
|
|
120
|
+
* Currently active item
|
|
121
|
+
*/
|
|
122
|
+
activeItem: ComputedRef<Item | undefined>;
|
|
123
|
+
/**
|
|
124
|
+
* Select the currently active item
|
|
125
|
+
*/
|
|
126
|
+
selectActiveItem: () => void;
|
|
127
|
+
/**
|
|
128
|
+
* Activate the currently selected item
|
|
129
|
+
*/
|
|
130
|
+
activateSelectedItem: (options?: ActivationOptions) => void;
|
|
131
|
+
/**
|
|
132
|
+
* Activate the first item
|
|
133
|
+
*/
|
|
134
|
+
activateFirstItem: (options?: ActivationOptions) => void;
|
|
135
|
+
/**
|
|
136
|
+
* Activate the last item
|
|
137
|
+
*/
|
|
138
|
+
activateLastItem: (options?: ActivationOptions) => void;
|
|
139
|
+
/**
|
|
140
|
+
* Activate next item
|
|
141
|
+
*/
|
|
142
|
+
activateNextItem: (options?: ActivationOptions & NavigationOptions) => void;
|
|
143
|
+
/**
|
|
144
|
+
* Activate previous item
|
|
145
|
+
*/
|
|
146
|
+
activatePrevItem: (options?: ActivationOptions & NavigationOptions) => void;
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Injection Key
|
|
151
|
+
|
|
152
|
+
> [!NOTE]
|
|
153
|
+
> List items get unique ids that are not equal to their indexes in the `items` array returned by the composable. You need to access `item.id` to get its id value.
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
interface UseListInjectionKey {
|
|
157
|
+
/**
|
|
158
|
+
* The list value
|
|
159
|
+
*/
|
|
160
|
+
value: Readonly<Ref<unknown>>;
|
|
161
|
+
/**
|
|
162
|
+
* Select an item by ID
|
|
163
|
+
*/
|
|
164
|
+
selectItem: (itemId: number) => void;
|
|
165
|
+
/**
|
|
166
|
+
* Activate an item by ID
|
|
167
|
+
*/
|
|
168
|
+
activateItem: (itemId: number, options?: ActivationOptions) => void;
|
|
169
|
+
/**
|
|
170
|
+
* Check if an item is selected
|
|
171
|
+
*/
|
|
172
|
+
isSelected: (itemId: number) => boolean;
|
|
173
|
+
/**
|
|
174
|
+
* Check if an item is active
|
|
175
|
+
*/
|
|
176
|
+
isActive: (itemId: number) => boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Add an item to the list
|
|
179
|
+
*
|
|
180
|
+
* @returns New item ID
|
|
181
|
+
*/
|
|
182
|
+
addItem: (
|
|
183
|
+
itemEl: HTMLElementType,
|
|
184
|
+
itemVal: ItemValue,
|
|
185
|
+
disabled?: MaybeRef<boolean>
|
|
186
|
+
) => number;
|
|
187
|
+
/**
|
|
188
|
+
* Remove an item from the list by ID
|
|
189
|
+
*/
|
|
190
|
+
removeItem: (itemId: number) => void;
|
|
191
|
+
}
|
|
192
|
+
```
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# usePopover
|
|
2
|
+
|
|
3
|
+
Popover is a floating container that appears next to its activator element above the main document flow. It can be used as a basic component for dropdown menus, comboboxes, tooltips, and more.
|
|
4
|
+
|
|
5
|
+
The composable abstracts the logic of positioning a popover relative to its activating element and captures clicks to automatically close the popover.
|
|
6
|
+
|
|
7
|
+
No event listeners are attached to the activating element to give the user full control over the way the popover is triggered.
|
|
8
|
+
|
|
9
|
+
## Type Declarations
|
|
10
|
+
|
|
11
|
+
### Composable
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
interface UsePopoverOptions {
|
|
15
|
+
/**
|
|
16
|
+
* The direction of the popover dialog
|
|
17
|
+
*
|
|
18
|
+
* @defaultValue `"down"`
|
|
19
|
+
*/
|
|
20
|
+
direction?: "up" | "down" | "left" | "right";
|
|
21
|
+
/**
|
|
22
|
+
* The alignment of the popover dialog
|
|
23
|
+
*
|
|
24
|
+
* @defaultValue `"left"`
|
|
25
|
+
*/
|
|
26
|
+
align?: "top" | "bottom" | "left" | "right" | "center" | "stretch";
|
|
27
|
+
/**
|
|
28
|
+
* The CSS position of the popover dialog
|
|
29
|
+
*
|
|
30
|
+
* @defaultValue `"fixed"`
|
|
31
|
+
*/
|
|
32
|
+
position?: "fixed" | "absolute";
|
|
33
|
+
/**
|
|
34
|
+
* Close the popover on a click outside of the dialog
|
|
35
|
+
*
|
|
36
|
+
* @defaultValue `true`
|
|
37
|
+
*/
|
|
38
|
+
closeOnOutsideClick?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Close the popover on a click inside of the dialog
|
|
41
|
+
*
|
|
42
|
+
* @defaultValue `false`
|
|
43
|
+
*/
|
|
44
|
+
closeOnInsideClick?: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* @param activatorEl A template ref or a CSS selector
|
|
50
|
+
* @param popupEl A template ref or a CSS selector
|
|
51
|
+
* @param options Popover options
|
|
52
|
+
*/
|
|
53
|
+
export declare function usePopover(
|
|
54
|
+
activatorEl: TemplateRefOrSelector,
|
|
55
|
+
popupEl: TemplateRefOrSelector,
|
|
56
|
+
options?: UsePopoverOptions
|
|
57
|
+
): UsePopoverReturn;
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Return Type
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
interface FocusOptions {
|
|
64
|
+
/**
|
|
65
|
+
* Focus the popover/activator
|
|
66
|
+
*
|
|
67
|
+
* @defaultValue `true`
|
|
68
|
+
*/
|
|
69
|
+
focus?: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface UsePopoverReturn {
|
|
73
|
+
/**
|
|
74
|
+
* The popover state
|
|
75
|
+
*/
|
|
76
|
+
isOpen: Ref<boolean>;
|
|
77
|
+
/**
|
|
78
|
+
* Open the popover
|
|
79
|
+
*/
|
|
80
|
+
open: (options?: FocusOptions) => void;
|
|
81
|
+
/**
|
|
82
|
+
* Close the popover
|
|
83
|
+
*/
|
|
84
|
+
close: (options?: FocusOptions) => void;
|
|
85
|
+
/**
|
|
86
|
+
* Toggle the popover
|
|
87
|
+
*/
|
|
88
|
+
toggle: (options?: FocusOptions) => void;
|
|
89
|
+
}
|
|
90
|
+
```
|
package/docs/index.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
# https://vitepress.dev/reference/default-theme-home-page
|
|
3
|
+
layout: home
|
|
4
|
+
|
|
5
|
+
hero:
|
|
6
|
+
name: "Vue Composable UI"
|
|
7
|
+
text: "A truly headless UI framework"
|
|
8
|
+
tagline: My great project tagline
|
|
9
|
+
actions:
|
|
10
|
+
- theme: brand
|
|
11
|
+
text: Introduction
|
|
12
|
+
link: /intro
|
|
13
|
+
- theme: alt
|
|
14
|
+
text: API Examples
|
|
15
|
+
link: /api-examples
|
|
16
|
+
|
|
17
|
+
features:
|
|
18
|
+
- title: Feature A
|
|
19
|
+
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
|
|
20
|
+
- title: Feature B
|
|
21
|
+
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
|
|
22
|
+
- title: Feature C
|
|
23
|
+
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
|
|
24
|
+
---
|
package/docs/intro.md
ADDED
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vue-composable-ui",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"repository": "https://github.com/dzapletin/vue-composable-ui",
|
|
6
|
+
"main": "./dist/composable-ui.umd.cjs",
|
|
7
|
+
"module": "./dist/composable-ui.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/composable-ui.js",
|
|
11
|
+
"require": "./dist/composable-ui.umd.cjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"types": "./dist/types/main.d.ts",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"dev": "vite",
|
|
17
|
+
"build": "vite build && vue-tsc",
|
|
18
|
+
"preview": "vite preview",
|
|
19
|
+
"docs:dev": "vitepress dev docs",
|
|
20
|
+
"docs:build": "vitepress build docs",
|
|
21
|
+
"docs:preview": "vitepress preview docs"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"vue": "^3.3.4"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^22.4.0",
|
|
28
|
+
"@vitejs/plugin-vue": "^5.1.2",
|
|
29
|
+
"sass": "^1.69.5",
|
|
30
|
+
"typescript": "^5.0.2",
|
|
31
|
+
"vite": "^5.4.1",
|
|
32
|
+
"vitepress": "^1.0.0-rc.24",
|
|
33
|
+
"vue-tsc": "^2.0.29"
|
|
34
|
+
}
|
|
35
|
+
}
|