@naptics/vue-collection 0.1.2 → 0.1.3

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.
@@ -1,7 +1,7 @@
1
1
  import type { HeroIcon } from '../utils/tailwind';
2
2
  import type { TWTextSize } from '../utils/tailwind';
3
- import type { PropType } from 'vue';
4
3
  import type { RouteLocationRaw } from 'vue-router';
4
+ import type { PropType } from 'vue';
5
5
  export declare const nBreadcrumbProps: {
6
6
  /**
7
7
  * The items of the breadcrumb.
@@ -42,6 +42,10 @@ export declare const nBreadcrumbProps: {
42
42
  * Adds the classes to the top-level element.
43
43
  */
44
44
  readonly addClass: StringConstructor;
45
+ /**
46
+ * Adds the classes to the separator icons.
47
+ */
48
+ readonly addIconClass: StringConstructor;
45
49
  /**
46
50
  * A slot the replace the breadcrumb labels.
47
51
  */
@@ -105,6 +109,10 @@ declare const _default: import("vue").DefineComponent<{
105
109
  * Adds the classes to the top-level element.
106
110
  */
107
111
  readonly addClass: StringConstructor;
112
+ /**
113
+ * Adds the classes to the separator icons.
114
+ */
115
+ readonly addIconClass: StringConstructor;
108
116
  /**
109
117
  * A slot the replace the breadcrumb labels.
110
118
  */
@@ -154,6 +162,10 @@ declare const _default: import("vue").DefineComponent<{
154
162
  * Adds the classes to the top-level element.
155
163
  */
156
164
  readonly addClass: StringConstructor;
165
+ /**
166
+ * Adds the classes to the separator icons.
167
+ */
168
+ readonly addIconClass: StringConstructor;
157
169
  /**
158
170
  * A slot the replace the breadcrumb labels.
159
171
  */
@@ -1,5 +1,5 @@
1
1
  import { createVNode as _createVNode, Fragment as _Fragment } from "vue";
2
- import { createComponent } from '../utils/component';
2
+ import { createComponentWithSlots } from '../utils/component';
3
3
  import { ChevronRightIcon } from '@heroicons/vue/24/solid';
4
4
  import NLink from './NLink';
5
5
  export const nBreadcrumbProps = {
@@ -42,6 +42,10 @@ export const nBreadcrumbProps = {
42
42
  * Adds the classes to the top-level element.
43
43
  */
44
44
  addClass: String,
45
+ /**
46
+ * Adds the classes to the separator icons.
47
+ */
48
+ addIconClass: String,
45
49
  /**
46
50
  * A slot the replace the breadcrumb labels.
47
51
  */
@@ -55,7 +59,7 @@ export const nBreadcrumbProps = {
55
59
  /**
56
60
  * The `NBreadcrumb` is a styled breadcrumb which can be used as a navigation in hierarchical views.
57
61
  */
58
- export default createComponent('NBreadcrumb', nBreadcrumbProps, props => {
62
+ export default createComponentWithSlots('NBreadcrumb', nBreadcrumbProps, ['seperator', 'item'], props => {
59
63
  return () => _createVNode("div", {
60
64
  "class": `flex flex-wrap items-center ${props.addClass}`
61
65
  }, [props.items.map((item, index) => _createVNode(_Fragment, null, [props.item?.(item, index) || _createVNode(NLink, {
@@ -65,6 +69,6 @@ export default createComponent('NBreadcrumb', nBreadcrumbProps, props => {
65
69
  }, {
66
70
  default: () => [item.label]
67
71
  }), index < props.items.length - 1 && (props.seperator?.(item, index) || _createVNode(props.icon, {
68
- "class": `mx-2 w-${props.iconSize} h-${props.iconSize} text-${props.color}-500`
72
+ "class": `mx-2 w-${props.iconSize} h-${props.iconSize} text-${props.color}-500 ${props.addIconClass}`
69
73
  }, null))]))]);
70
74
  });
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@naptics/vue-collection",
3
3
  "author": "Timo Siegenthaler",
4
4
  "description": "Vue Collection is a collection of styled and fully functional Vue components which can easily be integrated into our projects.",
5
- "version": "0.1.2",
5
+ "version": "0.1.3",
6
6
  "main": "./index.js",
7
7
  "repository": {
8
8
  "type": "git",
@@ -1,7 +1,8 @@
1
1
  import type { LooseRequired } from '@vue/shared';
2
2
  import { type ComponentObjectPropsOptions, type ExtractPropTypes, type RenderFunction, type SetupContext, type ToRefs, type UnwrapNestedRefs } from 'vue';
3
+ import type { AnyObject } from './utils';
3
4
  type Data = Record<string, unknown>;
4
- export type Props<T = Data> = ComponentObjectPropsOptions<T>;
5
+ export type Props<T extends Data = Data> = ComponentObjectPropsOptions<T>;
5
6
  /**
6
7
  * `ExtractedProps` maps a prop object to the props, which are received in the `setup` function of a components.
7
8
  */
@@ -19,6 +20,16 @@ export type ExtractedProps<T extends Props> = Readonly<LooseRequired<Readonly<Ex
19
20
  export declare function createComponent<T extends Props>(name: string, props: T, setup: (props: ExtractedProps<T>, context: SetupContext<never[]>) => RenderFunction | Promise<RenderFunction>): import("vue").DefineComponent<T, RenderFunction, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, never[], never, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<T extends import("vue").ComponentPropsOptions<{
20
21
  [x: string]: unknown;
21
22
  }> ? ExtractPropTypes<T> : T> & {}, import("vue").ExtractDefaultPropTypes<T>>;
23
+ /**
24
+ * When using this function, the created component will make available all props
25
+ * specifiedin `slotPropKeys` as slot. In this way, they can be used by either setting
26
+ * the prop directly or by using a slot with the same name. This is useful for older
27
+ * components (in `.vue` files), because they are dependent on slots.
28
+ * @see {@link createComponent}
29
+ */
30
+ export declare function createComponentWithSlots<T extends Props>(name: string, props: T, slotPropKeys: SlotPropsKeys<ExtractedProps<T>>, setup: (props: ExtractedProps<T>, context: SetupContext<never[]>) => RenderFunction | Promise<RenderFunction>): import("vue").DefineComponent<T, RenderFunction, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, never[], never, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<T extends import("vue").ComponentPropsOptions<{
31
+ [x: string]: unknown;
32
+ }> ? ExtractPropTypes<T> : T> & {}, import("vue").ExtractDefaultPropTypes<T>>;
22
33
  /**
23
34
  * Views should be created using this helper function. Views are special components, which don't have props.
24
35
  * They are often the parent objects in a view hierarchy and contain many components.
@@ -39,4 +50,12 @@ export declare function createView(name: string, setup: (context: SetupContext<n
39
50
  * console.log(childProps) // { title: 'hi' }
40
51
  */
41
52
  export declare function extractProps<T extends Record<string, unknown>>(props: T, ...keys: (keyof T)[]): UnwrapNestedRefs<Partial<ToRefs<T>>>;
53
+ type SlotFunction<Args extends any[] = any[]> = (...args: Args) => JSX.Element;
54
+ /**
55
+ * Filters object T to only have properties of type K.
56
+ */
57
+ type FilterObject<T, K> = {
58
+ [P in keyof T as T[P] extends K ? P : never]: T[P];
59
+ };
60
+ type SlotPropsKeys<T extends AnyObject> = (keyof FilterObject<T, SlotFunction | undefined>)[];
42
61
  export {};
@@ -1,41 +0,0 @@
1
- import { defineComponent, reactive, toRef, } from 'vue';
2
- /**
3
- * Components should be created using this helper function.
4
- * It only takes three arguments, the name and the props of the component and the setup function.
5
- * All other arguments which the {@link defineComponent} method of vue may provide,
6
- * should not be used for a better consistency across all components.
7
- * @param name the name of the component, should be more than one word.
8
- * @param props the props of the component.
9
- * @param setup the setup function, which will be called when the component is mounted.
10
- * @returns the created vue-component.
11
- */
12
- export function createComponent(name, props, setup) {
13
- return defineComponent({ name, props, emits: [], setup });
14
- }
15
- /**
16
- * Views should be created using this helper function. Views are special components, which don't have props.
17
- * They are often the parent objects in a view hierarchy and contain many components.
18
- * This function is syntactic sugar to create views and just calls {@link createComponent}.
19
- * @param name the name of the component, should be more than one word.
20
- * @param setup the setup function, which will be called when the component is mounted.
21
- * @returns the created vue-component.
22
- */
23
- export function createView(name, setup) {
24
- return defineComponent({ name, emits: [], setup: (props, context) => setup(context) });
25
- }
26
- /**
27
- * Extracts props from another prop object and returns a reactive object with the specified props.
28
- * @param props the props to extract from
29
- * @param keys the keys to extract from the props
30
- * @returns the new object with the specified props
31
- * @example
32
- * const parentProps = { title: 'hi', text: 'ho' }
33
- * const childProps = extractProps(parentProps, 'title')
34
- * console.log(childProps) // { title: 'hi' }
35
- */
36
- export function extractProps(props, ...keys) {
37
- const partial = {};
38
- for (const key of keys)
39
- partial[key] = toRef(props, key);
40
- return reactive(partial);
41
- }