Skip to content
This repository was archived by the owner on Jan 9, 2022. It is now read-only.

Commit 440fc12

Browse files
committed
refactor: upgrade demo
1 parent 5dd3003 commit 440fc12

File tree

11 files changed

+268
-96
lines changed

11 files changed

+268
-96
lines changed

src/App.vue

Lines changed: 3 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,17 @@
11
<template>
22
<div class="app">
3-
<GDialog v-model="dialogState" max-width="400">
4-
<div class="text-box">
5-
<div>
6-
Header
7-
</div>
8-
<p v-for="i in 6" :key="i">
9-
Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas porro
10-
aliquid sunt expedita possimus ipsam nihil magni eos quam beatae
11-
repellat neque totam quidem reiciendis, incidunt commodi sequi, minus
12-
accusantium?
13-
</p>
14-
<div>
15-
Footer
16-
</div>
17-
</div>
18-
</GDialog>
19-
20-
<GDialog
21-
v-model="dialogState2"
22-
max-width="400"
23-
scrollable
24-
>
25-
<div class="text-box scrollable">
26-
<div>
27-
Header
28-
</div>
29-
<div class="scrollable-content">
30-
<p v-for="i in 6" :key="i">
31-
Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas
32-
porro aliquid sunt expedita possimus ipsam nihil magni eos quam beatae
33-
repellat neque totam quidem reiciendis, incidunt commodi sequi, minus
34-
accusantium?
35-
</p>
36-
</div>
37-
<div>
38-
Footer
39-
</div>
40-
</div>
41-
</GDialog>
42-
43-
<button @click="onClick">
44-
Simple
45-
</button>
46-
<hr>
47-
<button @click="dialogState2 = true">
48-
Scrollable
49-
</button>
50-
<hr>
51-
<button @click="onOpenBoth">
52-
both
53-
</button>
3+
<DialogLayout />
544
</div>
555
</template>
566

577
<script lang="ts">
588
import { defineComponent } from 'vue'
59-
60-
import QLib from '@/gitart-vue-dialog/index'
9+
import DialogLayout from './components/Layout/DialogLayout.vue'
6110
6211
export default defineComponent({
6312
name: 'App',
6413
components: {
65-
GDialog: QLib.GDialog,
66-
},
67-
68-
data: () => ({
69-
dialogState: false,
70-
dialogState2: false,
71-
}),
72-
73-
methods: {
74-
onClick() {
75-
console.log('set true')
76-
this.dialogState = true
77-
},
78-
onOpenBoth() {
79-
console.log('set true')
80-
this.dialogState = true
81-
setTimeout(() => {
82-
this.dialogState2 = true
83-
}, 2200)
84-
},
14+
DialogLayout,
8515
},
8616
})
8717
</script>
@@ -90,22 +20,4 @@ export default defineComponent({
9020
.app {
9121
height: 2000px;
9222
}
93-
94-
.text-box {
95-
background: rgb(248, 248, 248);
96-
box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
97-
font-size: 20px;
98-
border-radius: 4px;
99-
}
100-
101-
.scrollable {
102-
max-height: 100%;
103-
max-width: 100%;
104-
display: flex;
105-
flex-direction: column;
106-
}
107-
108-
.scrollable-content {
109-
overflow: auto;
110-
}
11123
</style>

src/components/Dialog/DialogCard.vue

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<template>
2+
<div class="dialog-card">
3+
<slot />
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
name: 'DialogCard',
10+
}
11+
</script>
12+
13+
<style lang="scss" scoped>
14+
.dialog-card {
15+
background: rgb(248, 248, 248);
16+
border-radius: 4px;
17+
padding: 20px 30px;
18+
}
19+
</style>

src/components/Dialog/DialogToolbar.vue

Whitespace-only changes.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<template>
2+
<GDialog
3+
v-model="value"
4+
:max-width="400"
5+
:depressed="depressed"
6+
>
7+
<p>
8+
Base component
9+
</p>
10+
11+
<BooleanSwitch
12+
v-model="depressed"
13+
label="depressed (without box-shadow)"
14+
/>
15+
</GDialog>
16+
</template>
17+
18+
<script>
19+
import { ref } from 'vue'
20+
import { GDialog } from '@/gitart-vue-dialog'
21+
22+
import { useModelWrapper } from '@/composables/modelWrapper'
23+
24+
import BooleanSwitch from '@/components/PropControls/BooleanSwitch/BooleanSwitch.vue'
25+
26+
export default {
27+
name: 'BaseDialog',
28+
components: {
29+
GDialog,
30+
BooleanSwitch,
31+
},
32+
33+
props: {
34+
modelValue: {
35+
type: Boolean,
36+
default: false,
37+
},
38+
},
39+
40+
setup(props, { emit }) {
41+
const depressed = ref(false)
42+
const value = useModelWrapper(props, emit)
43+
44+
return {
45+
depressed,
46+
value,
47+
}
48+
},
49+
}
50+
</script>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<template>
2+
<BaseDialog v-model="model" />
3+
4+
<button @click="open">
5+
BaseDialog
6+
</button>
7+
</template>
8+
9+
<script>
10+
import { ref } from 'vue'
11+
import BaseDialog from './BaseDialog.vue'
12+
13+
export default {
14+
name: 'BaseDialogWrapper',
15+
components: {
16+
BaseDialog,
17+
},
18+
19+
setup() {
20+
const model = ref(false)
21+
22+
const open = () => {
23+
model.value = true
24+
}
25+
26+
return {
27+
model,
28+
open,
29+
}
30+
},
31+
}
32+
</script>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<template>
2+
<GDialog
3+
v-model="value"
4+
:max-width="400"
5+
>
6+
<DialogCard>
7+
<p>
8+
StyledDialogWrapper
9+
</p>
10+
</DialogCard>
11+
</GDialog>
12+
</template>
13+
14+
<script>
15+
import { GDialog } from '@/gitart-vue-dialog'
16+
17+
import { useModelWrapper } from '@/composables/modelWrapper'
18+
19+
import DialogCard from '@/components/Dialog/DialogCard.vue'
20+
21+
export default {
22+
name: 'BaseDialog',
23+
components: {
24+
GDialog,
25+
DialogCard,
26+
},
27+
28+
props: {
29+
modelValue: {
30+
type: Boolean,
31+
default: false,
32+
},
33+
},
34+
35+
setup(props, { emit }) {
36+
const value = useModelWrapper(props, emit)
37+
38+
return {
39+
value,
40+
}
41+
},
42+
}
43+
</script>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<template>
2+
<StyledDialog v-model="model" />
3+
4+
<button @click="open">
5+
StyledDialog
6+
</button>
7+
</template>
8+
9+
<script>
10+
import { ref } from 'vue'
11+
import StyledDialog from './StyledDialog.vue'
12+
13+
export default {
14+
name: 'StyledDialogWrapper',
15+
components: {
16+
StyledDialog,
17+
},
18+
19+
setup() {
20+
const model = ref(false)
21+
22+
const open = () => {
23+
model.value = true
24+
}
25+
26+
return {
27+
model,
28+
open,
29+
}
30+
},
31+
}
32+
</script>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<template>
2+
<div>
3+
<BaseDialogWrapper />
4+
</div>
5+
6+
<div>
7+
<StyledDialogWrapper />
8+
</div>
9+
</template>
10+
11+
<script>
12+
import BaseDialogWrapper from '@/components/Dialogs/BaseDialog/BaseDialogWrapper.vue'
13+
import StyledDialogWrapper from '@/components/Dialogs/StyledDialog/StyledDialogWrapper.vue'
14+
15+
export default {
16+
name: 'DialogLayout',
17+
components: {
18+
BaseDialogWrapper,
19+
StyledDialogWrapper,
20+
},
21+
22+
setup() {
23+
},
24+
}
25+
</script>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<template>
2+
<RadioGroup v-model="value">
3+
{{ label }}
4+
<Radio
5+
:value="true"
6+
label="True"
7+
/>
8+
9+
<Radio
10+
:value="false"
11+
label="False"
12+
/>
13+
</RadioGroup>
14+
</template>
15+
16+
<script lang="ts">
17+
import { useModelWrapper } from '@/composables/modelWrapper'
18+
19+
import Radio from '@/components/UI/Radio/Radio.vue'
20+
import RadioGroup from '@/components/UI/RadioGroup/RadioGroup.vue'
21+
22+
export default {
23+
name: 'BooleanSwitch',
24+
components: {
25+
Radio,
26+
RadioGroup,
27+
},
28+
29+
props: {
30+
modelValue: {
31+
type: Boolean,
32+
default: false,
33+
},
34+
35+
label: {
36+
type: String,
37+
default: null,
38+
},
39+
},
40+
41+
setup(props, { emit }) {
42+
const value = useModelWrapper(props, emit)
43+
44+
return {
45+
value,
46+
}
47+
},
48+
}
49+
</script>

src/composables/modelWrapper.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { computed } from 'vue'
2+
3+
interface modelWrapperProps {
4+
modelValue: boolean
5+
}
6+
7+
type modelWrapperEmitter = (event: 'update:modelValue', value: boolean) => void
8+
9+
export function useModelWrapper(props: modelWrapperProps, emit: modelWrapperEmitter) {
10+
return computed({
11+
get: () => props.modelValue,
12+
set: (value) => emit('update:modelValue', value),
13+
})
14+
}

0 commit comments

Comments
 (0)