Skip to content

Commit c778d16

Browse files
committed
feat(dynamic): add dynamic components and context management
1 parent 3412b18 commit c778d16

39 files changed

+1115
-0
lines changed

packages/vue/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"@destyler/combobox": "catalog:prod",
5454
"@destyler/dialog": "catalog:prod",
5555
"@destyler/dom": "catalog:prod",
56+
"@destyler/dynamic": "catalog:prod",
5657
"@destyler/edit": "catalog:prod",
5758
"@destyler/file-upload": "catalog:prod",
5859
"@destyler/focus-trap": "catalog:prod",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { anatomy as dynamicAnatomy } from '@destyler/dynamic'
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<script lang="ts">
2+
import type { PolymorphicProps } from '~/factory'
3+
4+
export interface DynamicClearTriggerProps extends PolymorphicProps {}
5+
</script>
6+
7+
<script setup lang="ts">
8+
import { ui } from '~/factory'
9+
import { useDynamicContext } from '../composables/use-dynamic-context'
10+
import { useForwardExpose } from '~/composables'
11+
12+
defineOptions({
13+
name: 'DynamicClearTrigger'
14+
})
15+
16+
defineProps<DynamicClearTriggerProps>()
17+
const dynamic = useDynamicContext()
18+
19+
useForwardExpose()
20+
</script>
21+
22+
<template>
23+
<ui.button v-bind="dynamic.getClearTriggerProps()" :as-child="asChild">
24+
<slot />
25+
</ui.button>
26+
</template>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<script lang="ts">
2+
import type { SlotsType, UnwrapRef } from 'vue'
3+
import type { UseDynamicContext } from '../composables/use-dynamic-context'
4+
5+
export interface DynamicContextProps
6+
extends SlotsType<{
7+
default: UnwrapRef<UseDynamicContext>
8+
}> {}
9+
</script>
10+
11+
<script setup lang="ts">
12+
import { useDynamicContext } from '../composables/use-dynamic-context'
13+
14+
defineOptions({
15+
name: 'DynamicContext'
16+
})
17+
18+
const dynamic = useDynamicContext()
19+
20+
defineSlots<{
21+
default(dynamic: UnwrapRef<UseDynamicContext>): unknown
22+
}>()
23+
</script>
24+
25+
<template>
26+
<slot v-bind="dynamic"></slot>
27+
</template>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<script lang="ts">
2+
import type { PolymorphicProps } from '~/factory'
3+
4+
export interface DynamicControlProps extends PolymorphicProps {}
5+
</script>
6+
7+
<script setup lang="ts">
8+
import { ui } from '~/factory'
9+
import { useDynamicContext } from '../composables/use-dynamic-context'
10+
import { useForwardExpose } from '~/composables'
11+
12+
defineOptions({
13+
name: 'DynamicControl'
14+
})
15+
16+
defineProps<DynamicControlProps>()
17+
const dynamic = useDynamicContext()
18+
19+
useForwardExpose()
20+
</script>
21+
22+
<template>
23+
<ui.div v-bind="dynamic.getControlProps()" :as-child="asChild">
24+
<slot />
25+
</ui.div>
26+
</template>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<script lang="ts">
2+
import type { PolymorphicProps } from '~/factory'
3+
4+
export interface DynamicHiddenInputProps extends PolymorphicProps {}
5+
</script>
6+
7+
<script setup lang="ts">
8+
import { ui } from '~/factory'
9+
import { useDynamicContext } from '../composables/use-dynamic-context'
10+
import { useFieldContext } from '~/components/field'
11+
import { useForwardExpose } from '~/composables'
12+
13+
defineOptions({
14+
name: 'DynamicHiddenInput'
15+
})
16+
17+
defineProps<DynamicHiddenInputProps>()
18+
19+
const dynamic = useDynamicContext()
20+
const field = useFieldContext()
21+
22+
useForwardExpose()
23+
</script>
24+
25+
<template>
26+
<ui.input :aria-describedby="field?.ariaDescribedby" v-bind="dynamic.getHiddenInputProps()" :as-child="asChild">
27+
<slot />
28+
</ui.input>
29+
</template>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<script lang="ts">
2+
import type { PolymorphicProps } from '~/factory'
3+
4+
export interface DynamicInputProps extends PolymorphicProps {}
5+
</script>
6+
7+
<script setup lang="ts">
8+
import { ui } from '~/factory'
9+
import { useDynamicContext } from '../composables/use-dynamic-context'
10+
import { useForwardExpose } from '~/composables'
11+
12+
defineOptions({
13+
name: 'DynamicInput'
14+
})
15+
16+
defineProps<DynamicInputProps>()
17+
const dynamic = useDynamicContext()
18+
19+
useForwardExpose()
20+
</script>
21+
22+
<template>
23+
<ui.input v-bind="dynamic.getInputProps()" :as-child="asChild"><slot /></ui.input>
24+
</template>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<script lang="ts">
2+
import type { ItemProps } from '@destyler/dynamic'
3+
import type { PolymorphicProps } from '~/factory'
4+
5+
export interface DynamicItemProps extends ItemProps, PolymorphicProps {}
6+
</script>
7+
8+
<script setup lang="ts">
9+
import { computed } from 'vue'
10+
import { ui } from '~/factory'
11+
import { useDynamicContext } from '../composables/use-dynamic-context'
12+
import { DynamicItemProvider } from '../composables/use-dynamic-item-context'
13+
import { DynamicItemPropsProvider } from '../composables/use-dynamic-item-props-context'
14+
import { useForwardExpose } from '~/composables'
15+
16+
defineOptions({
17+
name: 'DynamicItem'
18+
})
19+
20+
const props = defineProps<DynamicItemProps>()
21+
const dynamic = useDynamicContext()
22+
23+
DynamicItemPropsProvider(props)
24+
DynamicItemProvider(computed(() => dynamic.value.getItemState(props)))
25+
26+
useForwardExpose()
27+
</script>
28+
29+
<template>
30+
<ui.div v-bind="dynamic.getItemProps(props)" :as-child="asChild">
31+
<slot />
32+
</ui.div>
33+
</template>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<script lang="ts">
2+
import type { SlotsType, UnwrapRef } from 'vue'
3+
import type { UseDynamicItemContext } from '../composables/use-dynamic-item-context'
4+
5+
export interface DynamicItemContextProps
6+
extends SlotsType<{
7+
default: UnwrapRef<UseDynamicItemContext>
8+
}> {}
9+
</script>
10+
11+
<script setup lang="ts">
12+
import { useDynamicItemContext } from '../composables/use-dynamic-item-context'
13+
14+
defineOptions({
15+
name: 'DynamicItemContext'
16+
})
17+
18+
const dynamic = useDynamicItemContext()
19+
20+
defineSlots<{
21+
default(dynamic: UnwrapRef<UseDynamicItemContext>): unknown
22+
}>()
23+
</script>
24+
25+
<template>
26+
<slot v-bind="dynamic"></slot>
27+
</template>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<script lang="ts">
2+
import type { PolymorphicProps } from '~/factory'
3+
4+
export interface DynamicItemDeleteTriggerProps extends PolymorphicProps {}
5+
</script>
6+
7+
<script setup lang="ts">
8+
import { ui } from '~/factory'
9+
import { useDynamicContext } from '../composables/use-dynamic-context'
10+
import { useDynamicItemPropsContext } from '../composables/use-dynamic-item-props-context'
11+
import { useForwardExpose } from '~/composables'
12+
13+
defineOptions({
14+
name: 'DynamicItemDeleteTrigger'
15+
})
16+
17+
defineProps<DynamicItemDeleteTriggerProps>()
18+
const dynamic = useDynamicContext()
19+
const itemProps = useDynamicItemPropsContext()
20+
21+
useForwardExpose()
22+
</script>
23+
24+
<template>
25+
<ui.button v-bind="dynamic.getItemDeleteTriggerProps(itemProps)" :as-child="asChild">
26+
<slot />
27+
</ui.button>
28+
</template>

0 commit comments

Comments
 (0)