Skip to content

Commit 75373bd

Browse files
committed
tab component added
1 parent 6d5645a commit 75373bd

File tree

5 files changed

+180
-7
lines changed

5 files changed

+180
-7
lines changed

demo-app/src/App.vue

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
<template>
2-
<SketchyDiv class="pd" style="margin-bottom: 10px;">INsied</SketchyDiv>
3-
<SketchyBtn label="Click" style="padding: 10px 5px; font-size: 18px; margin-bottom: 100px;"/>
2+
<SketchyDiv class="pd" style="margin-bottom: 10px">INsied</SketchyDiv>
3+
<SketchyBtn
4+
label="Click"
5+
style="padding: 10px 5px; font-size: 18px; margin-bottom: 100px"
6+
/>
47
<SketchyHLine />
8+
<div>NEXT</div>
9+
<br />
10+
<SketchyTabs v-model="tab">
11+
<SketchyTab name="focuz" label="Focuz Time" />
12+
<SketchyTab name="short" label="Short Break" />
13+
<SketchyTab name="long" label="Long Break" />
14+
</SketchyTabs>
515
</template>
616

717
<script setup>
8-
import { SketchyDiv } from "codeglynuikit";
9-
import { SketchyBtn } from "codeglynuikit";
10-
import { SketchyHLine } from "codeglynuikit";
18+
import { SketchyDiv, SketchyBtn, SketchyHLine, SketchyTab, SketchyTabs } from "codeglynuikit";
19+
import { ref } from "vue";
20+
21+
const tab = ref("focuz")
22+
1123
</script>
1224

1325
<style>

lib/src/components/sketchybtn/SketchyBtn.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import { computed, h, onMounted, ref, useCssModule } from "vue";
2+
import { computed, h, ref, useCssModule } from "vue";
33
import SketchyDiv from "../sketchydiv/SketchyDiv.vue";
44
55
export default {
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<script>
2+
import { computed, h, inject, onMounted, onUpdated, ref, useCssModule, watch } from 'vue'
3+
import SketchyDiv from "../sketchydiv/SketchyDiv.vue";
4+
5+
export default {
6+
name: 'SketchyTab',
7+
8+
props: {
9+
label: String,
10+
name: String
11+
},
12+
13+
setup(props, {}) {
14+
const $tabs = inject('_sketchy_tabs_')
15+
const defaultWdith = 2
16+
const hoverDist = 6
17+
const activationDist = 10
18+
const style = useCssModule()
19+
const classes = computed(() => {
20+
let updatedClasses
21+
if (props.class) {
22+
updatedClasses = `${style.container}` + ' ' + props.class
23+
} else {
24+
updatedClasses = `${style.container}`
25+
}
26+
return updatedClasses
27+
})
28+
const isActive = ref($tabs.currentModel.value === props.name)
29+
30+
watch($tabs.currentModel, () => {
31+
isActive.value = $tabs.currentModel.value === props.name
32+
calculateWidthNormal()
33+
})
34+
const nodeProps = ref({
35+
options: {
36+
seed: 9,
37+
strokeWidth: defaultWdith
38+
},
39+
class: classes.value,
40+
onmouseenter: hoverCallback,
41+
onmouseleave: unhoverCallback,
42+
onClick
43+
})
44+
45+
function calculateWidthHover() {
46+
if (isActive.value) {
47+
nodeProps.value.options.strokeWidth = hoverDist + activationDist
48+
} else {
49+
nodeProps.value.options.strokeWidth = hoverDist
50+
}
51+
}
52+
53+
function calculateWidthNormal() {
54+
if (isActive.value) {
55+
nodeProps.value.options.strokeWidth = activationDist
56+
} else {
57+
nodeProps.value.options.strokeWidth = defaultWdith
58+
}
59+
}
60+
function onClick(e) {
61+
$tabs.updateModel(props.name)
62+
}
63+
function hoverCallback() {
64+
65+
calculateWidthHover()
66+
}
67+
function unhoverCallback() {
68+
calculateWidthNormal()
69+
}
70+
71+
onMounted(() => {
72+
isActive.value = $tabs.currentModel.value === props.name
73+
calculateWidthNormal()
74+
})
75+
76+
onUpdated(() => {})
77+
78+
return () => h(SketchyDiv, nodeProps.value, { default: () => props.label })
79+
}
80+
}
81+
</script>
82+
83+
<style module>
84+
.container {
85+
text-align: center;
86+
padding: 10px 30px;
87+
cursor: pointer;
88+
user-select: none;
89+
}
90+
</style>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<script>
2+
import {
3+
computed,
4+
h,
5+
onMounted,
6+
onUpdated,
7+
provide,
8+
ref,
9+
useCssModule,
10+
} from "vue";
11+
import SketchyDiv from "../sketchydiv/SketchyDiv.vue";
12+
13+
export default {
14+
name: "SketchyTabs",
15+
16+
props: {
17+
modelValue: String,
18+
},
19+
20+
setup(props, { slots, emit }) {
21+
const currentModel = computed(() => props.modelValue);
22+
const $tabs = {
23+
currentModel,
24+
updateModel,
25+
};
26+
provide("_sketchy_tabs_", $tabs);
27+
const divRef = ref(null);
28+
const style = useCssModule();
29+
const classes = computed(() => {
30+
let updatedClasses;
31+
if (props.class) {
32+
updatedClasses = `${style.container}` + " " + props.class;
33+
} else {
34+
updatedClasses = `${style.container}`;
35+
}
36+
return updatedClasses;
37+
});
38+
39+
function updateModel(name) {
40+
emit("update:modelValue", name);
41+
}
42+
43+
onMounted(() => {});
44+
45+
onUpdated(() => {});
46+
47+
return () => {
48+
return h(
49+
SketchyDiv,
50+
{
51+
class: classes.value,
52+
ref: divRef,
53+
},
54+
{
55+
default: () => (slots.default ? slots.default() : []),
56+
}
57+
);
58+
};
59+
},
60+
};
61+
</script>
62+
63+
<style module>
64+
.container {
65+
display: flex;
66+
justify-content: center;
67+
align-items: center;
68+
}
69+
</style>

lib/src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import SketchyDiv from "./components/sketchydiv/SketchyDiv.vue";
22
import SketchyBtn from "./components/sketchybtn/SketchyBtn.vue";
33
import SketchyHLine from "./components/sketchyhline/SketchyHLine.vue";
4+
import SketchyTabs from "./components/sketchytab/SketchyTabs.vue"
5+
import SketchyTab from "./components/sketchytab/SketchyTab.vue"
46

5-
export { SketchyDiv, SketchyBtn, SketchyHLine };
7+
export { SketchyDiv, SketchyBtn, SketchyHLine, SketchyTabs, SketchyTab };

0 commit comments

Comments
 (0)