Skip to content

Commit 5f90fcb

Browse files
committed
feat: add utils and compossable example
1 parent c593d38 commit 5f90fcb

16 files changed

Lines changed: 189 additions & 0 deletions

File tree

src/App.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- src/App.vue -->
12
<script setup lang="ts">
23
import { computed } from 'vue';
34
import { RouterView, useRoute } from 'vue-router';

src/components/common/AppHeader.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- src/components/common/AppHeader.vue -->
12
<script setup lang="ts">
23
import { RouterLink } from 'vue-router';
34
</script>

src/components/common/BaseButton.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- src/components/common/BaseButton.vue -->
12
<script setup lang="ts">
23
type Props = {
34
variant?: 'primary' | 'secondary' | 'danger';

src/composables/.gitkeep

Whitespace-only changes.

src/composables/use-toggle.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// src/composables/useToggle.ts
2+
import type { Ref } from 'vue';
3+
4+
import { ref } from 'vue';
5+
6+
/**
7+
* A simple composable to manage boolean state.
8+
* Useful for modals, menus, and switch toggles.
9+
*/
10+
export function useToggle(initialValue: boolean = false) {
11+
const value: Ref<boolean> = ref(initialValue);
12+
13+
/**
14+
* Explicitly sets the value to true.
15+
*/
16+
const on = (): void => {
17+
value.value = true;
18+
};
19+
20+
/**
21+
* Explicitly sets the value to false.
22+
*/
23+
const off = (): void => {
24+
value.value = false;
25+
};
26+
27+
/**
28+
* Toggles the current value.
29+
*/
30+
const toggle = (newValue?: boolean): void => {
31+
if (typeof newValue === 'boolean') {
32+
value.value = newValue;
33+
}
34+
else {
35+
value.value = !value.value;
36+
}
37+
};
38+
39+
return {
40+
value,
41+
on,
42+
off,
43+
toggle,
44+
};
45+
}

src/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// src/env.d.ts
12
/// <reference types="vite/client" />
23

34
declare module '*.vue' {

src/layouts/BlankLayout.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- src/layouts/BlankLayout.vue -->
12
<template>
23
<div class="min-h-screen flex flex-col justify-center items-center bg-gray-50">
34
<slot />

src/layouts/DefaultLayout.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- src/layouts/DefaultLayout.vue -->
12
<script setup lang="ts">
23
import AppHeader from '@/components/common/AppHeader.vue';
34
</script>

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// src/main.ts
12
import { createPinia } from 'pinia';
23
import { createApp } from 'vue';
34

src/stores/counter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// src/stores/counter.ts
12
import { defineStore } from 'pinia';
23
import { computed, ref } from 'vue';
34

0 commit comments

Comments
 (0)