style(projects): format code

This commit is contained in:
Soybean
2023-12-14 21:45:29 +08:00
parent a176dc443e
commit a748166399
127 changed files with 2472 additions and 3006 deletions

View File

@ -1,8 +1,9 @@
import { ref } from 'vue';
/**
* boolean
* @param initValue init value
* Boolean
*
* @param initValue Init value
*/
export default function useBoolean(initValue = false) {
const bool = ref(initValue);

View File

@ -2,61 +2,60 @@ import { inject, provide } from 'vue';
import type { InjectionKey } from 'vue';
/**
* use context
* @param contextName context name
* @param fn context function
* Use context
*
* @example
* ```ts
* // there are three vue files: A.vue, B.vue, C.vue, and A.vue is the parent component of B.vue and C.vue
* ```ts
* // there are three vue files: A.vue, B.vue, C.vue, and A.vue is the parent component of B.vue and C.vue
*
* // context.ts
* import { ref } from 'vue';
* import { useContext } from '@sa/hooks';
* // context.ts
* import { ref } from 'vue';
* import { useContext } from '@sa/hooks';
*
* export const { setupStore, useStore } = useContext('demo', () => {
* const count = ref(0);
* export const { setupStore, useStore } = useContext('demo', () => {
* const count = ref(0);
*
* function increment() {
* count.value++;
* }
* function increment() {
* count.value++;
* }
*
* function decrement() {
* count.value--;
* }
* function decrement() {
* count.value--;
* }
*
* return {
* count,
* increment,
* decrement
* };
* })
* ```
* return {
* count,
* increment,
* decrement
* };
* })
* ``` // A.vue
* ```vue
* <template>
* <div>A</div>
* </template>
* <script setup lang="ts">
* import { setupStore } from './context';
*
* // A.vue
* ```vue
* <template>
* <div>A</div>
* </template>
* <script setup lang="ts">
* import { setupStore } from './context';
* setupStore();
* // const { increment } = setupStore(); // also can control the store in the parent component
* </script>
* ``` // B.vue
* ```vue
* <template>
* <div>B</div>
* </template>
* <script setup lang="ts">
* import { useStore } from './context';
*
* setupStore();
* // const { increment } = setupStore(); // also can control the store in the parent component
* </script>
* ```
* // B.vue
* ```vue
* <template>
* <div>B</div>
* </template>
* <script setup lang="ts">
* import { useStore } from './context';
* const { count, increment } = useStore();
* </script>
* ```;
*
* const { count, increment } = useStore();
* </script>
* ```
* // C.vue is same as B.vue
*
* // C.vue is same as B.vue
* @param contextName Context name
* @param fn Context function
*/
export default function useContext<T extends (...args: any[]) => any>(contextName: string, fn: T) {
type Context = ReturnType<T>;
@ -69,20 +68,14 @@ export default function useContext<T extends (...args: any[]) => any>(contextNam
}
return {
/**
* setup store in the parent component
*/
/** Setup store in the parent component */
setupStore,
/**
* use store in the child component
*/
/** Use store in the child component */
useStore
};
}
/**
* create context
*/
/** Create context */
function createContext<T>(contextName: string) {
const injectKey: InjectionKey<T> = Symbol(contextName);

View File

@ -1,8 +1,9 @@
import useBoolean from './use-boolean';
/**
* loading
* @param initValue init value
* Loading
*
* @param initValue Init value
*/
export default function useLoading(initValue = false) {
const { bool: loading, setTrue: startLoading, setFalse: endLoading } = useBoolean(initValue);

View File

@ -2,33 +2,27 @@ import { h } from 'vue';
import type { Component } from 'vue';
/**
* svg icon render hook
* @param SvgIcon svg icon component
* Svg icon render hook
*
* @param SvgIcon Svg icon component
*/
export default function useSvgIconRender(SvgIcon: Component) {
interface IconConfig {
/**
* iconify icon name
*/
/** Iconify icon name */
icon?: string;
/**
* local icon name
*/
/** Local icon name */
localIcon?: string;
/**
* icon color
*/
/** Icon color */
color?: string;
/**
* icon size
*/
/** Icon size */
fontSize?: number;
}
type IconStyle = Partial<Pick<CSSStyleDeclaration, 'color' | 'fontSize'>>;
/**
* svg icon VNode
* Svg icon VNode
*
* @param config
*/
const SvgIconVNode = (config: IconConfig) => {